-
Notifications
You must be signed in to change notification settings - Fork 1
/
stage5.py
81 lines (64 loc) · 2.75 KB
/
stage5.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
# crowd surfing game
import pygame
import pyganim
import random
from .stage import Stage, Text
class Stage5(Stage):
def __init__(self, resolution):
super().__init__(resolution)
self.texts = [Text("CROWD SURFING", (255, 255, 255), self._center_text)]
self.bg = pygame.image.load("images/2013_Woodstock_144_crowd_surfing.jpg")
self.crowd = pyganim.PygAnimation([("images/button1.png", 10),
("images/button 2.png", 10)])
self.player = pyganim.PygAnimation([("images/surfer.png", 10),])
rects = [
[64 * 1, 0, 64, 64],
[64 * 2, 0, 64, 64],
[64 * 3, 0, 64, 64],
[64 * 0, 0, 64, 64],
]
exit = pyganim.getImagesFromSpriteSheet("images/door2.png", rects=rects)
frames = list(zip(exit, [1000, 400, 400, 400]))
self.exit = pyganim.PygAnimation(frames)
self.exit.scale2x()
self.crowd.play()
self.player.play()
self.exit.play()
self.reset()
def reset(self):
self.crowds = []
x = 100
for i in range(100):
crowd = self.crowd.getCopy()
crowd.play()
pos = (x, random.randint(100, self.resolution[1] - 100))
if i % 2:
x += random.randint(0, 40)
self.crowds.append((crowd, pos))
self.exit_pos = (700, random.randint(100, 350))
self.player_pos = [100, random.randint(100, 450)]
def update(self, input, tick):
speed = 30
if input.right: self.player_pos[0] += speed
if input.left: self.player_pos[0] -= speed
if input.up: self.player_pos[1] -= speed
if input.down: self.player_pos[1] += speed
# if input.right_hold: self.player_pos[0] += speed
# if input.left_hold: self.player_pos[0] -= speed
# if input.up_hold: self.player_pos[1] -= speed
# if input.down_hold: self.player_pos[1] += speed
self.player_pos[0] += random.randint(-2, 1)
self.player_pos[1] += random.randint(-2, 1)
self.player_pos[0] = max(130, min(self.player_pos[0], self.exit_pos[0] + 100))
self.player_pos[1] = max(130, min(self.player_pos[1], self.exit_pos[1] + 300))
player = self.player.getRect().move(self.player_pos)
exit = self.exit.getRect().move(self.exit_pos)
if player.colliderect(exit):
return True
def draw(self, screen):
screen.blit(self.bg, [0, -150])
super().draw(screen)
# for crowd, pos in self.crowds:
# crowd.blit(screen, pos)
self.exit.blit(screen, self.exit_pos)
self.player.blit(screen, self.player_pos)