-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_objects.py
60 lines (47 loc) · 1.89 KB
/
base_objects.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
import pygame
class StartGameObject(pygame.sprite.Sprite):
def __init__(self, image, position):
super().__init__()
self.image = image # Assume image is already loaded
self.rect = self.image.get_rect(topleft=position)
class PlacedObject(pygame.sprite.Sprite):
object_list = [] # This could be overridden by subclasses if separate lists are needed
def __init__(self, pos, placed_sprites, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect(topleft=pos)
placed_sprites.add(self)
self.add_to_class_list()
def add_to_class_list(self):
# This method will be overridden by subclasses to add the object to the specific list
pass
def update(self):
pass
def destroy(self):
self.remove_from_class_list()
self.kill()
def remove_from_class_list(self):
# This method will be overridden by subclasses to remove the object from the specific list
pass
class PlayObject(pygame.sprite.Sprite):
def __init__(self, pos, play_sprites, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect(topleft=pos)
self.original_pos = pos # Save the original position for restarting
play_sprites.add(self)
self.add_to_class_list()
def add_to_class_list(self):
# This method should be overridden by subclasses if they maintain a specific list
pass
def update(self):
# Common update logic (if any) or just pass if all subclasses will override
pass
def destroy(self):
self.remove_from_class_list()
self.kill()
def remove_from_class_list(self):
# This method should be overridden by subclasses to remove the object from its specific list
pass
def restart(self):
self.rect.topleft = self.original_pos