|
|
#1 | ||||||||||||||
|
Ice Turret
Join Date: Aug 2007
Posts: 492
![]() |
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 Code:
shot = 1 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
}
}
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 Code:
if hp < 1 then
{
with (self) instance_destroy();
}
Code:
hp = hp - 34 with (other) instance_destroy(); 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
}
8th: create Obj_Tower_Place, and set sprite to Spr_Tower on create: Code:
image_alpha = 0.5; 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 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 Code:
instance_create(32,0,Obj_Enemy) global.hp = global.hp + global.hpboost alarm[0] = room_speed*5 Code:
global.hpboost = 8 Code:
global.hpboost = 9 Code:
global.hpboost = 10 Code:
global.hpboost = 11 Code:
global.time = global.time + 1 alarm[5] = room_speed*1 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
__________________
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. |
||||||||||||||
|
|
|
||||||||||||||
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |