Skip to content

Commit

Permalink
Adds controllable paddle (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieugagne committed Jun 15, 2020
1 parent 9162bdc commit ebab0d5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/models/paddle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,30 @@ def move_left
return unless $args.inputs.keyboard.key_down.left || $args.inputs.keyboard.key_held.left

@x -= @speed
@x = 0 if @x < 0
@x = left_edge if @x < left_edge
end

def move_right
return unless can_move_right?
return unless $args.inputs.keyboard.key_down.right || $args.inputs.keyboard.key_held.right

@x += @speed
@x = (Viewport.width - length) if @x > (Viewport.width - length)
@x = right_edge if @x > right_edge
end

def can_move_left?
@x != 0
@x > left_edge
end

def can_move_right?
@x != (Viewport.width - length)
@x < right_edge
end

def left_edge
0
end

def right_edge
Viewport.width - length
end
end

0 comments on commit ebab0d5

Please sign in to comment.