Rotating CannonHearth

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

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());

View File

@ -5,7 +5,7 @@
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);

View File

@ -0,0 +1,61 @@
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\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);
}

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
data/cannon_hearth_base.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.