__init__.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. #!/usr/bin/env python
  2. #! coding: utf-8
  3. #! python3
  4. # Python ish game layer à la GM
  5. # Dirty as hay, if you learn python with this file, you will learn garbage.
  6. # 2022-2024
  7. import random
  8. import os
  9. #os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
  10. import pygame
  11. import pygame.freetype
  12. # Basic message system
  13. def info( message="!?" ) :
  14. color = ""
  15. reset = ""
  16. if __colorConsole__ :
  17. reset = colorama.Style.RESET_ALL
  18. color = colorama.Style.BRIGHT + colorama.Fore.CYAN
  19. print( f"{color}[info] {message}{reset}" )
  20. def warning( message="!?" ) :
  21. color = ""
  22. reset = ""
  23. if __colorConsole__ :
  24. reset = colorama.Style.RESET_ALL
  25. color = colorama.Style.BRIGHT + colorama.Fore.YELLOW
  26. print( f"{color}[Warn] {message}{reset}" )
  27. def error( message="!?" ) :
  28. color = ""
  29. reset = ""
  30. if __colorConsole__ :
  31. reset = colorama.Style.RESET_ALL
  32. color = colorama.Style.BRIGHT + colorama.Fore.RED
  33. print( f"\a{color}[ERR.] {message}{reset}" )
  34. # Optional libraries
  35. __colorConsole__ = True
  36. try :
  37. import colorama
  38. colorama.init( autoreset=False )
  39. info( "color console output" )
  40. except ImportError or ModuleNotFoundError :
  41. __colorConsole__ = False
  42. info( "monochrome console output" )
  43. _internal_backgrounds = {}
  44. _internal_sounds = []
  45. _internal_musics = {}
  46. _internal_fonts = []
  47. #===== Computing things =====
  48. #===== Game play =====
  49. #===== User interaction =====
  50. #===== Game graphics =====
  51. #===== Sound and music =====
  52. #----- Basic sound functions -----
  53. # Plays the indicates sound once. If the sound is background music the current background music is stopped.
  54. def sound_play( index=None ) :
  55. # if index in _internal_sounds :
  56. # snd = _internal_sounds[index]
  57. # if not snd.loaded :
  58. # pygame.mixer.music.load( snd.filename )
  59. # snd.loaded = True
  60. # pygame.mixer.music.play()
  61. pass
  62. # Plays the indicates sound, looping continuously. If the sound is background music the current background music is stopped.
  63. def sound_loop( index=None ) :
  64. pass
  65. # Stops the indicates sound. If there are multiple sounds with this index playing simultaneously, all will be stopped.
  66. def sound_stop( index=None ) :
  67. pass
  68. # Stops all sounds.
  69. def sound_stop_all() :
  70. for sndIndex in _internal_sounds :
  71. sound_stop( sndIndex )
  72. # Returns whether (a copy of) the indicated sound is playing.
  73. def sound_isplaying( index=None ) :
  74. pass
  75. # Plays or loops the music. The current music is stopped beforehand.
  76. def music_play( name=None, loop=False ) :
  77. global _internal_musics
  78. if music_exists( name ) :
  79. msk = _internal_musics[name]
  80. pygame.mixer.music.unload()
  81. if msk["intro"] != None :
  82. pygame.mixer.music.load( msk["intro"])
  83. pygame.mixer.music.play()
  84. pygame.mixer.music.queue( msk["file"], loops={True:-1, False:0}[loop] )
  85. else :
  86. pygame.mixer.music.load( msk["file"] )
  87. pygame.mixer.music.play( {True:-1, False:0}[loop])
  88. # Plays the indicated music, looping continuously.
  89. # The current music is stopped beforehand.
  90. # You can use music_play( loop=True ) too
  91. def music_loop( index=None ) :
  92. music_play( index, loop=True )
  93. # Stops the music.
  94. def music_stop() :
  95. pygame.mixer.music.stop()
  96. pygame.mixer.music.unload()
  97. # Returns whether music is playing.
  98. def music_isplaying() :
  99. return pygame.mixer.music.get_busy()
  100. #----- Special effects -----
  101. #----- 3D music -----
  102. #----- CD music -----
  103. #===== Splash screens, highscores and other pop-ups =====
  104. #===== Resources =====
  105. #===== Changing resources =====
  106. #----- Sprites -----
  107. #----- Sound -----
  108. # Adds a sound resource to the game. fname is the name of the sound file.
  109. # kind indicates the kind of sound (0=normal, 1=background, 2=3d, 3=mmplayer) preload indicates whether the sound should immediately be stored in audio memory (true or false).
  110. # The function returns the index of the new sound, which can be used to play the sound. (-1 if an error occurred, e.g. the file does not exist).
  111. def sound_add(fname,kind,preload) :
  112. pass
  113. # Same as the previous function but this time a new sound is not created but the existing sound index is replaced, freeing the old sound.
  114. # Returns whether correct.
  115. def sound_replace(index,fname,kind,preload) :
  116. pass
  117. # Deletes the indicated sound, freeing all memory associated with it.
  118. # It can no longer be restored.
  119. def sound_delete(index) :
  120. pass
  121. def music_add( name, filename, intro=None ):
  122. global _internal_musics
  123. ret = None
  124. if not isinstance( name, str ) :
  125. error( f"music_delete: name must be a string, got '{name}' instead." )
  126. else :
  127. if len( name ) > 0 :
  128. if not os.path.exists( filename ) :
  129. warning( f"music_add: Unable to check file '{filename}'." )
  130. else :
  131. msk = {"file":filename, "intro":None}
  132. if intro != None :
  133. if not os.path.exists( intro ) :
  134. warning( f"music_add: Unable to check intro file '{intro}'." )
  135. else :
  136. msk["intro"] = intro
  137. _internal_musics[name] = msk
  138. ret = name
  139. return ret
  140. # Delete the music with the given name
  141. def music_delete( name ):
  142. global _internal_musics
  143. ret = None
  144. if not isinstance( name, str ) :
  145. error( f"music_delete: name must be a string, got '{name}' instead." )
  146. else :
  147. if name in _internal_musics :
  148. # No data is loaded until playing, so we can simply remove the entry
  149. del _internal_musics[name]
  150. else :
  151. warning( f"music_delete: '{name}' is not a loaded music." )
  152. return ret
  153. # Checks if a music with this name already exists
  154. def music_exists( name ):
  155. global _internal_musics
  156. ret = False
  157. if not isinstance( name, str ) :
  158. error( f"music_exists: name must be a string, got '{name}' instead." )
  159. else :
  160. if name in _internal_musics :
  161. ret = True
  162. return ret
  163. #----- Backgrounds -----
  164. def background_add( name, filename, removeback=False, smooth=False ) :
  165. global _internal_backgrounds
  166. ret = None
  167. if not isinstance( name, str ) :
  168. error( f"background_add: Unnacceptable name '{name}'." )
  169. else :
  170. if len( name ) > 0 :
  171. if not os.path.exists( filename ) :
  172. warning( f"background_add: Unable to check file '{filename}'." )
  173. else :
  174. bck = {"file":filename, "surface":None}
  175. bck["surface"] = pygame.image.load( bck["file"] )
  176. _internal_backgrounds[name] = bck
  177. ret = name
  178. return ret
  179. def background_delete( name ):
  180. global _internal_backgrounds
  181. ret = None
  182. if not isinstance( name, str ) :
  183. error( f"background_delete: name must be a string, got '{name}' instead." )
  184. else :
  185. if name in _internal_backgrounds :
  186. del _internal_backgrounds[name]["surface"]
  187. del _internal_backgrounds[name]
  188. else :
  189. print( f"background_delete: '{name}' is not a loaded background" )
  190. return ret
  191. def background_exists( name ):
  192. global _internal_backgrounds
  193. ret = False
  194. if not isinstance( name, str ) :
  195. error( f"background_delete: name must be a string, got '{name}' instead." )
  196. else :
  197. if name in _internal_backgrounds :
  198. ret = True
  199. return ret
  200. #----- Fonts -----
  201. def font_add( name=None, size=16, bold=False, italic=False, first=32, last=128 ) :
  202. global _internal_fonts
  203. # Size sanity check
  204. size = int( size )
  205. if size < 1 : size = 1
  206. # Font file check
  207. if name != None :
  208. if not os.path.exists( name ) :
  209. warning( f"Can't find file '{name}', fall back to default font." )
  210. name = None
  211. # Load it
  212. if name != None :
  213. # font = pygame.freetype.Font( name, size )
  214. font = pygame.font.Font( name, size )
  215. else :
  216. font = pygame.font.SysFont( None, size )
  217. _internal_fonts.append( font )
  218. return font
  219. #----- Paths -----
  220. #----- Scripts -----
  221. #----- time lines -----
  222. #----- Objects -----
  223. #----- Rooms -----
  224. #===== Files, registry, and executing programs =====
  225. #===== Data structures =====
  226. #===== Creating particles =====
  227. #===== Multiplayer games =====
  228. #===== Using DLL's =====
  229. #===== 3D Graphics =====
  230. #----- Timelines -----
  231. #----- Objects -----
  232. #----- Instances -----
  233. #----- Rooms -----
  234. #===== General Game Control =====
  235. game_initialized = False
  236. game_id = 0
  237. game_save_id = game_id
  238. game_display_name = "Great Mishmash"
  239. game_project_name = "Undefined"
  240. game_clock = 0
  241. # Initialize
  242. def game_init():
  243. global game_clock
  244. pygame.init()
  245. pygame.mixer.init()
  246. game_clock = pygame.time.Clock()
  247. WINDOW_SIZE = (800,600)
  248. surface_create( WINDOW_SIZE )
  249. window_set( WINDOW_SIZE )
  250. _draw_text_currentFont = font_add()
  251. game_initialized = True
  252. #
  253. def game_end() :
  254. pygame.quit()
  255. #
  256. def game_restart( ) :
  257. pass
  258. #
  259. def game_load( ) :
  260. pass
  261. #
  262. def game_load_buffer( ) :
  263. pass
  264. #
  265. def game_save( ) :
  266. pass
  267. #
  268. def game_save_buffer( ) :
  269. pass
  270. #
  271. def game_get_speed( ) :
  272. pass
  273. #
  274. def game_set_speed( ) :
  275. pass
  276. #
  277. def highscore_add() :
  278. pass
  279. #
  280. def highscore_name() :
  281. pass
  282. #
  283. def highscore_value() :
  284. pass
  285. #
  286. def highscore_clear() :
  287. pass
  288. #
  289. def draw_highscore() :
  290. pass
  291. #
  292. def cursor_sprite() :
  293. pass
  294. #===== Movement And Collisions =====
  295. #===== Drawing =====
  296. _draw_surface_currentSurface = None
  297. #----- Drawing shapes -----
  298. # Clears the current surface in the given color
  299. def draw_clear( color=(0,0,0) ) :
  300. global _draw_surface_currentSurface
  301. _draw_surface_currentSurface.fill( color )
  302. # Clears the current surface in the given color and alpha value
  303. def draw_clear_alpha( color=(0,0,0), alpha=0) :
  304. pass
  305. # Draws a point at (x,y) in the current color.
  306. def draw_point( coords=(0,0) ) : pass
  307. # Draws a line from (x1,y1) to (x2,y2).
  308. def draw_line( start=(0,0), end=(16,16) ) : pass
  309. # Draws a line from (x1,y1) to (x2,y2) with width w.
  310. def draw_line_width( start=(0,0), end=(16,16), width=1 ) : pass
  311. # Draws a rectangle. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
  312. def draw_rectangle( start=(0,0), end=(16,16), outline=True ) :
  313. global _draw_surface_currentSurface
  314. global _draw_color_currentColor
  315. global _draw_color_currentAlpha
  316. width = 0
  317. if outline == True : width = 1
  318. color = _draw_color_currentColor
  319. if (_draw_color_currentAlpha != 1) :
  320. s = pygame.Surface( (end[0]-start[0], end[1]-start[1]) )
  321. s.set_alpha( int(_draw_color_currentAlpha*255) )
  322. s.fill( color )
  323. _draw_surface_currentSurface.blit( s, (start[0], start[1]) )
  324. else :
  325. pygame.draw.rect( _draw_surface_currentSurface, color, (start[0], start[1], end[0]-start[0], end[1]-start[1]), width=width )
  326. #----- Colour And Alpha -----
  327. c_aqua = (0,255,255)
  328. c_black = (0,0,0)
  329. c_blue = (0,0,255)
  330. c_dkgray = (64,64,64)
  331. c_fuchsia = (255,0,255)
  332. c_gray = (128,128,128)
  333. c_green = (0,128,0)
  334. c_lime = (0,255,0)
  335. c_ltgray = (192,192,192)
  336. c_maroon = (128,0,0)
  337. c_navy = (0,0,128)
  338. c_olive = (128,128,0)
  339. c_orange = (64,160,0)
  340. c_purple = (128,0,128)
  341. c_red = (255,0,0)
  342. c_silver = (192,192,192)
  343. c_teal = (0,128,128)
  344. c_white = (255,255,255)
  345. c_yellow = (255,255,0)
  346. _draw_color_currentColor = c_black
  347. _draw_color_currentAlpha = 1
  348. #
  349. def colour_get_blue() :
  350. pass
  351. #
  352. def colour_get_green() :
  353. pass
  354. #
  355. def colour_get_red() :
  356. pass
  357. #
  358. def colour_get_hue() :
  359. pass
  360. #
  361. def colour_get_saturation() :
  362. pass
  363. #
  364. def colour_get_value() :
  365. pass
  366. #
  367. def draw_getpixel() :
  368. pass
  369. #
  370. def draw_getpixel_ext() :
  371. pass
  372. #
  373. def draw_get_colour() :
  374. pass
  375. #
  376. def draw_get_alpha() :
  377. pass
  378. #
  379. def make_colour_hsv() :
  380. pass
  381. #
  382. def make_colour_rgb( r=0, g=0, b=0) :
  383. return (r,g,b)
  384. #
  385. def merge_colour() :
  386. pass
  387. #
  388. def draw_set_alpha( alpha=0 ) :
  389. global _draw_color_currentAlpha
  390. _draw_color_currentAlpha = alpha
  391. #
  392. def draw_set_color( color=(0,0,0) ) :
  393. global _draw_color_currentColor
  394. if len(color) == 4 :
  395. draw_set_alpha( color[3]/255 )
  396. _draw_color_currentColor = color[:3]
  397. #Non standard GM
  398. def sanitize_color( color=None ):
  399. # Default to black
  400. if color == None : color = 0
  401. # String families (Hex, HTML and stringified lists)
  402. if isinstance( color, str ) :
  403. if (color[0]=='(') and (color[-1]==')') and color.count(',') in (2,3) :
  404. color = [int(c) for c in color[1:-1].split(',')]
  405. else:
  406. #TODO: scan for $ or # for hex color, and maybe some html names
  407. color = (0,0,0)
  408. # RGB integer
  409. if isinstance( color, int ) :
  410. make_color_rgb( (color % 256), ((color/256)%256), ((color/65536)%256) )
  411. # multiple values
  412. if isinstance( color, tuple ) or isinstance( color, list ) :
  413. if len( color ) not in [3,4] :
  414. color = (0,0,0)
  415. return color
  416. #----- GPU Control -----
  417. #----- Mipmapping -----
  418. #----- Basic Forms -----
  419. #----- Sprites And Tiles -----
  420. def draw_background( background=None, x=0, y=0 ) :
  421. # width = background_get_width( background )
  422. # height = background_get_height( background )
  423. width, height = background_get_size( background )
  424. draw_background_general( background, 0,0,width,height, x,y, 1,1, 0, c_white,c_white,c_white,c_white, 1 )
  425. def draw_background_general( background=None, left=0,top=0, width=16,height=16, x=0,y=0, xscale=1,yscale=1, rotation=0, c1=c_white,c2=c_white,c3=c_white,c4=c_white, alpha=1) :
  426. global _internal_backgrounds
  427. if background in _internal_backgrounds :
  428. surface_get_target().blit( _internal_backgrounds[background]["surface"], (x,y) )
  429. #----- Text -----
  430. fa_left = "left"
  431. fa_center = "center"
  432. fa_right = "right"
  433. fa_top = "top"
  434. fa_middle = "middle"
  435. fa_bottom = "bottom"
  436. _draw_text_currentFont = None
  437. _draw_text_hAlign = fa_left
  438. _draw_text_vAlign = fa_top
  439. #
  440. def draw_set_font( font=None ) :
  441. global _internal_fonts
  442. global _draw_text_currentFont
  443. if font not in _internal_fonts : font = _internal_fonts[0]
  444. _draw_text_currentFont = font
  445. #
  446. def draw_set_halign( halign=fa_left ) :
  447. global _draw_text_hAlign
  448. if halign not in [fa_left, fa_center, fa_right] :
  449. halign = fa_left
  450. _draw_text_hAlign = halign
  451. #
  452. def draw_set_valign( valign=fa_top ) :
  453. global _draw_text_vAlign
  454. if valign not in [fa_top, fa_middle, fa_bottom] :
  455. valign = fa_top
  456. _draw_text_vAlign = valign
  457. #
  458. def draw_get_font( ) :
  459. global _draw_text_currentFont
  460. return _draw_text_currentFont
  461. #
  462. def draw_get_halign( ) :
  463. global _draw_text_hAlign
  464. return _draw_text_hAlign
  465. #
  466. def draw_get_valign( ) :
  467. global _draw_text_vAlign
  468. return _draw_text_vAlign
  469. #
  470. def draw_text( coords=(0,0), string="Text" ) :
  471. draw_text_color( coords, string, _draw_color_currentColor, _draw_color_currentAlpha )
  472. #
  473. def draw_text_ext( ) :
  474. pass
  475. #
  476. def draw_text_color( coords=(0,0), string="Text", colors=( c_black, c_black, c_white, c_white), alpha=0.5 ) :
  477. global _draw_surface_currentSurface
  478. global _draw_text_currentFont
  479. global _draw_text_hAlign
  480. global _draw_text_vAlign
  481. error = None
  482. # Normalization and sanity checks
  483. if _draw_surface_currentSurface == None : error = "No surface"
  484. if _draw_text_currentFont == None : error = "No Font"
  485. if isinstance( coords, tuple ) or isinstance( coords, list ) :
  486. x,y = coords
  487. else :
  488. error = "Malformed coords"
  489. if not isinstance( string, str ) :
  490. string = str( string )
  491. if isinstance( colors, tuple ) or isinstance( colors, list ) :
  492. #TODO find a way to do it cleanly. Use sanitize_color()
  493. if len( colors ) == 3 :
  494. c = colors
  495. colors = (c,c,c,c)
  496. if error == None :
  497. textImage = _draw_text_currentFont.render( string, False, colors[0])
  498. # Compute coordinates
  499. if _draw_text_hAlign == fa_center :
  500. w,h = textImage.get_size()
  501. x -= w/2
  502. if _draw_text_hAlign == fa_right :
  503. w,h = textImage.get_size()
  504. x += w
  505. if _draw_text_vAlign == fa_middle :
  506. w,h = textImage.get_size()
  507. y -= h/2
  508. if _draw_text_vAlign == fa_bottom :
  509. w,h = textImage.get_size()
  510. y += h
  511. _draw_surface_currentSurface.blit( textImage, (x,y) )
  512. else :
  513. error( error )
  514. #
  515. def draw_text_transformed( ) :
  516. pass
  517. #
  518. def draw_text_ext_colour( ) :
  519. pass
  520. #
  521. def draw_text_ext_transformed( ) :
  522. pass
  523. #
  524. def draw_text_transformed_colour( ) :
  525. pass
  526. #
  527. def draw_text_ext_transformed_colour( ) :
  528. pass
  529. #----- Primitives And Vertex Formats -----
  530. #----- Surfaces -----
  531. _internal_surfaces = []
  532. #
  533. def surface_exists() :
  534. pass
  535. # Creates a surface of the indicated width and height.
  536. # Returns the id of the surface, which must be used in all further calls.
  537. # Note that the surface will not be cleared.
  538. def surface_create( size=(128,128) ) :
  539. return surface_create_ext( size, color=None, mode=pygame.SRCALPHA )
  540. #
  541. def surface_create_ext( size=(128,128), color=None, mode=pygame.SRCALPHA ) :
  542. global _internal_surfaces
  543. surface = pygame.Surface( size, mode )
  544. _internal_surfaces.append( surface )
  545. if color != None :
  546. surface_set_target( surface )
  547. draw_clear( color )
  548. surface_reset_target()
  549. return surface
  550. #
  551. def surface_resize() :
  552. pass
  553. #
  554. def surface_set_target( surface=None ) :
  555. global _internal_surfaces
  556. global _draw_surface_currentSurface
  557. if surface not in _internal_surfaces : surface = _internal_surfaces[0]
  558. _draw_surface_currentSurface = surface
  559. #
  560. def surface_get_target() :
  561. global _draw_surface_currentSurface
  562. return _draw_surface_currentSurface
  563. # Resets the drawing target to the normal screen.
  564. def surface_reset_target() :
  565. global _internal_surfaces
  566. global _draw_surface_currentSurface
  567. _draw_surface_currentSurface = _internal_surfaces[0]
  568. #----- Lighting -----
  569. #----- Particles -----
  570. #----- Textures -----
  571. #----- Shaders -----
  572. #----- Video Playback -----
  573. #===== Cameras And Display =====
  574. def window_set( size=(640,480), flags=pygame.SHOWN ) :
  575. global _internal_surfaces
  576. global _draw_surface_currentSurface
  577. pygame.display.quit()
  578. pygame.display.init()
  579. _internal_surfaces[0] = pygame.display.set_mode( size, flags )
  580. surface_reset_target()
  581. #===== Ressources =====
  582. #----- Background -----
  583. # Returns whether a background with the given index exists.
  584. def background_exists( index=None ):
  585. pass
  586. # Returns the name of the background with the given index.
  587. def background_get_name( index=None ):
  588. pass
  589. # Returns the width of the background with the given index.
  590. def background_get_width( name=None ):
  591. global _internal_backgrounds
  592. pass
  593. # Returns the height of the background with the given index.
  594. def background_get_height( name=None ):
  595. global _internal_backgrounds
  596. pass
  597. #
  598. def background_get_size( name=None ):
  599. return ( background_get_width( name ), background_get_height( name ) )
  600. # In certain situations you might want to save the bitmap corresponding the background to a file. For this the following function can be used:
  601. # Saves the background ind to the file with the name fname. This must be a .png file.
  602. def background_save( index=None, fname=None ):
  603. pass
  604. #===== Game Input =====
  605. #===== Data Structures =====
  606. #===== Strings =====
  607. #===== Maths And Numbers =====
  608. #===== Physics =====
  609. #===== Asynchronous Functions =====
  610. #===== Networking =====
  611. #===== File Handling =====
  612. #===== Buffers =====
  613. #===== Debugging =====
  614. #===== Garbage Collection =====
  615. # Miscelaneous
  616. # Choose one item of a list at random
  617. def choose( l=None ) :
  618. r = None
  619. if l != None :
  620. r = l[ random.randrange( 0, len(l) ) ]
  621. return r
  622. # Initialisation
  623. if __name__=="__main__":
  624. game_init()
  625. draw_set_color( (255,255,255) )
  626. bigFont = font_add( None, 64 )
  627. smlFont = font_add( None, 16 )
  628. running = True
  629. while running:
  630. # Event handling, gets all event from the event queue
  631. for event in pygame.event.get():
  632. if event.type == pygame.QUIT:
  633. running = False
  634. # Draw
  635. draw_clear()
  636. draw_set_font( bigFont )
  637. draw_text( (8,8), "GM" )
  638. draw_set_font( smlFont )
  639. draw_text( (8,48), "is meant to be used as a lib." )
  640. pygame.display.flip()
  641. game_clock.tick(60)
  642. pygame.event.poll()