$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.9, 1.1, 0, 1, 1, 0, 0); } function Ban::onMouseDown(%this, %modifier, %worldPosition, %clicks) { %this.dismount(); %this.setSize(%this.getSize()*1.5); $BananaSplitCountp2 = 0; $BananaExplosionCountp2 = 0; // deduct and check ammo if(!$BananaFiringp2) p2BombananaAmmoCount.subtract(1); p2BombananaAmmoCount.checkCount(p2BombananaAmmoCount.text); // set firing true $BananaFiringp2 = 1; alxStop($Banp2Handle); $Banp2Handle = alxPlay(BanHoming); $player2tempBan.playAnimation("BombananaAnimation", false, 1, false); %this.firemainBanana(); } function Ban::onTouchDown(%this, %event) { %this.dismount(); %this.setSize(%this.getSize()*1.5); $BananaSplitCountp2 = 0; $BananaExplosionCountp2 = 0; // deduct and check ammo if(!$BananaFiringp2) p2BombananaAmmoCount.subtract(1); p2BombananaAmmoCount.checkCount(p2BombananaAmmoCount.text); // set firing true $BananaFiringp2 = 1; alxStop($Banp2Handle); $Banp2Handle = alxPlay(BanHoming); $player2tempBan.playAnimation("BombananaAnimation", false, 1, false); %this.firemainBanana(); } 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:: firemainBanana(%this) { %this.setSize(15,15); //store various variables, setting speed and calculating flying direction $fly_speed1 = 36; %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 , Homing1, %this); } schedule(10000, 0, timeUp1, %this); //fuse of the bombanana } function sBan:: firesmallBanana(%this) { //store various variables, setting speed and calculating flying direction $fly_speed1 = 6; %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::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "Player1") { %srcObj.explode(); %srcObj.spawn(); %srcObj.dealDamage(3, %dstObj); } if(%dstObj.class $= "trees") if($BananaFiringp2) { %srcObj.explode(); $BananaExplosionCountp2=0; } else return; } function sBan::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) { if(%dstObj.class $= "Player1") { %srcObj.explode(); %srcObj.dealDamage(3, %dstObj); } if(%dstObj.class $= "trees") if($BananaFiringp2) { %srcObj.explode(); $BananaExplosionCountp2=0; } else return; } function Ban::explode(%this) { alxStop($Banp2Handle); $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 sBan::explode(%this) { alxStop($Banp2Handle); $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 = sBan; 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(-110,-26); $tempBanana1.firesmallBanana(); ////// $tempBanana2 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan; 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(-76,-68); $tempBanana2.firesmallBanana(); ////// $tempBanana3 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan; 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(-50,-47); $tempBanana3.firesmallBanana(); ////// $tempBanana4 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan; 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(-40,76); $tempBanana4.firesmallBanana(); ////// $tempBanana5 = new t2dAnimatedSprite() { animationName="spawnSmallAnimation"; scenegraph = %this.scenegraph; class = sBan; 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(-103,90); $tempBanana5.firesmallBanana(); } function Ban ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); } function sBan ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); } function disableP2Bombanana() { p2BombananaAmmoCount.setLayer(30); $p2BombananaEnabled = false; Player2BombananaAmmoConsole.setUseTouchEvents(false); Player2BombananaAmmoConsole.setUseMouseEvents(false); } function enableP2Bombanana() { p2BombananaAmmoCount.setLayer(1); $p2BombananaEnabled = true; Player2BombananaAmmoConsole.setUseTouchEvents(true); Player2BombananaAmmoConsole.setUseMouseEvents(false); }