-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
485 additions
and
547 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
"sub_scene": "game", | ||
"speed": 2, | ||
"score": 0, | ||
"version": "1.1.0" | ||
"version": "1.2.0", | ||
"color": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"nick": "your nick here", | ||
"effects": true, | ||
"full_screen": false | ||
"full_screen": false, | ||
"color": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
import pygame | ||
from json import dump | ||
|
||
|
||
class ButtonMixin: | ||
def __init__(self, screen, base_dir, config, switch): | ||
self.switch = switch | ||
|
||
self.screen = screen | ||
self.screen_rect = self.screen.get_rect() | ||
|
||
self.config = config | ||
|
||
self.settings_path = f'{base_dir}/config/user.json' | ||
|
||
if switch: | ||
self.img = self.imgs['false'] | ||
|
||
self.rect = self.img.get_rect() | ||
|
||
self.rect.center = self.screen_rect.center | ||
|
||
self._screen = pygame.Surface((self.width, self.height), pygame.SRCALPHA) | ||
self._screen.fill((0, 0, 0, 0)) | ||
|
||
self._rect = pygame.Rect(0, 0, self.width, self.height) | ||
self._rect.center = self.rect.center | ||
|
||
self.is_save = False | ||
|
||
def update(self): | ||
if self.is_save and self.switch: | ||
with open(self.settings_path, 'w') as file: | ||
dump(self.config['user'], file, indent=4) | ||
|
||
self.is_save = False | ||
|
||
if self.switch: | ||
self.is_enable = self.config['user'][self.index] | ||
|
||
if self.is_enable: | ||
self.img = self.imgs['true'] | ||
else: | ||
self.img = self.imgs['false'] | ||
|
||
self._rect.center = self.rect.center | ||
|
||
def blit(self): | ||
self.screen.blit(self._screen, self.rect) | ||
self.screen.blit(self.img, self.rect) | ||
self._screen.fill((0, 0, 0, 0), self._rect, pygame.BLEND_RGBA_ADD) | ||
|
||
|
||
class FloatButtonMixin: | ||
def __init__(self, base_dir, config, direction): | ||
self.config = config | ||
|
||
self._screen = pygame.Surface((self.width, self.height), pygame.SRCALPHA) | ||
self._screen.fill((0, 0, 0, 0)) | ||
|
||
self._rect = pygame.Rect(0, 0, self.width, self.height) | ||
self._rect.centerx = self.rect.centerx | ||
self._rect.centery = self.rect.centery | ||
|
||
self.direction = direction | ||
|
||
if direction == 'top': | ||
self.to_bottom = True | ||
self.to_top = False | ||
self.change_scene = False | ||
|
||
elif direction == 'bottom': | ||
self.to_bottom = False | ||
self.to_top = True | ||
self.change_scene = False | ||
|
||
def update(self): | ||
if self.direction == 'top': | ||
if self.to_top: | ||
if self.rect.bottom >= self.screen_rect.top: | ||
self.rect.y -= self.speed | ||
else: | ||
self.to_top = False | ||
|
||
if self.change_scene: | ||
self.change_scene = False | ||
self.config['scene'] = self.scene | ||
|
||
elif self.to_bottom: | ||
if self.rect.centery <= self.screen_rect.centery: | ||
self.rect.y += self.speed | ||
else: | ||
self.to_bottom = False | ||
|
||
elif self.direction == 'bottom': | ||
if self.to_bottom: | ||
if self.rect.top <= self.screen_rect.bottom: | ||
self.rect.y += self.speed | ||
else: | ||
self.to_bottom = False | ||
|
||
if self.change_scene: | ||
self.change_scene = False | ||
self.config['scene'] = self.scene | ||
|
||
elif self.to_top: | ||
if self.rect.bottom + 5 >= self.screen_rect.bottom: | ||
self.rect.y -= self.speed | ||
else: | ||
self.to_top = False | ||
|
||
self._rect.center = self.rect.center | ||
|
||
def blit(self): | ||
self.screen.blit(self._screen, self.rect) | ||
self.screen.blit(self.img, self.rect) | ||
self._screen.fill((0, 0, 0, 0), self._rect, pygame.BLEND_RGBA_ADD) | ||
|
||
|
||
class CaptionMixin: | ||
def __init__(self, base_dir, config, caption, fields=[]): | ||
self.config = config | ||
|
||
self.fields = fields | ||
self.caption = caption | ||
|
||
self.fg_color = (255, 255, 255) | ||
self.border = 1 | ||
self.font = pygame.font.Font(f'{base_dir}/assets/fonts/pixeboy.ttf', 72) | ||
|
||
self._update() | ||
|
||
def _update(self): | ||
self.img = self.font.render(self.caption.format(eval('list(map(eval, self.fields))')), True, self.fg_color) | ||
|
||
self.colors = [self.font.render(self.caption.format(eval('list(map(eval, self.fields))')), True, (0, 153, 255)), | ||
self.font.render(self.caption.format(eval('list(map(eval, self.fields))')), True, (252, 15, 192)), | ||
self.font.render(self.caption.format(eval('list(map(eval, self.fields))')), True, (0, 255, 0))] | ||
|
||
self.rect = self.img.get_rect() | ||
|
||
def _blit(self): | ||
self.screen.blit(self.colors[self.config['user']['color']], (self.rect.x + self.border, self.rect.y)) | ||
self.screen.blit(self.colors[self.config['user']['color']], (self.rect.x - self.border, self.rect.y)) | ||
self.screen.blit(self.colors[self.config['user']['color']], (self.rect.x, self.rect.y + self.border)) | ||
self.screen.blit(self.colors[self.config['user']['color']], (self.rect.x, self.rect.y - self.border)) | ||
self.screen.blit(self.img, self.rect) | ||
|
||
|
||
class BoostMixin: | ||
def __init__(self, base_dir, config): | ||
self.config = config | ||
|
||
self.fg_color = (255, 255, 255) | ||
self.bg_color = (255, 0, 0) | ||
self.font = pygame.font.Font(f'{base_dir}/assets/fonts/pixeboy.ttf', 28) | ||
|
||
self.is_active = False | ||
self.life = 5 | ||
self.tick = 0 | ||
|
||
def _update(self): | ||
if self.is_active: | ||
if (self.life * self.config['FPS'] - self.tick) // self.config['FPS'] + 1 <= 3: | ||
self.img_2 = self.font.render(f"{(self.life * self.config['FPS'] - self.tick) // self.config['FPS'] + 1}S", True, self.bg_color) | ||
self.rect_2 = self.img_2.get_rect() | ||
self.rect_2.top = self.screen_rect.top + 2 | ||
self.rect_2.left = self.screen_rect.left + 24 | ||
else: | ||
self.img_2 = self.font.render(f"{(self.life * self.config['FPS'] - self.tick) // self.config['FPS'] + 1}S", True, self.fg_color) | ||
self.rect_2 = self.img_2.get_rect() | ||
self.rect_2.top = self.screen_rect.top + 2 | ||
self.rect_2.left = self.screen_rect.left + 24 | ||
|
||
if self.life * self.config['FPS'] - self.tick <= 0: | ||
if self.name == 'time': | ||
self.config['speed'] = self.speed | ||
self.kill() | ||
else: | ||
self.tick += 1 | ||
else: | ||
self.rect.x -= self.config['speed'] | ||
|
||
if self.rect.right < 0: | ||
self.kill() | ||
|
||
def _blit(self): | ||
if self.is_active: | ||
self.screen.blit(self.img_2, self.rect_2) | ||
self.screen.blit(self.img_3, self.rect_3) | ||
else: | ||
self.screen.blit(self.img, self.rect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.