+ All Categories
Home > Documents > 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot,...

1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot,...

Date post: 29-May-2018
Category:
Upload: vutu
View: 222 times
Download: 0 times
Share this document with a friend
19
VACUUM MARAUDERS V5.0 © 2008 PAUL KNICKERBOCKER FOR LANE COMMUNITY COLLEGE In this game we will expand on our V4.0 model to include powerups that switch the player’s weapons and the introduction of a boss character. This game will focus on: Defining Custom Variables Counter Variables Status Variables Health and health bars 1.PLAYER WEAPON SELECTION The cluster bomb is a devastating weapon and makes the game kind of trivial if allowed to be used at will. What we want to do with the player object is to make the <Space> button fire just one of the missile types. What missile will depend on what powerup the player has grabbed last. To do this we will use variables, but instead of ones that Game Maker has we will define one ourselves. Custom variables operate just like Game Maker’s variable but we create them and so are in charge of maintaining them. To define a custom variable you just need to add in Set Variable action ( , in the control tab), give it a name and a value. Once this variable is set it can be called by name in any future action to get its value. We will create a custom variable in “object_player” that will track what
Transcript
Page 1: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

VACUUM MARAUDERS

V5.0© 2008 PAUL KNICKERBOCKER FOR LANE COMMUNITY COLLEGE

In this game we will expand on our V4.0 model to include powerups that switch the player’s weapons and the introduction of a boss character.

This game will focus on:

Defining Custom Variables Counter Variables Status Variables Health and health bars

1.PLAYER WEAPON SELECTIONThe cluster bomb is a devastating weapon and makes the game kind of trivial if allowed to be used at will. What we want to do with the player object is to make the <Space> button fire just one of the missile types. What missile will depend on what powerup the player has grabbed last. To do this we will use variables, but instead of ones that Game Maker has we will define one ourselves.

Custom variables operate just like Game Maker’s variable but we create them and so are in charge of maintaining them. To define a custom variable you just need to

add in Set Variable action ( , in the control tab), give it a name and a value. Once this variable is set it can be called by name in any future action to get its value. We will create a custom variable in “object_player” that will track what weapon we are shooting, and later another variable to track ammo. Remember that these variables are bound to the object that defines them, a variable defined in one object will not be usable in another (except under certain circumstances).

Page 2: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Open “object_player” and add a Create event. Inside the Create event put a Set

Variable action ( ) with Variable = “weapon”, Value = 0 and Relative turned off:

We now have a variable “weapon” that we can call on during any other action. We define the variable in the Create event because we can’t use it till we have defined it. Create is usually used to define all the custom variables the object will need.

We want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Standard Shot Drill Shot Cluster Bomb“weapon” 0 1 2With this system we can now program the Key Press <Space> event to shoot the appropriate missile based on the value of “weapon”.

Page 3: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

First delete the Key Press <Ctr> and Key Press <Shift> events from “object_player” and go to Key Press <Space>. We will want to insert in a Test

Variable ( ) conditional for Variable = “weapon”, Value = 0 (the normal missile), Operation = Equal to and NOT turned off:

Then add the blocking so that the Create Instance action ( ) that makes a “object_shot” is under the conditional:

This way, when “weapon” = 0, the normal shot will be fired.

Page 4: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Now make 2 more blocks of Test Variable ( ) conditionals that shoot a “object_shot_drill” when “weapon” = 1, and shoots a “object_shot_bomb” when “weapon” = 2. This will end up looking like:

This will make the missile shot contingent on the status of “weapon”

One more addition we will want to make is putting in Exit Event actions ( , in control tab) at the end of the blocks. Exit Event automatically stops the processing of actions inside the event, and is useful if you don’t need to process the rest of the event. In our case, after we have made a shot we don’t need to test the weapon variable anymore so we can put in the Exit Event and save ourselves some processing time. This will modify it to look like:

Page 5: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

2.POWERUP OBJECTWe will be making two powerup objects, so make sure that you have two powerup sprites loaded.

Make a new object named “object_powerup”, but assign it no sprite:

What we are trying to do with this powerup is to assign it a value that it will then transfer to the variable “weapon” in “object_player”. The powerup will either set “weapon” to 1 or 2. While we could make 2 different powerup items, we will demonstrate how we can make a single powerup that acts like 2 by using custom variables.

Page 6: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Put in a Create event and define the custom variable “type” using a Set Variable action

( ) with Variable = “type”, Relative off and Value = “choose(1,2)”:

“choose” is another function like “random”. In “choose” you supply the function with a list of numbers separated by commas and the function chooses one at random. So “choose(1,2)” will be replaced with either 1 or 2. “choose” is handy when you don’t want a number in a range but just want to pick out of several choices.

We want to use 2 different sprites for the two different values of type so that players can know what type of powerup they are grabbing. Now that “type” is set

we can manually set the sprite using the Change Sprite action ( , in the main1 tab). Put in a Test Variable

( ) conditional that checks if “type” = 1 and then put the Change Sprite action in the block with the chosen sprite in Sprite, Subimage = 0 and Speed = 0 (refers to speed of animation):

Page 7: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Repeat the same process with a Test Variable ( ) that checks “type” = 2 and set a different sprite. We also want the powerup to move down the screen so add a Move Fixed

( ) with the arrow facing down and Speed = 6. The end result should look like:

Because the powerup is moving it will eventually fall behind the player, so for cleanup’s sake add in a Outside Room event with a Destroy Instance action () applied to Self in it.

We use 1 and 2 in “type” so that we can transfer the value of “type” directly into “weapon”. Create a Collision event with “object_player” and put in a Set Variable

action ( ) with Variable = “object_player.weapon”, Relative off and Value = “type”:

Page 8: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

In this variable we are setting the “weapon” variable in “object_player” to be the same as “type”. Because “type” is either 1 or 2, the player will end up firing either a drill shot or a cluster bomb. Add on the end a Destroy Instance action ( ) applied to Self to get rid of the powerup.

The final thing we need to do is have the enemies drop the powerup when they die. Not every enemy will drop a powerup so we will introduce some randomness into the process. Open “object_enemy” and in the Collision with “object_shot” add in a

Test Chance ( ) conditional at the top of the actions with Sides = 10 (a

powerup every 10 enemies killed). Inside the blocking put a Create Instance ( ) action for “object_powerup” at point (0,0) relative:

Because the drill shot is handled differently, you will have copy this segment into the Collision event for “object_shot_drill”.

Now we should have a powerup that drops every 10 or so enemies that changes our weapon:

Page 9: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

3.AMMO COUNTERRight now we have a pickup that changes the weapon but we still have a bit of a problem with balance. If the user picks up a cluster bomb powerup the game becomes very easy again. To balance this out we will add an ammo variable that limits the number of shots the player gets before it reverts back to the original missile. To do this we will have to define a new variable “ammo” and track it.

Open up the Create event in “object_player” and add in a new Set Variable action

( ) with Variable = “ammo” and Value = 0. This defines the new ”ammo” variable and sets it to 0. Now we will add in a check for the ammo variable at the beginning of Key Press <Space> by adding in a Test Variable ( ) conditional

Page 10: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

at the beginning that checks to see if “ammo” = 0, and if so it sets “weapon” to 0

(the standard missile) with a Set Variable action ( ):

This will automatically reset the missile type when ammo is reached.

We still need to keep track of the ammo so we need to make sure that for every special weapon (type 1 and 2) we decrease the ammo counter by one. In the blocks

for the drill missile and the cluster bomb put in a Set Variable action ( ) that sets Variable = “ammo”, Value = -1 and Relative turned on. This will decrease ammo by one every time a special missile is fired. The end result should look like:

Page 11: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

We have an ammo counter that counts down but we have to set it to something other than 0 when the pickup hits it. Open “object_powerup” and enter the

Collision event with “object_player”, add in a Set Variable action ( ) below the first one, where Variable = “object_player.ammo”, Value = 75 and Relative turned off:

Now the weapon should have only 75 shots before it reverts to the regular missile.

4.BOSS ENEMYAll our enemies have been fairly easy up to this point and so we will now make a boss object that will take several shots to kill. We will not make this object a child of “object_enemy” because its behavior will be different enough that making it a child would be more hassle then help.

Create a new object called “object_boss” and assign it a large boss sprite (load it if necessary):

Page 12: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

While you can give the boss any of the movement techniques we have learned, for simplicity’s sake we will just add in a Create event with a simple Move Fixed ( ) with Speed = 4 and both left and right arrows pushed in. Next we add in the Set

Health action ( , in score tab) where Value = 100:

“health” is another variable built into game maker and manipulated by special actions. Health can apply to the user or to enemies (like we will use it), but there is only one health variable so it can only really apply to one instance.

Before we continue to deal with health, add in an Intersect Boundary event and

put in it a Reverse Horizontal action ( ) so that the boss bounces between the sides of the room.

Page 13: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

Just as we set the initial health, we will have to decrease it after a missile strike. Add a Collision event for “object_shot”. We will handle all the missiles the same so

this is the only collision we will need. First add in a Set Health action ( ) with Value = -5 and Relative turned on, this will decrease the current health by 5.

Next, add in a Test Health conditional ( , in score tab) with Value = 0 and Operation = Equal to:

Inside the blocks will be the events we want to happen when the enemy dies (i.e. health = 0).

First put in a Set Score action ( ) in the blocks with new score = 5000 and

Relative on (add on 5000 points). Then put in a Create Instance action ( ) which makes an object “object_explosion” at X = “random(100) – 50”, Y = “random(100) – 50” and Relative on:

Page 14: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

This action will create a random explosion within the relative range of (-50,-50) and (50,50) (since “random(100) – 50” is a random number between -50 and 50). Make another 5 copies of this action to make a decent amount of explosions. Finish up the block with a Destroy Instance action ( ) applied to Self, and finish up the event with a Destroy Instance action ( ) applied to Other. The end result should be:

Now that we have a destruction event, we want to make the boss a treat by having

it throw a lot of fireballs, so create a Step event and add a Test Chance ( ) conditional with Sides = 15 (every half second or so). Inside the block add a

Create Instance action ( ) for a “object_fireball” and also an

Page 15: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

“object_fireball_seek”. You will need to surround the “object_fireball_seek” with a

Test Instance Count ( ) block that checks to make sure there is a “object_player” around, just like in “object_enemy3” (the easy way is to just copy and paste). The end result should be:

The last thing we need to do for the boss is give it a health bar so the player knows how close they are getting; to do this we will use the Draw event. Make a Draw

event and add in a Draw Health action ( , in score tab) with (X1,Y1) = (-20, -60), (X2,Y2) = (20, -50) and Relative on:

Back color and Bar color effect the look of the health bar and are left to personal preference.

The whole X1, Y1 thing requires some explanation as it also comes up when drawing boxes to the screen. The point (X1,Y1) is the upper left-hand corner of the

(X1,Y1)

Page 16: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

health box we are trying to draw, (X2, Y2) is the lower right-hand corner of the box. Laid out it looks like this:

(-20, -60) and (20, -50) work for the sprite I’m using because it is 180 X 136 and the top is about 60 pixels up (hence Y1 = -60). The proper positioning may require some image shifting.

We will also need to manually redraw the sprite because of the interference of the

health bar. Add a Draw Sprite action ( , in draw tab), with the main boss sprite at (0,0) relative and Subimage = -1.

Our final action is to add in the boss on our timeline. Put a Create Instance action

( ) to make the boss object at (120,120) in moment 1000. Shift the looping command back to 1500 to give the player time to deal with the boss. Now we should have major boss to fight at the end of the timeline:

(X2,Y2)

Page 17: 1.Player Weapon selection · Web viewWe want variable “weapon” to tell us what weapon to shoot, but the variable can only hold numbers so we will have to assign the weapons numbers:

FINISHING UPNow we should have the following new features implemented:

Powerups that confer new weapons and ammo A boss enemy with its own health


Recommended