All posts by Atomic Toddler

Level 14 – Lesson 01 [Inheritance]

Introduction
Sometimes you will find yourself creating several objects that have the same (or very similar) game behaviour. You will probably notice that you are copying and pasting the same blocks of code into the events of each one. This is when you should take advantage of using inheritance. Inheritance allows you create objects that build off of previously made objects. You can use all the code of previously created objects and then add extra code to your object to make it extra special. And the good news is that inheritance is easy to code.


Part A – Parents and Children

Watch the video: 14-01-A
Done File: 14-01-A-Done.gmk


Part B – Overriding Events of your Parent

Watch the video: 14-01-B
Done File: 14-01-B-Done.gmk


Part C – ISA (Is A) Relationships

Watch the video: 14-01-C
Done File: 14-01-C-Done.gmk


Challenge 1 – Blockers

Start with the project file 14-01-X1-Start.
Use inheritance so that when the player contacts a barrier (wall, bigWall, woodWall, statue) the player stops moving and the sound ‘snd_hit’ is played. To do this, create and code the behavior inside of a parent object called ‘o_barrier’ and then make these four objects children of the barrier object. Remove the player collides with bigWall code already found coded and replace with your own player collides with barrier code. Add a few in the room and test.

Solution Video: 14-01-X1-Solution
Solution File: 14-01-X1-Done.gmk


Challenge 2 – Magical Drinks
Start with the project file 14-01-X1-Start.gmk
(or continue from Challenge 1 project file)
There are three magical drinks in the game: potion, superPotion, and poison. Use inheritance to set up the following behavior using a parent object.   (HP has been coded in the player object already – it draws out under the player)

potion: adds 10 hp to player
superPotion: adds 25 hp to player
poison: takes away 50 hp from player

All three potions share the following behavior: they are destroyed when picked up, the sound ‘pick_up’ is played, the player hp is changed.

*Bonus to this Challenge*
The poison has some additional behavior: after picked up and destroyed a new one is placed somewhere in the room at a random location that is at least 201 pixels away from any other potion type (potion, superPotion, or poison).   Hint: use a loop to keep picking locations until you have found a location where the nearest potionParent is more than 200 pixels away – then create a new poison.

Solution Video: 14-01-X2-Solution
Solution File: 14-01-X2-Done.gmk


Challenge 3 – DragOn

Start with the project file 14-01-X3-Start.gmk .
This project contains an object called ‘o_dragMe’. This object has been coded with simple drag and drop behavior that lets the user left click on the object to start and stop dragging. The object has been given an apple sprite so you can test it out in the room before you start.

Use this object as a parent object to the gold and coin objects that are placed in the room so that the gold and coin objects can now be dragged and dropped with left clicks too. Be careful though – the gold and coin objects have code in the create and step event (so does the dragMe object) so you will have to use event_inherited at the right time so you don’t lose behavior when you override parent event code.

*note: this drag and drop code is very simple and has a few flaws, but the focus here is you figuring out how to apply inheritance properly to the objects

Solution Video:  14-01-X3-Solution
Solution File: 14-01-X3-Done.gmk

 

Level 15 Intro

You have learned how to store numbers and text using variables, lists, maps, and grids.  In this level you will learn one final way to store values – Arrays.

Arrays are common to almost all programming languages.  Arrays allow you store many values under one variable name.   Arrays are similar to lists, but more simple to use.  There are certain game tasks that just don’t need the complexity of using the scripts that go along with lists.  That’s when arrays are great to use.  Lets go learn how to use arrays and show you some examples of how arrays can make your games easier to code.

Level 15 Lesson 01 [ Arrays ]

Introduction
A variable is great at storing one value. But is it possible to store several values under one variable name? Of course. One option you have explored in Level 13 is the list data structure. In this level we will take a look at arrays and how they can make certain game tasks much easier and efficient to code. Almost every programming language makes use of arrays because arrays are awesome.

Part A – What is an Array?
Watch the video: 15-01-A
Done File: 15-01-A-Done.gmk


Part B – Three Simple Array Game Examples
Watch the video: 15-01-B
Done File: 15-01-B-Done.gmk


Challenge 1 – Dropper

Start with the project file 15-01-X1-Start.gmk

All the monsters have a parent object called o_monsterParent. Currently when you click on a monster it is destroyed. Add code to the o_monsterParent mouse pressed event that will randomly generate a dropped object such as a potion, apple, or gold when a monster is destroyed. Use an array to store the possible dropped objects and randomly select from this array when deciding which object to drop.

  Solution Video:  15-01-X1-Solution
  Solution File:  15-01-X1-Done.gmk


Challenge 2 – Dropper Cycled

Start with the project file 15-01-X1-Start.gmk

Modify your answer to Challenge 1 (Dropper) so that the items dropped by the destroyed monsters cycle. For example, the first monster destroyed will drop a potion, then the second monster will drop an apple, the third some gold, and then the next monster will drop a potion, then the next an apple, then the next some gold – see the cycle?

    Solution Video: 15-01-X2-Solution
    Solution File: 15-01-X2-Done.gmk


Challenge 3 – Level Names

Start with the project file 15-01-X1-Start

a) Each time you mouse click on a monster to destroy it the script increaseLevelPoints is executed and it increases the level points by 1 (This is already coded for you!). When the level points reaches 3 you should reset the level points to 0 AND increase the global.level by 1 (the player has gone up one level). The highest level should be limited to level 3. Add this behaviour by adding code into the increaseLevelPoints script. No arrays are required for this part!

b) Use an array to keep track of the name of each level so that you can write the name of the level next to the level number when using the draw object that is already in provided in the project.

Level 1 : Noob
Level 2 : Warrior
Level 3 : Master

   Solution Video: 15-01-X3-Solution
   Solution File: 15-01-X3-Done.gmk

Level 16 Intro

It’s time to take a break from serious code and learn a little more about something every game needs to have – good sound.

You have learned how to play a single sound using the audio engine but there is much more that can be done with a little more learning. In this level we will look at more detailed control of individual sounds, grouping sounds, and even some of the 3d audio techniques that allow your game to have positional sound.

Lets go!

Level 16 Lesson 01 [ Sounds, Emitters, Audio Groups ]

Introduction
In this lesson you will learn how to start taking more precise control of the sounds that you are playing in your game.  This will include using sound ids, audio emitters, and audio groups.  A focus of this lesson will be controlling, muting, and fading the sound of background music and sound effects separately in your game.

Part A – Sound Id’s
Every sound you play is treated like an individual game instance.  It is given a unique id number that allows you take control of it once it is playing.  Lets see how these id numbers can be used for a simple task of checking whether or not a certain sound is already playing in the game.

Watch the video:  16-01-A
Start with File: 16-01-A.gmk

 


Part B – Volume Control with Master Gain and Ids
The master gain value controls the overall volume of all sounds in the game, while individual sound volumes can be controlled using the id of the sound you want to control.  Lets take a look.

Watch the video: 16-01-B
Start with File: 16-01-A.gmk


Part C – Emitters and Volume Control
Sound emitters are created and placed in the room.  When you play a sound, you can choose which emitter you want to play the sound on.  The nice thing about emitters is that you can play several sounds from one emitter, and you can also control things like the volume for an emitter.  In this part we will look at how you can use emitters to control the volume of background music and sound effects independently.  In lesson two you will continue to use emitters to create panning, fading, and positional 3d sound effects.

Watch the video: 16-01-C
Start with File: 16-01-C.gmk


Part D – Audio Groups
Audio Groups allow you to group sounds into, guess what, groups!  Once sounds are in a group you can apply effects to the entire sound group at once.  They are a must learn for total sound control.

Watch the video: 16-01-D
Start with File: 16-01-D.gmk


No Challenges – Just go try some of this stuff in your games!

Level 16 Lesson 02 [ 3d Positional Sound ]

Introduction
In the last lesson you used emitters to play sounds and to control their volume. In this lesson you will learn what emitters were intended to do – position sounds in 3d space and apply effects like panning, fading, Doppler effect, and several more.

Part A – Emitter, Listeners, and Positional Effects
Once you create an emitter the sounds that are played on that emitter will appear to come from that position in the game world. You can get some nice sound effects by moving the emitters around the game room. In this part you will move an emitter along with one of your sound producing monsters (so the sound appears to come from the monster) and move our listener with the player to see how the 3d positional effects work. You will also be shown how the drop-off distance effects work with emitters and listeners.

Watch the video: 16-02-A
Start with File: 16-02-A.gmk

Part B – Doppler Effects with Emitters  ***Coming Soon***
Lets add on to what we did in Part A. A fun effect you can add to your games is Doppler effect to your moving objects. A good example is an police car moving towards you and passing you – the sound of the siren changes as it comes and goes. The audio engine makes this easy to accomplish through the use of emitters and adding just a line or two of code.

Watch the video: 16-02-B
Start with File: 16-02-B.gmk

Level 17 Intro

Almost every game will benefit from being able to use the file system to write and read game information. Game settings, high scores, level information, achievements, etc. can be easily saved and loaded from files.

In this level you will learn the basics of using the file system in GameMaker.

Level 17 Lesson 01 [ ini File Writing/Reading ]

Introduction
One way to save information to the file system involves writing and reading from an initialization file (.ini file). Using .ini files is fast and easy. The information is organized inside of them into sections and each piece of data is given a ‘key’ name to help you find the data quickly. In the following four parts you will learn to use .ini files for some simple tasks like saving user preferences, and for some longer tasks like saving and loading room/level information.

Part A – INI File Basics
In this part you will learn how to create an .ini file, write numbers and text to key values, and read these values back into the game.

Watch the video: 17-01-A
Done File: 17-01-ABCD-Done.gmk

Part B – INI Files and Lists
In Part A you saved key/value pairs into an .ini file. In this part you will save the positions of many game pieces into an .ini using just one key and a ds_list. Saving lists into .ini files is one way to store lots of values into your .ini files without having to create hundreds of key values.

Watch the video: 17-01-B
Done File: 17-01-ABCD-Done.gmk


Part C – INI Files and Maps
Lists are useful for storing many values into one key in a file. Maps can be even more useful depending on the tasks. In this example a map is used to save some user preferences for easy writing and reading.

Watch the video: 17-01-C
Done File: 17-01-ABCD-Done.gmk


Part D – INI Files and Grids
Want to store an entire room or level into a file? This example will show you using a grid data structure to save and load the type and position of objects in a room. Very useful for saving and loading levels, but also very useful for any type of save that requires you save lots of organized data.

Watch the video: 17-01-D
Done File: 17-01-ABCD-Done.gmk

Level 17 Lesson 02 [ text File writing/reading ]

Introduction
In the last lesson you learned how to use .ini files to save data in a structured way with key-value pairs. In this lesson you will learn how to use text files to save data. When using text files YOU decide how the file is written. There are no sections and key names. You simply write data to the file line by line. When you read the data from the file you go line by line. The order that you wrote data will be the order that you read data from the file. Text files require a little more organization than .ini files but are more versatile. Text files can be much larger than .ini files and you can have up to 32 text files open at once during your game.


Part A – Text File Basics

Text files make use of simple commands to write and read from the file. In this example you will be introduced to the read and write commands, what the text files look like, and the general logic you will use when deciding how to organize your text files.

Watch the video: 17-02-A
Done File: 17-01-A-Done.gmk

Part B – Text Files and readln() Caution!
The readln() method will read until the end of the current line on a text file and then move to the start of the next line. But beware the string that this method returns – it contains extra key characters representing the newline/carriage return. Must watch!

Watch the video: 17-02-B
Done File: 17-02-B-Done.gmk

 

Challenge 01 – Save and Load User Preferences
Start with the project from part B: 17-02-B-Done.gmk

Practice saving and loading the difficulty level, points, hp, and difficulty text.
When the user presses the save button, save these four pieces of information in the following format in a text file:

line 1: difficulty level points hp
line 2: difficultyText

So the actual text file might look like this:

2 123 50
easy

When the load button is pressed your program should read the data from the text file and you should see the values on the screen (the drawing is already coded for you in the project). *For testing, you can hit the “R” key to randomly set some of the values and then press load to see if the saved values are properly set back.

    Solution Video: 17-02-X1-Solution
    Solution File: 17-02-X1-Solution.gmk

Part C – Text Files with Lists,Maps, Grids
In the previous lesson you learned how to save lists, maps, and grids into an .ini file. In this part you will see how the same tasks can be done using a text file. The main idea of this part is that the entire list string is saved on one single line of the text file, regardless of how much data is contained.

Watch the video: 17-02-C
Done File: 17-02-C-Done.gmk

Part D – Detecting the End of a File
Sometimes when you read a text file you don’t know how many lines are actually in the file. In this video the example used is loading the types and locations of objects in the room. There could be 50 units, there could be 1000. How does your program know when to stop reading the file? You keep reading a carefully formatted text file until you hit the end of the file. The eof() method will help you do this.

Watch the video: 17-02-D
Done File: 17-02-D-Done.gmk