#help with reorganizing code into state machine

5 messages · Page 1 of 1 (latest)

pulsar hornet
#

the states i have right now are IDLE, MOVE, JUMP, DASH and DASH JUMP. i wanna find a way to fit my code into these states (aside from the jump state)

#
move_dir = right_key - left_key;

//direction
if move_dir != 0 {face = move_dir}

//get xspeed
x_speed = move_dir * move_speed;

//x collision
var _subpixel = .5;

if place_meeting(x + x_speed,y,obj_wall)
{
    var _pixel_check = _subpixel * sign(x_speed);
    
    while !place_meeting(x + _pixel_check,y,obj_wall)
    {
        x += _pixel_check;
    }
    
    x_speed = 0;
}

x += x_speed;

what's left of the x movement

#
//gravity
y_speed += grav;

//jump

if on_ground 
{
    jump_count = 0;
} else {
    if jump_count == 0 {jump_count = 1}
}





//y collision

if place_meeting(x ,y + y_speed,obj_wall)
{
    var _pixel_check = _subpixel * sign(y_speed);
    
    while !place_meeting(x ,y + _pixel_check,obj_wall)
    {
        y += _pixel_check;
    }
    
    y_speed = 0;
}

if y_speed >= 0 && place_meeting(x,y + 1, obj_wall)
{
    on_ground = true;
} else {
    on_ground = false;
}

y += y_speed;

what's left of the y movement

#
if abs(x_speed) > 0 {sprite_index = walk_sprite}
if x_speed == 0 {sprite_index = idle_sprite}
if !on_ground {sprite_index = jump_sprite}
if !on_ground && y_speed >= 0 {sprite_index = spr_player_fall}
mask_index = mask_sprite;

and the sprite controller

pulsar hornet
#

actually if im gonna use states i might drop the sprite controller