/
asteroid.rb
37 lines (33 loc) · 1.14 KB
/
asteroid.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Asteroid
attr_reader :x, :y, :asteroid
attr_accessor :x_vel, :y_vel, :angle, :checked
def initialize(window, x, y, x_vel, y_vel, image)
@window = window
@x = x
@y = y
@y_vel = x_vel
@x_vel = y_vel
@asteroid = image
@angle = 0
@checked = false
if rand(2) == 1
@angle_vel = rand(4) + 1
else
@angle_vel = -rand(4) - 1
end
end
def update
@x += @x_vel
@y += @y_vel
@angle += @angle_vel
end
def draw(asteroids)
asteroids[@asteroid].draw_rot(@x, @y, 7, @angle)
if @window.debug == true
@window.draw_line(@x, @y, Gosu::Color::GREEN, @x + asteroids[@asteroid].width, @y, Gosu::Color::GREEN, 20)
@window.draw_line(@x, @y, Gosu::Color::GREEN, @x, @y + asteroids[@asteroid].height, Gosu::Color::GREEN, 20)
@window.draw_line(@x, @y + asteroids[@asteroid].height, Gosu::Color::GREEN, @x + asteroids[@asteroid].width, @y + asteroids[@asteroid].height, Gosu::Color::GREEN, 20)
@window.draw_line(@x + asteroids[@asteroid].width, @y, Gosu::Color::GREEN, @x + asteroids[@asteroid].width, @y + asteroids[@asteroid].height, Gosu::Color::GREEN, 20)
end
end
end