CannonShooter/core/src/de/samdev/cannonshooter/entities/CannonBullet.java

112 lines
2.5 KiB
Java
Raw Normal View History

2015-09-17 19:07:49 +02:00
package de.samdev.cannonshooter.entities;
import com.badlogic.gdx.graphics.Color;
2015-09-17 21:02:27 +02:00
import com.badlogic.gdx.math.Rectangle;
2015-09-17 19:07:49 +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 21:02:27 +02:00
import de.samdev.cannonshooter.teams.Team;
2015-09-17 19:07:49 +02:00
public class CannonBullet extends Entity {
2015-09-18 15:04:14 +02:00
private final static float RESIZE_SPEED = 0.002f;
2015-09-17 21:02:27 +02:00
2015-09-17 19:07:49 +02:00
private Cannon cannon;
2015-09-17 21:02:27 +02:00
private final Team team;
private boolean inBarrel = true;
2015-09-18 15:04:14 +02:00
public float scale = 0.001f;
2015-09-17 21:02:27 +02:00
private boolean death = false;
2015-09-17 19:07:49 +02:00
2015-09-17 21:02:27 +02:00
public CannonBullet(Cannon owner, Team t) {
2015-09-18 15:04:14 +02:00
super(Textures.cannon_bullet, 0.5f, 0.5f);
2015-09-17 21:02:27 +02:00
this.cannon = owner;
this.team = t;
2015-09-17 19:07:49 +02:00
setPosition(cannon.getPositionX(), cannon.getPositionY());
setZLayer(ZLayers.LAYER_CANNON_BULLET);
2015-09-17 21:02:27 +02:00
setColorTint(team.teamColor);
2015-09-17 19:07:49 +02:00
}
2015-09-17 21:02:27 +02:00
@Override
public void beforeUpdate(float delta) {
if (death) {
scale -= RESIZE_SPEED * delta;
if (scale <= 0) {
death = false;
scale = 0.0001f;
alive = false;
}
}
// TODO OPTIMIZE
// TODO Add max lifetime (=> kill() )
if (! owner.getVisibleMapBox().overlaps(new Rectangle(getPositionX(), getPositionY(), getWidth(), getHeight())))
{
alive = false;
}
}
public void shoot(float rotation) {
inBarrel = false;
speed.set(0.001f, 0);
speed.rotate(rotation);
}
public void kill() {
death = true;
}
@Override
public float getTextureScaleX() {
return scale;
}
@Override
public float getTextureScaleY() {
return scale;
}
2015-09-17 19:07:49 +02:00
@Override
public void onLayerAdd(GameLayer layer) {
//
}
@Override
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
//
}
@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;
}
}