From b00fe8fe50392a75529864fe03399fa3a0976143 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Mon, 18 Mar 2024 13:05:58 +0200 Subject: internal resolution x10. get rid of rest get_sprites functions --- src/sliceitoff/__main__.py | 8 ++++---- src/sliceitoff/display/static.py | 4 ++-- src/sliceitoff/enemies/enemies.py | 11 +++++------ src/sliceitoff/field/field.py | 3 ++- src/sliceitoff/images/images.py | 2 +- src/sliceitoff/player/player.py | 12 ++++-------- src/sliceitoff/status/status.py | 4 ++-- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/sliceitoff/__main__.py b/src/sliceitoff/__main__.py index 5fc766b..2da9aa8 100644 --- a/src/sliceitoff/__main__.py +++ b/src/sliceitoff/__main__.py @@ -35,15 +35,15 @@ def sliceitoff(): while True: dt = clock.tick(60) - for fun in (status, field): + for fun in (status, field, enemies): fun.update(dt) - + display.update( [ status.sprites, field.sprites, - enemies.get_sprites(), - player.get_sprites() + enemies.sprites, + player.sprites ]) if game.step(): diff --git a/src/sliceitoff/display/static.py b/src/sliceitoff/display/static.py index 1678994..af1cc67 100644 --- a/src/sliceitoff/display/static.py +++ b/src/sliceitoff/display/static.py @@ -1,2 +1,2 @@ -INTERNAL_WIDTH = 40_000 -INTERNAL_HEIGHT = 30_000 +INTERNAL_WIDTH = 400_000 +INTERNAL_HEIGHT = 300_000 diff --git a/src/sliceitoff/enemies/enemies.py b/src/sliceitoff/enemies/enemies.py index b0ac187..6a9fda4 100644 --- a/src/sliceitoff/enemies/enemies.py +++ b/src/sliceitoff/enemies/enemies.py @@ -56,8 +56,8 @@ class Enemies(): def emerge_enemies(self): for _ in range(self.level * 1): enemy = EnemyBall() - enemy.set_position( (randrange(0,38_000), randrange(0,26_000)) ) - enemy.set_movement( (randrange(0,400)-200, randrange(0,400)-200) ) + enemy.set_position( (randrange(0,380_000), randrange(0,260_000)) ) + enemy.set_movement( (randrange(0,200)-100, randrange(0,200)-100) ) self.sprites.add(enemy) def wall_hit(self, field, enemy): @@ -70,8 +70,9 @@ class Enemies(): if ( enemy.rect.y + enemy.rect.h >= field.rect.y + field.rect.h ): enemy.force_up() - def get_sprites(self): - self.sprites.update(move=1) + def update(self, dt): + """ Update sprites basis of dt. dt = milliseconds from last update """ + self.sprites.update(move=dt) for enemy in self.sprites: for field in self.field.sprites: if field.rect.contains(enemy): @@ -80,5 +81,3 @@ class Enemies(): for field in self.field.sprites: if field.rect.colliderect(enemy): self.wall_hit(field, enemy) - - return self.sprites diff --git a/src/sliceitoff/field/field.py b/src/sliceitoff/field/field.py index a6084f1..979590e 100644 --- a/src/sliceitoff/field/field.py +++ b/src/sliceitoff/field/field.py @@ -16,7 +16,7 @@ class FieldSprite(pygame.sprite.Sprite): class Field(): def __init__(self): self.sprites = pygame.sprite.Group() - self.sprites.add(FieldSprite( (0, 0, 40_000, 28_000) )) + self.sprites.add(FieldSprite( (0, 0, 400_000, 280_000) )) def coordinates_inside_area(self, area, x, y) -> bool: if x < area[0]: @@ -68,5 +68,6 @@ class Field(): return Scaling.area_to_rect((ax, y2, aw, y3-y2)) def update(self, dt): + """ Update sprites basis of dt. dt = milliseconds from last update """ pass \ No newline at end of file diff --git a/src/sliceitoff/images/images.py b/src/sliceitoff/images/images.py index 07a8bcd..7ae1f6d 100644 --- a/src/sliceitoff/images/images.py +++ b/src/sliceitoff/images/images.py @@ -20,7 +20,7 @@ class Images: print(f"Loading images {name = }, {filename = }") image = pygame.image.load(filename) rgba = pygame.Surface.convert_alpha(image) - scaled = pygame.transform.smoothscale_by(rgba, Scaling.factor) + scaled = pygame.transform.smoothscale_by(rgba, Scaling.factor*10) __class__.surfaces[name] = scaled return True diff --git a/src/sliceitoff/player/player.py b/src/sliceitoff/player/player.py index f383077..9870c50 100644 --- a/src/sliceitoff/player/player.py +++ b/src/sliceitoff/player/player.py @@ -17,7 +17,7 @@ class Player(): def __init__(self, field = None, enemies = None): self.field = field self.enemies = enemies - self.position = (20_000, 14_000) + self.position = (200_000, 140_000) self.direction = False self.lazer = False self.sprites = pygame.sprite.Group() @@ -39,15 +39,15 @@ class Player(): self.position = Scaling.scale_to_internal(pos) self.updated = True - def get_sprites(self): + def update(self, dt): + """ Update sprites basis of dt. dt = milliseconds from last update """ if self.updated: self.__update_sprites() - return self.sprites def fire_lazer(self): # self.lazer = True # self.updated = True - hitbox = self.field.slice(self.position, self.direction, 450) + hitbox = self.field.slice(self.position, self.direction, 4_500) if hitbox is not None: for enemy in self.enemies.sprites: if hitbox.colliderect(enemy.rect): @@ -64,7 +64,3 @@ class Player(): if not self.lazer: self.direction = not self.direction self.updated = True - - def __del__(self): - pass - \ No newline at end of file diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py index 5390299..4f2125a 100644 --- a/src/sliceitoff/status/status.py +++ b/src/sliceitoff/status/status.py @@ -26,9 +26,9 @@ class Status(): """ Update sprites basis of dt. dt = milliseconds from last update """ if self.updated: self.sprites.empty() - y = 28_000 + y = 280_000 score_str="{:010d}".format(self.score) - for letter, x in zip(score_str, range(30_000,40_000,1_000)): + for letter, x in zip(score_str, range(300_000,400_000,10_000)): self.sprites.add(LetterSprite( Images.surfaces[f"letter_{letter}"], Scaling.scale_to_display((x,y)) )) -- cgit v1.2.3