Jump to content


Photo
* * * * * 1 votes

Tower Defense Game Tutorial


  • Please log in to reply
109 replies to this topic

#81 jhf97

jhf97

    GMC Member

  • New Member
  • 2 posts

Posted 11 October 2010 - 11:07 PM

How about some thing like this

//Check if enemies are in range and activate firing if needed

{
if firing > 0 firing += 1;
if firing >= 30/rate firing = 0;
if not instance_exists(target) target = noone;
if instance_exists(ob_enemy)
{
if target = noone target = instance_nearest(x,y,ob_enemy);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}


if instance_exists(ob_enemy2)
{
if target = noone target = instance_nearest(x,y,ob_enemy2);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy3)
{
if target = noone target = instance_nearest(x,y,ob_enemy3);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy4)
{
if target = noone target = instance_nearest(x,y,ob_enemy4);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy5)
{
if target = noone target = instance_nearest(x,y,ob_enemy5);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}


if firing = 1 depth = -3;
else depth = -2;
}

Edited by jhf97, 11 October 2010 - 11:08 PM.

  • 0

#82 Turok

Turok

    GMC Member

  • New Member
  • 3 posts

Posted 13 October 2010 - 08:10 PM

How about some thing like this

//Check if enemies are in range and activate firing if needed

{
if firing > 0 firing += 1;
if firing >= 30/rate firing = 0;
if not instance_exists(target) target = noone;
if instance_exists(ob_enemy)
{
if target = noone target = instance_nearest(x,y,ob_enemy);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}


if instance_exists(ob_enemy2)
{
if target = noone target = instance_nearest(x,y,ob_enemy2);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy3)
{
if target = noone target = instance_nearest(x,y,ob_enemy3);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy4)
{
if target = noone target = instance_nearest(x,y,ob_enemy4);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}

if instance_exists(ob_enemy5)
{
if target = noone target = instance_nearest(x,y,ob_enemy5);
if point_distance(x,y,target.x,target.y) > range
target = noone;
else if firing = 0
firing = 1;
}


if firing = 1 depth = -3;
else depth = -2;
}


i figured it out.

I just needed to make the other enemies the child of the original enemy :)
  • 0

#83 flamses1000

flamses1000

    GMC Member

  • New Member
  • 27 posts

Posted 05 December 2010 - 12:36 PM

i need help so the tower will point at the enemy and shoot when an enemy comes by i looked back,but it didnt work for me
  • 0

#84 TDsDomain

TDsDomain

    GMC Member

  • New Member
  • 1 posts

Posted 05 December 2010 - 11:46 PM

how do you make it so the wave ends when all the enemies are dead instead of a time limit?
  • 0

#85 guowei

guowei

    GMC Member

  • New Member
  • 5 posts

Posted 06 December 2010 - 07:56 AM

Awesome tower defend tutorial :D just some of the code bug me to no end, but that is just me:P

Thanks to your tutorial I'm able to complete my tower defense much faster then if i'm doing it alone :D Thanks alot!

Edited by guowei, 06 December 2010 - 07:56 AM.

  • 0

#86 the_recruiting

the_recruiting

    GMC Member

  • New Member
  • 800 posts

Posted 09 December 2010 - 09:55 AM

Sorry to bring this topic back up but does anyone have a working link to the file? Really important as this was a great tut!

Thanks ;)
  • 0

#87 flamses1000

flamses1000

    GMC Member

  • New Member
  • 27 posts

Posted 12 December 2010 - 01:05 PM

Please someone help me with my with rotating the towers
  • 0

#88 OrangeDragonOrigami

OrangeDragonOrigami

    GMC Member

  • New Member
  • 1 posts

Posted 30 December 2010 - 04:57 AM

This is the best td tutorial i have found so far.
But i seem to be having problems with understanding how to add more towers.
I'm not that familiar with GM code.
This tutorial helped me understand more about GM code.
But can someone help me with adding more types of towers?
Also does anybody now how to make a bomb weapon that has a target in the middle and can blow up an enemy like in 'interceptor' "the swc" but this is followed by the mouse and after used once is not used again until ypu buy another one.
Like the bomb used in 'warzone tower defence' (for a better explanation).
By the way im using Game Maker 8pro.
  • 0

#89 flamses1000

flamses1000

    GMC Member

  • New Member
  • 27 posts

Posted 02 January 2011 - 11:16 PM

how do you make it so the wave ends when all the enemies are dead instead of a time limit?


you would have to change the wave system to do this:
{
globalvar ee;
if wave_time = 600
{
wave += 1;
wave_time = 0;
wave_enemies = min(5+floor(wave*0.4),25);
ee = wave_enemies;
}
//Creates enemies
if wave_time < 600 wave_time += 1;
if wave_enemies > 0
{
if(wave_time = (ee-wave_enemies)*30+30)
{
switch(floor(wave/1))
{
case 1:instance_create(-32,0,ob_alien); break;--change ob_alien and other stuff to what ur enemies are if u want only one change all to same
case 2:instance_create(-32,0,ob_alien); break;
case 3:instance_create(-32,0,ob_alien); break;
case 4:instance_create(-32,0,ob_huge_spaceship); break;
case 5:instance_create(-32,0,ob_enemy); break;
case 6:instance_create(-32,0,ob_enemy); break;
case 7:instance_create(-32,0,ob_alien); break;
case 8:instance_create(-32,0,ob_enemy); break;
case 9:instance_create(-32,0,ob_huge_spaceship); break;
case 10:instance_create(-32,0,ob_alien); break;
case 11:instance_create(-32,0,ob_alien); break;
case 12:instance_create(-32,0,ob_tank); break;
case 13:instance_create(-32,0,ob_alien); break;
case 14:instance_create(-32,0,ob_huge_spaceship); break;
case 15:instance_create(-32,0,ob_enemy); break;
case 16:instance_create(-32,0,ob_tank); break;
case 17:instance_create(-32,0,ob_alien); break;
case 18:instance_create(-32,0,ob_enemy); break;
case 19:instance_create(-32,0,ob_huge_spaceship); break;
case 20:instance_create(-32,0,ob_alien); break;
case 21:instance_create(-32,0,ob_alien); break;
case 22:instance_create(-32,0,ob_tank); break;
case 23:instance_create(-32,0,ob_alien); break;
case 24:instance_create(-32,0,ob_huge_spaceship); break;
case 25:instance_create(-32,0,ob_enemy); break;
case 26:instance_create(-32,0,ob_tank); break;
case 27:instance_create(-32,0,ob_alien); break;
case 28:instance_create(-32,0,ob_enemy); break;
case 29:instance_create(-32,0,ob_huge_spaceship); break;
case 30:instance_create(-32,0,ob_alien); break;
case 31:instance_create(-32,0,ob_tank); break;
case 32:instance_create(-32,0,ob_alien); break;
case 33:instance_create(-32,0,ob_alien); break;
case 34:instance_create(-32,0,ob_huge_spaceship); break;
case 35:instance_create(-32,0,ob_boss); break;
if wave>= 35
room_goto(rm_menu)--change this to what u want like game_end()

}
wave_enemies -= 1;
}
}
}
  • 0

#90 _181743

_181743

    GMC Member

  • New Member
  • 1 posts

Posted 08 January 2011 - 04:30 PM

This is the best td tutorial i have found so far.
But i seem to be having problems with understanding how to add more towers.
I'm not that familiar with GM code.
This tutorial helped me understand more about GM code.
But can someone help me with adding more types of towers?
Also does anybody now how to make a bomb weapon that has a target in the middle and can blow up an enemy like in 'interceptor' "the swc" but this is followed by the mouse and after used once is not used again until ypu buy another one.
Like the bomb used in 'warzone tower defence' (for a better explanation).
By the way im using Game Maker 8pro.


this should do there is new kind of tower save(if needed), and nuke(like warzone)hope you like it :D
download link:Download td game.gmk

EDIT* : These files are now friendly with lite users

Edited by _181743, 24 January 2011 - 11:03 AM.

  • 0

#91 jak2027

jak2027

    GMC Member

  • New Member
  • 16 posts
  • Version:Unknown

Posted 08 February 2011 - 06:57 AM

Quick question, how would one going about to change the Wave system so it spawns a number of enemies you choose instead of using the equation in the curent wave system?
  • 0

#92 The Rock Abdo

The Rock Abdo

    GMC Member

  • GMC Member
  • 50 posts
  • Version:GM8

Posted 06 March 2011 - 06:51 PM

Great Tutorial Thanks VERY MUCH :) :wub:
  • 0

#93 DioFlare

DioFlare

    GMC Member

  • New Member
  • 56 posts
  • Version:GM8

Posted 06 March 2011 - 08:40 PM

Thanks! Nice tutorial!
  • 0

#94 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 07 July 2011 - 02:34 AM

Std Msg: Please use the tutorial template header (The Tutorial Clean Up Crew).
Std Msg: Please add a summary/explanation or basic outline of what your tutorial is for or teaches (The Tutorial Clean Up Crew).
Std Msg: Please remove the Local Moderator Said quote (The Tutorial Clean Up Crew).

Not Rejected;

Moved to Staff Choice for all the effort in the .doc and incremental gmks
  • 0

#95 Terrified Virus

Terrified Virus

    Moderators Plaything

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

Posted 11 July 2011 - 04:11 AM

Wow, this is awesome, I might just use some codes in my game! This definitely deserves to be in the staff choice section.
  • 0

#96 _223916

_223916

    GMC Member

  • New Member
  • 1 posts

Posted 20 August 2011 - 12:05 PM

How do you add different levels (maps/rooms)?
  • 0

#97 skibbi

skibbi

    GMC Member

  • New Member
  • 7 posts

Posted 05 September 2011 - 08:35 AM

I'm a noob :laugh: and I haven't a clue how to make this!
Please give permission to mod it if we give you lots of credit and don't enter it in anything!

  • 0

#98 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16799 posts
  • Version:GM:Studio

Posted 05 September 2011 - 08:39 AM

I'm a noob :laugh: and I haven't a clue how to make this!
Please give permission to mod it if we give you lots of credit and don't enter it in anything!


Everything submitted to the turorials forums is for using! The idea is that you take it apart, learn from it then put it back together again in your own games, or create your own version based on this... so go ahead, but remember that CREDIT is an important part of the tutorials forum and so thank the member in your game for their help/engine/whatever... Posted Image
  • 0

#99 NestoFlo

NestoFlo

    GMC Member

  • GMC Member
  • 460 posts

Posted 05 November 2011 - 02:50 AM

Great job! My father wants me to learn GML and coding, so this will definitely help out!
Its way better then hitting the apple haha.
  • 0

#100 LVSF3

LVSF3

    GMC Member

  • New Member
  • 1 posts
  • Version:Unknown

Posted 12 November 2011 - 10:01 PM

I don't know why I'm getting this error:

dist = point_distance(x,y,target.x,target.y)/24;

at position 47: Unknown variable x

(second x variable)
(in step event of bullet tower)

Please help!

Edited by LVSF3, 12 November 2011 - 10:09 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users