Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YariKartoshe4ka committed Oct 1, 2021
2 parents 305e021 + e29eb6e commit eaa9d0f
Show file tree
Hide file tree
Showing 18 changed files with 648 additions and 111 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
on:
push:
tags:
- '*'

name: Release

jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
tag_name: ${{ steps.tag_name.outputs.tag }}
steps:
- name: Get tag name
id: tag_name
uses: olegtarasov/get-tag@v2.1
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_API_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ steps.tag_name.outputs.tag }}
body: |
# Draft release (${{ steps.tag_name.outputs.tag }})
[Guide for updating](https://github.com/YariKartoshe4ka/Space-Way/blob/master/docs/UPDATE.md)
### Changes
draft: true
prerelease: false

build-windows:
name: Build for Windows
runs-on: windows-latest
needs: create-release
steps:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install Pyinstaller
run: pip install pyinstaller==4.3
- name: Checkout code
uses: actions/checkout@v2
- name: Install Space Way
run: pip install .
- name: Build binary
run: pyinstaller --onefile --noconsole --icon=spaceway/icon.ico --collect-all spaceway "Space Way.py"
- name: Upload binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_API_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: "./dist/Space Way.exe"
asset_name: "Space-Way-${{ needs.create-release.outputs.tag_name }}.exe"
asset_content_type: application/exe

publish-pypi:
name: Publish on PyPI
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: pip install build
- name: Checkout code
uses: actions/checkout@v2
with:
ref: pypi
- name: Build project
run: python -m build --sdist --wheel --outdir dist/ .
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Get path to wheel
id: wheel_path
run: |
cd ./dist
echo '::set-output name=path::'$(ls -t *.whl | head -1)
- name: Upload wheel to GitHub
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_API_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./dist/${{ steps.wheel_path.outputs.path }}
asset_name: ${{ steps.wheel_path.outputs.path }}
asset_content_type: application/x-wheel+zip

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 requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pygame==1.9.6
pygame==2.0.2.dev2
packaging==20.4
requests==2.24.0
appdirs==1.4.4
28 changes: 13 additions & 15 deletions spaceway/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import pygame

from .mixins import BoostMixin, SceneButtonMixin


class BoostsGroup(pygame.sprite.Group):
""" Extension of default pygame.sprite.Group for more easier control
Expand All @@ -22,19 +20,19 @@ class BoostsGroup(pygame.sprite.Group):
{<ShieldBoost sprite(in 1 groups)>: 0} """

# Define additional groups
active: Dict[str, BoostMixin] = {}
passive: Dict[BoostMixin, int] = {}
active: Dict[str, 'BoostMixin'] = {}
passive: Dict['BoostMixin', int] = {}

# Define interval for next boost spawn (in score)
next_spawn = 3

def add_internal(self, boost: BoostMixin) -> None:
def add_internal(self, boost: 'BoostMixin') -> None:
""" Adds boost to passive group """

self.passive[boost] = 0
pygame.sprite.Group.add_internal(self, boost)

def remove_internal(self, boost: BoostMixin) -> None:
def remove_internal(self, boost: 'BoostMixin') -> None:
""" Removes boost. If boost is located in passive group,
it simply will remove it from group. If boost is located
in active group, it will update number in queue of other
Expand Down Expand Up @@ -75,15 +73,15 @@ def empty(self) -> None:
# Reset `next_spawn`
self.next_spawn = 3

def __contains__(self, item: Union[str, BoostMixin]) -> bool:
def __contains__(self, item: Union[str, 'BoostMixin']) -> bool:
""" Will return True, if group contains activated
boost with passed name, else - False """

if isinstance(item, str):
return bool(self.get(item))
return self.has(item)

def activate(self, boost: BoostMixin) -> None:
def activate(self, boost: 'BoostMixin') -> None:
""" Activates passed boost and move boost from passive group
to active. If boost with boost's name have already activated,
it will nullify tick (boost timer will start again) """
Expand All @@ -102,7 +100,7 @@ def activate(self, boost: BoostMixin) -> None:
self.active[boost.name] = boost
boost.activate()

def get(self, name: str) -> Union[BoostMixin, None]:
def get(self, name: str) -> Union['BoostMixin', None]:
""" Will return boost if active group contains boost
with passed name. Else it will return `None` """

Expand Down Expand Up @@ -203,9 +201,9 @@ class SceneButtonsGroup(pygame.sprite.Group):
} """

# Define an additional dictionary for structuring buttons by scenes
buttons: Dict[str, Dict[str, List[SceneButtonMixin]]] = {}
buttons: Dict[str, Dict[str, List['SceneButtonMixin']]] = {}

def __init__(self, config, *buttons: List[SceneButtonMixin]) -> None:
def __init__(self, config, *buttons: List['SceneButtonMixin']) -> None:
""" Initialization of group. Pass `config` argument and list of buttons
`buttons` to add them to group """

Expand All @@ -215,7 +213,7 @@ def __init__(self, config, *buttons: List[SceneButtonMixin]) -> None:
# Set `config` for the further use
self.config = config

def add_internal(self, button: SceneButtonMixin) -> None:
def add_internal(self, button: 'SceneButtonMixin') -> None:
""" Adding button to group and structuring by scene """

# If there were not buttons with scene of current button yet
Expand All @@ -231,7 +229,7 @@ def add_internal(self, button: SceneButtonMixin) -> None:

pygame.sprite.Group.add_internal(self, button)

def remove_internal(self, button: SceneButtonMixin) -> None:
def remove_internal(self, button: 'SceneButtonMixin') -> None:
""" Remove button from group. It is assumed that button has already been added """

# Remove button from group
Expand Down Expand Up @@ -281,15 +279,15 @@ def draw(self) -> None:
button.update()
button.blit()

def get_by_scene(self, scene: str = '', sub_scene: str = '') -> List[SceneButtonMixin]:
def get_by_scene(self, scene: str = '', sub_scene: str = '') -> List['SceneButtonMixin']:
""" Returns all buttons of selected scene. If no scene was selected,
buttons of current scene will be returned """

return self.buttons \
.get(scene or self.config['scene'], {}) \
.get(sub_scene or self.config['sub_scene'], [])

def get_by_instance(self, instance: any) -> Union[SceneButtonMixin, None]:
def get_by_instance(self, instance: any) -> Union['SceneButtonMixin', None]:
""" Returns only one button or `None` which is an instance of passed class """

for button in self:
Expand Down
11 changes: 11 additions & 0 deletions spaceway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from appdirs import user_config_dir


class Namespace:
""" Stores variables that do not need to be imported or exported
Since `ConfigManager` is passed everywhere, it allows you to
safely exchange variables from different functions and even
scenes """
pass


class ConfigManager(dict):
""" Configuration manager. Inherited from `dict` class and can be
used as default dictionary. Different configuration files are
Expand Down Expand Up @@ -91,6 +99,9 @@ def __load(self) -> None:

config['score_list'].append((int(score), nick[:-1]))

# Creating namespace for temporary variables
config['ns'] = Namespace()

# Initializing ConfigManager as dictionary
dict.__init__(self, config)

Expand Down
6 changes: 2 additions & 4 deletions spaceway/config/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"caption": "Space Way",
"mode": [700, 450],
"FPS": 30,
"FPS": 60,
"scene": "headpiece",
"sub_scene": "headpiece",
"speed": 2,
"score": 0,
"version": "2.0.1",
"version": "2.1.0",
"debug": false
}
42 changes: 21 additions & 21 deletions spaceway/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
""" Root file with main entrypoint """

import os
from sys import platform

import pygame

from . import scenes, collection, updater
from .config import ConfigManager


def main() -> None:
# Set environment variable for centering window
os.environ['SDL_VIDEO_CENTERED'] = '1'
# Set environment variable for centering window
os.environ['SDL_VIDEO_CENTERED'] = '1'

# Initialization of pygame
pygame.mixer.pre_init(44100, -16, 1, 512)
pygame.init()

# Initialization of pygame
pygame.mixer.pre_init(44100, -16, 1, 512)
pygame.init()

def main() -> None:
""" Main entrypoint of Space Way. Execute this to run game """

# Get base directory to create absolute paths
base_dir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -27,10 +31,8 @@ def main() -> None:
updater.check_software_updates(config['version'], base_dir)

# Сreate screen with accounting for user settings
if config['user']['full_screen']:
screen = pygame.display.set_mode(config['mode'], pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode(config['mode'])
flags = (pygame.FULLSCREEN | pygame.NOFRAME * int(not platform.startswith('win'))) * int(config['user']['full_screen']) | pygame.SCALED
screen = pygame.display.set_mode(config['mode'], flags=flags)

# Configure screen
pygame.display.set_caption(config['caption'])
Expand All @@ -46,8 +48,9 @@ def main() -> None:
debugger.enable_module(debug.DebugStat, screen, base_dir, clock)
debugger.enable_module(debug.DebugHitbox)

# Set tick for calculating the past time in seconds
tick = 0
# Define variables in namespace
config['ns'].dt = 0 # Set delta-time for the further use
config['ns'].tick = 0 # Set tick for calculating the past time in seconds

# Initialization of headpiece scene
text = scenes.headpiece.init(screen, base_dir, config)
Expand Down Expand Up @@ -84,12 +87,12 @@ def main() -> None:

while True:
# Update tick
tick += 1
config['ns'].tick += 1

# Showing a specific scene
if config['scene'] == 'headpiece':
scenes.headpiece.functions.check_events(config, base_dir)
scenes.headpiece.functions.update(screen, config, text, tick)
scenes.headpiece.functions.update(screen, config, text)

elif config['scene'] == 'lobby':
scenes.lobby.functions.check_events(config, base_dir, scene_buttons, caption)
Expand All @@ -105,21 +108,18 @@ def main() -> None:

# If fullscreen button was pressed, change screen to fullscreen and back again
if full_screen_button.changed:
screen = pygame.display.set_mode(config['mode'], pygame.FULLSCREEN * int(full_screen_button.state))
flags = (pygame.FULLSCREEN | pygame.NOFRAME * int(not platform.startswith('win'))) * int(config['user']['full_screen']) | pygame.SCALED
screen = pygame.display.set_mode(config['mode'], flags=flags)
full_screen_button.changed = False

elif config['scene'] == 'game':
scenes.game.functions.check_events(config, base_dir, plate, astrs, boosts, end, pause, scene_buttons)
scenes.game.functions.update(screen, config, base_dir, bg, plate, astrs, boosts, score, end, pause, tick, pause_buttons, end_buttons, scene_buttons)

# Zeroize tick from overflow
if tick >= config['FPS'] * 10:
tick = 0
scenes.game.functions.update(screen, config, base_dir, bg, plate, astrs, boosts, score, end, pause, pause_buttons, end_buttons, scene_buttons)

# Update debugger if debug mode enabled
if config['debug']:
debugger.update()

# Update screen and adjust speed to FPS
pygame.display.update()
clock.tick(config['FPS'])
config['ns'].dt = clock.tick(config['FPS']) * 0.03
Loading

0 comments on commit eaa9d0f

Please sign in to comment.