Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get rectangle to move in all directions

  • Loading branch information...
commit ff032872e635bbf79bec3c64c070fab5bfba2563 1 parent 125f615
@practicingruby practicingruby authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 game.rb
View
12 game.rb
@@ -7,17 +7,15 @@
@rect = Ray::Polygon.rectangle([-10, -10, 20, 20], Ray::Color.red)
@rect.pos = [200,200]
- on :key_press, key(:left) do
- @moving_left = true
- end
-
- on :key_release, key(:left) do
- @moving_left = false
+ always do
+ @rect.pos += [-1, 0] if holding?(:left)
+ @rect.pos += [1, 0] if holding?(:right)
+ @rect.pos += [0, -1] if holding?(:up)
+ @rect.pos += [0, 1] if holding?(:down)
end
render do |win|
win.draw @rect
- @rect.pos += [-1,0] if @moving_left
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.