samples/05_mouse/02_mouse_move/app/main.rb
# Calculates the position and movement of the player on the screen.
Calculates the position and movement of the player on the screen.
Calculates the position and movement of the player on the screen .
def calc_player
    state.player.x += state.player.dx 
    state.player.y += state.player.dy 
    state.player.dx *= 0.9 
    state.player.dy *= 0.9 
    state.player.x = state.player.x.lesser(1280).greater(0)
    state.player.y = state.player.y.lesser(720).greater(0) 
  end
def calc_player state . player . x += state . player . dx state . player . y += state . player . dy state . player . dx *= 0.9 state . player . dy *= 0.9 state . player . x = state . player . x . lesser ( 1280 ) . greater ( 0 ) state . player . y = state . player . y . lesser ( 720 ) . greater ( 0 ) end
Calculates the position and movement of the player on the screen.
Calculates the position and movement of the player on the screen .
# changes x based on dx (change in x) # changes y based on dy (change in y) # scales dx down # scales dy down # Compares player's x to 1280 to find lesser value, then compares result to 0 to find greater value. # This ensures that the player remains within the screen's scope. # same with player's y