var i:int = projectiles.length; var x:int = 0; var cleanx = -1; //status.text = "test"; while (x < i) { if (projectiles.getItemAt(x).added == false) { add(projectiles.getItemAt(x).bullet); projectiles.getItemAt(x).added = true; var radAngle : Number = projectiles.getItemAt(x).angle * (Math.PI /180); projectiles.getItemAt(x).bullet.velocity.x = Math.cos(radAngle) * 150; projectiles.getItemAt(x).bullet.velocity.y = Math.sin(radAngle) * 150; projectiles.getItemAt(x).counts = projectiles.getItemAt(x).counts + 1; // FlxG.overlap(projectiles.getItemAt(x).bullet, level , function(e:FlxSprite, p:FlxTilemap):void { //score.text = "WOWWW"; //}); } if (projectiles.getItemAt(x).added == true) { // FlxG.collide(projectiles.getItemAt(x).bullet, level, function(e:FlxSprite, p:FlxTilemap):void { //projectiles.getItemAt(x).clean = true; //cleanx = x; //bouncing? e.velocity = currentPos - collisionPoint //}); // var workedx:uint = Math.round((projectiles.getItemAt(x).bullet.x-2) / FlxG.width*40); // var workedy:uint = Math.round((projectiles.getItemAt(x).bullet.y - 4) / (240) * 30 ); //score.text = String(level.getTile(workedx, workedy)); var proj = projectiles.getItemAt(x); var futurex:uint = Math.round((proj.bullet.x + proj.bullet.velocity.x -2 ) / FlxG.width*40); var futurey:uint = Math.round((proj.bullet.y + proj.bullet.velocity.y - 4 ) / (240) * 30 ); if (level.getTile(futurex, futurey) != 0) { //Collision ! // Now to check if it hit vertically or horizontally var currentx:uint = Math.round((proj.bullet.x -2 ) / FlxG.width*40); var currenty:uint = Math.round((proj.bullet.y- 4 ) / (240) * 30 ); if (level.getTile(futurex, currenty) != 0) proj.bullet.velocity.x = -proj.bullet.velocity.x; // Horizontal hit ! if (level.getTile(currentx, futurey) != 0) proj.bullet.velocity.y = -proj.bullet.velocity.y; // Vertical hit ! } //status.text = "added" + projectiles.getItemAt(x).destinationx; // projectiles.getItemAt(x).bullet.x++; //projectiles.getItemAt(x).bullet.y = projectiles.getItemAt(x).destinationy; var ix:int = players.length; var xx:int = 0; //status.text = "test"; while (xx < ix) { // FlxG.overlap(players.getItemAt(xx).player,projectiles.getItemAt(x).bullet,doHealth); if (distance(players.getItemAt(xx).player, projectiles.getItemAt(x).bullet) == true && projectiles.getItemAt(x).owner != players.getItemAt(xx).id ) { if ( projectiles.getItemAt(x).team != players.getItemAt(xx).team) { remove(projectiles.getItemAt(x).bullet); projectiles.removeItemAt(x); doHealth(xx); } } xx++; } } if (projectiles.getItemAt(x).bullet.x > projectiles.getItemAt(x).fromx + 70 || projectiles.getItemAt(x).bullet.y > projectiles.getItemAt(x).fromy + 70 || projectiles.getItemAt(x).bullet.x < projectiles.getItemAt(x).fromx - 70 || projectiles.getItemAt(x).bullet.y < projectiles.getItemAt(x).fromy - 70 ){ //remove(projectiles.getItemAt(x).bullet); //projectiles.getItemAt(x).clean = true; // cleanx = x; //FlxG.collide(projectiles.getItemAt(x).bullet, level, function(e:bullet):void { //G.log("collision!"); // }); } //status.text = projectiles.getItemAt(x).counts; if (projectiles.getItemAt(x).counts > 170) { cleanx = x; projectiles.getItemAt(x).clean = true; } x++; } if (cleanx > -1) { remove(projectiles.getItemAt(cleanx).bullet); projectiles.removeItemAt(cleanx); }