-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboosters.rb
88 lines (60 loc) · 1.65 KB
/
boosters.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Boosters
class Booster
attr_reader :x, :y, :img
def initialize(path)
@x = rand($game.settings.default_width)
@y = 0
@img = Image.new(path)
@speed = 8
@base = 0
@rarity = 0
@rectangle = Rectangle.new(0, 0, @img.width, @img.height)
end
def update(player_x, booster_speed, can_go_down)
@x -= (player_x - $game.settings.default_width / 2) * 0.2
@y += @speed + booster_speed if can_go_down
if @y > $game.settings.default_height then
reset()
end
@rectangle.x = @x
@rectangle.y = @y
end
def draw(player_x = nil)
@img.draw(@x, @y, 500) if @img != nil and @y + @img.height > 0
@x += (player_x - $game.settings.default_width / 2) * 0.2 if player_x != nil
end
def collides?(rect)
return true if @rectangle.collides?(rect)
return false
end
def reset
@y = -rand(@base..@rarity)
@x = rand($game.settings.default_width)
end
end
class NormalBooster < Booster
def initialize
super("res/booster_normal.png")
@base = 1000
@rarity = 8000
@y = -rand(@base..@rarity)
end
end
class SuperBooster < Booster
def initialize
super("res/booster_super.png")
@base = 3000
@rarity = 12000
@y = -rand(@base..@rarity)
end
end
class HyperBooster < Booster
def initialize
super("res/booster_hyper.png")
@base = 8000
@rarity = 20000
@y = -rand(@base..@rarity)
@speed = 12
end
end
end