def __init__(self, x, y, blocks, screen, zoneArtwork=1): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param blocks: Integer, the number of times to replicate the wall. :param screen: pygame.Surface, the screen to draw the wall onto. :param zoneArtwork: Integer, choosing the image based on zone. """ self.screen = screen # REFACTOR: Clumsy implementation to change image of the renderer. # - Causes instantiating argument to be needlessly long. # - The code below does not scale well. if zoneArtwork == 1: left = ZONE1_RESOURCES["platforms"]["platform_1"][0] mid = ZONE1_RESOURCES["platforms"]["platform_2"][0] right = ZONE1_RESOURCES["platforms"]["platform_3"][0] if zoneArtwork == 2: left = ZONE2_RESOURCES["platforms"]["platform_1"][0] mid = ZONE2_RESOURCES["platforms"]["platform_2"][0] right = ZONE2_RESOURCES["platforms"]["platform_3"][0] image = buildParts(blocks, "h", [left, mid, right]) self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0)
def __init__(self, screen): super().__init__(screen) self.levelNum = 3 self.players = self.addPlayers() self.bosses = self.addBosses() self.bosses[0].target(self.players) self.walls = self.addWalls() self.sPlatforms = self.addSPlatforms() self.dPlatforms = self.addDPlatforms() self.mPlatforms = self.addMPlatforms() self.switches = self.addSwitches() self.doors = self.addDoors() self.spikes = self.addSpikes() self.decorations = self.addDecorations() self.elapsed = 0 self.origin = pg.time.get_ticks() image = ZONE1_RESOURCES["levels"]["coop_jail_03"] self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.JAIL_COOP_3, 10, 410, "caption") self.messageCutScene("transition", "pig_cutscene") self.messageMenu("transition", "blank_menu")
def __init__(self, x, y, switchNum, screen, zoneArtwork=1): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param switchNum: Integer, identifying the number of the button. :param screen: pygame.Surface, the screen to draw the wall onto. :param zoneArtwork: Integer, choosing the image based on zone. """ self.screen = screen self.num = switchNum self.isOn = True # REFACTOR: Clumsy implementation to change image of the renderer # - Causes instantiating argument to be needlessly long. # - The code below does not scale well. if zoneArtwork == 1: button = ZONE1_RESOURCES["buttons"] if zoneArtwork == 2: button = ZONE2_RESOURCES["buttons"] self.render = RenderComponent(self, enableRepeat=False) self.render.add("on", [button["switch"][0]]) self.render.add("off", button["switch"], 500) self.render.state = "on" self.rect = pg.Rect(x, y, 0, 0) self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("click", SFX_RESOURCES["scene_switch"])
def __init__(self, x, y, num, screen, zoneArtwork=1): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param num: Integer, identifying the number of the button. :param screen: pygame.Surface, the screen to draw the wall onto. :param zoneArtwork: Integer, choosing the image based on zone. """ self.screen = screen self.num = num self.switchesWaiting = [] self.isClosed = True # REFACTOR: Clumsy implementation to change image of the renderer. # - Causes instantiating argument to be needlessly long. # - The code below does not scale well. if zoneArtwork == 1: door = ZONE1_RESOURCES["doors"] if zoneArtwork == 2: door = ZONE2_RESOURCES["doors"] self.render = RenderComponent(self, enableRepeat=False) self.render.add("open", door["open"]) self.render.add("closed", door["close"]) self.render.state = "closed" self.rect = pg.Rect(x, y, 0, 0) self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("open", SFX_RESOURCES["scene_door"])
def __init__(self, screen): super().__init__(screen) self.fontSize = 50 self.fontColour = "orange" self.x = 270 self.y = 225 self.pauseText = TextLabel("Pause", self.fontSize, self.fontColour, self.x, self.y, self.screen, isItalic=True) image = MENU_RESOURCES["screens"]["fade"][0] self.render = RenderComponent(self) self.render.add("background", image) self.render.state = "background" self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("pause", SFX_RESOURCES["menu_pause"]) self.audio.state = "pause" # Need to draw once only otherwise it overrides what is already drawn # by the Scene Engine self.render.update() self.pauseText.update() self.pauseText.draw() self.render.draw()
def __init__(self, screen): super().__init__(screen) fontSize = 22 fontColour = "white" x, y = 230, 155 dx, dy = 0, 50 self.backgroundSetting = _SettingsLabel("Orientación: ", ["Vertical", "Horizontal"], fontSize, fontColour, x, y, 130, screen) self.fullscreenSetting = _SettingsLabel("Full Screen: ", ["Desactivar", "Activar"], fontSize, fontColour, x, y + dy, 130, screen) self.arrow = _Arrow(x - 40, y - 10, dx, dy, 2, screen) self.escapeImage = ImageLabel(MENU_RESOURCES["assets"]["esc"], 25, 440, screen) self.escapeText = TextLabel("Esc para volver", 14, fontColour, 50, 445, screen) self.effect = FadeEffect(self.screen) self.effect.timeStartDarken = float('inf') self.effect.timeEndDarken = float('inf') self.dt = 2 background = MENU_RESOURCES["screens"]["options"][0] self.render = RenderComponent(self) self.render.add("background", background) self.render.state = "background" self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("exit", SFX_RESOURCES["menu_exit"])
def __init__(self, screen): super().__init__(screen) self.totalOptions = 4 self.fontSize = 22 self.fontColour = "white" self.x = 250 self.y = 155 self.dx = 0 self.dy = 38 self.option1 = TextLabel("1 Jugador", self.fontSize, self.fontColour, self.x, self.y + 1 * self.dy, self.screen) self.option2 = TextLabel("2 Jugadores", self.fontSize, self.fontColour, self.x, self.y + 2 * self.dy, self.screen) self.option3 = TextLabel("Opciones", self.fontSize, self.fontColour, self.x, self.y + 3 * self.dy, self.screen) self.option4 = TextLabel("Salir", self.fontSize, self.fontColour, self.x, self.y + 4 * self.dy, self.screen) self.title = ImageLabel(MENU_RESOURCES["assets"]["title"][0], 60, 55, self.screen) self.arrow = _Arrow(self.x - 40, self.y + 28, self.dx, self.dy, self.totalOptions, self.screen) background = MENU_RESOURCES["screens"]["main"][0] self.render = RenderComponent(self) self.render.add("background", background) self.render.state = "background" self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("enter", SFX_RESOURCES["menu_enter"])
def __init__(self, screen): super().__init__(screen) self.rect = pg.Rect(0, 0, 0, 0) office = CUTSCENE_RESOURCES["office"] self.origin = pg.time.get_ticks() # milliseconds self.elapsed = 0 # milliseconds self._isSentMessage = False self.render = RenderComponent(self) self.render.add("office_dog", office["dog"], 1500) self.render.add("office_cat", office["cat"], 1500) self.audio = AudioComponent(self, isAutoPlay=False) # self.audio.add("meow", SFX_RESOURCES["meow_1"]) self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.OFFICE_1, 240, 50, "left") self.dialogue.add(dialogue.OFFICE_2, 370, 100) self.dialogue.add(dialogue.OFFICE_3, 240, 50, "left") self.dialogue.add(dialogue.OFFICE_4, 370, 100) speed = 1 ts = [0, 4000, 8000, 12000, 16000] self.timings = [speed * t for t in ts]
def __init__(self, screen): super().__init__(screen) self.rect = pg.Rect(0, 0, 0, 0) telephone = CUTSCENE_RESOURCES["telephone"] self.origin = pg.time.get_ticks() # milliseconds self.elapsed = 0 # milliseconds self._isComplete = False self._isReversed = False self.render = RenderComponent(self, enableRepeat=False) self.render.add("telephone_none", telephone["none"]) self.render.add("telephone_pick", telephone["pick"], 1100) self.render.add("telephone_hold", telephone["hold"]) self.render.add("telephone_put", telephone["put"], 1100) self.audio = AudioComponent(self) self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.TELEPHONE_1, 350, 150, "left") self.dialogue.add(dialogue.TELEPHONE_2, 350, 150, "left") speed = 1 ts = [2000, 2800, 3300, 6300, 10300, 11300, 12100, 14000] self.timings = [speed * t for t in ts]
def __init__(self, x, y, image, screen): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param image: pygame.Surface, the image of the wall. :param screen: pygame.Surface, the screen to draw the wall onto. """ self.screen = screen self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0)
def __init__(self, x, y, screen): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param screen: pygame.Surface, the screen to draw the wall onto. """ self.screen = screen assets = ZONE2_RESOURCES["traps"]["spear"] self.render = RenderComponent(self) self.render.add("idle", assets) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0)
class IntroMenu(BaseMenu): """ The intro screen of the game after the splash screen. """ def __init__(self, screen): super().__init__(screen) self.effect = FadeEffect(screen) self.effect.timeEndDarken += 1.0 ICONS = ICON_RESOURCES["assets"] self.render = RenderComponent(self) self.render.add("red", ICONS["red"][0]) self.render.add("black", ICONS["black"][0]) self.render.state = "black" w, h = ICONS["red"][0].get_size() offsetX = (settings.WIDTH - w) / 2 offsetY = (settings.HEIGHT - h) / 2 self.rect.center = (offsetX, offsetY) self.audio = AudioComponent(self, isRepeat=True, isAutoPlay=True) self.audio.add("intro_1", SFX_RESOURCES["menu_intro_1"]) self.audio.add("intro_2", SFX_RESOURCES["menu_intro_2"]) self.audio.state = "intro_1" def __str__(self): return "intro_menu" def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_RETURN: self._sendMessage() def update(self): self.audio.update() self.render.update() if not self.effect.isComplete: self.effect.update() if self.effect.time > self.effect.timeStartDarken + 2.0: self.render.state = "red" self.audio.state = "intro_2" else: self._sendMessage() def draw(self, camera=None): self.render.draw(camera) self.effect.draw() def _sendMessage(self): """ Sends a message to start the next menu. """ self.messageMenu("transition", "main_menu") pg.mixer.stop()
def __init__(self, screen): super().__init__(screen) self.effect = FadeEffect(screen) background = MENU_RESOURCES["screens"]["splash"][0] background = addBackground(background) self.render = RenderComponent(self) self.render.add("background", background) self.render.state = "background" self.audio = AudioComponent(self) self.audio.add("door_knock", SFX_RESOURCES["splash_door_knock"]) self.audio.add("door_open", SFX_RESOURCES["splash_door_open"]) self.audio.add("door_close", SFX_RESOURCES["splash_door_close"]) self.audio.add("meow", SFX_RESOURCES["splash_meow"]) self.audio.link("door_knock", "door_open", delay=1000) self.audio.link("door_open", "meow") self.audio.link("meow", "door_close") self.audio.state = "door_knock"
def __init__(self, screen): super().__init__(screen) self.fontSize = 18 self.fontColour = "white" self.x = 150 self.y = 320 self.enterText = TextLabel("Enter para salir", self.fontSize, self.fontColour, self.x, self.y, self.screen) image = MENU_RESOURCES["screens"]["lose"][0] self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("meow", SFX_RESOURCES["menu_lose"]) self.audio.state = "meow"
def __init__(self, screen): super().__init__(screen) self.effect = FadeEffect(screen) self.effect.timeStartLighten = 0.0 self.effect.timeEndLighten = 1.0 self.effect.timeStartDarken = 1.0 self.effect.timeEndDarken = 1.5 image = pg.Surface((settings.WIDTH, settings.HEIGHT)) image.fill(settings.COLOURS["dark_red"]) image = image.convert() self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.audio = AudioComponent(self, isAutoPlay=True, isRepeat=False) self.audio.add("death", SFX_RESOURCES["menu_death"]) self.audio.state = "death"
def __init__(self, screen): super().__init__(screen) self.players = self.addPlayers() self.walls = self.addWalls() self.sPlatforms = self.addSPlatforms() self.switches = self.addSwitches() self.doors = self.addDoors() self.elapsed = 0 self.origin = pg.time.get_ticks() image = ZONE1_RESOURCES["levels"]["solo_jail_01"][0] self.render = RenderComponent(self) self.render.add("background", image) self.render.state = "background" self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.JAIL_SOLO_1, 10, 410, "caption")
def __init__(self, screen): """ :param screen: pygame.Surface, representing the screen. """ super().__init__() self.screen = screen self.rect = pg.Rect(0, 0, 0, 0) self.num = 0 self.lives = 5 self.isOnGround = False self.jumpSpeed = -12 self.moveSpeed = 9 self.physics = PhysicsComponent(self) self.render = RenderComponent(self, enableOrientation=True) self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("jump", SFX_RESOURCES["cat_jump"]) self.keybinds = None
def __init__(self, screen): super().__init__(screen) self.effect = FadeEffect(screen) self.effect.timeEndDarken += 1.0 ICONS = ICON_RESOURCES["assets"] self.render = RenderComponent(self) self.render.add("red", ICONS["red"][0]) self.render.add("black", ICONS["black"][0]) self.render.state = "black" w, h = ICONS["red"][0].get_size() offsetX = (settings.WIDTH - w) / 2 offsetY = (settings.HEIGHT - h) / 2 self.rect.center = (offsetX, offsetY) self.audio = AudioComponent(self, isRepeat=True, isAutoPlay=True) self.audio.add("intro_1", SFX_RESOURCES["menu_intro_1"]) self.audio.add("intro_2", SFX_RESOURCES["menu_intro_2"]) self.audio.state = "intro_1"
def __init__(self, screen): super().__init__(screen) self.transparentValue = 255 self.isComplete = False background = pg.Surface((settings.WIDTH, settings.HEIGHT)) background.fill(settings.COLOURS["black"]) background = background.convert() self.render = RenderComponent(self) self.render.add("background", background) self.render.state = "background" # Units are in seconds (use floats to reduce rounding errors) self.origin = pg.time.get_ticks() / 1000 self.time = 0.0 self.timeStartLighten = 1.0 self.timeEndLighten = 3.0 self.timeStartDarken = 5.0 self.timeEndDarken = 8.0
class Switch(GameObject): """ A switch entity that the player can turn on and off. """ def __init__(self, x, y, switchNum, screen, zoneArtwork=1): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param switchNum: Integer, identifying the number of the button. :param screen: pygame.Surface, the screen to draw the wall onto. :param zoneArtwork: Integer, choosing the image based on zone. """ self.screen = screen self.num = switchNum self.isOn = True # REFACTOR: Clumsy implementation to change image of the renderer # - Causes instantiating argument to be needlessly long. # - The code below does not scale well. if zoneArtwork == 1: button = ZONE1_RESOURCES["buttons"] if zoneArtwork == 2: button = ZONE2_RESOURCES["buttons"] self.render = RenderComponent(self, enableRepeat=False) self.render.add("on", [button["switch"][0]]) self.render.add("off", button["switch"], 500) self.render.state = "on" self.rect = pg.Rect(x, y, 0, 0) self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("click", SFX_RESOURCES["scene_switch"]) def __str__(self): return "switch " + str(self.num) def update(self): self.render.update() self.audio.update() def draw(self, camera=None): self.render.draw(camera) def turnOff(self): """ Changes the state of the button to off and sends out an event. """ self.isOn = False self.render.state = "off" self.audio.state = "click" self.messageScene("switch", (self.num, self.isOn))
def __init__(self, screen): super().__init__(screen) self.players = self.addPlayers() self.walls = self.addWalls() self.dPlatforms = self.addDPlatforms() self.switches = self.addSwitches() self.doors = self.addDoors() self.decorations = self.addDecorations() self.elapsed = 0 self.origin = pg.time.get_ticks() image = ZONE1_RESOURCES["levels"]["coop_jail_01"] self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.JAIL_COOP_1A, 10, 410, "caption") self.dialogue.add(dialogue.JAIL_COOP_1B, 10, 410, "caption")
class Spike(GameObject): """ A spike entity that kills the player. """ def __init__(self, x, y, blocks, orientation, image, screen): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param image: pygame.Surface, the image of the wall. :param screen: pygame.Surface, the screen to draw the wall onto. """ self.screen = screen image = replicate(blocks, orientation, image) self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0) def update(self): self.render.update() def draw(self, camera=None): self.render.draw(camera)
class Decoration(GameObject): """ An entity that does nothing other than act as a background decoration. """ def __init__(self, x, y, image, screen): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param image: pygame.Surface, the image of the wall. :param screen: pygame.Surface, the screen to draw the wall onto. """ self.screen = screen self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0) def __str__(self): return "decoration" def update(self): self.render.update() def draw(self, camera=None): self.render.draw(camera)
def __init__(self, screen): super().__init__(screen) self.screen = screen self.fontSize = 18 self.fontColour = "white" self.x = 150 self.y = 320 self.enterText = TextLabel("Enter para salir", self.fontSize, self.fontColour, self.x, self.y, self.screen) self.Text2 = TextLabel("NIVEL 3 COMING SOON...", 32, self.fontColour, 100, 100, self.screen) image = MENU_RESOURCES["screens"]["fade"][0] self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.audio = AudioComponent(self, isAutoPlay=False, isRepeat=True) self.audio.add("win", SFX_RESOURCES["scene_win"]) self.audio.state = "win"
def __init__(self, screen): super().__init__(screen) self.rect = pg.Rect(0, 0, 0, 0) pig = CUTSCENE_RESOURCES["pig"]["appear"] pig = [addBackground(p) for p in pig] self.origin = pg.time.get_ticks() # milliseconds self.elapsed = 0 # milliseconds self._isComplete = False self.render = RenderComponent(self, enableRepeat=False) self.render.add("appear", pig, 3000) self.audio = AudioComponent(self) self.audio.add("machine", SFX_RESOURCES["pig_machine"]) self.audio.state = "machine" self.dialogue = Dialogue(self.screen) speed = 1 ts = [3000] self.timings = [speed * t for t in ts]
def __init__(self, x, y, blocks, orientation, images, screen): """ :param x: Integer, the x-position of the wall. :param y: Integer, the y-position of the wall. :param blocks: Integer, the number of times to replicate the wall. :param orientation: String, either 'v' or 'h' for vertical or horizontal. :param images: Tuple, containing either a single or three pygame.Surfaces to build the platform. :param screen: pygame.Surface, the screen to draw the wall onto. """ self.screen = screen if len(images) == 3: image = buildParts(blocks, orientation, images) elif len(images) == 1: image = replicate(blocks, orientation, images[0]) else: raise ValueError("A wall must have one or three images only!") self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(x, y, 0, 0)
def __init__(self, x, y, dx, dy, totalOptions, screen): """ :param x: Integer, the x-position of the arrow. :param y: Integer, the y-position of the arrow. :param dx: Integer, the change in x-position per movement. :param dy: Integer, the change in y-position per moevement. :param totalOptions: Integer, the total number of options. :param screen: pygame.Surface, representing the screen. """ self.rect = pg.Rect(x, y, 0, 0) self.dx = dx self.dy = dy self.totalOptions = totalOptions self.screen = screen self.index = 0 self.render = RenderComponent(self) self.render.add("spin", MENU_RESOURCES["assets"]["coin"], 350) self.render.state = "spin" self.audio = AudioComponent(self, isAutoPlay=False) self.audio.add("move", SFX_RESOURCES["menu_arrow"]) self.audio.state = "move"
def __init__(self, A, B, dx, dy, screen, image): """ :param A: 2-Tuple, containing coordinates of a point A. :param B: 2-Tuple, containing coordinates of a point B. :param dx: Number, pixels moved in the x-axis every physics tick. :param dy: Number, pixels moved in the y-axis every physics tick. :param screen: pygame.Surface, the screen to draw the wall onto. :param image: pygame.Surface, the image of the platform. """ self.screen = screen self.A = A self.B = B self.dx = dx self.dy = dy self.isDirectionX = True self.isDirectionY = True self.physics = PhysicsComponent(self) self.physics.isGravity = False self.render = RenderComponent(self) self.render.add("idle", image) self.render.state = "idle" self.rect = pg.Rect(A[0], A[1], 0, 0)
def __init__(self, screen): super().__init__(screen) self.players = self.addPlayers() self.walls = self.addWalls() self.mPlatforms = self.addMPlatforms() self.switches = self.addSwitches() self.doors = self.addDoors() self.spikes = self.addSpikes() self.spears = self.addSpears() self.dPlatforms = self.addDPlatforms() self.decorations = self.addDecorations() self.elapsed = 0 self.origin = pg.time.get_ticks() image = ZONE2_RESOURCES["levels"]["solo_forest_01"] self.render = RenderComponent(self) self.render.add("background", image) self.render.state = "background" self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.FOREST_SOLO_2, 10, 410, "caption")
def __init__(self, screen): super().__init__(screen) self.rect = pg.Rect(0, 0, 0, 0) jail = CUTSCENE_RESOURCES["jail"] self.origin = pg.time.get_ticks() # milliseconds self.elapsed = 0 # milliseconds self._isComplete = False self.render = RenderComponent(self, enableRepeat=False) self.render.add("fence_show", jail["fence_show"], 2000) self.render.add("fence_static", jail["fence_static"]) self.render.add("fence_hide", jail["fence_hide"], 2000) self.render.add("cat_static", jail["cat_static"]) self.render.add("cat_close", jail["cat_close"], 3500) self.audio = AudioComponent(self) self.dialogue = Dialogue(self.screen) self.dialogue.add(dialogue.JAIL_1, 19, 25, "caption") speed = 1 ts = [2000, 4000, 6000, 9500, 11500] self.timings = [speed * t for t in ts]