Rotating CannonHearth
This commit is contained in:
parent
f1cd7f4099
commit
aa006a5c0b
BIN
android/assets/cannon_hearth.png
Normal file
BIN
android/assets/cannon_hearth.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 119 KiB |
@ -10,7 +10,7 @@ public final class Textures {
|
|||||||
|
|
||||||
public static Texture cannon_body;
|
public static Texture cannon_body;
|
||||||
public static TextureRegion[] cannon_barrel;
|
public static TextureRegion[] cannon_barrel;
|
||||||
public static Texture cannon_hearth;
|
public static TextureRegion[] cannon_hearth;
|
||||||
public static Texture cannon_bullet;
|
public static Texture cannon_bullet;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
@ -18,5 +18,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import de.samdev.cannonshooter.ZLayers;
|
|||||||
public class Cannon extends Entity {
|
public class Cannon extends Entity {
|
||||||
|
|
||||||
private CannonBarrel barrel;
|
private CannonBarrel barrel;
|
||||||
|
private CannonHearth hearth;
|
||||||
|
|
||||||
public Cannon(float x, float y) {
|
public Cannon(float x, float y) {
|
||||||
super(Textures.cannon_body, 2, 2);
|
super(Textures.cannon_body, 2, 2);
|
||||||
@ -22,8 +23,10 @@ public class Cannon extends Entity {
|
|||||||
@Override
|
@Override
|
||||||
public void onLayerAdd(GameLayer layer) {
|
public void onLayerAdd(GameLayer layer) {
|
||||||
barrel = new CannonBarrel(this);
|
barrel = new CannonBarrel(this);
|
||||||
|
hearth = new CannonHearth(this);
|
||||||
|
|
||||||
layer.addEntity(barrel);
|
layer.addEntity(barrel);
|
||||||
|
layer.addEntity(hearth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,13 +8,13 @@ import de.samdev.cannonshooter.Textures;
|
|||||||
import de.samdev.cannonshooter.ZLayers;
|
import de.samdev.cannonshooter.ZLayers;
|
||||||
|
|
||||||
public class CannonBarrel extends Entity {
|
public class CannonBarrel extends Entity {
|
||||||
private static final float ANIMATION_DURATION = 2000;
|
private static final float ANIMATION_DURATION = 1000;
|
||||||
|
|
||||||
|
|
||||||
private float rotation = 0;
|
private float rotation = 0;
|
||||||
|
|
||||||
public CannonBarrel(Cannon owner) {
|
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());
|
setPosition(owner.getPositionX() - 1, owner.getPositionY());
|
||||||
|
|
||||||
|
71
core/src/de/samdev/cannonshooter/entities/CannonHearth.java
Normal file
71
core/src/de/samdev/cannonshooter/entities/CannonHearth.java
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,17 +5,17 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import de.samdev.absgdx.framework.AgdxGame;
|
import de.samdev.absgdx.framework.AgdxGame;
|
||||||
import de.samdev.absgdx.framework.layer.GameLayer;
|
import de.samdev.absgdx.framework.layer.GameLayer;
|
||||||
import de.samdev.absgdx.framework.map.TileMap;
|
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.absgdx.framework.map.mapscaleresolver.ShowCompleteMapScaleResolver;
|
||||||
import de.samdev.cannonshooter.Textures;
|
import de.samdev.cannonshooter.Textures;
|
||||||
import de.samdev.cannonshooter.entities.Cannon;
|
import de.samdev.cannonshooter.entities.Cannon;
|
||||||
import de.samdev.cannonshooter.framework.TileAlignedBackground;
|
|
||||||
|
|
||||||
public class StandardLevel extends GameLayer {
|
public class StandardLevel extends GameLayer {
|
||||||
|
|
||||||
public StandardLevel(AgdxGame owner) {
|
public StandardLevel(AgdxGame owner) {
|
||||||
super(owner, TileMap.createEmptyMap(32, 20));
|
super(owner, TileMap.createEmptyMap(32, 20));
|
||||||
|
|
||||||
addBackground(new TileAlignedBackground(Textures.texbackground, 1));
|
addBackground(new RepeatingBackground(Textures.texbackground, 1/32f));
|
||||||
|
|
||||||
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
setMapScaleResolver(new ShowCompleteMapScaleResolver());
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
void Main()
|
void Main()
|
||||||
{
|
{
|
||||||
Image input = Image.FromFile(@"F:\Eigene Dateien\Dropbox\Programming\Java\workspace\Cannon Shooter\data\cannon_barrel_single.png");
|
Image input = Image.FromFile(@"F:\Eigene Dateien\Dropbox\Programming\Java\workspace\Cannon Shooter\data\cannon_barrel_base.png");
|
||||||
|
|
||||||
Image output = new Bitmap(input.Width * 4, input.Height * 4, PixelFormat.Format32bppArgb);
|
Image output = new Bitmap(input.Width * 4, input.Height * 4, PixelFormat.Format32bppArgb);
|
||||||
|
|
61
data/CreateSpriteSheet_Hearth.linq
Normal file
61
data/CreateSpriteSheet_Hearth.linq
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<Query Kind="Program">
|
||||||
|
<Reference><RuntimeDirectory>\System.Numerics.dll</Reference>
|
||||||
|
<Namespace>System.Drawing</Namespace>
|
||||||
|
<Namespace>System.Drawing.Imaging</Namespace>
|
||||||
|
<Namespace>System.Numerics</Namespace>
|
||||||
|
</Query>
|
||||||
|
|
||||||
|
void Main()
|
||||||
|
{
|
||||||
|
var input = new Bitmap(Image.FromFile(@"F:\Eigene Dateien\Dropbox\Programming\Java\workspace\Cannon Shooter\data\cannon_hearth_base.png"));
|
||||||
|
|
||||||
|
Image output = new Bitmap(input.Width * 8, input.Height * 8, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
|
var b1 = new SolidBrush(Color.Black);
|
||||||
|
var b2 = new SolidBrush(Color.Magenta);
|
||||||
|
|
||||||
|
using (Graphics g = Graphics.FromImage(output))
|
||||||
|
{
|
||||||
|
for (int x = 0; x < 8; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 8; y++)
|
||||||
|
{
|
||||||
|
var rad = ((y*8 + x) / 64.0) * 2 * Math.PI;
|
||||||
|
|
||||||
|
for (int ix = 0; ix < input.Width; ix++)
|
||||||
|
{
|
||||||
|
for (int iy = 0; iy < input.Height; iy++)
|
||||||
|
{
|
||||||
|
int dx = input.Width * x + ix;
|
||||||
|
int dy = input.Height * y + iy;
|
||||||
|
|
||||||
|
if (input.GetPixel(ix, iy).A > 0)
|
||||||
|
{
|
||||||
|
if (GetAngle(new Vector2(ix - input.Width / 2f, iy - input.Height / 2f)) < rad)
|
||||||
|
{
|
||||||
|
g.FillRectangle(b1, dx, dy, 1, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g.FillRectangle(b2, dx, dy, 1, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.Dump();
|
||||||
|
|
||||||
|
output.Save(@"F:\Eigene Dateien\Dropbox\Programming\Java\workspace\Cannon Shooter\android\assets\cannon_hearth.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
double GetAngle(Vector2 p)
|
||||||
|
{
|
||||||
|
var vector2 = p;
|
||||||
|
var vector1 = new Vector2(0, -1);
|
||||||
|
|
||||||
|
return (Math.Atan2(vector2.Y, vector2.X) - Math.Atan2(vector1.Y, vector1.X) + 2*Math.PI) % (2*Math.PI);
|
||||||
|
}
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
data/cannon_hearth_base.png
Normal file
BIN
data/cannon_hearth_base.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
Loading…
Reference in New Issue
Block a user