/
Main.py
191 lines (163 loc) · 5.96 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
191
import random
import json
import os
from pico2d import *
import FrameWork
import Title
name = "MainState"
gunner = None
grass = None
font = None
#class Bullet:
class Grass:
def __init__(self):
self.image = load_image('Home.bmp')
def draw(self):
self.image.draw(400, 300)
class Gunner:
image = None #이미지를 배열로 해서 만들면 LEFT RIGHT다 할 수 있지 않을까image[2]이렇게
RIGHT_STAND1 , RIGHT_STAND2 , RIGHT_DOUBLE_SHOT , RIGHT_DOWN_SHOT , RIGHT_WALK , RIGHT_JUMP1 , RIGHT_JUMP\
, RIGHT_SPEED_SHOT , RIGHT_SLIDING , RIGHT_DAMAGE , RIGHT_POWERGUN\
,RIGHTUP_POWERGUN , RIGHT_KICK , RIGHT_WHEEL_SHOT , RIGHT_TURN_SHOT\
= 15 , 14 , 13 , 12 , 11 , 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1
#생각으로는 그냥 RIGHT_RUN같은거 말고 WALK, RUN이런거로 구분해서 그 안에서 나누는 것으로 하는 것이 나을 수도
PLAYER_RIGHT , PLAYER_LEFT , PLAYER_UP , PLAYER_DOWN = 0 , 1 , 2 , 3
"""
def handle_left_run(self):
self.x -= self.speed
self.run_frames += 1
if self.x < 0:
self.state = self.RIGHT_RUN
self.x = 0
if self.run_frames == 100:
self.state = self.LEFT_STAND
self.stand_frames = 0
pass # fill here
def handle_left_stand(self):
self.stand_frames += 1
if self.stand_frames == 50:
self.state = self.RIGHT_STAND1
self.run_frames = 0
pass # fill here
def handle_right_run(self):
self.x += self.speed
self.run_frames += 1
if self.x > 800:
self.state = self.LEFT_RUN
self.x = 800
if self.run_frames == 100:
self.state = self.RIGHT_STAND
self.stand_frames = 0
pass # fill here
"""
def handle_right_stand1(self):
#self.stand_frames += 1
#if self.stand_frames == 50:
#self.state = self.RIGHT_WORK
#self.run_frames = 0
pass # fill here
def handle_right_walk(self): #handle_up_walk를 추가하면 될 거 같다. 4방향이 일단 있어야 될거 같다
if self.direction == self.PLAYER_RIGHT:
self.x += self.speed
elif self.direction == self.PLAYER_UP:
self.y += self.speed
#self.stand_frames += 1
#if self.stand_frames == 50:
# self.state = self.RIGHT_WORK
# self.run_frames = 0
pass
#fill here
handle_state = {
#LEFT_RUN : handle_left_run,
#RIGHT_RUN : handle_right_run,
#LEFT_STAND : handle_left_stand,
RIGHT_WALK : handle_right_walk,
RIGHT_STAND1 : handle_right_stand1,
}
def update(self):
self.ModuleFrame = self.endframe - self.startframe
self.frame = (self.frame + 1) % self.ModuleFrame
self.FinalFrame = self.frame + self.startframe #프레임을 시작위치로 이동후 연산
self.handle_state[self.state](self)
pass # fill here
def __init__(self):
self.x, self.y = random.randint(100, 700), 90
self.frame = random.randint(0, 13)
self.endframe = 11 #프레임 끝 위치가 달라서 끝 프레임을 넣음
self.startframe = 0 #프레임 시작위치가 달라서 시작 프레임을 넣음
self.FinalFrame = 0 #마지막 스프라이트는 이것으롣 돌린다
self.ModuleFrame = 0 #돌려아 하는 스프라이트가 달라서 나눔
self.state = self.RIGHT_STAND1
self.direction = 0
self.speed = 7
if Gunner.image == None:
Gunner.image = load_image('Player/RPlayer.png')
#Gunner.image = load_image('Player/LPlayer.bmp')
def draw(self):
self.image.clip_draw(self.FinalFrame * 271, self.state * 237, 271, 237, self.x, self.y)
delay(0.1)
def enter():
global gunner , grass
gunner = Gunner()
grass = Grass()
pass
def exit():
global gunner , grass
del(gunner)
del(grass)
pass
def pause():
pass
def resume():
pass
def handle_events():
global gunner
events = get_events()
for event in events:
if event.type == SDL_QUIT:
FrameWork.quit()
elif event.type == SDL_KEYDOWN and event.key == SDLK_ESCAPE:
FrameWork.change_state(Title)
elif event.type == SDL_KEYDOWN and event.key == SDLK_RIGHT:
if gunner.state != gunner.RIGHT_WALK:
gunner.direction = gunner.PLAYER_RIGHT
gunner.state = gunner.RIGHT_WALK
gunner.endframe = 10
gunner.startframe = 3
elif event.type == SDL_KEYDOWN and event.key == SDLK_UP:
if gunner.state != gunner.RIGHT_WALK:
gunner.direction = gunner.PLAYER_UP
gunner.state = gunner.RIGHT_WALK
gunner.endframe = 10
gunner.startframe = 3
elif event.type == SDL_KEYUP and event.key == SDLK_RIGHT:
if gunner.state != gunner.RIGHT_STAND1:
gunner.state = gunner.RIGHT_STAND1
gunner.endframe = 11
gunner.startframe = 0
elif event.type == SDL_KEYUP and event.key == SDLK_UP:
if gunner.state != gunner.RIGHT_STAND1:
gunner.state = gunner.RIGHT_STAND1
gunner.endframe = 11
gunner.startframe = 0
"""
elif event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
if gunner.state == gunner.LEFT_RUN:
gunner.state = gunner.RIGHT_RUN
elif gunner.state == gunner.RIGHT_RUN:
gunner.state = gunner.LEFT_RUN
elif gunner.state == gunner.RIGHT_STAND:
gunner.state = gunner.RIGHT_RUN
elif gunner.state == gunner.LEFT_STAND:
gunner.state = gunner.LEFT_RUN
"""
pass
def update():
gunner.update()
pass
def draw():
clear_canvas()
grass.draw()
gunner.draw()
update_canvas()
pass