Clean up code a bit
This commit is contained in:
1 parent
4f5c9ede55
commit
1d45c6dbd4
1 file changed
+32
-77
+32
-77
@@ -26,75 +26,44 @@ if not os.path.exists(app_folder):
|
||||
if not os.path.exists(resources_folder):
|
||||
os.mkdir(resources_folder)
|
||||
|
||||
if not os.path.exists(icon_path):
|
||||
with open(icon_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/icon.png").content)
|
||||
resources = {
|
||||
icon_path: "https://cdn.lncvrt.xyz/foodiedash/icon.png",
|
||||
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(berry_path):
|
||||
with open(berry_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/berry.png").content)
|
||||
|
||||
if not os.path.exists(death_path):
|
||||
with open(death_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/death.mp3").content)
|
||||
|
||||
if not os.path.exists(eat_path):
|
||||
with open(eat_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/eat.mp3").content)
|
||||
|
||||
if not os.path.exists(music_path):
|
||||
with open(music_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/music.mp3").content)
|
||||
|
||||
if not os.path.exists(font_path):
|
||||
with open(font_path, 'wb') as f:
|
||||
f.write(requests.get("https://cdn.lncvrt.xyz/foodiedash/font.ttf").content)
|
||||
for path, url in resources.items():
|
||||
if not os.path.exists(path):
|
||||
with open(path, 'wb') as f:
|
||||
f.write(requests.get(url).content)
|
||||
|
||||
pygame.init()
|
||||
|
||||
WIDTH = 800
|
||||
HEIGHT = 600
|
||||
WIDTH, HEIGHT = 800, 600
|
||||
WHITE, COLOR = (255, 255, 255), (141, 103, 216)
|
||||
|
||||
WHITE = (255, 255, 255)
|
||||
COLOR = (141, 103, 216)
|
||||
player_width, player_height, player_speed = 128, 128, 15
|
||||
food_width, food_height, food_speed = 128, 128, 8
|
||||
|
||||
player_width = 128
|
||||
player_height = 128
|
||||
player_speed = 15
|
||||
|
||||
food_width = 128
|
||||
food_height = 128
|
||||
food_speed = 8
|
||||
|
||||
player_hitbox_width = 128
|
||||
player_hitbox_height = 128
|
||||
food_hitbox_width = 128
|
||||
food_hitbox_height = 128
|
||||
player_hitbox_width, player_hitbox_height = 128, 128
|
||||
food_hitbox_width, food_hitbox_height = 128, 128
|
||||
|
||||
icon_image = pygame.image.load(icon_path)
|
||||
|
||||
window = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
pygame.display.set_caption("Foodie Dash")
|
||||
pygame.display.set_icon(icon_image)
|
||||
|
||||
player_image = icon_image.convert_alpha()
|
||||
player_image = pygame.transform.scale(player_image, (player_width, player_height))
|
||||
player_image = pygame.transform.scale(icon_image.convert_alpha(), (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(berry_path).convert_alpha()
|
||||
food_image = pygame.transform.scale(food_image, (food_width, food_height))
|
||||
player_x, player_y = (WIDTH - player_width) // 2, HEIGHT - player_height
|
||||
food_x, food_y = random.randint(0, WIDTH - food_width), 0
|
||||
|
||||
player_x = (WIDTH - player_width) // 2
|
||||
player_y = HEIGHT - player_height
|
||||
|
||||
food_x = random.randint(0, WIDTH - food_width)
|
||||
food_y = 0
|
||||
|
||||
score = 1
|
||||
draw_hitboxes = False
|
||||
auto_mode = False
|
||||
|
||||
auto_color_change_interval = 100
|
||||
auto_color_change_timer = pygame.time.get_ticks()
|
||||
score, draw_hitboxes, auto_mode = 1, False, False
|
||||
auto_color_change_interval, auto_color_change_timer = 100, pygame.time.get_ticks()
|
||||
|
||||
font = pygame.font.Font(font_path, 36)
|
||||
clock = pygame.time.Clock()
|
||||
@@ -102,9 +71,7 @@ clock = pygame.time.Clock()
|
||||
pygame.mixer.music.load(music_path)
|
||||
pygame.mixer.music.play(loops=-1)
|
||||
|
||||
death_sound_channel = pygame.mixer.Channel(1)
|
||||
eat_sound_channel = pygame.mixer.Channel(2)
|
||||
|
||||
death_sound_channel, eat_sound_channel = pygame.mixer.Channel(1), pygame.mixer.Channel(2)
|
||||
flipped = False
|
||||
|
||||
gradient_progress = 0.0
|
||||
@@ -122,7 +89,6 @@ def lerp(start, end, t):
|
||||
|
||||
def COLORraw_window():
|
||||
global red, green, blue, gradient_progress
|
||||
|
||||
window.fill((30, 30, 30))
|
||||
|
||||
if draw_hitboxes and not auto_mode:
|
||||
@@ -136,24 +102,18 @@ def COLORraw_window():
|
||||
score_text = font.render("Score: " + str(score), True, COLOR)
|
||||
else:
|
||||
if gradient_progress < 0.333:
|
||||
red = lerp(255, 0, gradient_progress * 3)
|
||||
green = lerp(0, 255, gradient_progress * 3)
|
||||
blue = 0
|
||||
red, green, blue = lerp(255, 0, gradient_progress * 3), lerp(0, 255, gradient_progress * 3), 0
|
||||
elif gradient_progress < 0.666:
|
||||
red = 0
|
||||
green = lerp(255, 0, (gradient_progress - 0.333) * 3)
|
||||
blue = lerp(0, 255, (gradient_progress - 0.333) * 3)
|
||||
red, green, blue = 0, lerp(255, 0, (gradient_progress - 0.333) * 3), lerp(0, 255, (gradient_progress - 0.333) * 3)
|
||||
else:
|
||||
red = lerp(0, 255, (gradient_progress - 0.666) * 3)
|
||||
green = 0
|
||||
blue = lerp(255, 0, (gradient_progress - 0.666) * 3)
|
||||
red, green, blue = lerp(0, 255, (gradient_progress - 0.666) * 3), 0, lerp(255, 0, (gradient_progress - 0.666) * 3)
|
||||
|
||||
gradient_progress += 0.00025
|
||||
if gradient_progress >= 1.0:
|
||||
gradient_progress = 0.0
|
||||
|
||||
score_text = font.render("Auto Mode", True, (red, green, blue))
|
||||
|
||||
|
||||
score_rect = score_text.get_rect(center=(WIDTH // 2, 50))
|
||||
window.blit(score_text, score_rect)
|
||||
|
||||
@@ -163,9 +123,7 @@ def check_collision():
|
||||
player_hitbox = pygame.Rect(player_x, player_y, player_hitbox_width, player_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
|
||||
return player_hitbox.colliderect(food_hitbox)
|
||||
|
||||
def game_loop():
|
||||
global score, player_x, food_x, food_y, draw_hitboxes, auto_mode, player_image, flipped
|
||||
@@ -214,13 +172,10 @@ def game_loop():
|
||||
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
|
||||
player_x = max(0, min(player_x, WIDTH - player_width))
|
||||
|
||||
food_y += food_speed * dt
|
||||
if auto_mode == True:
|
||||
if auto_mode:
|
||||
if abs(player_x - food_x) > player_speed * dt:
|
||||
if player_x < food_x:
|
||||
player_x += player_speed * dt
|
||||
|
||||
Reference in new issue
Block a user