S
Shadowblitz16
Guest
does anybody know how to create good super mario player logic?
currently I am trying to replicate code from super mario war which is a c++ game
however the code is very messy and I can see several place where they could have optimized
basicly I want to know as good player code structure where I can eventually port it to this for modding purposes
I want to make my player to be able to idle, walk, run, skid, jump, and fall right now
but a good thing to note is that x friction does not happen when the player is not pressing left or right
anyways this is my current code but it is not very good quality because it doesn't use states
could someone tell me how to refine my code and make it work similar to a mario game?
currently I am trying to replicate code from super mario war which is a c++ game
however the code is very messy and I can see several place where they could have optimized
basicly I want to know as good player code structure where I can eventually port it to this for modding purposes
I want to make my player to be able to idle, walk, run, skid, jump, and fall right now
but a good thing to note is that x friction does not happen when the player is not pressing left or right
anyways this is my current code but it is not very good quality because it doesn't use states
Code:
input = Input
// Move Friction
//if (!collision_tile_bottom && Input.xaxis == 0) { fx = VEL_FRICTION_AIR; fy = VEL_FRICTION_AIR; }
//else if ( collision_tile_bottom && Input.xaxis == 0) { fx = VEL_FRICTION fy = VEL_FRICTION; }
//else { fx = 0 fy = 0; }
//// Move Speed
//if (in_ice) accel = VEL_ACCELERATION_ICE
//else if (in_mud) accel = VEL_ACCELERATION_MUD
//else accel = VEL_ACCELERATION
//// Move Speed Max
//if (Input.b) vx_max = VEL_SPEED_FAST
//else vx_max = VEL_SPEED
// BUG: player can walk backwards if signed vx is equeal to signed xaxis and state is already PS_MOVE
if (Input.xaxis != 0)
{
if (state != PS_SKID && osign(Input.xaxis, vx)) { state = PS_SKID animation_play(sprite_index, [13], 1.0, false) audio_play_sound(snd_skid, 1, false) }
else if (state != PS_MOVE && ssign(Input.xaxis, vx)) { state = PS_MOVE animation_play(sprite_index, [1, 2], 0.4, true) flip(input.xaxis) }
vx_max = 0.0
if (osign(Input.xaxis, vx))
{
if (++skid_timer > 3)
{
skid_timer = 0
instance_create_depth(x + 7 * sign(image_xscale), y + 12, depth -1, Effect)
}
}
// Start of movement logic
if (in_ice) vx += VEL_ACCELERATION_ICE * sign(Input.xaxis)
else vx += VEL_ACCELERATION * sign(Input.xaxis)
if (!is_frozen)
{
if (input.b) vx_max = (VEL_SPEED_FAST + (tagged_id == id ? VEL_SPEED_TAGGED : 0.0)) * sign(vx)
else vx_max = (VEL_SPEED + (tagged_id == id ? VEL_SPEED_TAGGED : 0.0)) * sign(vx)
//show_debug_message(vx_max)
}
if (abs(vx) > abs(vx_max)) vx = abs(vx_max) * sign(vx);
}
else
{
//if (state == PS_SKID && vx == 0) { state = PS_IDLE animation_play(sprite_index, [1], 1.0, false) }
if (state != PS_IDLE && vx == 0) { state = PS_IDLE animation_play(sprite_index, [1], 1.0, false) }
//else if (state != PS_MOVE && ssign(Input.xaxis, vx)) { state = PS_MOVE animation_play(sprite_index, [1, 2], 0.4, true) flip(input.xaxis) }
if (state == PS_SKID)
{
if (+skid_timer > 3)
{
skid_timer = 0
instance_create_depth(x + 8 * sign(image_xscale), y + 16, depth -1, Effect)
}
}
if (vx != 0.0)
{
if (in_air) vx -= VEL_FRICTION_AIR * sign(vx)
else if (in_ice) vx -= VEL_FRICTION_ICE * sign(vx)
else vx -= VEL_FRICTION * sign(vx)
//if (vx != 0.0) vx = 0.0
}
//if (!in_air) vx = 0.0
}
if (!in_air)
{
if (input.a)
{
jump(sign(image_xscale), input, 1.0, false);
}
}
if (collision_tile_bottom)
{
in_air = false
}
vy += VEL_GRAVITY
if (vy > VEL_MAX_Y) vy = VEL_MAX_Y