world.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # THIS IS A SOURCE CODE FILE FROM I'M NOT EVEN HUMAN THE GAME.
  2. # IT COULD BE USED IN A DIFFERENT PIECE OF SOFTWARE ( LIKE A
  3. # DIFFERENT GAME ), BUT IT WAS ORIGINALLY WRITTEN FOR I'M NOT
  4. # EVEN HUMAN THE GAME.
  5. # THE DEVELOPERS OF THE GAME ARE : (C) J.Y.AMIHUD, AYYZEE AND
  6. # OTHER CONTRIBUTORS. THIS AND OTHER FILES IN THIS GAME,
  7. # UNLESS SPECIFICALLY NOTED, COULD BE USED UNDER THE TERMS OF
  8. # GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER VERSION.
  9. import os
  10. import json
  11. import cairo
  12. from modules import ui
  13. def draw(game, outlayer, x, y, w, h, grid=True):
  14. """This function will draw the level it self"""
  15. x = int(x)
  16. y = int(y)
  17. w = int(w)
  18. h = int(h)
  19. # To make it a bit more nice, I will use a separate image
  20. # layer for the level.
  21. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h)
  22. layer = cairo.Context(surface)
  23. layer.set_antialias(cairo.ANTIALIAS_NONE)
  24. if game.current["testing"]:
  25. ui.color(game, layer, "red")
  26. layer.rectangle(0,0,w-1,h-1)
  27. layer.stroke()
  28. sidex = 64
  29. sidey = 36
  30. offsetx = int(sidex / 2)
  31. offsety = int(sidey / 2)
  32. # moving the game world
  33. if game.current["MMB"]:
  34. game.current["camera"][0] += (game.current["mx"] - game.previous["mx"])
  35. game.current["camera"][1] += (game.current["my"] - game.previous["my"])
  36. # Drawing the cells
  37. for th in range(int(h/offsety)+4):
  38. offx = game.current["camera"][0] % sidex
  39. offy = game.current["camera"][1] % sidey
  40. if th % 2 == 0:
  41. offx += offsetx
  42. for tw in range(int(w/sidex)+3):
  43. drawx = (tw-2)*sidex+offx
  44. drawy = (th-3)*offsety+offy
  45. ui.color(game, layer, "#00FF00")
  46. ui.image(game, layer,
  47. drawx,
  48. drawy,
  49. "assets/grid.png", color=True)
  50. # THIS MAGICAL MATH GIVES US THE CURRENT CELL
  51. xaddr = 0-int( (game.current["camera"][0] - drawx) / sidex )
  52. yaddr = 0-int( (game.current["camera"][1] - drawy) / offsety )
  53. ui.text(game,layer, str(xaddr)+":"+str(yaddr),
  54. offsetx+((tw-2)*sidex+offx),
  55. -4+offsety+((th-3)*offsety+offy),
  56. align="center")
  57. # Drawing the world to the outlayer
  58. outlayer.set_source_surface(surface, x , y)
  59. outlayer.paint()
  60. def generate_empty_chunk(game):
  61. """This function will generate empty chunks"""
  62. chunkx = 50
  63. chunky = 50
  64. sidex = 62
  65. sidey = 36
  66. offsetx = int(sidex / 2)
  67. offsety = int(sidey / 2)
  68. # The chunk will be more or less square
  69. # [ 1 ][ 2 ][ 3 ]
  70. # [ 4 ][ 5 ][ 6 ]
  71. # [ 7 ][ 8 ][ 9 ]