zap284
05-09-2008, 08:33 PM
ok, im fairly new to flash so bear with me. im making a game where you play a turret and shoot at enemies that move towards you. the problem is when i tried to duplicate the enemy that moves towards you, it seemed to work, the original enemy worked fine as usual, it moved towards me and i blew it up. the duplicated enemy did move towards me but didnt explode when i shot it. im baffled... my only idea is that it has something to do with my bullets. please help.
heres the code for the turret which acts as the button btw
on (press) {
i = i + 1;
duplicateMovieClip (_root.Alien, "Alien" + i, i);
}
heres the code for the bullet
onClipEvent (load) {
xmove = _xmouse/30;
ymove = _ymouse/30;
}
//shot timer
onClipEvent (load) {
timer = 300;
}
onClipEvent (enterFrame) {
timer = timer-1;
}
onClipEvent (enterFrame) {
if (timer<1) {
this.removeMovieClip();
}
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame) {
//lets move the player's shot around
this._x = this._x+xmove;
this._y = this._y+ymove;
//destroy this if it reaches the top
if (this._y<0) {
this.removeMovieClip();
}
//test to see if this is colliding with the alien
col = _root.md(_x, _y, _root.Alien._x, _root.Alien._y);
//you can change 40 to another number if shots seem to pass through
if (col<20) {
//increments the IDs and creates an explosion
//notice that _root. is put in front
++_root.UniqueID;
++_root.ExplosionID;
_root.Explosions[_root.ExplosionID] = _root.MakeObject("Explosion", _root.ExplosionT, _root.UniqueID, _root.Alien._x, _root.Alien._y);
//"resets" the alien
_root.Alien._x = random(640);
_root.Alien._y = -5;
_root.Alien.xmove = 0;
_root.Alien.ymove = 0;
//this sets the ymovement randomly
//increases the score by one and updates the score variable for the text
++_root.scorenumber;
_root.score = "Score "+_root.scorenumber;
//puts a string and number together
//destroys this instance
//once the instance is gone, no further actions can be performed
this.removeMovieClip();
}
}
heres the code for the alien/enemy
onClipEvent(enterFrame){
_rotation = Math.atan2(_parent.PlayerShip._y-_y, _parent.PlayerShip._x-_x)*180/Math.PI+90;
_x += Math.cos((_rotation-90)*Math.PI/180)*9;
_y += Math.sin((_rotation-90)*Math.PI/180)*9;
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame)
{
//lets move the alien around
this._x = this._x + xmove;
this._y = this._y + ymove;
//bounce the alien if it is out of bounds
if(this._x > 640){xmove = Math.abs(xmove) * -1}
if(this._x < 0){xmove = Math.abs(xmove)}
if(this._y > 480){ymove = Math.abs(ymove) * -1}
if(this._y < 0){ymove = Math.abs(ymove)}
//this is to get the alien to fire randomly
fire = random(10);
//one in 40 chance of firing every frame!
if(fire == -1)
{
_root.BShotID = _root.BShotID + 1;
_root.UniqueID = _root.UniqueID + 1;
//run function to make shot
_root.BadShots[_root.BShotID]= _root.MakeObject("BShot",_root.AlienShotT,_root.UniqueID,_root.Alien._x,_r oot.Alien._y);
}
}
ok, im fairly new to flash so bear with me. im making a game where you play a turret and shoot at enemies that move towards you. the problem is when i tried to duplicate the enemy that moves towards you, it seemed to work, the original enemy worked fine as usual, it moved towards me and i blew it up. the duplicated enemy did move towards me but didnt explode when i shot it. im baffled... my only idea is that it has something to do with my bullets. please help.
heres the code for the turret which acts as the button btw
on (press) {
i = i + 1;
duplicateMovieClip (_root.Alien, "Alien" + i, i);
}
heres the code for the bullet
onClipEvent (load) {
xmove = _xmouse/30;
ymove = _ymouse/30;
}
//shot timer
onClipEvent (load) {
timer = 300;
}
onClipEvent (enterFrame) {
timer = timer-1;
}
onClipEvent (enterFrame) {
if (timer<1) {
this.removeMovieClip();
}
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame) {
//lets move the player's shot around
this._x = this._x+xmove;
this._y = this._y+ymove;
//destroy this if it reaches the top
if (this._y<0) {
this.removeMovieClip();
}
//test to see if this is colliding with the alien
col = _root.md(_x, _y, _root.Alien._x, _root.Alien._y);
//you can change 40 to another number if shots seem to pass through
if (col<20) {
//increments the IDs and creates an explosion
//notice that _root. is put in front
++_root.UniqueID;
++_root.ExplosionID;
_root.Explosions[_root.ExplosionID] = _root.MakeObject("Explosion", _root.ExplosionT, _root.UniqueID, _root.Alien._x, _root.Alien._y);
//"resets" the alien
_root.Alien._x = random(640);
_root.Alien._y = -5;
_root.Alien.xmove = 0;
_root.Alien.ymove = 0;
//this sets the ymovement randomly
//increases the score by one and updates the score variable for the text
++_root.scorenumber;
_root.score = "Score "+_root.scorenumber;
//puts a string and number together
//destroys this instance
//once the instance is gone, no further actions can be performed
this.removeMovieClip();
}
}
heres the code for the alien/enemy
onClipEvent(enterFrame){
_rotation = Math.atan2(_parent.PlayerShip._y-_y, _parent.PlayerShip._x-_x)*180/Math.PI+90;
_x += Math.cos((_rotation-90)*Math.PI/180)*9;
_y += Math.sin((_rotation-90)*Math.PI/180)*9;
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame)
{
//lets move the alien around
this._x = this._x + xmove;
this._y = this._y + ymove;
//bounce the alien if it is out of bounds
if(this._x > 640){xmove = Math.abs(xmove) * -1}
if(this._x < 0){xmove = Math.abs(xmove)}
if(this._y > 480){ymove = Math.abs(ymove) * -1}
if(this._y < 0){ymove = Math.abs(ymove)}
//this is to get the alien to fire randomly
fire = random(10);
//one in 40 chance of firing every frame!
if(fire == -1)
{
_root.BShotID = _root.BShotID + 1;
_root.UniqueID = _root.UniqueID + 1;
//run function to make shot
_root.BadShots[_root.BShotID]= _root.MakeObject("BShot",_root.AlienShotT,_root.UniqueID,_root.Alien._x,_r oot.Alien._y);
}
}
heres the swf
http://media.putfile.com/space-defense-3
if you guys need my other codes or something just ask.
ill be checking this thread twice a day at least.
heres the code for the turret which acts as the button btw
on (press) {
i = i + 1;
duplicateMovieClip (_root.Alien, "Alien" + i, i);
}
heres the code for the bullet
onClipEvent (load) {
xmove = _xmouse/30;
ymove = _ymouse/30;
}
//shot timer
onClipEvent (load) {
timer = 300;
}
onClipEvent (enterFrame) {
timer = timer-1;
}
onClipEvent (enterFrame) {
if (timer<1) {
this.removeMovieClip();
}
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame) {
//lets move the player's shot around
this._x = this._x+xmove;
this._y = this._y+ymove;
//destroy this if it reaches the top
if (this._y<0) {
this.removeMovieClip();
}
//test to see if this is colliding with the alien
col = _root.md(_x, _y, _root.Alien._x, _root.Alien._y);
//you can change 40 to another number if shots seem to pass through
if (col<20) {
//increments the IDs and creates an explosion
//notice that _root. is put in front
++_root.UniqueID;
++_root.ExplosionID;
_root.Explosions[_root.ExplosionID] = _root.MakeObject("Explosion", _root.ExplosionT, _root.UniqueID, _root.Alien._x, _root.Alien._y);
//"resets" the alien
_root.Alien._x = random(640);
_root.Alien._y = -5;
_root.Alien.xmove = 0;
_root.Alien.ymove = 0;
//this sets the ymovement randomly
//increases the score by one and updates the score variable for the text
++_root.scorenumber;
_root.score = "Score "+_root.scorenumber;
//puts a string and number together
//destroys this instance
//once the instance is gone, no further actions can be performed
this.removeMovieClip();
}
}
heres the code for the alien/enemy
onClipEvent(enterFrame){
_rotation = Math.atan2(_parent.PlayerShip._y-_y, _parent.PlayerShip._x-_x)*180/Math.PI+90;
_x += Math.cos((_rotation-90)*Math.PI/180)*9;
_y += Math.sin((_rotation-90)*Math.PI/180)*9;
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame)
{
//lets move the alien around
this._x = this._x + xmove;
this._y = this._y + ymove;
//bounce the alien if it is out of bounds
if(this._x > 640){xmove = Math.abs(xmove) * -1}
if(this._x < 0){xmove = Math.abs(xmove)}
if(this._y > 480){ymove = Math.abs(ymove) * -1}
if(this._y < 0){ymove = Math.abs(ymove)}
//this is to get the alien to fire randomly
fire = random(10);
//one in 40 chance of firing every frame!
if(fire == -1)
{
_root.BShotID = _root.BShotID + 1;
_root.UniqueID = _root.UniqueID + 1;
//run function to make shot
_root.BadShots[_root.BShotID]= _root.MakeObject("BShot",_root.AlienShotT,_root.UniqueID,_root.Alien._x,_r oot.Alien._y);
}
}
ok, im fairly new to flash so bear with me. im making a game where you play a turret and shoot at enemies that move towards you. the problem is when i tried to duplicate the enemy that moves towards you, it seemed to work, the original enemy worked fine as usual, it moved towards me and i blew it up. the duplicated enemy did move towards me but didnt explode when i shot it. im baffled... my only idea is that it has something to do with my bullets. please help.
heres the code for the turret which acts as the button btw
on (press) {
i = i + 1;
duplicateMovieClip (_root.Alien, "Alien" + i, i);
}
heres the code for the bullet
onClipEvent (load) {
xmove = _xmouse/30;
ymove = _ymouse/30;
}
//shot timer
onClipEvent (load) {
timer = 300;
}
onClipEvent (enterFrame) {
timer = timer-1;
}
onClipEvent (enterFrame) {
if (timer<1) {
this.removeMovieClip();
}
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame) {
//lets move the player's shot around
this._x = this._x+xmove;
this._y = this._y+ymove;
//destroy this if it reaches the top
if (this._y<0) {
this.removeMovieClip();
}
//test to see if this is colliding with the alien
col = _root.md(_x, _y, _root.Alien._x, _root.Alien._y);
//you can change 40 to another number if shots seem to pass through
if (col<20) {
//increments the IDs and creates an explosion
//notice that _root. is put in front
++_root.UniqueID;
++_root.ExplosionID;
_root.Explosions[_root.ExplosionID] = _root.MakeObject("Explosion", _root.ExplosionT, _root.UniqueID, _root.Alien._x, _root.Alien._y);
//"resets" the alien
_root.Alien._x = random(640);
_root.Alien._y = -5;
_root.Alien.xmove = 0;
_root.Alien.ymove = 0;
//this sets the ymovement randomly
//increases the score by one and updates the score variable for the text
++_root.scorenumber;
_root.score = "Score "+_root.scorenumber;
//puts a string and number together
//destroys this instance
//once the instance is gone, no further actions can be performed
this.removeMovieClip();
}
}
heres the code for the alien/enemy
onClipEvent(enterFrame){
_rotation = Math.atan2(_parent.PlayerShip._y-_y, _parent.PlayerShip._x-_x)*180/Math.PI+90;
_x += Math.cos((_rotation-90)*Math.PI/180)*9;
_y += Math.sin((_rotation-90)*Math.PI/180)*9;
}
//this is triggered everytime a new frame is entered, in this case 30 times a sec
onClipEvent (enterFrame)
{
//lets move the alien around
this._x = this._x + xmove;
this._y = this._y + ymove;
//bounce the alien if it is out of bounds
if(this._x > 640){xmove = Math.abs(xmove) * -1}
if(this._x < 0){xmove = Math.abs(xmove)}
if(this._y > 480){ymove = Math.abs(ymove) * -1}
if(this._y < 0){ymove = Math.abs(ymove)}
//this is to get the alien to fire randomly
fire = random(10);
//one in 40 chance of firing every frame!
if(fire == -1)
{
_root.BShotID = _root.BShotID + 1;
_root.UniqueID = _root.UniqueID + 1;
//run function to make shot
_root.BadShots[_root.BShotID]= _root.MakeObject("BShot",_root.AlienShotT,_root.UniqueID,_root.Alien._x,_r oot.Alien._y);
}
}
heres the swf
http://media.putfile.com/space-defense-3
if you guys need my other codes or something just ask.
ill be checking this thread twice a day at least.