-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmainmenu.py
More file actions
75 lines (61 loc) · 2.61 KB
/
mainmenu.py
File metadata and controls
75 lines (61 loc) · 2.61 KB
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
__author__ = 'marble_xu'
import pygame as pg
from .. import tool
from .. import constants as c
# 게임 처음 들어가고 난 뒤에 나오는 메뉴
# 각종 이미지, 스프라이트 정의
class Menu(tool.State):
def __init__(self):
tool.State.__init__(self)
def startup(self, current_time, persist):
self.next = c.LEVEL
self.persist = persist
self.game_info = persist
# 뒷배경과 설정 표시
self.setupBackground()
self.setupOption()
def setupBackground(self):
frame_rect = [80, 0, 800, 600]
# 메뉴 이미지
# 상수 MAIN_MENU_IMAGE
self.bg_image = tool.get_image(tool.GFX[c.MAIN_MENU_IMAGE], *frame_rect)
self.bg_rect = self.bg_image.get_rect()
self.bg_rect.x = 0
self.bg_rect.y = 0
def setupOption(self):
self.option_frames = []
frame_names = [c.OPTION_ADVENTURE + '_0', c.OPTION_ADVENTURE + '_1']
frame_rect = [0, 0, 165, 77]
for name in frame_names:
self.option_frames.append(tool.get_image(tool.GFX[name], *frame_rect, c.BLACK, 1.7))
self.option_frame_index = 0
self.option_image = self.option_frames[self.option_frame_index]
self.option_rect = self.option_image.get_rect()
self.option_rect.x = 435
self.option_rect.y = 75
self.option_start = 0
self.option_timer = 0
self.option_clicked = False
def checkOptionClick(self, mouse_pos):
x, y = mouse_pos
if(x >= self.option_rect.x and x <= self.option_rect.right and
y >= self.option_rect.y and y <= self.option_rect.bottom):
self.option_clicked = True
self.option_timer = self.option_start = self.current_time
return False
def update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_time
if not self.option_clicked:
if mouse_pos:
self.checkOptionClick(mouse_pos)
else:
if(self.current_time - self.option_timer) > 200:
self.option_frame_index += 1
if self.option_frame_index >= 2:
self.option_frame_index = 0
self.option_timer = self.current_time
self.option_image = self.option_frames[self.option_frame_index]
if(self.current_time - self.option_start) > 1300:
self.done = True
surface.blit(self.bg_image, self.bg_rect)
surface.blit(self.option_image, self.option_rect)