mirror of
https://github.com/csd4ni3l/notifplayground.git
synced 2026-01-01 12:33:47 +01:00
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:
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user