Simple Enemies in Playdate
This post is how I made the enemy’s move in my Playdate Pulp game. First, you need a function, EnemyMoveUpdate once you have that, in the game code you create a variable that is (I will use foo as this variable)= to event.frame. Event.frame is equal to the number of frames that have elapsed since the start of the game. Now you divided this by how fast you want your enemy to move, so 4 is fast whereas 10 is more normal. Then you make a new variable foo2 that = to the floor of foo then you see if foo is equal to foo2 if it is then tell that function to run otherwise do nothing.
Credit to SquidGod for this part.
Now onto the actual enemy, make your little design
then get to coding. On the function set the EnemyX, and EnemyY to event.x/y which basically tracks wherever the tile is and then says if event.px which is the player x is more than enemyX then minus one from EnemyX elseif event.px less than the enemy then plus one to the EnemyX if nothing happens the player x is equal to the enemy x and it should change its y. You do the same for the enemy Y’s then you have to make sure the enemy isn’t going out of bounds so you just say something like foo = name of new enemyX and EnemyY now we have the name of the next block the enemy is going to go to. then it is != to white(which is the only block the enemies should go on) if it’s true it resets the EnemyX to event.x wherever it is now so when we change the next block it won’t plus or minus the x at all the x will stay the same. This just makes it so the enemy can’t go over solid block and it can’t go out of bounds. You do the same for the Y then you tell the enemy to swap white and the new EnemyX, EnemyY to swap with the enemy.
The final thing we have to do is deal damage. so we check if enemyX = to PlayerX then if EnemyY = PlayerY if that’s true I have a function to do damage to the player so we set the damage to 1 then tell event.player to call that function and in that function it damages the player. More on the health system next post. Thank you for reading tell me if you have any questions