コード例 #1
0
ファイル: slime.py プロジェクト: themoonisacheese/GZEN
    def update(self, ticktime, objlist):
        self.__timeSinceJump += ticktime / 1000.0
        player = None
        for obj in objlist:
            if obj.__class__.__name__ == 'Player':
                player = obj
                break
        if player is not None:
            if self.currentAnimationFrameIndex == 2:
                playerDirection = pygame.math.Vector2(
                    player.rect.centerx - self.rect.centerx,
                    player.rect.centery - self.rect.centery)
                self.facingLeft = not playerDirection.x < 0
                if playerDirection.x < 0:
                    self.changeVec((-100, -200))
                else:
                    self.changeVec((100, -200))
            if self.currentAnimationFrameIndex == 5:
                self.changeVec((0, 300))
                self.__timeSinceJump = 0

        GravityObject.update(self, ticktime, objlist)
コード例 #2
0
ファイル: player.py プロジェクト: themoonisacheese/GZEN
    def update(self, ticktime, objlist):
        self.timeSinceLastSwing += ticktime / 1000.0
        self.invincibleTimeLeft -= ticktime / 1000.0
        self.timeUntilGravChange -= ticktime / 1000.0
        GravityObject.update(self, ticktime, objlist, self.gravity)
        for obj in objlist:
            if obj.__class__.__name__ == 'Room':
                for block in obj.roomBlocks:
                    if self.respawn and block.__class__.__name__ == 'SpawnPoint':
                        self.respawn = False
                        self.changeVec((0, 0))
                        self.moveto(block.rect.center)
                    elif block.__class__.__name__ == 'Wall' and self.nextLevel and block.rect.collidepoint(
                            self.rect.centerx, self.rect.top - 4):
                        self.nextLevel = False
                        self.respawn = True
                        index = objlist.index(obj)
                        objlist[index] = Room(0, obj.floorNumber + 1)
                        if obj.floorNumber + 1 == 4:
                            self.setGravity(-1.0)
                        else:
                            self.setGravity(1.0)
                        objlist[index].show(True)
                        break
                    elif block.__class__.__name__ == 'Boss':
                        if not block.alreadyTalked:
                            self.changeVec((0, 0))
                            self.isInCutScene = True
                            block.alreadyTalked = True
                            self.__BossRoom = obj
                            self.__bossobj = block
                            obj.roomBlocks.append(
                                NpcDialog(
                                    (block.rect.centerx, block.rect.top - 200),
                                    block.nextDialogue(), self.nextBossDialog))
                    if self.isColliding(block):
                        if block.__class__.__name__ == 'Coin':
                            self.score = self.score + 100
                            block.destroy()
                            obj.roomBlocks.remove(block)
                        elif block.__class__.__name__ == 'Chicken':
                            if block.pickupDelay <= 0.0:
                                self.score = self.score + 200
                                block.destroy()
                                obj.roomBlocks.remove(block)
                        elif block.__class__.__name__ == 'Spike':
                            self.takeDamage(200)
                        elif block.__class__.__name__ == 'Spring':
                            self.addToVec(0, -800)
                            self.nextLevel = True
                            block.use()
                        elif block.__class__.__name__ == 'Button':
                            if self.timeUntilGravChange <= 0.0:
                                self.timeUntilGravChange = 2.0
                                self.setGravity(-self.gravity)
                                block.use()
                        elif block.__class__.__name__ == 'PNJ':
                            if not block.alreadyTalked and not self.upgrades.earPods:
                                self.changeVec((0, 0))
                                self.isInCutScene = True
                                obj.roomBlocks.append(
                                    NpcDialog((block.rect.centerx,
                                               block.rect.top - 10),
                                              block.getDialogue(),
                                              self.stopCutscene))

                        # test root class of enemies, to accomodate different enemy levels.
                        elif issubclass(block.__class__, Slime) or issubclass(
                                block.__class__, Bat):
                            if self.isSwingingSword:
                                # damage the enemy
                                block.takeDamage(
                                    self.upgrades.attackMultiplier)
                                if block.hp <= 0:
                                    obj.roomBlocks.append(
                                        Chicken(block.rect.center))
                                    block.destroy()
                                    obj.roomBlocks.remove(block)
                            else:
                                self.takeDamage(block.damage)