Esempio n. 1
0
class Ship:
    def __init__(self, app):
        self.screen = app.screen
        self.screen_rect = app.screen.get_rect()
        self.image = pygame.image.load("Assets/Image/Ship.png")
        self.rect = self.image.get_rect()
        self.rect.midbottom = self.screen_rect.midbottom
        self.speed = 1
        self.x = float(self.rect.x)
        self.move_right = False
        self.move_left = False
        self.Weapon = Weapon()

    def draw(self):
        self.screen.blit(self.image, self.rect)
        self.Weapon.draw(self.screen)

    def update(self):
        if self.move_right and self.rect.x + self.rect.width - 20 < self.screen_rect.width:
            self.speed = 1
            self.x += self.speed
        elif self.move_left and self.rect.x + 15 > 0:
            self.speed = 1
            self.x -= self.speed
        self.rect.x = self.x
        self.Weapon.update()

    def Disparar(self):
        self.Weapon.shoot(self.rect.x + 18, self.rect.y)

    def DispararESP(self, Puntuacion):
        if (Puntuacion >= 4):
            self.Weapon.shootESP(self.rect.x + 18, self.rect.y)
Esempio n. 2
0
class Ship:
    ships = []

    def __init__(self, parent, pos=[0, 0]):

        self.parent = parent
        self.stats = RPGStats()
        self.pos = Vex(pos[0], pos[1])
        self.rot = 0
        self.stats.lvlUP()

        self.weapon = Weapon(self, [0, 0, 0], [.5, .5, .5], 60, 1, 1,
                             (255, 0, 0))
        self.points = [
            Vex(-.5, .5, 0),
            Vex(.5, .5, 0),
            Vex(0.0, -.5, 0),
            Vex(0.0, .5, -.3),
            Vex(-.25, .45, -.15),
            Vex(.25, .45, -.15)
        ]
        self.projPoints = [Vex(0, 0)] * 6
        self.lines = [(0, 4), (4, 5), (5, 1), (1, 2), (2, 0), (2, 3), (3, 0),
                      (3, 1), (2, 4), (2, 5)]

        self.shieldPoints = []
        self.shieldEdges = []
        self.shieldRot = [0, 0, 0]
        self.occupied = False

        #construct player shield
        sides = 10
        size = 2

        self.shieldRadius = size
        mi = 0

        for i in range(sides):
            angle_deg = (360 / sides) * i
            angle_rad = 3.14159265359 / 180 * angle_deg
            x = 0 + size * math.cos(angle_rad)
            y = 0 + size * math.sin(angle_rad)
            self.shieldPoints += [Vex(x, y)]

        for i in range(mi, len(self.shieldPoints)):
            seg = []
            if i + 1 < len(self.shieldPoints):
                seg = (i, i + 1)
            else:
                seg = (i, mi)
                mi = i + 1
            self.shieldEdges.append(seg)

    def getShieldRadius(self):
        return self.shieldRadius

    def setParent(self, par):
        self.parent = par

    def isOccupied(self):
        return self.occupied

    def setOccupied(self, val):
        self.occupied = val

    def totalDamage(self):
        return self.stats.getSTR()

    def shoot(self, pos, rot, ant):
        self.weapon.Shoot(pos, rot, ant)

    def syncPos(self, pos):
        self.pos = pos.copy()

    def updatePlayerShip(self, cam):
        env = Environment.Environment
        self.weapon.update()

        proj = []
        for vec in self.points:
            if not self.isOccupied():
                v = ((vec.rotate2dXY(-self.rot) - cam.pos +
                      self.pos).rotate2dXY(cam.rot[1])).rotate2dYZ(
                          cam.mov[2], cam.rot[0])  # pitch
            else:
                v = (vec + self.pos).setZ(vec.z() - cam.pos.z()).rotate2dYZ(
                    cam.mov[2], cam.rot[0])  # pitch

            f = env.fov / (v.z() + .0000001)
            if (f < env.lim):
                f = 1000
            v = v * f + env.center
            proj += [v.p2D()]

        for l in self.lines:
            points = [proj[l[0]], proj[l[1]]]
            if (env.inScreen(points[0]) or env.inScreen(points[1])):
                env.add_edge(Color.NEONBLUE, points)
        self.shieldRot[1] = cam.rot[1]

        shldH = -(self.stats.getHP() / self.stats.getHTH()) / 4
        proj = []
        fs = []
        for vec in self.shieldPoints:
            if not self.isOccupied():
                v = ((vec.rotate2dXY(-self.rot) - cam.pos +
                      self.pos).rotate2dXY(cam.rot[1])).rotate2dYZ(
                          cam.mov[2], cam.rot[0])  # pitch
            else:
                v = (vec.rotate2dXY(self.shieldRot[1]) +
                     self.pos).setZ(self.pos.z() - cam.pos.z()).rotate2dYZ(
                         cam.mov[2], cam.rot[0])  # pitch

            f = env.fov / (v.z() + .00000001)
            if (f < env.lim):
                f = 1000
            v = v * f + env.center
            proj += [v.p2D()]
            fs += [f]

        for l in self.shieldEdges:
            points = [proj[l[0]], proj[l[1]]]
            fst = [fs[l[0]], fs[l[1]]]
            if (env.inScreen(points[0]) or env.inScreen(points[1])):
                env.add_edge(Color.BLUE, points, 1, 1, shldH, fst)

    def updateCreatureShip(self, cam, pos, ang):
        env = Environment.Environment
        self.weapon.update()
        if cam.pos.dist2D(self.pos) < env.renderDist:
            proj = []
            for vec in self.points:
                v = ((vec.rotate2dXY(math.radians(ang)) - cam.pos +
                      pos).rotate2dXY(cam.rot[1])).rotate2dYZ(
                          cam.mov[2], cam.rot[0])  # pitch

                f = env.fov / (v.z() + .00000001)
                if (f < env.lim):
                    f = 1000
                v = v * f + env.center
                proj += [v.p2D()]

            for l in self.lines:
                points = [proj[l[0]], proj[l[1]]]
                if (env.inScreen(points[0]) or env.inScreen(points[1])):
                    env.add_edge(Color.NEONBLUE, points)

            hth = -(self.stats.getHP() / self.stats.getHTH()) / 2

            proj = []
            fs = []
            for vec in self.shieldPoints:
                v = (vec.rotate2dXY(math.radians(ang)) - cam.pos +
                     pos).rotate2dXY(cam.rot[1]).rotate2dYZ(
                         cam.mov[2], cam.rot[0])  # pitch
                f = env.fov / (v.z() + .00000001)
                if (f < env.lim):
                    f = 1000
                v = v * f + env.center
                proj += [v.p2D()]
                fs += [f]

            for l in self.shieldEdges:
                points = [proj[l[0]], proj[l[1]]]
                fst = [fs[l[0]], fs[l[1]]]
                if (env.inScreen(points[0]) or env.inScreen(points[1])):
                    env.add_edge(Color.BLUE, points, 1, 1, hth, fst)

    @staticmethod
    def remove_unoccupied(ship):
        try:
            Ship.ships.remove(ship)
        except:
            pass

    @staticmethod
    def add_unoccupied(ship):
        Ship.ships += [ship]

    @staticmethod
    def updateUnOccupied(cam):
        env = Environment.Environment
        for self in Ship.ships:
            if not self.isOccupied() and cam.pos.dist2D(self.pos) < 300:
                proj = []
                for vec in self.points:
                    v = (vec.rotate2dXY(self.rot) - cam.pos +
                         self.pos).rotate2dXY(cam.rot[1]).rotate2dYZ(
                             cam.mov[2], cam.rot[0])  # pitch

                    f = env.fov / (v.z() + .00000001)
                    if (f < env.lim):
                        f = 1000
                    v = v * f + env.center
                    proj += [v.p2D()]

                for l in self.lines:
                    points = [proj[l[0]], proj[l[1]]]
                    if (env.inScreen(points[0]) or env.inScreen(points[1])):
                        env.add_edge(Color.NEONBLUE, points)

                hth = -(self.stats.getHP() / self.stats.getHTH()) / 2

                proj = []
                fs = []
                for vec in self.shieldPoints:
                    v = (vec - cam.pos + self.pos).rotate2dXY(
                        cam.rot[1]).rotate2dYZ(cam.mov[2], cam.rot[0])  # pitch
                    f = env.fov / (v.z() + .00000001)
                    if (f < env.lim):
                        f = 1000
                    v = v * f + env.center
                    proj += [v.p2D()]
                    fs += [f]

                for l in self.shieldEdges:
                    points = [proj[l[0]], proj[l[1]]]
                    fst = [fs[l[0]], fs[l[1]]]
                    if (env.inScreen(points[0]) or env.inScreen(points[1])):
                        env.add_edge(Color.BLUE, points, 1, 1, hth, fst)
Esempio n. 3
0
class Player(QWidget):  # player1 or player2

    livesSignal = pyqtSignal()
    pointsSignal = pyqtSignal(int)

    def __init__(self, parent, playerId, noOfPlayers):

        super().__init__(parent)

        self.noOfPlayers = noOfPlayers
        self.parent = parent
        self.isDead = False
        self.playerId = playerId
        self.playerImg_normal = IMAGES_DIR + playerId + '.png'
        self.playerImg_left = IMAGES_DIR + playerId + '_left.png'
        self.playerImg_right = IMAGES_DIR + playerId + '_right.png'
        self.player = QLabel(parent)
        self.initialPositionX = None
        self.initialPositionY = None
        self.PixMap = QPixmap(self.playerImg_normal)

        self.Normal = True
        self.Left = False
        self.Right = False
        self.Heigth = 50
        self.Width = 50

        self.bonusNoWeapon = False
        self.counterBonus = 0

        self.lifes = 3
        self.score = 0

        self.timer = QBasicTimer()
        self.timer.start(32, self)

        if self.noOfPlayers == 1:
            if self.playerId == 'player1':
                self.PositionX = WINDOWWIDTH/2
                self.initialPositionX = WINDOWWIDTH/2
                self.PositionY = PLAYER_HEIGTH
        elif self.noOfPlayers == 2:
            if self.playerId == 'player1':
                self.PositionX = 55
                self.initialPositionX = 55
                self.PositionY = PLAYER_HEIGTH
            elif self.playerId == 'player2':
                self.PositionX = 700
                self.initialPositionX = 700
                self.PositionY = PLAYER_HEIGTH
        self.weapon = Weapon(self)

    def timerEvent(self, event):
        if self.bonusNoWeapon:
            self.counterBonus += 1
            if self.counterBonus == 80:
                self.counterBonus = 0
                self.bonusNoWeapon = False
        self.weapon.update()

    def shoot(self):
        if not self.bonusNoWeapon:
            self.weapon.isActive = True

    def drawPlayer(self, orientation):
        if orientation == 'normal':
            self.Normal = True
            self.Left = False
            self.Right = False
            self.PixMap = QPixmap(self.playerImg_normal)

        elif orientation == 'left':
            self.Normal = False
            self.Left = True
            self.Right = False
            self.PixMap = QPixmap(self.playerImg_left)
        elif orientation == 'right':
            self.Normal = False
            self.Left = False
            self.Right = True
            self.PixMap = QPixmap(self.playerImg_right)

        self.player.setPixmap(self.PixMap)

    def update(self, key):

        if self.playerId == 'player1':
            if key == Qt.Key_Space:  # and not self.weapon.isActive:
                    self.shoot()
            elif key == Qt.Key_Right:
                if self.PositionX + self.Width < WINDOWWIDTH-13:
                    self.drawPlayer('right')
                    self.PositionX += 5
                    self.player.setGeometry(self.PositionX, self.PositionY, self.Width, self.Heigth)

            elif key == Qt.Key_Left:
                if self.PositionX - 5 > 20:
                    self.drawPlayer('left')
                    self.PositionX -= 5
                    self.player.setGeometry(self.PositionX, self.PositionY, self.Width, self.Heigth)
            elif key == Qt.Key_Minus:
                self.drawPlayer('normal')
                self.PositionX = self.initialPositionX
                self.player.setGeometry(self.PositionX, self.PositionY, self.Width, self.Heigth)

        elif self.playerId == 'player2':
            if key == Qt.Key_Shift:
                    self.shoot()
            elif key == Qt.Key_D:
                if self.PositionX + self.Width < WINDOWWIDTH-13:
                    self.drawPlayer('right')
                    self.PositionX += 5
                    self.player.setGeometry(self.PositionX, self.PositionY, self.Width, self.Heigth)
            elif key == Qt.Key_A:
                if self.PositionX - 5 > 20:
                    self.drawPlayer('left')
                    self.PositionX -= 5
                    self.player.setGeometry(self.PositionX, self.PositionY, self.Width, self.Heigth)
            elif key == Qt.Key_Minus:
                self.drawPlayer('normal')
                self.player.setGeometry(self.initialPositionX, self.PositionY, self.Width, self.Heigth)