Small improvements

This commit is contained in:
Lncvrt committed 2024-12-13 20:54:24 -07:00
1 parent 09f2554f69
commit cf51e81a5d
1 file changed
+32 -23
+32 -23
View File
@@ -5,37 +5,46 @@ import random
import shutil import shutil
from sys import exit from sys import exit
version_num = 1
app_folder = os.path.join(os.environ['APPDATA'].replace("\\", "/"), "Foodie Dash") app_folder = os.path.join(os.environ['APPDATA'].replace("\\", "/"), "Foodie Dash")
resources_folder = os.path.join(app_folder, "Resources") resources_folder = os.path.join(app_folder, "Resources")
icon_path = f"{resources_folder}/icon.png"
berry_path = f"{resources_folder}/berry.png"
death_path = f"{resources_folder}/death.mp3"
eat_path = f"{resources_folder}/eat.mp3"
music_path = f"{resources_folder}/music.mp3"
font_path = f"{resources_folder}/font.ttf"
if not os.path.exists(app_folder): if not os.path.exists(app_folder):
os.mkdir(app_folder) os.mkdir(app_folder)
if not os.path.exists(resources_folder): if not os.path.exists(resources_folder):
os.mkdir(resources_folder) os.mkdir(resources_folder)
if not os.path.exists(f"{resources_folder}/icon.png"): if not os.path.exists(icon_path):
with open(f"{resources_folder}/icon.png", 'wb') as f: with open(icon_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/icon.png").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/icon.png").content)
if not os.path.exists(f"{resources_folder}/berry.png"): if not os.path.exists(berry_path):
with open(f"{resources_folder}/berry.png", 'wb') as f: with open(berry_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/berry.png").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/berry.png").content)
if not os.path.exists(f"{resources_folder}/death.mp3"): if not os.path.exists(death_path):
with open(f"{resources_folder}/death.mp3", 'wb') as f: with open(death_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/death.mp3").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/death.mp3").content)
if not os.path.exists(f"{resources_folder}/eat.mp3"): if not os.path.exists(eat_path):
with open(f"{resources_folder}/eat.mp3", 'wb') as f: with open(eat_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/eat.mp3").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/eat.mp3").content)
if not os.path.exists(f"{resources_folder}/music.mp3"): if not os.path.exists(music_path):
with open(f"{resources_folder}/music.mp3", 'wb') as f: with open(music_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/music.mp3").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/music.mp3").content)
if not os.path.exists(f"{resources_folder}/font.ttf"): if not os.path.exists(font_path):
with open(f"{resources_folder}/font.ttf", 'wb') as f: with open(font_path, 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/font.ttf").content) f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/font.ttf").content)
pygame.init() pygame.init()
@@ -59,14 +68,16 @@ player_hitbox_height = 128
food_hitbox_width = 128 food_hitbox_width = 128
food_hitbox_height = 128 food_hitbox_height = 128
icon_image = pygame.image.load(icon_path)
window = pygame.display.set_mode((WIDTH, HEIGHT)) window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Foodie Dash") pygame.display.set_caption("Foodie Dash")
pygame.display.set_icon(pygame.image.load(f"{resources_folder}/icon.png")) pygame.display.set_icon(icon_image)
player_image = pygame.image.load(f"{resources_folder}/icon.png").convert_alpha() player_image = icon_image.convert_alpha()
player_image = pygame.transform.scale(player_image, (player_width, player_height)) player_image = pygame.transform.scale(player_image, (player_width, player_height))
food_image = pygame.image.load(f"{resources_folder}/berry.png").convert_alpha() food_image = pygame.image.load(berry_path).convert_alpha()
food_image = pygame.transform.scale(food_image, (food_width, food_height)) food_image = pygame.transform.scale(food_image, (food_width, food_height))
player_x = (WIDTH - player_width) // 2 player_x = (WIDTH - player_width) // 2
@@ -83,11 +94,10 @@ auto_key = 0
auto_color_change_interval = 100 auto_color_change_interval = 100
auto_color_change_timer = pygame.time.get_ticks() auto_color_change_timer = pygame.time.get_ticks()
font = pygame.font.Font(font_path, 36)
font = pygame.font.Font(f'{resources_folder}/font.ttf', 36)
clock = pygame.time.Clock() clock = pygame.time.Clock()
pygame.mixer.music.load(f"{resources_folder}/music.mp3") pygame.mixer.music.load(music_path)
pygame.mixer.music.play(loops=-1) pygame.mixer.music.play(loops=-1)
death_sound_channel = pygame.mixer.Channel(1) death_sound_channel = pygame.mixer.Channel(1)
@@ -189,7 +199,6 @@ def game_loop():
elif player_x > WIDTH - player_width: elif player_x > WIDTH - player_width:
player_x = WIDTH - player_width player_x = WIDTH - player_width
food_y += food_speed * dt food_y += food_speed * dt
if auto_mode == True: if auto_mode == True:
if abs(player_x - food_x) > player_speed * dt: if abs(player_x - food_x) > player_speed * dt:
@@ -208,11 +217,11 @@ def game_loop():
if check_collision(): if check_collision():
if not auto_mode: if not auto_mode:
score += 1 score += 1
pygame.mixer.Sound(f"{resources_folder}/eat.mp3").play().set_volume(0.15) pygame.mixer.Sound(eat_path).play().set_volume(0.15)
food_x = random.randint(0, WIDTH - food_width) food_x = random.randint(0, WIDTH - food_width)
food_y = 0 food_y = 0
else: else:
pygame.mixer.Sound(f"{resources_folder}/death.mp3").play().set_volume(0.4) pygame.mixer.Sound(death_path).play().set_volume(0.4)
score = 1 score = 1
player_x = (WIDTH - player_width) // 2 player_x = (WIDTH - player_width) // 2
food_x = random.randint(0, WIDTH - food_width) food_x = random.randint(0, WIDTH - food_width)
@@ -223,5 +232,5 @@ def game_loop():
COLORraw_window() COLORraw_window()
if __name__ == "__main__":
game_loop() game_loop()