In the third section we will make the monsters drop equipment or loot
Give the equipment a chance to have bonuses
Make the bonuses increase as your level increases
Create Randomly Generated Rooms
Add Dialog system
Create Opening scene
Make a NPC that can enchant your equipment to give it more powerful bonuses
Boss Room design
Spelunky
Step
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
33a
33b
34
35
C
36
37
Directions
Change loot drop script to add equipment to drops
Create a new script and call it scr_lootDrop() drop script
We also need to set up a new global variable called global.lastmonster so open the obj_variables objects and add global.lastmonster = noone; This will keep track of the last monster you killed so we can id it as the monster
This script is long so I will show it to you in two parts
This script will also call another script called scr_chance which will check the chance of something happening call this script scr_chance()
Picture
Part 1
Part 2
Monster Destroy Event
Open you obj_monster the parent monster object
Add a Destroy Event and call the script scr_lootDrop() script
It will pass one argument the level of the monster that way the drops will be better based upon the monsters level
Challenges
When you pick up gold loot it doesnt add to your gold fix this
The avatar in your gui that shows what items are equipped does not have the glow draw on them fix this
Your inventory does not show glow fix this
Add Sound effects for the following:
Coin pick up
Hit, miss and critical all different sounds.
Death
Background music
Make Monsters get harder based on your level
We want the game to get harder the higher your level gets
We will use a script from GML scripts to accomplish this
http://www.gmlscripts.com/script/exp_dist
Randomly Generated Rooms
One of the concepts of a rogue like game is randomly generated levels so we will tackle that now
I will show you how to use the work of another coder and integrate it into your game.
We will use this https://marketplace.yoyogames.com/assets/489/grid-shadow-casting
Download the file here
https://drive.google.com/file/d/1CEguYbEd7JRCqeOvvl2EaE20F9prg9sk/view?usp=sharing
Open the file and play the game check out how it works
Make sure you save the Grid Shadow Project so you can import its assets in the next step
Add Scripts to your Game
You can add the assets from this game to your game without having to re-type the code
Open your game in another instance of Game Maker Studio
Now right click on the scripts folder and select "Add Existing Script"
Four new scripts added to your game
Browse to the Grid Shadow Project folder usually found in C:/My documents / Game Maker / Projects Folder Open the Scripts folder and select all the scripts Press Open
This will import all the scripts into your game sometimes you have to add a comment to the script to make your game recognize the script
Add other Resourced to you Game
We now need to add the other assets to your game from the Grid Shadow game
You will need the following added to your game:
Sprites
spr_black
spr_light
Backgrounds
bck_01
objects
obj_createRoom
obj_camera
obj_torch
Add these in the same way as the scripts
Create a New Room that will be randomly Generated
Create a room called room_random place this second after your roomSplash
Add two objects to your room_random
obj_createRoom and your obj_player
It doesn't matter where you put either of these objects
You will need to center your player sprite
Make Changes to new assets
You need to make sure that the new assets will work with your game so lets go over each asset :
Room Size Make sure your game room size is a multiple of 32 mine is 1024 x 768 so it will work great 1000 x 750 wont work so adjust it if needed
Player Name needs to be obj_player or you need to change it in obj_camera and obj_createRoom
Torch Range obj_torch has a variable called Range this is how far the light travels in the grid change this if you want
Player object Changes Create Event
This is where most of the changes take place first go to the Create event of your obj_player in your rogue game and compare it the the obj_player in the Grid Shadow game
Copy all the variables from the Grid shadow player to your players create event
Just like the torch object the Range variable is how far you player can see with light I changed mine to 4
Also change the depth of your player to -50
Player object Changes to the Step Event
Compare the step events of the player objects
You will notice the the shadow grid movement checks for the x and y position before you move then if you have moved during that step it will update the grid to illuminate grids around your player based on the range variable
Your Step event will now look like this
playerMove script Changes
You noticed that the movement in the player in the Grid Shadow game do not use collision detection but grid placement
So if a floor tile is in the grid you are trying to move to it is allowed however if a wall is in the grid you cannot move
So we will have to change our check to add the grid check as well as the place_free check
if place_free(x+xoff,y+yoff)
to the new grid check
if(ds_grid_get(global.mygrid, (x+xoff) div 32, (y+yoff) div 32) == 1)
We will have to change for all 8 keypress directions
Test your Game
You should be able to move and stop when you come walls
The areas you have visited before should be semi-grey the unexplored areas are blacked out
If you want the grey to to lighter or darker change the variable Shadow = 0.85; found in the Create Event of obj_main
You can also change the view of your room to make your game looked zoomed in
Go to the room_random and click on the views tab
A safe way is to cut the room size in half for both port and view like this:
Create Event obj_player
Remember to tick Enable the use of Views and visible when room starts
And make the view follow you player
Add Items to your room
Now we have to figure out a way to add items to your room
The room is made up of tiles which are marked on the grid with a 0 or 1
0 = Wall. You cannot walk on that one
1 = floor. You can walk on that one.
So we can only place items like loot monsters traps etc on items marked as 1
This graphic shows what your room looks like numerically so we will cycle through all grid positions in the room and place items randomly only if it is on a position marked 1
Create the Scatter script
Now that we understand how the room was created we can create the script
Create a script called scr_scatter_instance
It will have two arguments
the type of item to scatter and the number of items to scatter
We will be able to use this script to create loot, monsters or anything else we want.
It will only create an item when it finds a floor tile that doesn't contains another object
Call the Script
Now to call the script go to the obj_createRoom
Add a new code box and run the script we will create 10 loot objects
Test it out
Everything should work good you should be able to collect the loot and none of the loot should be inside of a wall
Scatter Monsters
Now lets scatter some monsters everything is already set up to to this just run the scatter script again and pass the correct arguments
We only want to scatter items if we are in the random room
Test it out
Oops something is wrong... The monsters can walk through walls and you can walk through them as well
Fix Monsters walking through walls
Remember our room doesn't contain wall objects only a grid with tiles of walls or floors
We will use the same check we used in our players object to check if the grid space is a wall or floor in the monMove script
You will need to change the x y offsets or add a xoff and yoff variable to your monster just like we did with the player
Test it the monster can now only move on floor tiles
Make player not be able to walk through monsters
The other problem is walking through the monsters
So we need to add back the check for place free since the monsters are marked as solid
Before we move two things must be checked:
Chase State of monMove script
Wander State of monMove script
If the tile is a floor or wall
If a solid object is in our path
If the tile is a floor and nothing solid is in our way we can move so add back the place free to the playerMove script
Fix monsters from stacking on top of each other
You may have also noticed that monsters can walk on top of each other as well this is for the same reason as the player so add back to place_free check to the monMove script
I am also going to add the xoff and yoff variables to the monster
This will make it faster to change the script
Design Document Re Look
Books are written with stages your game should follow this basic outline
Think about games and how this pattern is followed
obj_monster Create Event
Add rooms after splash room cut scenes that shows your player in the ordinary world
Then show the players call to adventure
Then show his refusal
Then show mentor helper
Update Splash Room
Lets add a options for controls and a background
Make Two buttons one that says start one that says controls
I buttonized mine
Now create objects for each button
Add Buttons to room
Add the buttons to the room
Add Create Event to control button and add a variable hoover = false; and pressed = false;
Add a Mouse Enter Event set hoover = true;
Add a Mouse Leave Event set hoover = false;
Add a Draw Event draw_sprite(sprite_index,hoover,x,y);
Make the start button a child of the control button
Test it out the buttons should change when mouse hoovers over them
Make Start button Start Game
Add a Mouse Left Released Event
Make Controls Button display controls
When you press this button we want a box to pop up that shows all the controls of the game
Modify the text for your controls
Draw Event obj_controlsButton
Room Background
Take a screen shot of your game play to use as a background for your splash room
Add it as a background then go to your room and select it as your room background
Create Cut Scene room
Create a new room called room_intro
This room will show the "Call to Adventure" in 5 parts
Backstory dialog
Ordinary World
Call to Adventure
Refusal
Consequences
Create Event
Backstory Dialog
You need to write a backstory about your character We will display this in scrolling text
Create a new object and call it obj_backstory
This object will move as it draws the text creating the scrolling text effect.
The variable backstory will contain all the text for your backstory so it will be very long.
Draw Event
Background Backstory and Player representation
Draw or find a background sprite I used mountains create it as a sprite
You need to be creative and draw upon your video game knowledge to create this page
I made an object that represents my character follow a path to add a mini animation while the dialog is scrolling.
Make three objects
obj_josh your player representation
obj_mountains the background image
obj_backstory the scrolling text
Now set the depth
0 for backstory
-1 for mountains
-2 for player
Place the mountain object and the player object into your room_intro also place the backstory object near the bottom left corner of the room
This will make the objects stack correctly
obj_josh
The representative of your player is what you player looked like in the normal world
We will make him follow a path.
Paths are great ways to make cutscenes
Click on path and add a new one call path_josh
Now click on <select room background>
Uncheck Closed so the path is one way
Click near the player to start the path now each time you click you give another way point for the player to follow You can either choose Smooth Curve or Straight lines
Add a create event to Josh then start the path
Transition Object
A nice effect for cut scenes is a transition object that will fade to black them fade back to normal
This is easy to make create a new object and call it obj_transition
This objects depth should be -4
Timelines
Timelines are another method that can be used to make them happen at certain moments in the game
To be able to tell what moment your game is in we will draw the moment using the a new object called obj_timeline give this a depth of -3
This will serve as our time keeper of events in our cut-scene
Watch the moment to determine when you want the fade transition to start mine starts at 1500
You want the opening backstory to play then fade to black and come back up with the cutscene
Which will show dialog of you player with a a NPC that "Calls you to Adventure"
Then You refuse the "Call"
Then You get "Mentor Help"
Then you "Cross the Threshold" into the dungeons
Create Event
Step Event
Draw Event
Create
Step
Draw_GUI
Create Timeline
Create a new timeline and name it tl_intro
Add a moment at the time when your text is done the create an instance of the obj_transition
Now figure out the moment when the screen is completely black it should be 150 more
Destroy the following objects: obj_josh, obj_mountains, obj_backstory and obj_crowd
Moment 1500
Moment 1650
Dialog Object
We need to create a dialog system so we can talk with NPC this will be used later when we talk to other NPC in the game
To do this we will follow the video of instructions here:
https://www.youtube.com/watch?v=HdJ0ZUIs-AI
This will allow us to use the dialog system where every we want.
Dialog Object upgrade
I added some code to my obj_text to make it fade out the destroy itself
Create Event
add a variable fadeout = false;
Alarm[0]
fadeout = true;
Alarm[1]
instance_destroy()'
Draw Event
Script Upgrade
Now we want to add to the scr_text so that the text will fade out so we will set up an alarm
Text Object fade Out
You will notice that the obj_text which you just made with help from the video does not disappear. So we have to make it fade out then be destroyed.
Compare your code with mine and make the adjustments
Call to Adventure
Now that we can create dialog anytime we want lets create a back and forth dialog scene using the timeline and the dialog script
First create an object called obj_theCall
Create dialog using an array make the dialog go back and forth between the player and the Call to Adventure NPC
Continue to add moments in the timeline and just change to coordinates and the DIALOG[number]
Challenge Create Character Skills
Study this page to determine what skills you want your character to have
Now Play this game and chart how each skill increases
Write down notes on what you find out
Draw out how you will display the skills on the GUI
Develop a flow chart on how you will code this to happen
You must have the following:
Create
Alarm0
Alarm1
Draw Text 2
Create Event of obj_the Call
Draw Event
Add Moments to Timeline
3 or more skills
Skills must be visually show increases in the skills
The skills must improve your player
Weapon Proficiency
Lets add another way to upgrade your weapon called proficiency this means every-time you kill a monster you get better with that weapon
First create some global variables to keep track of your proficiency with each type of weapon
Next lets add this bonus to your attack damage so go to your damageRoll script and multiply your bonus by the damage
Now we need to make the proficiency increase each time you make a kill your experience scripts runs each time you make a kill so that would be a good place to add to your proficiency
Next we want a indicator showing how many more kills you need to upgrade the proficiency with that weapon
This is how I would start now your turn to develop and code this into being
We also need to populate your equipment grid with -1 values so that no weapons are thought to be equipped
I moved the gems to the right to make room for the skills
adjust yours as necessary
Ranged Attack
You may have noticed we can equip a ranged weapon but we cannot fire it lets make that happen
We need to figure out several things:
obj_variables
attMonster script
damageRoll script
scr_skillsExp
obj_gui
Get Input change
Determine what button to press to fire ranged weapon
I will Press U
Determine how to target the enemy
I will target nearest enemy
Determine visual of firing weapon
I will create a ranged ammo sprite that matches ranged weapons
playerMove script add this at the top of the script
38
39
40
41
42
43
44
45
46
47
Ranged Weapon Ammo Sprite
My ammo sprite matches the ranged weapon sprite
Ammo Object
Create a new object called obj_rangedAmmo
You also need to add two events to destroy the ammo
Outside Room and Outside View
Both need instance_destroy(); in them
Create Event
Draw Event
Add Collision Event to Monster
We are using a new variable in the monster object called target
In the create event of the monster add
target=false;
nearestEnemy script
We need to write a script the will find the nearest enemy and shoot toward that position
attMonsterRanged
When ammo hits a monster it needs to damage the monster
Collision with obj_rangedAmmo
Ranged Weapon Skill
We have skills for melee weapons now lets add for ranged weapons
Add global variables for to keep track of these skills
Draw New Skill On GUI
Add this under your other skills you may have to adjust
The draw locations to make it look correct
Add Skill Exp with Ranged Weapon
This is similar to melee weapon
First we need to add to the attMonsterRanged script
scr_RanskillsExp
You notice we have a new script
We could have redonet the scr_skillExp script to pass more arguments to it in this case I just make a new script and change it slightly
In part 4 we will have boss rooms
Enchant equipment with gems and more
Create Event of obj_variables