From 742ff1eafca32a30180a5f4a32f8d3048741b3e2 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 9 Dec 2014 11:01:43 +0100 Subject: [PATCH 1/5] Bugfix: Shield makes player get remaining damage as hp. --- src/de/teamteamteam/spacescooter/entity/LivingEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 048cf4b..7d0b3fd 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -104,7 +104,7 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable return; if (this.shieldPoints > 0) { if (this.shieldPoints < damage) { - this.healthPoints = (damage - this.shieldPoints); + this.healthPoints -= (damage - this.shieldPoints); this.shieldPoints = 0; } else { this.shieldPoints -= damage; From 5610ff78067735f2991108f9d6553f18db40d464 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 9 Dec 2014 11:03:02 +0100 Subject: [PATCH 2/5] Performance: Maybe this fixes very big frame times. --- src/de/teamteamteam/spacescooter/GameFrame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/teamteamteam/spacescooter/GameFrame.java b/src/de/teamteamteam/spacescooter/GameFrame.java index fa2973d..bf4f8f2 100644 --- a/src/de/teamteamteam/spacescooter/GameFrame.java +++ b/src/de/teamteamteam/spacescooter/GameFrame.java @@ -148,8 +148,8 @@ public class GameFrame extends JFrame { bufferedGraphics.dispose(); } } while (this.bufferStrategy.contentsRestored()); //Redraw in case the VolatileImage was restored - this.bufferStrategy.show(); //Show the drawn image } while (this.bufferStrategy.contentsLost()); //Redraw in case the VolatileImage got lost + this.bufferStrategy.show(); //Show the drawn image Toolkit.getDefaultToolkit().sync(); //Tell the OS to update its graphics of the window. this.frameTime = System.nanoTime() - frameStart; //Update frameTime } From c810d9d966c8ab319320282ad4833453cdc95b1e Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 9 Dec 2014 11:15:48 +0100 Subject: [PATCH 3/5] Bugfix: Level does not care after the last interval ended. --- .../spacescooter/level/Level.java | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index 0509123..9c67e9b 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -84,37 +84,40 @@ public final class Level { public void handleUpdateTick() { //Check whether the current interval is configured int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock); - if(currentIntervalIndex == -1) return; //Nothing to do - //Fetch the current interval - int[] currentInterval = this.config.intervalList.get(currentIntervalIndex); - int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0]; - int intervalLength = currentInterval[1] - currentInterval[0]; - /* - * @see - * Get all the spawnrules for the current interval. - * - 0: Interval this rule belongs to - * - 1: EntityNumber - This helps to find out what Entity to actually spawn. - * - 2: Amount - The amount of Entities to spawn at a time. - * - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. - * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn. - */ - for(int[] spawnRule : this.config.spawnRuleList) { - //Skip spawn rules that are not in the current spawn interval. - if(spawnRule[0] != currentIntervalIndex) continue; - //Divide the current interval by spawnrate - int intervalModulus = intervalLength / spawnRule[3]; - //Check whether the spawn rate strikes right now. - if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) { - //If the rule matches the current time, spawn the configured Entity in the configured amount: - for(int i=0; i + * Get all the spawnrules for the current interval. + * - 0: Interval this rule belongs to + * - 1: EntityNumber - This helps to find out what Entity to actually spawn. + * - 2: Amount - The amount of Entities to spawn at a time. + * - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. + * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn. + */ + for(int[] spawnRule : this.config.spawnRuleList) { + //Skip spawn rules that are not in the current spawn interval. + if(spawnRule[0] != currentIntervalIndex) continue; + //Divide the current interval by spawnrate + int intervalModulus = intervalLength / spawnRule[3]; + //Check whether the spawn rate strikes right now. + if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) { + //If the rule matches the current time, spawn the configured Entity in the configured amount: + for(int i=0; i Date: Tue, 9 Dec 2014 11:15:55 +0100 Subject: [PATCH 4/5] make debug playing easier :p --- res/levels/test.level | 7 ------- 1 file changed, 7 deletions(-) diff --git a/res/levels/test.level b/res/levels/test.level index 2d2d832..c22ddb7 100644 --- a/res/levels/test.level +++ b/res/levels/test.level @@ -6,13 +6,6 @@ background:CloudBackground spawn:EnemyBoss,1,1,50 [1-2] spawn:StoneOne,2,1,0 -spawn:StoneOne,2,1,10 -spawn:StoneTwo,2,1,20 -spawn:StoneOne,2,1,30 -spawn:StoneTwo,2,1,40 -spawn:EnemyOne,2,1,50 -spawn:StoneOne,2,1,60 -spawn:StoneThree,2,1,70 spawn:StoneOne,2,1,80 spawn:StoneThree,2,1,90 spawn:StoneThree,2,1,100 From 73f948b4e1238ca5b46d6ab7fa328be8703dba96 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 9 Dec 2014 11:58:31 +0100 Subject: [PATCH 5/5] Feature: Add centered hitboxes that can have seperate dimensions. --- .../spacescooter/control/Keyboard.java | 4 + .../spacescooter/entity/CollidableEntity.java | 86 +++++++++++++++++++ .../spacescooter/entity/Entity.java | 29 ++++--- .../spacescooter/entity/Player.java | 2 +- .../spacescooter/entity/enemy/Enemy.java | 2 +- .../spacescooter/entity/enemy/EnemyBoss.java | 6 +- .../entity/explosion/ExplosionOne.java | 2 +- .../entity/explosion/ExplosionTwo.java | 2 +- .../spacescooter/entity/item/Item.java | 2 +- .../entity/obstacle/StoneOne.java | 1 + .../entity/obstacle/StoneThree.java | 1 + .../entity/obstacle/StoneTwo.java | 1 + .../spacescooter/entity/shot/BeamImage.java | 1 - .../spacescooter/entity/shot/Shot.java | 4 +- .../spacescooter/entity/spi/Collidable.java | 22 +++-- .../gui/SecondaryWeaponAmount.java | 1 - .../utility/CollisionHandler.java | 20 ++--- 17 files changed, 144 insertions(+), 42 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/control/Keyboard.java b/src/de/teamteamteam/spacescooter/control/Keyboard.java index 104a756..dcb3bc2 100644 --- a/src/de/teamteamteam/spacescooter/control/Keyboard.java +++ b/src/de/teamteamteam/spacescooter/control/Keyboard.java @@ -11,6 +11,7 @@ import de.teamteamteam.spacescooter.entity.enemy.EnemyOne; import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo; import de.teamteamteam.spacescooter.entity.item.ItemNuke; +import de.teamteamteam.spacescooter.screen.GameScreen; /** * This is our main control input source. @@ -126,6 +127,9 @@ public class Keyboard implements KeyListener { if(e.getKeyCode() == KeyEvent.VK_0) { new EnemyBoss(400,400); } + if(e.getKeyCode() == KeyEvent.VK_5) { + GameScreen.getPlayer().setCollide(!GameScreen.getPlayer().canCollide()); + } } diff --git a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java index 9fb7712..761780f 100644 --- a/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/CollidableEntity.java @@ -1,5 +1,9 @@ package de.teamteamteam.spacescooter.entity; +import java.awt.Color; +import java.awt.Graphics2D; + +import de.teamteamteam.spacescooter.brain.GameConfig; import de.teamteamteam.spacescooter.entity.spi.Collidable; /** @@ -22,6 +26,16 @@ public abstract class CollidableEntity extends Entity implements Collidable { */ private boolean damaging; + /** + * Height of the hitbox. + */ + private int hitboxHeight; + + /** + * Width of the hitbox. + */ + private int hitboxWidth; + /** * Default constructor. Initializes sane defaults. @@ -32,6 +46,78 @@ public abstract class CollidableEntity extends Entity implements Collidable { this.setDamaging(true); } + /** + * Get X-Position of the Collidable. + */ + public int getHitboxX() { + return this.getCenteredX() - (this.hitboxWidth / 2); + } + + /** + * Get Y-Position of the Collidable. + */ + public int getHitboxY() { + return this.getCenteredY() - (this.hitboxHeight / 2); + } + + /** + * Get the width of the Collidable. + */ + public int getHitboxWidth() { + return this.hitboxWidth; + } + + /** + * Set the width of the Collidable. + */ + public void setHitboxWidth(int hitboxWidth) { + this.hitboxWidth = hitboxWidth; + } + + /** + * Get the height of the Collidable. + */ + public int getHitboxHeight() { + return this.hitboxHeight; + } + + /** + * Set the height of the Collidable. + */ + public void setHitboxHeight(int hitboxHeight) { + this.hitboxHeight = hitboxHeight; + } + + /** + * Set the dimensions of the CollidableEntities hitbox. + */ + public void setHitboxDimenstions(int width, int height) { + this.hitboxWidth = width; + this.hitboxHeight = height; + } + + /** + * Overriding the Entities setImageDimension to (ab)use their width/height + * for reuse in the hitbox. + */ + @Override + public void setImageDimensions(int width, int height) { + super.setImageDimensions(width, height); + this.hitboxWidth = this.getImageWidth(); + this.hitboxHeight = this.getImageHeight(); + } + + /** + * Adding a debugging option to draw the hitbox in red. + */ + @Override + public void paint(Graphics2D g) { + super.paint(g); + if(GameConfig.DEBUG) { + g.setColor(new Color(255,0,0)); + g.drawRect(this.getHitboxX(), this.getHitboxY(), this.hitboxWidth, this.hitboxHeight); + } + } /** * Handle collisions based on what the LivingEntity collided with. diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index 75f2fa0..1073d79 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -53,12 +53,12 @@ public abstract class Entity implements Updateable, Paintable { /** * Entity width. */ - private int width; + private int imageWidth; /** * Entity height. */ - private int height; + private int imageHeight; /** * Whether or not the Entity is able to move using transpose. @@ -106,14 +106,14 @@ public abstract class Entity implements Updateable, Paintable { * Get the centered X-Position of the Entity. */ public int getCenteredX() { - return this.x + (this.width / 2); + return this.x + (this.imageWidth / 2); } /** * Get the centered Y-Position of the Entity. */ public int getCenteredY() { - return this.y + (this.height / 2); + return this.y + (this.imageHeight / 2); } /** @@ -138,23 +138,23 @@ public abstract class Entity implements Updateable, Paintable { /** * Get the Entities width. */ - public int getWidth() { - return this.width; + public int getImageWidth() { + return this.imageWidth; } /** * Get the Entities height. */ - public int getHeight() { - return this.height; + public int getImageHeight() { + return this.imageHeight; } /** * Set the entities width and height. */ - public void setDimensions(int width, int height) { - this.width = width; - this.height = height; + public void setImageDimensions(int width, int height) { + this.imageWidth = width; + this.imageHeight = height; } /** @@ -170,7 +170,7 @@ public abstract class Entity implements Updateable, Paintable { public void setImage(String filename) { this.img = Loader.getBufferedImageByFilename(filename); //set the entities dimensions using the dimensions of the image. - this.setDimensions(this.img.getWidth(), this.img.getHeight()); + this.setImageDimensions(this.img.getWidth(), this.img.getHeight()); } /** @@ -190,11 +190,12 @@ public abstract class Entity implements Updateable, Paintable { /** * The default way to paint the Entity. * Simply draw the Entities image on its current position. + * Debugging option: draw the image border in green. */ public void paint(Graphics2D g) { if(GameConfig.DEBUG) { - g.setColor(new Color(255,0,0)); - g.drawRect(this.x, this.y, this.width, this.height); + g.setColor(new Color(0,255,0)); + g.drawRect(this.x, this.y, this.imageWidth, this.imageHeight); } g.drawImage(this.img, this.x, this.y, null); } diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index c650fcd..721ca0f 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -128,7 +128,7 @@ public class Player extends ShootingEntity implements KeyboardListener { public void paint(Graphics2D g) { if(this.currentCollisionCooldown > 0) { g.setColor(Color.RED); - g.drawRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); + g.drawRect(this.getX(), this.getY(), this.getImageWidth(), this.getImageHeight()); } super.paint(g); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java index cc23a19..39c5dc2 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java @@ -42,7 +42,7 @@ public abstract class Enemy extends ShootingEntity { super.update(); // enemy has fully left the screen ..to the left! - if(this.getX() + this.getWidth() < 0){ + if(this.getX() + this.getImageWidth() < 0){ this.remove(); return; } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java index b4ea41b..af231d1 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java @@ -44,7 +44,7 @@ public class EnemyBoss extends Enemy{ public void update() { super.update(); //Move into the Screen until it fits on X-Axis - if(this.getX() > GameConfig.gameScreenWidth+GameConfig.gameScreenXOffset-this.getWidth()) { + if(this.getX() > GameConfig.gameScreenWidth+GameConfig.gameScreenXOffset-this.getImageWidth()) { this.transpose(-1, 0); } //Move up or down within the GameScreen. @@ -52,12 +52,12 @@ public class EnemyBoss extends Enemy{ if(this.getY() == GameConfig.gameScreenYOffset){ move = 1; } - if(this.getY() == GameConfig.gameScreenHeight + GameConfig.gameScreenYOffset - this.getHeight()){ + if(this.getY() == GameConfig.gameScreenHeight + GameConfig.gameScreenYOffset - this.getImageHeight()){ move = -1; } //Randomly spawn minions. if(Random.nextInt(1000) < 5) { - new EnemyBossMinion(GameConfig.gameScreenWidth +GameConfig.gameScreenXOffset - this.getWidth(), this.getY()); + new EnemyBossMinion(GameConfig.gameScreenWidth +GameConfig.gameScreenXOffset - this.getImageWidth(), this.getY()); } //Randomly fire doubleshots. if(Random.nextInt(1000) < 50) { diff --git a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java index 11619af..4f27df7 100644 --- a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java +++ b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionOne.java @@ -17,7 +17,7 @@ public class ExplosionOne extends Animation { "images/explosions/01/explosion7.png" }; this.configure(images, 10); - this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + this.setPosition(x - (this.getImageWidth()/2), y - (this.getImageHeight()/2)); SoundSystem.playSound("sounds/bad_explosion1.wav"); } } diff --git a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java index 7ca3797..48348ce 100644 --- a/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/explosion/ExplosionTwo.java @@ -26,7 +26,7 @@ public class ExplosionTwo extends Animation { "images/explosions/02/explosion2_16.png" }; this.configure(images, 10); - this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + this.setPosition(x - (this.getImageWidth()/2), y - (this.getImageHeight()/2)); SoundSystem.playSound("sounds/bad_explosion2.wav"); } diff --git a/src/de/teamteamteam/spacescooter/entity/item/Item.java b/src/de/teamteamteam/spacescooter/entity/item/Item.java index ced3250..88020c2 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/Item.java +++ b/src/de/teamteamteam/spacescooter/entity/item/Item.java @@ -38,7 +38,7 @@ public abstract class Item extends CollidableEntity { */ public void update(){ this.transpose(-1, 0); - if(this.getX() < this.getWidth()) { + if(this.getX() < this.getImageWidth()) { this.remove(); } } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java index 034be47..8c504f1 100644 --- a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneOne.java @@ -9,6 +9,7 @@ public class StoneOne extends MovingObstacle { super(x, y); this.setImage("images/stones/stone01.png"); this.setCollisionDamage(9001); + this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5); } } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java index f1b92b4..992bd6b 100644 --- a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneThree.java @@ -9,6 +9,7 @@ public class StoneThree extends MovingObstacle { super(x, y); this.setImage("images/stones/stone03.png"); this.setCollisionDamage(9001); + this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5); } } diff --git a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java index 8392b9d..f9bf4ee 100644 --- a/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/obstacle/StoneTwo.java @@ -9,6 +9,7 @@ public class StoneTwo extends MovingObstacle { super(x, y); this.setImage("images/stones/stone02.png"); this.setCollisionDamage(9001); + this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5); } } diff --git a/src/de/teamteamteam/spacescooter/entity/shot/BeamImage.java b/src/de/teamteamteam/spacescooter/entity/shot/BeamImage.java index 802600b..ad1015f 100644 --- a/src/de/teamteamteam/spacescooter/entity/shot/BeamImage.java +++ b/src/de/teamteamteam/spacescooter/entity/shot/BeamImage.java @@ -15,7 +15,6 @@ public class BeamImage extends Entity { this.setImage("images/shots/beam.png"); } - @Override public void update() { this.lifetime++; if(this.lifetime>30){ diff --git a/src/de/teamteamteam/spacescooter/entity/shot/Shot.java b/src/de/teamteamteam/spacescooter/entity/shot/Shot.java index 1085e76..a32e20f 100644 --- a/src/de/teamteamteam/spacescooter/entity/shot/Shot.java +++ b/src/de/teamteamteam/spacescooter/entity/shot/Shot.java @@ -90,8 +90,8 @@ public class Shot extends CollidableEntity { public void update() { this.transpose(this.direction * this.speed, 0); //remove the shot in case it is out of the game window. - if ((this.getX() + this.getWidth()) < 0 || this.getX() > GameConfig.windowWidth - || (this.getY() + this.getHeight()) < 0 + if ((this.getX() + this.getImageWidth()) < 0 || this.getX() > GameConfig.windowWidth + || (this.getY() + this.getImageHeight()) < 0 || this.getY() > GameConfig.windowHeight) { this.remove(); } diff --git a/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java b/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java index 45202d5..2bad3b5 100644 --- a/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java +++ b/src/de/teamteamteam/spacescooter/entity/spi/Collidable.java @@ -8,22 +8,32 @@ public interface Collidable { /** * Get X-Position of the Collidable. */ - public int getX(); - + public int getHitboxX(); + /** * Get Y-Position of the Collidable. */ - public int getY(); + public int getHitboxY(); /** * Get the width of the Collidable. */ - public int getWidth(); - + public int getHitboxWidth(); + + /** + * Set the width of the Collidable. + */ + public void setHitboxWidth(int hitboxWidth); + /** * Get the height of the Collidable. */ - public int getHeight(); + public int getHitboxHeight(); + + /** + * Set the height of the Collidable. + */ + public void setHitboxHeight(int hitboxHeight); /** * Notify the Collidable that a collision happened. diff --git a/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java b/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java index c6c6c9a..ba939f2 100644 --- a/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java +++ b/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java @@ -30,7 +30,6 @@ public class SecondaryWeaponAmount extends Entity{ } } - @Override public void update() {} } diff --git a/src/de/teamteamteam/spacescooter/utility/CollisionHandler.java b/src/de/teamteamteam/spacescooter/utility/CollisionHandler.java index a1d7b48..5dc491e 100644 --- a/src/de/teamteamteam/spacescooter/utility/CollisionHandler.java +++ b/src/de/teamteamteam/spacescooter/utility/CollisionHandler.java @@ -70,18 +70,18 @@ public class CollisionHandler { * Check if two Collidables actually collided. */ private static boolean doCollide(Collidable cOne, Collidable cTwo) { - int x1 = cOne.getX(); - int x2 = cOne.getX() + cOne.getWidth(); - int x3 = cTwo.getX(); - int x4 = cTwo.getX() + cTwo.getWidth(); - int total_width = cOne.getWidth() + cTwo.getWidth(); + int x1 = cOne.getHitboxX(); + int x2 = cOne.getHitboxX() + cOne.getHitboxWidth(); + int x3 = cTwo.getHitboxX(); + int x4 = cTwo.getHitboxX() + cTwo.getHitboxWidth(); + int total_width = cOne.getHitboxWidth() + cTwo.getHitboxWidth(); boolean x_overlap = total_width > Math.abs(Math.max(x2, x4) - Math.min(x1, x3)); - int y1 = cOne.getY(); - int y2 = cOne.getY() + cOne.getHeight(); - int y3 = cTwo.getY(); - int y4 = cTwo.getY() + cTwo.getHeight(); - int total_height = cOne.getHeight() + cTwo.getHeight(); + int y1 = cOne.getHitboxY(); + int y2 = cOne.getHitboxY() + cOne.getHitboxHeight(); + int y3 = cTwo.getHitboxY(); + int y4 = cTwo.getHitboxY() + cTwo.getHitboxHeight(); + int total_height = cOne.getHitboxHeight() + cTwo.getHitboxHeight(); boolean y_overlap = total_height > Math.abs(Math.max(y2, y4) - Math.min(y1, y3)); return x_overlap && y_overlap;