-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoor.py
62 lines (50 loc) · 2.08 KB
/
Door.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
#Door.py
import pygame
door_img = pygame.image.load("Assets/Door_Sprite.png")
class Door:
def __init__(self, midbottom, exit):
self.currentSprite = 0
self.lastTicks = 0
# self.image = door_img
self.load_images()
self.image = self.opennning[0]
self.center = ( midbottom[0], midbottom[1] - (self.image.get_height()/2) )
self.rect = self.image.get_rect()
self.rect.center = self.center
self.exit = exit
self.entrance = not exit
self.unlocked = False
#triggers next level load
def get_images(self, a, b, wid, hei):
sprite = pygame.image.load('Assets/Door_Sprite.png').convert()
getimage = pygame.Surface((wid,hei))
getimage.blit(sprite,(0,0),(a,b,wid,hei))
getimage = pygame.transform.scale(getimage,(wid//6, hei//6))
return getimage
def load_images(self):
self.opennning = [self.get_images(20,20,413,333),self.get_images(20,373,408,326),self.get_images(453,369,410,327),self.get_images(453,20,410,329)]
for pic in self.opennning:
pic.set_colorkey((0,0,0))
#triggers next level load
def win(self, player):
if(self.exit and player.rect.collidepoint( self.center ) and self.unlocked):
return True
#unlocks the door
def unlock(self):
if not self.unlocked:
self.unlocked = True
#open door animation/sound
pygame.mixer.music.load('Audio/Door.ogg')
pygame.mixer.music.set_volume(1)
pygame.mixer.music.play()
self.doorMotion()
def doorMotion(self):
nowTicks = pygame.time.get_ticks()
if self.currentSprite < 3:
if nowTicks - self.lastTicks > 300:
self.lastTicks = nowTicks
self.currentSprite = self.currentSprite + 1
#bottom = self.rect.bottom
self.image = self.opennning[self.currentSprite]
#self.rect = self.image.get_rect()
#self.rect.bottom = bottom