How would you solve this effectively?

0 favourites
  • 5 posts
From the Asset Store
Solve the mathematical equations as fast as you can!
  • Just wanna do a little thought experiment. I have roughly an idea on how I'd do this myself, mostly using javascript. But the point is to do this via events only, because that's one of the main things in Construct. So here's the task:

    1. Have an object

    2. This object should get destroyed whenever it overlaps with something that's "spiky"

    3. "Spiky" objects can be pretty much anything, be it Sprites, 9-patch, tiled backgrounds, maybe even a specific tile in a tilemap

    Seems deceptively simple, but how do you actually define "spiky" objects? Instance variable perhaps? That means I will need an "on collision with familyA OR familyB OR familyC OR..." for each type of family. Super annoying to work with, should be easier imo.

    In javascript I'd subclass all my objects, so it's pretty easy to just add a property "this.spiky = true", then gather all relevant instances and execute a testOverlap() on them. Done, maybe I need some extra handling for the tilemap part at worst.

    	const instances = [array of instances I wanna check for overlap];
    	const spiky = instances.filter(obj => obj.spiky === true);
    
    	for(const i of spiky) {
    		if(this.testOverlap(i)) {
    			this.destroy();
    			break;
    		} 
    	}
    

    I think the key here is the fact that the collection of instances can simply be a wild mix of any type of instances. The filter function doesn't care, neither does testOverlap().

    Any idea on how or even if it's possible to replicate that in events with the same effectiveness?

  • I’d just make an invisible spikySprite that would be created over anything you want to be spiky. Placing them over all the relevant objects is pretty straightforward with events. And you could use pin or something to attach it to moving objects.

  • Heh, I just had an epiphany. See, I'd have argued that this can be also quite annoying to deal with. It does work well with hierarchies/templates, but what if I don't need a rectangular hitbox. What if it's a single big spike and I need it triangle-shaped? My first thought was I'd need to create specific collision polygons for every differently shaped object... but there's a feature that I tend to overlook a bit. Meshes! Meshes solve that quite elegantly. And one obvious benefit is that I can also make an enemy only partially spiky simply by adjusting that sprite, which I would have to solve this way anyway even with javascript.

    Only downside I see with this approach is the lack of a simple catch-all. I don't think spawing in the spiky sprites via events is ideal and hierarchies can be a little bit annoying to deal with (although it's gotten better over time), and some objects (let's say a static sprite) would be so simple to solve by just saying "you're spiky now" as opposed to creating hierarchy, template, placing replicas, having to remember to update the replicas across all layouts when I make changes,... And the mesh could also be somewhat annoying to set up in some cases at least, for example with a round sprite it's quite easy to just press "guess collision polygon" and be done with it, but adjusting the mesh nicely to that...

    Tilemaps are also a bit tricky in that regard I think. I can't really just create the spiky sprites if I have differently shaped spikes, at least not without some extra work to make a specific template for the specific tiles. Or I make an extra tilemap that is only spikes, but that then again would require me to do an extra "or on collision with tilemap" which kinda defeats the purpose.

    But I suppose this is still the ideal solution.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It comes down to there is no perfect solution. You have to deal with some complexity somewhere.

  • Oh absolutely. I just wanna make sure that I'm not making something more complex than it needs to be. I hate being in the middle of a project and realizing that I could have done some things much easier + my code tends to spaghettify anyway and it's harder to maintain. So I kinda started to look for the most simple and effective solutions I could possibly think of so I don't get frustrated when the code is a maintenance nightmare. It's hard enough as is :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)