Ejemplo n.º 1
0
 def defineVariables(self, pos: Vector, color, type, image, length=300):
     self.pos = pos
     self.vel = Vector()
     self.radius = 30
     self.length = length
     self.normalLine = Vector(0, -self.length)
     self.lineLeftGen = Vector(-self.radius * 2, -self.length)
     self.lineRightGen = Vector(+self.radius * 2, -self.length)
     self.line = Line
     self.direction = Vector()
     self.looking = False
     self.rotation = 5
     self.losColour = 'rgb(255,255,0)'
     self.found = False
     self.type = type
     self.soundRange = 100
     self.stealthRange = 150
     self.color = color
     self.speed = 0.45
     self.health = 100
     self.ability = Cannon()
     self.enemyIMG = Enemy2IMG(self.pos, image, 530, 172, 9, 4, [0, 2], 150,
                               150, 0)
     self.stopDistance = 0
     self.updateLOS()
Ejemplo n.º 2
0
    def __init__(self, vel, pos, image, rotation, size=0):
        self.vel: Vector = vel
        self.pos: Vector = pos
        self.speed = 5
        self.maxSpeed = 6
        self.health = 100
        self.activeAbility = Cannon()
        self.image = image
        self.rotation = rotation
        self.directions = ["UP", "LEFT", "DOWN", "RIGHT"]
        self.direction = ""
        self.stamina = 0
        self.staminaColor = "green"
        self.rest = False
        self.staminaReg = 0.5
        self.running = False
        self.damageStack = 0
        self.speedStack = 0
        self.staminaStack = 0

        #GodMode for testing
        self.god = False

        if size == 0:
            self.size = self.dim
        else:
            self.size = size

        self.radius = max(size[0] / 2, size[1] / 2)
Ejemplo n.º 3
0
 def nextMap(self):
     global currentMap,offset,projectiles,lasers,teleporter,walls,enemies,pickups,inventory,character,boss,noHearts
     currentMap += 1
     if map.__len__() > currentMap:
         map[currentMap].start(frame,CANVAS_WIDTH,CANVAS_HEIGHT)
         offset = -map[currentMap].startPos + (Vector(CANVAS_WIDTH, CANVAS_HEIGHT) / 2)
         projectiles = []
         lasers = []
         if currentMap != 2:
             teleporter = map[currentMap].teleporter
         walls = map[currentMap].walls
         enemies = map[currentMap].enemies
         pickups = map[currentMap].pickups
         if currentMap == 1:
             inventory = Inventory(CANVAS_WIDTH, CANVAS_HEIGHT,character)
             character.healthInit(HealthIMG, heart1)
             character.healthStart(character.healthOB, 3)
             Cannon().baseDamage = Cannon().resetDamage
             Laser().baseDamage = Laser().resetDamage
             Shotgun().baseDamage = Shotgun().resetDamage
             character.staminaReg = 0.5
             character.stamina = 0
             character.staminaStack=character.speedStack=character.damageStack= 0
         if currentMap == 2:
             boss = map[2].Boss
         character.pos = map[currentMap].startPos
Ejemplo n.º 4
0
 def __init__(self,pos,vel,baseimage,image,fadedBase,death):
     self.trident = False
     self.pos = pos
     self.vel = vel
     self.detectedRadius = 500
     self.followRadius = 800
     self.speed = 60
     self.direction = Vector()
     self.ability = Cannon()
     self.incrementalTimer = 0
     self.incrementalTimer2 = 0
     self.incrementalTimer3 = 0
     self.incrementalTimer4 = 0
     self.inBoundary = False
     self.positions = []
     self.enemies = []
     self.health = 1000
     self.radius = 100
     self.spawn = False
     self.boss = LynelSprite(self.pos, baseimage, 175, 300, 3, 6, [0, 2],image, 608, 130, 8, 2, [1, 1], fadedBase, 175, 300, 3, 6, [0, 2],death, 270, 50, 6, 1, [0, 0],0)
     self.start(self.pos, baseimage, 175, 300, 3, 6, [0.2],
                image, 608, 130, 8  , 2, [1,1], fadedBase, 175, 300, 3, 6, [0, 2],death, 270, 50, 6, 1, [0, 0],0)
     self.moving = False
     self.generator = Vector(0,-200)
     self.draw = False
     self.fireOrb = simplegui._load_local_image('Resources/images/fireOrb.png')
     self.fire = simplegui._load_local_image('Resources/images/fireBall.png')
     self.fireEnabled = False
     self.death = False
     self.damageResistence = 3
Ejemplo n.º 5
0
 def __init__(self,pos:Vector,color,type,image,FrameIndex,rotation=0):
     self.defineVariables(pos,color,type,image)
     self.soundRange = 100
     self.stealthRange = 150
     self.speed = 1.6
     self.health = 70
     self.ability = Cannon()
     self.enemyIMG = Enemy2IMG(self.pos, image,330,232,9,4,FrameIndex,100,100,0)
     self.entity = "Bat"
     self.lineLeftGen.rotate(rotation)
     self.normalLine.rotate(rotation)
     self.lineRightGen.rotate(rotation)
     self.updateLOS()
Ejemplo n.º 6
0
    def __init__(self,
                 pos: Vector,
                 color,
                 type,
                 FireEnemy,
                 FrameIndex,
                 rotation=0):
        self.defineVariables(pos, color, type, FireEnemy)

        #Specific to this enemy
        self.speed = 0.7
        self.health = 180
        self.ability = Cannon()
        self.enemyIMG = Enemy2IMG(self.pos, FireEnemy, 530, 172, 9, 4,
                                  FrameIndex, 150, 150, 0)
        self.stopDistance = 200
        self.lineLeftGen.rotate(rotation)
        self.normalLine.rotate(rotation)
        self.lineRightGen.rotate(rotation)
        self.updateLOS()
        self.entity = "fireEnemy"
Ejemplo n.º 7
0
 def __init__(self,
              pos: Vector,
              color,
              type,
              image,
              FrameIndex,
              rotation=0):
     self.defineVariables(pos, color, type, image)
     self.soundRange = 100
     self.stealthRange = 150
     self.speed = 2
     self.health = 250
     self.ability = Cannon()
     self.enemyIMG = Enemy2IMG(self.pos, image, 170, 20, 5, 1, FrameIndex,
                               100, 100, 0)
     self.lineLeftGen.rotate(rotation)
     self.normalLine.rotate(rotation)
     self.lineRightGen.rotate(rotation)
     self.updateLOS()
     self.found = True
     self.entity = "flameBat"
Ejemplo n.º 8
0
class Character:
    def __init__(self, vel, pos, image, rotation, size=0):
        self.vel: Vector = vel
        self.pos: Vector = pos
        self.speed = 5
        self.maxSpeed = 6
        self.health = 100
        self.activeAbility = Cannon()
        self.image = image
        self.rotation = rotation
        self.directions = ["UP", "LEFT", "DOWN", "RIGHT"]
        self.direction = ""
        self.stamina = 0
        self.staminaColor = "green"
        self.rest = False
        self.staminaReg = 0.5
        self.running = False
        self.damageStack = 0
        self.speedStack = 0
        self.staminaStack = 0

        #GodMode for testing
        self.god = False

        if size == 0:
            self.size = self.dim
        else:
            self.size = size

        self.radius = max(size[0] / 2, size[1] / 2)

    def healthStart(self, healthList, noHearts):
        self.noHearts = noHearts
        self.hearts: list = healthList
        self.heartList = []
        for i in range(0, self.hearts.__len__() + 1):
            self.heart = 1
            self.heartList.append(self.heart)
        self.lastHeart = noHearts
        self.last = noHearts

    def healthInit(self, HealthIMG, heart1):
        noHearts = 3
        self.previous = 50
        self.healthListInit = []
        for i in range(0, noHearts):
            self.healthListInit.append(
                HealthIMG(Vector(self.previous, 50), heart1))
            self.previous += 50

        self.healthOB = []
        for i in range(0, noHearts):
            self.healthOB.append(self.healthListInit[i])

    def damageTaken(self):
        if self.last > 0:
            if self.heartList[self.last] == 1:
                self.heartList[self.last] = 2
                self.hearts[self.last - 1].frameIndex = [1, 0]
            elif self.heartList[self.last] == 2:
                self.heartList[self.last] = 3
                self.hearts[self.last - 1].frameIndex = [2, 0]
            elif self.heartList[self.last] == 3:
                self.heartList[self.last] = 4
                self.hearts[self.last - 1].frameIndex = [3, 0]
            elif self.heartList[self.last] == 4:
                self.hearts[self.last - 1].frameIndex = [4, 0]
                self.last -= 1

    def fire(self, pos: Vector, projectiles: list, lasers: list):
        self.activeAbility.fire(pos, projectiles, lasers, self.pos, "player")

    def pickup(self, pickup, inventory):
        if pickup.type == "Ability":
            inventory.enableAbility(pickup.value)

    def draw(self, canvas, offset):
        # canvas.draw_image(self.image, self.center, self.dim, (self.pos+offset).getP(), self.size, self.rotation)
        self.image.draw(canvas, offset, self.pos)

    def update(self, keyboard, zoom, mousePos, offset, frame, timer):
        self.image.updatePlayer(self)
        angle = math.atan2((self.pos + offset).getP()[0] - mousePos[0],
                           (self.pos + offset).getP()[1] - mousePos[1])
        for i in range(len(self.directions)):
            if ((i - 0.5) / len(self.directions) * 2 * math.pi) <= angle <= (
                (i + 0.5) / len(self.directions) * 2 * math.pi):
                self.direction = self.directions[i]
                #  Split for clarity
            elif ((i - 0.5 - len(self.directions)) / len(self.directions) * 2 *
                  math.pi) <= angle <= ((i + 0.5 - len(self.directions)) /
                                        len(self.directions) * 2 * math.pi):
                self.direction = self.directions[i]

        if self.last == 0 and not self.god:
            frame.stop()
            timer.stop()
            import runpy
            file_globals = runpy.run_path("Classes/PyGamesGameOver.py")

        if keyboard.shift:
            if self.rest and self.stamina > 0:
                self.stamina -= self.staminaReg
                self.staminaColor = "red"
                self.running = False
            elif self.rest and self.stamina <= 0:
                self.rest = False

            speed = self.speed
            if self.stamina <= 144 and not self.rest:
                speed = self.speed * 2.5
                self.running = True
                self.stamina += 0.5
                self.staminaColor = "green"
            elif not self.rest:
                self.rest = True
                speed = self.speed
                self.running = False
        else:
            self.running = False
            if self.stamina > 0:
                self.stamina -= self.staminaReg
            else:
                self.staminaColor = "green"
                self.rest = False

            speed = self.speed
        if keyboard.right:
            self.vel.add(Vector(speed, 0))
        if keyboard.left:
            self.vel.add(Vector(-speed, 0))
        if keyboard.up:
            self.vel.add(Vector(0, -speed))
        if keyboard.down:
            self.vel.add(Vector(0, speed))
        self.pos.add(self.vel / zoom)
        self.vel = self.vel.getNormalized() * min(self.vel.length(),
                                                  self.maxSpeed) * 0.935
Ejemplo n.º 9
0
class EnemySuper:
    def defineVariables(self, pos: Vector, color, type, image, length=300):
        self.pos = pos
        self.vel = Vector()
        self.radius = 30
        self.length = length
        self.normalLine = Vector(0, -self.length)
        self.lineLeftGen = Vector(-self.radius * 2, -self.length)
        self.lineRightGen = Vector(+self.radius * 2, -self.length)
        self.line = Line
        self.direction = Vector()
        self.looking = False
        self.rotation = 5
        self.losColour = 'rgb(255,255,0)'
        self.found = False
        self.type = type
        self.soundRange = 100
        self.stealthRange = 150
        self.color = color
        self.speed = 0.45
        self.health = 100
        self.ability = Cannon()
        self.enemyIMG = Enemy2IMG(self.pos, image, 530, 172, 9, 4, [0, 2], 150,
                                  150, 0)
        self.stopDistance = 0
        self.updateLOS()

    def spriteUpdate(self, character, enemy):
        self.enemyIMG.updateDirection(character, enemy)
        self.enemyIMG.update(enemy)

    def fire(self, pos: Vector, projectiles: list, lasers: list):
        self.ability.fire(pos, projectiles, lasers, self.pos, "enemy")

    def updateLOS(self):
        self.normalGen = Vector((self.pos.x + self.normalLine.x),
                                (self.pos.y + self.normalLine.y))
        self.normalBoundary = Line(self.pos, self.normalGen, "blue")

        self.leftgen = Vector((self.pos.x + self.lineLeftGen.x),
                              (self.pos.y + self.lineLeftGen.y))
        self.leftBoundary = Line(self.pos, self.leftgen, "white")

        self.rightgen = Vector((self.pos.x + self.lineRightGen.x),
                               (self.pos.y + self.lineRightGen.y))
        self.rightBoundary = Line(self.pos, self.rightgen, "white")

    def update(self, zoom, player):
        self.updateLOS()
        self.inLOS(player)
        self.updateSoundDistance(player)

        self.vel.multiply(0.90)
        if self.found:
            self.vel.add(self.direction.getNormalized() * self.speed)
        self.pos.add(self.vel / zoom)

    def drawLos(self, canvas, offset):
        pass
        canvas.draw_polygon([
            ((self.leftBoundary.pA.x + offset.x),
             (self.leftBoundary.pA.y + offset.y)),
            ((self.leftBoundary.pB.x + offset.x),
             (self.leftBoundary.pB.y + offset.y)),
            ((self.rightBoundary.pB.x + offset.x),
             (self.rightBoundary.pB.y + offset.y)),
        ], 0, "white", self.losColour)

    def draw(self, canvas, offset):
        if not self.found:
            self.drawLos(canvas, offset)
        self.enemyIMG.draw(canvas, offset)

    def stealthDistance(self, player):
        if self.stealthRange >= (self.pos - player.pos).length() and (
                self.pos - player.pos).length() > self.soundRange:
            return True
        return False

    def alertDistance(self, enemy2):
        distanceVector = self.pos.copy().subtract(enemy2.pos)
        if distanceVector.length() <= (self.radius + enemy2.radius):
            enemy2.vel.x = -enemy2.vel.x
        elif distanceVector.length() < 350 and (enemy2.found or self.found):
            enemy2.found = True
            self.found = True

    def inLOS(self, player):
        leftVision: Vector = self.pos - self.leftgen
        rightVision: Vector = self.pos - self.rightgen
        playerVector = self.pos - player.pos

        # Debuging
        # losAngle = (self.leftgen - self.rightgen).angleToX()
        # canvas.draw_line((self.pos+offset).getP(), (self.pos+offset+Vector(1,0).rotateRad(playerVector.angleToX())).getP(), 9, "black")

        if self.length >= playerVector.length():
            if rightVision.angleToX() >= playerVector.angleToX(
            ) >= leftVision.angleToX():
                self.found = True
                self.normalBoundary.color = 'rgb(255,0,0)'
            elif (rightVision.angleToX() < math.pi / 2
                  and leftVision.angleToX() > 3 * math.pi / 2):
                if(rightVision.angleToX()+2*math.pi >= playerVector.angleToX() >= leftVision.angleToX() \
                    or rightVision.angleToX() >= playerVector.angleToX() >= leftVision.angleToX()-2*math.pi):
                    self.found = True
                    self.normalBoundary.color = 'rgb(255,0,0)'
        elif self.length * 2 < playerVector.length(
        ) and self.entity != "flameBat":
            self.found = False

    def updateSoundDistance(self, player):
        if self.soundRange >= (self.pos - player.pos).length():
            self.found = True

    def stop(self, player):
        if (self.radius + player.radius) + self.stopDistance >= (
                self.pos - player.pos).length():
            self.direction = Vector(0, 0)

    def follow(self, player):
        self.losColour = 'rgb(255,0,0)'
        playertest: Vector = player.pos.copy().subtract(self.pos)
        self.direction = playertest

    def search(self, player):
        playerVector = self.pos - player.pos
        vectorOfLeft = self.leftBoundary.pA - self.leftBoundary.pB
        Vectorleft = self.pos.copy().subtract(vectorOfLeft)
        Left = self.pos.copy().subtract(Vectorleft)

        angleLess = Left.getNormal().angle(playerVector.getNormal())
        vectorToNormal = (self.normalBoundary.pA - self.normalBoundary.pB)
        VectorNormal = self.pos.copy().subtract(vectorToNormal)
        normal = self.pos.copy().subtract(VectorNormal)

        tester = playerVector.getNormal().angle(normal.getNormal())

        playerToLOSAngle = (self.pos - player.pos
                            ).angle(self.pos - self.normalGen) * 180 / math.pi
        if playerToLOSAngle < self.rotation * 3:
            rotation = playerToLOSAngle / 7
        else:
            rotation = self.rotation

        if self.found:
            if round(angleLess, 2) > round(tester, 2):
                self.lineLeftGen.rotate(rotation)
                self.normalLine.rotate(rotation)
                self.lineRightGen.rotate(rotation)
            elif round(angleLess, 2) < round(tester, 2):
                self.lineLeftGen.rotate(-rotation)
                self.normalLine.rotate(-rotation)
                self.lineRightGen.rotate(-rotation)
Ejemplo n.º 10
0
class LynelBoss(LynelSprite):
    def __init__(self,pos,vel,baseimage,image,fadedBase,death):
        self.trident = False
        self.pos = pos
        self.vel = vel
        self.detectedRadius = 500
        self.followRadius = 800
        self.speed = 60
        self.direction = Vector()
        self.ability = Cannon()
        self.incrementalTimer = 0
        self.incrementalTimer2 = 0
        self.incrementalTimer3 = 0
        self.incrementalTimer4 = 0
        self.inBoundary = False
        self.positions = []
        self.enemies = []
        self.health = 1000
        self.radius = 100
        self.spawn = False
        self.boss = LynelSprite(self.pos, baseimage, 175, 300, 3, 6, [0, 2],image, 608, 130, 8, 2, [1, 1], fadedBase, 175, 300, 3, 6, [0, 2],death, 270, 50, 6, 1, [0, 0],0)
        self.start(self.pos, baseimage, 175, 300, 3, 6, [0.2],
                   image, 608, 130, 8  , 2, [1,1], fadedBase, 175, 300, 3, 6, [0, 2],death, 270, 50, 6, 1, [0, 0],0)
        self.moving = False
        self.generator = Vector(0,-200)
        self.draw = False
        self.fireOrb = simplegui._load_local_image('Resources/images/fireOrb.png')
        self.fire = simplegui._load_local_image('Resources/images/fireBall.png')
        self.fireEnabled = False
        self.death = False
        self.damageResistence = 3


    def drawHealthBar(self,canvas,offset):
        canvas.draw_line((390, 50), (1390, 50), 25, "black")
        canvas.draw_line((390, 50), (390+self.health, 50), 25, "Red")

    def updateSprite(self,canvas,offset,player):
        self.boss.updateDirection(player,self.inBoundary,self.spawn,self)
        self.boss.draw(canvas,offset,self.positions,self.spawn,self)

    def spawnBats(self):
        self.spawn = True

    def update(self):
        self.vel.multiply(0.85)
        self.pos.add(self.vel)


    def fireTridents(self,player,projectiles,lasers,trident):
        self.ability.fire(player.pos, projectiles, lasers, self.pos, "enemy",1.5,4,trident)


    def detectionArea(self,player:Character):
        if not self.spawn:
            distanceToPlayer = player.pos.copy().subtract(self.pos)
            if distanceToPlayer.length() >= self.detectedRadius+player.radius:
                self.inBoundary = False
                if self.incrementalTimer2 % 1 == 0:
                    self.positions.append(self.pos.copy())
                    if self.positions.__len__() == 10:
                        self.positions.pop(0)
                    self.incrementalTimer2 = 0
                self.incrementalTimer2 += 1

                if self.incrementalTimer % 30 == 0 and not self.moving:
                    self.moving = True
                    self.vel = distanceToPlayer.getNormalized()*self.speed
                    self.incrementalTimer = 0
                self.incrementalTimer += 1
                self.trident = False

            if self.vel.length() < 5:
                self.moving = False
                self.inBoundary = True
                self.positions = []
                self.vel = Vector(0,0)
                if not distanceToPlayer.length() >= self.detectedRadius+player.radius:
                    self.trident = True

    def drawDetectionArea(self,canvas,offset):
        canvas.draw_circle((self.pos + offset).getP(), self.detectedRadius, 1, "red")
        canvas.draw_circle((self.pos + offset).getP(), self.followRadius, 1, "white")
        canvas.draw_circle((self.pos + offset).getP(), self.radius, 1, "white")

    def fireBombard(self):
        angle = 360 / 9
        gen = self.generator
        self.vertices = []
        for i in range(9):
            self.vertices.append(self.pos + gen)
            gen.rotate(angle)

    def drawFire(self,canvas,offset,player,projectiles,lasers):
        if not self.fireEnabled:
            self.fireBombard()
            self.fireEnabled = True
        for i in range(9):
            canvas.draw_image(self.fireOrb, (self.fireOrb.get_width() / 2,
                                             self.fireOrb.get_height() / 2),
                              (self.fireOrb.get_width(), self.fireOrb.get_height()), ((self.vertices[i] + offset).getP()),
                              (self.fireOrb.get_width() * 6, self.fireOrb.get_height() * 6), 0
                              )

            if self.incrementalTimer3 % 50 == 0:
                self.ability.fire(player.pos, projectiles, lasers, self.vertices[i], "enemy", 1, 4, self.fire)
                self.incrementalTimer3 = 0

            self.incrementalTimer3 += 1