Tag: safe zone object spawning

Wrapping safe zone spawn in Game Maker

I got a working demo of a safe zone spawn which works with wrapping rooms. I refined my technique for determining the safe zone, and now instead of being a square, it is circular.

I like this approach, it works pretty well. Basically, rather than trying to literally “wrap” the safe zone around the edge of the room, I create five safe zones. They are at protected(x,y), protected((x+/-room_width), y), and protected(x,(y+/-room_height)). In my instance_create loop, I merely determine whether the new instance’s candidate x,y location is within some distance of any of these five points.

The current script I wrote up is working, but it just uses a distance in pixels. My original approach calculated a distance automatically, based on the size of the objects’ sprites, and a padding factor, which I liked. I’ll likely create a version of this script that works that way in the next day or so, when I have a moment, and then package the whole thing up into a .gex for distribution.

Until then, the .gmk source is already up on the site.

One other note: One of the annoying things about Game Maker is that when you write a function, you can only return a single value. In most other languages, you can create classes of objects, which can be used to encapsulate as many values as you like, and return the entire object. Game Maker kindof lets you do this, but you have to create a Game Maker object, which it a bit more literally object-like, in that it carries some baggage with it. I think that my function would be more useful if it simply returned a set of (x,y) coordinates without actually creating an instance there. But I can’t return both x and y — a function can only return one value. I could return the id of an instance of an object, however, and simply spawn an empty, spriteless object at those x,y coordinates, and allow the developer to either change that instance into whatever kind of object they needed there, or else grab the x and y values from the object and destroy it. It’s an idea I’m toying with, not really sure which way to handle it is best at the moment, but it’s fun to play around with ideas.