-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.py
More file actions
56 lines (49 loc) · 1.49 KB
/
Copy pathtarget.py
File metadata and controls
56 lines (49 loc) · 1.49 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
53
54
55
56
"""
Author Paul Brace April 2024
Target class for Snake game
"""
import pygame
from constants import *
from game_sprite import GameSprite
from sprite_list import SpriteList
import random
pygame.init()
eat = pygame.mixer.Sound('sounds/crunch.wav')
apple = pygame.image.load("images/apple.png")
bomb = pygame.image.load("images/bomb.png")
sweet_images = []
sweet_images.append(pygame.image.load("images/sweet1.png"))
sweet_images.append(pygame.image.load("images/sweet2.png"))
sweet_images.append(pygame.image.load("images/sweet3.png"))
sweet_images.append(pygame.image.load("images/sweet4.png"))
targets = SpriteList()
class Target(GameSprite):
def __init__(self, type, x, y):
"""
:param type: Type of taget - apple, bomb or sweet
:param x: x coordinate on screen
:param y: y coordinate on screen
"""
self.type = type
if type == "apple":
image = apple
self.points = 5
elif type == "bomb":
image = bomb
self.points = 0
else:
image = sweet_images[random.randint(0, 3)]
self.points = 15
super().__init__(image, x, y)
self.timer = DISPLAY_SWEET
def eaten(self):
if self.type != "bomb":
eat.play()
self.done = True
return self.points
def update(self):
# remove sweet after timer frames
if self.type == "sweet":
self.timer -= 1
if self.timer <= 0:
self.done = True