Module: Grueserve::Soldier
- Defined in:
- lib/grueserve/soldier.rb
Defined Under Namespace
Classes: Aim
Constant Summary collapse
- RELOAD =
"RELOAD"
Class Method Summary collapse
Instance Method Summary collapse
- #ammo ⇒ Object
- #ammo=(x) ⇒ Object
- #base_grenade_precision_factor ⇒ Object
- #damage ⇒ Object
- #grenade_max_precision_factor ⇒ Object
- #grenade_precision_delta ⇒ Object
- #handle_lbutton(command) ⇒ Object
- #handle_reload(command) ⇒ Object
- #init_soldier ⇒ Object
- #max_ammo ⇒ Object
- #max_throwing_distance ⇒ Object
- #precision ⇒ Object
- #refill ⇒ Object
- #reload ⇒ Object
- #reload_time ⇒ Object
- #shoot_fuzz_factor ⇒ Object
- #throw_grenade ⇒ Object
- #throwing_speed ⇒ Object
Class Method Details
.extend_object(o) ⇒ Object
32 33 34 35 |
# File 'lib/grueserve/soldier.rb', line 32 def self.extend_object(o) super o.init_soldier end |
Instance Method Details
#ammo ⇒ Object
50 51 52 |
# File 'lib/grueserve/soldier.rb', line 50 def ammo @ammo end |
#ammo=(x) ⇒ Object
54 55 56 57 |
# File 'lib/grueserve/soldier.rb', line 54 def ammo=(x) @ammo = x self.extra_status = " Ammo: #{@ammo}" end |
#base_grenade_precision_factor ⇒ Object
63 64 65 |
# File 'lib/grueserve/soldier.rb', line 63 def base_grenade_precision_factor 2 end |
#damage ⇒ Object
156 157 158 |
# File 'lib/grueserve/soldier.rb', line 156 def damage 2 end |
#grenade_max_precision_factor ⇒ Object
71 72 73 |
# File 'lib/grueserve/soldier.rb', line 71 def grenade_max_precision_factor 5 end |
#grenade_precision_delta ⇒ Object
67 68 69 |
# File 'lib/grueserve/soldier.rb', line 67 def grenade_precision_delta 0.1 end |
#handle_lbutton(command) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/grueserve/soldier.rb', line 107 def (command) unless @reloading if command.nil? unless @aim.nil? throw_grenade end else if current_command.include?("SHIFT") max_rate_of(10).times_a_second do if @aim.nil? new_point = Geo::Point.new(command["x"].to_i, command["y"].to_i) - body.origo new_point.abs = max_throwing_distance if new_point.abs > max_throwing_distance @aim = Aim.new(new_point, base_grenade_precision_factor) else @aim.precision += grenade_precision_delta unless @aim.precision > grenade_max_precision_factor end aim_point = body.origo + @aim.point send_aim(aim_point.x, aim_point.y, @aim.point.abs / @aim.precision) end else if @aim.nil? if ammo > 0 max_rate_of(8).times_a_second do shot_line = body.origo.to(command["x"].to_i, command["y"].to_i) this_fuzz_factor = shoot_fuzz_factor angle = fuzz * this_fuzz_factor + shot_line.angle send_aim(command["x"], command["y"], Math.tan(this_fuzz_factor) * shot_line.abs) fire_bullet(angle) self.ammo -= 1 end else max_rate_of(1).times_a_second do broadcast_noise("dry_shot", body.origo) end end else throw_grenade end end end end end |
#handle_reload(command) ⇒ Object
150 151 152 153 154 |
# File 'lib/grueserve/soldier.rb', line 150 def handle_reload(command) unless command.nil? reload end end |
#init_soldier ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/grueserve/soldier.rb', line 37 def init_soldier self.behaviour = "soldier" @reloading = false @aim = nil subscribe("LBUTTON", :handle_lbutton) subscribe("RELOAD", :handle_reload) end |
#max_ammo ⇒ Object
59 60 61 |
# File 'lib/grueserve/soldier.rb', line 59 def max_ammo 32 end |
#max_throwing_distance ⇒ Object
83 84 85 |
# File 'lib/grueserve/soldier.rb', line 83 def max_throwing_distance 200 end |
#precision ⇒ Object
174 175 176 |
# File 'lib/grueserve/soldier.rb', line 174 def precision 30.0 end |
#refill ⇒ Object
45 46 47 48 |
# File 'lib/grueserve/soldier.rb', line 45 def refill super self.ammo = max_ammo end |
#reload ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/grueserve/soldier.rb', line 87 def reload if !@reloading && @aim.nil @reloading = true broadcast_noise("reload", body.origo) thread_with_rescue do sleep(reload_time) self.ammo = max_ammo @reloading = false end end end |
#reload_time ⇒ Object
75 76 77 |
# File 'lib/grueserve/soldier.rb', line 75 def reload_time 3 end |
#shoot_fuzz_factor ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/grueserve/soldier.rb', line 160 def shoot_fuzz_factor rval = 1.0 if moving? if state == :dodging rval *= 4 else rval *= 2 end else rval *= 0.5 if state == :dodging end return rval / precision end |
#throw_grenade ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/grueserve/soldier.rb', line 99 def throw_grenade this_fuzz_factor = @aim.point.abs / @aim.precision loc = body.origo + Geo::Point.new(@aim.point.x + (this_fuzz_factor * fuzz), @aim.point.y + (this_fuzz_factor * fuzz)) send_throw(body.origo.to(loc), throwing_speed) @aim = nil end |
#throwing_speed ⇒ Object
79 80 81 |
# File 'lib/grueserve/soldier.rb', line 79 def throwing_speed 100 end |