-
Notifications
You must be signed in to change notification settings - Fork 0
/
death.py
72 lines (58 loc) · 2.29 KB
/
death.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
65
66
67
68
69
70
71
72
# 'Wages of Fear'
# By Andrey Sidorenko [email protected]
# The game inspired by 'Jeux et casse-tête à programmer' (Jacques Arsac, 1985)
# Bitmap images http://pixabay.com/
# WAV sounds/music https://freesound.org/ (Attribution 3.0 Unported)
# Future TimeSplitters font is licensed under the 1001Fonts Free For Commercial Use License (FFC)
# Released under a "Simplified BSD" license
import pygame
from pygame.sprite import Sprite
from random import randint
class Death(Sprite):
"""
"""
def __init__(self,wof_settings,screen):
"""
The Death's settings initialization
"""
super().__init__()
self.screen = screen
self.wof_settings = wof_settings
self.image = pygame.image.load('images/pacman.bmp')
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
self.screen_rect = screen.get_rect()
self.rect.centerx = self.screen_rect.centerx
self.rect.centery = self.screen_rect.centery
self.centerx = float(self.rect.centerx)
self.centery = float(self.rect.centery)
# Movement step
self.deltaX = 1
self.deltaY = 1
def update(self, walls,inkblots,diamonds):
"""
Update the death position
"""
old_x = self.rect.centerx
old_y = self.rect.centery
self.rect.centerx += self.deltaX * self.wof_settings.death_speed_factor
self.rect.centery += self.deltaY * self.wof_settings.death_speed_factor
if not pygame.sprite.spritecollide(self, walls, False,pygame.sprite.collide_mask) and not pygame.sprite.spritecollide(self, inkblots, False) and not pygame.sprite.spritecollide(self, diamonds, False):
old_x = self.rect.centerx
old_y = self.rect.centery
else:
self.rect.centerx = old_x
self.rect.centery = old_y
choise = randint(0,3)
if choise == 0:
self.deltaX = 1
if choise == 1:
self.deltaX =-1
if choise == 2:
self.deltaY = 1
if choise == 3:
self.deltaY =-1
def draw_death(self):
"""
"""
self.screen.blit(self.image,self.rect)