-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlot.py
More file actions
52 lines (43 loc) · 1.51 KB
/
Slot.py
File metadata and controls
52 lines (43 loc) · 1.51 KB
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
import pygame, sys
from pygame.locals import *
import random
from Config import *
from Zombie import *
class Slot(pygame.sprite.Sprite):
def __init__(self, id):
pygame.sprite.Sprite.__init__(self)
self.id = id
self.image = pygame.Surface((Z_WIDTH, Z_HEIGHT))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
x = self.getPos()[0]
y = self.getPos()[1]
self.rect.center = (x + self.rect.width/2, y + self.rect.height/2)
self.zombie = Zombie()
self.timeRemain = 0
def getPos(self):
switcher = {
0: (0, 0),
1: (Z_WIDTH, 0),
2: (2*Z_WIDTH, 0),
3: (0, Z_HEIGHT),
4: (Z_WIDTH, Z_HEIGHT),
5: (2*Z_WIDTH, Z_HEIGHT),
6: (0, 2*Z_HEIGHT),
7: (Z_WIDTH, 2*Z_HEIGHT),
8: (2*Z_WIDTH, 2*Z_HEIGHT)
}
return switcher.get(self.id, (0, 0))
def checkHit(self, pos):
if (self.zombie.timeRemain > 0 and self.zombie.state == Z_SHOW_STATE):
return self.rect.collidepoint(pos)
return False
def killZombie(self):
self.zombie.die()
def update(self):
self.image.fill(GREEN)
if (self.zombie.state != Z_NOT_SHOW_STATE):
self.image.blit(self.zombie.image, self.zombie.rect)
if (self.zombie.state == Z_NOT_SHOW_STATE):
if random.randint(0, 6*FPS) == FPS:
self.zombie.respawn()