Hey, so, I'm making a platformer, and I need my character to jump. I tried, but it is lumpy. Any other way to do jumping? How do you do it? Please help me out!
Thanks!
if (jump == 1)
{
yvelocity -= 10; //place 10 with the value you want
jump = 0;
}
jump = 1;
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;
}
}
CollisionJump("Player", KEY_UP, 10);
Users browsing this forum: No registered users and 1 guest