Added Rotate Gesture to Barrel
This commit is contained in:
parent
83a80700db
commit
efcd34ebff
BIN
android/assets/cannon_bullet.png
Normal file
BIN
android/assets/cannon_bullet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -19,5 +19,6 @@ public final class Textures {
|
|||||||
cannon_body = new Texture("cannon_body.png");
|
cannon_body = new Texture("cannon_body.png");
|
||||||
cannon_barrel = TextureHelper.load1DArray("cannon_barrel.png", 512, 256, 16);
|
cannon_barrel = TextureHelper.load1DArray("cannon_barrel.png", 512, 256, 16);
|
||||||
cannon_hearth = TextureHelper.load1DArray("cannon_hearth.png", 256, 256, 64);
|
cannon_hearth = TextureHelper.load1DArray("cannon_hearth.png", 256, 256, 64);
|
||||||
|
cannon_bullet = new Texture("cannon_bullet.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.samdev.cannonshooter.entities;
|
package de.samdev.cannonshooter.entities;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input.Buttons;
|
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;
|
||||||
@ -36,39 +36,43 @@ public class Cannon extends Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeUpdate(float delta) {
|
public void beforeUpdate(float delta) {
|
||||||
if (isMouseOverEntity() && Gdx.input.justTouched() && Gdx.input.isButtonPressed(Buttons.LEFT) && power > 0)
|
if (owner.owner.settings.debugEnabled.get())
|
||||||
{
|
{
|
||||||
power -= 0.1;
|
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.DOWN))
|
||||||
|
{
|
||||||
|
power = Math.max(0, power - 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMouseOverEntity() && Gdx.input.justTouched() && Gdx.input.isButtonPressed(Buttons.RIGHT) && power < 1)
|
if (isMouseOverEntity() && Gdx.input.isKeyPressed(Keys.UP))
|
||||||
{
|
{
|
||||||
power += 0.1;
|
power = Math.min(1, power + 0.01f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMouseOverEntity() && Gdx.input.justTouched())
|
||||||
|
{
|
||||||
|
barrel.startDrag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package de.samdev.cannonshooter.entities;
|
package de.samdev.cannonshooter.entities;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
||||||
|
|
||||||
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;
|
||||||
@ -10,14 +9,23 @@ import de.samdev.absgdx.framework.entities.colliosiondetection.geometries.Collis
|
|||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
import de.samdev.cannonshooter.ZLayers;
|
import de.samdev.cannonshooter.ZLayers;
|
||||||
|
import de.samdev.cannonshooter.util.MathUtils;
|
||||||
|
|
||||||
public class CannonBarrel extends Entity {
|
public class CannonBarrel extends Entity {
|
||||||
private static final float ANIMATION_DURATION = 1000;
|
private static final float CHARGE_DURATION = 0.0001f;
|
||||||
|
private static final float ROTATION_SPEED = 0.18f;
|
||||||
|
|
||||||
|
private boolean dragging = false;
|
||||||
|
|
||||||
private float rotation = 0;
|
private float rotation = 0;
|
||||||
|
private float targetRotation = 0;
|
||||||
|
private float charge = 0;
|
||||||
|
|
||||||
|
private Cannon cannon;
|
||||||
|
|
||||||
public CannonBarrel(Cannon owner) {
|
public CannonBarrel(Cannon owner) {
|
||||||
super(Textures.cannon_barrel[0], 4, 2);
|
super(Textures.cannon_barrel[0], 4, 2);
|
||||||
|
cannon = owner;
|
||||||
|
|
||||||
setPosition(owner.getPositionX() - 1, owner.getPositionY());
|
setPosition(owner.getPositionX() - 1, owner.getPositionY());
|
||||||
|
|
||||||
@ -25,27 +33,62 @@ public class CannonBarrel extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void beforeUpdate(float delta) {
|
||||||
// TODO Auto-generated method stub
|
if (dragging) updateDragging();
|
||||||
|
|
||||||
|
if (rotation != targetRotation) {
|
||||||
|
float sign = MathUtils.moduloSignum(rotation, targetRotation, 360, 1);
|
||||||
|
|
||||||
|
rotation += sign * ROTATION_SPEED * delta;
|
||||||
|
if (sign != MathUtils.moduloSignum(rotation, targetRotation, 360, 1)) rotation = targetRotation;
|
||||||
|
|
||||||
|
rotation = (rotation + 360) % 360;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getTextureRotation() {
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDragging() {
|
||||||
|
if (! Gdx.input.isTouched()) {
|
||||||
|
dragging = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 mouse = new Vector2(owner.getMouseOnMapPositionX() - cannon.getCenterX(), owner.getMouseOnMapPositionY() - cannon.getCenterY());
|
||||||
|
|
||||||
|
targetRotation = mouse.angle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startDrag() {
|
||||||
|
dragging = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLayerAdd(GameLayer layer) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActiveCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onPassiveCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onActiveMovementCollide(CollisionGeometryOwner passiveCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
public void onPassiveMovementCollide(CollisionGeometryOwner activeCollider, CollisionGeometry myGeo, CollisionGeometry otherGeo) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,21 +101,4 @@ public class CannonBarrel extends Entity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeUpdate(float delta) {
|
|
||||||
rotation += 1;
|
|
||||||
rotation = (rotation + 1) % 360;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getTextureRotation() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLayerAdd(GameLayer layer) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
66
core/src/de/samdev/cannonshooter/entities/CannonBullet.java
Normal file
66
core/src/de/samdev/cannonshooter/entities/CannonBullet.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package de.samdev.cannonshooter.entities;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
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 CannonBullet extends Entity {
|
||||||
|
private Cannon cannon;
|
||||||
|
|
||||||
|
public CannonBullet(Cannon owner) {
|
||||||
|
super(Textures.cannon_bullet, 0.25f, 0.25f);
|
||||||
|
cannon = owner;
|
||||||
|
|
||||||
|
setPosition(cannon.getPositionX(), cannon.getPositionY());
|
||||||
|
|
||||||
|
setZLayer(ZLayers.LAYER_CANNON_BULLET);
|
||||||
|
|
||||||
|
setColorTint(Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeUpdate(float delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -41,40 +41,6 @@ public class CannonHearth extends Entity {
|
|||||||
sbatch.setColor(Color.WHITE);
|
sbatch.setColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void beforeUpdate(float delta) {
|
public void beforeUpdate(float delta) {
|
||||||
if (cannon.power < 1)
|
if (cannon.power < 1)
|
||||||
@ -99,8 +65,37 @@ public class CannonHearth extends Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayerAdd(GameLayer layer) {
|
public void onLayerAdd(GameLayer layer) {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
package de.samdev.cannonshooter.framework;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
|
|
||||||
import de.samdev.absgdx.framework.map.TileMap;
|
|
||||||
import de.samdev.absgdx.framework.map.background.MapBackground;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a repeating background.
|
|
||||||
*
|
|
||||||
* The texture will be repeated from the map-origin (0|0) to cover the whole map
|
|
||||||
* The texture tiles are aligned to the map tiles, with scale=1 the texture-tiles equal the map-tiles
|
|
||||||
* But the texture-tiles go on after the map borders and fill the whole viewport
|
|
||||||
*/
|
|
||||||
public class TileAlignedBackground extends MapBackground { //TODO Merge back to absGDX
|
|
||||||
|
|
||||||
private final TextureRegion texture;
|
|
||||||
private final float scale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new repeating Background aligned to the TiledMap
|
|
||||||
*
|
|
||||||
* @param tex the background texture
|
|
||||||
* @param scale size of a background tile (1 = Background equals MapTile) (2 = Background equals 4 MapTile) ...
|
|
||||||
*/
|
|
||||||
public TileAlignedBackground(TextureRegion tex, float scale) {
|
|
||||||
this.texture = tex;
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new repeating Background aligned to the TiledMap
|
|
||||||
*
|
|
||||||
* @param tex the background texture
|
|
||||||
* @param scale size of a background tile (1 = Background equals MapTile) (2 = Background equals 4 MapTile) ...
|
|
||||||
*/
|
|
||||||
public TileAlignedBackground(Texture tex, float scale) {
|
|
||||||
this(new TextureRegion(tex), scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(SpriteBatch sbatch, Vector2 map_offset, TileMap map, Rectangle visible) {
|
|
||||||
int minX = (int)(visible.x + map_offset.x);
|
|
||||||
int minY = (int)(visible.y + map_offset.y);
|
|
||||||
int maxX = (int)(visible.x + visible.width - map_offset.x + 1);
|
|
||||||
int maxY = (int)(visible.y + visible.height - map_offset.y + 1);
|
|
||||||
|
|
||||||
for (int x = minX; x < maxX; x+=scale) {
|
|
||||||
for (int y = minY; y < maxY; y+=scale) {
|
|
||||||
sbatch.draw(texture, x , y, scale, scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -20,9 +20,7 @@ public class StandardLevel extends GameLayer {
|
|||||||
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
||||||
|
|
||||||
addEntity(new Cannon(7, 13));
|
addEntity(new Cannon(7, 13));
|
||||||
|
|
||||||
addEntity(new Cannon(14, 5));
|
addEntity(new Cannon(14, 5));
|
||||||
|
|
||||||
addEntity(new Cannon(20, 13));
|
addEntity(new Cannon(20, 13));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
core/src/de/samdev/cannonshooter/util/MathUtils.java
Normal file
16
core/src/de/samdev/cannonshooter/util/MathUtils.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package de.samdev.cannonshooter.util;
|
||||||
|
|
||||||
|
public final class MathUtils {
|
||||||
|
|
||||||
|
public static int moduloSignum(float a, float b, float mod, int fallback) {
|
||||||
|
if (a == b) return 0;
|
||||||
|
|
||||||
|
float d_positive = ((a - b) + 2*mod) % mod;
|
||||||
|
float d_negative = ((b - a) + 2*mod) % mod;
|
||||||
|
|
||||||
|
if (d_positive > d_negative) return 1;
|
||||||
|
else if (d_positive < d_negative) return -1;
|
||||||
|
else return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user