Exemplo n.º 1
0
    def __init__(self, name, lifes, image, collisionBoxImage,
                 playerBulletImage, playerSpeed, playerDamage,
                 putBulletPattern, shootBulletPattern):
        pygame.sprite.Sprite.__init__(self)
        self.name = name
        self.lifes = lifes
        self.image_origin = image
        self.image = self.image_origin.copy()
        self.collisionBoxImage = collisionBoxImage
        self.playerBulletImage = playerBulletImage
        self.playerDamage = playerDamage
        self.playerFastSpeed = playerSpeed[0]
        self.playerSlowSpeed = playerSpeed[1]
        self.putBulletPattern = putBulletPattern
        self.shootBulletPattern = shootBulletPattern

        self.rect = self.image.get_rect(
            center=(parameter.getGamearea().centerx,
                    parameter.getGamearea().bottom - 50))

        self.collisionBox = playerCollisionBox(
            collisionBoxImage=self.collisionBoxImage, playerRect=self.rect)

        self.radius = int(self.collisionBox.rect.width / 2)

        self.lastShootingTime = parameter.getTimer()

        self.power = 0

        self.hidden = False
        self.hiddenTime = parameter.getTimer()
Exemplo n.º 2
0
 def hide(self):
     # Hide player
     for eb in parameter.getEnemyBulletSprites():
         eb.kill()
     self.hidden = True
     self.hiddenTime = parameter.getTimer()
     self.rect.center = (parameter.getGamearea().centerx,
                         parameter.getGamearea().top - 200)
     # Decrease player power
     if self.power > 4:
         self.power -= 4
     else:
         self.power = 0
Exemplo n.º 3
0
    def update(self):
        now = parameter.getTimer()

        self.rect.move_ip(self.shootBulletPattern(now - self.generateTime))

        if not self.rect.colliderect(parameter.getGamearea()):
            self.kill()
Exemplo n.º 4
0
    def update(self):
        now = parameter.getTimer()

        self.rotate()
        self.rect.center = (self.dx * (now - self.generateTime) + self.generateCenter[0], \
                            self.dy * (now - self.generateTime) + self.generateCenter[1])

        if not self.rect.colliderect(parameter.getGamearea()):
            self.kill()
Exemplo n.º 5
0
 def update(self):
     now = parameter.getTimer()
     # Moving enemy
     self.rect.move_ip(self.movePattern(now - self.generateTime))
     # Kill enemy if out of screen
     if not self.rect.colliderect(parameter.getGamearea()):
         self.kill()
     # Shoot bullet
     self.shoot()
Exemplo n.º 6
0
    def __init__(self, name, Hp, image, movePattern, enemyBulletImage,
                 putBulletPattern, shootBulletPattern, dropItem):
        pygame.sprite.Sprite.__init__(self)
        self.name = name
        self.Hp = Hp
        self.image = image
        self.movePattern = movePattern
        self.enemyBulletImage = enemyBulletImage
        self.putBulletPattern = putBulletPattern
        self.shootBulletPattern = shootBulletPattern
        self.dropItem = dropItem

        self.rect = self.image.get_rect(center = (movePattern(-1)[0] + parameter.getGamearea().left, \
                                                  movePattern(-1)[1] + parameter.getGamearea().top))
        self.radius = int((self.rect.width / 2) * 0.5)

        self.generateTime = parameter.getTimer()
        self.lastShootingTime = [
            parameter.getTimer() for i in range(len(self.enemyBulletImage))
        ]
Exemplo n.º 7
0
    def update(self):
        now = parameter.getTimer()
        time = now - self.generateTime

        def itemMovement(time):
            v0 = -3
            g = 0.1
            v = v0 + g * time
            if v < 3:
                oldCenterX = self.rect.center[0]
                self.rect.center = (oldCenterX, v0 * time + 0.5 * g *
                                    (time**2) + self.generatePosition[1])
            else:
                self.rect.move_ip(0, 3)

        itemMovement(time)
        if self.rect.top > parameter.getGamearea().bottom:
            self.kill()
Exemplo n.º 8
0
    def update(self):
        self.rotate(self.generateTime)
        now = parameter.getTimer()
        # Becoming non-transparent by time
        if now - self.generateTime < 128:
            self.image.set_alpha((now - self.generateTime) * 2)
            self.radius = 0
        # Can collide detect with player as  being opaque
        else:
            self.image.set_alpha(255)
            self.radius = self.radius_origin

        if now - self.generateTime > 300:
            self.px += self.dx
            self.py += self.dy
            self.rect.center = (self.px, self.py)

        if not self.rect.colliderect(parameter.getGamearea()):
            self.kill()
Exemplo n.º 9
0
    def update(self):
        now = parameter.getTimer()
        # Find the nearest enemy
        try:
            enemyCenter = function.findMostCloseEnemy(self.playerRectCenter)
            self.dx += (enemyCenter[0] - self.rect.center[0]) / 5000 * (
                now - self.generateTime)**2
            self.dy += (enemyCenter[1] - self.rect.center[1]) / 5000 * (
                now - self.generateTime)**2

        except:
            pass

        self.rotate()

        self.rect.move_ip(function.returnTheComponentOfVectorX(self.dx, self.dy, self.speed), \
                          function.returnTheComponentOfVectorY(self.dx, self.dy, self.speed))

        if not self.rect.colliderect(parameter.getGamearea()):
            self.kill()
Exemplo n.º 10
0
    def __init__(self,
                 order,
                 time,
                 ifSpellCard,
                 bonus,
                 Hp,
                 bossImage,
                 bossMovement,
                 bossBulletImage,
                 bossPutBulletPattern,
                 BossShootBulletPattern,
                 dropItem,
                 background,
                 spellCardName=None):
        self.order = order
        self.time = time
        self.ifSpellCard = ifSpellCard
        self.spellCardName = spellCardName
        self.bonus_origin = bonus
        self.bonus = self.bonus_origin
        self.Hp = Hp
        self.bossImage = bossImage
        self.bossMovement = bossMovement
        self.bossBulletImage = bossBulletImage
        self.bossPutBulletPattern = bossPutBulletPattern
        self.bossShootBulletPattern = BossShootBulletPattern
        self.dropItem = dropItem
        self.background = background

        if not self.background == None:
            self.background_rect = self.background.get_rect(
                topleft=parameter.getGamearea().topleft)

        self.isAlive = False
        self.isDead = False
        self.ifGenerateBoss = False
        self.ifBonus = True
        self.timer = 0
Exemplo n.º 11
0
    def update(self):
        now = parameter.getTimer()

        # Hide player for a while when player died
        if self.hidden and now - self.hiddenTime < 30:
            for eb in parameter.getEnemyBulletSprites():
                eb.kill()
        elif self.hidden and now - self.hiddenTime == 30:
            self.radius = 0
            self.rect.center = (parameter.getGamearea().centerx,
                                parameter.getGamearea().bottom - 50)
        elif self.hidden and now - self.hiddenTime < 120:
            self.radius = 0
            if ((now - self.hiddenTime) % 6) in [0, 1, 2]:
                transparentImg = self.image_origin.copy()
                transparentImg.set_alpha(64)
                self.image = transparentImg
            else:
                self.image = self.image_origin
        else:
            self.image = self.image_origin
            self.radius = int(self.collisionBox.rect.width / 2)
            self.hidden = False

        # Key control
        keystate = pygame.key.get_pressed()
        if keystate[pygame.K_LSHIFT]:
            speed = self.playerSlowSpeed
        else:
            speed = self.playerFastSpeed
        if keystate[pygame.
                    K_LEFT] and self.rect.left > parameter.getGamearea().left:
            self.rect.move_ip(-1 * speed, 0)
            if self.rect.left < parameter.getGamearea().left:
                self.rect.left = parameter.getGamearea().left
        if keystate[
                pygame.
                K_RIGHT] and self.rect.right < parameter.getGamearea().right:
            self.rect.move_ip(speed, 0)
            if self.rect.right > parameter.getGamearea().right:
                self.rect.right = parameter.getGamearea().right
        if keystate[
                pygame.K_UP] and self.rect.top > parameter.getGamearea().top:
            self.rect.move_ip(0, -1 * speed)
            if self.rect.top < parameter.getGamearea().top:
                self.rect.top = parameter.getGamearea().top
        if keystate[
                pygame.
                K_DOWN] and self.rect.bottom < parameter.getGamearea().bottom:
            self.rect.move_ip(0, speed)
            if self.rect.bottom > parameter.getGamearea().bottom:
                self.rect.bottom = parameter.getGamearea().bottom
        if keystate[pygame.K_z]:
            self.shoot()

        # Stick player collision box to the player center
        self.collisionBox.rect.center = self.rect.center
        # self.collisionBox.rotate()

        # Return player position
        parameter.returnPlayerPosition(self.rect.center)
Exemplo n.º 12
0
 def update(self):
     super().update()
     if self.rect.bottom > parameter.getGamearea().bottom:
         self.kill()
Exemplo n.º 13
0
        # Set in parameter.py

        # Read config

        with open(path.join(path.dirname(__file__), "config.json"),
                  "r") as config:
            config_dic = json.load(config)
        highscore = config_dic["highscore"]

        # Set parameter
        running = True
        stageInitiated = True

        # Set player, enemy, bullet
        gameareaBackground1 = classes.Background(image = gameareaBackgroundImg, \
                                                topleft = function.raletivePosition(parameter.getGamearea().topleft, (0, -1440)),\
                                                speed = 1)
        gameareaBackground2 = classes.Background(image = gameareaBackgroundImg, \
                                                topleft = parameter.getGamearea().topleft,\
                                                speed = 1)

        parameter.getBackgroundSprites().add(gameareaBackground1)
        parameter.getBackgroundSprites().add(gameareaBackground2)

        player = classes.Player(name = "player", \
                                lifes = 9, \
                                image = playerImg, \
                                collisionBoxImage = playerCollisionBoxImg, \
                                playerBulletImage = (playerBulletImg, playerBulletTrackingImg), \
                                playerSpeed = (7, 4), \
                                playerDamage = (6, 4), \