bombcopy.py 884 B

1234567891011121314151617181920212223242526272829303132333435
  1. import json
  2. import pygame
  3. BOMB_FRAME_ROOT = "game/frame/bomb/"
  4. BOMB_IMG_ROOT = "res/img/bomb/"
  5. bombs = {}
  6. def get_bomb(name):
  7. if name not in bombs.keys():
  8. bombs[name] = load_bomb(name)
  9. return bombs[name]
  10. def load_bomb(name):
  11. a_bomb = {}
  12. with open(BOMB_FRAME_ROOT + name + ".json") as f:
  13. bomb_json = json.load(f)
  14. a_bomb["INTERVAL"] = bomb_json["INTERVAL"]
  15. a_bomb["STAND"] = list()
  16. size = len(bomb_json["STAND"]["IMG"])
  17. for i in range(size):
  18. img = pygame.image.load(BOMB_IMG_ROOT + '/' + bomb_json["STAND"]["IMG"][i]).convert_alpha()
  19. cx = bomb_json["STAND"]["CX"][i]
  20. cy = bomb_json["STAND"]["CY"][i]
  21. a_bomb["STAND"].append(Frame(img, cx, cy))
  22. return a_bomb
  23. class Frame:
  24. def __init__(self, image: pygame.Surface, cx, cy):
  25. self.image = image
  26. self.cx = cx
  27. self.cy = cy