TowerDefence.net Forums
Home
Forum
Contact
Search
Go Back   Tower Defence Forums > Tower Defence > Code Forge

Code Forge Share your coding problems with the rest of the community, and help other people overcome the same problem's you have.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old June 5th, 2008, 03:05 PM   #1
Fireblade
Ice Turret
Points: 5,275, Level: 33
Points: 5,275, Level: 33 Points: 5,275, Level: 33 Points: 5,275, Level: 33
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Fireblade's Avatar
 
Join Date: Aug 2007
Posts: 492
Fireblade is a normal user
Default Game Maker Tower Defence tut

This is a tutorial of how to create a Obj_Enemy and Obj_Tower that interact with each other. As in, the tower will shoot back at a certain range. And the enemy will spawn, go along a path, and you will beable to build more towers.

Note: I work to get the job done. xD there are others better then me xD

My tower will be able to rotate, this could be very difficult if your sprite of the tower is not suited for rotation, if you do not want it to rotate, then remove every line of the image_angle = Point_direction. i mean the WHOLE LINE


if you change names of your objects, you need to change the names of them in the code.

if you follow my guide, make sure everything here is also capitalized in your game as names.

This tutorial mostly ment for tower and enemy, the spawning of the enemys will spawn

1st:
Build a Obj_Tower, new sprite, name it Spr_Tower(any name works, but coding it could be difficult if your n ot organized)

Make a Obj_Bullet (sprite too)
Make a Obj_Enemy


2nd: now lets make the Obj_Tower

on create
Code:
shot = 1
on alarm 0
Code:
shot = 1
on step
Code:
//This code makes gets the nearest enemy, and if its in distance (75 or lower)
//Then it creates a bullet!
Enemy = instance_nearest(x,y,Obj_Enemy)

if (distance_to_object(Enemy) < 76) then
    {
        image_angle = point_direction(x,y,Enemy.x,Enemy.y)
        if shot = 1
        {
            instance_create(x,y,Obj_Bullet)
            shot = 0
            alarm[0] = 100
        }
    }
now Obj_Tower is ready.

3rd: create Obj_Path, make it a 32X32 green object with transparency off if you want it simple.
make Obj_Path solid. depth 1.

4th: create a path followed by your path in a room. named Path_Enemy


create Obj_End 32x32 and place at the end of your path
make it solid






5th:
Obj_Enemy

on create:
[CODE]hp = global.hp/CODE]
and set path Path_Enemy at end stop relative (sorry dunno code for this)

on destroy:
Code:
global.money = global.money + 3
on step
Code:
if hp < 1 then
{
    with (self) instance_destroy();
}
collision with bullet
Code:
hp = hp - 34

with (other) instance_destroy();
collision with Obj_End
Code:
global.live = global.live - 1
with (self) instance_destroy();
global.money = global.money - 3




6th:
Obj_Bullet
on create
Code:
Enemy = instance_nearest(x,y,Obj_Enemy)

move_towards_point(Enemy.x,Enemy.y,2);

7th:
Create Obj_Tower_Icon, and make it solid.
place it at the bottom left of the room.
On Mouse left RELEASED
Code:
if (instance_number(Obj_Tower_Place) = 0) && global.money > 4 then
{
    instance_create(mouse_x,mouse_y,Obj_Tower_Place)
    global.money = global.money - 5
}
note: there is no global.money yet.

8th: create Obj_Tower_Place, and set sprite to Spr_Tower
on create:
Code:
image_alpha = 0.5;
(sorry about this part not being code, i forget how to code theese in code)

on step
Use jump to a given position icon
x = mouse_x
y = mouse_y

on mouse left released
If there is NOT a collision at x,y with only solid
{ (start of block)
create instance Obj_Tower x,y
destroy self
} (end of block)

on right released
Code:
with (self) instance_destroy();
global.money = global.money + 5
8th:

create Obj_Control with no sprite, place on map

on create:
Code:
global.money = 10
global.hp = 68
global.hpboost = 7
global.live = 20
global.time = 0
alarm[0] = room_speed*5
alarm[1] = room_speed*120
alarm[2] = room_speed*180
alarm[3] = room_speed*240
alarm[4] = room_speed*300
alarm[5] = room_speed*1
alarm 0
Code:
instance_create(32,0,Obj_Enemy)

global.hp = global.hp + global.hpboost

alarm[0] = room_speed*5
alarm 1
Code:
global.hpboost = 8
alarm 2
Code:
global.hpboost = 9
alarm 3
Code:
global.hpboost = 10
alarm 4
Code:
global.hpboost = 11
alarm 5
Code:
global.time = global.time + 1
alarm[5] = room_speed*1
on draw
draw variable global.money x=0 y=432
draw variable global.live x=0 y=400
draw variable global.time x=0 y=368
draw variable global.hp x=0 y=336








you can get the gmk that works, as i found many errors making this tut and doing the gmk tut
this tut does not destroy the bullets, wich later will lag the game

important! the gmk is forgeting 1 thing, make the towers SOLID
Attached Files
File Type: zip TDtut.zip (17.6 KB, 4 views)
__________________
My tower defence game <-- My td game, just need a pm and u can get the key.

Next version wont be required to have a key!

Last edited by Fireblade; June 5th, 2008 at 03:19 PM.
Fireblade is offline   Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Game maker Tower Defense - HELP! lepape Code Forge 4 February 3rd, 2009 07:25 PM
New Tower Defence Game in Development Jon137 Tree Tower Defence 17 November 17th, 2008 01:15 PM
how do i make a tower defence game? likkyzero General 2 October 27th, 2008 06:29 AM
Tower Defense Game Maker Sim Code Forge 11 August 12th, 2008 07:47 PM



All times are GMT. The time now is 06:34 PM.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.