Change sprite's behaviour according to player's position

Hi there, I'm new there and i'm just starting my pulp journey.

I've tried to find an answer by myself on this forum but i'm struggling with tile / player positions in general..

my goal : have a better understanding of events and how to trigger them according to specific conditions, especially according to position.

for exemple:

  1. I would like my player to be able to grab a torch ( no problem with that)

  2. I would like to make a dark wall (sprite) to change to a lit wall tile when the player walks by it holding the torch and go dark again when the players is out of range.

my problem:
I'm missing something understanding event.px

Since for certain applications I would like to get these values to trigger animations / events

I' first tried to label player's coordinates in real time by using:

on update do
	P_X = event.px // Store starting position
	P_Y = event.py
end

on draw do
  
	// Print player position----------------------------------
	label "{P_X}" at 1,1
	label ":" at 2,1
	label "{P_Y}" at 3,1
end

but it doesn't work the expected way...

i'm struggling with tile / player positions in general.

if anyone has an idea on this it would make my day (and make me feel a lil less dumb :slight_smile: )
Thanks!

For the label problem:

label "{P_X} : {P_Y}" at 1,1 // would work just fine!
1 Like

Sure! seems obvious now! thanks!

i don't now the reason but with the label correction it seems to work right this time...
before, the Y position was correct but the X behaved odd..

anyway , Thanks!!

I managed to make a sprite behave according to the player's position.

I made an "eye" follow the player, but I'm struggling with diagonals.

eye-v1

here's my code :

on GAME script

on loop do
 emit "eyeMoveUpdate
end

on EYE sprite script

on eyeMoveUpdate do
	eyePosX = event.x
	eyePosY = event.y
	
	
	
	if event.px<eyePosX then // player is on the Left side
		frame 3
	elseif event.px>eyePosX then // player is on the Right side
		frame 4
	elseif event.py<eyePosY then // player is above
		frame 1
	elseif event.py>eyePosY then // player is under
		frame 2
		
	end
end

for exemple:
if the player is NorthWest. (up / left)

it should be:
event.px < eyePosX
event.py < eyePosY so two conditions at the same time..

but I'm not sure how to implement them in else if ...then

any ideas ?
thanks!

I've found a way... probably not the best but it works for now..

gif - arrows

2 Likes