Step
1
2
3
4
5
6
7
8
Directions
Torch lighting system
Some of our rooms will be deep in dungeons, caves or in the dead on night.
To make the ambiance effect I will introduce you to surfaces
Surfaces are like a canvas that we can draw on that will overlay the regular drawing surface.
Create an object called obj_lighting
Add a Create Event
The code will set up the surface and give it the name light we made it global so that many objects can use the surface
Add a Draw Event
This will blend the surface by subtracting from base color c_white
Add a Draw Begin Event
We set the surface target to light and select the color c_white if you use c_ltgray the room will be partially light while c_white will make the room totally dark
Place this object in the room you want to have the lighting effect
Picture
Create Event
Draw Event
Draw Begin
Give your Player a Torch
Now we want our player to have a torch light effect
Open the Draw Event of your player
The size variable is used to control the size of the light effect you can adjust to whatever size you like
Make Torch Object
Create a torch sprite and make an object for it call it obj_torch this will be used to give your room ambient light we will also make a sprite that will have the torch out and when the player collides with the torch it will be lit
So create a lit torch sprite and a un-lit torch sprite
Add Create Event to the torch and add variable lighted = false;
Add a Collision Event with the player and add Code to change lighted to true and change the sprite to the lit sprite
Add a Draw Event
The Draw event is almost the same as the player except we check if it is lit
Collision Event
Draw Event
Random Level Generation
Lets begin the random level generation process. We will use a ds_grid to create the room. The room will be created with tiles so no objects will be used.
Then we will autotile the room to make it look awesome.
Then we will make your character and the monsters not be able to walk through walls without having any objects in your room.
In this section we will use a video tutorial and follow the instructions for heartbeast to create this effect.
Heartbeast Video series
https://www.youtube.com/watch?v=TZtMNnXFnHE
Create a new room and put it second after your splash room only put the obj_level in the room dont put in turn controller,. gui, player or any other object. We will make the obj_level create all these objects.
reference
http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_generation
https://eskerda.com/bsp-dungeon-generation/
https://www.youtube.com/watch?v=TZtMNnXFnHE
Random Level Generation Options
We need to make a few adjustments to make the random level generation work with our game.
We need to create the player and the turn controller in the obj_level
After we declare the controller variables cx and cy we will create these two objects. The player will be created at the starting position of the room creator
Spawn Enemies in Randomly Generated Rooms
Spawn enemies in the room is easy open the obj_level and find the section were we draw the floor tiles.
Since we are adding floor tiles it is a good place to add monsters other wise the monsters might be spawned inside walls or in void areas.
First we set a variable called odds 10 means a 1 in 10 chance 20 means a 1 in 20 chance
We then get the location of the floor tile in the loop
We dont want monsters to spawn right next to the player so we check a distance and only allow monsters to spawn if they are 200 pixels away from player
Next we set up a varibale called monType that will choose what kind of monster to spawn
Then we create the monster
To make all object go behind the walls you need to add depth = -y; to the step event of each object other wise at the top of the room some object may appear above the wall.
Spawn Loot, Torches etc
We can spawn other items in a similar way
Just add this code under the spawn monsters code
Different Walls
We can make the rooms look different by changing the bg_walltiles background
And adding a choose() function to the obj_level object
Each sprite is identical in its shape, size and position but the colors have been changed.
In the part 4 section add a variable called tileset that will choose between the three or more tilesets you make for your walls. It then puts the name in the variable tileset and uses that tileset to draw the walls so everyspot in the code that had bg_walltiles is replaced by tileset.