$BananaExplosionCountp1=0; function Ban1::Player1BananaEnable(%this) { $BananaFiringp1 = 0; $BananaSplitCountp1 = 0; $fly_speedp1 = 0; $prev_UVXp1_2_1 = 0; $prev_UVYp1_2_1 = 0; $prev_UVXp1_2 = 0; $prev_UVYp1_2 = 0; %this.mount(Player1Image, 0.9, 1.1, 0, 1, 1, 0, 0); } function Ban1::onMouseDown(%this, %modifier, %worldPosition, %clicks) { %this.dismount(); %this.setSize(%this.getSize()*1.5); $BananaSplitCountp1 = 0; $BananaExplosionCountp1 = 0; // deduct and check ammo if(!$BananaFiringp1) p1BombananaAmmoCount.subtract(1); p1BombananaAmmoCount.checkCount(p1BombananaAmmoCount.text); // set firing true $BananaFiringp1 = 1; alxStop($Banp1Handle); $Banp1Handle = alxPlay(BanHoming); $player1tempBan.playAnimation("BombananaAnimation", false, 1, false); %this.firemainBanana(); } function Ban1::onTouchDown(%this, %modifier, %worldPosition, %clicks) { //%this.setTimerOn(100); %this.dismount(); %this.setSize(%this.getSize()*1.5); $BananaSplitCountp1 = 0; $BananaExplosionCountp1 = 0; // deduct and check ammo if(!$BananaFiringp1) p1BombananaAmmoCount.subtract(1); p1BombananaAmmoCount.checkCount(p1BombananaAmmoCount.text); // set firing true $BananaFiringp1 = 1; $player1tempBan.playAnimation("BombananaAnimation", false, 1, false); %this.firemainBanana(); //%this.setPosition(40,30); } function Homingp1(%this) { %fly_dir_x = Player2Image.getPositionX() - $player1tempBan.getPositionX(); //get new vector to target %fly_dir_y = Player2Image.getPositionY() - $player1tempBan.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_UVXp1_2_1 / 1.5); //homing is a function of new target location and previous missile vector %fly_actual_vy = %fly_temp_unitVY + ($prev_UVYp1_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_speedp1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speedp1); } function Ban1:: firemainBanana(%this) { %this.setSize(15,15); //store various variables, setting speed and calculating flying direction $fly_speedp1 = 36; %fly_dir_x = Player2Image.getPositionX() - %this.getPositionX(); %fly_dir_y = Player2Image.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_speedp1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speedp1); $prev_UVXp1_2 = %fly_unitVX; $prev_UVYp1_2 = %fly_unitVY; for(%homed = 1 ; %homed < 30 ; %homed++) //set homing every 0.333 sec { schedule( (333 * %homed) , 0 , Homingp1, %this); } schedule(10000, 0, timeUp_p1, %this); //fuse of the bombanana } function sBan1:: firesmallBanana(%this) { //store various variables, setting speed and calculating flying direction $fly_speedp1 = 6; %fly_dir_x = Player2Image.getPositionX() - %this.getPositionX(); %fly_dir_y = Player2Image.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_speedp1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speedp1); $prev_UVXp1_2 = %fly_unitVX; $prev_UVYp1_2 = %fly_unitVY; for(%homed = 1 ; %homed < 30 ; %homed++) //set homing every 0.333 sec { schedule( (333 * %homed) , 0 , smallHomingp1, %this); } schedule(10000, 0, timeUp_p1, %this); //fuse of the bombanana } function smallHomingp1(%this) { $fly_speedp1 = ($duration * $duration / 12) + 20; %fly_dir_x = Player2Image.getPositionX() - %this.getPositionX(); //get new vector to target %fly_dir_y = Player2Image.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_UVXp1_2 / 1.5); //homing is a function of new target location and previous missile vector %fly_actual_vy = %fly_temp_unitVY + ($prev_UVYp1_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_speedp1); //to set the bombanana speed %this.setLinearVelocityY(%fly_unitVY * $fly_speedp1); } function timeUp_p1(%this) { %this.explodep1(); } function Ban1::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "Player2") { %srcObj.explodep1(); %srcObj.spawn(); %srcObj.dealDamage(3, %dstObj); } if(%dstObj.class $= "trees") if($BananaFiringp1) { %srcObj.explodep1(); $BananaExplosionCountp1=0; } else return; } function sBan1::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "Player2") { %srcObj.explodep1(); %srcObj.dealDamage(3, %dstObj); } if(%dstObj.class $= "trees") if($BananaFiringp1) { %srcObj.explodep1(); $BananaExplosionCountp1=0; } else return; } function sBan1::explodep1(%this) { alxStop($Banp1Handle); $BananaFiringp1 = 0; $MainBananaXPos_p1 = %this.getPositionx(); $MainBananaYPos_p1 = %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); $BananaExplosionCountp1+=1; } function Ban1::explodep1(%this) { alxStop($Banp1Handle); $BananaFiringp1 = 0; $MainBananaXPos_p1 = %this.getPositionx(); $MainBananaYPos_p1 = %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); $BananaExplosionCountp1+=1; } function Ban1::spawn(%this) { $BananaSplitCountp1+=1; ////// $tempBananap1_1 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan1; 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"; }; $tempBananap1_1.addToScene(scenegraph); $tempBananap1_1.setPosition(36,-65); $tempBananap1_1.firesmallBanana(); ////// $tempBananap1_2 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan1; 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"; }; $tempBananap1_2.addToScene(scenegraph); $tempBananap1_2.setPosition(110,-60); $tempBananap1_2.firesmallBanana(); ////// $tempBananap1_3 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan1; 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"; }; $tempBananap1_3.addToScene(scenegraph); $tempBananap1_3.setPosition(102,45); $tempBananap1_3.firesmallBanana(); ////// $tempBananap1_4 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan1; 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"; }; $tempBananap1_4.addToScene(scenegraph); $tempBananap1_4.setPosition(42,80); $tempBananap1_4.firesmallBanana(); ////// $tempBananap1_5 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan1; 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"; }; $tempBananap1_5.addToScene(scenegraph); $tempBananap1_5.setPosition(32,20); $tempBananap1_5.firesmallBanana(); } function Ban1 ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); } function sBan1 ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }