Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var maxDist:int = MathX.getDist(ship,y,screenTopY) // the max distance the primary arc beam can travel
- var moveHops:Number = 3; // the number of pixels between each collision check, pixel by pixel would be expensive and unnecessary
- var arcPoint:Point; // a temporary point to represent where the arc bolt currently is whilst moving
- var secondaryRadius:int 60; // the max radius a secondary arc can jump to.
- var maxSecondaryTargets:int = 3; // max number of secondary targets an arc bolt can jump to
- // test primary bolt - handles the movement and collision test of the main bolt and calls the secondary test if the primary on hits an enemy target
- function primaryArcBoltCalculation(){
- arcPoint = new Point(ship.x,ship.y)
- for(var i:int = maxDist / moveHops;i>0;i--){
- arcPoint.y -= moveHops
- // test collision against enemies
- for(var e:int = enemies.length-1;e>=0;e--){
- if(enemies[e].hitTestPoint(arcPoint.x,arcPoint.y,true)){
- // enemy has been hit, damage it
- enemies[e].takeDamage();
- // set i to 0 to stop the bolt moving any further
- i = 0
- // set off the test for secondary points
- secondaryArcBoltsCaluclation(arcPoint)
- // create visual special effect of the arc bolt
- effectsMan.createArcLightning(ship,arcPoint)
- }
- else if(arcPoint.y <= screenTopY){
- // arcPoint has reached the top without hitting anything, create missed bolt effect
- effectsMan.createArcLightning(ship,screenTopY)
- i = 0;
- // player has missed the shot
- }
- }
- // test secondary bolts
- function secondaryArcBoltsCaluclation(testPoint:Point){
- var secondaryTargets = Math.min(maxSecondaryTargets,enemies.length) // check the number of targets to test against
- for(var i:int = secondaryTargets;i>0;i--){
- for(var e:int = enemies.length-1;e>=0;e--){
- if(MathX.getDist(testPoint,enemies[e]) <= secondaryRadius){
- // enemy is within arc jump radius, damage it
- // show visual effect
- effectsMan.createArcLightning(testPoint,enemies[e])
- enemies[e].takeDamage();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement