From 8c7a078aa1e1d1d16b94fa72dc83279ad0432e8a Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Fri, 4 May 2018 15:15:50 +0200 Subject: [PATCH] Worm: projectile --- OGP1718-Worms/src/worms/model/Worm.java | 43 ++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 2855e06..a2a9d0f 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -1225,16 +1225,49 @@ public class Worm extends GameObject { } // region firing and projectiles //=================================================================================== + private double[] locationProj; + private double massProj; + private long hitpointsProj; + private double forceProj; + public void fire() { - + if (getActionPoints() >= 30 && getWorld() != null) { + Random r = new Random(); + int random = r.nextInt((1 - 0) + 1); + locationProj[0] = cos(getOrientation())*getRadius(); + locationProj[1] = sin(getOrientation())*getRadius(); + if (random == 0) { + propertiesRifle(); + decreaseActionPoints(10); + } + else { + propertiesBazooka(); + decreaseActionPoints(25); + } + new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj); + } } - public void createRifle() { - + public void propertiesRifle() { + massProj = 10; + forceProj = 1.5; + Random r = new Random(); + hitpointsProj = 0 + r.nextInt((10-0)/2) *2; } - public void createBazooka() { - + public void propertiesBazooka() { + massProj = 300; + forceProj = 2.5 + getActionPoints()/8; + Random r = new Random(); + hitpointsProj = 0 + r.nextInt((10-0)/(2+1)) *(2+1); + } + + public void hitByRifle() { + decreaseHitPoints(hitpointsProj); + } + + public void hitByBazooka() { + decreaseHitPoints(hitpointsProj * (long) forceProj); } // =================================================================================== // endregion