/
Menu.py
103 lines (77 loc) · 3.36 KB
/
Menu.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
import arcade
import Mapedit
import Setting
import Game
screen_w = 1280
screen_h = 720
screen_t = "Platformer"
MOVEMENT_SPEED = 8
GRAVITY = 1
player_jump_speed = 18
# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
LEFT_VIEWPORT_MARGIN = 100
RIGHT_VIEWPORT_MARGIN = 100
BOTTOM_VIEWPORT_MARGIN = 50
TOP_VIEWPORT_MARGIN = 100
# Scaling
char_scaling = 0.25
class MainView(arcade.View):
def __init__(self):
super().__init__()
self.menu_list = None
self.menu_list = None
self.mouse_list = None
self.mouse_sprite = None
self.remember_menu = 0
# 창에 마우스 보이게/안보이게 하는 기능
self.window.set_mouse_visible(False)
def setup(self):
self.menu_list = arcade.SpriteList(use_spatial_hash=True)
self.mouse_sprite = arcade.Sprite("pic/default/char.png", char_scaling)
self.menu_line(screen_w / 2, screen_h / 2 + 32 * 5, "pic/menu/start.png") # start
self.menu_line(screen_w / 2, screen_h / 2 + 32 * 2, "pic/menu/setting.png") # setting
self.menu_line(screen_w / 2, screen_h / 2 - 32 * 1, "pic/menu/mapedit.png") # map_edit
self.menu_line(screen_w / 2, screen_h / 2 - 32 * 4, "pic/menu/quit.png") # quit
self.menu_line(96, 32, "pic/menu/back.png") # back
self.mouse_list = arcade.SpriteList()
self.mouse_list.append(self.mouse_sprite)
def menu_line(self, center_x, center_y, img):
menu = arcade.Sprite(img)
menu.center_x = center_x
menu.center_y = center_y
self.menu_list.append(menu)
def on_show(self):
arcade.set_background_color(arcade.csscolor.BLACK)
arcade.set_viewport(0, screen_w - 1, 0, screen_h - 1)
def on_draw(self):
arcade.start_render()
self.menu_list.draw()
self.mouse_list.draw()
arcade.draw_text("JUMPER", screen_w / 2, screen_h / 2 + 32 * 8, arcade.color.WHITE, font_size=30,
anchor_x="center")
# 마우스로 화면 클릭시 게임화면으로 전환
def on_mouse_motion(self, x, y, dx, dy):
self.mouse_sprite.center_x = x
self.mouse_sprite.center_y = y
def on_mouse_press(self, _x, _y, button, _modifiers):
menu_hit_list = arcade.check_for_collision_with_list(self.mouse_sprite, self.menu_list)
for menu_index in menu_hit_list :
if button == arcade.MOUSE_BUTTON_LEFT :
if menu_index == self.menu_list[0]: # start
game_view = Game.GameView()
game_view.setup()
self.window.show_view(game_view)
if menu_index == self.menu_list[1]: # setting
setting_view = Setting.SettingView()
setting_view.setup()
self.window.show_view(setting_view)
if menu_index == self.menu_list[2]: # map edit
mapedit_view = Mapedit.MapeditView()
mapedit_view.setup()
self.window.show_view(mapedit_view)
if menu_index == self.menu_list[3]: # quit
arcade.close_window()
return 0
if menu_index == self.menu_list[4]: # back
return 0