• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM check for instance in x,y without using collision masks

T

TheRBZ

Guest
I'd like to find out how to check if x,y is occupied WITHOUT using collision masks due to my implementation of the z axis. This is why position_meeting will not work. Any ideas?
Code:
        if !(position_meeting(mouse_x - mouse_x mod 32,mouse_y - mouse_y mod 32,obj_tree)){
            tree_create(mouse_x,mouse_y,1,irandom(3)+1);
            global.wood -= 10;
        }
is what I've tried but the function uses collision masks so a tree in front of it blocks it from placing
It could be easier to check if a grid square is occupied but then I'd need to work out a system for that instead of using x - x mod 32.
and a gif to show what I'm on about https://gyazo.com/a9fa02d6a440703f13222eb536639087
Thanks
 
Last edited by a moderator:

NightFrost

Member
If your sprites are larger than grid size then yeah, you can't use collision checking because of the overlap. As you assumed, a system to check for occupied grid cells is better. First create a 2d array with size equal to your grid and fill with zeroes. The x and y coordinates can be translated to grid coordinates by dividing by 32 and flooring, or more simply using div (var grid_x = x div 32 etc). Better yet, use a variable instead of hardcoding 32 so you can change grid size on the fly if necessary. When you plant a tree, set the appropriate array position to one. When a tree is removed, set to zero. If only one thing at a time can occupy a grid slot, you can use this to track everything, simply assigning numbers to each type of occupant. Simplify your coding process by creating two scripts for the job, like grid_set_position(x, y, occupant type) and grid_clear_position(x, y).
 
Top