flame.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import json
  2. import pygame
  3. import game.const.game as G
  4. FLAME_JSON_ROOT = "game/frame/flame/"
  5. FLAME_JSON_FILE = "flame.json"
  6. FLAME_IMG_ROOT = "res/img/flame/"
  7. ORIENTATIONS = ("FLAME_C", "FLAME_R", "FLAME_U", "FLAME_L", "FLAME_D")
  8. flames = {}
  9. flame_seq = None
  10. try:
  11. with open(G.GAME_PATH + "\\" + FLAME_JSON_ROOT + '/' + FLAME_JSON_FILE) as f:
  12. j = json.load(f)
  13. flame_seq = j["FLAME_SEQ"]
  14. except Exception as e:
  15. print(e)
  16. def get_flame(orientation):
  17. if orientation not in flames.keys():
  18. flames[orientation] = list()
  19. with open(G.GAME_PATH + "\\" + FLAME_JSON_ROOT + '/' + FLAME_JSON_FILE) as f:
  20. flame_json = json.load(f)
  21. root = flame_json[orientation]
  22. size = len(root["IMG"])
  23. for i in range(size):
  24. img = pygame.image.load(G.GAME_PATH + "\\" + FLAME_IMG_ROOT + '/' + root["IMG"][i]).convert_alpha()
  25. cx = root["CX"][i]
  26. cy = root["CY"][i]
  27. a_flame = Frame(img, cx, cy)
  28. flames[orientation].append(a_flame)
  29. return flames[orientation]
  30. class Frame:
  31. def __init__(self, image: pygame.Surface, cx, cy):
  32. self.image = image
  33. self.cx = cx
  34. self.cy = cy