Class: Gembots::Projectile
- Inherits:
-
Object
- Object
- Gembots::Projectile
- Defined in:
- lib/gembots/projectile.rb
Overview
Class used by the arena to represent a projectile(bullet).
Instance Attribute Summary collapse
-
#angle ⇒ Object
readonly
Angle of the projectile.
-
#x ⇒ Object
readonly
Positions of the projectile.
-
#y ⇒ Object
readonly
Positions of the projectile.
Instance Method Summary collapse
-
#draw ⇒ Object
Method called via the arena.
-
#initialize(window, x = 0, y = 0, angle = 0) ⇒ Projectile
constructor
A new instance of Projectile.
-
#update ⇒ Object
Method called via the arena.
Constructor Details
#initialize(window, x = 0, y = 0, angle = 0) ⇒ Projectile
Returns a new instance of Projectile.
11 12 13 14 15 16 17 |
# File 'lib/gembots/projectile.rb', line 11 def initialize window, x=0, y=0, angle=0 @window = window @image = Gosu::Image.new @window, "#{Gembots::MEDIA}/projectile.png", false @angle = angle @x = x + Gosu::offset_x(@angle, 10) @y = y + Gosu::offset_y(@angle, 10) end |
Instance Attribute Details
#angle ⇒ Object (readonly)
Angle of the projectile.
9 10 11 |
# File 'lib/gembots/projectile.rb', line 9 def angle @angle end |
#x ⇒ Object (readonly)
Positions of the projectile.
6 7 8 |
# File 'lib/gembots/projectile.rb', line 6 def x @x end |
#y ⇒ Object (readonly)
Positions of the projectile.
6 7 8 |
# File 'lib/gembots/projectile.rb', line 6 def y @y end |
Instance Method Details
#draw ⇒ Object
Method called via the arena.
29 30 31 |
# File 'lib/gembots/projectile.rb', line 29 def draw @image.draw_rot @x, @y, 1, @angle - 90 % 360 end |
#update ⇒ Object
Method called via the arena. Moves the projectile 2 forward.
21 22 23 24 25 26 |
# File 'lib/gembots/projectile.rb', line 21 def update @x += Gosu::offset_x @angle, 2 @y += Gosu::offset_y @angle, 2 @x %= 640 @y %= 480 end |