Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
Types & Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Virashu committed Feb 18, 2024
1 parent 9dc8b86 commit 138e971
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
4 changes: 4 additions & 0 deletions danmaku/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def get_game_history() -> list[dict[str, int]]:


def delete_last_game():
"""Remove last game record from database"""
games = list(iter(SavedGame.select()))
SavedGame.delete_by_id(games[-1])
SavedGame.update()
Expand Down Expand Up @@ -155,6 +156,7 @@ def delete_saved_objects() -> None:


def get_settings() -> dict:
"""Get all settings"""
settings = {}
for setting in Settings.select():
match setting.type:
Expand All @@ -178,12 +180,14 @@ def get_settings() -> dict:


def delete_settings():
"""Delete all settings"""
for setting in Settings.select():
Settings.delete_by_id(setting)
Settings.update()


def set_settings(settings: dict) -> None:
"""Set settings from dictionary"""
for key, value in settings.items():
s = Settings.get(Settings.name == key)
s.value = value
Expand Down
2 changes: 1 addition & 1 deletion danmaku/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
db = SqliteDatabase(resource_path("DataBase.db"))


# pylint: disable=missing-class-docstring
# pylint: disable=missing-class-docstring,too-few-public-methods


class BaseModel(Model):
Expand Down
3 changes: 3 additions & 0 deletions danmaku/game/animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def animate(self) -> None:


class AnimatedDirectional(Animated):
"""Base class for animated objects, that change animations based on direction"""

def __init__(
self,
xy: tuple[int | float, int | float],
Expand Down Expand Up @@ -121,6 +123,7 @@ def animate(
direction = Direction.LEFT
elif direction_vector[1] < 0:
direction = Direction.UP

if direction == Direction.STATIC:
a = ""
if self.last_direction == Direction.UP:
Expand Down
2 changes: 2 additions & 0 deletions danmaku/game/enemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def shoot_radial(
def shoot_cluster(
self, waves: int = 1, n: int = 10, base_angle: int = 0, arc: int = 180
) -> list[Bullet]:
"""Shoot spiral wave of bullets"""
bullets: list[Bullet] = []
for wave in range(waves):
for i, a in enumerate(range(0, arc, arc // n)):
Expand All @@ -106,6 +107,7 @@ def shoot_cluster(
return bullets

def generate_drops(self) -> list[Drop]:
"""Generate drops"""
drops: list[Drop] = []
count = 1
if self.my_type == "boss":
Expand Down
4 changes: 3 additions & 1 deletion danmaku/game/entity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Base class for alive objects"""

from danmaku.game.gameobject import GameObject
import pygame

from danmaku.database import get_settings
from danmaku.game.gameobject import GameObject
from danmaku.utils import resource_path


Expand Down Expand Up @@ -31,6 +32,7 @@ def get_damage(self, damage: int | float):
self.damage_sound(3)

def damage_sound(self, channel: int):
"""Play damage sound"""
pygame.mixer.init()
sound = pygame.mixer.Sound(resource_path("sounds/hit.wav"))
sound.set_volume(get_settings()["sfx_volume"]["value"] / 100)
Expand Down
24 changes: 23 additions & 1 deletion danmaku/game/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@


class Stage:
"""Base stage
Contains enemies"""

_enemies: list[Enemy]

_start_time: int
Expand All @@ -23,14 +27,20 @@ def __init__(self, enemies: list[Enemy]) -> None:

self._start_time = pygame.time.get_ticks()

def update(self) -> None: ...
def update(self) -> None:
"""WIP
Update all enemies on the stage"""

@property
def enemies(self) -> list[Enemy]:
"""Enemies on the stage"""
return self._enemies


class BossStage(Stage):
"""Stage centered on boss"""

# +enemies: list[Enemy]
_boss: Enemy

Expand Down Expand Up @@ -60,6 +70,7 @@ def update(self) -> None:

@property
def boss(self) -> Enemy:
"""Boss property"""
return self._boss

@property
Expand All @@ -68,6 +79,12 @@ def enemies(self) -> list[Enemy]:


class Level:
"""Game level
Contains stages
For chapter separation by theme
(can contain only one boss, but with multiple boss stages)"""

stages: list[Stage]
current_stage: int

Expand All @@ -86,15 +103,20 @@ def __getitem__(self, index: int) -> Stage:

@property
def stage(self) -> Stage:
"""Current stage"""
return self.stages[self.current_stage]

def next_stage(self) -> bool:
"""Switch stage to next if possible
Returns: bool - success"""
if len(self.stages) > self.current_stage + 1:
self.current_stage += 1
self.enemies = list(self.stages[self.current_stage].enemies)
return True
return False

def set_stage(self, index: int) -> None:
"""Set stage by index"""
self.current_stage = index
self.enemies = list(self.stages[self.current_stage].enemies)
7 changes: 1 addition & 6 deletions danmaku/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,7 @@ def update(self, delta: int | float) -> None:
self.y, self.top + self.height / 2, self.bottom - self.height / 2
)

self.rect.centerx, self.rect.centery, self.rect.w, self.rect.h = (
int(self.x),
int(self.y),
int(self.width),
int(self.height),
)
super().update(0)

def draw(self, graphics: vgame.graphics.Graphics) -> None:
graphics.draw_sprite(self)
Expand Down
1 change: 1 addition & 0 deletions danmaku/game/shooter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def can_shoot(self) -> bool:
return False

def shoot_sound(self, channel: int):
"""Play sound of shooting"""
pygame.mixer.init()
sound = pygame.mixer.Sound(resource_path("sounds/shoot.wav"))
sound.set_volume(get_settings()["sfx_volume"]["value"] / 100)
Expand Down

0 comments on commit 138e971

Please sign in to comment.