zuperxtreme
02-26-2009, 07:13 PM
Hey guys, I'm just trying to make a tower defense test. Just to see if I can.
I've ran into a little problem:
1) The shooting is off. It shoots a tad too behind. I'm guessing I have to calculate the vector of the "enemy" and accommodate for the shot. I just don't know how.
2) The bullets aren't erasing correctly. They erase, but I get an error traced(Error #2025)
3) The bullets aren't rotated correctly.
If anyone needs the whole file or fla let me know.
Cheeers.
Here's most of it:
stage.addEventListener(Event.ENTER_FRAME,function( ){
shot_txt.text = String(shotCount)
//move mc to mouse position
mousePointer.x = mouseX
mousePointer.y = mouseY
//--
coord_txt.x = mouseX+10
coord_txt.y = mouseY
coord_txt.text = "x: "+mouseX+"/y: "+mouseY
//if closer than radius of tower, set the towers rotation to aim at enemy
//if(enemyArray.length){
for(var i:int = 0; i < enemyArray.length; i++){
if(getDistance(enemyArray[i], Tower) < Tower.radius){
Tower.rotation = ((Math.atan2(enemyArray[i].y-Tower.y, enemyArray[i].x-Tower.x))/Math.PI)*180
shootEnemy()
}
}
})
//-----------SHOOT AT ENEMIES------------
function shootEnemy(){
if (getTimer() - t > 500){
var newBullet:bullet_1 = new bullet_1
shotCount++
newBullet.x = Tower.x
newBullet.y = Tower.y
newBullet.rotation = Tower.rotation
addChild(newBullet)
newBullet.addEventListener(Event.ENTER_FRAME,moveB ullet)
t = getTimer();
}
}
function moveBullet(e:Event){
e.target.dirx = Math.cos(e.target.rotation*Math.PI/180);
e.target.diry = Math.sin(e.target.rotation*Math.PI/180);
e.target.x += e.target.dirx*e.target.bulletSpeed
e.target.y += e.target.diry*e.target.bulletSpeed
if(e.target.x<50 || e.target.x> 500 || e.target.y<50 || e.target.y> 350){
removeChild(MovieClip(e.target)
)
}
}
I've ran into a little problem:
1) The shooting is off. It shoots a tad too behind. I'm guessing I have to calculate the vector of the "enemy" and accommodate for the shot. I just don't know how.
2) The bullets aren't erasing correctly. They erase, but I get an error traced(Error #2025)
3) The bullets aren't rotated correctly.
If anyone needs the whole file or fla let me know.
Cheeers.
Here's most of it:
stage.addEventListener(Event.ENTER_FRAME,function( ){
shot_txt.text = String(shotCount)
//move mc to mouse position
mousePointer.x = mouseX
mousePointer.y = mouseY
//--
coord_txt.x = mouseX+10
coord_txt.y = mouseY
coord_txt.text = "x: "+mouseX+"/y: "+mouseY
//if closer than radius of tower, set the towers rotation to aim at enemy
//if(enemyArray.length){
for(var i:int = 0; i < enemyArray.length; i++){
if(getDistance(enemyArray[i], Tower) < Tower.radius){
Tower.rotation = ((Math.atan2(enemyArray[i].y-Tower.y, enemyArray[i].x-Tower.x))/Math.PI)*180
shootEnemy()
}
}
})
//-----------SHOOT AT ENEMIES------------
function shootEnemy(){
if (getTimer() - t > 500){
var newBullet:bullet_1 = new bullet_1
shotCount++
newBullet.x = Tower.x
newBullet.y = Tower.y
newBullet.rotation = Tower.rotation
addChild(newBullet)
newBullet.addEventListener(Event.ENTER_FRAME,moveB ullet)
t = getTimer();
}
}
function moveBullet(e:Event){
e.target.dirx = Math.cos(e.target.rotation*Math.PI/180);
e.target.diry = Math.sin(e.target.rotation*Math.PI/180);
e.target.x += e.target.dirx*e.target.bulletSpeed
e.target.y += e.target.diry*e.target.bulletSpeed
if(e.target.x<50 || e.target.x> 500 || e.target.y<50 || e.target.y> 350){
removeChild(MovieClip(e.target)
)
}
}