Switch statements but in ruby

pull/1/head
E. Almqvist 3 years ago
parent 35754c120e
commit 13ef9957ea
  1. 4
      app.rb
  2. 10
      config.rb
  3. 16
      controller.rb

@ -20,8 +20,8 @@ class Window < Gosu::Window
@physobjs = physobjs
@planets = planets
@font = Gosu::Font.new(self, "monospace", 18)
@font2 = Gosu::Font.new(self, "monospace", 20)
@font = Gosu::Font.new(self, MAIN_FONT, 18)
@font2 = Gosu::Font.new(self, MAIN_FONT, 20)
@fonts = {
normal: @font,

@ -2,4 +2,12 @@
MAIN_FONT = "monospace"
# Keybinds
BIND_PAUSE = Gosu::KbEscape
# General
BIND_PAUSE = Gosu::KbEscape
# Player Controlls
BIND_TURN_LEFT = Gosu::KbLeft
BIND_TURN_RIGHT = Gosu::KbRight
BIND_INCREASE_THRUST = Gosu::KbUp
BIND_DECREASE_THRUST = Gosu::KbDown
BIND_TOGGLE_ENGINE = Gosu::KbSpace

@ -28,24 +28,22 @@ class Player < PhysCube
end
def button_down(id)
if( id == Gosu::KbSpace ) then
case id
when BIND_TOGGLE_ENGINE
@engine = !@engine
end
if( id == Gosu::KbLeft ) then
when BIND_TURN_LEFT
self.angle -= 20
end
if( id == Gosu::KbRight ) then
when BIND_TURN_RIGHT
self.angle += 20
end
if( id == Gosu::KbUp ) then
when BIND_INCREASE_THRUST
self.thrust += 0.0005
self.thrust = self.thrust.round(5)
end
if( id == Gosu::KbDown ) then
when BIND_DECREASE_THRUST
self.thrust -= 0.0005
self.thrust = self.thrust.round(5)
end

Loading…
Cancel
Save