summaryrefslogtreecommitdiff
path: root/src/sliceitoff/player/player.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-16 15:11:12 +0200
committerViljami Ilola <+@hix.fi>2024-03-16 15:11:12 +0200
commit3d1e8a068f98a32e0146d8e9ab58dea49fbb4c74 (patch)
tree013814df21967af7dc9dfb390fd6de9770799616 /src/sliceitoff/player/player.py
parent77d104cced553b8dfc9896cb456bd039807ed6c6 (diff)
controls and gamelogic draft
Diffstat (limited to 'src/sliceitoff/player/player.py')
-rw-r--r--src/sliceitoff/player/player.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/sliceitoff/player/player.py b/src/sliceitoff/player/player.py
new file mode 100644
index 0000000..e9cb569
--- /dev/null
+++ b/src/sliceitoff/player/player.py
@@ -0,0 +1,58 @@
+import os
+import pygame
+
+from display import Scaling
+from images import Images
+
+class PlayerSprite(pygame.sprite.Sprite):
+ def __init__(self, image, pos):
+ super().__init__()
+ self.image = image
+ x, y = self.image.get_size()
+ x = pos[0] - x // 2
+ y = pos[1] - y // 2
+ self.rect = self.image.get_rect().move(x,y)
+
+class Player():
+ def __init__(self, field = None):
+ self.field = field
+ self.position = (20_000, 14_000)
+ self.direction = False
+ self.lazer = False
+ self.sprites = pygame.sprite.Group()
+ self.updated = True
+
+ def __update_sprites(self):
+ self.sprites.empty()
+ image = Images.surfaces['player_00']
+ if self.direction:
+ image = pygame.transform.rotate(image, 90)
+ self.sprites.add(PlayerSprite(
+ image,
+ Scaling.scale_to_display(self.position) ))
+ if not self.lazer:
+ self.updated = False
+
+ def set_position(self, pos):
+ if not self.lazer:
+ self.position = Scaling.scale_to_internal(pos)
+ self.updated = True
+
+ def get_sprites(self):
+ if self.updated:
+ self.__update_sprites()
+ return self.sprites
+
+ def set_lazer(self):
+ # self.lazer = True
+ # self.updated = True
+ self.field.slice(self.position, self.direction, 1_000)
+
+ def set_direction(self):
+ if not self.lazer:
+ self.direction = not self.direction
+ self.updated = True
+
+ def __del__(self):
+ pass
+ \ No newline at end of file