item.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import json
  2. import pygame
  3. from game.frame.frame import Frame
  4. from game.file_loader.fileLoader import load_json, load_rouge_data
  5. ITEM_FRAME_ROOT = "game/frame/item/"
  6. ITEM_IMG_ROOT = "res/img/item/"
  7. items = {}
  8. def get_item(name):
  9. if name not in items.keys():
  10. items[name] = load_item(name)
  11. return items[name]
  12. def load_item(name):
  13. an_item = {}
  14. # with open(ITEM_FRAME_ROOT + '/' + name + ".json") as f:
  15. # item_json = json.load(f)
  16. item_json = load_json(ITEM_FRAME_ROOT + '/' + name + ".json")
  17. an_item["INTERVAL"] = item_json["INTERVAL"]
  18. an_item["NAME"] = item_json["NAME"]
  19. append_item(item_json, an_item, "STAND")
  20. append_item(item_json, an_item, "DIE")
  21. return an_item
  22. def append_item(item_json, an_item, state: str):
  23. if state in item_json:
  24. an_item[state] = list()
  25. frames = item_json[state]
  26. size = len(frames["IMG"])
  27. for i in range(size):
  28. # print(ITEM_IMG_ROOT + frames["IMG"][i])
  29. img = pygame.image.load(ITEM_IMG_ROOT + frames["IMG"][i]).convert_alpha()
  30. cx = frames["CX"][i]
  31. cy = frames["CY"][i]
  32. an_item[state].append(Frame(img, cx, cy))