-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
147 lines (117 loc) · 4.24 KB
/
init.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
137
138
139
140
141
142
143
144
145
146
147
from entity import Player
from settings import settings
import asset
import pickle
from pygame.locals import *
import pygame
HIGHSCORE = 0
def load_data():
global HIGHSCORE
origin = {}
try:
with open('score.dat', 'rb') as file:
origin = pickle.load(file)
except FileNotFoundError as e:
with open('score.dat', 'wb') as file:
pickle.dump({}, file)
if type(origin) != dict:
with open('score.dat', 'wb') as file:
pickle.dump({}, file)
if "score" in origin:
HIGHSCORE = origin["score"]["highest"]
else:
with open('score.dat', 'wb') as file:
pickle.dump({
"score": {
"highest": 0
}
}, file)
def save_data(record):
global HIGHSCORE
if HIGHSCORE < record:
HIGHSCORE = record
with open("score.dat", "wb") as file:
pickle.dump({
"score": {
"highest": HIGHSCORE
}
}, file)
load_data()
# 기본 설정 (수정 금지)
screen_width = 480
screen_height = 640
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_icon(pygame.image.load(asset.entity["poop"]))
pygame.display.set_caption("Avoid!")
clock = pygame.time.Clock()
# 기본 배경
background = pygame.image.load(asset.background["default"][0])
setting_font = pygame.font.Font(asset.font["NeoDunggeunmo"], 22)
# 음악 재생
class Sound:
def __init__(self):
self.soundtrack = asset.sound["rollin_at_5"]
self.isStart = False
self.isToned = False
self.theme = settings["background_theme"].main
self.load = pygame.mixer.music.load(self.soundtrack[0])
def setMusicTheme(self):
if settings["background_theme"].main == "LIGHT":
self.theme = settings["background_theme"].main
self.soundtrack = asset.sound["rollin_at_5"]
self.load = pygame.mixer.music.load(self.soundtrack[0])
elif settings["background_theme"].main == "DARK":
self.theme = settings["background_theme"].main
self.soundtrack = asset.sound["raving_energy"]
self.load = pygame.mixer.music.load(self.soundtrack[0])
def play(self):
if settings["use_sound"].main:
pygame.mixer.music.play(1000, 0.0)
if (settings["volume"].main == 0):
pygame.mixer.music.set_volume(0)
else:
pygame.mixer.music.set_volume(settings["volume"].main / 100)
self.isStart = True
def stop(self):
if settings["use_sound"].main:
pygame.mixer.music.stop()
self.isStart = False
def toneUp(self):
self.load = pygame.mixer.music.load(self.soundtrack[1])
self.isToned = True
def reset(self):
self.load = pygame.mixer.music.load(self.soundtrack[0])
self.isStart = False
self.isToned = False
def loadBackground(backType, filter=None) -> list:
returnValue = []
if settings["background_theme"].main == "LIGHT":
if settings["background_solid"].main:
returnValue.append(pygame.image.load(asset.background["solid"][0]))
else:
returnValue.append(pygame.image.load(backType[0]))
elif settings["background_theme"].main == "DARK":
if settings["background_solid"].main:
returnValue.append(pygame.image.load(asset.background["solid"][1]))
else:
returnValue.append(pygame.image.load(backType[1]))
if filter != None:
if settings["language"].main == "En-US":
returnValue.append(pygame.image.load(filter[0]))
elif settings["language"].main == "Ko-KR":
returnValue.append(pygame.image.load(filter[1]))
return tuple(returnValue)
# 만약 게임오버라면,
isGameOver = False
# 구역
areaList = ["title", "setting", "info", "start", "end"] # 구역 목록
area = areaList[0] # 현재 구역
# 인스턴스
# 플레이어 메인 인스턴스
player = Player(asset.entity["sprite"], screen)
player2 = Player(asset.entity["sprite2"], screen)
sound = Sound() # 배경 음악
settings["mode"].isSelect(True)
# 이벤트 루프
running = True
isPause = False