-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin_objects.py
48 lines (30 loc) · 1.08 KB
/
plugin_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
from typing import Set
import pygame
from plugin_core import Window
__all__ = ['Object', 'ObjectWindow']
class Object:
def draw(self, screen: pygame.Surface):
pass
class SurfaceObject:
def __init__(self, surface: pygame.Surface):
self.surface = surface
self.rect = surface.get_rect()
def draw(self, screen: pygame.Surface):
screen.blit(self.surface, self.rect)
def move(self, x: int, y: int):
self.rect = self.rect.move(x, y)
class ObjectWindow(Window):
def __init__(self, *, background=(0, 0, 0), objects: Set[Object] = set(), **kwargs):
super().__init__(background=background, objects=objects, **kwargs)
self.background = background
self.objects = objects
def add_object(self, obj: Object):
self.objects.add(obj)
def on_event(self, event: pygame.event.EventType):
super().on_event(event)
def main_loop(self):
super().main_loop()
self.screen.fill(self.background)
for obj in self.objects:
obj.draw(self.screen)
pygame.display.flip()