Game Mechanics Your Thoughts on How to Do Transformable and Destructible Landscape?

Hello Everyone,

I recently began a thread in the Programming forum asking how one might have Game Maker randomly generate a Risk-style map for a strategy game. I got some good advice, but it quickly became apparent that the requirements are way beyond an absolute beginner like myself, especially considering some of the features that I ultimately want my game to have. And so, for now, I have settled for pre-made maps.

One of the aforementioned features is the ability to transform or even destroy vast swathes of land, for I'm making a "god game" that gives the player the ability to do so. What I intend to do in order to achieve this in my pre-made maps is to draw the entire thing out in my art program, including the regions, and then cut those regions out of that image one by one. Then in Game Maker I reassemble them again like a jigsaw, with each region sprite belonging to an object. I've attached a screenshot of my testing room which has a reassembled map, a makeshift city, and a makeshift human. The water that the land tiles rest within is not the background, but an object of its own on a lower layer.

To my novice mind, having every region be its own instance seems to be a very easy way of having as much control over them as possible. I can have the player drown, drought, burn, plague, or do anything to any region, very easily show the effects visually by just changing the instance's sprite, and change the properties of or remove that instance entirely, and every other instance that might be on it at the time. I also don't see why this would cause any problems when it comes to creating an MP grid upon which the sentient entities of my worlds will travel. The one issue is that this approach would seem to demand that I have different versions of every region's sprite to account for everything a player might do to it, which will be a lot of work in terms of art, something that could be negated by having the landscape formed by tiles which all adhere to the same rules, which I think would be more complex in terms of coding.

The thing is that for me it isn't enough to simply emulate someone else's code to accomplish something, I really want to understand exactly what is going on, and according to my current, lowly understanding, this is the best way of accomplishing what I want to. However, I'd appreciate your thoughts on how I've approached this issue. Perhaps it is a terribly crude way to accomplish what I want.
 

Attachments

Last edited:
It sort of depends on what you mean by destructible terrain. Whenever I hear that term, I think of Worms, with the weapons blowing chunks out of the ground and stuff like that. But burning and plague and stuff, I'm not entirely sure what you mean visually when you say that, so it's hard to offer advice.

For the Worms-style destruction, the general method is to draw the sprite to a surface, set the blendmode to bm_subtract (gpu_set_blendmode(bm_subtract);) and then draw a sprite that represents the area of destruction (generally a white circle or shape of some sort, but in Worms it's always a circle) on the surface. This will "subtract" that area from the surface, leaving a transparent region where the pixels used to be. Once you've done that, you can then save the surface as a new sprite (my_new_sprite = sprite_create_from_surface(index, x, y, w, h, removeback, smooth, xorig, yorig);) and then you would assign the newly saved sprite to the sprite index of the object (sprite_index = my_new_sprite;). The "problems" here are that each sprite that is saved from a surface will be added to its own texture page, which will increase texture swaps (but this isn't too much of a worry unless you already have a bunch of texture swaps happening) and that you have to remember to delete the newly saved sprite once you're done with it (for instance, if a new destruction is applied to the sprite, you would have to delete the old sprite after creating the new one (perhaps assigning the new sprite to a temporary variable and then assigning it to the previous my_new_sprite variable after the deletion) with sprite_delete(my_new_sprite);, otherwise you'll have a memory leak as the old sprites are piling up in memory with no way to reference and delete them).

Perhaps this method could be used in some way for your project. Other than that, I would look into particles for things like plague/fire (I have a tutorial on creating particle effects in my sig so that might be helpful), and perhaps image_blend for the sprite, depending on what sort of effects you are after. Neither of those require the sprite alteration/saving technique I mentioned above, but you could get some pretty nice dynamic effects with them.
 
Top