Skip to content

Commit

Permalink
barrel lifting
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Smith committed Feb 4, 2016
1 parent 96cadb0 commit 9a8e033
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def set_repeat(tex)
camera.position.y = 1.0
camera.rotation.y = Math::PI

turret.add(camera)
barrel.add(camera)

renderer.window.on_resize do |width, height|
renderer.set_viewport(0, 0, width, height)
Expand Down Expand Up @@ -182,6 +182,15 @@ def drive_tank(tank, amount)
tank.translate_z(amount)
end

def lift_barrel(barrel, amount)
barrel.rotation.x += amount
if barrel.rotation.x > Math::PI/18.0
barrel.rotation.x = Math::PI/18.0
elsif barrel.rotation.x < -Math::PI/9.0
barrel.rotation.x = -Math::PI/9.0
end
end

x = 0
renderer.window.run do
if renderer.window.joystick_present?
Expand All @@ -194,6 +203,7 @@ def drive_tank(tank, amount)
drive_tank(tank, -left_stick.y)
turn_tank(tank, turret, -left_stick.x)
rotate_turret(turret, -right_stick.x)
lift_barrel(barrel, right_stick.y)
end

if renderer.window.key_down?(GLFW_KEY_A)
Expand All @@ -214,6 +224,12 @@ def drive_tank(tank, amount)
if renderer.window.key_down?(GLFW_KEY_S)
drive_tank(tank, -JOYSTICK_SENSITIVITY)
end
if renderer.window.key_down?(GLFW_KEY_UP)
lift_barrel(barrel, -JOYSTICK_SENSITIVITY)
end
if renderer.window.key_down?(GLFW_KEY_DOWN)
lift_barrel(barrel, JOYSTICK_SENSITIVITY)
end

shiny_balls.each_with_index do |ball, i|
ball.position.y = Math::sin(x * 0.005 + i.to_f) * 3.0 + 4.0
Expand Down

0 comments on commit 9a8e033

Please sign in to comment.