16 Commits
Author SHA1 Message Date
Lncvrt 365ad6af60 Revert #f09eb86, was actually a intended feature 2024-12-13 23:17:12 -07:00
Lncvrt 975c16c551 Reuse same sound file 2024-12-13 23:08:43 -07:00
Lncvrt 380c7d6167 Clean up code even more 2024-12-13 23:06:22 -07:00
Lncvrt 7968f54d88 Change to Markdown 2024-12-13 23:00:56 -07:00
Lncvrt 798ef47922 Fix link 2024-12-13 23:00:29 -07:00
Lncvrt ca40fba5e9 Add a newline here 2024-12-13 23:00:04 -07:00
Lncvrt 1d45c6dbd4 Clean up code a bit 2024-12-13 22:59:29 -07:00
Lncvrt 4f5c9ede55 Update README 2024-12-13 22:58:11 -07:00
Lncvrt fd660d1121 Add note 2024-12-13 22:57:54 -07:00
Lncvrt aba346e571 Update flipping logic for auto mode 2024-12-13 22:48:09 -07:00
Lncvrt f09eb860eb Fix insanely stupid logic 2024-12-13 22:46:58 -07:00
Lncvrt f2fe855b51 Change "Points" to "Score" 2024-12-13 22:45:34 -07:00
Lncvrt 4b0b013b01 Change speeds, make better color changes for Auto Mode 2024-12-13 21:36:40 -07:00
Lncvrt 347d4d7215 Add version number to assets 2024-12-13 20:55:44 -07:00
Lncvrt cf51e81a5d Small improvements 2024-12-13 20:54:24 -07:00
Lncvrt 09f2554f69 Fix requirements file 2024-12-13 20:45:18 -07:00
3 changed files with 131 additions and 149 deletions

No files matched your search

+9 -11
View File
@@ -1,14 +1,12 @@
<div align="center"> ![Foodie Dash](https://cdn.lncvrt.xyz/foodiedash/icon.png)
<img src="https://cdn.lncvrt.xyz/foodiedash/icon.png"/>
<h1>Foodie Dash</h1> # Foodie Dash
<h3>A game where you collect food items with a leaderboard system</h3> ### A game where you collect food items with a leaderboard system
</div>
**NOTE:** this is an archive and now a "continued" version of the game
The code here is really bad, and has really bad parts. If you want the true 1.0.0/non updating version, [go here](https://github.com/Lncvrt/Foodie-Archive/releases/tag/true-1.0.0)
--- ---
<div align="center"> [Click here](https://github.com/Lncvrt/Foodie-Archive/releases/latest/download/Foodie-Dash.exe) to download the latest version
<a href="https://github.com/Lncvrt/Foodie-Archive/releases/latest/download/Foodie-Dash.exe">Click here</a> to download the latest version [Click here](https://cdn.lncvrt.xyz/foodiedash/Foodie%20Dash%20Information.pdf) for information on how to play
<br>
<br>
<a href="https://cdn.lncvrt.xyz/foodiedash/Foodie%20Dash%20Information.pdf">Click here</a> for information on how to play
</div>
+121 -138
View File
@@ -1,111 +1,92 @@
import requests import requests
import os import os
import pygame
import random import random
import shutil import shutil
from sys import exit from sys import exit
app_folder = os.path.join(os.environ['APPDATA'].replace("\\", "/"), "Foodie Dash") os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
version_num = 1
app_folder = os.path.join(os.environ['APPDATA'], "Foodie Dash")
resources_folder = os.path.join(app_folder, "Resources") resources_folder = os.path.join(app_folder, "Resources")
if not os.path.exists(app_folder): icon_path = f"{resources_folder}/icon_{version_num}.png"
os.mkdir(app_folder) berry_path = f"{resources_folder}/berry_{version_num}.png"
death_path = f"{resources_folder}/death_{version_num}.mp3"
eat_path = f"{resources_folder}/eat_{version_num}.mp3"
music_path = f"{resources_folder}/music_{version_num}.mp3"
font_path = f"{resources_folder}/font_{version_num}.ttf"
if not os.path.exists(resources_folder): os.makedirs(resources_folder, exist_ok=True)
os.mkdir(resources_folder)
if not os.path.exists(f"{resources_folder}/icon.png"): resources = {
with open(f"{resources_folder}/icon.png", 'wb') as f: icon_path: "https://cdn.lncvrt.xyz/foodiedash/icon.png",
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/icon.png").content) berry_path: "https://cdn.lncvrt.xyz/foodiedash/berry.png",
death_path: "https://cdn.lncvrt.xyz/foodiedash/death.mp3",
eat_path: "https://cdn.lncvrt.xyz/foodiedash/eat.mp3",
music_path: "https://cdn.lncvrt.xyz/foodiedash/music.mp3",
font_path: "https://cdn.lncvrt.xyz/foodiedash/font.ttf"
}
if not os.path.exists(f"{resources_folder}/berry.png"): for path, url in resources.items():
with open(f"{resources_folder}/berry.png", 'wb') as f: if not os.path.exists(path):
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/berry.png").content) with open(path, 'wb') as f:
f.write(requests.get(url).content)
if not os.path.exists(f"{resources_folder}/death.mp3"):
with open(f"{resources_folder}/death.mp3", 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/death.mp3").content)
if not os.path.exists(f"{resources_folder}/eat.mp3"):
with open(f"{resources_folder}/eat.mp3", 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/eat.mp3").content)
if not os.path.exists(f"{resources_folder}/music.mp3"):
with open(f"{resources_folder}/music.mp3", 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/music.mp3").content)
if not os.path.exists(f"{resources_folder}/font.ttf"):
with open(f"{resources_folder}/font.ttf", 'wb') as f:
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/font.ttf").content)
pygame.init() pygame.init()
WIDTH = 800 WIDTH, HEIGHT = 800, 600
HEIGHT = 600 WHITE, COLOR = (255, 255, 255), (141, 103, 216)
WHITE = (255, 255, 255) player_width, player_height, player_speed = 128, 128, 15
COLOR = (141, 103, 216) food_width, food_height, food_speed = 128, 128, 8
player_width = 128 player_hitbox_width, player_hitbox_height = 128, 128
player_height = 128 food_hitbox_width, food_hitbox_height = 128, 128
player_speed = 30
food_width = 128
food_height = 128
food_speed = 15
player_hitbox_width = 128
player_hitbox_height = 128
food_hitbox_width = 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 = pygame.transform.scale(icon_image.convert_alpha(), (player_width, player_height))
player_image = pygame.transform.scale(player_image, (player_width, player_height)) food_image = pygame.transform.scale(pygame.image.load(berry_path).convert_alpha(), (food_width, food_height))
food_image = pygame.image.load(f"{resources_folder}/berry.png").convert_alpha() death_sound = pygame.mixer.Sound(death_path)
food_image = pygame.transform.scale(food_image, (food_width, food_height)) eat_sound = pygame.mixer.Sound(eat_path)
player_x = (WIDTH - player_width) // 2 player_x, player_y = (WIDTH - player_width) // 2, HEIGHT - player_height
player_y = HEIGHT - player_height food_x, food_y = random.randint(0, WIDTH - food_width), 0
food_x = random.randint(0, WIDTH - food_width) score, draw_hitboxes, auto_mode, auto_key = 1, False, False, 0
food_y = 0 auto_color_change_interval, auto_color_change_timer = 100, pygame.time.get_ticks()
score = 1 font = pygame.font.Font(font_path, 36)
draw_hitboxes = False
auto_mode = False
auto_key = 0
auto_color_change_interval = 100
auto_color_change_timer = pygame.time.get_ticks()
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, eat_sound_channel = pygame.mixer.Channel(1), pygame.mixer.Channel(2)
eat_sound_channel = pygame.mixer.Channel(2)
flipped = False flipped = False
gradient_progress = 0.0
def should_change_color(): def should_change_color():
global auto_color_change_timer global auto_color_change_timer
current_time = pygame.time.get_ticks() if pygame.time.get_ticks() - auto_color_change_timer >= auto_color_change_interval:
if current_time - auto_color_change_timer >= auto_color_change_interval: auto_color_change_timer = pygame.time.get_ticks()
auto_color_change_timer = current_time
return True return True
return False return False
def COLORraw_window(): def lerp(start, end, t):
global red, green, blue return int(start + (end - start) * t)
def COLORraw_window():
global red, green, blue, gradient_progress
window.fill((30, 30, 30)) window.fill((30, 30, 30))
if draw_hitboxes and not auto_mode: if draw_hitboxes and not auto_mode:
@@ -116,27 +97,25 @@ def COLORraw_window():
window.blit(food_image, (food_x, food_y)) window.blit(food_image, (food_x, food_y))
if score != "Auto": if score != "Auto":
score_text = font.render("Points: " + str(score), True, COLOR) score_text = font.render(f"Score: {score}", True, COLOR)
else: else:
if should_change_color(): if gradient_progress < 0.333:
red = random.randint(0, 255) red, green, blue = lerp(255, 0, gradient_progress * 3), lerp(0, 255, gradient_progress * 3), 0
green = random.randint(0, 255) elif gradient_progress < 0.666:
blue = random.randint(0, 255) red, green, blue = 0, lerp(255, 0, (gradient_progress - 0.333) * 3), lerp(0, 255, (gradient_progress - 0.333) * 3)
else:
red, green, blue = lerp(0, 255, (gradient_progress - 0.666) * 3), 0, lerp(255, 0, (gradient_progress - 0.666) * 3)
gradient_progress = (gradient_progress + 0.00025) % 1.0
score_text = font.render("Auto Mode", True, (red, green, blue)) score_text = font.render("Auto Mode", True, (red, green, blue))
score_rect = score_text.get_rect(center=(WIDTH // 2, 50)) score_rect = score_text.get_rect(center=(WIDTH // 2, 50))
window.blit(score_text, score_rect) window.blit(score_text, score_rect)
pygame.display.update() pygame.display.update()
def check_collision(): def check_collision():
player_hitbox = pygame.Rect(player_x, player_y, player_hitbox_width, player_hitbox_height) return pygame.Rect(player_x, player_y, player_hitbox_width, player_hitbox_height).colliderect(pygame.Rect(food_x, food_y, food_hitbox_width, food_hitbox_height))
food_hitbox = pygame.Rect(food_x, food_y, food_hitbox_width, food_hitbox_height)
if player_hitbox.colliderect(food_hitbox):
return True
return False
def game_loop(): def game_loop():
global score, player_x, food_x, food_y, draw_hitboxes, auto_mode, auto_key, player_image, flipped global score, player_x, food_x, food_y, draw_hitboxes, auto_mode, auto_key, player_image, flipped
@@ -147,7 +126,7 @@ def game_loop():
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
try: try:
shutil.rmtree(f"{os.path.dirname(os.path.abspath(__file__))}\\data") shutil.rmtree(f"{os.path.dirname(os.path.abspath(__file__))}/data")
except FileNotFoundError: except FileNotFoundError:
pass pass
pygame.quit() pygame.quit()
@@ -158,70 +137,74 @@ def game_loop():
elif event.key == pygame.K_j: elif event.key == pygame.K_j:
auto_key += 1 auto_key += 1
if auto_key == 3: if auto_key == 3:
player_x = (WIDTH - player_width) // 2 reset_game_state("Auto")
food_x = random.randint(0, WIDTH - food_width)
food_y = 0
score = "Auto"
auto_mode = True
elif auto_key == 4: elif auto_key == 4:
score = 1 reset_game_state()
player_x = (WIDTH - player_width) // 2
food_x = random.randint(0, WIDTH - food_width)
food_y = 0
auto_mode = False
auto_key = 0
if not auto_mode: if not auto_mode:
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] or keys[pygame.K_a] and player_x > 0: if (keys[pygame.K_LEFT] or keys[pygame.K_a]) and player_x > 0:
player_x -= player_speed * dt move_player(-player_speed * dt)
if not flipped: if (keys[pygame.K_RIGHT] or keys[pygame.K_d]) and player_x < WIDTH - player_width:
player_image = pygame.transform.flip(player_image, True, False) move_player(player_speed * dt)
flipped = True
if keys[pygame.K_RIGHT] or keys[pygame.K_d] and player_x < WIDTH - player_width:
player_x += player_speed * dt
if flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
if player_x < 0:
player_x = 0
elif 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:
if abs(player_x - food_x) > player_speed * dt: auto_move_player(dt)
if player_x < food_x:
player_x += player_speed * dt
if flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
else:
player_x -= player_speed * dt
if not flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = True
if food_y >= player_y: if food_y >= player_y:
if check_collision(): if check_collision():
if not auto_mode: handle_collision()
score += 1
pygame.mixer.Sound(f"{resources_folder}/eat.mp3").play().set_volume(0.15)
food_x = random.randint(0, WIDTH - food_width)
food_y = 0
else: else:
pygame.mixer.Sound(f"{resources_folder}/death.mp3").play().set_volume(0.4) handle_death()
score = 1
player_x = (WIDTH - player_width) // 2
food_x = random.randint(0, WIDTH - food_width)
food_y = 0
if flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
COLORraw_window() COLORraw_window()
def reset_game_state(mode="Normal"):
global score, player_x, food_x, food_y, auto_mode, flipped, player_image
score = 1 if mode == "Normal" else "Auto"
player_x = (WIDTH - player_width) // 2
food_x = random.randint(0, WIDTH - food_width)
food_y = 0
auto_mode = mode == "Auto"
if flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
game_loop() def move_player(delta_x):
global player_x, flipped, player_image
player_x += delta_x
if delta_x < 0 and not flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = True
elif delta_x > 0 and flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
def auto_move_player(dt):
global player_x, flipped, player_image
if abs(player_x - food_x) > player_speed:
if player_x < food_x:
move_player(player_speed * dt)
else:
move_player(-player_speed * dt)
def handle_collision():
global score, food_x, food_y
if not auto_mode:
score += 1
eat_sound.set_volume(0.15)
food_x, food_y = random.randint(0, WIDTH - food_width), 0
def handle_death():
global score, player_x, food_x, food_y, flipped, player_image
death_sound.play().set_volume(0.4)
score = 1
player_x = (WIDTH - player_width) // 2
food_x, food_y = random.randint(0, WIDTH - food_width), 0
if flipped:
player_image = pygame.transform.flip(player_image, True, False)
flipped = False
if __name__ == "__main__":
game_loop()
+1
View File
@@ -1 +1,2 @@
pygame pygame
requests