Class: AiInput
- Defined in:
- lib/entities/components/ai_input.rb
Constant Summary collapse
- NAME_COLOR =
Dark red
Gosu::Color.argb(0xeeb10000)
- UPDATE_RATE =
ms
10
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Attributes inherited from Component
Instance Method Summary collapse
- #control(obj) ⇒ Object
- #draw(viewport) ⇒ Object
-
#initialize(name, object_pool) ⇒ AiInput
constructor
A new instance of AiInput.
- #on_collision(with) ⇒ Object
- #on_damage(amount) ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/entities/components/ai_input.rb', line 5 def name @name end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
6 7 8 |
# File 'lib/entities/components/ai_input.rb', line 6 def stats @stats end |
Instance Method Details
#control(obj) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/entities/components/ai_input.rb', line 16 def control(obj) self.object = obj object.components << self @vision = AiVision.new(obj, @object_pool, rand(700..1200)) @gun = AiGun.new(obj, @vision) @motion = TankMotionFSM.new(obj, @vision, @gun) end |
#draw(viewport) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/entities/components/ai_input.rb', line 46 def draw() @motion.draw() @gun.draw() @name_image ||= Gosu::Image.from_text( $window, @name, Gosu.default_font_name, 20) @name_image.draw( x - @name_image.width / 2 - 1, y + object.graphics.height / 2, 100, 1, 1, Gosu::Color::WHITE) @name_image.draw( x - @name_image.width / 2, y + object.graphics.height / 2, 100, 1, 1, NAME_COLOR) end |
#on_collision(with) ⇒ Object
25 26 27 28 |
# File 'lib/entities/components/ai_input.rb', line 25 def on_collision(with) return if object.health.dead? @motion.on_collision(with) end |
#on_damage(amount) ⇒ Object
30 31 32 33 |
# File 'lib/entities/components/ai_input.rb', line 30 def on_damage(amount) @motion.on_damage(amount) @stats.add_damage(amount) end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/entities/components/ai_input.rb', line 35 def update return respawn if object.health.dead? @gun.adjust_angle now = Gosu.milliseconds return if now - @last_update < UPDATE_RATE @last_update = now @vision.update @gun.update @motion.update end |