forked from Velesey/SuperMarioBoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks.py
64 lines (52 loc) · 2.29 KB
/
blocks.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pygame import *
import os
import pyganim
PLATFORM_WIDTH = 32
PLATFORM_HEIGHT = 32
PLATFORM_COLOR = "#000000"
ICON_DIR = os.path.dirname(__file__) # Полный путь к каталогу с файлами
ANIMATION_BLOCKTELEPORT = [
('%s/blocks/portal2.png' % ICON_DIR),
('%s/blocks/portal1.png' % ICON_DIR)]
ANIMATION_PRINCESS = [
('%s/blocks/princess_l.png' % ICON_DIR),
('%s/blocks/princess_r.png' % ICON_DIR)]
class Platform(sprite.Sprite):
def __init__(self, x, y):
sprite.Sprite.__init__(self)
self.image = Surface((PLATFORM_WIDTH, PLATFORM_HEIGHT))
self.image.fill(Color(PLATFORM_COLOR))
self.image = image.load("%s/blocks/platform.png" % ICON_DIR)
self.image.set_colorkey(Color(PLATFORM_COLOR))
self.rect = Rect(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT)
class BlockDie(Platform):
def __init__(self, x, y):
Platform.__init__(self, x, y)
self.image = image.load("%s/blocks/dieBlock.png" % ICON_DIR)
self.rect = Rect(x + PLATFORM_WIDTH / 4, y + PLATFORM_HEIGHT / 4, PLATFORM_WIDTH - PLATFORM_WIDTH / 2, PLATFORM_HEIGHT - PLATFORM_HEIGHT / 2)
class BlockTeleport(Platform):
def __init__(self, x, y, goX,goY):
Platform.__init__(self, x, y)
self.goX = goX # координаты назначения перемещения
self.goY = goY # координаты назначения перемещения
boltAnim = []
for anim in ANIMATION_BLOCKTELEPORT:
boltAnim.append((anim, 0.3))
self.boltAnim = pyganim.PygAnimation(boltAnim)
self.boltAnim.play()
def update(self):
self.image.fill(Color(PLATFORM_COLOR))
self.boltAnim.blit(self.image, (0, 0))
class Princess(Platform):
def __init__(self, x, y):
Platform.__init__(self, x,y)
boltAnim = []
for anim in ANIMATION_PRINCESS:
boltAnim.append((anim, 0.8))
self.boltAnim = pyganim.PygAnimation(boltAnim)
self.boltAnim.play()
def update(self):
self.image.fill(Color(PLATFORM_COLOR))
self.boltAnim.blit(self.image, (0, 0))