2015-09-17 15:35:24 +02:00
|
|
|
package de.samdev.cannonshooter.entities;
|
|
|
|
|
2015-09-17 16:11:58 +02:00
|
|
|
import com.badlogic.gdx.graphics.Color;
|
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
|
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
|
|
|
2015-09-17 15:35:24 +02:00
|
|
|
import de.samdev.absgdx.framework.entities.Entity;
|
|
|
|
import de.samdev.absgdx.framework.entities.colliosiondetection.CollisionGeometryOwner;
|
|
|
|
import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
|
|
|
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
|
|
|
import de.samdev.cannonshooter.Textures;
|
|
|
|
import de.samdev.cannonshooter.ZLayers;
|
2015-09-17 19:46:38 +02:00
|
|
|
import de.samdev.cannonshooter.level.StandardLevel;
|
2015-09-17 15:35:24 +02:00
|
|
|
|
|
|
|
public class CannonHearth extends Entity {
|
2015-09-17 19:46:38 +02:00
|
|
|
private static final Color COLOR_HEARTLESS = new Color(0.75f, 0.75f, 0.75f, 1f);
|
2015-09-17 18:25:04 +02:00
|
|
|
private static final float ROTATION_SPEED = 0.125f;
|
2015-09-17 16:11:58 +02:00
|
|
|
|
2015-09-17 15:35:24 +02:00
|
|
|
private float rotation = 0;
|
|
|
|
|
2015-09-17 18:25:04 +02:00
|
|
|
private Cannon cannon;
|
|
|
|
|
2015-09-17 15:35:24 +02:00
|
|
|
public CannonHearth(Cannon owner) {
|
2015-09-20 14:36:56 +02:00
|
|
|
super(Textures.cannon_hearth[0], 4, 4);
|
2015-09-17 18:25:04 +02:00
|
|
|
cannon = owner;
|
2015-09-17 15:35:24 +02:00
|
|
|
|
|
|
|
setPosition(owner.getPositionX(), owner.getPositionY());
|
|
|
|
|
|
|
|
setZLayer(ZLayers.LAYER_CANNON_HEARTH);
|
|
|
|
}
|
|
|
|
|
2015-09-17 16:11:58 +02:00
|
|
|
@Override
|
|
|
|
public void render(SpriteBatch sbatch, ShapeRenderer srenderer) {
|
2015-09-17 19:46:38 +02:00
|
|
|
sbatch.setColor(COLOR_HEARTLESS);
|
2015-09-17 16:11:58 +02:00
|
|
|
|
|
|
|
renderTexture(sbatch, Textures.cannon_hearth[63], 0, 0);
|
|
|
|
|
2015-09-17 19:46:38 +02:00
|
|
|
sbatch.setColor(cannon.team.teamColor);
|
2015-09-17 16:11:58 +02:00
|
|
|
|
2015-09-17 21:02:27 +02:00
|
|
|
renderTexture(sbatch, Textures.cannon_hearth[(int)(cannon.health * 63)], 0, 0);
|
2015-09-17 16:11:58 +02:00
|
|
|
|
|
|
|
sbatch.setColor(Color.WHITE);
|
|
|
|
}
|
|
|
|
|
2015-09-17 15:35:24 +02:00
|
|
|
@Override
|
|
|
|
public void beforeUpdate(float delta) {
|
2015-09-17 21:02:27 +02:00
|
|
|
if (cannon.health < 1) {
|
|
|
|
if (rotation != 0 && cannon.health > 0) {
|
2015-09-17 19:46:38 +02:00
|
|
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
2015-09-17 18:25:04 +02:00
|
|
|
if (rotation < 0) rotation = 0;
|
|
|
|
}
|
2015-09-17 19:46:38 +02:00
|
|
|
|
2015-09-17 21:02:27 +02:00
|
|
|
if (cannon.health == 0){
|
2015-09-17 19:46:38 +02:00
|
|
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
|
|
|
if (rotation < 0) rotation += 45;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rotation = (rotation - delta * ROTATION_SPEED * cannon.team.speedMultiplier);
|
2015-09-17 18:25:04 +02:00
|
|
|
if (rotation < 0) rotation += 45;
|
|
|
|
}
|
2015-09-17 15:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getTextureRotation() {
|
2015-09-17 18:25:04 +02:00
|
|
|
return rotation;
|
2015-09-17 15:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLayerAdd(GameLayer layer) {
|
2015-09-20 13:45:33 +02:00
|
|
|
//
|
2015-09-17 19:07:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
|
|
|
//
|
|
|
|
}
|
2015-09-17 15:35:24 +02:00
|
|
|
|
2015-09-17 19:07:49 +02:00
|
|
|
@Override
|
|
|
|
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canCollideWith(CollisionGeometryOwner other) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canMoveCollideWith(CollisionGeometryOwner other) {
|
|
|
|
return false;
|
2015-09-17 15:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|