In a small project of mine, I'm attempting to code a side scrolling shooterific game for a friend. I've coded to the best of my ability, but... the code seems to have incredible issues with my choice of arrangement.
In the code below, state doesn't change for anything except ducking, in which it changes properly. All of ducking works fine, save that you can still jump while doing it, which is a byproduct of the .state not changing. Likewise, the jump sprite is displayed for 1/32 of a second when you do jump, but the state doesn't change. While you walk, it doesn't set the sprite, and for the life of me, I can't figure out why. It's probably some dumb mistake with if else statements that I missed, but I'm completely stumped. Would any of you care to take a shot at it?
Player Step Event
if paused=false
{
// --------------- JUMPING ----------------
gravity_direction = 270;// Sets the direction of the pull of gravity. 270 = down.
//
if place_free(x,y+1)//
{
gravity = 0.5;// set gravity to .5
}
else //otherwise
{
gravity = 0;// set gravity to 0
}
// ------- JUMP SPEED --------
if vspeed > 10
{
vspeed = 10;
}
//
// -------- JUMP KEY ---------
//
if keyboard_check(vk_up) and !place_free(x,y+1) and state = 0 // If you're pressing down, and not busy...
{
state = 1; // State = 1
jumping = true; // And jumping = true
vspeed = -6;
}
else // Otherwise...
{
state = 0;// You're not busy
jumping = false;// You're not jumping.
}//
if state = 0
{
jumping = false;
}
//
if jumping = true // If you are jumping...
{
if facing = 90 // and if you're facing Right...
{
sprite_index = sprPlayerJumpR; //Sprite = jump Right
}
else if facing = 180 // Otherwise if you're facing Left...
{
sprite_index = sprPlayerJumpL; // Sprite = jump Left
}
}
//
// --------------- MOVING RIGHT AND LEFT ----------------
//
if keyboard_check(vk_right) and place_free(x+4,y)// If you're pressing Right, and there's nothing to your right...
{
x += 4; // Move to the right some.
facing = 90; // Facing becomes Right.
moving = true; // And you start moving.
}
else // Otherwise...
{
moving=false; // You're not moving.
}
//
if keyboard_check(vk_left) and place_free(x-4,y)// If you're pressing Left, and there's nothing to your Left...
{
x -= 4; //Move Left.
facing = 180; //Facing becomes Left.
moving = true; // And you start moving.
}
else // Otherwise...
{
moving = false; // You're not moving.
}
//
if moving = true and state = 0 // If you're facing Right, and Moving, see above ^^^, and not busy...
{
if facing = 90 // If you're facing Right...
{
sprite_index=sprPlayerWalkR; // Show the walking Right sprite.
}
else if facing = 180 // But if you're facing Left...
{
sprite_index=sprPlayerStandL; // Show that you're standing Left.
}
}
if moving = false and state = 0 //Otherwise ^^^^^^^^ if you're not moving, and not busy (ie, jumping or crouching)...
{
if facing = 90 //And if you're facing Right...
{
sprite_index = sprPlayerStandR; // Sprite = standing right.
}
else if facing = 180 //Otherwise if you're facing Left...
{
sprite_index = sprPlayerStandL; // Sprite = standing left.
}
}
//
// --------------- DUCKING -----------------
//
if keyboard_check(vk_down) and state = 0 // If you're pressing down, and not busy...
{
state = 2; // State = 2
ducking = true; // And ducking = true
}
else // Otherwise...
{
state = 0;// You're not busy
ducking = false;// You're not ducking.
}//
if state = 0
{
ducking = false;// State = not busy
}
//
if ducking = true // If you are ducking...
{
if facing = 90 // and if you're facing Right...
{
sprite_index = sprPlayerDuckR; //Sprite = duck Right
}
else if facing = 180 // Otherwise if you're facing Left...
{
sprite_index = sprPlayerDuckL; // Sprite = duck Left
}
}
}// --- Paused }
Collision w/ objFloor
if vspeed >=0
{
vspeed=0
}
if vspeed=0
{
jumping=false;
}