Example #1
0
	def enemyAI(self, playerCoords, worldMap, smellRange=13, chaseRange=17, walkSpeed=2, chaseSpeed=2, mapsize=256):
		playerX, playerY = playerCoords
		# Determine wether the zombie should starting or stop chasing
		if (((self.currentX - playerX))**2)+((self.currentY - playerY))**2 < (smellRange*32)**2:
			self.chasingPlayer = True
		if (((self.currentX - playerX))**2)+((self.currentY - playerY))**2 > (chaseRange*32)**2:
			self.chasingPlayer = False
			
		if self.chasingPlayer == True:
			if self.currentX < playerX and self.currentX+chaseSpeed+32 < mapsize*32:
				if worldMap[(self.currentX+32+chaseSpeed)/32][(self.currentY+16)/32] == 'grass':
					self.currentX += chaseSpeed
			if self.currentY < playerY and self.currentY+chaseSpeed+32 < mapsize*32:
				if worldMap[(self.currentX+16)/32][(self.currentY+chaseSpeed+32)/32] == 'grass':
					self.currentY += chaseSpeed
			if self.currentX > playerX:
				if worldMap[(self.currentX-chaseSpeed)/32][(self.currentY+16)/32] == 'grass':
					self.currentX -= chaseSpeed
			if self.currentY > playerY:
				if worldMap[(self.currentX+16)/32][(self.currentY-chaseSpeed)/32] == 'grass':
					self.currentY -= chaseSpeed
		anchorX, anchorY = (playerX-768/2, playerY-768/2)
		self.inScreen = False
		self.angle = sprites.calcAngleToMouse((playerX, playerY), (self.currentX, self.currentY))
		self.sprite.spriteRot = self.sprite.rotCenter(self.angle)
		
		if -32 < self.currentX - anchorX < 768 and -32 < self.currentY - anchorY < 768:
			self.inScreen = True
			self.inScreenX = self.currentX - anchorX
			self.inScreenY = self.currentY - anchorY
Example #2
0
    def updateIngame(self):
        self.screen.fill((0, 0, 0))
        self.anchorx, self.anchory = self.playerCoords
        self.zombie.enemyAI(self.playerCoords, self.world)
        self.playerCoords = movement.movePlayer(self.playerCoords, self.mapsize, self.world)
        terrain.drawMap(self.screen, self.currentChunk, self.playerCoords)
        self.mouseangle = sprites.calcAngleToMouse(self.mouseCoords, self.midCoords)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.gamestate = "quit"

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.gamestate = "quit"

            elif event.type == MOUSEMOTION:
                self.mouseCoords = event.pos

        self.newplayer = self.player.rotCenter(self.mouseangle)
        self.keys = pygame.key.get_pressed()

        self.keys = pygame.key.get_pressed()
        if self.keys[pygame.K_z]:
            self.fire = 1

        if self.fire == 1:
            if len(self.bullets) < 1:
                (initialX, initialY) = self.midCoords
                initialX += 16
                initialY += 16
                bulletCoords = (initialX, initialY)
                self.bullets.append(projectiles.Bullet(bulletCoords, self.mouseangle))
            self.fire = 0

        for idx, bullet in enumerate(self.bullets):
            bullCoords = (bullet.currentX, bullet.currentY)
            bullet.length += 1
            if bullet.currentY >= self.width or bullet.currentY <= 16:
                del self.bullets[idx]
                continue

            if bullet.currentX >= self.width or bullet.currentX <= 16:
                del self.bullets[idx]

        for bullet in self.bullets:
            bullet.update(self.bullImage.sprite, self.screen)
        self.screen.blit(self.newplayer, self.midCoords)
        self.zombie.update(self.screen)
        self.screen.blit(self.currentUI, (768, 0))
        self.fps = self.Clock.get_fps()
        self.Clock.tick(self.FPS)
        playerX, playerY = self.playerCoords
        caption = (
            "Fps: "
            + str(math.floor(self.fps))
            + " | Player:("
            + str(playerX / 32)
            + ","
            + str(playerY / 32)
            + ")  | Zombie:("
            + str(self.zombie.currentX / 32)
            + ","
            + str(self.zombie.currentY / 32)
            + ") |  Chasing: "
            + str(self.zombie.chasingPlayer)
        )
        pygame.display.set_caption(caption)
        pygame.display.flip()