Skip to content

Commit

Permalink
Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YariKartoshe4ka committed Sep 3, 2020
2 parents 2537301 + 4af4ac1 commit aa933b7
Show file tree
Hide file tree
Showing 22 changed files with 485 additions and 547 deletions.
Binary file added assets/images/asteroid/blue_idle.bmp
Binary file not shown.
Binary file added assets/images/asteroid/red_idle.bmp
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added assets/images/plate/green_fly.bmp
Binary file not shown.
Binary file added assets/images/plate/green_idle.bmp
Binary file not shown.
Binary file added assets/images/plate/pink_fly.bmp
Binary file not shown.
Binary file added assets/images/plate/pink_idle.bmp
Binary file not shown.
Binary file added assets/updater/background.bmp
Binary file not shown.
Binary file added assets/updater/pixeboy.ttf
Binary file not shown.
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"sub_scene": "game",
"speed": 2,
"score": 0,
"version": "1.1.0"
"version": "1.2.0",
"color": 0
}
3 changes: 2 additions & 1 deletion config/user.json
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
}
19 changes: 16 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main():
scenes.headpiece.functions.update(screen, config, text, tick)

elif config['scene'] == 'lobby':
scenes.lobby.functions.check_events(config, base_dir, play_button, table_button, back_button, settings_button)
scenes.lobby.functions.check_events(config, base_dir, play_button, table_button, back_button, settings_button, caption)
scenes.lobby.functions.update(bg, play_button, table_button, settings_button, caption)

elif config['scene'] == 'table':
Expand All @@ -77,13 +77,26 @@ def main():

elif config['scene'] == 'game':
scenes.game.functions.update(screen, config, base_dir, bg, plate, astrs, boosts, score, end, pause, tick)
scenes.game.functions.check_collides(config, base_dir, astrs, boosts, plate, play_button, table_button, settings_button)
scenes.game.functions.check_events(config, base_dir, plate, astrs, end, pause, play_button, table_button, settings_button)
scenes.game.functions.check_collides(config, base_dir, astrs, boosts, plate, play_button, table_button, settings_button, table)
scenes.game.functions.check_events(config, base_dir, plate, astrs, boosts, end, pause, play_button, table_button, settings_button)


if tick >= config['FPS'] * 10:
tick = 0



if config.get('debug'):
print(f'FPS: {clock.get_fps()}', end='\r')

if full_screen_button.state != config['user']['full_screen']:
if config['user']['full_screen']:
screen = pygame.display.set_mode(config['mode'], pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode(config['mode'])
full_screen_button.state = config['user']['full_screen']


pygame.display.update()
clock.tick(config['FPS'])

Expand Down
192 changes: 192 additions & 0 deletions mixins.py
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)
26 changes: 19 additions & 7 deletions scenes/game/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def init(screen, base_dir, config, msg):
return bg, plate, score, end, pause


def check_events(config, base_dir, plate, astrs, end, pause, play, table, settings):
def check_events(config, base_dir, plate, astrs, boosts, end, pause, play, table, settings):
if config['sub_scene'] == 'game':
for event in pygame.event.get():
if event.type == pygame.QUIT:
Expand Down Expand Up @@ -91,6 +91,7 @@ def check_events(config, base_dir, plate, astrs, end, pause, play, table, settin

plate.reset()
astrs.empty()
boosts.empty()
config['speed'] = 2
config['score'] = 0
config['sub_scene'] = 'game'
Expand All @@ -105,6 +106,13 @@ def spawn(screen, base_dir, config, tick, plate, astrs, boosts):
if len(astrs) == 0 or astrs.sprites()[-1].rect.x < config['mode'][0] - 200:
astrs.add(Asrteroid(screen, base_dir, config))

if config['score'] >= 20 and config['score'] % 5 == 0:
for sprite in astrs.copy():
if sprite.name == 'flying':
break
else:
astrs.add(FlyingAsrteroid(screen, base_dir, config))

if len(boosts) == 0:
choice = randint(0, 2)
y = randint(1, config['mode'][1] - 35)
Expand Down Expand Up @@ -141,7 +149,7 @@ def update(screen, config, base_dir, bg, plate, astrs, boosts, score, end, pause
spawn(screen, base_dir, config, tick, plate, astrs, boosts)

for astr in astrs.copy():
if astr.rect.right < 0:
if astr.rect.right < 0 or astr.rect.top > config['mode'][1]:
astrs.remove(astr)
if config['user']['effects']:
pygame.mixer.music.load(plate.sounds['score'])
Expand Down Expand Up @@ -182,14 +190,14 @@ def update(screen, config, base_dir, bg, plate, astrs, boosts, score, end, pause
pause.blit()


def check_collides(config, base_dir, astrs, boosts, plate, play, table, settings):
def check_collides(config, base_dir, astrs, boosts, plate, play, table, settings, score):
astrs_collides = pygame.sprite.spritecollide(plate, astrs, True)
boosts_collides = pygame.sprite.spritecollide(plate, boosts, False)

if astrs_collides:
if config['user']['effects']:
pygame.mixer.music.load(plate.sounds['bang'])
pygame.mixer.music.play()
pygame.mixer.music.load(plate.sounds['bang'])
pygame.mixer.music.play()

for boost in boosts:
if boost.name == 'shield' and boost.is_active:
Expand All @@ -200,6 +208,8 @@ def check_collides(config, base_dir, astrs, boosts, plate, play, table, settings
line = ','.join([str(config['score']), config['user']['nick']]) + '\n'
file.write(line)

score.is_update = True

plate.reset()
astrs.empty()
boosts.empty()
Expand All @@ -224,8 +234,8 @@ def check_collides(config, base_dir, astrs, boosts, plate, play, table, settings

elif plate.rect.bottom >= plate.screen_rect.bottom:
if config['user']['effects']:
pygame.mixer.music.load(plate.sounds['bang'])
pygame.mixer.music.play()
pygame.mixer.music.load(plate.sounds['bang'])
pygame.mixer.music.play()

for boost in boosts:
if boost.name == 'shield' and boost.is_active:
Expand All @@ -237,6 +247,8 @@ def check_collides(config, base_dir, astrs, boosts, plate, play, table, settings
line = ','.join([str(config['score']), config['user']['nick']]) + '\n'
file.write(line)

score.is_update = True

plate.reset()
astrs.empty()
boosts.empty()
Expand Down
Loading

0 comments on commit aa933b7

Please sign in to comment.