def __init__(self, image_path, y): metadata = { "image": pygame.image.load(find_data_file(image_path)), "x": 0, "y": y, } Component.__init__(self, "background", metadata)
def __init__(self, target_entity_id): metadata = { "target_entity_id": target_entity_id, "x": 0, "y": 0, } Component.__init__(self, "camera", metadata)
def __init__(self, xvel=0, yvel=0, xaccel=0, yaccel=0): metadata = { "xvel": xvel, "yvel": yvel, "xaccel": xaccel, "yaccel": yaccel } Component.__init__(self, "movement", metadata)
def __init__(self, screen, clock, background): metadata = { "screen": screen, "clock": clock, "background": background, "running": True, "paused": False, } Component.__init__(self, "context", metadata)
def __init__(self): metadata = { "has_jumped": False, "currency": 0, "hasCloudSleeves": 0, "hasWings": 0, "hasJetBoots": 0, } Component.__init__(self, "player", metadata)
def __init__(self): metadata = { "has_jumped": False, "jumping": False, "currency": 0, "hasCloudSleeves": 0, "hasWings": 0, "hasJetBoots": 0, "extraFuel": 0, "maxBoosts": 0, "numBoosts": 0, } Component.__init__(self, "player", metadata)
def main(): # Initialize pygame before we do anything else pygame.init() programIcon = pygame.image.load( find_data_file("resources/icarus_icon.png")) pygame.display.set_icon(programIcon) # Initialize global systems in the game world if pygame.mixer.get_init() is not None: WORLD.register_system(AudioSystem()) WORLD.register_system(ButtonSystem()) # Load game metadata and store it in an entity settings = Component.load_from_json("settings") WORLD.gen_entity().attach(settings) # Set up the pygame window flags = pygame.SCALED screen = pygame.display.set_mode((settings["height"], settings["width"]), flags=flags, vsync=1) pygame.display.set_caption(settings["title"]) # Store our dynamic resources that are created at runtime in the game world background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((200, 200, 200)) context = ContextComponent(screen, pygame.time.Clock(), background) game = WORLD.gen_entity() game.attach(context) # Create a new Title screen object title_screen = TitleScene() # Initialize a SceneManager with our title screen manager = SceneManager(title_screen, WORLD) # BIG GAME LOOP while game["context"]["running"]: game["context"]["clock"].tick(60) # Process game wide events, most likely only QUIT events = pygame.event.get() for event in events: if event.type == pygame.QUIT: game["context"]["running"] = False # Update the current scene switch_event = manager.update(events, WORLD) # Render the current scene manager.render(WORLD) pygame.display.flip( ) # Double buffers whatever was on the screen object to the actual display # Finally switch scenes in the scene manager manager.switch(switch_event, WORLD)
def __init__( self, rect, text="", callback=None, is_small=False, is_disabled=False, image=None, ): if is_small: normal_image = _create_image("resources/shop_btn_inactive.png", text, is_disabled, image) hover_image = _create_image("resources/shop_btn_hover.png", text, is_disabled, image) clicked_image = _create_image("resources/shop_btn_press.png", text, is_disabled, image) disabled_image = _create_image("resources/shop_btn_locked.png", text, is_disabled, image) else: normal_image = _create_image("resources/btn_inactive.png", text, is_disabled, image) hover_image = _create_image("resources/btn_hover.png", text, is_disabled, image) clicked_image = _create_image("resources/btn_press.png", text, is_disabled, image) disabled_image = _create_image("resources/btn_locked.png", text, is_disabled, image) metadata = { "normal": normal_image, "hover": hover_image, "clicked": clicked_image, "disabled": disabled_image, "rect": rect, "text": text, "active": False, "isMouseDown": False, "isDisabled": is_disabled, "callback": callback, } Component.__init__(self, "button", metadata)
def __init__(self): Component.__init__(self, "gravity", {})
def __init__(self): Component.__init__(self, "gliding", {})
def __init__(self, angle): metadata = {"angle": angle} Component.__init__(self, "rotation", metadata)
def __init__(self): metadata = {"velocity": 0, "angle": 0, "acceleration": 0} Component.__init__(self, "physics", metadata)
def __init__(self, x, y): metadata = {"x": x, "y": y} Component.__init__(self, "position", metadata)
def __init__(self, sprite): metadata = {"sprite": sprite} Component.__init__(self, "graphic", metadata)
def __init__(self): Component.__init__(self, "moon", {})
def __init__(self, worth): metadata = { "worth": worth, } Component.__init__(self, "collectable", metadata)