-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.py
54 lines (40 loc) · 2 KB
/
tile.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
import pygame
class Tile(pygame.sprite.Sprite):
def __init__(self, game, pos, groups, surf):
super().__init__(groups)
self.game = game
self.image = surf
self.image = pygame.transform.scale(self.image, (self.game.TILESIZE, self.game.TILESIZE))
self.rect = self.image.get_rect(topleft = pos)
self.hitbox = self.rect.inflate(-8, -8)
class Ramp(pygame.sprite.Sprite):
def __init__(self, game, pos, groups, surf):
super().__init__(groups)
self.game = game
self.image = surf
self.image = pygame.transform.scale(self.image, (self.game.TILESIZE, self.game.TILESIZE))
self.rect = self.image.get_rect(topleft = pos)
self.hitbox = self.rect.inflate(-26, -26) # ideal amount to stop player 'jumping' too much when hitting the first ramp on the edge - do not change
class Stairs(pygame.sprite.Sprite):
def __init__(self, game, zone, pos, groups, surf):
super().__init__(groups)
self.game = game
self.zone = zone
self.image = surf
self.image = pygame.transform.scale(self.image, (self.game.TILESIZE, self.game.TILESIZE))
self.rect = self.image.get_rect(topleft = pos)
self.hitbox = self.rect.inflate(-8, -8)
def collide_stairs(self):
if pygame.sprite.spritecollide(self.zone.player, self.zone.stairs_right_up_sprites, False):
self.zone.player.on_stairs_right_up = True
elif pygame.sprite.spritecollide(self.zone.player, self.zone.stairs_right_down_sprites, False):
self.zone.player.on_stairs_right_down = True
elif pygame.sprite.spritecollide(self.zone.player, self.zone.stairs_left_down_sprites, False):
self.zone.player.on_stairs_left_down = True
elif pygame.sprite.spritecollide(self.zone.player, self.zone.stairs_left_up_sprites, False):
self.zone.player.on_stairs_left_up = True
else:
self.zone.player.on_stairs_left_up, self.zone.player.on_stairs_right_up, self.zone.player.on_stairs_right_down,\
self.zone.player.on_stairs_left_down = False, False, False, False
# def update(self):
# self.collide_stairs()