Add demo GIF, Hot Air Baloon, add a way to customize notification timeout, rows and columns, make main menu buttons smaller, fix tetris not updating info label after restart

This commit is contained in:
csd4ni3l
2025-09-21 21:02:48 +02:00
parent 183eca33c5
commit 944b5ab212
13 changed files with 240 additions and 79 deletions

View File

@@ -2,8 +2,6 @@ import arcade, arcade.gui, time, random, os, json
from plyer import notification
from utils.constants import ROWS, COLS
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
@@ -18,8 +16,11 @@ class Game(arcade.gui.UIView):
self.should_jump = False
self.last_update_time = time.perf_counter()
with open("settings.json", "r") as file:
self.settings = json.load(file)
self.pipes = []
self.bird_position = [0, int(ROWS / 2)]
self.bird_position = [0, int(self.settings.get("notification_rows", 20) / 2)]
self.cycles = 0
if not os.path.exists("data.json"):
@@ -38,25 +39,25 @@ class Game(arcade.gui.UIView):
if pipe_type == "bottom":
bottom = 0
else:
bottom = ROWS - size
bottom = self.settings.get("notification_rows", 20) - size
left = COLS
left = self.settings.get("notification_cols", 25)
for pipe_y in range(bottom, bottom + size):
self.pipes.append([left, pipe_y])
def create_pipe(self):
gap_size = ROWS // 5
gap_start = random.randint(1, ROWS - gap_size - 1)
gap_size = self.settings.get("notification_rows", 20) // 5
gap_start = random.randint(1, self.settings.get("notification_rows", 20) - gap_size - 1)
bottom_height = gap_start
self.create_pipe_part(bottom_height, "bottom")
top_height = ROWS - (gap_start + gap_size)
top_height = self.settings.get("notification_rows", 20) - (gap_start + gap_size)
self.create_pipe_part(top_height, "top")
def on_update(self, delta_time):
if self.running and time.perf_counter() - self.last_update_time >= 0.4:
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.pipes = [[pipe_x - 1, pipe_y] for pipe_x, pipe_y in self.pipes if pipe_x - 1 >= 0]
if self.should_jump:
@@ -67,7 +68,7 @@ class Game(arcade.gui.UIView):
jumped = False
self.bird_position[1] += 2
if self.bird_position in self.pipes or self.bird_position[1] >= ROWS or self.bird_position[1] <= 0:
if self.bird_position in self.pipes or self.bird_position[1] >= self.settings.get("notification_rows", 20) or self.bird_position[1] <= 0:
self.info_label.text = "Game Over.\nPress r to restart"
self.running = False
@@ -87,8 +88,8 @@ class Game(arcade.gui.UIView):
text = ""
for y in range(ROWS):
for x in range(COLS):
for y in range(self.settings.get("notification_rows", 20)):
for x in range(self.settings.get("notification_cols", 25)):
if [x, y] in self.pipes:
text += "|"
elif [x, y] == self.bird_position:
@@ -135,7 +136,7 @@ class Game(arcade.gui.UIView):
self.last_update_time = time.perf_counter()
self.bird_position = [0, int(ROWS / 2)]
self.bird_position = [0, int(self.settings.get("notification_rows", 20) / 2)]
self.cycles = 0
self.should_jump = False

137
game/hot_air_baloon.py Normal file
View File

@@ -0,0 +1,137 @@
import arcade, arcade.gui, time, random, os, json
from plyer import notification
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Playing Hot Air Baloon inside notifications!")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.info_label = self.anchor.add(arcade.gui.UILabel("Use arrow keys or WASD to move\nYou can see the game inside notifications.", font_size=24, multiline=True))
self.running = True
self.last_update_time = time.perf_counter()
self.spikes = []
self.points = []
with open("settings.json", "r") as file:
self.settings = json.load(file)
self.baloon_position = arcade.math.Vec2(0, self.settings.get("notification_rows", 20) - 1)
self.baloon_direction = arcade.math.Vec2()
if not os.path.exists("data.json"):
self.data = {}
else:
with open("data.json", "r") as file:
self.data = json.load(file)
if "hot_air_baloon" not in self.data:
self.data["hot_air_baloon"] = {"high_score": 0}
self.score = 0
self.high_score = self.data["hot_air_baloon"]["high_score"]
self.last_spawn_time = time.perf_counter()
self.spawn_interval = 0.8
self.difficulty = 0.4
self.pattern_cooldown = 0
self.pattern = []
def spawn_items(self):
if self.pattern_cooldown <= 0:
pattern_type = random.choice(["wave", "gap", "scatter"])
if pattern_type == "wave":
base = random.randint(0, self.settings.get("notification_cols", 25) - 4)
self.pattern = [(base + i, 0) for i in range(3)]
elif pattern_type == "gap":
gap = random.randint(1, self.settings.get("notification_cols", 25) - 2)
self.pattern = [(x, 0) for x in range(self.settings.get("notification_cols", 25)) if x != gap]
else:
self.pattern = [(random.randint(0, self.settings.get("notification_cols", 25) - 1), 0) for _ in range(random.randint(2, 4))]
self.pattern_cooldown = random.randint(3, 6)
for pos in self.pattern:
if random.random() < self.difficulty:
self.spikes.append(pos)
else:
self.points.append(pos)
self.pattern_cooldown -= 1
def on_show_view(self):
super().on_show_view()
self.spawn_items()
def on_update(self, delta_time):
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.last_update_time = time.perf_counter()
self.baloon_position += self.baloon_direction
self.baloon_direction = arcade.math.Vec2()
self.baloon_position = arcade.math.Vec2(max(0, min(self.settings.get("notification_cols", 25) - 1, self.baloon_position.x)), max(0, min(self.settings.get("notification_rows", 20) - 1, self.baloon_position.y)))
self.spikes = [(x, y + 1) for x, y in self.spikes if y < self.settings.get("notification_rows", 20)]
self.points = [(x, y + 1) for x, y in self.points if y < self.settings.get("notification_rows", 20)]
if (self.baloon_position.x, self.baloon_position.y) in self.points:
self.score += 1
self.points.remove((self.baloon_position.x, self.baloon_position.y))
self.difficulty = min(0.9, self.difficulty + 0.01)
elif (self.baloon_position.x, self.baloon_position.y) in self.spikes:
self.running = False
self.info_label.text = f"Game Over! Score: {self.score}\nPress r to restart"
if time.perf_counter() - self.last_spawn_time >= self.spawn_interval:
self.last_spawn_time = time.perf_counter()
self.spawn_items()
text = ""
for y in range(self.settings.get("notification_rows", 20)):
for x in range(self.settings.get("notification_cols", 25)):
if arcade.math.Vec2(x, y) == self.baloon_position:
text += "O"
elif (x, y) in self.spikes:
text += "E"
elif (x, y) in self.points:
text += "o"
else:
text += "_"
text += "\n"
notification.notify(
title=f"Hot Air Baloon | Score: {self.score} High Score: {self.high_score}",
message=text
)
def on_key_press(self, symbol, modifiers):
if symbol == arcade.key.ESCAPE:
if self.score > self.high_score:
self.high_score = self.score
self.data["hot_air_baloon"]["high_score"] = self.high_score
with open("data.json", "w") as file:
file.write(json.dumps(self.data, indent=4))
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
elif symbol == arcade.key.R and not self.running:
self.info_label.text = "Use arrow keys or WASD to move\nThe game is shown inside notifications."
self.spikes.clear()
self.points.clear()
self.baloon_position = arcade.math.Vec2(0, self.settings.get("notification_rows", 20) - 1)
self.baloon_direction = arcade.math.Vec2()
self.score = 0
self.running = True
self.difficulty = 0.4
elif symbol in (arcade.key.LEFT, arcade.key.A):
self.baloon_direction = arcade.math.Vec2(-1, 0)
elif symbol in (arcade.key.RIGHT, arcade.key.D):
self.baloon_direction = arcade.math.Vec2(1, 0)
elif symbol in (arcade.key.UP, arcade.key.W):
self.baloon_direction = arcade.math.Vec2(0, -1)
elif symbol in (arcade.key.DOWN, arcade.key.S):
self.baloon_direction = arcade.math.Vec2(0, 1)

View File

@@ -1,9 +1,7 @@
import arcade, arcade.gui, time, random
import arcade, arcade.gui, time, random, json
from plyer import notification
from utils.constants import ROWS, COLS
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
@@ -14,6 +12,9 @@ class Game(arcade.gui.UIView):
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.info_label = self.anchor.add(arcade.gui.UILabel("Use arrow keys or WASD to move.\nMaze is shown in notifications.", font_size=24, multiline=True))
with open("settings.json", "r") as file:
self.settings = json.load(file)
self.running = True
self.time_start = time.perf_counter()
@@ -21,7 +22,7 @@ class Game(arcade.gui.UIView):
self.direction = arcade.math.Vec2()
def on_show_view(self):
self.maze, start_x, start_y = self.generate_maze(int(COLS / 2), int(ROWS / 2))
self.maze, start_x, start_y = self.generate_maze(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 2))
self.current_position = arcade.math.Vec2(start_x, start_y)
self.update()
@@ -82,7 +83,7 @@ class Game(arcade.gui.UIView):
self.info_label.text = "Use arrow keys or WASD to move.\nMaze is shown in notifications."
self.maze, start_x, start_y = self.generate_maze(int(COLS / 3), int(ROWS / 3))
self.maze, start_x, start_y = self.generate_maze(int(self.settings.get("notification_cols", 25) / 3), int(self.settings.get("notification_rows", 20) / 3))
self.current_position = arcade.math.Vec2(start_x, start_y)
self.update()

View File

@@ -2,8 +2,6 @@ import arcade, arcade.gui, time, random, os, json
from plyer import notification
from utils.constants import ROWS, COLS
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
@@ -17,14 +15,17 @@ class Game(arcade.gui.UIView):
self.running = True
self.last_update_time = time.perf_counter()
self.ball_position = arcade.math.Vec2(int(COLS / 2), int(ROWS / 4))
with open("settings.json", "r") as file:
self.settings = json.load(file)
self.ball_position = arcade.math.Vec2(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 4))
self.ball_direction = arcade.math.Vec2(*random.choice([(-1, 1), (1, 1), (-1, 1), (-1, -1)]))
self.paddle_a_position = arcade.math.Vec2(0, int(ROWS / 4))
self.paddle_a_position = arcade.math.Vec2(0, int(self.settings.get("notification_rows", 20) / 4))
self.paddle_a_direction = 0
self.paddle_b_position = arcade.math.Vec2(COLS - 1, int(ROWS / 4))
self.paddle_b_position = arcade.math.Vec2(self.settings.get("notification_cols", 25) - 1, int(self.settings.get("notification_rows", 20) / 4))
self.paddle_b_direction = 0
self.score_a = 0
@@ -42,7 +43,7 @@ class Game(arcade.gui.UIView):
self.high_score = self.data["pong"]["high_score"]
def on_update(self, delta_time):
if self.running and time.perf_counter() - self.last_update_time >= 0.4:
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.last_update_time = time.perf_counter()
self.ball_position += self.ball_direction
@@ -68,34 +69,34 @@ class Game(arcade.gui.UIView):
else:
if self.ball_position.x <= 0:
if self.ball_position.y <= 0 or self.ball_position.y >= int(ROWS / 2):
if self.ball_position.y <= 0 or self.ball_position.y >= int(self.settings.get("notification_rows", 20) / 2):
self.ball_position = arcade.math.Vec2(0, self.ball_position.y)
self.ball_direction = self.ball_direction.reflect(arcade.math.Vec2(1, 0))
else:
self.score_b += 1
self.ball_position = arcade.math.Vec2(int(COLS / 2), int(ROWS / 4))
self.ball_position = arcade.math.Vec2(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 4))
self.ball_direction = arcade.math.Vec2(*random.choice([(-1, 1), (1, 1), (-1, 1), (-1, -1)]))
elif self.ball_position.x >= COLS:
if self.ball_position.y <= 0 or self.ball_position.y >= int(ROWS / 2):
self.ball_position = arcade.math.Vec2(COLS, self.ball_position.y)
elif self.ball_position.x >= self.settings.get("notification_cols", 25):
if self.ball_position.y <= 0 or self.ball_position.y >= int(self.settings.get("notification_rows", 20) / 2):
self.ball_position = arcade.math.Vec2(self.settings.get("notification_cols", 25), self.ball_position.y)
self.ball_direction = self.ball_direction.reflect(arcade.math.Vec2(-1, 0))
else:
self.score_a += 1
self.ball_position = arcade.math.Vec2(int(COLS / 2), int(ROWS / 4))
self.ball_position = arcade.math.Vec2(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 4))
self.ball_direction = arcade.math.Vec2(*random.choice([(-1, 1), (1, 1), (-1, 1), (-1, -1)]))
if self.ball_position.y <= 0:
self.ball_position = arcade.math.Vec2(self.ball_position.x, 0)
self.ball_direction = self.ball_direction.reflect(arcade.math.Vec2(0, 1))
elif self.ball_position.y >= int(ROWS / 2):
self.ball_position = arcade.math.Vec2(self.ball_position.x, int(ROWS / 2))
elif self.ball_position.y >= int(self.settings.get("notification_rows", 20) / 2):
self.ball_position = arcade.math.Vec2(self.ball_position.x, int(self.settings.get("notification_rows", 20) / 2))
self.ball_direction = self.ball_direction.reflect(arcade.math.Vec2(0, -1))
text = ""
for y in range(int(ROWS / 2)):
for x in range(COLS):
for y in range(int(self.settings.get("notification_rows", 20) / 2)):
for x in range(self.settings.get("notification_cols", 25)):
if (x, y) == self.paddle_a_position or (x, y) == self.paddle_b_position:
text += "|"
elif self.ball_position == (x, y):
@@ -126,12 +127,12 @@ class Game(arcade.gui.UIView):
self.window.show_view(Main(self.pypresence_client))
elif symbol == arcade.key.R and not self.running:
self.paddle_a_direction = 0
self.paddle_a_position = arcade.math.Vec2(0, int(ROWS / 4))
self.paddle_a_position = arcade.math.Vec2(0, int(self.settings.get("notification_rows", 20) / 4))
self.paddle_b_direction = 0
self.paddle_b_position = arcade.math.Vec2(COLS - 1, int(ROWS / 4))
self.paddle_b_position = arcade.math.Vec2(self.settings.get("notification_cols", 25) - 1, int(self.settings.get("notification_rows", 20) / 4))
self.ball_position = arcade.math.Vec2(int(COLS / 2), int(ROWS / 4))
self.ball_position = arcade.math.Vec2(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 4))
self.ball_direction = arcade.math.Vec2(*random.choice([(-1, 1), (1, 1), (-1, 1), (-1, -1)]))
self.running = True

View File

@@ -2,8 +2,6 @@ import arcade, arcade.gui, time, random, os, json
from plyer import notification
from utils.constants import ROWS, COLS
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
@@ -18,9 +16,12 @@ class Game(arcade.gui.UIView):
self.running = True
self.last_update_time = time.perf_counter()
self.snake = [(int(COLS / 2), int(ROWS / 2))]
with open("settings.json", "r") as file:
self.settings = json.load(file)
self.snake = [(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 2))]
self.foods = []
if not os.path.exists("data.json"):
self.data = {}
else:
@@ -35,13 +36,13 @@ class Game(arcade.gui.UIView):
def spawn_food(self):
while True:
x, y = (random.randint(0, COLS), random.randint(0, ROWS))
x, y = (random.randint(0, self.settings.get("notification_cols", 25)), random.randint(0, self.settings.get("notification_rows", 20)))
if not (x, y) in self.snake:
return (x, y)
def on_update(self, dt):
if self.running and time.perf_counter() - self.last_update_time >= 0.4:
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.last_update_time = time.perf_counter()
head_x, head_y = self.snake[0]
@@ -55,7 +56,7 @@ class Game(arcade.gui.UIView):
elif self.direction == "down":
new_head = (head_x, head_y + 1)
if new_head in self.snake or not (0 <= new_head[0] < COLS and 0 <= new_head[1] < ROWS):
if new_head in self.snake or not (0 <= new_head[0] < self.settings.get("notification_cols", 25) and 0 <= new_head[1] < self.settings.get("notification_rows", 20)):
self.info_label.text = "Game Over.\nPress r to restart"
self.running = False
@@ -77,8 +78,8 @@ class Game(arcade.gui.UIView):
text = ""
for y in range(ROWS):
for x in range(COLS):
for y in range(self.settings.get("notification_rows", 20)):
for x in range(self.settings.get("notification_cols", 25)):
if (x, y) == self.snake[0]:
text += "H"
elif (x, y) in self.snake[1:]:
@@ -116,7 +117,7 @@ class Game(arcade.gui.UIView):
self.info_label.text = "Press keys inside this window to interact with the game.\nYou can see the game inside notifications."
self.info_label.fit_content()
self.snake = [(int(COLS / 2), int(ROWS / 2))]
self.snake = [(int(self.settings.get("notification_cols", 25) / 2), int(self.settings.get("notification_rows", 20) / 2))]
self.foods = [self.spawn_food() for _ in range(3)]
self.running = True
elif symbol == arcade.key.ESCAPE:

View File

@@ -2,8 +2,6 @@ import arcade, arcade.gui, time, random, os, json
from plyer import notification
from utils.constants import ROWS, COLS
class Game(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
@@ -17,6 +15,9 @@ class Game(arcade.gui.UIView):
self.running = True
self.last_update_time = time.perf_counter()
with open("settings.json", "r") as file:
self.settings = json.load(file)
if not os.path.exists("data.json"):
self.data = {}
else:
@@ -29,7 +30,7 @@ class Game(arcade.gui.UIView):
self.high_score = self.data["space_invaders"]["high_score"]
self.score = 0
self.ship_position = arcade.math.Vec2(0, int(ROWS / 2) - 1)
self.ship_position = arcade.math.Vec2(0, int(self.settings.get("notification_rows", 20) / 2) - 1)
self.ship_direction = arcade.math.Vec2(0, 0)
@@ -40,15 +41,15 @@ class Game(arcade.gui.UIView):
self.last_enemy_shoot = time.perf_counter()
def summon_enemies(self):
self.enemies = [[x, y] for x in range(int(COLS)) for y in range(int(int(ROWS / 2) / 5))]
self.enemies = [[x, y] for x in range(int(self.settings.get("notification_cols", 25))) for y in range(int(int(self.settings.get("notification_rows", 20) / 2) / 5))]
def update_enemies(self):
columns = list(range(COLS))
columns = list(range(self.settings.get("notification_cols", 25)))
random.shuffle(columns)
for x in columns:
max_y = -99999
for y in range(int(int(ROWS / 2) / 3)):
for y in range(int(int(self.settings.get("notification_rows", 20) / 2) / 3)):
if not [x, y] in self.enemies:
continue
@@ -65,15 +66,15 @@ class Game(arcade.gui.UIView):
self.summon_enemies()
def on_update(self, delta_time):
if self.running and time.perf_counter() - self.last_update_time >= 0.4:
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.last_update_time = time.perf_counter()
self.ship_position += self.ship_direction
if self.ship_position.x < 0:
self.ship_position = arcade.math.Vec2(0, self.ship_position.y)
elif self.ship_position.x > COLS:
self.ship_position = arcade.math.Vec2(COLS, self.ship_position.y)
elif self.ship_position.x > self.settings.get("notification_cols", 25):
self.ship_position = arcade.math.Vec2(self.settings.get("notification_cols", 25), self.ship_position.y)
self.ship_direction = arcade.math.Vec2(0, 0)
@@ -104,7 +105,7 @@ class Game(arcade.gui.UIView):
bullets_to_remove.add(b)
for b in new_enemy:
if b[1] > int(ROWS / 2):
if b[1] > int(self.settings.get("notification_rows", 20) / 2):
bullets_to_remove.add(b)
self.your_bullets = [b for b in new_yours if b not in bullets_to_remove]
@@ -112,8 +113,8 @@ class Game(arcade.gui.UIView):
text = ""
for y in range(int(ROWS / 2)):
for x in range(COLS):
for y in range(int(self.settings.get("notification_rows", 20) / 2)):
for x in range(self.settings.get("notification_cols", 25)):
if [x, y] in self.enemies:
text += "~"
elif (x, y) in self.enemy_bullets or (x, y) in self.your_bullets:
@@ -147,7 +148,7 @@ class Game(arcade.gui.UIView):
elif symbol == arcade.key.R:
self.score = 0
self.ship_position = arcade.math.Vec2(0, int(ROWS / 2) - 1)
self.ship_position = arcade.math.Vec2(0, int(self.settings.get("notification_rows", 20) / 2) - 1)
self.ship_direction = arcade.math.Vec2(0, 0)
self.enemies = []

View File

@@ -17,6 +17,9 @@ class Game(arcade.gui.UIView):
self.running = True
self.last_update_time = time.perf_counter()
with open("settings.json", "r") as file:
self.settings = json.load(file)
if not os.path.exists("data.json"):
self.data = {}
else:
@@ -111,7 +114,7 @@ class Game(arcade.gui.UIView):
self.shape_tuple = self.create_shape(int(10 / 2), 0, self.shape_to_place)
def on_update(self, delta_time):
if self.running and time.perf_counter() - self.last_update_time >= 0.4:
if self.running and time.perf_counter() - self.last_update_time >= self.settings.get("notification_timeout", 0.4):
self.last_update_time = time.perf_counter()
self.move_shape(*self.shape_tuple, 0, 1)
@@ -175,6 +178,8 @@ class Game(arcade.gui.UIView):
self.spawn_shape()
self.info_label.text = "Use arrow keys or WASD to move the blocks\nThe game is shown inside notifications."
self.running = True
elif symbol == arcade.key.SPACE:
self.shape_tuple = self.rotate_shape(*self.shape_tuple)

View File

@@ -2,7 +2,6 @@ import arcade, arcade.gui, time, random, os, json
from plyer import notification
from utils.constants import ROWS, COLS
from utils.preload import words
class Game(arcade.gui.UIView):
@@ -17,6 +16,9 @@ class Game(arcade.gui.UIView):
self.running = True
with open("settings.json", "r") as file:
self.settings = json.load(file)
if not os.path.exists("data.json"):
self.data = {}
else: