Functions! Anti-moonwalk, jump, view moving, actor following

Talk about making games.

What did you do with these functions?

I did use them
2
100%
I thought they are cool, but didn't use them
0
No votes
I thought they are useless
0
No votes
 
Total votes : 2

Functions! Anti-moonwalk, jump, view moving, actor following

Postby lcl » Mon Jul 12, 2010 12:32 pm

Easy to use functions!

Thanks to Hblade, I understand now something about making voids and here is some of what I've made! :D
Current functions:

- Move("animation1", "animation2", DIRECTION, speed);
- Jump("actor", number of actor using function, height of jump);
- EnableJump(the number that actor uses in jump);
- Follow("actor that follows", "actor to follow", axis, speed);
- ViewFollowActor("actor to follow", how much player can move on x axis before view starts moving, same for y, speed)
- CollisionJump("jumping actors name", key, jump height)








First function is for moving actor and same time commanding the animations:
Move("animation1", "animation2", DIRECTION, speed);

Directions:
- LEFT
- RIGHT
- UP
- DOWN
- STOP_LEFT
- STOP_RIGHT
- TWO_KEYS

Use it like this in key down events:
Code: Select all
Move("charRight", "(none)", RIGHT, 5);

"charRight" is the animation
"(none)" this is for second animation, it's usable for commanding animations when two keys are pressed
RIGHT is the way to move, there is many alternatives
5 is speed of move


This code can be also used to command animations while two keys are pressed like this:
Key Down - left, right - All keys are pressed - repeat:
Code: Select all
Move("charStopLeft", "charstopRight", TWO_KEYS, 0);

When using it like this, remember to put to the first animation the name of the animation that is for first one of the keys, and to
the second, place the name of the animation of the second key.






Second function is for jumping:
Jump("actor", number of actor using function, height of jump);

Code: Select all
Jump("Player", 1, 10);

This will make actor called Player jump to the height of 10.
This code work for every individual actor, you just must remember to type different value to the numberin middle of the code.






Third function is for enabling the jump again for certain actor, for example when colliding with ground:
EnableJump(the number that actor uses in jump);

Code: Select all
EnableJump(1);

If you use Jump function, you must remember to use also this, if you don't use this, actor will jump just once.
And remember to type the number same as the number in code what makes the actor jump.






The fourth function is for making actor to follow another:
Follow("actor that follows", "actor to follow", axis, speed);

Axes:
- AXIS_X
- AXIS_Y
- AXIS_BOTH

Code: Select all
Follow("enemy", "Player", AXIS_X, 5);

This will make actor called enemy to chase actor Player, following only Players x axel with speed of 5.
This code work for every individual actor, you just must remember to type different value to the numberin middle of the code.






The fifth function is for making view to follow actor:
ViewFollowActor("actor to follow", how much player can move on x axis before view starts moving, same for y, speed)
Code: Select all
ViewFollowActor("Player", 100, 100, 5);

This will make view follow actor Player with speed of 5. Remember to use this only
in view actors draw actor code.






For now, last function is for making actor jump just while it collides with some actor that you can choose, for example, ground:
CollisionJump("jumping actors name", key, jump height)
Type code to the collision event with actor that you want actor to be able to jump. Remember to put repeat to ON.
For example: Collision - Top side- Ground - Repeat:
Code: Select all
CollisionJump("Player", KEY_UP, 10);

This will make actor called Player to jump to height of 10 while on actor Ground and key up is pressed.
You can use any key on keyboard to use this function!!!


Enjoy of these, I'll make more soon!
I post also a .zip containing the demo of the using of these functions.


Please give me feedback!!! :D


THE CODE:
Code: Select all
long jump[1000];
int dir;
int moving;
int stop;
int stopWay;

#define LEFT 11
#define RIGHT 22
#define UP 33
#define DOWN 44
#define STOP_LEFT 55
#define STOP_RIGHT 66
#define TWO_KEYS 77

#define AXIS_X 88
#define AXIS_Y 99
#define AXIS_BOTH 110

//----------EASY TO USE FUNCTIONS----------
/*These are easy functions for beginners to use
for making their games easier way.*/









//-----MOVING THE PLAYER-----
/*This allows you to change animations and move player
with speed that you can decide yourself.


-----ABOUT USING-----
Moving functions must be used in key down events
following way:

Move("Animation name", "Second animation name" Direction, Speed with numbers);

There are 4 moving directions; left, right, up, down,
and also directions stop left, stop right, and two keys pressed.
To call some of these directions, type:
- LEFT
- RIGHT
- UP
- DOWN
- STOP_LEFT
- STOP_RIGHT
- TWO_KEYS
- JUMP
*/


void Move(char*anim, char*anim2, int moveWay, int speed)
{
    switch(moveWay)
    {
        case LEFT:
        x-=speed;
        if(moving==0)
        {
            if(dir!=1 && stop==0)
            {
                ChangeAnimation("Event Actor", anim, FORWARD);
                dir=1;
                stopWay=1;
            }
        }
        moving=1;
        break;
 
        case RIGHT:
        x+=speed;
        if(moving==0)
        {
            if(dir!=2 && stop==0)
            {
                ChangeAnimation("Event Actor", anim, FORWARD);
                dir=2;
                stopWay=2;
            }
        }
        moving=1;
        break;
 
        case UP:
        y-=speed;
        if(moving==0)
        {
            if(dir!=3)
            {
                ChangeAnimation("Event Actor", anim, FORWARD);
                dir=3;
            }
        }
        moving=1;
        break;
 
        case DOWN:
        y+=speed;
        if(moving==0)
        {
            if(dir!=4)
            {
                ChangeAnimation("Event Actor", anim, FORWARD);
                dir=4;
            }
        }
        moving=1;
        break;
 
        case STOP_LEFT:
        moving=0;
        if(dir!=5)
        {
            ChangeAnimation("Event Actor", anim, FORWARD);
            dir=5;
            stop=0;
        }
        break;
 
        case STOP_RIGHT:
        moving=0;
        if(dir!=6)
        {
            ChangeAnimation("Event Actor", anim, FORWARD);
            dir=6;
            stop=0;
        }
        break;
 
        case TWO_KEYS:
        moving=0;
        if(!stop)
        {
            switch(stopWay)
            {
                case 1:
                ChangeAnimation("Event Actor", anim, FORWARD);
                stop=1;
                break;
 
                case 2:
                ChangeAnimation("Event Actor", anim2, FORWARD);
                stop=1;
            }
        }
        break;
    }
}




//-----JUMPING-----
/*This allows you to make your player jump easily
to the height that you can decide. Function also
disables jumping after one jump. Use the function
EnableJump(); to enable it again ex. in collision with ground.


-----ABOUT USING-----
This function can be used in key down event
following way:
Jump(Set the height with numbers);
*/


void Jump(char*name, int number, int power)
{
    Actor*actor=getclone(name);
    if(jump[number]==0)
    {
        actor->yvelocity=-power;
        jump[number]=1;
    }
}

void EnableJump(int number)
{
    jump[number]=0;
}

 
void Follow(char*name2, char*name, int way, int speed)
{
    Actor*actor=getclone(name);
    Actor*follower=getclone(name2);
    switch(way)
    {
        case AXIS_X:
        if(follower->x<actor->x-speed)
        {
            follower->x+=speed;
        }
        if(follower->x>actor->x+speed)
        {
            follower->x-=speed;
        }
        break;
 
        case AXIS_Y:
        if(follower->y<actor->y-speed)
        {
            follower->y+=speed;
        }
        if(follower->y>actor->y+speed)
        {
            follower->y-=speed;
        }
        break;
 
        case AXIS_BOTH:
        if(follower->x<actor->x-speed)
        {
            follower->x+=speed;
        }
        if(follower->x>actor->x+speed)
        {
            follower->x-=speed;
        }
        if(follower->y<actor->y-speed)
        {
            follower->y+=speed;
        }
        if(follower->y>actor->y+speed)
        {
            follower->y-=speed;
        }
        break;
    }
}

void ViewFollowActor(char*name, int Fx, int Fy, int speed)
{
    Actor*actor=getclone(name);
    int X=view.width/2;
    int Y=view.height/2;
 
    if(x+X<actor->x-speed && actor->xscreen>xscreen+X+Fx)
    {
        x+=speed;
    }
    if(x+X>actor->x+speed && actor->xscreen<xscreen+X-Fx)
    {
        x-=speed;
    }
    if(y+Y<actor->y-speed && actor->yscreen>xscreen+Y+Fy)
    {
        y+=actor->yvelocity;
    }
    if(y+Y>actor->y+speed && actor->yscreen<xscreen+Y-Fy)
    {
        y-=speed;
    }
}

void CollisionJump(char*name, int that, int height)
{
    Actor*actor=getclone(name);
    char*key=GetKeyState();
    strcpy(key, getKeyText(that));
 
    if(key[that]==1)
    {
        actor->yvelocity=-height;
    }

}
Attachments
Functions.zip
(995.33 KiB) Downloaded 264 times
screenie.JPG
Last edited by lcl on Mon Jul 19, 2010 4:56 pm, edited 6 times in total.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Helper functions!

Postby Hblade » Mon Jul 12, 2010 1:25 pm

wow, this is very impressive :D!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Helper functions!

Postby lcl » Mon Jul 12, 2010 1:27 pm

Thanks! :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Helper functions!

Postby Hblade » Mon Jul 12, 2010 1:27 pm

no problem :D Its awesome
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Helper functions!

Postby lcl » Mon Jul 12, 2010 1:29 pm

I am trying to make also view scrolling like this. It's hard, I have tried alredy, but maybe if I try enough... xD
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Helper functions!

Postby Hblade » Mon Jul 12, 2010 1:38 pm

I can help with that :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Helper functions! (important for beginners!)

Postby krenisis » Wed Jul 14, 2010 2:24 am

This is pretty incredible ! I never thought of using code like this to simplify what we do. Thanks alot for sharing your coding secrets!!
Tutorial Database for all beginners click this link
viewtopic.php?f=4&t=8680
krenisis
 
Posts: 606
Joined: Sat Jul 25, 2009 3:27 pm
Score: 51 Give a positive score

Re: Helper functions! (important for beginners!)

Postby lcl » Wed Jul 14, 2010 10:33 am

Glad you like them and think they're useful! :D
I'd maybe add also an option that gives opportunity to define the actor that it would move and change animations. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Very useful functions! Contains perfect ANTI_MOONWALK!

Postby lcl » Sat Jul 17, 2010 10:36 am

Updated!!! :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Very useful functions! Contains perfect ANTI_MOONWALK!

Postby Hblade » Sat Jul 17, 2010 10:52 am

Great :D!

Adding to super list
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Very useful functions! Contains perfect ANTI_MOONWALK!

Postby savvy » Sat Jul 17, 2010 5:37 pm

Very helpful, thanks
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Very useful functions! Contains perfect ANTI_MOONWALK!

Postby lcl » Sat Jul 17, 2010 5:38 pm

Great!
Collision Jump is for making it disable to jump in air... :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Functions! Anti-moonwalk, jump, view moving, actor follo

Postby lcl » Mon Jul 19, 2010 5:02 pm

Has anyone ideas for new functions?? :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Functions! Anti-moonwalk, jump, view moving, actor follo

Postby 247wkman » Sun Feb 26, 2012 6:07 am

new function (idea anyway) i wanted to make a dynamic lantin lighting effect in which the light circles could blend with other players lantins.
i dont know if canvas can do it so the other approuch is to create a black square sprite of say 20x20 pixels and clone array it to fill the view.

The Function would be to give a value to give to your actors (call it light_source maybe) and then you tell the clones: if actor has value: light_source, change your transparency value when within range of it (say if it is 100 it will be completely transparent but beyond that will increase opacity by a relation (say a 1/2 every 25 pixels- so 2 spares of transition approx)

this would supposidly enable light bubbles to mesh together- maybe even tint them too. the picture is a concept render in gimp- it portrays the light bubbles being created by a clone array of squares (20x20) that would change alpha value in proximity the actors- this clone array would be paranted to the view.

i tried this with collision but even if i used a proximity formular i haven't figured how to make each clone respond independantly- instead once one was triggered to change its alpha, the lot did and they all vanished!
Attachments
lighting.jpg
247wkman
 
Posts: 67
Joined: Mon Dec 13, 2010 3:55 pm
Score: 3 Give a positive score

Re: Functions! Anti-moonwalk, jump, view moving, actor follo

Postby lcl » Sun Feb 26, 2012 2:08 pm

It sounds like you're asking for something like this: viewtopic.php?f=5&t=10994
But tell if this is not what you've been searching for. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest