First, do you know that this question is being asked like million times?
I am sure about that there is some answer to this problem, what is very easily founded...
Any way, I'll help you.
You can do it with many ways, here is two of them.
1. use jump variable.
If you know how to define variable, you can do this.
Create variable called jump and then go to actor that you want to
jump. Add event - key down - define key that you want to make him jump - repeat: no - script editor:
- Code: Select all
if (jump == 1)
{
yvelocity -= 10; //place 10 with the value you want
jump = 0;
}
And same actor - collision top side of your ground actor, repeat: yes - script editor:
- Code: Select all
jump = 1;
2. you can use the function that I have created for this.
- 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;
}
}
Copy the code over to the global code and add it.
Then actor - collision - top side of ground repeat: yes - script editor:
- Code: Select all
CollisionJump("Player", KEY_UP, 10);
That code will make actor called Player to jump to height of 10 when you press key up.
Look game editor script reference for other possible keys for this.
I hope this helps you!
If you have still questions, ask me.