-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.py
37 lines (33 loc) · 1.42 KB
/
platform.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
import pygame as pg
import random
from image import Image
from rock import Rock
class Platform(pg.sprite.Sprite):
_sprite_positions = [(0, 2), (0, 24), (0, 26), (1, 18), (1, 29), (2, 2), (2, 7), (2, 17)]
def __init__(self, game, width, height, x, y, border):
super().__init__()
self.game = game
self.visible = False if x > 700 else True
if self.visible:
self.game.block_list.add(self)
self.game.sprites_list.add(self)
self.width = width
self.height = height
self.sprite_pos = self._sprite_positions[random.randint(0, len(self._sprite_positions) - 1)]
self.image = self.game.ground_sprite.subsurface(
(32 + 160 * self.sprite_pos[0], 32 * self.sprite_pos[1], 32, 32))
self.image = pg.transform.flip(self.image, False, True)
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.mask = pg.mask.from_surface(self.image)
self.rock = Rock(self.game, x, y, border)
self.over_image = Image(self.game,
self.game.ground_sprite.subsurface(
(64 + 160 * self.sprite_pos[0], 32 * self.sprite_pos[1], 32, 32)), x,
y - 20)
def update(self):
if not self.visible:
if self.rect.x < 700:
self.game.block_list.add(self)
self.visible = True