$BananaExplosionCountp2=0; function Ban::Player2BananaEnable(%this) { $BananaFiringp2 = 0; $BananaSplitCountp2 = 0; $fly_speed1 = 0; $prev_UVXp2_2_1 = 0; $prev_UVYp2_2_1 = 0; $prev_UVXp2_2 = 0; $prev_UVYp2_2 = 0; %this.mount(Player2Image, 0.7, 0.8, 0, 1, 1, 0, 0); } function Ban::onMouseDown(%this, %modifier, %worldPosition, %clicks) { %this.setTimerOn(100); %this.dismount(); %this.setSize(%this.getSize()*2); //%this.setPosition(40,30); } function Ban::onMouseUp(%this) { $BananaSplitCountp2 = 0; $BananaExplosionCountp2 = 0; // set firing true $BananaFiringp2 = 1; // deduct and check ammo p2BombananaAmmoCount.subtract(1); p2BombananaAmmoCount.checkCount(p2BombananaAmmoCount.text); $player2tempBan.playAnimation("BombananaAnimation", false, 1, false); %this.setSize(15,15); %this.setTimerOff(); while ($firecount > 0) { if ($duration > 40) $duration = 40; //store various variables, setting speed and calculating flying direction $fly_speed1 = ($duration * $duration / 12) + 20; %fly_dir_x = Player1Image.getPositionX() - %this.getPositionX(); %fly_dir_y = Player1Image.getPositionY() - %this.getPositionY(); %fly_v_mag = mSqrt((%fly_dir_x * %fly_dir_x) + (%fly_dir_y * %fly_dir_y)); %fly_unitVX = %fly_dir_x / %fly_v_mag; %fly_unitVY = %fly_dir_y / %fly_v_mag; %this.setLinearVelocityX(%fly_unitVX * $fly_speed1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speed1); $prev_UVXp2_2_1 = %fly_unitVX; $prev_UVYp2_2_1 = %fly_unitVY; for(%homed = 1 ; %homed < 30 ; %homed++) //set homing every 0.333 sec { schedule( (333 * %homed) , 0 , Homing1, %this); } schedule(10000, 0, timeUp1, %this); //fuse of the bombanana $firecount -= 1; $presseddur = $duration; $duration = 0; } //powerBar.setSize(0,2.5); } function Homing1(%this) { %fly_dir_x = Player1Image.getPositionX() - $player2tempBan.getPositionX(); //get new vector to target %fly_dir_y = Player1Image.getPositionY() - $player2tempBan.getPositionY(); %fly_temp_mag = mSqrt((%fly_dir_x * %fly_dir_x) + (%fly_dir_y * %fly_dir_y)); %fly_temp_unitVX = %fly_dir_x / %fly_temp_mag; %fly_temp_unitVY = %fly_dir_y / %fly_temp_mag; %fly_actual_vx = %fly_temp_unitVX + ($prev_UVXp2_2_1 / 1.5); //homing is a function of new target location and previous missile vector %fly_actual_vy = %fly_temp_unitVY + ($prev_UVYp2_2_1 / 1.5); %fly_v_mag = mSqrt((%fly_actual_vx * %fly_actual_vx) + (%fly_actual_vy * %fly_actual_vy)); %fly_unitVX = %fly_actual_vx / %fly_v_mag; %fly_unitVY = %fly_actual_vy / %fly_v_mag; %this.setLinearVelocityX(%fly_unitVX * $fly_speed1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speed1); } function Ban:: firesmallBanana(%this) { //store various variables, setting speed and calculating flying direction $fly_speed1 = 10; %fly_dir_x = Player1Image.getPositionX() - %this.getPositionX(); %fly_dir_y = Player1Image.getPositionY() - %this.getPositionY(); %fly_v_mag = mSqrt((%fly_dir_x * %fly_dir_x) + (%fly_dir_y * %fly_dir_y)); %fly_unitVX = %fly_dir_x / %fly_v_mag; %fly_unitVY = %fly_dir_y / %fly_v_mag; %this.setLinearVelocityX(%fly_unitVX * $fly_speed1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speed1); $prev_UVXp2_2 = %fly_unitVX; $prev_UVYp2_2 = %fly_unitVY; for(%homed = 1 ; %homed < 30 ; %homed++) //set homing every 0.333 sec { schedule( (333 * %homed) , 0 , smallHoming1, %this); } schedule(10000, 0, timeUp1, %this); //fuse of the bombanana } function smallHoming1(%this) { $fly_speed1 = ($duration * $duration / 12) + 20; %fly_dir_x = Player1Image.getPositionX() - %this.getPositionX(); //get new vector to target %fly_dir_y = Player1Image.getPositionY() - %this.getPositionY(); %fly_temp_mag = mSqrt((%fly_dir_x * %fly_dir_x) + (%fly_dir_y * %fly_dir_y)); %fly_temp_unitVX = %fly_dir_x / %fly_temp_mag; %fly_temp_unitVY = %fly_dir_y / %fly_temp_mag; %fly_actual_vx = %fly_temp_unitVX + ($prev_UVXp2_2 / 1.5); //homing is a function of new target location and previous missile vector %fly_actual_vy = %fly_temp_unitVY + ($prev_UVYp2_2 / 1.5); %fly_v_mag = mSqrt((%fly_actual_vx * %fly_actual_vx) + (%fly_actual_vy * %fly_actual_vy)); %fly_unitVX = %fly_actual_vx / %fly_v_mag; %fly_unitVY = %fly_actual_vy / %fly_v_mag; %this.setLinearVelocityX(%fly_unitVX * $fly_speed1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speed1); } function timeUp1(%this) { %this.explode(); } function Ban::OnTimer(%this) { $duration += 2; $firecount = 1; } function Ban::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "Player1") { %srcObj.explode(); echo("BananaSplitCountp2"); echo($BananaSplitCountp2); if(!$BananaSplitCountp2) if($BananaExplosionCountp2 <2) %srcObj.spawn(); %srcObj.dealDamage(3, %dstObj); } else return; //if(%dstObj.class $= "Player2Image") //%srcObj.explode(); } function Ban::explode(%this) { $BananaFiringp2 = 0; $MainBananaXPos = %this.getPositionx(); $MainBananaYPos = %this.getPositionY(); %this.safeDelete(); %explosion1 = new t2dParticleEffect() { sceneGraph = %this.scenegraph; }; %explosion1.loadEffect("~/data/particles/big_explosion.eff"); %explosion1.setEffectLifeMode("KILL", 1); %explosion1.setPosition(%this.getPosition()); %explosion1.playEffect(); alxPlay(BombananaExplosion); $BananaExplosionCountp2+=1; } function Ban::spawn(%this) { $BananaSplitCountp2+=1; ////// $tempBanana1 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = Ban; layer=2; CollisionActiveReceive = "1"; CollisionActiveSend = "1"; CollisionCallback = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionPolyList = "-0.128 -0.128 0.113 -1.28 0.118 0.113 -0.128 0.113"; LinkPoints = "0 0"; }; $tempBanana1.addToScene(scenegraph); $tempBanana1.setPosition(-103.247,102.734); $tempBanana1.firesmallBanana(); ////// $tempBanana2 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = Ban; layer=2; CollisionActiveReceive = "1"; CollisionActiveSend = "1"; CollisionCallback = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionPolyList = "-0.128 -0.128 0.113 -1.28 0.118 0.113 -0.128 0.113"; LinkPoints = "0 0"; }; $tempBanana2.addToScene(scenegraph); $tempBanana2.setPosition(-33.247,92.601); $tempBanana2.firesmallBanana(); ////// $tempBanana3 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = Ban; layer=2; CollisionActiveReceive = "1"; CollisionActiveSend = "1"; CollisionCallback = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionPolyList = "-0.128 -0.128 0.113 -1.28 0.118 0.113 -0.128 0.113"; LinkPoints = "0 0"; }; $tempBanana3.addToScene(scenegraph); $tempBanana3.setPosition(-34.798,-43.894); $tempBanana3.firesmallBanana(); ////// $tempBanana4 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = Ban; layer=2; CollisionActiveReceive = "1"; CollisionActiveSend = "1"; CollisionCallback = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionPolyList = "-0.128 -0.128 0.113 -1.28 0.118 0.113 -0.128 0.113"; LinkPoints = "0 0"; }; $tempBanana4.addToScene(scenegraph); $tempBanana4.setPosition(-71.753,-82.405); $tempBanana4.firesmallBanana(); ////// $tempBanana5 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = Ban; layer=2; CollisionActiveReceive = "1"; CollisionActiveSend = "1"; CollisionCallback = "1"; CollisionPhysicsReceive = "0"; CollisionPhysicsSend = "0"; CollisionPolyList = "-0.128 -0.128 0.113 -1.28 0.118 0.113 -0.128 0.113"; LinkPoints = "0 0"; }; $tempBanana5.addToScene(scenegraph); $tempBanana5.setPosition(-116.753,-38.894); $tempBanana5.firesmallBanana(); } function ban::Player1BananaRemove(%this) { %this.safeDelete(); //do self-destruct the banana onPositionTarget(%this); //effect of self-destruct } function ban::onPositionTarget(%this) { %this.safeDelete(); } function Ban ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }