-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtower.rb
59 lines (56 loc) · 1.44 KB
/
tower.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Tower
attr_reader :board, :brick, :offset, :speed, :coins, :background
def initialize(window)
@window = window
@brick = Gosu::Image.new(@window, "tiles/red.png", true)
@coins = []
@background = make_background([], 150)
@board = make_row([], 400, 0)
@offset = 0
@speed = 3
end
def update(seconds, frames)
if seconds % 10 == 0 && seconds > 0 && frames == 0
@speed += 1
end
@offset -= @speed
end
def make_row(board, rows, multiplier)
y = multiplier
row = 1
rows.times do |j|
num = (rand(14) + 1) * @brick.width
x = 0
if row % 2 == 0
17.times do
board << Tile.new(@window, x, y) unless (x == num || x == num + @brick.width)
x += @brick.width
end
if row % 4 == 0 && j >= 8
num1 = (rand(15) + 1)
while num1 == num / @brick.width || num1 == num / @brick.width + 1
num1 = (rand(15) + 1)
end
@coins << Coin.new(@window, num1 * @brick.width + 8, y - @brick.height + 8)
end
y += @brick.height
else
2.times do
board << Tile.new(@window, 0, y)
board << Tile.new(@window, @window.width - @brick.width, y)
y += @brick.height
end
end
row += 1
end
board
end
def make_background(array, rows)
y = 0
rows.times do |i|
array << Background.new(@window, y)
y += 622
end
array
end
end