From 1ccdfc6ee87d0fb54c577ff608e5cdb514c400ac Mon Sep 17 00:00:00 2001 From: dvorakmortonxd Date: Sun, 31 May 2026 23:30:48 +0200 Subject: [PATCH] finished it up to work for pygbag with asyncio :3 --- levels.py | 4 ++-- main.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/levels.py b/levels.py index dc34bbd..767ddc6 100644 --- a/levels.py +++ b/levels.py @@ -9,8 +9,8 @@ holding_milk = False zombie_hp = 20 milkactive = False enemy_zombies = [ - {"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0, "coll": pygame.Rect(200, 200, 56, 96), "friendly": False}, - {"x": 400, "y": 300, "hp": 20, "dead": False, "dx": -1, "dy": 1, "timer": 0, "coll": pygame.Rect(400, 300, 56, 96), "friendly": False}, + {"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0, "coll": None, "friendly": False}, + {"x": 400, "y": 300, "hp": 20, "dead": False, "dx": -1, "dy": 1, "timer": 0, "coll": None, "friendly": False}, ] def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick): # the function for our first level, ignore the unused variables here, you can use them when you edit it diff --git a/main.py b/main.py index 6089adf..27220d0 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import pygame, levels # Imports the pygame library and our own levels.py we made for the code to be more readable, obviously +import asyncio window_fps = 60 # the frames per second, this decides how fast the main loop runs per second -def main(fps=window_fps): # the main function +async def main(fps=window_fps): # the main function pygame.init() # initalizes pygame screen_width = 768 # the screen width screen_height = 576 # the screen height @@ -29,8 +30,6 @@ def main(fps=window_fps): # the main function if event.type == pygame.KEYDOWN: # what happens when you press down a key if event.key == pygame.K_ESCAPE: # what happens when you press escape running = False # poof - if event.key == pygame.K_k: - level = 6 if event.type == pygame.MOUSEBUTTONDOWN: # what happens when you press down a mouse button click = True # sets the click variable to True so level function in levels.py can see print(pygame.mouse.get_pos()) # prints out where the mouse is during the click for debugging purposes @@ -68,7 +67,8 @@ def main(fps=window_fps): # the main function if level != 6: screen.blit(fps_text, (5, 5)) # this actually renders "ftp_text" on the screen at the position (5, 5) which is the top left corner pygame.display.flip() # this updates the display so it displays all the new stuff we added + await asyncio.sleep(0) clock.tick(fps) # this makes sure the game loop runs at the fps we set it to before pygame.quit() #this quits our game when the game loop somehow ends, for example by pressing escape or the X button on the window if __name__ == "__main__": # this just makes sure that this only runs when you launch it and not when you import it as a module like we imported levels.py at the top - main() # this actually runs our stuff \ No newline at end of file + asyncio.run(main()) # this actually runs our stuff \ No newline at end of file