-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.py
More file actions
67 lines (59 loc) · 2 KB
/
dot.py
File metadata and controls
67 lines (59 loc) · 2 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
57
58
59
60
61
62
63
64
65
66
67
"""
Author Paul Brace March 2025
PacMan game developed using arcade
Dot class used to display dots, energisers and fruit
"""
import arcade
from constants import *
class Dot(arcade.Sprite):
# Dot type constants
DOT = 0
ENERGISER = 1
FRUIT = 2
# Dot images
dot_image = arcade.load_texture('images/dot.png')
energiser_image = arcade.load_texture('images/energiser.png')
fruit_image = [
arcade.load_texture('images/Cherry.png'),
arcade.load_texture('images/Strawberry.png'),
arcade.load_texture('images/Orange.png'),
arcade.load_texture('images/Apple.png'),
arcade.load_texture('images/Melon.png'),
arcade.load_texture('images/Galaxian.png'),
arcade.load_texture('images/Bell.png')
]
# Score earned for each type of fruit when eaten
fruit_score = [100, 300, 500, 700, 1000, 2000, 3000, 5000]
def __init__(self, dtype, x, y, fruit_number=1):
self.dtype = dtype
x = x * 20 + 20
y = WINDOW_HEIGHT - (y * 20 + 40)
# Time fruit remains on screen
self.timer = 0
image = None
self.done = False
match dtype:
case Dot.DOT:
image = Dot.dot_image
self.score = 20
case Dot.ENERGISER:
image = Dot.energiser_image
self.score = 50
case Dot.FRUIT:
if fruit_number > 7:
fruit_number = 7
image = Dot.fruit_image[fruit_number - 1]
self.score = Dot.fruit_score[fruit_number - 1]
# Time fruit remains on screen
self.timer = DISPLAY_FRUIT
# position between 2 bricks
x = x - 10
super().__init__(image, 1, x, y)
def update(self, delta_time):
if self.dtype == Dot.FRUIT:
self.timer -= 1
if self.timer <= 0:
self.done = True
if self.done:
self.kill()
super().update(delta_time)