diff --git a/core/src/de/samdev/cannonshooter/CannonGame.java b/core/src/de/samdev/cannonshooter/CannonGame.java index f98db09..2815a91 100644 --- a/core/src/de/samdev/cannonshooter/CannonGame.java +++ b/core/src/de/samdev/cannonshooter/CannonGame.java @@ -26,7 +26,7 @@ public class CannonGame extends AgdxGame { @Override public void onUpdate(float delta) { - if (Gdx.input.isKeyJustPressed(Keys.F1)) settings.debugEnabled.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F1) || Gdx.input.isKeyJustPressed(Keys.MENU)) settings.debugEnabled.doSwitch(); if (Gdx.input.isKeyJustPressed(Keys.F2)) settings.debugVisualEntities.doSwitch(); if (Gdx.input.isKeyJustPressed(Keys.F3)) settings.debugVisualMap.doSwitch(); if (Gdx.input.isKeyJustPressed(Keys.F4)) settings.debugVisualMenu.doSwitch(); diff --git a/core/src/de/samdev/cannonshooter/entities/CannonBullet.java b/core/src/de/samdev/cannonshooter/entities/CannonBullet.java index b80a7ac..cf99da6 100644 --- a/core/src/de/samdev/cannonshooter/entities/CannonBullet.java +++ b/core/src/de/samdev/cannonshooter/entities/CannonBullet.java @@ -1,5 +1,8 @@ package de.samdev.cannonshooter.entities; +import java.util.HashMap; +import java.util.Map; + import com.badlogic.gdx.math.Rectangle; import de.samdev.absgdx.framework.entities.Entity; @@ -13,7 +16,7 @@ import de.samdev.cannonshooter.teams.Team; public class CannonBullet extends Entity { private final static float RESIZE_SPEED = 0.002f; private final static float MAX_LIFETIME = 25 * 1000; - + private final static float BULLET_IGNORE_TIME = 50; private final static float SHOOTING_SPEED = 0.004f; public Cannon cannon; @@ -25,6 +28,8 @@ public class CannonBullet extends Entity { public float lifetime = 0; + public Map ignoredBullets = new HashMap(); + public CannonBullet(Cannon owner, Team t) { super(Textures.cannon_bullet, 1f, 1f); this.cannon = owner; @@ -104,8 +109,9 @@ public class CannonBullet extends Entity { if (colliderBullet.team != this.team) { colliderBullet.alive = false; this.alive = false; + colliderBullet.alive = false; } else { - //TODO bounce + bounce(colliderBullet); } } } @@ -119,13 +125,38 @@ public class CannonBullet extends Entity { } } + private void bounce(CannonBullet other) { + float ctime = owner.owner.getCurrentGameTimeMillis(); + + if (this.isIgnored(other, ctime)) return; + + this.ignoredBullets.put(other, ctime); + other.ignoredBullets.put(this, ctime); + + float dx = other.getPositionX() - this.getPositionX(); + float dy = other.getPositionY() - this.getPositionY(); + + float quadDis = dx * dx + dy * dy; + + float v1d = this.speed.x * dx + this.speed.y * dy; + float v2d = other.speed.x * dx + other.speed.y * dy; + + float k1Vx = this.speed.x - dx * (v1d - v2d) / quadDis; + float k1Vy = this.speed.y - dy * (v1d - v2d) / quadDis; + float k2Vx = other.speed.x - dx * (v2d - v1d) / quadDis; + float k2Vy = other.speed.y - dy * (v2d - v1d) / quadDis; + + this.speed.set(k1Vx, k1Vy); + other.speed.set(k2Vx, k2Vy); + } + + private boolean isIgnored(CannonBullet other, float currentTimeMillis) { + return this.ignoredBullets.containsKey(other) && currentTimeMillis - this.ignoredBullets.get(other) < BULLET_IGNORE_TIME; + } + @Override public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) { - if (activeCollider == cannon) return; - - if (alive && !inBarrel) { - alive = false; - } + // } @Override diff --git a/core/src/de/samdev/cannonshooter/entities/CannonHearth.java b/core/src/de/samdev/cannonshooter/entities/CannonHearth.java index 39a8d5e..4fe2922 100644 --- a/core/src/de/samdev/cannonshooter/entities/CannonHearth.java +++ b/core/src/de/samdev/cannonshooter/entities/CannonHearth.java @@ -10,7 +10,6 @@ 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; public class CannonHearth extends Entity { private static final Color COLOR_HEARTLESS = new Color(0.75f, 0.75f, 0.75f, 1f); diff --git a/core/src/de/samdev/cannonshooter/level/StandardLevel.java b/core/src/de/samdev/cannonshooter/level/StandardLevel.java index ef5587c..5c1d850 100644 --- a/core/src/de/samdev/cannonshooter/level/StandardLevel.java +++ b/core/src/de/samdev/cannonshooter/level/StandardLevel.java @@ -39,6 +39,7 @@ public class StandardLevel extends GameLayer { setMapScaleResolver(new ShowCompleteMapScaleResolver()); addEntity(new Cannon(6, 25, team_player)); + addEntity(new Cannon(36, 25, team_player)); addEntity(new Cannon(48, 6, team_computer1)); addEntity(new Cannon(60, 34, team_neutral)); } diff --git a/lib/absGDX-framework-1.0.jar b/lib/absGDX-framework-1.0.jar index 6819193..0c1985d 100644 Binary files a/lib/absGDX-framework-1.0.jar and b/lib/absGDX-framework-1.0.jar differ