diff --git a/docs/CODESTYLE.md b/docs/CODESTYLE.md index 3a635de..14267f5 100644 --- a/docs/CODESTYLE.md +++ b/docs/CODESTYLE.md @@ -12,6 +12,7 @@ Now project has this structure: |____ debug.py |____ main.py |____ mixins.py +|____ rect.py |____ updater.py |____ assets | |____ @@ -34,6 +35,7 @@ General files: - *debug.py* - file with some objects for easier debugging game - *main.py* - main file, import all modules, contains the entrypoint of game and connects all the scenes together - *mixins.py* - file with mixins which are needed for simple creation of the same type of objects (DRY principle) +- *rect.py* - file with implementation of a `pygame.Rect` for working with float values - *updater.py* - file responsible for updating Space Way Assets: diff --git a/spaceway/config/config.json b/spaceway/config/config.json index 1eed96a..8978d5b 100644 --- a/spaceway/config/config.json +++ b/spaceway/config/config.json @@ -4,6 +4,6 @@ "FPS": 60, "scene": "headpiece", "sub_scene": "headpiece", - "version": "2.0.1", + "version": "2.1.0", "debug": false } \ No newline at end of file diff --git a/spaceway/rect.py b/spaceway/rect.py index c24fc71..55e41df 100644 --- a/spaceway/rect.py +++ b/spaceway/rect.py @@ -424,23 +424,3 @@ def collidedictall(self, rects_dict, use_values=0): out.append((key, rects_dict[key])) return out - - -__pygame_image_load = pygame.image.load - - -def __image_load(*args, **kwargs) -> FloatRect: - surface: pygame.Surface = __pygame_image_load(*args, **kwargs) - - class FloatSurface(pygame.Surface): - def get_rect(self, **kwargs): - return FloatRect(0, 0, *self.get_size(), **kwargs) - - float_surface: FloatSurface = FloatSurface(surface.get_size(), surface.get_flags(), surface) - float_surface.blit(surface, surface.get_rect()) - - return float_surface - - -# Replacing functions, which returns `pygame.Rect` object -pygame.image.load = __image_load diff --git a/spaceway/scenes/game/objects.py b/spaceway/scenes/game/objects.py index 5132aea..c4aae48 100644 --- a/spaceway/scenes/game/objects.py +++ b/spaceway/scenes/game/objects.py @@ -42,14 +42,15 @@ def __init__(self, screen, base_dir, config): self.is_flame = False self.img_flame = pygame.image.load(f'{base_dir}/assets/images/plate/flame.bmp') + self.img_flame_flip = pygame.transform.flip(self.img_flame, False, True) self.rect_flame = self.img_flame.get_rect() self.img = self.imgs[self.config['user']['color']] + self.img_flip = pygame.transform.flip(self.img, False, True) self.rect = FloatRect(self.img.get_rect()) self.rect.x = 5 - # self.rect.centery = self.screen_rect.centery - self.rect.top = self.screen_rect.top + self.rect.centery = self.screen_rect.centery self.rect_flame.centerx = self.rect.centerx + 1 @@ -74,6 +75,7 @@ def reset(self): def update(self): if self.img != self.imgs[self.config['user']['color']]: self.img = self.imgs[self.config['user']['color']] + self.img_flip = pygame.transform.flip(self.img, False, True) if not self.is_jump: self.gravity += self.gravity_scale * self.config['ns'].dt @@ -88,16 +90,10 @@ def update(self): inc = self.jump ** 2 // 3 * self.config['ns'].dt if self.jump < 0: self.is_flame = False - if self.flip: - self.rect.y -= inc - else: - self.rect.y += inc + self.rect.y += -inc if self.flip else inc else: self.is_flame = True - if self.flip: - self.rect.y += inc - else: - self.rect.y -= inc + self.rect.y += inc if self.flip else -inc self.jump -= 1 * self.config['ns'].dt else: self.is_jump = False @@ -110,9 +106,9 @@ def update(self): def blit(self): if self.flip: - self.screen.blit(pygame.transform.flip(self.img, False, True), self.rect) + self.screen.blit(self.img_flip, self.rect) if self.is_flame: - self.screen.blit(pygame.transform.flip(self.img_flame, False, True), self.rect_flame) + self.screen.blit(self.img_flame_flip, self.rect_flame) else: self.screen.blit(self.img, self.rect) if self.is_flame: diff --git a/spaceway/scenes/settings/objects.py b/spaceway/scenes/settings/objects.py index 61ff1dd..25b58e9 100644 --- a/spaceway/scenes/settings/objects.py +++ b/spaceway/scenes/settings/objects.py @@ -1,6 +1,7 @@ import pygame from ...mixins import SettingsButtonMixin, SceneButtonMixin +from ...rect import FloatRect class EffectsButton(SettingsButtonMixin): @@ -62,7 +63,7 @@ def __init__(self, screen, base_dir, config): self.width = self.height = 63 self.img = pygame.image.load(f'{base_dir}/assets/images/buttons/back.bmp') - self.rect = self.img.get_rect() + self.rect = FloatRect(self.img.get_rect()) self.rect.left = self.screen_rect.left + 5 self.rect.top = self.screen_rect.bottom - 5 diff --git a/spaceway/scenes/table/objects.py b/spaceway/scenes/table/objects.py index 45b8e85..9a13521 100644 --- a/spaceway/scenes/table/objects.py +++ b/spaceway/scenes/table/objects.py @@ -1,6 +1,7 @@ import pygame from ...mixins import SceneButtonMixin +from ...rect import FloatRect class TableScore: @@ -59,7 +60,7 @@ def __init__(self, screen, base_dir, config): self.width = self.height = 63 self.img = pygame.image.load(f'{base_dir}/assets/images/buttons/back.bmp') - self.rect = self.img.get_rect() + self.rect = FloatRect(self.img.get_rect()) self.rect.left = self.screen_rect.left + 5 self.rect.top = self.screen_rect.bottom - 5