SeriWolk
07-22-2011, 12:52 PM
Bullet:
var bullet:MovieClip;
//+other vars needed below
function bulletFire(){
if(reloadComplete==true){
bullet = attachMovie("bullet", "bullet_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_b_x, _y:start_b_y});
bullet._rotation=player._rotation;//bullet rotation
bullet.bulletLifeTimer = 0;
//bullet offset
randomNum = Math.random() * bulletOffset - (bulletOffset / 2);
var bulletAngle = player._rotation-90 + randomNum;
bullet.dirx = Math.cos(bulletAngle*Math.PI/180)*firePower;
bullet.diry = Math.sin(bulletAngle*Math.PI/180)*firePower;
bullet.onEnterFrame = function() {
//moving bullet
this._x += this.dirx;
this._y += this.diry;
//checking bullet lifetime
if (this.bulletLifeTimer>=bulletLifeTimerTotal) {
this.removeMovieClip();//delete the bullet
}
this.bulletLifeTimer++; };
}
startReloading();
}
}
function startReloading()
{
reloadComplete = false;//reload started
reloadTimer = setInterval(gunReloaded, reloadSpeed);//pistol - 350, smg - 100
}
function gunReloaded()
{
clearInterval(reloadTimer);//clear timer
reloadComplete = true;//reload complete
}
Zombie:
function enemy(){
for(i=1;i<=20;i++){
if(enemySpawned==false){
if(i<20){
attachMovie("zombie","zombie_"+i,100+i,{_x:random(800),_y:random(800),enemyHp:10 });
}
}
if(i==20){
enemySpawned=true;
}
_root["zombie_"+i].onEnterFrame = function(){
if(this.hitTest(bullet)){
crit=random(10);
if(crit==0){
this.removeMovieClip();//10% of headshot
}else{
this.enemyHp-=dm;
}
bullet.removeMovieClip();
if(this.enemyHp<=0){
this.removeMovieClip();
}
}
}
}
}
The code is simplified to the max, so the problem occured when i added a smg - the bullets started to ignore the zombies, they fly right through them, but only if shooting in auto mode(10 bullets in 1 second), if i shoot 1-2 bullets at a time or shoot rapidly, but close(~<150px) to the zombies - the zombies get hit. What could be the problem?
var bullet:MovieClip;
//+other vars needed below
function bulletFire(){
if(reloadComplete==true){
bullet = attachMovie("bullet", "bullet_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_b_x, _y:start_b_y});
bullet._rotation=player._rotation;//bullet rotation
bullet.bulletLifeTimer = 0;
//bullet offset
randomNum = Math.random() * bulletOffset - (bulletOffset / 2);
var bulletAngle = player._rotation-90 + randomNum;
bullet.dirx = Math.cos(bulletAngle*Math.PI/180)*firePower;
bullet.diry = Math.sin(bulletAngle*Math.PI/180)*firePower;
bullet.onEnterFrame = function() {
//moving bullet
this._x += this.dirx;
this._y += this.diry;
//checking bullet lifetime
if (this.bulletLifeTimer>=bulletLifeTimerTotal) {
this.removeMovieClip();//delete the bullet
}
this.bulletLifeTimer++; };
}
startReloading();
}
}
function startReloading()
{
reloadComplete = false;//reload started
reloadTimer = setInterval(gunReloaded, reloadSpeed);//pistol - 350, smg - 100
}
function gunReloaded()
{
clearInterval(reloadTimer);//clear timer
reloadComplete = true;//reload complete
}
Zombie:
function enemy(){
for(i=1;i<=20;i++){
if(enemySpawned==false){
if(i<20){
attachMovie("zombie","zombie_"+i,100+i,{_x:random(800),_y:random(800),enemyHp:10 });
}
}
if(i==20){
enemySpawned=true;
}
_root["zombie_"+i].onEnterFrame = function(){
if(this.hitTest(bullet)){
crit=random(10);
if(crit==0){
this.removeMovieClip();//10% of headshot
}else{
this.enemyHp-=dm;
}
bullet.removeMovieClip();
if(this.enemyHp<=0){
this.removeMovieClip();
}
}
}
}
}
The code is simplified to the max, so the problem occured when i added a smg - the bullets started to ignore the zombies, they fly right through them, but only if shooting in auto mode(10 bullets in 1 second), if i shoot 1-2 bullets at a time or shoot rapidly, but close(~<150px) to the zombies - the zombies get hit. What could be the problem?