Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds controllable paddle #21

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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