Rogue Like Random Maze Tutorial pt2: limiting your visible area

4

Attached Files

The following files have been attached to this tutorial:

.capx

rogueliketutorial.capx

Download now 205.25 KB

Stats

4,511 visits, 6,644 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 15 Sep, 2015. Last updated 19 Feb, 2019

HOW TO LIMIT YOUR VISIBLE AREA

This is a continuation of This tutorial where we made the random "dungeon" maze used in this demo.

Like Rogue, or other Rogue-Like games, we want to "light up" only what the player object could see from its vantage point.

What the player object "sees"

Instead of showing the whole maze:

You only get to see the room or hallway you're in...

which is much more "dungeoney."

Adding an element of suspense and mystery... and stuff.

STEP 1 ADD THE DARKNESS!

Add a layer just under the HUD layer (second to the top) called "darkness"

As the name implies, make the layer pitch black and non transparent. This will completely obscure the layers beneath it. If you leave it like that, the game will be 100% mystery!

...But not all that playable.

So you'll have to light it up!

Make a "light" object on the "darkness" layer.

Add a sprite make it 128x128 pixels and look like this:

White, kinda square ish but not filling up the whole square, with some soft edges. Feel free to be creative...

Now set the Blend mode to "Destination out" This will illuminate the darkness and reveal what's underneath to the degree of how bright the light object is.

Also set the intitial visibility of the light object to "invisible." We'll be making the object visible and invisible as the player moves around....

AHEM... OH YEAH.... THE PLAYER

I guess we're going to need a player object to move around with!

The "player" object I'm using is actually a character from the public domain 32x32 dungeon tileset here.

To help with the quazi sort of 3D ish effect, make the collision box of your game characters only go up to about half way up the character's body. That way they will appear to walk "in front of" the brick walls like so:

Give the player 8-directional movement behavior, and make sure you say "no" to the "set angle" property. Give it a good "dungeon crawling" Max Speed of around 60.

You can safely place the player anywhere inside the edge of the dungeion on every odd open square.

Be sure to start your player on the edge in one of the odd open squares like shown above. even squares might be occupied by a wall, and inner squares might be boxed in. But the maze gaurantees that you can get to any edge from any other edge, so as long as you put your player or any "must get to" things in odd squares along any edge, you're OK!

Now if you want to have items like stairs down, or treasure or player start or something in the middle, you need to add some more wall destroying events after your dungeon is made to make sure you can get to them.

By the way... don't forget to give your walls the "solid" behavior!

OK SO NOW WE HAVE A PLAYER... AND A LIGHT. LET'S ADD THE LIGHTS!

In the MakeDungeon function before we do the dungeon making, we have an event where we destroy all the walls, if there are any. We should destroy the lights too. So let's do that. Put this right inside the beginning of the MakeDungeon function:

Before or after you make the random walls, you're going to make lights on every EVEN square. Remember we made walls on every ODD square. This way we're lighting the passageways and parts of the walls, rather than just the walls.

Now your dungeon is full of invisible lights.... and still totally dark --cause they're invisible!

NOW MAKE THE LIGHTS WORK

We want the lights to turn on and off depending on what the player can see... so we need to add the line of sight behavior to the player. The regular default settings are fine.

Now somewhere outside your functions, add this event:

A word on Line of Sight.. It's slow as heck. For a large dungeon with lots of area full of light objects all checking for line of sight... it will destroy your FPS.

The distance function however, is fast and furious. Apparently Construct 2 can do distance all day long, so I limit my LOS calculations to only lights within 200 pixels.

And it seems to work. As with before here's a link to the capx. Thanks for reading and enjoy! Feel free to put any part of this in your own game!

.CAPX

rogueliketutorial.capx

Download now 205.25 KB
  • 0 Comments

Want to leave a comment? Login or Register an account!