I'm trying to make an enemy. I want to make it so if the enemy is above, below, to the right of, or to the left of the player, the player will take damage, but I could only figure out how to check if the enemy is in the same tile as the player. How would you check if something is next to the player, and not just in the same tile? Thanks!
on checkForAdjacentEnemies do
// set up some variables we will need
above_player = event.py
above_player--
below_player = event.py
below_player++
left_of_player = event.px
left_of_player--
right_of_player = event.px
right_of_player++
// check above
if above_player>=0 then
tile_name = name event.px, above_player
call "checkEnemyForDamage"
end
// check below
if below_player<=14 then
tile_name = name event.px, below_player
call "checkEnemyForDamage"
end
// check left
if left_of_player>=0 then
tile_name = name left_of_player, event.py
call "checkEnemyForDamage"
end
// check right
if right_of_player<=24 then
tile_name = name right_of_player, event.py
call "checkEnemyForDamage"
end
end
on checkEnemyForDamage do
if tile_name=="EnemyTile" then
call "enemyDealsDamageToPlayer"
end
end
something like this; I haven't tested it, but hopefully you get the idea
1 Like