Skip to content

Instantly share code, notes, and snippets.

@jaymcgavren
Created October 10, 2009 03:39
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 jaymcgavren/206570 to your computer and use it in GitHub Desktop.
Save jaymcgavren/206570 to your computer and use it in GitHub Desktop.
class ShellShooter < Jemini::Behavior
POWER_FACTOR = 120.0
def fire_weapon(power, angle)
begin
#TODO: configurable fire_from_distance to replace barrel anchor
shell = @target.game_state.create :Shell
# shell_offset = @target.barrel_anchor + Vector.new(0.0, -5.0 + @target.barrel_anchor.y)
shell_offset = Vector.new(0.0, -5.0 - @target.barrel_width)
shell_position = shell_offset.pivot_around_degrees(Vector::ORIGIN, @target.physical_rotation + angle)
shell.body_position = @target.body_position + shell_position
shell.physical_rotation = @target.physical_rotation + angle + 90.0
shell_vector = Vector.from_polar_vector(power * POWER_FACTOR, angle + @target.physical_rotation)
shell.add_force shell_vector
@target.game_state.manager(:sound).play_sound :fire_cannon
@target.add_force shell_vector.negate
rescue Exception => exception
puts exception.message, exception.backtrace
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment