I'm trying to make a jumping mechanic for an animated sprite and i wanted to know if my code is good
ball = {} ball.x = 20 ball.y = 80 ball.initial_sprite = 0 ball.sprite = ball.initial_sprite ball.frames = 10 ball.is_jumping = false ball.jumping_frame = 0 ball.jumping_max_frames = 4 function update_ball_sprite() ball.sprite += 1 ball.sprite %= ball.frames end function ball_jump(speed) if ball.jumping_frame < ball.jumping_max_frames then if ball.jumping_frame < ball.jumping_max_frames/2 then ball.y -= speed else ball.y += speed end ball.jumping_frame+=1 else ball.jumping_frame = 0 ball.is_jumping = false end end function _init() ticker = 0 end function _update() ticker += 1 if (btn(2) and not ball.is_jumping) ball.is_jumping = true if ((ticker % 2 == 0) and ball.is_jumping) ball_jump(6) if (ticker % 3 == 0) update_ball_sprite() if (ticker % 30 == 0) ticker = 0 end function _draw() clear_screen(0) spr(ball.sprite, ball.x, ball.y) end function clear_screen(color) rectfill(0,0,127,127,color) end |
It is a basic setup for an infinite runner with jumping, i feel like i'm doing something wrong but i can't know for sure. Is this good?
[Please log in to post a comment]