Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //We use these so we can just type the variables.
- //Instead of "keyboard_check(*)".
- KEY_RIGHT=keyboard_check(vk_right);
- KEY_LEFT=keyboard_check(vk_left);
- KEY_JUMP=keyboard_check_pressed(vk_up);
- KEY_ATTACK=keyboard_check_pressed(ord("A"));
- KEY_FALL=keyboard_check_released(vk_up); //This one's for variable jump height:
- //Vertical movements.
- //Is the player in the air?
- if (place_meeting(x,y+1,objBlock)) grounded=1;
- else grounded=0;
- //Jump with the up key when on the ground.
- if (KEY_JUMP and grounded)
- {
- vsp=jumpsp;
- }
- //If we're in air moving up and jump key is released, we remove
- //upward motion (So we fall and get variable jump height.)
- if (KEY_FALL and !grounded and vsp<-1) vsp=-1;
- //Fall with gravity.
- if (!grounded) vsp+=grav;
- //Now it's more complicated.
- //When hitting the ceiling, vertical speed must stop.
- //The if statement says, "if we hit the ceiling and are moving up"
- if (place_meeting(x,y+vsp,objBlock) && vsp<0)
- {
- //We must move up until contact with the ceiling.
- while (!place_meeting(x,y+sign(vsp),objBlock)) y+=sign(vsp);
- vsp=0;
- }
- //But if we are moving down and hit the floor, we have to land.
- if (place_meeting(x,y+vsp,objBlock) and vsp>0)
- {
- //Move so we hit the ground.
- var cc;
- cc=vsp+1; //A counter, so we don't get an infinite loop
- //Move down until we hit the floor.
- while (!place_meeting(x,y+1,objBlock) and cc>=0) y+=1;
- //Now ground the player.
- grounded=1;
- vsp=0;
- }
- //Again, we're not using vspeed, so we have to move ourselves.
- y+=vsp;
- //Now for horizontal movements.
- //Now check if the player pressed left or right and move.
- if (KEY_RIGHT)
- {
- hsp=walksp; //Walk right.
- image_xscale=1; //Face right.
- }
- if (KEY_LEFT)
- {
- hsp=-walksp; //Walk left.
- image_xscale=-1; //Face left.
- }
- //Stop moving when no keys are pressed.
- if (!KEY_RIGHT and !KEY_LEFT) hsp=0 stand=1;
- //Make sure we don't hit a wall.
- if (place_meeting(x+hsp,y,objBlock))
- {
- //Move until contact with the wall.
- if (hsp!=0)
- while (!place_meeting(x+sign(hsp),y,objBlock))
- x+=sign(hsp);
- hsp=0;
- }
- //Because we don't use hspeed, we got to move ourselves.
- x+=hsp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement