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

Commit

Permalink
Merge branch 'dev' of github.com:virashu/danmaku into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Virashu committed Feb 13, 2024
2 parents 2abca4e + e1986ee commit 394b735
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 弾幕 (Danmaku)
![pylint](https://img.shields.io/badge/PyLint-9.64-yellow?logo=python&logoColor=white)
![pylint](https://img.shields.io/badge/PyLint-9.57-yellow?logo=python&logoColor=white)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## Goal
Expand Down
Binary file modified assets/DataBase.db
Binary file not shown.
2 changes: 1 addition & 1 deletion danmaku/database/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
texture_size_height=50,
speed=200,
shoot_v=250,
hp=1300,
hp=500,
dm=10,
endurance=1,
hitbox_radius=10,
Expand Down
6 changes: 3 additions & 3 deletions danmaku/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_saved_objects() -> list:

def get_saved_game() -> dict:
"""Get saved game from database
Returns dict: {"score", "level", "power"}
Returns dict: {"score", "level", "power", "bombs"}
"""
game = tuple(iter(SavedGame.select().dicts()))[-1]
return game
Expand Down Expand Up @@ -122,9 +122,9 @@ def set_saved_objects(name: str, objects: Iterable) -> None:
n.save()


def set_saved_game(cur_level: int, score: int, power: int) -> None:
def set_saved_game(cur_level: int, score: int, power: int, bombs: int) -> None:
"""Set saved game to database"""
n = SavedGame.create(score=score, level=cur_level, power=power)
n = SavedGame.create(score=score, level=cur_level, power=power, bombs=bombs)
n.save()


Expand Down
1 change: 1 addition & 0 deletions danmaku/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SavedGame(BaseModel):
level = IntegerField()
score = IntegerField()
power = IntegerField()
bombs = IntegerField()


class Settings(BaseModel):
Expand Down
11 changes: 7 additions & 4 deletions danmaku/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def load(self):
if self.new_game:
self.current_level: int = 0
self.enemies: list[Enemy] = list(LEVELS[self.current_level].enemies)
self.player = Player((self.width // 2, self.height - 50), "player")
self.player = Player((self.width // 2, self.height - 50), "player",
bombs=get_settings()["bombs"]["value"], lives=get_settings()["lives"]["value"])

else:
self.enemies: list[Enemy] = []
Expand Down Expand Up @@ -145,6 +146,7 @@ def load(self):
self.current_level: int = saved_game["level"]
self.player.score = saved_game["score"]
self.player.power = saved_game["power"]
self.player.bombs = saved_game["bombs"]
delete_saved_objects()

self.player.set_bounds(0, 0, self.width, self.height)
Expand All @@ -163,7 +165,7 @@ def update_pause(self):
set_saved_objects("enemy", self.enemies)
set_saved_objects("bullet", self.bullets)
set_saved_objects("player", [self.player])
set_saved_game(self.current_level, self.player.score, self.player.power)
set_saved_game(self.current_level, self.player.score, self.player.power, self.player.bombs)
self.stop()

def update_game(self):
Expand Down Expand Up @@ -247,7 +249,7 @@ def update_game(self):
self.next_level()

if self.player.health <= 0:
set_saved_game(self.current_level, self.player.score, self.player.power)
set_saved_game(self.current_level, self.player.score, self.player.power, self.player.bombs)
self.exit_status = "lose"
death_sfx = pygame.mixer.Sound(resource_path("sounds/death.wav"))
death_sfx.set_volume(self.settings["sfx_volume"]["value"] / 100)
Expand All @@ -264,7 +266,7 @@ def next_level(self) -> None:
self.current_level += 1
self.enemies = list(LEVELS[self.current_level].enemies)
else:
set_saved_game(self.current_level, self.player.score, self.player.power)
set_saved_game(self.current_level, self.player.score, self.player.power, self.player.bombs)
self.exit_status = "win"
self.stop()

Expand Down Expand Up @@ -297,6 +299,7 @@ def draw(self):

self.graphics.text(f"HP: {self.player.health}", (0, 0))
self.graphics.text(f"Score: {self.player.score}", (150, 0))
# self.graphics.text(f"Bombs: {self.player.bombs}", (100, 0))
self.graphics.text(f"Score: {self.player.score}", (150, 0))

if self.paused:
Expand Down
2 changes: 1 addition & 1 deletion danmaku/pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update(self, pressed_keys):

def draw(self, graphics: vgame.graphics.Graphics):
"""Draw pause menu."""
graphics.rectangle((0, 0), (self.width, self.height), (0, 0, 0, 180), alpha=1)
graphics.rectangle((0, 0), (self.width, self.height), (0, 0, 180)) #, alpha=1)
graphics.text("Danmaku", (0, 10), (255, 255, 180))

for i, button in enumerate(self.buttons):
Expand Down
21 changes: 12 additions & 9 deletions danmaku/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Player(Shooter, Animated):
"""Player object."""

def __init__(
self, xy: tuple[int | float, int | float], object_type: str, updated_hp=0
self, xy: tuple[int | float, int | float], object_type: str, bombs=0, lives=1, updated_hp=0
) -> None:
args = get_player_type(object_type)

health = updated_hp or args["hp"]
health = updated_hp or args["hp"] * lives

super().__init__(
xy,
Expand Down Expand Up @@ -63,6 +63,7 @@ def __init__(
self.my_type = object_type
self.score: int = 0
self.power: int = 1
self.bombs = bombs

self.hitbox_radius = args["hitbox_radius"]
self.slow = False
Expand Down Expand Up @@ -108,13 +109,15 @@ def shoot(self) -> list[Bullet]:
def bomb(self) -> list[Bullet]:
"""Spawn bomb, AKA super-bullet"""
res: list[Bullet] = []
if self.can_shoot():
bullet = Bullet(
(self.x, self.y),
self.damage + self.power + 50,
"player bomb",
)
res.append(bullet)
if self.bombs != 0:
if self.can_shoot():
bullet = Bullet(
(self.x, self.y),
self.damage + self.power + 50,
"player bomb",
)
res.append(bullet)
self.bombs -= 1
return res

def set_bounds(
Expand Down
5 changes: 3 additions & 2 deletions danmaku/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def load(self):

settings_dict = get_settings()

self.buttons: list[object] = [
self.buttons: list[object] = []
"""= [
SettingsValue("music_volume", "Music Volume", (0, 25, 50, 75, 100), 50),
]
]"""

for key, value in settings_dict.items():
self.buttons.append(
Expand Down

0 comments on commit 394b735

Please sign in to comment.