The hunt continues. It took me several hours to understand how the hitTest should work. When I finally got it I found out that it didn't always work like it supposed to. The collision between the "defender" and the "attacker" work flawless, but when the bullets hit there's a delay. Not always though, only when you fire several shots at a time. Try it out here:
http://www.reachground.se/shugoshin.html
Controls: W-A-S-D -> Fire with ENTER.
When the defender and the attacker collides the defender is supposed to move to Y-300 and X-150. When the bullets hit the attacker the defender should move to Y-300 and X-375 (this is only for testpurposes). I tried to trace it too and it only reacted to some bullets but not all.
Code:var allowfire:Number = 1; arrow_mc.onEnterFrame = function() { if (Key.isDown(68)) { this._x += 10; if(this._x >537) { this._x=537; } } if (Key.isDown(65)) { this._x -= 10; if(this._x <13) { this._x=13; } } if (Key.isDown(87)) { this._y -= 10; if(this._y <15) { this._y=15; } } if (Key.isDown(83)) { this._y += 10; if(this._y >387) { this._y=387; } } if(this.hitTest(ball)) { arrow_mc._y = 300; arrow_mc._x = 150; } arrowX = this._x; arrowY = this._y; if (Key.isDown(Key.ENTER)) { fireBullets(); } else { allowFire = 1; } } var i:Number = 1; function fireBullets() { if(allowFire == 1) { i += 1; var newname = "bullet"+i; _root.attachMovie("bullet", newname, i); // trace("bullet"+newname+i); _root[newname]._y = _root.arrow_mc._y-20; _root[newname]._x = _root.arrow_mc._x+0; allowFire = 0; _root[newname].onEnterFrame = function() { var bullet_speed = 10; this._y -= bullet_speed; if (this._y<0) { this.removeMovieClip(); } } } } var angle:Number = 0; var centerX:Number = randRange(); var range:Number = 20; var xspeed:Number = 5; var yspeed:Number = .6; ball.onEnterFrame = function() { ball._y += xspeed; ball._x = centerX + Math.sin(angle) * range; angle += yspeed; if(ball._y > 400) { ball._y = -25; centerX = randRange(); }else{ if(this.hitTest(_root["bullet"+i])) { arrow_mc._y = 300; arrow_mc._x = 375; } } } function controlFire(){ allowFire = 1; } var myListener:Object = new Object(); fireInt = setInterval(controlFire,500);




Reply With Quote