Game A Gogo wrote:how did you make that happen? (Btw the mario sprite has nothing do to with collision, it's on another hidden actor, so his nose got nothing to do with it o: )
EDIT: just found out how... pretty strange, I think it's because it's not detecting anything under mario, so the yvelocity=0; happens later, or something S:
lcl wrote:Game A Gogo wrote:how did you make that happen? (Btw the mario sprite has nothing do to with collision, it's on another hidden actor, so his nose got nothing to do with it o: )
EDIT: just found out how... pretty strange, I think it's because it's not detecting anything under mario, so the yvelocity=0; happens later, or something S:
No, I dragged the collision actor to that point and actually, at that exact point one pixel of that collision actor is on top of the ground causing Mario to stand in air
float MSensor=1.2;
char*key=GetKeyState();
//xvelocity becomes either 2 or -2 depending on the key pressed
//if both or none are pressed it is 0
xvelocity=(key[KEY_RIGHT]-key[KEY_LEFT])*2;
//if ceiling is high enough
//but if we land too deep into ground, lift player up 2 pixels
if(abs(xvelocity)>0&&CollisionFree("Event Actor",x+xvelocity,y-5)&&
CollisionFree("Event Actor",x+xvelocity,y-1)==0)y-=2;
//if ceiling is too low, we cannot move
else if(CollisionFree("Event Actor",x+xvelocity,y-5)==0)xvelocity=0;
//determine the direction of movement
//if "1" means key right is pressed, if "-1" key left
if(abs(xvelocity)>0)PlayerWD=xvelocity/abs(xvelocity);
//if xvelocity is larger-equal than movement sensor (we definitely move)
//and if yvelocity is smaller-equal to movement sensor (we are not falling too fast)
//we draw going right animation
if(xvelocity>=MSensor&&abs(yvelocity)<=MSensor)ChangeAnimation("actor", "goright1", NO_CHANGE);
//or if xvelocity is smaller-equal than negative movement sensor (we move another direction)
//and we are not falling too fast
//we draw going left animation
else if(xvelocity<=-MSensor&&abs(yvelocity)<=MSensor)ChangeAnimation("actor", "goleft1", NO_CHANGE);
//if we are not moving and not falling, we draw stand animation
if(abs(xvelocity)<MSensor&&abs(yvelocity)<=MSensor)
{
//here we choose which direction to draw
if(PlayerWD==1)ChangeAnimation("actor", "standright", NO_CHANGE);
else ChangeAnimation("actor", "standleft", NO_CHANGE);
}
//if we are definitely falling
//we draw falling animation
if(yvelocity>=MSensor)
{
if(PlayerWD==1)ChangeAnimation("actor", "standright", NO_CHANGE);
else ChangeAnimation("actor", "standleft", NO_CHANGE);
}
//if we are "falling" the other direction, means we are jumping
else if(yvelocity<=-MSensor)
{
if(Jump==1)PlaySound2("data/BUTTON01.WAV", 0.233333, 1, 0.000000);
if(PlayerWD==1)ChangeAnimation("actor", "jumpright", NO_CHANGE);
else ChangeAnimation("actor", "jumpleft", NO_CHANGE);
}
//if there is no collision immediately below us
//and no collision even 1 pixel more below us
//we turn gravity on and disallow jumping
if(CollisionFree("Event Actor",x,y+yvelocity)||
CollisionFree("Event Actor",x,y+yvelocity+1)){
yvelocity+=0.16;Jump=0;
}
//but if there is a collision, we turn gravity off
else {
//we turn off ability to jump if there is a
//collision near top of player;
if(CollisionFree("Event Actor",x,y+yvelocity-4)==0)Jump=0;
//if nothing is near top of player, we allow jumping
else {
Jump=1;
}
}
yvelocity=0;
}
yvelocity-=key['z']*Jump*jump_height;
Users browsing this forum: No registered users and 1 guest