Skip to content

Instantly share code, notes, and snippets.

@p-acDev
Last active April 4, 2021 19:49
Show Gist options
  • Select an option

  • Save p-acDev/78bafc285018022ea8ea51a149394d7f to your computer and use it in GitHub Desktop.

Select an option

Save p-acDev/78bafc285018022ea8ea51a149394d7f to your computer and use it in GitHub Desktop.
{
"appName": "War Game",
"windowSettings": {
"WIDTH": 900,
"HEIGHT": 500
},
"FPS": 60
}
class WarGameUI:
def __init__(self, config_file):
# import the input data
with open(config_file, "r") as f:
self.CONFIG = json.load(f)
# setup initial windows
self.WIN = pygame.display.set_mode((self.CONFIG["windowSettings"]["WIDTH"],
self.CONFIG["windowSettings"]["HEIGHT"]))
pygame.display.set_caption(self.CONFIG["appName"])
class Player:
def __init__(self, player_profile):
with open(player_profile, "r") as f:
profile = json.load(f)
self.player_image = pygame.image.load(os.path.join('assets',
profile["player_picture"]))
self.player_image = pygame.transform.scale(self.player_image,(profile["width"],
profile["height"]))
self.name = profile["playerName"]
self.width = profile["width"]
self.height = profile["height"]
self.initialX = profile["initialX"] - self.width / 2
self.initialY = profile["initialY"] - self.height / 2
self.x = self.initialX
self.y = self.initialY
self.keyUp = profile["keyUp"]
self.keyDown = profile["keyDown"]
{
"player_picture": "bar.png",
"playerName": "left",
"initialX": 10,
"initialY": 250,
"width": 15,
"height": 50,
"keyUp": "a",
"keyDown": "q",
"fire": "s"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment