From c069051001b56d4f388407052c8750046b5f9bc7 Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Fri, 13 Apr 2018 18:33:04 +0200 Subject: [PATCH] =?UTF-8?q?fall=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OGP1718-Worms/src/worms/model/Worm.java | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index ec3ec2c..d65297b 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -832,25 +832,29 @@ public class Worm extends GameObject { //=================================================================================== public void fall() { - double[] center = {getLocation().getX(), getLocation().getY()}; + double heigth = getWorld().getHeight() - getRadius(); Coordinate oldLocation = getLocation(); - double endY = getLocation().getY(); if (canFall()) { - for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) { - if (y >= (getWorld().getHeight() + 1)) { - terminate(); - } + for (double y = oldLocation.getY(); y <= heigth; y = y - 0.1) { double[] newLoc = {oldLocation.getX(), y}; - setLocation(newLoc); - if (! canFall()) { - endY = y; + if (! getWorld().isPassable(newLoc, getRadius())) { + setLocation(newLoc); break; } - center[1] = y; +// for (double i = y; i >= y - 1; i = i - 0.1) { +// double[] newLocation = {oldLocation.getX(), i}; +// if (! getWorld().isPassable(newLocation, getRadius())) { +// setLocation(newLocation); +// endY = i; +// break; +// } +// } } + + terminate(); } - long cost = 3 * (long) Math.floor(oldLocation.getY() - endY); + long cost = 3 * (long) Math.floor(oldLocation.getY() - getLocation().getY()); decreaseHitPoints(cost); }