Blocks, gravity, and suspended objects

This forum is currently in read-only mode.
From the Asset Store
Gravity Square is a game where I aim to reach the square at the polka dot door :)
  • Using only 4 events!

    What it does

    If you run the cap it should be pretty self explainator what the engine does.

    I got the idea from a game called 'Cactus Bruce and the Corporate Monkeys', when I noticed the bricks the monkeys stand on are able to suspend themselves in the air, but the lighter coloured bricks do not. While the object of the game was to destroy all the bricks, you could save yourself time by destroying the bricks which suspended themselves in the air, causing the lighter coloured bricks which were affected by gravity to fall into the ocean (and thus be destroyed)

    Anyway I created a similar kind of falling engine where falling dirt can land on the magic golden capsules and will remain there until either the capsule is destroyed. Likewise, ground holds up other ground, and if theres no connection to a piece of ground that is suspended by a capsule, the ground falls.

    Theory to how such an engine works

    To put it simply, a piece of ground will fall unless a piece of ground which its overlapping isn't falling, or it is overlapping a capsule.

    To create this in the simpilist and easiest way, we use a variable 'canFall' which indicates to the objects if they might fall or not. It is assumed everything will fall until proven otherwise. First off we tell the capsules they cant fall. Next, its just a simple case of looping every object and checking to see if it is overlapping any other objects which cant fall.

    How it works

    We place all the objects into 2 families: red and green, so that we can take advantage of how Construct handles individual Selected Object Lists for each family.

    If we loop each Red, we can then test if Red overlaps Green. Even though Red and Green are infact refering to the same collection of objects, the objects selected are different, and so testing for an overlap between red and green will infact check for an overlap between the selected red and all the other objects on the layout.

    After the overlap condition, Green now represents (if any) all the surrounding objects to the one in question (red). Finally we check to see if any of them wont fall. If the condition proves true, we can tell the object in question (red) that it also wont fall.

    This leads to a problem though. An object wont know if it cant fall unless the object sounding it also knows at that particular time that it cant fall...and its possible that object will be further down the list and therefore wont know yet. As a quick fix to this, I made the event repeat itself for Red.Count. This is NOT the most efficient way, but it does solve the problem for now.

    In Conclusion

    I think this once again demonstrates the power behind constructs event system, and perhaps provides a little more information about how families and stuff work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the example! I think I understand how to achieve a loop without Sub-Events now too

  • Yeah, the recent versions of construct also indent conditions below loops so they are easier to read

    Also its still good practise to use sub events, i just thought it was awesome to make this in only 4 events

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