Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sebastjan-hribar
Created April 13, 2019 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastjan-hribar/d2b421bf28ff3c62bb0a75e9a5f71718 to your computer and use it in GitHub Desktop.
Save sebastjan-hribar/d2b421bf28ff3c62bb0a75e9a5f71718 to your computer and use it in GitHub Desktop.
require 'ruby2d'
set( { :title => "Project", :background => "navy", :width => 640, :height => 640, } )
class Tank
attr_accessor :x, :y, :width, :height
def initialize
@x = (get :width) / 2
@y = (get :height) / 2
@width = 50
@height = 100
end
end
tank = Image.new('tank.jpeg')
tank.x, tank.y = get(:width) / 2 - tank.width / 2, get(:height) / 2 - tank.height / 2
on :key_held do |event|
case event.key
when 'a'
tank.x -= 3
when 'd'
tank.x += 3
when 'w'
tank.y -= 3
when 's'
tank.y += 3
end
end
update do
tank.x
tank.y
end
show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment