In section I will add extra things that you can add to your game if you want.
Make a request if there is something that you would like to do and I will add it to this page.
Many of the items on this page a tied to parts 1-3 like the completion of the quest.
STEP 1
The Gate Object
When you enter the boss lair you will be trapped inside and must defeat the boss to escape.
So when you get close enough to the boss it will trigger a trap that will lock you inside with no way out. Find a sprite for a gate or door that will shut when you get inside. I used this one. I erased part of the gate to make it open. You will need both sprites to make it work. In the Create Event add this code to set the sprite to open.
In the Draw Event of the Gate add this code to draw the correct sprite.
Make oBock the parent of the gate so you can walk on it. Place the gate in your room so you can walk into the boss lair.
Create Event of oGate
sprite_index=sGateOpen;
Draw Event for oGate
draw_sprite(sprite_index,-1,x,y)
STEP 2
The Gate Object code
We will put the code to change to gate to closed in the boss object.
Go to the step event and place this at the top replacing lines 1-7 with the new code.
You will notice that we will play two sounds as well.
Gate slamming sound
Evil laugh
Sound effects add to the game play experience so use them.
Since the gate is a child of the block you wont be able to walk through it when it slams shut.
step event in boss object
if distance_to_object(oPerson) < 300 && state==idle // checks if your character is within range of the boss monster to start the battle
{
sound_play(snd_gate);
sound_play(snd_laugh);
oGate.sprite_index=sGateClosed;
state=getbow;
}
STEP 3 Boss Lair Design
We want the boss lair to be cool looking so we want to design it carefully with different ways to defeat the boss. We already added the gate to lock you in but some other ideas could be.
Breakable object
Falling object
Traps
Push-able blocks
Lets make the falling object. Notice that the chain link looks rusty.
STEP 4
Boss Lair Pipe Object
Find a sprite for an object that can fall, I used the pipe. Make the pipe objects parent the block so you can walk on it and add this code to a Collision Event with the Block.
This code will detect if the pipe if moving if it is it will stop it, play a crash sound and destroy the falling chain object.
I also made the depth of this object 1 so that the fire trap is in front of the pipe.
Collision Event with the Block in oPipe
if vspeed>0
sound_play(snd_pipecrash);
vspeed=0;
with oChainBot
instance_destroy();
STEP 5
Boss Lair Chain Object
Find a sprite for a chain or rope that can be broken with your sword or arrow. Then you will need to modify the sprite into two different parts a top and a bottom. Here are the three sprites I used.
Notice that I changed to color of one of the links this will be the weak link that can be destroyed.
You need to make objects for all three of these sprites.
STEP 6
Chain Object
Add a collision event with the arrow and the sword object add the following code.
The code will destroy the chain object and create a top chain that doesn't move and a bottom chain that falls with the pipe.
It also plays a sound.
collision events for arrow and sword
sound_play(snd_chainbreak);
instance_destroy();
instance_create(x,y,oChaintop);
instance_create(x,y,oChainbot);
STEP 7
Falling Chain Object
The falling chain object is your oChainbot.
This object will fall down make the pipe start to fall.
Notice the "with oPipe" construction
this type of code cause that pipe to start moving down.
This is how you can control objects with other objects.
Create Event of oChainbot
vspeed=9;
with oPipe
{
vspeed=9;
}
STEP 8
Boss Drops Wand
Now we will work on using a third attack which will be a wand that will drop from the boss when you defeat him. This is our first upgrade so with that comes some nice additions to the game
We will make the wand object I used this sprite
Call this obj_wand
We want the boss to drop it when he dies so add the following code to both the arrow and sword collision events in your boss
You could also make the boss drop a key to unlock the way to the princess.
Collision Events of sword and arrow in the Boss object
with other
instance_destroy();
hpamount-=30;
if hpamount<0
{
instance_destroy();
score+=points;
instance_create(x,y,oWand); // Create the wand object
}
STEP 9
Wand Object
Now we will add the code for the wand object.
We want it to drop to the ground when it is created and have a message stored in the create event.
Notice that the variable message has text stored in it instead of a number.
The step event just makes the wand fall to the ground.
Create Event of obj_wand
///Initialize Variables
grav = 0.2;
vsp = 0;
message="This is a Wand of Fire. It uses Energy talk to the Princess to find out how to use this skill.";
Step Event of obj_wand
//Set speed
vsp += grav;
//Vertical Collision
if (place_meeting(x,y+vsp,oBlock))
{
while(!place_meeting(x,y+sign(vsp),oBlock))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
STEP 10
Get the Wand Attack
Now that we see the boss drop the wand we want to pick it up so we can use it.
We will also display a message giving us information about the wand.
So we must add a few variables to the create event of your player
Don't remove the old variables just add the new ones
this third weapon variable holds a string or words instead of a number
Change your Step Event code line 7 the weaponselect now must have 3 choices so toggling doesn't work anymore we add one to your weaponselect then check to see if we are greater than total weapons if so reset to weapon 0.
We also need to be able to shoot wand when we learn the skill so we have to add some code for that. Under your sword attack code place the third bit of code.
Also we have to change some of the other code since we have a new state called attackwand we have the check if your NOT in a state of attackwand to go into an idle state.
The last item is to draw a sprite for the wand attack I used this one:
Create Event of your player
wepselect=0; // 0 for sword 1 for bow 2 for wand
//Weapons
havewand=0;
sword=0;
bow=1;
wand=2;
weapon=sword;
thirdweapon="Unknown";
energymax=100;
energyamount=0;
energycost=10;
energyfactor=1;
useenergy=0;
Step Event of your character
// Changes the weapon from sword 0 to bow 1 to wand 2
if wepselect == 1
weapon+=1;
if weapon>2
weapon=0;
//fireball attack
if canattack==1 && weapon==wand && havewand==1 // You must press the attack button
{
if energyamount>energycost*energyfactor
state=attackwand;
}
// set state to idle if not attacking and not moving
if move==0 && !state==attacksword && !state==attackbow && !state==attackwand
state=idle
case attackwand:
sprite_index=sWandAttack;
image_xscale = facing;
break;
STEP 11
Fireball Object
Now we need to make a fireball object just like our arrow object but with a fireball sprite
I used the above sprite
Center this sprite and create an Object for it called oFireball
Add a create event to get it moving and a outside view[0] Event to destroy it that way you can shoot outside of your view.
Remember your view is what you can currently see in the room.
Create Event of oFireball
//Create Event Code
hspeed=oPerson.facing*15
image_xscale = oPerson.facing;
Outside View Event of oFireball
instance_destroy();
STEP 12
Create Fireball
Now we want to make a fireball just like the arrow so we will do it in the Animation End event add this to the switch statement in the animation end.
To make the fireball damage enemies just make its parent the arrow
Animation End event of your character
case attackwand:
instance_create(x,y,oFireball);
sound_play(snd_bossBow);
energyamount-=energycost*energyfactor;
break;
STEP 13
Princess Area
After we defeat the boss the next area of our room will contain the Princess that we will talk to so the energy skill can be learned.
Create an area after the boss that will have the princess. This area should look like a throne room. I put loots of tiles in this room to make it look elaborate.
STEP 14
Princess Draw Event
To give a good visual effect we want the Princess to look powerful so we will add an aura around her we also want a magical looks effect appear when she teaches you how to use energy. I used the sprites above
Find two sprites and center the origins.
The draw event will checks if your state is spell if it is it slows down the image speed to .2, draws the energy on the player and on the princess and sets your players energy amount to 100.
Then it sets image speed back to normal and draws the Princess and the aura.
Now we have to end the state of spell somehow we will use the animation end event to do this code to go back to a state of talk
state=talk;
Princess Draw Event
if state==spell
{
image_speed=.05;
draw_sprite(sPrincessSpell,-1,x,y);
draw_sprite(sEnergy,-1,x,y);
draw_sprite(sEnergy,-1,oPerson.x,oPerson.y);
oPerson.energyamount=oPerson.energymax;
oPerson.useenergy=1;
sound_play(snd_magic);
}
if state==talk
{
image_speed=1;
draw_sprite(sPrincessIdle,-1,x,y);
draw_sprite(sAura,-1,x,y);
}
STEP 15
Health and Energy Regeneration
You will notice that after you fire your wand you lose energy and when it gets too low you can shoot anymore. Your health also decreases.
We will add a slow regeneration code.
Put this code in the step event of your character under your weapon select code.
STEP Event of your character
if energyamount < energymax
energyamount += .1;
if global.hpamount < global.hpmax
global.hpamount += .1;
STEP 16
Boss Monster
Now it is time to create your Boss.
This will be the ultimate enemy. This enemy will move, have health and fight back with both projectiles and a super attack.
To make your boss look good you will need the following sprites walking sprite, melee attacking sprite, ranged attacking sprite and idle sprite.
We will use states just like your character to change the sprite.
I have my sprites shown to the left.
You could also make your boss go into other states like falling down, dancing, etc.
This is a good time to make a diagram of what your boss will do this makes it much easier to code if you have thought through the plan ahead of time.
here is a link to a document you can use as an example.
https://docs.google.com/document/d/1jWnv39Z7o5JhxptVn5u9IkU8DMYljaUyOEM7MtUM3aI/edit?usp=sharing
You will also need to make two weapon object that the boss will get. These will be placed in the room and will have no code.
So I made a bow and a trident.
Walking
Melee Attack
Ranged Attack
STEP 17
Boss Monster Create Event
In the create event we will initialize all the variables we will use for our boss.
These will look familiar since we have used them in your character. The code can be used over and over again.
Create Event
///Initialize Variables
image_speed=.5; // changes the image speed to slow down animation to 1/2 speed you may not need this
dir = 0;
movespeed = 3;
jumpspeed = 25; // this is higher because I made gravity higher
movefactor=1;
grav = 1; // gravity is higher so he will fall quicker
hsp = 0;
vsp = 0;
jump=0;
hpmax=100;
hpamount=hpmax;
points=10000;
can_attack=0;
alarm[0]=60; // attack alarm
// All the states the boss can be in
idle=0;
laugh=1;
getbow=2
attackbow=3;
superjump=4;
gettrident=5;
walktrident=6;
attacktrident=7;
state=0; // sets the state to idle
STEP 18
Boss Monster Alarm Event
The Boss needs to be able to attack, We use an alarm event to make him attack every 3 seconds.
Add alarm[0] event and put the following code to make the can_attack variable trigger every 3 seconds
Remember 30 steps is equal to one second.
Alarm[0] Event
can_attack=1;
alarm[0]=90;
STEP 19
Boss Monster Step Event
The step event uses much of the same code as other enemies but it also adds states like your player.
Since we want the boss to perform a series of events based on the players position, amount of hit points we must add some extra code to make all this happen.
Boss Monster Step Event Lines 1-7
Code Breakdown. To make the boss perform the desired actions we must have conditions that can be checked. If the conditions are met then the boss will go to a certain state.
The boss starts in an idle state which means he just stands and does nothing he is waiting for you to get close enough.
We check two things distance to person and if boss is idle. Both of these conditions must be true for the code to run.
If the two are true we set the state to getbow we will discuss what that does latter.
Boss Monster Step Event Lines 8-12
After the Boss has got the bow he is in a state of attackbow. However in our plan we want the boss to switch to a trident when is health goes below 50%.
So we check if we are in a state of attackbow and hpamount < 50
The && means and in programming.
If these two conditions are met we go to a state of gettrident
Boss Monster Step Event Lines 14-17
We want the boss to have AI (artificial intelligence) attacking. This means he will only attack you if you are within range of his trident otherwise he will patrol back and forth.
Three conditions must be met for this to take place.
distance to person is less than 200 pixels
state must be walktrident
can_attack = 1
If these three conditions are met he goes into a state of attacktrident
Lines 19-75 have been explained earlier so we will move on to new stuff.
BOSS STEP EVENT
// checks if your character is within range of the boss monster
if distance_to_object(oPerson) < 300 && state==idle
{
state=getbow;
}
//if HP of boss falls below 50 change to trident attack
if state==attackbow && hpamount<50
{
image_speed=1;
state=gettrident;
}
// checks if your character is within range for trident attack
if distance_to_object(oPerson) < 200 && state==walktrident && can_attack=1
{
state=attacktrident;
}
// checks if your character is within range for trident attack
if distance_to_object(oPerson) < 200 && state==walktrident && can_attack=1
{
state=attacktrident;
}
hsp = dir * movespeed * movefactor;
vsp += grav;
//Jumping
if (vsp < 10) vsp += grav;
if (place_meeting(x,y+1,oBlock))
{
vsp = jump * -jumpspeed
jump=0
}
//Horizontal Collision
if (place_meeting(x+hsp,y,oBlock))
{
while(!place_meeting(x+sign(hsp),y,oBlock))
{
x += sign(hsp);
}
hsp = 0;
dir *= -1;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,oBlock))
{
while(!place_meeting(x,y+sign(vsp),oBlock))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Enemy Collision
if (place_meeting(x,y,oPerson))
{
if (oPerson.y < y-16)
{
with (oPerson) vsp = -jumpspeed;
hpamount-=5;
}
else // Bounce back effect if hit without attacking
{
oPerson.hpamount-=1;
if oPerson.x > x
{
if place_empty(x-32,y)
x-=32;
}
if oPerson.x < x
{
if place_empty(x+32,y)
x+=32;
}
}
}
// animate character
switch state
{
case idle:
sprite_index=sKnightIdle;
break;
case getbow:
sprite_index=sKnightWalk;
dir=1;
image_xscale=dir;
break;
case attackbow:
sprite_index=sKnightBow;
image_xscale=-1;
// jumps if an arrow gets within 40 pixels of the boss
if distance_to_object(oArrow) < 40 && vsp==0
jump=1;
if can_attack==0
image_speed=0;
if can_attack==1
{
image_speed=1;
}
break;
case gettrident:
sprite_index=sKnightWalk;
dir=1;
image_xscale=dir;
break;
case walktrident:
sprite_index=sTridentWalk;
image_xscale=dir;
movefactor=1;
break;
case attacktrident:
sprite_index=sKnightTrident;
if obj_person.x < x
{
dir=-1;
movefactor=4;
}
if oPerson.x > x
{
dir=1;
movefactor=4;
}
image_xscale=dir;
jump=1;
break;
}
STEP 20
Boss Monster Step Event Lines 78-133
These lines control what happens if you are in each state.
Each state has a sprite which must be changed so it looks correct and some have some actions that must be performed as well.
Remember a switch statement is like a long list of if then statements I like switch statements because they are easier to follow: These are the states and what happens in each.
idle
changes to idle sprite
getbow
changes to walk sprite
walks right
changes sprite to face right
attackbow
changes to bow attack sprite
changes sprite to face left
checks to see if your arrow is going to hit him then jumps if you are on ground
checks if you can attack if so animate sprite
gettrident
changes to walk sprite
walks right
changes sprite to face right
walktrident
changes to trident walk sprite
changes sprite to face your current direction
sets movefactor to 1 which means normal movement speed
attacktrident
changes to trident attack sprite
checks if your character is either to the bosses right or left
moves toward your character at 4 times normal speed
changes sprite to face your character
jumps
STEP 21
Boss Monster Animation End Event
Add an animation end event and add the following code.
In the code you will notice it does different things depending upon what state your boss is currently in.
If your boss in in attackbow state and can_attack=1 which means he is attacking he will create an arrow play an arrow firing sound and set can_attack to 0
So to make these happen you have to create a new object called oBossarrow and find a sound to play when the arrow fires.
If your boss is in attacktrident state
it changes your state to walktrident and can_attack to 0 and jump to 0
It is important to remember that if your animation is too short the animation end event will occur and stop your attack. So you have to lengthen your attack animation to match how long you want your attack to last I made mine 20 frames in length so 2/3 of a second attack.
Boss Animation End Event
switch state
{
case attackbow:
instance_create(x,y,oBossarrow);
sound_play(snd_bossBow);
can_attack=0;
break;
case attacktrident:
state=walktrident;
can_attack=0;
jump=0;
break;
}
STEP 22
Boss Monster Collision with Bow Object
Add an collision with the bow object you made in step 29
Add the code.
This code will destroy the bow object
Go to attackbow state and stop the character from move thus dir=0
Remember:
dir = 1 move right
dir = -1 move left
dir = 0 no movement
Boss Monster Collision with Bow Object
with other
instance_destroy();
state=attackbow;
dir=0;
STEP 23
Boss Monster Collision with Trident Object
Add an collision with the trident object you made in step 29
Add the code.
This code will destroy the trident object
Go to walktrident state and make the character move left
Boss Monster Collision with Trident Object
with other
instance_destroy();
dir=-1;
state=walktrident;
STEP 24
Boss Health
We will draw the healthbar for your boss using the oHealth object. The same object that is drawing the healthbar for your character.
So in the draw event add this code below the first the numbers may need to be changed depending upon the size of the sprite of your boss.
Draw Event for oHealth
//DRAW health bar
draw_healthbar(oKnight.x-16,oKnight.y-40,oKnight.x+16,oKnight.y-45,oKnight.hpamount,255,65280,65280,0,1,1);
STEP 25
Hurting the Boss with Arrow
Now that the boss has a health bar we want to be able to hurt him with your arrows and blade.
To do this add a collision event in your boss object with your arrow and add the following code.
This code will destroy the arrow take away 2 health from boss check if boss has no health and if so destroy boss and give you points.
Collision Events with arrow in obj_boss
with other
instance_destroy();
hpamount-=2;
if hpamount<0
{
instance_destroy();
score+=points;
}
STEP 26
Hurting the Boss with Sword
Now that the boss has a health bar we want to be able to hurt him with your arrows and blade.
To do this add a collision event in your boss object with your attack sword object and add the following code.
This code will destroy the sword object take away 3 health from boss check if boss has no health and if so destroy boss and give you points.
Collision Events with oSwordAtt in obj_boss
with other
instance_destroy();
hpamount-=3;
if hpamount<0
{
instance_destroy();
score+=points;
}
STEP 27
Rope Swing
This is how to make a rope to swing across pits
Create an obj_rope give it a sprite like this. Make the origin 2,0
Create Event of oRope
t = 0; //Time variable used for swinging
radius = 0; //This will be used when the player grabs onto the rope
Step Event of oRope
t += 1;
if t >= 4*room_speed
{
t = 0;
} //Assumes a period of 4 seconds
//Angle will swing between 45 and -45 degrees
image_angle = 75*sin(2*pi*t/(4*room_speed));
if image_angle < 0
{
image_angle += 360;
} //Not sure if this is necessary, but keeps image_angle between 0 and 360
if place_meeting(x, y, oPlayer) && radius == 0 && keyboard_check(ord("W"))
{ //When player grabs on
//Include condition for when player grabs rope
//If you do not have this, you may not be able to let go.
radius = point_distance(x, y, oPlayer.x, oPlayer.y);
}
if instance_exists(oPlayer) && radius > 0 && keyboard_check(ord("W"))
{
oPlayer.x = x + radius*sin(image_angle*pi/180);
oPlayer.y = y + radius*cos(image_angle*pi/180);
}
//Don't forget to set radius to 0 when player jumps off.
if keyboard_check_released(ord("W"))
radius=0
STEP 28
Thors Hammer Weapon
This is how to make a Thors Hammer which will return to you after you throw it.
Create two objects oHammer and oHammerBack with a sprite like this they will both use the same sprite.
You will need to have an action that creates the hammer so either have a new button to create it or switch your weapon from sword to bow to hammer.
To make the hammer have more range increase the number of sprites in the sub-image.
The obj_thor.throw=0 will allow Thor to throw another hammer this avoids have two hammers thrown at same time. You will need to change the name obj_thor to the name of your player unless you are using this code for a boss enemy.
To make the hammer collide with Thor we need to use collision_circle function since the Step toward function won't allow the hammer to collide with Thor instead it will just circle him.
Create Event oHammer
move_towards_point(mouse_x,mouse_y,15);
Animation End Event of oHammer
instance_destroy();
instance_create(x,y,oHammerBack);
Step Event oHammerBack
action_potential_step(oThor.x,oThor.y,10,1);
if collision_circle(x, y, 20, oThor, false, true)
{
instance_destroy();
oThor.throw=0
}