Log In  


I am using a sprite tile as a pickup item. When the player interacts with it, I need it to just disappear. How can I achieve this? I was imagining something along this line:

if(pickup_tile(player.x-1,player.y) == false) then
P#48781 2018-01-31 09:39 ( Edited 2018-02-14 12:16)


You'd need to do something like:

--inside _init()
needPickup = true

--inside _update()
if (abs(player.x - tile.x) < 8 and abs(player.y - tile.y) < 8 and needPickup) then
 needPickup = false
--inside _draw()
if (needPickup) then
 spr(99, tile.x, tile.y)
P#48783 2018-01-31 10:31


hey @MEMalguy - You probably want to store all of the pickups in a table.
Then check for collisions between the player and each item in that table every frame.
And if you get a hit, you can remove that item from the table.
You'll want to remove it /after/ you iterate over the list, OR you can do your checks using the the FOREACH(table) keyword.

Here's a quick example:

Cart [#48784#] | Copy | Code | 2018-01-31 | Link

P#48785 2018-01-31 10:47


Thank you @enargy for taking the time to create that example. I am not prepared to tackle collisions yet and am trying to stick with the simple approach of tiles, though.

I added this code to each of the 'btn' values:

if(pickup_tile(player.x+8+1,player.y) == false) then

However, it still does not seem to be working.

P#49279 2018-02-14 09:45 ( Edited 2018-02-14 09:56)


When you say a sprite tile as a pickup item, do you mean a tile on the map? Like you have made a level map and put coins on it too?

The simplest way to deal with this is to detect if the player is intersecting with a map tile using that particular sprite ID, and if so, add one to their collectible counter or whatever, and then replace that map tile with nothing (or sky/air etc.). Since you have physically changed that map tile, it won't trigger picking it up again the next time the program checks where the player is standing.

However there is one pitfall with this: because you have permanently modified the map, the collectibles won't automatically be back in place if the player dies and you restart the level. You might need to actually reset the cart, unless you perform some more complicated operations to track and spawn the collectibles.

This is basically how I did combat with enemies in Micro RPG, I just replaced them on the map with whatever map tile was directly below them:

Cart [#49010#] | Copy | Code | 2018-02-05 | Link

The relevant code here is:

if mget(sx,sy)==223 then

In other words, if the player's location (sx/sy) on the map is 223 (an enemy), then set the current map tile of the player with the same tile as the one just below it, and increase the player's level by 1 (sl).

You probably can't use this exact code because my player moves in exact tile increments, very simply. It's not like a platformer with smooth movement. But maybe you can see the concept.

P#49281 2018-02-14 12:16 ( Edited 2018-02-14 12:26)

Log in to post a comment


New User | Account Help
:: New User
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-02-18 01:04 | 0.282s | 1572k | Q:29