import os import math import time from PIL import Image # Tells OS where to place the window os.environ['SDL_VIDEO_WINDOW_POS'] = str(460) + "," + str(40) # helper function that processes commandline arguments into key-value pairs or a list of arguments from helper_module import mykwargs # returns a dictionary of color names and their hex/rgb values from helper_module import load_json # grab command line arguments using the helper function and put them into a dictionary _, ARGDICT = mykwargs(sys.argv) # constants TILE_WIDTH = int(ARGDICT['tile_width']) TILE_HEIGHT = int(ARGDICT['tile_height']) WINDOW_WIDTH_TILE = int(ARGDICT["width"]) WINDOW_HEIGHT_TILE = int(ARGDICT["height"]) WINDOW_WIDTH = WINDOW_WIDTH_TILE*TILE_WIDTH WINDOW_HEIGHT = WINDOW_HEIGHT_TILE*TILE_HEIGHT WINDOW_TITLE = ARGDICT["title"] GAME_FPS = int(ARGDICT["fps"]) # each set of sprite animation frames has an info file that contains the names of the frames, how many exist per set, # and a value for adjusting the rate each frame plays. Since each animation is stored in its own folder, we only need to know # how many frames there are and stick that value into the info file. We'll use a loop to iterate through each frame. player_animations = load_json(ARGDICT["player_images"]+"/info.json")
pressed_keys = pygame.key.get_pressed() Sprites.update(pressed_keys) pygame.display.flip() quit() def usage(): # Params in square brackets are optional # The kwargs function script needs key=value to NOT have spaces print("Usage: python LostPirate.py title=string img_path=string width=int height=int [jsonfile=string]") print("Example:\n\n\t python LostPirate.py title='Wonderer' img_path=./images/zoro.png width=500 height=500 pwidth=100 pheight=100\n") sys.exit() if __name__=='__main__': """ This example has 4 required parameters, so after stripping the file name out of the list argv, I can test the len() of argv to see if it has 4 params in it. """ argv = sys.argv[1:] if len(argv) < 6: print(len(argv)) usage() args,kwargs = mykwargs(argv) # here you have a dictionary with all your parameters in it print("Printing dictionary from name == main:") pprint.pprint(kwargs) # you could send all of them to a main function main(**kwargs)
import math # Tells OS where to open the window os.environ['SDL_VIDEO_WINDOW_POS'] = str(460) + "," + str(40) # helper function that processes commandline arguments into key-value pairs or a list of arguments from helper_module import mykwargs # returns the euclidian distance of two points in 2D space from helper_module import straightDistance # returns a dictionary of color names and their hex/rgb values from helper_module import load_colors # grab command line arguments _, argDict = mykwargs(sys.argv) # constants WINDOW_WIDTH = int(argDict["width"]) WINDOW_HEIGHT = int(argDict["height"]) HALF_WINDOW_WIDTH = int(WINDOW_WIDTH / 2) HALF_WINDOW_HEIGHT = int(WINDOW_HEIGHT / 2) WINDOW_TITLE = argDict["title"] GAME_FPS = int(argDict["fps"]) # grab json info from colors.json and load into a dictionary colors = load_colors('colors.json') class Camera(): """ Used to create an offset in pixels, that when added to all sprites in the game,