Enemy AI In Pulp

I have a decent enemy AI put together thanks to this awesome video by Squidgod: https://www.youtube.com/watch?v=ERJ0J2vxbzk&list=PLlMPQvEA0GZMNW-l1vImDQtSMUDAcIuFa&index=3

However, I can't quite get it 100% right and I am not sure what to do after tinkering with it for an hour or so. The enemies movement works, but the player has to run through the enemy (via interact) to trigger a death or kill enemy action. The combat logic in the game works by looking at who has the higher attack power, the player or the enemy. For example, if the player's attack power is 4 and the enemy's attack power is 2 the player should kill the enemy. In testing I have enemies that can sneak onto the same tile as the player (behind the player, the player sitting on top) which is not correct because ANY contact should trigger a comparison of the attack power. How do I get Pulp to trigger that when either the enemy or the player touches one another? Here is what I have so far, I know this is wrong but update/collect/bump/etc. also do not work:

on interact do

// if the player's attack power is less than 2 (skeleton's attack power) then 
if attack<2 then
        //death
	fin "You died."
else
        //remove the enemy (they die)
	swap "white"
end

end

You need to have the player’s tile trigger whatever tile it is on, so the enemy or the player will always trigger each other. Example:

on turn do
//this is for every turn in your game
tell event.px,event.py to
call “attack”
end

on move do
call “turn”
end

Change this as you want, if the “turn” function doesn’t trigger the enemy code to check, try adding “wait 0.05 then”, it’s the smallest possible delay. Hope this helped.

1 Like

That didn't work, but your suggestion was still super helpful, it pointed me down a path where I was able to find a solution. Here's a rough outline of what I did for anyone that has a similar issue:

  1. Set up AI using Squidgod's outline
  2. Set playerX = event.px and playerY = event.py
    3a. Set up a call when the enemy's x and y match the player's x and y (enemy x/y is covered in Squidgod's video).

3b. call "attack" basically does this (enemyAttack will vary by the type of enemy):

on attack do

if attack<=enemyAttack then
	
	fin "You died."

    else
	
	tell newEnemyX,newEnemyY to
		
                 swap "white"
                 say "You killed whatever/add background."
	
            end
	
end

end

  1. I kept the interact piece for when the player moves into the enemy. The stuff I added triggers if the enemy moves into the player.

I think I have it, if I don't I will try and repost a solution. I'm noticing adding say "something" really helps during testing, it is sort of like print in other languages.