Jump to content


Photo
- - - - -

Tower Defence / Defense


  • Please log in to reply
14 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 12 June 2012 - 06:50 AM

  • Title: Tower Defence / Defense Complete Tutorial and engine
  • Description: Short Description
  • GM Version: :GM8: (:GM81: and higher Delete the script lerp) GM:Studio No Pause Feature
  • Registered: Yes
  • File Type: .zip (18 gmk files GM8 + 1 gmz Studio File)
  • File Size: 13 MB
  • File Link: Download
  • Required Extensions: None
  • Required DLLs: None
Summary
Tower Defence/Defense Engine by icuurd12b42

Intensive 17 part tutorial + engine, Please read the Game Information for each tutorial gmk
 
Studio:
Available as an asset, see my store in signature
 
If used inform me icuurd12b42 on gmc.yoyogames.com

You must also put credit to the engine in your game and put the url to the topic on the GMC. Here is the link to my tools page where this engine is likely posted... From there you can find the Tower Defence tutorial link

http://gmc.yoyogames...howtopic=451383


How it works:
For gawd sakes, read the tutorial files (yeah there are 17! So freaken what). It took me a week to make all that stuff, you can't expect to use this right away without learning it first. It's going to take about 1 hour of your time.


The kreepers follow a path to the destination. Once there, they reduce the lives count. Once the lives count is 0 it's game over. Other systems can be implemented.

If you run through all the waves without loosing all your lives, you win.

The waves are controlled and defined with a set of APIs. See the Wave Level Controllers folder

Each level is a room. Each level needs it's own Wave Level Controller

In the Wave Level Controller you state the money the player has, you setup the waves of kreepers for that level.

To make a level
Clone a level room
Design the room looks, like I used a nice picture for the play field
Make the paths used for the level using the path editor and the room as underlay.
Place a End Of Line object where the kreeper reach the end.
Clone a Wave Level Controller and name it to match the level, and drop it in the room
Design the waves with the API sets. Read up on the API sets.

To make a new kreeper
Duplicate an existing kreeper that matches what you want. Clone the components it uses if they don't match what you want.

To make a new Tower
Clone the tower that matches the most what you want... did I just say that? Oh and the Hud equivalent as well.

The core engine systems
WaveSystemAPI is used to define you waves or groups of kreeper that will be created during a level. You can tell the system to create a kreeper on this path at this timeframe then a few of another type later on. You can make it look like a single wave or cluster is coming from multiple points by having multiple paths to the target.

InfoSystemAPI is used to define what information is shown where and at what time during the level play time line. Currently it is used to show what kreeper type is about to pop up and where from. The system is isolated from the Wave System so you can place any information you want in there to show at any time you want.

WaveCountSystem is used to define how many waves there are while defining when the next wave count is about to go up. This system visually ties in with the WaveSystem but it is not physically tied with it. Only the timeframe makes it look that way.

All these systems are separate on purpose as they allow you to make multiple creeper groups for each wave in a visual sense as opposed to a systematic way.

GameControllerAndHud is where you will find the UI and game state detection code

It create the global variables used by the other game components

Most components can work on their own as long the global variable they use are set and the objects they may need are in the resources.

The system is flexible enough to be modified to your visual liking or game type without breaking anything (much)

You may contact me for help on the GMC, preferably in the tutorial topic.

Good luck!

**Do NOT use the provided background taken from iBomber (from a youtube video) for you game. The image is for tutorial use ONLY.

Edited by icuurd12b42, 30 November 2014 - 03:17 PM.

  • 3

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#2 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 212 posts
  • Version:GM:Studio

Posted 12 June 2012 - 07:35 AM

I tried running the engine just to see how everything looked but when I tried to run I kept getting the error
"script name "lerp" is equal to a function name"
  • 0
Posted Image

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 12 June 2012 - 07:43 AM

I tried running the engine just to see how everything looked but when I tried to run I kept getting the error
"script name "lerp" is equal to a function name"



GM81 and higher. delete the script lerp as it is now a part of the GML language
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#4 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 212 posts
  • Version:GM:Studio

Posted 12 June 2012 - 08:30 AM

thank you deleting the script worked fine. Thank you very much for posting this, it looks amazing. Also i'm extremely happy that you broke down everything into parts, I get confused looking at huge engines like this, once I wake up ill look through all 17 parts. Thanks again :).
  • 0
Posted Image

#5 kukurayami88

kukurayami88

    GMC Member

  • New Member
  • 1 posts
  • Version:GM8

Posted 28 July 2012 - 08:45 AM

very detailed and amazing engine... tq so much for the effort!
  • 0

#6 Boysano

Boysano

    GMS Pro Member

  • GMC Member
  • 467 posts
  • Version:GM:Studio

Posted 20 April 2013 - 08:58 PM

In GMS the obsolete functions on the TowerDefence.Engine.gmk file needs to be updates, with these errors as tips:

 

 

Error : gml_Object_HudPauseButton_obj_Step_0(13) : cannot use function/script name for a variable, using "sleep"
Error : gml_Object_HudPauseButton_obj_Step_0(14) : cannot use function/script name for a variable, using "sleep"
Error : gml_Object_kreeper_obj_Other_8(5) : malformed if statement
Error : gml_Object_ShootingKreeper_obj_Other_8(6) : malformed if statement

  • 0

#7 Deepweb

Deepweb

    GMC Member

  • GMC Member
  • 130 posts
  • Version:GM:Studio

Posted 19 November 2013 - 11:47 PM

 

In GMS the obsolete functions on the TowerDefence.Engine.gmk file needs to be updates, with these errors as tips:

 

 

Error : gml_Object_HudPauseButton_obj_Step_0(13) : cannot use function/script name for a variable, using "sleep"
Error : gml_Object_HudPauseButton_obj_Step_0(14) : cannot use function/script name for a variable, using "sleep"
Error : gml_Object_kreeper_obj_Other_8(5) : malformed if statement
Error : gml_Object_ShootingKreeper_obj_Other_8(6) : malformed if statement

 

True that, just tried it in GM Studio and functions like sleep and io_handle are obsolete... any ideas if this is getting updated?


  • 0

#8 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 20 November 2013 - 04:52 AM

I added GMStudio gmz project for the final engine file in the zip.

Edited by icuurd12b42, 20 November 2013 - 04:53 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#9 davidian22

davidian22

    GMC Member

  • GMC Member
  • 103 posts
  • Version:GM:Studio

Posted 15 December 2013 - 09:21 PM

When running this on android, the kreepers do not spawn correctly. Do you know what is causing this problem?

 

 

David


  • 0

Press the green arrow if I helped you.


#10 davidian22

davidian22

    GMC Member

  • GMC Member
  • 103 posts
  • Version:GM:Studio

Posted 17 December 2013 - 02:54 PM

Hi,

 

It seems that when running on android, the kreepers only spawn when the time between each spawning kreeper is set to more than 120 steps.

I've looked through all the code but i cant seem to find the problem...

 

David


  • 0

Press the green arrow if I helped you.


#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 17 December 2013 - 07:30 PM

look at the ds_map(__sorted) references

see if converting the key to a string fixes it
ds_map_add(__sorted,argument0,at); -> ds_map_add(__sorted,string(argument0),at);

and everywhere I lookup value, convert the key to a string too
var listpos; listpos = ds_map_find_value(__sorted,pos); -> var listpos; listpos = ds_map_find_value(__sorted,string(pos));

Check all WaveSystemAPI scripts...
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#12 davidian22

davidian22

    GMC Member

  • GMC Member
  • 103 posts
  • Version:GM:Studio

Posted 18 December 2013 - 04:19 PM

Hi,

 

I converted all the keys to strings in WaveSystemAdd and WaveSystemStep, but when I did this some functions broke, so I had to convert the values for those functions back to reals.

So after some errors and tries this is my code in WaveSystemStep: 

//WaveSystemStep()
//call each step

//global state for done
global.WavesDone = true;
//if no more exit
if(ds_map_size(__sorted) == 0) exit;

//not done
global.WavesDone = false;
    
//if there is an entry for this step

//ask the map for the first sorted entry
var pos; pos = ds_map_find_first(__sorted);
//the map key is mapped to the step wanted...
//is there a key for this step or prior step
while(pos <= string(__curstep))
{
    //get the list index
    var listpos; listpos = ds_map_find_value(__sorted,string(pos));
    //get the AI, the path the speed and the repeat...
    var ai; ai = ds_list_find_value(__ais,string(listpos));
    var pth; pth = ds_list_find_value(__paths,string(listpos));
    var s; s = ds_list_find_value(__speeds,string(listpos));
    var rpt; rpt = ds_list_find_value(__reps,string(listpos));
    //get your other properties here
    
    ////
    
    //create the instance, away from view
    with(instance_create(-1000,-1000,real(ai)))
    {
        //path start at speed using specified path, this will move the instance back in play
        path_start(real(pth),real(s),3,1);
        //the speed need to be known for th estaller code
        m_SetSpeed = real(s);
        //set the repeat
        m_Rep = real(rpt);
        //set your other properties here
        
        ////
    }
    //remove the step entry
    ds_map_delete(__sorted,pos);
    //quit if no more
    if(ds_map_size(__sorted) == 0) exit;
    //get the next one, there may be many AI to make at the same step
    pos = ds_map_find_first(__sorted);
}
__curstep+=1;


and the problem is still there. Exactly the same as before...

 

David


Edited by davidian22, 18 December 2013 - 04:20 PM.

  • 0

Press the green arrow if I helped you.


#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 18 December 2013 - 10:03 PM

you should have done

var pos; pos = real(ds_map_find_first(__sorted));

 

not

while(pos <= string(__curstep))

 

you stringafied pos which is a numerical value.. "2" is bigger than "10"

 

You need to convert the key... Hmm still though it will be the wrong order in the list....

 

instead of string, use string_format

ds_map_add(__sorted,argument0,at); -> ds_map_add(__sorted,string_format(argument012,0),at);

 

right. this is getting a littl convoluted... referert to the original file

 

add a new script

ds_map_add2

return ds_map_add(argument0,string_format(argument1,12,0),argument2);

 

add a new script

ds_map_find_value2

return ds_map_find_value(argument0,string_format(argument1,12,0));

 

and so on for all the ds_map functions the system uses. then search and replace all ds_map function to ds_map_whatever2

 

for the ds_map functions retuning the key like find first,

return real(ds_map_find_first(argument0))

 

and find next

return ds_map_find_next(argument0,string_format(argument1,12,0));


Edited by icuurd12b42, 18 December 2013 - 10:06 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#14 davidian22

davidian22

    GMC Member

  • GMC Member
  • 103 posts
  • Version:GM:Studio

Posted 19 December 2013 - 08:14 PM

Hi,

 

I think I did all that you told me, but when running on android the kreepers do not spawn, not even one. When running in html5 the wavecount system does count waves, but the kreepers do not spawn also. I am attaching the gmz file that I created so it is easier to read. 

 

The dropbox link: https://www.dropbox....enceAndroid.gmz

 

 

David


  • 0

Press the green arrow if I helped you.


#15 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 19 December 2013 - 11:23 PM

It does not work in windows either... Arrgh. Stupid studio. ds_map_find_first does not return the first smallest key anymore. I swear the thing was working a few studio versions ago, or I may not have paid attention. who knows

 

I changed the code to use 2 priority_queue instead of 1 ds_map

 

re download at

https://skydrive.liv...45D1EA9168D!157

 

I forget to remove the show_debug.. search in script to find it


Edited by icuurd12b42, 19 December 2013 - 11:28 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button