Skip to content

Commit

Permalink
Исправление недочетов, небольшая оптимизация, подготовка к релизу
Browse files Browse the repository at this point in the history
  • Loading branch information
YariKartoshe4ka committed Oct 1, 2021
1 parent 518dfe2 commit e29eb6e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 35 deletions.
2 changes: 2 additions & 0 deletions docs/CODESTYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Now project has this structure:
|____ debug.py
|____ main.py
|____ mixins.py
|____ rect.py
|____ updater.py
|____ assets
| |____ <fonts, sprites, sounds and other binary files...>
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion spaceway/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"FPS": 60,
"scene": "headpiece",
"sub_scene": "headpiece",
"version": "2.0.1",
"version": "2.1.0",
"debug": false
}
20 changes: 0 additions & 20 deletions spaceway/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 8 additions & 12 deletions spaceway/scenes/game/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion spaceway/scenes/settings/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pygame

from ...mixins import SettingsButtonMixin, SceneButtonMixin
from ...rect import FloatRect


class EffectsButton(SettingsButtonMixin):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spaceway/scenes/table/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pygame

from ...mixins import SceneButtonMixin
from ...rect import FloatRect


class TableScore:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e29eb6e

Please sign in to comment.