Class: Gembots::Projectile

Inherits:
Object
  • Object
show all
Defined in:
lib/gembots/projectile.rb

Overview

Class used by the arena to represent a projectile(bullet).

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#angleObject (readonly)

Angle of the projectile.



9
10
11
# File 'lib/gembots/projectile.rb', line 9

def angle
  @angle
end

#xObject (readonly)

Positions of the projectile.



6
7
8
# File 'lib/gembots/projectile.rb', line 6

def x
  @x
end

#yObject (readonly)

Positions of the projectile.



6
7
8
# File 'lib/gembots/projectile.rb', line 6

def y
  @y
end

Instance Method Details

#drawObject

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

#updateObject

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