Package: pygame-hotreload
pygame-hotreloadTable of Contentspygame-hotreloadInstallationHow it workimports-start-hotreloadglobals-start-hotreloadinit-start-hotreloadloop-start-hotreloadExamplegame.pygen.pyContributingDevelopmentLicenseInstallationpipinstallpygame-hotreloadHow it workThepygame-hotreloadmodule is a simple hot-reload module for pygame. It is partialy parse the main python file provided.It looks for these comments in the main file:imports-start-hotreload# imports-start-hotreload...# imports-end-hotreloadThis is where the module will look for the imports that needed for the game loop.globals-start-hotreload# globals-start-hotreload...# globals-end-hotreloadThis is where the module will look for the global variables that needed for the game loop.init-start-hotreload# init-start-hotreload...# init-end-hotreloadThis is where the module will look for the initialization of the game loop.
There is where you should initialize your global variables.loop-start-hotreload# loop-start-hotreload...# loop-end-hotreloadThis is where the module will look for the game loop.Examplegame.py# game.pyfrompygame_hotreloadimportHotReload,set_caption# imports-start-hotreloadimportpygame# imports-end-hotreload# Initialize pygamepygame.init()# Set the window captionset_caption("Hot Reload Example")clock=pygame.time.Clock()screen_width=800screen_height=600screen=pygame.display.set_mode((screen_width,screen_height))# globals-start-hotreloadglobaldtglobalplayer_posglobalplayer_pos_2# globals-end-hotreload# init-start-hotreloaddefinit():globaldtglobalplayer_posglobalplayer_pos_2dt=0player_pos=pygame.Vector2(screen.get_width()/2,screen.get_height()/2)player_pos_2=pygame.Vector2(screen.get_width()//3,screen.get_height()//3)# init-end-hotreload# loop-start-hotreloaddefloop():globaldtglobalplayer_posglobalplayer_pos_2screen.fill("black")pygame.draw.rect(screen,"purple",pygame.Rect(player_pos.x,player_pos.y,100,100))pygame.draw.rect(screen,"purple",pygame.Rect(player_pos_2.x,player_pos_2.y,100,100),1)keys=pygame.key.get_pressed()ifkeys[pygame.K_z]orkeys[pygame.K_UP]:player_pos.y-=300*dtifkeys[pygame.K_s]orkeys[pygame.K_DOWN]:player_pos.y+=300*dtifkeys[pygame.K_q]orkeys[pygame.K_LEFT]:player_pos.x-=300*dtifkeys[pygame.K_d]orkeys[pygame.K_RIGHT]:player_pos.x+=300*dtdt=clock.tick(60)/1000# loop-end-hotreload# Initialize the hot reloadhotreload=HotReload(main_file=__file__,screen=screen,clock=clock,clock_tick=60,gen_script_name="gen.py",)hotreload.run()gen.pyimportpygameglobaldtglobalplayer_posglobalplayer_pos_2definit():globaldtglobalplayer_posglobalplayer_pos_2dt=0player_pos=pygame.Vector2(screen.get_width()/2,screen.get_height()/2)player_pos_2=pygame.Vector2(screen.get_width()//3,screen.get_height()//3)defloop():globaldtglobalplayer_posglobalplayer_pos_2screen.fill("black")pygame.draw.rect(screen,"purple",pygame.Rect(player_pos.x,player_pos.y,100,100))pygame.draw.rect(screen,"purple",pygame.Rect(player_pos_2.x,player_pos_2.y,100,100),1)keys=pygame.key.get_pressed()ifkeys[pygame.K_z]orkeys[pygame.K_UP]:player_pos.y-=300*dtifkeys[pygame.K_s]orkeys[pygame.K_DOWN]:player_pos.y+=300*dtifkeys[pygame.K_q]orkeys[pygame.K_LEFT]:player_pos.x-=300*dtifkeys[pygame.K_d]orkeys[pygame.K_RIGHT]:player_pos.x+=300*dtdt=clock.tick(60)/1000ContributingContributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.DevelopmentTo set uppygame-hotreloadfor local development:Fork thepygame-hotreloadrepository.Clone your fork locallyUsepipenv shellto enter the virtual environmentUsepipenv installto install all dependenciesMake a change, and push your local branch to your forkMake a pull requestYou can build your own version of the project withhatch version beta && hatch build --wheeland install it withpipenv install dist/pygame_hotreload-<VERSION>-py3-none-any.whlLicensepygame-hotreloadis distributed under the terms of theMITlicense.