function c1Grenade::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 = Player1Image.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 = Player1Image.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) ); $p1grenadeLoaded = 0; } function c1Grenade::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) { $GrenadeImpactHandle = alxPlay(Explosion1); Grenadeexplode(%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 c1Grenade::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)) { $GrenadeImpactHandle = alxPlay(Explosion1); if ($damagedone == 0) { %srcObj.dealDamage(6, %dstObj); $damagedone = 1; } Grenadeexplode(%dstObj); } } if (%dstObj.class $= "trees") { $correctdist3 = VectorDist(Player1Image.getPosition(), %dstObj.getPosition()); if (($distancetravelled > $correctdist3-30) && ($distancetravelled < $correctdist3+30)) { $GrenadeImpactp2Handle = alxPlay(Explosion1); treeFire(%dstObj); } } } function Grenadeexplode(%this) { %grenadeExplodeEffect = new t2dParticleEffect() { scenegraph = Player1Image.scenegraph; }; %grenadeExplodeEffect.loadEffect("~/data/particles/big_explosion.eff"); %grenadeExplodeEffect.setLayer(3); %grenadeExplodeEffect.setEffectLifeMode("KILL", 1); %grenadeExplodeEffect.setPosition(%this.getPosition()); %grenadeExplodeEffect.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 c1Grenade::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }