summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-20 17:46:10 +0200
committerViljami Ilola <+@hix.fi>2024-03-20 17:46:10 +0200
commit975e5dca49fb09fe2f762462f1c337c0d63735bf (patch)
tree4c837b346d7b7e4a9246c1be846f48d787a327ba
parent398eebe7829622c6983cb28528f2208b4d596f32 (diff)
exploding text
-rw-r--r--src/sliceitoff/__main__.py19
-rw-r--r--src/sliceitoff/display/display.py4
-rw-r--r--src/sliceitoff/display/scaling.py2
-rw-r--r--src/sliceitoff/game/__init__.py1
-rw-r--r--src/sliceitoff/game/show.py33
-rw-r--r--src/sliceitoff/screens/__init__.py2
-rw-r--r--src/sliceitoff/screens/welcome.py24
-rw-r--r--src/sliceitoff/text/text.py16
8 files changed, 76 insertions, 25 deletions
diff --git a/src/sliceitoff/__main__.py b/src/sliceitoff/__main__.py
index 717403e..7d21c7d 100644
--- a/src/sliceitoff/__main__.py
+++ b/src/sliceitoff/__main__.py
@@ -9,9 +9,9 @@ import pygame
from display import Display
from images import Images, Fonts
-from game import Level
+from game import Level, Show
from stats import Stats
-from screens import Welcome
+from screens import welcome_screen
def sliceitoff():
@@ -20,22 +20,27 @@ def sliceitoff():
pygame.mouse.set_visible(False)
+ clock = pygame.time.Clock()
+
display = Display()
current_path = Path(__file__).parent.resolve()
Images.load_images( current_path )
Fonts.load_fonts( current_path )
- welcome = Welcome()
- display.update( [welcome.sprites] )
- sleep(2)
-
- clock = pygame.time.Clock()
+
+ welcome = Show(welcome_screen())
dt = 0
+ while welcome.step(dt):
+ dt = clock.tick()
+ display.update( [welcome.sprites] )
+
+
Stats.new_game()
while Stats.lives:
level = Level(display = display)
+ dt = 0
while level.step(dt):
dt = clock.tick()
if Stats.lives:
diff --git a/src/sliceitoff/display/display.py b/src/sliceitoff/display/display.py
index 2d6605f..06b222c 100644
--- a/src/sliceitoff/display/display.py
+++ b/src/sliceitoff/display/display.py
@@ -22,7 +22,7 @@ class Display():
print(
"DISPLAY: \n"
f" {Scaling.active = }\n"
- f" {Scaling.border = }\n"
+ f" {Scaling.borders = }\n"
f" {Scaling.factor = }\n")
def update(self, groups = None):
@@ -30,6 +30,8 @@ class Display():
self.screen.fill(Stats.bgcolor, rect=Scaling.active)
for group in groups:
group.draw(self.screen)
+ self.screen.fill(Stats.bordercolor, rect=Scaling.borders[0])
+ self.screen.fill(Stats.bordercolor, rect=Scaling.borders[1])
pygame.display.flip()
def __del__(self):
diff --git a/src/sliceitoff/display/scaling.py b/src/sliceitoff/display/scaling.py
index f40d33c..53a9fb1 100644
--- a/src/sliceitoff/display/scaling.py
+++ b/src/sliceitoff/display/scaling.py
@@ -58,7 +58,7 @@ class Scaling():
__class__.factor = size[1] / INTERNAL_HEIGHT
__class__.left = (size[0] - INTERNAL_WIDTH * __class__.factor) // 2
__class__.top = 0
- __class__.border = (
+ __class__.borders = (
pygame.Rect(
0,
0,
diff --git a/src/sliceitoff/game/__init__.py b/src/sliceitoff/game/__init__.py
index 87cb41b..d578385 100644
--- a/src/sliceitoff/game/__init__.py
+++ b/src/sliceitoff/game/__init__.py
@@ -1,2 +1,3 @@
from .gameplay import Gameplay
from .level import Level
+from .show import Show
diff --git a/src/sliceitoff/game/show.py b/src/sliceitoff/game/show.py
new file mode 100644
index 0000000..f81c211
--- /dev/null
+++ b/src/sliceitoff/game/show.py
@@ -0,0 +1,33 @@
+""" Reads user input and does actions when game play is on. """
+import pygame
+
+class Show:
+ """ To show some sprites and quit on any key """
+ def __init__(self, sprites = []):
+ self.sprites = sprites
+ self.fadeout = 500
+ self.timeout = 5_000
+
+ def step(self, dt):
+ if self.fadeout < 0:
+ return False
+
+ if self.timeout < 0:
+ for event in pygame.event.get():
+ if event.type in (
+ pygame.MOUSEBUTTONDOWN,
+ pygame.KEYDOWN,
+ pygame.QUIT):
+ return False
+ self.fadeout -= dt
+ self.sprites.update(explode=dt)
+ return True
+
+ for event in pygame.event.get():
+ if event.type in (
+ pygame.MOUSEBUTTONDOWN,
+ pygame.KEYDOWN,
+ pygame.QUIT):
+ self.timeout = 0
+ self.timeout -= dt
+ return True
diff --git a/src/sliceitoff/screens/__init__.py b/src/sliceitoff/screens/__init__.py
index a03f76b..89294bd 100644
--- a/src/sliceitoff/screens/__init__.py
+++ b/src/sliceitoff/screens/__init__.py
@@ -1,2 +1,2 @@
#from .levelup import LevelUp
-from .welcome import Welcome
+from .welcome import welcome_screen
diff --git a/src/sliceitoff/screens/welcome.py b/src/sliceitoff/screens/welcome.py
index ddfd997..93218f3 100644
--- a/src/sliceitoff/screens/welcome.py
+++ b/src/sliceitoff/screens/welcome.py
@@ -1,15 +1,13 @@
from text import TextPage
-from display import Scaling
-class Welcome():
- def __init__(self):
- self.sprites = TextPage(
- " Slice it off!\n"
- "\n"
- "* Do not hit the balls\n"
- "* Slice off empty areas\n"
- "* Slice off empty areas\n",
- font = 'computer',
- size = (8_000, 16_000),
- grid = (9_000, 16_000) )
- \ No newline at end of file
+def welcome_screen():
+ return TextPage(
+ " Slice it off!\n"
+ " \n"
+ " * Do not hit the balls\n"
+ " * Make area 10% or smaller\n"
+ " * Do not separate the balls\n"
+ " * Be fast!!\n",
+ font = 'computer',
+ size = (8_000, 16_000),
+ grid = (9_000, 16_000) )
diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py
index f01e517..e86bede 100644
--- a/src/sliceitoff/text/text.py
+++ b/src/sliceitoff/text/text.py
@@ -12,8 +12,20 @@ class LetterSprite(pygame.sprite.Sprite):
self.image = image
self.rect = self.image.get_rect().move(pos)
self.direction = (
- Scaling.factor * 40 * 1_000 + randrange(4_000),
- Scaling.factor * 40 * 1_000 + randrange(4_000))
+ Scaling.factor * (2_000 - randrange(4_000)),
+ Scaling.factor * (2_000 - randrange(4_000)))
+
+ def update(self, explode=0):
+ if explode:
+ self.rect = pygame.Rect(
+ self.rect.x + self.direction[0] * explode,
+ self.rect.y + self.direction[1] * explode,
+ self.rect.w,
+ self.rect.h)
+ self.direction = (
+ self.direction[0] * 1.15,
+ self.direction[1] * 1.15)
+
class TextPage(pygame.sprite.Group):
def __init__(