Created
April 13, 2019 11:10
-
-
Save sebastjan-hribar/d2b421bf28ff3c62bb0a75e9a5f71718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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