Log In  

Hey, I'm making a small game.

I need to get the flag value of a sprite I'm drawing and moving in the _draw function.
I need to know when the player hits the sprite. But I can't use mget() to get sprite number of it, because the sprite is not part of the map..

Any ideas how to go about it?
Right now I'm just using pget() to register it by color, but that solution is not super stable with so few colors ;)

Hope someone can help.

P#26605 2016-08-06 17:58 ( Edited 2016-08-07 11:14)

:: s0r00t

This is an idea I just got, might not work, but worth giving it a try.
Considering a sprite is 8x8 :

-> get the top left pixel of the sprite
-> iterate through all colors
-> then iterate through the spritesheet to compare colors

P#26606 2016-08-06 18:22 ( Edited 2016-08-06 22:22)

In pico-8, the only built-in functionality of a "sprite" is you can draw it with spr(). Any flags, or a location, or velocity, or hit detection etc. has to be created/tracked from scratch.

Most people make a a table for enemies, or bullets, or the player, and assign various variables to it.

function spawnenemy()
 add(enemies, {sprite=5,x=20,y=20,flag=1})

Go to pico-8.txt (same as the manual link up top here) and check out the "Example Cartridges" section - Jelpi does a decent job of tracking multiple types of objects. (player, pickups, and enemies (all actors) and seperate sparkle particles)

P#26607 2016-08-06 19:11 ( Edited 2016-08-06 23:25)

Also... If what you are wanting to do is check for a collision you'll need to do that by comparing x/y positions of the two Sprite objects (eg player and enemy).

Sorry if I'm stating the obvious but I thought it worth mentioning just in case.

P#26609 2016-08-06 19:59 ( Edited 2016-08-06 23:59)
:: ilkke

Right, did you actually wanted to ask how to detect collision between two sprites?

P#26619 2016-08-07 05:02 ( Edited 2016-08-07 09:02)

Good idea s0r00t. Might try it out later :)

But yeah, basically I just wanted to do collision, and since there was the awesome mget() I was just wandering if there was the same for sprites.
I will try and look into how it's done in Jelpi then :) Thanks for the help!

P#26623 2016-08-07 07:14 ( Edited 2016-08-07 11:14)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-08-10 05:06:41 | 0.007s | Q:17