summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-08 21:03:40 +0300
committerViljami Ilola <+@hix.fi>2024-04-08 21:03:40 +0300
commit9548295de1d343e831baaa2e1c908f70cef0e33a (patch)
treee9cb817de24b179beb842ec356e542ce22cde086
parentc99a7138e78352c4e26483dd4dad36b009a72e4f (diff)
life group. indicator for lost life
-rw-r--r--src/sliceitoff/display/scaling.py6
-rw-r--r--src/sliceitoff/field/field.py2
-rw-r--r--src/sliceitoff/game/gameplay.py5
-rw-r--r--src/sliceitoff/game/level.py8
-rw-r--r--src/sliceitoff/player/__init__.py1
-rw-r--r--src/sliceitoff/player/life.py40
6 files changed, 56 insertions, 6 deletions
diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py
index b4292b4..834c02e 100644
--- a/src/sliceitoff/display/scaling.py
+++ b/src/sliceitoff/display/scaling.py
@@ -50,7 +50,8 @@ class Scaling():
if size[0] / size[1] <= INTERNAL_WIDTH / INTERNAL_HEIGHT:
__class__.factor = size[0] / INTERNAL_WIDTH
__class__.left = 0
- __class__.top = (size[1] - INTERNAL_HEIGHT * __class__.factor) // 2
+ __class__.top = int (
+ (size[1] - INTERNAL_HEIGHT * __class__.factor) // 2)
__class__.borders = (
pygame.Rect(
0,
@@ -65,7 +66,8 @@ class Scaling():
)
else:
__class__.factor = size[1] / INTERNAL_HEIGHT
- __class__.left = (size[0] - INTERNAL_WIDTH * __class__.factor) // 2
+ __class__.left = int(
+ (size[0] - INTERNAL_WIDTH * __class__.factor) // 2)
__class__.top = 0
__class__.borders = (
pygame.Rect(
diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py
index 2bf7d12..27f4ceb 100644
--- a/src/sliceitoff/field/field.py
+++ b/src/sliceitoff/field/field.py
@@ -144,4 +144,4 @@ class Field(pygame.sprite.LayeredUpdates):
else:
self.explode(field.area)
field.remove(self)
- self.stats.field_count=len(self.active_sprites())
+ self.stats.field_count = len(self.active_sprites())
diff --git a/src/sliceitoff/game/gameplay.py b/src/sliceitoff/game/gameplay.py
index 5a14767..49ff026 100644
--- a/src/sliceitoff/game/gameplay.py
+++ b/src/sliceitoff/game/gameplay.py
@@ -8,11 +8,13 @@ class Gameplay:
player = None,
field = None,
enemies = None,
- stats = None):
+ stats = None,
+ life = None):
self.player = player
self.field = field
self.enemies = enemies
self.stats = stats
+ self.life = life
def fire(self):
""" Lazer is fired. Actions to be taken. """
@@ -24,6 +26,7 @@ class Gameplay:
return False
self.stats.add_score(-500)
if pygame.sprite.spritecollideany(zap_sprite, self.enemies):
+ self.life.lose_life()
if self.stats.lose_life():
return True
self.field.kill_if_not_colliding(self.enemies.sprites())
diff --git a/src/sliceitoff/game/level.py b/src/sliceitoff/game/level.py
index c6633fd..845c960 100644
--- a/src/sliceitoff/game/level.py
+++ b/src/sliceitoff/game/level.py
@@ -2,7 +2,7 @@
import pygame
from status import Status
-from player import Player
+from player import Player, Life
from field import Field
from enemies import Enemies
from screens import levelup_screen, gameover_screen, level_screen
@@ -19,6 +19,7 @@ class Level(pygame.sprite.Group):
self.field = Field(stats = self.stats)
self.enemies = Enemies(count = self.stats.enemies)
self.player = Player()
+ self.life = Life()
self.level_info = Show(level_screen(stats.level))
self.ended = False
self.active = True
@@ -28,7 +29,8 @@ class Level(pygame.sprite.Group):
player = self.player,
field = self.field,
enemies = self.enemies,
- stats = self.stats)
+ stats = self.stats,
+ life = self.life)
def update(self, dt = 0):
""" Updates groups, calls gameplay and adds sprites for drawing """
@@ -36,6 +38,7 @@ class Level(pygame.sprite.Group):
self.status.update(dt = dt)
self.field.update(dt = dt)
self.enemies.update(dt = dt, field_rects = self.field.active_rects())
+ self.life.update(dt = dt)
self.add(self.status, self.field, self.enemies)
if self.level_info.active:
@@ -57,3 +60,4 @@ class Level(pygame.sprite.Group):
self.endscreen = Show(levelup_screen(self.stats))
else:
self.endscreen = Show(gameover_screen())
+ self.add(self.life)
diff --git a/src/sliceitoff/player/__init__.py b/src/sliceitoff/player/__init__.py
index 12ca32c..16d890e 100644
--- a/src/sliceitoff/player/__init__.py
+++ b/src/sliceitoff/player/__init__.py
@@ -1,2 +1,3 @@
""" player - The slicing tool on the screen """
from .player import Player
+from .life import Life
diff --git a/src/sliceitoff/player/life.py b/src/sliceitoff/player/life.py
new file mode 100644
index 0000000..7d72729
--- /dev/null
+++ b/src/sliceitoff/player/life.py
@@ -0,0 +1,40 @@
+""" player.life - Hearth that will explode """
+import os
+import pygame
+
+from display import Scaling, CGA_COLORS
+
+from text import get_letter_surface, ExplodingSprite
+
+class PieceOfHearth(ExplodingSprite):
+ def __init__(self, image, pos):
+ super().__init__()
+ self.image = image
+ self.rect = self.image.get_rect().move(pos)
+
+class Life(pygame.sprite.Group):
+ """ The slicer. Special sprite group that only list 1 sprite """
+ def __init__(self):
+ super().__init__()
+ self.timeout = 0
+
+ def update(self, loselife = False, dt = 0, **kwargs):
+ explode = True if self.timeout < 1_000 else False
+ super().update(dt = dt, explode = explode, **kwargs)
+ if self.timeout > 0:
+ self.timeout -= dt
+ else:
+ self.empty()
+
+ def lose_life(self):
+ self.timeout = 2_000
+ font_width = int(Scaling.factor * 200_000)
+ block_width = int(Scaling.factor * 8_000)
+ offset = (
+ int(Scaling.factor * 72_500 + Scaling.left),
+ int(Scaling.factor * 20_000 + Scaling.top))
+ srfc = get_letter_surface(("8x8", 200_000, 4), 0x03)
+ for x in range(0, font_width, block_width):
+ for y in range(0, font_width, block_width):
+ image = srfc.subsurface((x, y, block_width, block_width))
+ self.add(PieceOfHearth(image,(x + offset[0], y + offset[1])))