function c2Grenade::throwGrenade(%this) { %this.dismount(); %this.playAnimation("grenadeImgAnimation", false, 1, false); %this.enableUpdateCallback(); // Pick the image and set its size %this.setSize(25, 25); %facing_angle_deg = Player2Image.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(3, "0.071 -0.3140", "0.204 0.363","-0.039 0.363"); %facing_angle_deg = Player2Image.getRotation(); %facing_angle_rad = (%facing_angle_deg / 180) * 3.142; %this.setLinearVelocityPolar(%facing_angle_deg + 90, 20*$speedmultiplier2); %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) ); $p2grenadeLoaded = 0; } function c2Grenade::onUpdate(%this) { $initialspeed2 = 20*($speedmultiplier2)*0.1; $distancetravelled2 = ($initialspeed2*$initialspeed2)/12; if ($distancetravelled2 > 300) $distancetravelled2 = 300; $currentDistance2 = VectorDist(%this.getPosition(), Player2Image.getPosition()); if ($currentDistance2 > ($distancetravelled2/1.5)) { if (%this.getWidth() < 20) { $GrenadeImpactp2Handle = alxPlay(Explosion1); Grenadeexplode(%this); %this.safeDelete(); $damagedone = 0; } else { $currentWidth2 = %this.getWidth()-6; %this.setSize(%this.getWidth()-6, %this.getHeight()-6); } } else { $currentWidth2 = %this.getWidth()+6; %this.setSize(%this.getWidth()+6, %this.getHeight()+6); } } function c2Grenade::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) { if (%dstObj.class $= "Player1") { $correctdist2 = VectorDist(Player2Image.getPosition(), Player1Image.getPosition()); if (($distancetravelled2 > $correctdist2-40) && ($distancetravelled2 < $correctdist2+40)) { $GrenadeImpactp2Handle = alxPlay(Explosion1); if ($damagedone == 0) { %srcObj.dealDamage(6, %dstObj); $damagedone = 1; } Grenadeexplode(%dstObj); } } if (%dstObj.class $= "trees") { $correctdist4 = VectorDist(Player2Image.getPosition(), %dstObj.getPosition()); if (($distancetravelled2 > $correctdist4-30) && ($distancetravelled2 < $correctdist4+30)) { $GrenadeImpactp2Handle = alxPlay(Explosion1); treeFire(%dstObj); } } } function Grenadeexplode(%this) { %grenadeExplodeEffect2 = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %grenadeExplodeEffect2.loadEffect("~/data/particles/big_explosion.eff"); %grenadeExplodeEffect2.setLayer(3); %grenadeExplodeEffect2.setEffectLifeMode("KILL", 1); %grenadeExplodeEffect2.setPosition(%this.getPosition()); %grenadeExplodeEffect2.playEffect(); } function treeFire(%this) { %treeBurn = new t2dParticleEffect() { scenegraph = %this.scenegraph; }; %treeBurn.loadEffect("~/data/particles/campfire.eff"); %treeBurn.setLayer(3); %treeBurn.setEffectLifeMode("KILL", 1); %treeBurn.setPosition(%this.getPosition()); %treeBurn.playEffect(); } function c2Grenade::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }