View Full Version : I need some help with a defense game.
altoid_masta
06-12-2007, 04:48 PM
I'm creating a top-down overhead defense game, kinda like Defend Your Castle, except without the click n' drag. The only thing I need to know right now is how to create waves. Like once the enemies are in (zombies), how do I get the wave to end once all of the zombies are dead?
All help is appreciated. I might come back to post more questions later.
Insane Knux
06-12-2007, 05:03 PM
I think Matt created a game of that sort. You might want to ask him.
altoid_masta
06-12-2007, 06:05 PM
I think Matt created a game of that sort. You might want to ask him.
Oh OK, I think I will. Thanks ^_^
Well after the zombie dies simply add 1 to a value called "kills" or something. Once "kills" reaches a number like 50 then goto the next level.
EXAMPLE: you will have to change and use according to your game.
kills=0
totalzombies=50
//set vars
onEnterFrame=fuction(){
//basic handler
for(var i=1;i<totalzombies;i++){
//run for loop
if(_root["zombie"+i].health<1){
//check if the value of health on all zombies labled zombie1, zombie2, zomie 3 ect
kills++
//add to kills
_root["zombie"+i].gotoAndStop("dead")
//make the zombie goto a dead frame
}
}
if(kills==50){
//if kills is equal to 50
_root.gotoAndStop("level2")
//goto a frame caleld level2
}
}
//end brackets
Insane Knux
06-12-2007, 06:42 PM
Oh OK, I think I will. Thanks ^_^
Glad to help. ^^
1. I need to make a code that ends the level once all of the enemies are dead.
2. A code that makes a healthbar go down once the enemies get too close to the stronghold.
3.Then a code that lets you replenish the health, with money.
Read the comments to know what to change AND to understand it some. Ask any questions you have.
//On the frame
kills=0
totalzombies=50
forthealth=100
//set vars
onEnterFrame=fuction(){
//basic handler
for(var i=1;i<totalzombies;i++){
//run for loop
if(_root["zombie"+i].hitTest(_root.your_fort)){
//if a zombie hits your base with the instance name of "your_fort"
forthealth-=2
//take away from the forts health
}
if(forthealth<1){
//if the fort is dead
_root.gotoAndStop("loose")
//goto a frame called loose
}
if(_root["zombie"+i].health<1){
//check if the value of health on all zombies labled zombie1, zombie2, zomie 3 ect
kills++
//add to kills
_root["zombie"+i].gotoAndStop("dead")
//make the zombie goto a dead frame
}
}
if(kills==50){
//if kills is equal to 50
_root.gotoAndStop("level2")
//goto a frame caleld level2
}
}
Now on each zombie you make. Give the the instance names of zombie1,zombie2,zombie3,zombie4 ect.
Give them this code on THEIR ActionScript panels.
onClipEvent(load){
this.health=25
}
altoid_masta
06-13-2007, 04:16 PM
WOOOAAH.... Thanks Matt:D
Now, I got one question with the code:
_root["zombie"+i].gotoAndStop("dead")
//make the zombie goto a dead frame
}
}
I don't get the gotoAndStop("dead") part. When you mean dead frame, where would that go?
(Sorry if that's a stupid question, it kinda confused me a bit.)
Double click on the zombie. Make a new frame and put an animation of him dieing. Label the frame "dead"
altoid_masta
06-13-2007, 07:33 PM
Double click on the zombie. Make a new frame and put an animation of him dieing. Label the frame "dead"
Oh OK, gotcha.
Now I got one more, that kinda stems from that one. Would I have to make the whole thing like most top-down shooters? You know, like the bullet coming out of the gun, then if it hits the zombie, it dies? You think you could teach me how to do that?
Then a last question would be getting to make the zombies move D:
Sorry if it's a bit much to ask :blush:
truimagz
06-13-2007, 07:54 PM
this.onEnterFrame = function {
var diff:Number = Math.atan2(player._y-enemy._y, player._x-enemy._x)/(Math.PI/180);
var diffRad:Number = diff*Math.PI/180;
enemy._x -= moveSpeed*Math.cos(diffRad);
enemy._y -= moveSpeed*Math.sin(diffRad);
}
altoid_masta
06-14-2007, 10:46 AM
this.onEnterFrame = function {
var diff:Number = Math.atan2(player._y-enemy._y, player._x-enemy._x)/(Math.PI/180);
var diffRad:Number = diff*Math.PI/180;
enemy._x -= moveSpeed*Math.cos(diffRad);
enemy._y -= moveSpeed*Math.sin(diffRad);
}
?
ry79418
06-14-2007, 11:12 AM
Quote:
Originally Posted by truimagz http://forums.xgenstudios.com/images/buttons/viewpost.gif (http://forums.xgenstudios.com/showthread.php?p=1515625#post1515625)
Code:
this.onEnterFrame = function {
var diff:Number = Math.atan2(player._y-enemy._y, player._x-enemy._x)/(Math.PI/180);
var diffRad:Number = diff*Math.PI/180;
enemy._x -= moveSpeed*Math.cos(diffRad);
enemy._y -= moveSpeed*Math.sin(diffRad);
}
?
?
Hmmmm the guy asked a question truimagz answered it duh:o
altoid_masta
06-14-2007, 03:24 PM
Well, I have no idea what he answered, and more importantly, where the code goes.
altoid_masta
06-14-2007, 04:53 PM
I made a very early version of it, and I have a problem with the AS. Click the link and you'll see what I mean.
http://i3.photobucket.com/albums/y83/sovellis/zombiedefense.swf
Just click on the skip button (don't watch the first part yet xP)
There's something wrong with the crosshair this is the code that I used:
onClipEvent (enterFrame) {
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
_root.yChange = Math.round(_root._ymouse-this._y);
_root.xChange = Math.round(_root._xmouse-this._x);
_root.yMove = Math.round(_root.yChange/20);
_root.xMove = Math.round(_root.xChange/20);
this._rotation = myDegrees+180;
}
ry79418
06-14-2007, 07:18 PM
make your gun MC so it faces up to start
altoid_masta
06-14-2007, 09:29 PM
make your gun MC so it faces up to start
What do you mean by that? Right now the gun and person are both one MC. Do I have to make then separate or what?
Insane Knux
06-14-2007, 09:30 PM
No; rotate to where he starts off facing up.
Double click on the gun. Now select it. Rotate it so it faces up.
altoid_masta
06-21-2007, 11:02 PM
But it IS facing up.
arkhan
06-22-2007, 08:30 AM
thats what is wrong..it should be facing RIGHt!
angles: 0º = right; 90º = down; +-180º = left; -90 = up;
altoid_masta
06-23-2007, 10:46 PM
Yeah, that didn't do ####. It's still all ####ed up.
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.