summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sliceitoff/enemies/ball.py27
-rw-r--r--src/sliceitoff/enemies/bouncher.py36
-rw-r--r--src/sliceitoff/enemies/enemies.py56
-rw-r--r--src/sliceitoff/enemies/enemy.py32
-rw-r--r--src/sliceitoff/status/__init__.py3
-rw-r--r--src/sliceitoff/status/status.py2
6 files changed, 111 insertions, 45 deletions
diff --git a/src/sliceitoff/enemies/ball.py b/src/sliceitoff/enemies/ball.py
new file mode 100644
index 0000000..b8c8467
--- /dev/null
+++ b/src/sliceitoff/enemies/ball.py
@@ -0,0 +1,27 @@
+""" enemies.ball - Enemy type that goes straight line hitting walls """
+from random import randrange, choice
+
+from text import get_letter_surface
+from .enemy import Enemy
+
+BALL_SPAWN_AREA = (0, 0, 300_000, 200_000)
+BALL_MOVEMENT = (100, 100)
+BALL_SYMBOLS = (0x1,0x2)
+BALL_SIZE = 8_000
+
+class EnemyBall(Enemy):
+ """ Basic type of enemy. """
+ def __init__(self):
+ super().__init__()
+ self.position = (
+ randrange(BALL_SPAWN_AREA[0], BALL_SPAWN_AREA[2]),
+ randrange(BALL_SPAWN_AREA[1], BALL_SPAWN_AREA[3]))
+ self.movement = (
+ randrange(0, BALL_MOVEMENT[0]*2) - BALL_MOVEMENT[0],
+ randrange(0, BALL_MOVEMENT[1]*2) - BALL_MOVEMENT[1])
+ font_key = ('8x8', BALL_SIZE, 0)
+ surface = get_letter_surface(font_key, choice(BALL_SYMBOLS))
+ self.image = surface.subsurface(
+ (0, 0, surface.get_rect().w, surface.get_rect().w))
+ self.update()
+ self.rect = None
diff --git a/src/sliceitoff/enemies/bouncher.py b/src/sliceitoff/enemies/bouncher.py
new file mode 100644
index 0000000..692492b
--- /dev/null
+++ b/src/sliceitoff/enemies/bouncher.py
@@ -0,0 +1,36 @@
+""" enemies.bouncher - Enemy type that bouches around """
+from random import randrange, choice
+
+from text import get_letter_surface
+from .enemy import Enemy
+
+BOUNCHER_SPAWN_AREA = (0, 0, 300_000, 80_000)
+BOUNCHER_MOVEMENT = (200, 20)
+BOUNCHER_SIZE = 12_000
+BOUNCHER_SYMBOLS = (0x1,0x2)
+GRAVITY = 4
+
+class EnemyBouncher(Enemy):
+ """ Type of enemy that is affected by gravity """
+ def __init__(self):
+ super().__init__()
+ self.position = (
+ randrange(BOUNCHER_SPAWN_AREA[0], BOUNCHER_SPAWN_AREA[2]),
+ randrange(BOUNCHER_SPAWN_AREA[1], BOUNCHER_SPAWN_AREA[3]))
+ self.movement = (
+ randrange(0, BOUNCHER_MOVEMENT[0]*2) - BOUNCHER_MOVEMENT[0],
+ randrange(0, BOUNCHER_MOVEMENT[1]*2) - BOUNCHER_MOVEMENT[1])
+ font_key = ('8x8', BOUNCHER_SIZE, 0)
+ surface = get_letter_surface(font_key, choice(BOUNCHER_SYMBOLS))
+ self.image = surface.subsurface(
+ (0, 0, surface.get_rect().w, surface.get_rect().w))
+ self.rect = None
+ self.update()
+
+ def update(self, dt = 0, wall_hit = None, **kwargs):
+ """ wall hit from super(). added gravity """
+ super().update(dt = dt, wall_hit = wall_hit, **kwargs)
+ if dt:
+ self.movement = (
+ self.movement[0],
+ (self.movement[1] + GRAVITY)*0.999)
diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py
index 41a19fa..c52059f 100644
--- a/src/sliceitoff/enemies/enemies.py
+++ b/src/sliceitoff/enemies/enemies.py
@@ -1,52 +1,22 @@
-import pygame
from random import randrange
+import pygame
-from display import Scaling
-from text import get_letter_surface
-
-BALL_SPAWN_AREA = (0, 0, 300_000, 200_000)
-BALL_MOVEMENT = (100, 100)
-
-class EnemyBall(pygame.sprite.Sprite):
- def __init__(self):
- super().__init__()
- self.position = (
- randrange(BALL_SPAWN_AREA[0], BALL_SPAWN_AREA[2]),
- randrange(BALL_SPAWN_AREA[1], BALL_SPAWN_AREA[3]))
- self.movement = (
- randrange(0, BALL_MOVEMENT[0]*2) - BALL_MOVEMENT[0],
- randrange(0, BALL_MOVEMENT[1]*2) - BALL_MOVEMENT[1])
- self.image = get_letter_surface(
- ('8x8', 8_000, 0),
- randrange(1,3)).subsurface(
- (0,0,8_000*Scaling.factor,8_000*Scaling.factor))
- self.update()
- self.rect = None
-
- def update(self, dt = 0, wall_hit = None, **kwargs):
- if wall_hit:
- if self.rect.x < wall_hit.x:
- self.movement = (abs(self.movement[0]), self.movement[1])
- if self.rect.y < wall_hit.y:
- self.movement = (self.movement[0], abs(self.movement[1]))
- if self.rect.x + self.rect.w >= wall_hit.x + wall_hit.w:
- self.movement = (-abs(self.movement[0]), self.movement[1])
- if self.rect.y + self.rect.h >= wall_hit.y + wall_hit.h:
- self.movement = (self.movement[0], -abs(self.movement[1]))
- return
- if dt:
- self.position = (
- self.position[0] + self.movement[0] * dt,
- self.position[1] + self.movement[1] * dt)
- self.rect = pygame.Rect(
- Scaling.scale_to_display(self.position),
- self.image.get_size())
+from .ball import EnemyBall
+from .bouncher import EnemyBouncher
class Enemies(pygame.sprite.Group):
def __init__(self, field = None, count = 0):
super().__init__()
- for _ in range(count):
- self.add(EnemyBall())
+ while count:
+ match randrange(0,4):
+ case 0|1|2:
+ if count >= 1:
+ self.add(EnemyBall())
+ count -= 1
+ case 3:
+ if count >= 2:
+ self.add(EnemyBouncher())
+ count -= 2
self.field = field
def update(self, field_rects = [], **kwargs):
diff --git a/src/sliceitoff/enemies/enemy.py b/src/sliceitoff/enemies/enemy.py
new file mode 100644
index 0000000..08d75dd
--- /dev/null
+++ b/src/sliceitoff/enemies/enemy.py
@@ -0,0 +1,32 @@
+""" enemy.enemy - Enemy super class. Wall hitting and other commons """
+import pygame
+
+from display import Scaling
+
+class Enemy(pygame.sprite.Sprite):
+ """ Enemy super class. Just common movements. """
+ def __init__(self):
+ super().__init__()
+ self.position = (0, 0)
+ self.movement = (0, 0)
+ self.rect = None
+
+ def update(self, dt = 0, wall_hit = None):
+ """ hit walls, update position and rect """
+ if wall_hit:
+ if self.rect.x < wall_hit.x:
+ self.movement = (abs(self.movement[0]), self.movement[1])
+ if self.rect.y < wall_hit.y:
+ self.movement = (self.movement[0], abs(self.movement[1]))
+ if self.rect.x + self.rect.w >= wall_hit.x + wall_hit.w:
+ self.movement = (-abs(self.movement[0]), self.movement[1])
+ if self.rect.y + self.rect.h >= wall_hit.y + wall_hit.h:
+ self.movement = (self.movement[0], -abs(self.movement[1]))
+ return
+ if dt:
+ self.position = (
+ self.position[0] + self.movement[0] * dt,
+ self.position[1] + self.movement[1] * dt)
+ self.rect = pygame.Rect(
+ Scaling.scale_to_display(self.position),
+ self.image.get_size())
diff --git a/src/sliceitoff/status/__init__.py b/src/sliceitoff/status/__init__.py
index 2a4c93e..68a41e1 100644
--- a/src/sliceitoff/status/__init__.py
+++ b/src/sliceitoff/status/__init__.py
@@ -1 +1,2 @@
-from .status import Status \ No newline at end of file
+""" status - Statusline bottom of screen when level is going on """
+from .status import Status
diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py
index bbe9a03..8a1a130 100644
--- a/src/sliceitoff/status/status.py
+++ b/src/sliceitoff/status/status.py
@@ -9,7 +9,7 @@ class Status(pygame.sprite.Group):
super().__init__()
self.stats = stats
self.old_srt = None
-
+
def update(self, **kwargs):
""" Rebuilds statusline if needed """
super().update(**kwargs)