bullets hit the health
This commit is contained in:
parent
c38c0fb099
commit
6966bf3933
core/src/de/samdev/cannonshooter
@ -5,7 +5,6 @@ import com.badlogic.gdx.Input.Keys;
|
|||||||
|
|
||||||
import de.samdev.absgdx.framework.entities.Entity;
|
import de.samdev.absgdx.framework.entities.Entity;
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionCircle;
|
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
|
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
|
||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
@ -13,6 +12,8 @@ import de.samdev.cannonshooter.ZLayers;
|
|||||||
import de.samdev.cannonshooter.teams.Team;
|
import de.samdev.cannonshooter.teams.Team;
|
||||||
|
|
||||||
public class Cannon extends Entity {
|
public class Cannon extends Entity {
|
||||||
|
private static final float HEALTH_REGEN_PER_HIT = 0.2f;
|
||||||
|
|
||||||
public Team team;
|
public Team team;
|
||||||
|
|
||||||
private CannonBarrel barrel;
|
private CannonBarrel barrel;
|
||||||
@ -98,11 +99,13 @@ public class Cannon extends Entity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBulletHit(CannonBullet bullet, Team hit_team) {
|
public void onBulletHit(Team hit_team) {
|
||||||
|
if (hit_team.isNeutral) return;
|
||||||
|
|
||||||
if (hit_team == team) {
|
if (hit_team == team) {
|
||||||
health = Math.min(1, health + 0.01f);
|
health = Math.min(1, health + HEALTH_REGEN_PER_HIT);
|
||||||
} else {
|
} else {
|
||||||
health = Math.max(0, health - 0.01f);
|
health = Math.max(0, health - HEALTH_REGEN_PER_HIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
|
|
||||||
import de.samdev.absgdx.framework.entities.Entity;
|
import de.samdev.absgdx.framework.entities.Entity;
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionBox;
|
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
|
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
|
||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
@ -89,7 +88,7 @@ public class CannonBarrel extends Entity {
|
|||||||
owner.addEntity(bullet);
|
owner.addEntity(bullet);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (cannon.health <= 0.5) {
|
||||||
charge -= UNCHARGE_SPEED * delta;
|
charge -= UNCHARGE_SPEED * delta;
|
||||||
|
|
||||||
if (charge < 0)
|
if (charge < 0)
|
||||||
|
@ -96,7 +96,7 @@ public class CannonBullet extends Entity {
|
|||||||
CannonBullet colliderBullet = (CannonBullet)passiveCollider;
|
CannonBullet colliderBullet = (CannonBullet)passiveCollider;
|
||||||
|
|
||||||
if (colliderBullet.inBarrel) {
|
if (colliderBullet.inBarrel) {
|
||||||
colliderBullet.cannon.onBulletHit(this, this.team);
|
colliderBullet.cannon.onBulletHit(this.team);
|
||||||
|
|
||||||
alive = false;
|
alive = false;
|
||||||
} else {
|
} else {
|
||||||
@ -113,7 +113,7 @@ public class CannonBullet extends Entity {
|
|||||||
if (passiveCollider instanceof Cannon) {
|
if (passiveCollider instanceof Cannon) {
|
||||||
Cannon cannon = (Cannon)passiveCollider;
|
Cannon cannon = (Cannon)passiveCollider;
|
||||||
|
|
||||||
cannon.onBulletHit(this, this.team);
|
cannon.onBulletHit(this.team);
|
||||||
|
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.samdev.cannonshooter.tiles;
|
package de.samdev.cannonshooter.tiles;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
||||||
|
Loading…
Reference in New Issue
Block a user