-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
190 lines (171 loc) · 5.89 KB
/
main.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import sys
from time import sleep
import pygame
from pygame.locals import *
from charactor import circle
from charactor import spaceCircle
tan_bool = False
space_bool = False
while True:
moveType = int(input('''
완전탄성충돌 : 1
포물선 통통 : 2
무중력 시뮬 : 3
무중력 시뮬 게임 : 4
종료 : 아무 키나 입력
>>>'''))
if moveType == 1:
move = False # 'wantanchung'
tan_bool = True
break
elif moveType == 2:
move = True # 'pomul'
tan_bool = True
break
elif moveType == 3:
space_bool = True
game_play = False
break
elif moveType == 4:
space_bool = True
game_play = True
break
else:
sys.exit()
pygame.init()
FPS = 100
FramePerSec = pygame.time.Clock()
BLUE = (0, 0, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
size = (600, 400)
display_x, display_y = size
GameDisplay = pygame.display.set_mode(size)
GameDisplay.fill(WHITE)
pygame.display.set_caption("Gravity Falls")
big_font = pygame.font.SysFont("malgungothicsemilight", 60)
middle_font = pygame.font.SysFont("malgungothicsemilight", 30)
little_font = pygame.font.SysFont("malgungothicsemilight", 16)
if tan_bool:
circle.dis_x = display_x
circle.dis_y = display_y
Circle = circle.Circle(GameDisplay)
while tan_bool:
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
pygame.draw.circle(GameDisplay, BLACK, event.pos, 10)
FramePerSec.tick(FPS)
Circle.accel()
if move:
Circle.angry()
Circle.draw()
if space_bool:
spaceCircle.dis_x = display_x
spaceCircle.dis_y = display_y
spacePlayer = spaceCircle.SpaceCircle(GameDisplay)
def game_runing():
global spacePlayer, score_val
while game_run_bool:
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
elif event.key == K_LEFT:
# spacePlayer.v_x -= 0.1
spacePlayer.v_x = round(spacePlayer.v_x - 0.1, 1)
print(f'x{spacePlayer.v_x}')
elif event.key == K_RIGHT:
# spacePlayer.v_x += 0.1
spacePlayer.v_x = round(spacePlayer.v_x + 0.1, 1)
print(f'x{spacePlayer.v_x}')
elif event.key == K_UP:
# spacePlayer.v_y += 0.1
spacePlayer.v_y = round(spacePlayer.v_y - 0.1, 1)
print(f'y{spacePlayer.v_y}')
elif event.key == K_DOWN:
spacePlayer.v_y = round(spacePlayer.v_y + 0.1, 1)
print(f'y{spacePlayer.v_y}')
FramePerSec.tick(FPS)
spacePlayer.x_posMove()
spacePlayer.y_posMove()
spacePlayer.max_cheacker()
spacePlayer.draw()
if game_play:
text = little_font.render(f'x축 속도: {abs(spacePlayer.v_x)} y축 속도: {abs(spacePlayer.v_y)} out: {spacePlayer.out_count} life: {spacePlayer.life_count}', True, BLACK)
GameDisplay.blit(text, (10,0))
score_val = int((abs(spacePlayer.v_x) + abs(spacePlayer.v_y))*100+0.5)
score_txt = little_font.render(f'score : {score_val}', True, BLACK)
GameDisplay.blit(score_txt, (10,30))
spacePlayer.max_cheacker()
if spacePlayer.out_count == 2:
if spacePlayer.life_count:
return 1
else:
return 0
def life_out():
while True:
spacePlayer.life_count -= 1
font_1 = pygame.font.SysFont("malgungothicsemilight", 40)
text_out = font_1.render(f'{spacePlayer.life_count}번 남았습니다.', True, BLACK)
GameDisplay.blit(text_out, (160,110))
spacePlayer.out_count = 0
pygame.display.update()
sleep(1)
break
game_runing()
def game_over():
global spacePlayer
try:
best_file = open('bestscore.txt','r')
best_score = int(best_file.readline())
finally:
best_file.close()
if score_val > best_score: # 내 점수가 최고기록 일 떄
best_score = score_val
with open('bestscore.txt', 'w') as f:
f.write(str(best_score)) # 최고기록 작성
while True:
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
elif event.key == K_SPACE:
spacePlayer = spaceCircle.SpaceCircle(GameDisplay)
return 1
GameDisplay.fill(WHITE)
game_over_txt = big_font.render('Game Over', True, BLACK) # 최고기록 예정
best_score_txt = middle_font.render(f'bestscore: {best_score}', True, BLACK)
my_score_txt = middle_font.render(f'socre: {score_val}',True,BLACK)
play_again_txt = middle_font.render('Enter를 누르면 다시 시작합니다.',True,BLACK)
GameDisplay.blit(game_over_txt, (100,80))
GameDisplay.blit(best_score_txt, (100,160))
GameDisplay.blit(my_score_txt, (100,190))
GameDisplay.blit(play_again_txt, (80,250))
game_run_bool = True
if space_bool:
while True:
if game_runing():
life_out()
else:
if game_over():
game_runing()