Created
October 10, 2009 03:39
-
-
Save jaymcgavren/206570 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
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