Kazeged.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/usr/bin/env python
  2. #! coding: utf-8
  3. #! python3
  4. # Kazeged 2022
  5. import argparse
  6. import os.path
  7. import random
  8. import GM
  9. #==============================================================================
  10. # Gather arguments
  11. #==============================================================================
  12. def Args():
  13. parser = argparse.ArgumentParser()
  14. parser.add_argument( "-p", "--play", default=None, dest="gameFolder", help="Auto load a game folder" )
  15. parser.add_argument( "-g", "--games-folder", default=None, dest="gamesFolder", help="Change the games folder" )
  16. parser.add_argument( "-s", "--skip-intro", default=False, action="store_true", dest="skipIntro", help="Skips intro" )
  17. return parser.parse_args()
  18. #==============================================================================
  19. # Engine intro
  20. #==============================================================================
  21. def engine_intro() :
  22. clock = GM.pygame.time.Clock()
  23. GM.draw_set_color( (255,255,255) )
  24. GM.draw_set_halign( GM.fa_center )
  25. GM.draw_set_valign( GM.fa_middle )
  26. running = True
  27. counter = 0
  28. step = 0
  29. titleFont = GM.font_add( None, 64 )
  30. titleText = "Kazeged"
  31. subFont = GM.font_add( None, 20 )
  32. subText = GM.choose( ["Stories to tell", "The mane engine", "Always mare", "Horsing around"] )
  33. W,H = GM._draw_surface_currentSurface.get_size()
  34. while running:
  35. # Event handling, gets all event from the event queue
  36. for event in GM.pygame.event.get():
  37. if event.type == GM.pygame.QUIT:
  38. running = False
  39. # Step
  40. counter += 1
  41. if step == 0 :
  42. C = 192 * min( 1, (counter/63.0) )
  43. if counter > 63 :
  44. counter = 0
  45. step = 1
  46. elif step == 1:
  47. C = 192
  48. if counter > 63 :
  49. counter = 0
  50. step = 2
  51. elif step == 2:
  52. C = 192 * (1-min( 1, (counter/31.0) ))
  53. if counter > 31 :
  54. running = False
  55. else :
  56. C = 255
  57. # Draw
  58. GM.draw_clear()
  59. r = random.randrange(-2,2)
  60. GM.draw_set_font( titleFont )
  61. GM.draw_text_color( ((W/2)+2+r,(H/2)+2+r), titleText, (C,0,0) )
  62. GM.draw_text_color( ((W/2)-2+r,(H/2)+2+r), titleText, (0,C,0) )
  63. GM.draw_text_color( ((W/2)+r,(H/2)-2+r), titleText, (0,0,C) )
  64. GM.draw_text_color( (W/2, H/2), titleText, (0,0,0) )
  65. GM.draw_set_font( subFont )
  66. GM.draw_text_color( (W/2,(H/2)+64), subText, (C,C,C) )
  67. # surface.fill( blendColor, None, 0x3 ) #0x3 = BLEND_RGB_MULT
  68. GM.pygame.display.flip()
  69. clock.tick(60)
  70. GM.pygame.event.poll()
  71. #==============================================================================
  72. # Main program
  73. #==============================================================================
  74. engineFolder = os.path.dirname( os.path.realpath( __file__ ) )
  75. args = Args()
  76. # Initialize
  77. clock = GM.pygame.time.Clock()
  78. # Create a surface on screen
  79. background_color = (0,0,0)
  80. screen = GM._draw_surface_currentSurface
  81. display = GM.pygame.Surface( (256, 200) )
  82. # Check parameters: Skip engine intro?
  83. if args.skipIntro == False : engine_intro()
  84. # Check parameters: Change game lib folder?
  85. gamesFolder = engineFolder + "/Games"
  86. if args.gamesFolder :
  87. if os.path.exists( args.gamesFolder ) :
  88. gamesFolder = args.gamesFolder
  89. # Check parameters: Auto load a game folder?
  90. gameFolder = None
  91. if args.gameFolder :
  92. if os.path.exists( args.gameFolder ) :
  93. gameFolder = args.gameFolder
  94. # Small interface to choose the game to load if non given
  95. if gameFolder == None :
  96. GM.draw_set_color( (255,255,255) )
  97. GM.draw_set_halign( GM.fa_left )
  98. GM.draw_set_valign( GM.fa_top )
  99. GM.draw_set_font( None )
  100. GM.draw_text( (0,0), "Loading game list..." )
  101. GM.pygame.display.flip()
  102. _, directories, files = next( os.walk( gamesFolder ) )
  103. gameList = []
  104. # Check wich folder is a game
  105. for directory in directories :
  106. configFile = os.path.join(gamesFolder,directory, "Kazeged.game")
  107. if os.path.exists(configFile) :
  108. with open(configFile, "r") as f: meta = {k:v for k, v in (l.replace("\n", "").split("=") for l in f)}
  109. print("Game: " + meta["name"])
  110. meta["path"] = os.path.join(gamesFolder,directory)
  111. if "icon" in meta: meta["icon"] = GM.pygame.image.load(os.path.join(meta["path"], meta["icon"]))
  112. else: meta["icon"] = GM.pygame.image.load(engineFolder + "/404.png")
  113. gameList.append(meta)
  114. if len( gameList ) > 0 :
  115. y = 40
  116. GM.draw_set_valign( GM.fa_middle )
  117. for game in gameList :
  118. GM.draw_text( (40,y+20), game["name"] )
  119. GM._draw_surface_currentSurface.blit(game["icon"], (4,y+4) )
  120. y += 40
  121. else :
  122. GM.draw_text( (0,16), "No game found." )
  123. # Really dirty debug
  124. running = True
  125. while running:
  126. # Event handling, gets all event from the event queue
  127. for event in GM.pygame.event.get():
  128. if event.type == GM.pygame.QUIT:
  129. running = False
  130. GM.pygame.display.flip()
  131. clock.tick(60)
  132. GM.pygame.event.poll()
  133. GM.game_end()