Repository navigation
Expand file tree
/
Copy pathMain.py
More file actions
392 lines (353 loc) · 14.8 KB
/
Copy pathMain.py
File metadata and controls
392 lines (353 loc) · 14.8 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import pygame
import time
import ctypes
pygame.init()
user32 = ctypes.windll.user32
width, height = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
if width > 1280:
width = 1280
if height > 720:
height = 720
screen = pygame.display.set_mode((width, height), pygame.NOFRAME | pygame.FULLSCREEN, 32)
char_steps = 5
main_group = pygame.sprite.Group()
orc_group = pygame.sprite.Group()
class Sprite(pygame.sprite.Sprite):
def __init__(self, screen_pos_x, screen_pos_y, board_pos_x, board_pos_y, char_width, char_height):
super(Sprite, self).__init__()
self.screen_pos = pygame.Rect(screen_pos_x, screen_pos_y, char_width, char_height)
self.board_pos = pygame.Rect(board_pos_x, board_pos_y, char_width, char_height)
self.direction = None
@staticmethod
def image_bliting(image_loc, pos_x, pos_y, angle):
screen.blit(pygame.transform.rotate(pygame.image.load(image_loc), angle), (pos_x, pos_y))
def calc_angle(self):
if self.direction == 1:
return 0
elif self.direction == 2:
return 270
elif self.direction == 3:
return 180
else:
return 90
class main_character(Sprite):
def __init__(self, start_x, start_y):
super(main_character, self).__init__(start_x, start_y, start_x + 1000, start_y + 1000, 81, 80) # going to the father of rpg_board (pygame.Rect())
self.direction = 1
self.moving_seq = 1
self.add(main_group)
self.state = None
self.normal_image = 'Textures/Skins/Main_Char/MC_S.png'
self.now_showing = 'Textures/Skins/Main_Char/MC_S.png'
def update_normal(self):
board.blit_board()
self.image_bliting(self.normal_image, self.screen_pos.left, self.screen_pos.top, self.calc_angle())
def update(self):
board.blit_board()
keys = pygame.key.get_pressed()
if keys[pygame.K_w] or keys[pygame.K_s] or keys[pygame.K_a] or keys[pygame.K_d]:
if keys[pygame.K_w]:
board.move_up()
elif keys[pygame.K_s]:
board.move_down()
elif keys[pygame.K_a]:
board.move_left()
elif keys[pygame.K_d]:
board.move_right()
orc1.update()
orc1.blit_showing()
pygame.display.update()
else:
self.breath()
pygame.display.update()
def breath(self):
board.blit_board()
if self.state == 1:
self.image_bliting('Textures/Skins/Main_Char/Animation/B/B1.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Main_Char/Animation/B/B1.png'
self.state = 2
else:
self.image_bliting('Textures/Skins/Main_Char/Animation/B/B2.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Main_Char/Animation/B/B2.png'
self.state = 1
orc1.update()
orc1.blit_showing()
pygame.display.update()
for x in range(1000):
pygame.time.delay(1)
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
return
def walk(self, d):
if self.direction == d:
self.image_bliting('Textures\Skins\Main_Char\Animation\W\W' + str(self.moving_seq) + '.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures\Skins\Main_Char\Animation\W\W' + str(self.moving_seq) + '.png'
else:
self.moving_seq = 1
self.direction = d
self.image_bliting('Textures\Skins\Main_Char\Animation\W\W1.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures\Skins\Main_Char\Animation\W\W1.png'
self.moving_seq = self.moving_seq + 1
if self.moving_seq == 35:
self.moving_seq = 1
for x in range(20):
pygame.time.delay(1)
for event in pygame.event.get():
if event.type == pygame.KEYUP:
self.update_normal()
return
class Orcs(Sprite):
def __init__(self):
super(Orcs, self).__init__(0, 0, 1600, 2000, 87, 64)
self.direction = 1
self.moving_seq = 1
self.state = 1
self.add(orc_group)
self.now_showing = 'Textures/Skins/Orcs/1/Animation/B/B1.png'
self.start = -1.0
def blit_showing(self):
self.image_bliting(self.now_showing, self.screen_pos.left, self.screen_pos.top, self.calc_angle())
def visible(self):
if self.board_pos.colliderect(board.shown):
return True
else:
return False
def calc_board_pos(self):
self.screen_pos.left = int(self.board_pos.left) - int(board.shown.left)
self.screen_pos.top = int(self.board_pos.top) - int(board.shown.top)
def update(self):
if self.visible():
self.calc_board_pos()
# self.image_bliting('Textures/Skins/Orcs/1/Orc_S1.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.breath()
def walk(self, d):
if self.direction == d:
self.image_bliting('Textures/Skins/Orcs/1/W' + str(self.moving_seq) + '.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Orcs/1/W' + str(self.moving_seq) + '.png'
else:
self.moving_seq = 1
self.direction = d
self.image_bliting('Textures/Skins/Orcs/1/W/W1', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Orcs/1/W1.png'
if self.moving_seq == 35:
self.moving_seq = 1
pygame.time.delay(20)
def breath(self):
if self.state == 1:
if self.start == -1.0 or time.time() - self.start > 1:
print 'lol'
self.image_bliting('Textures/Skins/Orcs/1/Animation/B/B1.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Orcs/1/Animation/B/B1.png'
self.state = 2
self.start = time.time()
else:
if time.time() - self.start > 1:
print 'lel'
self.image_bliting('Textures/Skins/Orcs/1/Animation/B/B2.png', self.screen_pos.left, self.screen_pos.top, self.calc_angle())
self.now_showing = 'Textures/Skins/Orcs/1/Animation/B/B2.png'
self.state = 1
self.start = time.time()
class Barriers(object):
def __init__(self):
self.walls_arr = []
self.misc_arr = []
self.enemy_arr = []
self.wall_arr_init()
self.misc_arr_init()
def wall_arr_init(self):
# walls adding, numbers according to the wall mapping picture
# wall 1
self.walls_arr.append(pygame.Rect(1000, 1180, 129, 2719))
# wall 2
self.walls_arr.append(pygame.Rect(1130, 1000, 7799, 179))
# wall 3A
self.walls_arr.append(pygame.Rect(8930, 1180, 66, 1249))
# wall 3B
self.walls_arr.append(pygame.Rect(8930, 2820, 66, 1079))
# wall 4
self.walls_arr.append(pygame.Rect(1130, 3900, 7799, 99))
# wall 5
self.walls_arr.append(pygame.Rect(5630, 1180, 89, 499))
# wall 6
self.walls_arr.append(pygame.Rect(3540, 1500, 2089, 179))
# wall 7
self.walls_arr.append(pygame.Rect(3430, 1500, 99, 499))
# wall 8
self.walls_arr.append(pygame.Rect(2630, 1180, 89, 819))
# wall 9
self.walls_arr.append(pygame.Rect(1130, 1930, 869, 89))
# wall 10
self.walls_arr.append(pygame.Rect(1820, 1180, 109, 319))
# wall 11
self.walls_arr.append(pygame.Rect(6220, 1180, 99, 889))
# wall 12
self.walls_arr.append(pygame.Rect(4110, 1930, 2109, 139))
# wall 13
self.walls_arr.append(pygame.Rect(7220, 1180, 99, 889))
# wall 14
self.walls_arr.append(pygame.Rect(7720, 1431, 1209, 138))
# wall 15
self.walls_arr.append(pygame.Rect(8000, 1820, 900, 149))
# wall 16
self.walls_arr.append(pygame.Rect(8000, 1970, 129, 99))
# wall 17
self.walls_arr.append(pygame.Rect(8220, 2320, 709, 109))
# wall 18
self.walls_arr.append(pygame.Rect(8220, 2820, 709, 149))
# wall 19
self.walls_arr.append(pygame.Rect(7820, 3220, 109, 679))
# wall 20
self.walls_arr.append(pygame.Rect(5320, 3220, 1998, 159))
# wall 21
self.walls_arr.append(pygame.Rect(5320, 3380, 109, 519))
# wall 22
self.walls_arr.append(pygame.Rect(4630, 3220, 109, 679))
# wall 23
self.walls_arr.append(pygame.Rect(3610, 3220, 109, 679))
# wall 24
self.walls_arr.append(pygame.Rect(2320, 3220, 899, 159))
# wall 25
self.walls_arr.append(pygame.Rect(2320, 3380, 109, 519))
# wall 26
self.walls_arr.append(pygame.Rect(1130, 3220, 869, 99))
# wall 27: Door
self.walls_arr.append(pygame.Rect(8930, 2430, 66, 389))
def misc_arr_init(self):
# misc 1: Rock
self.misc_arr.append(pygame.Rect(1130, 1179, 200, 181))
# misc 2: Rock
self.misc_arr.append(pygame.Rect(1130, 1369, 60, 91))
# misc 3: Rock
self.misc_arr.append(pygame.Rect(1130, 2299, 100, 291))
# misc 4: Rock
self.misc_arr.append(pygame.Rect(1130, 2989, 100, 191))
# misc 5: Rock
self.misc_arr.append(pygame.Rect(2079, 3719, 240, 180))
# misc 6: Rock
self.misc_arr.append(pygame.Rect(3359, 3759, 250, 140))
# misc 7: Rock
self.misc_arr.append(pygame.Rect(3720, 3500, 190, 399))
# misc 8: Rock
self.misc_arr.append(pygame.Rect(5430, 3749, 130, 150))
# misc 9: Rock
self.misc_arr.append(pygame.Rect(7519, 3629, 271, 182))
# misc 10: Rock
self.misc_arr.append(pygame.Rect(7369, 3779, 450, 120))
# misc 11: Rock
self.misc_arr.append(pygame.Rect(7930, 3819, 30, 80))
# misc 12: Rock
self.misc_arr.append(pygame.Rect(8660, 3709, 269, 190))
# misc 13: Rock
self.misc_arr.append(pygame.Rect(8749, 1570, 180, 140))
# misc 14: Rock
self.misc_arr.append(pygame.Rect(8609, 1570, 61, 40))
# misc 15: Rock
self.misc_arr.append(pygame.Rect(7049, 1180, 121, 140))
# misc 16: Rock
self.misc_arr.append(pygame.Rect(6099, 2149, 141, 101))
# misc 17: Rock
self.misc_arr.append(pygame.Rect(6249, 2089, 141, 101))
# misc 18: Rock
self.misc_arr.append(pygame.Rect(4029, 2079, 161, 81))
# misc 19: Rock
self.misc_arr.append(pygame.Rect(4249, 2079, 121, 71))
# misc 20: Rock
self.misc_arr.append(pygame.Rect(2559, 2789, 141, 111))
# misc 21: Rock
self.misc_arr.append(pygame.Rect(2709, 2649, 261, 171))
# misc 22: Rock
self.misc_arr.append(pygame.Rect(6609, 3059, 431, 121))
# misc 23: Rock + Webs
self.misc_arr.append(pygame.Rect(2720, 1179, 80, 141))
# misc 24: Statue
self.misc_arr.append(pygame.Rect(4409, 2460, 701, 340))
def can_pass_up(self, sprite, steps):
for x in xrange(steps):
sprite.board_pos.top -= 1
if sprite.board_pos.collidelist(self.walls_arr) != -1 or sprite.board_pos.collidelist(self.misc_arr) != -1:
sprite.board_pos.top += 1
return x
return steps
def can_pass_down(self, sprite, steps):
for x in xrange(steps):
sprite.board_pos.top += 1
if sprite.board_pos.collidelist(self.walls_arr) != -1 or sprite.board_pos.collidelist(self.misc_arr) != -1:
sprite.board_pos.top -= 1
return x
return steps
def can_pass_right(self, sprite, steps):
for x in xrange(steps):
sprite.board_pos.left += 1
if sprite.board_pos.collidelist(self.walls_arr) != -1 or sprite.board_pos.collidelist(self.misc_arr) != -1:
sprite.board_pos.left -= 1
return x
return steps
def can_pass_left(self, sprite, steps):
for x in xrange(steps):
sprite.board_pos.left -= 1
if sprite.board_pos.collidelist(self.walls_arr) != -1 or sprite.board_pos.collidelist(self.misc_arr) != -1:
sprite.board_pos.left += 1
return x
return steps
class rpg_board(object):
def __init__(self, start_x=0, start_y=0):
self.shown = pygame.Rect(start_x, start_y, start_x + width, start_y + height)
self.image = pygame.image.load('Textures/Board/3/Board3.png').convert()
self.image_width = self.image.get_width()
self.image_height = self.image.get_height()
screen.blit(self.image, (0, 0), area=(self.shown.left, self.shown.top, self.shown.width, self.shown.height))
pygame.display.update()
self.Barriers = Barriers()
self.char = main_character(width / 2, height / 2)
def blit_board(self):
screen.fill((255, 255, 255))
screen.blit(self.image, (0, 0), area=(self.shown.left, self.shown.top, self.shown.width, self.shown.height))
def move_up(self):
real_step = self.Barriers.can_pass_up(self.char, char_steps)
if real_step == 0:
self.char.direction = 1
self.char.breath()
return
self.shown.top = self.shown.top - real_step
self.blit_board()
self.char.walk(1)
def move_down(self):
real_step = self.Barriers.can_pass_down(self.char, char_steps)
if real_step == 0:
self.char.direction = 3
self.char.breath()
return
self.shown.top = self.shown.top + real_step
self.blit_board()
self.char.walk(3)
def move_left(self):
real_step = self.Barriers.can_pass_left(self.char, char_steps)
if real_step == 0:
self.char.direction = 4
self.char.breath()
return
self.shown.left = self.shown.left - real_step
self.blit_board()
self.char.walk(4)
def move_right(self):
real_step = self.Barriers.can_pass_right(self.char, char_steps)
if real_step == 0:
self.char.direction = 2
self.char.breath()
return
self.shown.left = self.shown.left + real_step
self.blit_board()
self.char.walk(2)
board = rpg_board(1000, 1000)
board.char.update_normal()
orc1 = Orcs()
finish = False
while not finish:
for event in pygame.event.get():
if event.type == pygame.QUIT:
finish = True
board.char.update()
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE]:
finish = True
pygame.quit()