Log In  

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?

P#99939 2021-11-11 17:55 ( Edited 2021-11-11 17:56)

1

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
P#99941 2021-11-11 18:31

Hmm... Well don't I feel like a dummy. That's absurdly easy.

Thank you!

P#99943 2021-11-11 18:41

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?

P#100026 2021-11-13 04:19

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.

P#100068 2021-11-13 20:51

Ok that makes sense. Currently using tables to create the objects, since I need multiple instances of them.

P#100129 2021-11-14 19:58

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?

P#100200 2021-11-16 00:27

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 11:07:23 | 0.007s | Q:17