PowerLevel in Cannon

This commit is contained in:
Mike Schwörer 2015-09-17 18:25:04 +02:00
parent 9c63975f2c
commit 83a80700db
6 changed files with 42 additions and 10 deletions

View File

@ -1,5 +1,8 @@
package de.samdev.cannonshooter.entities; package de.samdev.cannonshooter.entities;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
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.CollisionGeometry; import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.CollisionGeometry;
@ -12,6 +15,8 @@ public class Cannon extends Entity {
private CannonBarrel barrel; private CannonBarrel barrel;
private CannonHearth hearth; private CannonHearth hearth;
public float power = 1f; // 1 = active | 0 = neutral
public Cannon(float x, float y) { public Cannon(float x, float y) {
super(Textures.cannon_body, 2, 2); super(Textures.cannon_body, 2, 2);
@ -29,6 +34,19 @@ public class Cannon extends Entity {
layer.addEntity(hearth); layer.addEntity(hearth);
} }
@Override
public void beforeUpdate(float delta) {
if (isMouseOverEntity() && Gdx.input.justTouched() && Gdx.input.isButtonPressed(Buttons.LEFT) && power > 0)
{
power -= 0.1;
}
if (isMouseOverEntity() && Gdx.input.justTouched() && Gdx.input.isButtonPressed(Buttons.RIGHT) && power < 1)
{
power += 0.1;
}
}
@Override @Override
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) { public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -63,10 +81,4 @@ public class Cannon extends Entity {
return false; return false;
} }
@Override
public void beforeUpdate(float delta) {
// TODO Auto-generated method stub
}
} }

View File

@ -13,11 +13,15 @@ import de.samdev.cannonshooter.ZLayers;
public class CannonHearth extends Entity { public class CannonHearth extends Entity {
private static final Color COLOR_NEUTRAL = new Color(0.75f, 0.75f, 0.75f, 1f); private static final Color COLOR_NEUTRAL = new Color(0.75f, 0.75f, 0.75f, 1f);
private static final float ROTATION_SPEED = 0.125f;
private float rotation = 0; private float rotation = 0;
private Cannon cannon;
public CannonHearth(Cannon owner) { public CannonHearth(Cannon owner) {
super(Textures.cannon_hearth[0], 2, 2); super(Textures.cannon_hearth[0], 2, 2);
cannon = owner;
setPosition(owner.getPositionX(), owner.getPositionY()); setPosition(owner.getPositionX(), owner.getPositionY());
@ -32,7 +36,7 @@ public class CannonHearth extends Entity {
sbatch.setColor(Color.RED); sbatch.setColor(Color.RED);
renderTexture(sbatch, Textures.cannon_hearth[(int)(rotation/4f) % 64], 0, 0); renderTexture(sbatch, Textures.cannon_hearth[(int)(cannon.power * 63)], 0, 0);
sbatch.setColor(Color.WHITE); sbatch.setColor(Color.WHITE);
} }
@ -73,12 +77,24 @@ public class CannonHearth extends Entity {
@Override @Override
public void beforeUpdate(float delta) { public void beforeUpdate(float delta) {
rotation = (rotation + 360 + delta / 8) % 360; if (cannon.power < 1)
{
if (rotation != 0)
{
rotation = (rotation - delta * ROTATION_SPEED);
if (rotation < 0) rotation = 0;
}
}
else
{
rotation = (rotation - delta * ROTATION_SPEED);
if (rotation < 0) rotation += 45;
}
} }
@Override @Override
public float getTextureRotation() { public float getTextureRotation() {
return 0;//rotation; return rotation;
} }
@Override @Override

View File

@ -19,7 +19,11 @@ public class StandardLevel extends GameLayer {
setMapScaleResolver(new ShowCompleteMapScaleResolver()); setMapScaleResolver(new ShowCompleteMapScaleResolver());
addEntity(new Cannon(10, 10)); addEntity(new Cannon(7, 13));
addEntity(new Cannon(14, 5));
addEntity(new Cannon(20, 13));
} }
@Override @Override

Binary file not shown.

Binary file not shown.

Binary file not shown.