-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameOver.py
136 lines (105 loc) · 6.3 KB
/
GameOver.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import arcade
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
class GameOver(arcade.View):
def __init__(self):
self.window = None
self.hover_color = [0, 0, 0, 100]
self.click_color = [0, 0, 0, 150]
self.hovering = None
self.clicking = None
self.draw_restart_button_hover = None
self.restart_bottom = None
self.restart_left = None
self.game_over_text = None
self.game_over_text2 = None
self.restart_button = None
self.old_screen_center_x = None
self.old_screen_center_y = None
self.screen_center_x = None
self.screen_center_y = None
def on_show(self):
self.window = arcade.get_window()
self.draw_restart_button_hover = False
self.hovering = False
self.clicking = False
self.old_screen_center_x = int(self.window.get_size()[0] / 2)
self.old_screen_center_y = int(self.window.get_size()[1] / 2)
self.screen_center_x = int(self.window.get_size()[0] / 2)
self.screen_center_y = int(self.window.get_size()[1] / 2)
game_over_text = 'Game Over!'
self.game_over_text = arcade.draw_text(game_over_text, self.screen_center_x, self.screen_center_y + 150,
anchor_x='center',
anchor_y='center', color=arcade.csscolor.WHITE, font_size=32, font_name='fonts/RobotoMono-Regular.ttf')
game_over_text = 'You Couldn\'t Get More Coins Than You Did On The Bar-Round!'
self.game_over_text2 = arcade.draw_text(game_over_text, self.screen_center_x, self.screen_center_y + 100,
anchor_x='center',
anchor_y='center', color=arcade.csscolor.WHITE, font_size=32,
font_name='fonts/RobotoMono-Regular.ttf')
restart_text = 'Restart'
self.restart_button = arcade.draw_text(restart_text, self.screen_center_x, self.screen_center_y,
anchor_x='center', anchor_y='center',
color=arcade.csscolor.WHITE, font_size=64, font_name='fonts/RobotoMono-Regular.ttf')
arcade.set_background_color([66, 245, 212, 255])
arcade.set_viewport(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)
def on_mouse_motion(self, x, y, dx, dy):
if self.play_left + self.restart_button.width + 50 >= x >= self.play_left - 50 and self.play_bottom + self.restart_button.height + 25 >= y >= self.play_bottom - 25:
self.draw_restart_button_hover = True
self.hovering = True
else:
self.draw_restart_button_hover = False
self.hovering = False
def on_mouse_press(self, x, y, button, modifiers):
if self.play_left + self.restart_button.width + 50 >= x >= self.play_left - 50 and self.play_bottom + self.restart_button.height + 25 >= y >= self.play_bottom - 25:
self.draw_restart_button_hover = True
self.clicking = True
else:
self.draw_restart_button_hover = False
self.clicking = False
def on_mouse_release(self, x, y, button, modifiers):
if self.play_left + self.restart_button.width + 50 >= x >= self.play_left - 50 and self.play_bottom + self.restart_button.height + 25 >= y >= self.play_bottom - 25:
from open_window_views import MyGame
game = MyGame(1, 0, 0)
self.window.show_view(game)
def on_draw(self):
arcade.start_render()
arcade.set_viewport(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT)
screen_width, screen_height = self.window.get_size()
self.screen_center_x = int(screen_width / 2)
self.screen_center_y = int(screen_height / 2)
if self.old_screen_center_x != self.screen_center_x or self.old_screen_center_y != self.screen_center_y:
game_over_text = 'Game Over!'
self.game_over_text = arcade.draw_text(game_over_text, self.screen_center_x, self.screen_center_y + 150,
anchor_x='center',
anchor_y='center', color=arcade.csscolor.WHITE, font_size=32,
font_name='fonts/RobotoMono-Regular.ttf')
game_over_text = 'You Couldn\'t Get More Coins Than You Did On The Bar-Round!'
self.game_over_text2 = arcade.draw_text(game_over_text, self.screen_center_x, self.screen_center_y + 100,
anchor_x='center',
anchor_y='center', color=arcade.csscolor.WHITE, font_size=32,
font_name='fonts/RobotoMono-Regular.ttf')
restart_text = 'Restart'
self.restart_button = arcade.draw_text(restart_text, self.screen_center_x,
self.screen_center_y,
anchor_x='center', anchor_y='center',
color=arcade.csscolor.WHITE, font_size=64,
font_name='fonts/RobotoMono-Regular.ttf')
self.old_screen_center_x = self.screen_center_x
self.old_screen_center_y = self.screen_center_y
if self.draw_restart_button_hover:
if self.clicking:
arcade.draw_rectangle_filled(self.screen_center_x, self.screen_center_y, self.restart_button.width + 100, self.restart_button.height + 50, self.click_color)
elif self.hovering:
arcade.draw_rectangle_filled(self.screen_center_x, self.screen_center_y, self.restart_button.width + 100, self.restart_button.height + 50, self.hover_color)
self.play_bottom = self.restart_button.bottom
self.play_left = self.restart_button.left
self.game_over_text.draw()
self.game_over_text2.draw()
self.restart_button.draw()
def main(gm=False):
if not gm:
window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, 'Help', resizable=True)
window.show_view(GameOver())
arcade.run()
if __name__ == "__main__":
main()