I'm working on my first original idea after having followed. A few tutorials. Going to be a 2 player cooperative falling block puzzle. I'm using Sprite flags to check the color of adjacent blocks. Each color with its own flag. But, is there a way I can check for ANY flag for the purpose of collision detection? Or do I need to set aside a separate flag or that?
![](/media/59910/received_967406017189282.webp)
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/14590/2_2bitchuck.png)
Yeah, if no flags are set, fget will return 0 and if any flags are set, fget will return greater than 0, so if you just want to check for any flag:
if fget(sprite_number) > 0 then -- one or more flags are set, do stuff else -- no flags are set, do other stuff end |
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi6.png)
Hmm... Well don't I feel like a dummy. That's absurdly easy.
Thank you!
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi6.png)
Ok so here's a question. Apparently mget only works on tiles set by the map function. Is there another way to check what Sprite is below the current object if that Sprite is also an object?
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/41031/avapourwok.png)
Not quite: mget does not look at the screen data at all, it looks at tiles in the map data. For games that draw the map with its 0,0 corner at 0,0 on screen these appear to be the same, so it’s an easy thing to miss! Note that fget does not care about the map or screen, it only operates on a sprite number that you give it.
To keep your code working, you can use mset to put your pieces in the map (I suppose you are using spr now). This means they will move 8px at a time, and have to call mset to replace the previous position of each piece.
The other way to manage moving objects is to create them in code, for example as tables (with keys for coordinates, current sprite, animation info, etc). Board games typically have a table to represent their grid, containing data to represent the game pieces, so the code to check neighbours does not look at the map but at the board table.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi6.png)
Ok that makes sense. Currently using tables to create the objects, since I need multiple instances of them.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi6.png)
Ok. Are there any carts I can look at that would give me a good idea of how to set up a table to represent my game board?
[Please log in to post a comment]