function c1Cannon::onLevelLoaded(%this, %scenegraph) { $p1Cannon = %this; //mount the machine gun onto player p1Cannon.mount(Player1Image, 1, 0.5, 0, 1, 1, 0, 0); p1Cannon.setEnabled(0); } function c1Cannon::createProjectile(%this) { %this.Cannonball = new t2dStaticSprite() { scenegraph = %this.scenegraph; class = Cannonball; player = %this; }; %this.Cannonball.shootProjectile(); } function Cannonball::shootProjectile(%this) { %this.enableUpdateCallback(); // Pick the image and set its size %this.setImageMap(cannonballImageMap1); %this.setSize(5, 5); %facing_angle_deg = $p1Cannon.getRotation(); %this.setRotation(%facing_angle_deg); %this.setLayer(3); // Turn on collision, but turn off physics %this.setCollisionActive( true, false ); %this.setCollisionPhysics(false, false); %this.setCollisionCallback(true); %this.setCollisionPolyCustom(6, "-0.388 -0.403", "0.083 -0.560","0.570 -0.162","0.467 0.452", "-0.177 0.594","-0.594 0.162"); %this.setPositionX(%this.player.getPositionX()); %this.setPositionY(%this.player.getPositionY()); %facing_angle_deg = $p1Cannon.getRotation(); %facing_angle_rad = (%facing_angle_deg / 180) * 3.142; %this.setLinearVelocityPolar(%facing_angle_deg + 90, 20*$speedmultiplier1); %this.setDamping(2.0); %cameraViewBounds = sceneWindow2D.getCurrentCameraArea(); %this.setWorldLimit( kill, getword(%cameraViewBounds, 0) - (%this.getWidth() / 2), getword(%cameraViewBounds, 1) - (%this.getHeight() / 2), getword(%cameraViewBounds, 2) + (%this.getWidth() / 2), getword(%cameraViewBounds, 3) + (%this.getHeight() / 2) ); } function Cannonball::onUpdate(%this) { $initialspeed = 20*($speedmultiplier1)*0.1; $distancetravelled = ($initialspeed*$initialspeed)/12; if ($distancetravelled > 300) $distancetravelled = 300; $currentDistance = VectorDist(%this.getPosition(), Player1Image.getPosition()); if ($currentDistance > ($distancetravelled/1.5)) { if (%this.getWidth() < 20) { $CannonballImpactHandle = alxPlay(Explosion1); Cannonexplode(%this); %this.safeDelete(); $damagedone = 0; } else { $currentWidth = %this.getWidth()-6; %this.setSize(%this.getWidth()-6, %this.getHeight()-6); } } else { $currentWidth = %this.getWidth()+6; %this.setSize(%this.getWidth()+6, %this.getHeight()+6); } } function Cannonball::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) { if (%dstObj.class $= "Player2") { $correctdist = VectorDist(Player2Image.getPosition(), Player1Image.getPosition()); if (($distancetravelled > $correctdist-40) && ($distancetravelled < $correctdist+40)) { $CannonballImpactHandle = alxPlay(Explosion1); if ($damagedone == 0) { %srcObj.dealDamage(6, %dstObj); $damagedone = 1; } Cannonexplode(%dstObj); } } if (%dstObj.class $= "trees") { $correctdist3 = VectorDist(Player1Image.getPosition(), %dstObj.getPosition()); if (($distancetravelled > $correctdist3-30) && ($distancetravelled < $correctdist3+30)) { $GrenadeImpactp2Handle = alxPlay(Explosion1); treeFire(%dstObj); } } } function Cannonexplode(%this) { %cannonExplodeEffect = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %cannonExplodeEffect.loadEffect("~/data/particles/cannonExplosion.eff"); %cannonExplodeEffect.setLayer(3); %cannonExplodeEffect.setEffectLifeMode("KILL", 1); %cannonExplodeEffect.setPosition(%this.getPosition()); %cannonExplodeEffect.playEffect(); } function treeFire(%this) { %treeBurn1 = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %treeBurn1.loadEffect("~/data/particles/campfire.eff"); %treeBurn1.setLayer(3); %treeBurn1.setEffectLifeMode("KILL", 1); %treeBurn1.setPosition(%this.getPosition()); %treeBurn1.playEffect(); } function Cannonball::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }