-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstar.rb
More file actions
55 lines (43 loc) · 653 Bytes
/
star.rb
File metadata and controls
55 lines (43 loc) · 653 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Hasu.load 'quad_object.rb'
class Star < QuadObject
attr_reader :x, :y, :color, :speed, :size
def initialize
@x = rand_x
@y = rand_y
@color = Gosu::Color::GRAY
@speed = rand + 0.5
@size = rand(2) + 1
end
def update
move
if out_of_screen?
set_new_position
end
end
def out_of_screen?
y1 > Game::HEIGHT
end
private
def rand_x
rand(Game::WIDTH)
end
def rand_y
rand(Game::HEIGHT)
end
def move
@y += speed
end
def set_new_position
@y = - rand(20)
@x = rand_x
end
def width
size
end
def height
size
end
def size
@size.to_f
end
end