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

Commit

Permalink
Change some visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
ShelkovkinaM committed Feb 14, 2024
1 parent de50aaf commit 4fe8be8
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 37 deletions.
Binary file modified assets/DataBase.db
Binary file not shown.
Binary file added assets/textures/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion danmaku/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_saved_game() -> dict:

def get_game_history() -> list:
"""Get game history from database
Returns list: [{"score", "level"}]
Returns list: [{"score", "level", "time"}]
"""
games = tuple(iter(SavedGame.select()))
res = []
Expand All @@ -106,6 +106,12 @@ def get_game_history() -> list:
return res


def delete_last_game():
games = list(iter(SavedGame.select()))
SavedGame.delete_by_id(games[-1])
SavedGame.update()


def set_saved_objects(name: str, objects: Iterable) -> None:
"""Set saved objects to database"""
for e in objects:
Expand Down
9 changes: 7 additions & 2 deletions danmaku/game/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ def __init__(
y: int | float,
width: int | float,
height: int | float,
frames: list[str]
):
self.frame_count = 48
frames = [f"background/background_{i}.png" for i in range(self.frame_count)]
if not frames:
self.frame_count = 48
frames = [f"background/background_{i}.png" for i in range(self.frame_count)]
else:
pass

super().__init__((x, y), (width, height), 0, frames, 0, period=0.1)
self.texture_size = self.width, self.height

Expand Down
33 changes: 19 additions & 14 deletions danmaku/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
set_saved_game,
delete_saved_objects,
get_settings,
delete_last_game
)
from danmaku.game.pause import Pause
from danmaku.game.background import Background
Expand All @@ -27,6 +28,7 @@ class Game(vgame.Scene):
new_game: bool = True

def load(self):
self.game_border = self.width * 2 // 3
STAGE1 = Stage([Enemy((150, 15), "basic enemy")])
STAGE2 = Stage(
[Enemy((50, -25), "basic enemy"), Enemy((200, -50), "basic enemy")]
Expand Down Expand Up @@ -106,7 +108,7 @@ def load(self):
self.pause_object = Pause()
self.exit_status = ""

self.background_object = Background(0, 0, self.width // 2, self.height)
self.background_object = Background(0, 0, self.game_border, self.height, [])

self.bullets: list[Bullet] = []
self.drops: list[Drop] = []
Expand All @@ -118,7 +120,7 @@ def load(self):
self.last_time = 0
self.enemies: list[Enemy] = list(self.levels[self.current_level].enemies)
self.player = Player(
(self.width // 4, self.height - 50),
(self.game_border // 2, self.height - 50),
"player",
bombs=get_settings()["bombs"]["value"],
lives=get_settings()["lives"]["value"],
Expand Down Expand Up @@ -155,6 +157,7 @@ def load(self):
case "points":
self.drops.append(Points(entity["object_position"]))


saved_game = get_saved_game()
self.current_level: int = saved_game["level"]
self.player.score = saved_game["score"]
Expand All @@ -163,8 +166,9 @@ def load(self):
self.last_time = saved_game["time"]
self.start_time = pygame.time.get_ticks()
delete_saved_objects()
delete_last_game()

self.player.set_bounds(0, 0, self.width // 2, self.height)
self.player.set_bounds(0, 0, self.game_border, self.height)

def update_pause(self):
"""Called from update loop if paused"""
Expand All @@ -173,8 +177,6 @@ def update_pause(self):
match status:
case "continue":
self.paused = False
case "settings":
raise NotImplementedError()
case "menu":
delete_saved_objects()
set_saved_objects("enemy", self.enemies)
Expand Down Expand Up @@ -219,6 +221,8 @@ def update_game(self):
stage.update()
if isinstance(stage, BossStage):
self.boss_hp = stage.boss.health
if stage.boss.health < 0:
self.boss_hp = None
else:
self.boss_hp = None

Expand All @@ -229,7 +233,7 @@ def update_game(self):
enemy.animate()
enemy.update(self.delta)
if (
enemy.y > self.height / 2 and not 0 <= enemy.x < self.width // 2
enemy.y > self.height / 2 and not 0 <= enemy.x < self.game_border
) or enemy.y > self.height + enemy.height / 2:
self.enemies.remove(enemy)

Expand All @@ -255,7 +259,7 @@ def update_game(self):
bullet.update(self.delta)

if not not_in_border(
bullet.x, bullet.y, bullet.vx, bullet.vy, self.width // 2, self.height
bullet.x, bullet.y, bullet.vx, bullet.vy, self.game_border, self.height
):
self.bullets.remove(bullet)

Expand All @@ -271,7 +275,7 @@ def update_game(self):
drop.update(self.delta)

if not not_in_border(
drop.x, drop.y, drop.vx, drop.vy, self.width // 2, self.height
drop.x, drop.y, drop.vx, drop.vy, self.game_border, self.height
):
self.drops.remove(drop)

Expand Down Expand Up @@ -320,7 +324,7 @@ def update(self):
self.pressed_keys.remove(Keys.ESCAPE)
self.paused = not self.paused
if self.paused:
self.pause_object.load(self.width, self.height)
self.pause_object.load(self.width, self.height, self.delta)

if self.paused:
self.update_pause()
Expand All @@ -332,6 +336,7 @@ def update(self):
self.update_game()

def draw(self):
self.graphics.rectangle((0, 0), (self.width, self.height), (30, 157, 214, 180))
self.graphics.draw_sprite(self.background_object)

self.player.draw(self.graphics)
Expand All @@ -345,14 +350,14 @@ def draw(self):
for drop in self.drops:
self.graphics.draw_sprite(drop)

self.graphics.text(f"HP: {self.player.health}", (self.width // 1.7, 0))
self.graphics.text(f"Score: {self.player.score}", (self.width // 1.7, 50))
self.graphics.text(f"HP: {self.player.health}", (self.game_border + 10, 0))
self.graphics.text(f"Score: {self.player.score}", (self.game_border + 10, 50))
self.graphics.text(
f"Time: {round(self.current_time, 1)}", (self.width // 1.7, 100)
f"Time: {round(self.current_time, 1)}", (self.game_border + 10, 100)
)
self.graphics.text(f"Bombs: {self.player.bombs}", (self.width // 1.7, 150))
self.graphics.text(f"Bombs: {self.player.bombs}", (self.game_border + 10, 150))
if self.boss_hp is not None:
self.graphics.text(f"BOSS: {self.boss_hp}", (self.width // 1.7, 200))
self.graphics.text(f"BOSS: {self.boss_hp}", (self.game_border + 10, 200))

if self.paused:
self.pause_object.draw(self.graphics)
Expand Down
34 changes: 23 additions & 11 deletions danmaku/game/pause.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"""In-game pause menu."""

import vgame
from danmaku.game.background import Background
from danmaku.ui.button import Button, Cursor


# pylint: disable=attribute-defined-outside-init, missing-class-docstring
class Pause:
def load(self, width, height):
def load(self, width, height, delta):
"""Load pause menu."""
self.selection_index = 0
self.delta = delta

self.cursor = Cursor((10, 100))

self.width, self.height = width, height
self.background_object = Background(0, 0, self.width, self.height, ["menu.png"])

self.buttons = (
("Continue", "continue"),
("Settings", "settings"),
("Main menu", "menu"),
Button("Continue", "continue"),
Button("Main menu", "menu")
)

self.exit_status: str = ""
Expand All @@ -28,16 +33,23 @@ def update(self, pressed_keys):
pressed_keys.discard(vgame.Keys.DOWN)
self.selection_index = (self.selection_index + 1) % len(self.buttons)
if {vgame.Keys.RETURN, vgame.Keys.Z, vgame.Keys.SPACE} & pressed_keys:
self.exit_status = self.buttons[self.selection_index][1]
self.exit_status = self.buttons[self.selection_index].codename
self.cursor.y = 100 + self.selection_index * 50
self.cursor.update(self.delta)

def draw(self, graphics: vgame.graphics.Graphics):
"""Draw pause menu."""
graphics.rectangle((0, 0), (self.width, self.height), (0, 0, 0, 180))
graphics.text("Danmaku", (0, 10), (255, 255, 180))
graphics.draw_sprite(self.background_object)
graphics.text("Danmaku", (self.width // 2 - 70, 10), (0, 74, 127))

self.cursor.draw(graphics)

for i, button in enumerate(self.buttons):
selected_color = (0, 74, 127)
color = selected_color if i == self.selection_index else (255, 255, 255)

graphics.text(
button[0],
(0, 100 + i * 50),
(255, 200, 180) if i == self.selection_index else (255, 255, 255),
)
button.text,
(70, 100 + i * 50),
color,
)
2 changes: 1 addition & 1 deletion danmaku/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def bomb(self) -> list[Bullet]:
if self.can_shoot():
bullet = Bullet(
(self.x, self.y),
self.damage + self.power + 50,
(self.damage + self.power) * 30,
"player bomb",
)
res.append(bullet)
Expand Down
6 changes: 4 additions & 2 deletions danmaku/ui/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def update(self):
self.stop()

def draw(self):
self.graphics.text("History", (0, 0), (255, 255, 180))
self.graphics.rectangle((0, 0), (self.width, self.height), (30, 157, 214, 180))

self.graphics.text("History", (self.width // 2 - 30, 0), (0, 74, 127))

for i, game in enumerate(self.history[self.selection_index :]):
self.graphics.text(
f"Level: {game['level'] + 1}, Score: {game['score']}, Time: {game['time']}",
(0, 100 + 50 * i),
(20, 50 + 50 * i),
(255, 255, 255),
)

Expand Down
9 changes: 7 additions & 2 deletions danmaku/ui/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from danmaku.database import get_saved_objects
from danmaku.ui.button import Button, Cursor
from danmaku.utils import resource_path
from danmaku.game.background import Background


# pylint: disable=attribute-defined-outside-init, missing-class-docstring
Expand All @@ -15,6 +16,8 @@ def load(self):

self.selection_index = 0

self.background_object = Background(0, 0, self.width, self.height, ["menu.png"])

self.buttons = (
Button("New game", "new_game"),
Button("Continue", "continue"),
Expand Down Expand Up @@ -60,12 +63,14 @@ def update(self):
self.cursor.update(self.delta)

def draw(self):
self.graphics.text("Danmaku", (0, 10), (255, 255, 180))
self.graphics.draw_sprite(self.background_object)

self.graphics.text("Danmaku", (self.width // 2 - 70, 10), (0, 74, 127))

self.cursor.draw(self.graphics)

for i, button in enumerate(self.buttons):
selected_color = (180, 255, 255)
selected_color = (0, 74, 127)
if button.codename == "continue":
if not get_saved_objects():
selected_color = (255, 100, 100)
Expand Down
10 changes: 6 additions & 4 deletions danmaku/ui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,25 @@ def update(self):
self.stop()

def draw(self):
self.graphics.text("Danmaku", (0, 10), (255, 255, 180))
self.graphics.rectangle((0, 0), (self.width, self.height), (30, 157, 214, 180))

self.graphics.text("Settings", (self.width // 2 - 40, 0), (0, 74, 127))

for i, button in enumerate(self.buttons):

color = (255, 200, 180) if i == self.selection_index else (255, 255, 255)
color = (0, 74, 127) if i == self.selection_index else (255, 255, 255)

if isinstance(button, Button):
self.graphics.text(
button.text,
(0, 100 + i * 50),
(20, 100 + i * 50),
color,
)

if isinstance(button, SettingsValue):
self.graphics.text(
f"{button.text}: < {button.value} >",
(0, 100 + i * 50),
(20, 100 + i * 50),
color,
)

Expand Down

0 comments on commit 4fe8be8

Please sign in to comment.