-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameoverstate.rb
117 lines (94 loc) · 3.04 KB
/
gameoverstate.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class GameOverState
def initialize
@buttons = [Button.new(0, 0, 500, "res/button_n.png", "res/button_s.png"),
Button.new(0, 0, 500, "res/button_n.png", "res/button_s.png")]
@buttons[0].text = "Go Menu"
@buttons[0].x = 5
@buttons[0].y = $game.settings.default_height - @buttons[0].height - 5
@buttons[1].text = "Exit"
@buttons[1].x = $game.settings.default_width - @buttons[1].width - 5
@buttons[1].y = $game.settings.default_height - @buttons[1].height - 5
@defining_score = false
@final_score = 0
@quitting = false
# Scale stuffs
@scale = 0.0
@scale_time = 0.0
end
def update
$menus_channel = $menus_sample.play(($game.settings.music_volume / 100.0), 1, true) if $menus_channel == nil or !$menus_channel.playing?
if Fader::faded_in? then
Fader::fade_out(10)
$game.stop_shaking!
end
if @defining_score
@final_score += 100 if @final_score < ($game.score + $game.distance).to_i
@final_score = ($game.score + $game.distance).to_i if @final_score > ($game.score + $game.distance).to_i
if @final_score == ($game.score + $game.distance).to_i then
@defining_score = false
end
else
@scale_time += 0.1
@scale = 0.8 + Math::sin(@scale_time) * 0.1
end
if !@defining_score
passed = false
if @buttons[0].clicked?
@quitting = true
Fader::fade_in(10)
passed = true
elsif @buttons[1].clicked?
$game.close()
exit(0)
passed = true
end
if passed
File.open("data/scores.txt", "a") do |f|
time = Time.new
date = time.day.to_s + "/" + time.month.to_s + "/" + time.year.to_s
f.write("#{date}:#{@final_score}\n")
end
end
end
if Fader::faded_in? and @quitting then
$game.score = 0
$game.distance = 0
$game.state = :menu
end
end
def draw
StarAnimation.draw()
@buttons.each do |button|
button.draw()
end
$font.draw("Final score : #{@final_score.to_i} !",
($game.settings.default_width - $font.text_width("Final score : #{@final_score.to_i} !", @scale)) / 2,
50,
500,
@scale,
@scale + 0.1,
Color::YELLOW)
$font.draw("Game score : #{$game.score.to_i} points",
($game.settings.default_width - $font.text_width("Distance travelled : #{$game.distance.to_i} meters", 0.4)) / 2,
250,
500,
0.4,
0.5,
Color::RED)
$font.draw("Distance travelled : #{$game.distance.to_i} meters",
($game.settings.default_width - $font.text_width("Distance travelled : #{$game.distance.to_i} meters", 0.4)) / 2,
350,
500,
0.4,
0.5,
Color::RED)
end
def reset
@scale_time = 0.0
@scale = 0.8
@defining_score = true
@final_score = $game.score.to_i
@quitting = false
end
def set_volume; end
end