-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollout_2015180042최현욱.py
224 lines (160 loc) · 5.54 KB
/
rollout_2015180042최현욱.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
from pico2d import *
import Uishowcase
from wall import wall
from Weapon import Disk, WeapoN
import math
from hitdetection import collide
#class definition here{
#플레이어 무빙.
class player:
def __init__(self):
self.jumpable=True#prevent multiple jump
self.x=0
self.y=107#좌표
self.watch=1#looking direction
self.step=0#0=stop,1=jumpup,2=jumpdown
self.jmax=17#jumpmaxheight
self.jdelt=17#jump
self.cnt=0#counting
self.tick=[0,0,0,0,0,0,0,0]#타격 판정. 머리와 몸통 순서로 좌상우하
self.framex,self.framey=0,0#프레임.
self.movecheck=False#키로 인한 좌표변화의 표현
self.img=load_image('movingbot.png')#로드할 이미지
def get_bb(self):
return self.x-50,self.y-62,self.x+49,self.y+61
def update(self):
global x,y,watch
x=self.x
y=self.y
watch=self.watch
if self.movecheck==True:#이동중 애니메이션 표시
if self.watch==1:#왼쪽 볼 시
self.framex=0
self.framey += 1
if self.framey == 8:
self.framey -=1
self.tick = [X-45,Y+44,X+30,Y + 9,X-21,Y+6,X+21,Y - 57]
self.x-=10
elif self.watch==2:
self.framex=1
self.framey += 1
if self.framey == 8:
self.framey -= 1
self.tick = [X-30,Y+44,X+45, Y + 30,X-21,Y+6,X+21,Y - 57]
self.x+=10
elif self.movecheck==False:#정지중 애니메이션 표시
if self.watch==1:
self.framex=0
self.framey=1
self.tick=[X-22,Y+61,X+48,Y+26,X-3,Y+21,X+33,Y-53]
else:
self.framex=1
self.framey = 0
self.tick=[X-48,Y+61,X+22,Y+26,X-33,Y+21,X+3,Y-53]
if self.step==1:
if self.jdelt<=10:
self.step=2
self.walk=False
else:
if self.cnt%5 == 0:
self.jdelt=self.jdelt/5*4
self.y+=self.jdelt
self.cnt += 1
if self.step==2:
if self.jdelt>=self.jmax:
self.jdelt=self.jmax
self.y -= self.jdelt
else:
if self.cnt%5 == 0:
self.jdelt = self.jdelt * 2
self.y -= self.jdelt
self.cnt += 1
if self.y-57<=50:#오브젝트 충돌시도 동일처리.추후 낙하판정 들어올시 제거 계획.
self.y=107
self.step=0
self.jumpable=True
def draw(self):
self.img.clip_draw(self.framex*100,1116-(124*(self.framey+1)),100,124,self.x,self.y)
#이벤트 핸들러
def handle_events():
global running
global x,y
global mx, my # 마우스좌표
events = get_events()
for event in events:
if (event.type) == (SDL_MOUSEBUTTONDOWN):
if event.button == SDL_BUTTON_LEFT:
if d.ison == False:
d.x = event.x
d.y = 600 - event.y
d.ison = True
if event.button == SDL_BUTTON_RIGHT:
if d.ison == True and d.blast == False:
if event.x <= d.x + 10 and event.x >= d.x - 10:
if (600 - event.y) <= d.y + 10 and (600 - event.y) >= d.y - 10:
d.blast = True
if event.type == SDL_MOUSEMOTION:
wp.degree = math.atan2((600 - event.y) - 100, event.x - 100)
if event.type == SDL_QUIT:
running = False
elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
running = False
elif event.type==SDL_KEYDOWN:
if event.key==SDLK_a:
pl.watch=1
pl.framey=1
pl.movecheck = True
elif event.key==SDLK_d:
pl.watch=2
pl.framey=1
pl.movecheck = True
elif event.type==SDL_KEYUP:
if event.key==SDLK_a:
pl.watch=2
pl.framey=1
if event.key==SDLK_d:
pl.watch=1
pl.framey=1
if event.type==SDL_KEYDOWN and event.key==SDLK_SPACE and pl.jumpable==True:
pl.step=1
pl.jumpable=False
elif event.type==SDL_KEYUP:
if event.key==SDLK_a or event.key==SDLK_d:
pl.movecheck = False
if event.key==SDLK_SPACE:
pl.step=2
def draw(self):
self.dis.clip_draw(0, (self.kind + 1) * 21, 21, 21, self.pivx, self.pivy)
#초기화 구역
global step
global X,Y
open_canvas()
pl = player()
ui=Uishowcase.UI()
#####
wl=wall()
wp=WeapoN()
d=Disk()
running=True
#게임 루프 구간
while running:
X,Y=pl.x,pl.y
handle_events()
clear_canvas()
if d.blast==True and d.blasttime==1:
if pl.x>d.x-100 and pl.x<wl.x+100:
if pl.y>d.y-100 and pl.y<d.y+100:
pl.x+=2*(d.x-pl.x)
pl.update()
d.update()
wp.x=pl.x
wp.y=pl.y
wl.draw()
ui.draw()
pl.draw()
wp.draw()
d.draw()
update_canvas()
delay(0.01)
#종료 코드
close_canvas()