Example #1
0
    def go(self, display):

        super().go(display)

        self.speed_change_funtime()

        if self._current_animation == ATTACK_ANIMATION_KEY:
            if self._in_front and self._animation_cycle == self._attack_key_frame * self._animation_spd:
                if self._dmg != 0:
                    self._in_front.apply_damage(self._dmg)
                else:
                    self._projectile_queued = True
                if constants.SHOW_DEBUG:
                    print(self._name + " attacks!")
            elif self._animation_looped:
                self.change_animation(WALK_ANIMATION_KEY, WALK_ANIMATION_SPEED)

        target_rect = self._in_front.get_rect()
        if self._dmg and self._in_front and collisions.rectangles(self.get_rect(), target_rect) or \
           not self._dmg and self._in_front and collisions.rectangles(self.get_range_rect(), target_rect):
            if self._cooldown_left <= 0:
                self.change_animation(ATTACK_ANIMATION_KEY, ATTACK_ANIMATION_SPEED)
                self._cooldown_left = self._cooldown_timer
            elif self._current_animation == WALK_ANIMATION_KEY:
                self.change_animation(STATIC_ANIMATION_KEY, STATIC_ANIMATION_SPEED)
        else:
            if self._current_animation != WALK_ANIMATION_KEY:
                self.change_animation(WALK_ANIMATION_KEY, WALK_ANIMATION_SPEED)
            self.pos()

        if self._cooldown_left > 0:
            self._cooldown_left -= 1
Example #2
0
 def go(self, ctx, room, player):
     self.pos(room)
     self.draw(ctx)
     if self.name == "good":
         for e in room["enemies"]:
             if collisions.rectangles(self, e) and e.hp > 0:
                 sounds.play("squish")
                 self.removeFlag = True
                 e.hp -= self.dmg
     elif self.name == "bad":
         if collisions.rectangles(self, player):
             self.removeFlag = True
             player.hp -= self.dmg
Example #3
0
 def go(self, display):
     self.pos()
     super().go(display)
     if self._in_front and collisions.rectangles(self.get_rect(),
                                                 self._in_front.get_rect()):
         self._in_front.apply_damage(self._dmg)
         self._active = False
Example #4
0
 def canMove(self, room):
     for o in room["obstructions"]:
         if collisions.rectangles(self, o):
             return False
     if self.x < 0 or self.y < 0 or self.x + self.w > constants.gameW or self.y + self.h > constants.gameH:
         return False
     return True
Example #5
0
 def go(self, ctx, player, roomCleared):
     if roomCleared:
         super().go(ctx)
         if collisions.rectangles(self, player):
             self.activate(player)
Example #6
0
def main():

    pygame.mixer.music.play()

    state = constants.AUTHORS
    enemiesCleared = False
    bullets = []
    running = True

    player = Player()
    hud = HUD(player)
    teleporter = Teleporter()

    curFloor, curRoom, curPos, minimap = None, None, None, None

    while running:
        running = listen(running)

        if state == constants.AUTHORS:
            for t in text.authorsList:
                ctx.blit(t[0],t[1])

            if keyboard.controls["keyEnter"]:
                sounds.changeMusic(sounds.overtureGoTime)
            if keyboard.controls["keyEnter"] or pygame.mixer.music.get_pos() > sounds.overtureGoTime*1000:
                state = constants.START
                keyboard.enterLock = True

        if state == constants.START:
            ctx.blit(images.splash,(0,0))
            ctx.blit(text.begin,text.beginRECT)
            if keyboard.controls["keyEnter"]:
                if not keyboard.enterLock:
                    state = constants.GAME
                    curFloor, curRoom, curPos, minimap = generator.nextFloor(None)
            elif keyboard.enterLock:
                keyboard.enterLock = False

        elif state == constants.GAME:

            # Check pause
            if keyboard.controls["keyEscape"]:
                if keyboard.pauseLock == constants.pauseNone:
                    state = constants.PAUSE
                    keyboard.pauseLock = constants.pauseEnter
            else:
                keyboard.pauseLock = constants.pauseNone

            # Reset BG
            ctx.blit(images.backgrounds[curRoom.type],(0,0))

            if enemiesCleared:
                # Test for room changes
                for c in curRoom.doors:
                    key = c.name
                    if collisions.rectangles(player,constants.clearZones[key]):

                        spaceBuffer = 20
                        if key == "w" and keyboard.controls["keyW"]:
                            curPos[0] -= 1
                            player.y = constants.roomB - 10 - constants.playerH - spaceBuffer
                        elif key == "a" and keyboard.controls["keyA"]:
                            curPos[1] -= 1
                            player.x = constants.roomR - 10 - constants.playerW - spaceBuffer
                        elif key == "s" and keyboard.controls["keyS"]:
                            curPos[0] += 1
                            player.y = 10 + spaceBuffer
                        elif key == "d" and keyboard.controls["keyD"]:
                            curPos[1] += 1
                            player.x = constants.roomL + 10 + spaceBuffer
                        if curRoom != curFloor[curPos[0]][curPos[1]]:
                            curRoom = curFloor[curPos[0]][curPos[1]]
                            bullets = []
                            enemiesCleared = enterRoom(curRoom)

                if curRoom.type == "boss":
                    if teleporter.go(ctx, player):
                        curFloor, curRoom, curPos, minimap = generator.nextFloor(minimap)
                        enemiesCleared = enterRoom(curRoom)
            else:
                # Test for door unlock
                enemiesCleared = enemyCheck(curRoom)
                if enemiesCleared:
                    sounds.play("unlock")

            # Update All Entities
            hud.go(ctx, player)
            minimap.go(ctx, curPos)

            for d in curRoom.doors:
                d.go(ctx, enemiesCleared)
            for i in curRoom.items:
                if not i.consumedFlag:
                    i.go(ctx, player, enemiesCleared)
            for b in bullets:
                b.go(ctx, curRoom, player)
                if b.removeFlag:
                    bullets.remove(b)
            for e in curRoom.enemies:
                projectile = e.go(ctx, curRoom, player)
                if projectile is not None:
                    bullets.append(projectile)
                if e.hp <= 0:
                    curRoom.enemies.remove(e)
                generator.trySpawn(e, curRoom, minimap)

            projectile = player.go(ctx, curRoom)
            if projectile is not None:
                bullets.append(projectile)

            if player.hp <= 0:
                state = constants.GAMEOVER
                ctx.blit(text.gameOver, text.gameOverRECT)
                ctx.blit(text.retry, text.retryRECT)

            # Debug
            fps = constants.muli["15"].render(str(round(clock.get_fps(),1)),True,constants.black)
            ctx.blit(fps,(840,575))

        elif state == constants.PAUSE:
            # pause(ctx)

            ctx.blit(images.backgrounds[curRoom.type], (0, 0))
            hud.go(ctx, player)
            minimap.go(ctx, curPos)
            ctx.blit(images.playerPause, (constants.roomL + 50, constants.roomR + 50))
            ctx.blit(text.spud, text.spudRECT)
            ctx.blit(text.pause, text.pauseRECT)

            if keyboard.controls["keyEscape"]:
                if keyboard.pauseLock == constants.pauseNone:
                    state = constants.GAME
                    keyboard.pauseLock = constants.pauseExit
            else:
                keyboard.pauseLock = constants.pauseNone

        elif state == constants.GAMEOVER:

            if keyboard.controls["keyEnter"]:
                state = constants.GAME
                enemiesCleared = False
                bullets = []
                player.__init__()
                hud.__init__(player)
                curFloor, curRoom, curPos, minimap = generator.nextFloor(None)

            continue # Skips updating window

        # Update Window
        pygame.display.update()
        clock.tick(30)

    pygame.quit()