From 14ee843974f6fb4b1e689399d73c32e0b2deefbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 20 Sep 2015 13:45:33 +0200 Subject: [PATCH] Added team change by attack --- .../samdev/cannonshooter/entities/Cannon.java | 35 ++++++++++++++++--- .../cannonshooter/entities/CannonBarrel.java | 2 +- .../cannonshooter/entities/CannonHearth.java | 5 +-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/core/src/de/samdev/cannonshooter/entities/Cannon.java b/core/src/de/samdev/cannonshooter/entities/Cannon.java index ed2dd5e..bbb6df1 100644 --- a/core/src/de/samdev/cannonshooter/entities/Cannon.java +++ b/core/src/de/samdev/cannonshooter/entities/Cannon.java @@ -9,15 +9,20 @@ import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.Collis import de.samdev.absgdx.framework.layer.GameLayer; import de.samdev.cannonshooter.Textures; import de.samdev.cannonshooter.ZLayers; +import de.samdev.cannonshooter.level.StandardLevel; import de.samdev.cannonshooter.teams.Team; public class Cannon extends Entity { private static final float HEALTH_REGEN_PER_HIT = 0.2f; + private static final float START_HEALTH_REGEN = 0.000015f; + private static final float END_HEALTH_REGEN = 0.000105f; public Team team; private CannonBarrel barrel; private CannonHearth hearth; + + private StandardLevel level; public float health; // 1 = active | 0 = neutral @@ -33,6 +38,8 @@ public class Cannon extends Entity { @Override public void onLayerAdd(GameLayer layer) { + level = (StandardLevel) layer; + addFullCollisionCircle(); //##################################################################### @@ -48,17 +55,27 @@ public class Cannon extends Entity { public void beforeUpdate(float delta) { if (owner.owner.settings.debugEnabled.get()) { if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.DOWN) && ! team.isNeutral) { - health = Math.max(0, health - 0.01f); + addHealth(-0.01f, level.team_neutral); } if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.UP) && ! team.isNeutral) { - health = Math.min(1, health + 0.01f); + addHealth(+0.01f, level.team_neutral); } } + //####################### + if (isMouseOverEntity() && Gdx.input.justTouched()) { barrel.startDrag(); } + + if (! team.isNeutral && health < 1) { + addHealth(getHealthRegen(delta), team); + } + } + + public float getHealthRegen(float delta) { + return (START_HEALTH_REGEN + (END_HEALTH_REGEN - START_HEALTH_REGEN) * health) * delta; // exponential, bitches } public void setTeam(Team newteam) { @@ -103,9 +120,19 @@ public class Cannon extends Entity { if (hit_team.isNeutral) return; if (hit_team == team && health < 1) { - health = Math.min(1, health + HEALTH_REGEN_PER_HIT); + addHealth(HEALTH_REGEN_PER_HIT, hit_team); } else if (hit_team != team) { - health = Math.max(0, health - HEALTH_REGEN_PER_HIT); + addHealth(-HEALTH_REGEN_PER_HIT, hit_team); + } + } + + private void addHealth(float add, Team hit_team) { + health += add; + if (health <= 0) { + setTeam(hit_team); + health = -health; + } else if (health > 1) { + health = 1; } } } diff --git a/core/src/de/samdev/cannonshooter/entities/CannonBarrel.java b/core/src/de/samdev/cannonshooter/entities/CannonBarrel.java index 0c46bc6..39f6fd9 100644 --- a/core/src/de/samdev/cannonshooter/entities/CannonBarrel.java +++ b/core/src/de/samdev/cannonshooter/entities/CannonBarrel.java @@ -16,7 +16,7 @@ import de.samdev.cannonshooter.util.MathUtils; public class CannonBarrel extends Entity { private static final float CHARGE_SPEED = 0.00066f; private static final float UNCHARGE_SPEED = 0.001f; - private static final float ROTATION_SPEED = 0.18f; + private static final float ROTATION_SPEED = 0.175f; private static final float RECOIL_PERC = 0.035f; private boolean dragging = false; diff --git a/core/src/de/samdev/cannonshooter/entities/CannonHearth.java b/core/src/de/samdev/cannonshooter/entities/CannonHearth.java index 432bbb9..64dc883 100644 --- a/core/src/de/samdev/cannonshooter/entities/CannonHearth.java +++ b/core/src/de/samdev/cannonshooter/entities/CannonHearth.java @@ -19,7 +19,6 @@ public class CannonHearth extends Entity { private float rotation = 0; private Cannon cannon; - private StandardLevel level; public CannonHearth(Cannon owner) { super(Textures.cannon_hearth[0], 2, 2); @@ -52,8 +51,6 @@ public class CannonHearth extends Entity { } if (cannon.health == 0){ - if (! cannon.team.isNeutral) cannon.setTeam(level.team_neutral); - rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier); if (rotation < 0) rotation += 45; } @@ -70,7 +67,7 @@ public class CannonHearth extends Entity { @Override public void onLayerAdd(GameLayer layer) { - level = (StandardLevel) layer; + // } @Override