Rotating CannonHearth

This commit is contained in:
2015-09-17 15:35:24 +02:00
parent f1cd7f4099
commit aa006a5c0b
11 changed files with 142 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ public final class Textures {
public static Texture cannon_body;
public static TextureRegion[] cannon_barrel;
public static Texture cannon_hearth;
public static TextureRegion[] cannon_hearth;
public static Texture cannon_bullet;
public static void init() {
@@ -18,5 +18,6 @@ public final class Textures {
cannon_body = new Texture("cannon_body.png");
cannon_barrel = TextureHelper.load1DArray("cannon_barrel.png", 512, 256, 16);
cannon_hearth = TextureHelper.load1DArray("cannon_hearth.png", 256, 256, 64);
}
}

View File

@@ -10,6 +10,7 @@ import de.samdev.cannonshooter.ZLayers;
public class Cannon extends Entity {
private CannonBarrel barrel;
private CannonHearth hearth;
public Cannon(float x, float y) {
super(Textures.cannon_body, 2, 2);
@@ -22,8 +23,10 @@ public class Cannon extends Entity {
@Override
public void onLayerAdd(GameLayer layer) {
barrel = new CannonBarrel(this);
hearth = new CannonHearth(this);
layer.addEntity(barrel);
layer.addEntity(hearth);
}
@Override

View File

@@ -8,13 +8,13 @@ import de.samdev.cannonshooter.Textures;
import de.samdev.cannonshooter.ZLayers;
public class CannonBarrel extends Entity {
private static final float ANIMATION_DURATION = 2000;
private static final float ANIMATION_DURATION = 1000;
private float rotation = 0;
public CannonBarrel(Cannon owner) {
super(Textures.cannon_barrel, ANIMATION_DURATION, 4, 2);
super(Textures.cannon_barrel[0], 4, 2);
setPosition(owner.getPositionX() - 1, owner.getPositionY());

View File

@@ -0,0 +1,71 @@
package de.samdev.cannonshooter.entities;
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;
public class CannonHearth extends Entity {
private float rotation = 0;
public CannonHearth(Cannon owner) {
super(Textures.cannon_hearth[0], 2, 2);
setPosition(owner.getPositionX(), owner.getPositionY());
setZLayer(ZLayers.LAYER_CANNON_HEARTH);
}
@Override
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
// TODO Auto-generated method stub
}
@Override
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
// TODO Auto-generated method stub
}
@Override
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
// TODO Auto-generated method stub
}
@Override
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
// TODO Auto-generated method stub
}
@Override
public boolean canCollideWith(CollisionGeometryOwner other) {
return false;
}
@Override
public boolean canMoveCollideWith(CollisionGeometryOwner other) {
return false;
}
@Override
public void beforeUpdate(float delta) {
rotation = (rotation + 360 - delta / 8) % 360;
}
@Override
public float getTextureRotation() {
return rotation;
}
@Override
public void onLayerAdd(GameLayer layer) {
// TODO Auto-generated method stub
}
}

View File

@@ -5,17 +5,17 @@ import com.badlogic.gdx.math.Vector2;
import de.samdev.absgdx.framework.AgdxGame;
import de.samdev.absgdx.framework.layer.GameLayer;
import de.samdev.absgdx.framework.map.TileMap;
import de.samdev.absgdx.framework.map.background.RepeatingBackground;
import de.samdev.absgdx.framework.map.mapscaleresolver.ShowCompleteMapScaleResolver;
import de.samdev.cannonshooter.Textures;
import de.samdev.cannonshooter.entities.Cannon;
import de.samdev.cannonshooter.framework.TileAlignedBackground;
public class StandardLevel extends GameLayer {
public StandardLevel(AgdxGame owner) {
super(owner, TileMap.createEmptyMap(32, 20));
addBackground(new TileAlignedBackground(Textures.texbackground, 1));
addBackground(new RepeatingBackground(Textures.texbackground, 1/32f));
setMapScaleResolver(new ShowCompleteMapScaleResolver());