finished it up to work for pygbag with asyncio :3

This commit is contained in:
Martin Dvořák 2026-05-31 23:30:48 +02:00
commit 1ccdfc6ee8
2 changed files with 6 additions and 6 deletions

View file

@ -9,8 +9,8 @@ holding_milk = False
zombie_hp = 20 zombie_hp = 20
milkactive = False milkactive = False
enemy_zombies = [ 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": 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": pygame.Rect(400, 300, 56, 96), "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 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

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python3 #!/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 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 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 pygame.init() # initalizes pygame
screen_width = 768 # the screen width screen_width = 768 # the screen width
screen_height = 576 # the screen height 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.type == pygame.KEYDOWN: # what happens when you press down a key
if event.key == pygame.K_ESCAPE: # what happens when you press escape if event.key == pygame.K_ESCAPE: # what happens when you press escape
running = False # poof 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 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 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 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: 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 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 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 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 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 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 asyncio.run(main()) # this actually runs our stuff