diff --git a/android/assets/cannon.png b/android/assets/cannon.png new file mode 100644 index 0000000..c5a6640 Binary files /dev/null and b/android/assets/cannon.png differ diff --git a/android/assets/level_background.png b/android/assets/level_background.png index b209885..0a5f68e 100644 Binary files a/android/assets/level_background.png and b/android/assets/level_background.png differ diff --git a/core/src/de/samdev/cannonshooter/CannonGame.java b/core/src/de/samdev/cannonshooter/CannonGame.java index dd05247..722e527 100644 --- a/core/src/de/samdev/cannonshooter/CannonGame.java +++ b/core/src/de/samdev/cannonshooter/CannonGame.java @@ -1,6 +1,7 @@ package de.samdev.cannonshooter; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.g2d.BitmapFont; import de.samdev.absgdx.framework.AgdxGame; @@ -12,14 +13,22 @@ public class CannonGame extends AgdxGame { public void onCreate() { Textures.init(); - pushLayer(new StandardLevel(this)); + setLayer(new StandardLevel(this)); setDebugFont(new BitmapFont(Gdx.files.internal("consolefont.fnt"))); + + settings.debugVisualMenu.set(false); + settings.debugMenuLayerTextInfos.set(false); + settings.debugEnabled.set(true); } @Override - public void onUpdate(float arg0) { - // TODO Auto-generated method stub - + public void onUpdate(float delta) { + if (Gdx.input.isKeyJustPressed(Keys.F1)) settings.debugEnabled.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F2)) settings.debugVisualEntities.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F3)) settings.debugVisualMap.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F4)) settings.debugVisualMenu.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F5)) settings.debugTextInfos.doSwitch(); + if (Gdx.input.isKeyJustPressed(Keys.F6)) settings.debugEntitiesPhysicVectors.doSwitch(); } } diff --git a/core/src/de/samdev/cannonshooter/Textures.java b/core/src/de/samdev/cannonshooter/Textures.java index aeb79d6..86cc784 100644 --- a/core/src/de/samdev/cannonshooter/Textures.java +++ b/core/src/de/samdev/cannonshooter/Textures.java @@ -4,8 +4,10 @@ import com.badlogic.gdx.graphics.Texture; public final class Textures { public static Texture texbackground; + public static Texture cannon; public static void init() { texbackground = new Texture("level_background.png"); + cannon = new Texture("cannon.png"); } } diff --git a/core/src/de/samdev/cannonshooter/entities/Cannon.java b/core/src/de/samdev/cannonshooter/entities/Cannon.java new file mode 100644 index 0000000..84f51d5 --- /dev/null +++ b/core/src/de/samdev/cannonshooter/entities/Cannon.java @@ -0,0 +1,63 @@ +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; + +public class Cannon extends Entity { + + public Cannon(float x, float y) { + super(Textures.cannon, 1, 1); + + setPosition(x, y); + } + + @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) { + // TODO Auto-generated method stub + + } + + @Override + public void onLayerAdd(GameLayer layer) { + // TODO Auto-generated method stub + + } + +} diff --git a/core/src/de/samdev/cannonshooter/framework/TileAlignedBackground.java b/core/src/de/samdev/cannonshooter/framework/TileAlignedBackground.java new file mode 100644 index 0000000..8921e7d --- /dev/null +++ b/core/src/de/samdev/cannonshooter/framework/TileAlignedBackground.java @@ -0,0 +1,61 @@ +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); + } + } + + } + +} diff --git a/core/src/de/samdev/cannonshooter/level/StandardLevel.java b/core/src/de/samdev/cannonshooter/level/StandardLevel.java index f51af4b..b5b1905 100644 --- a/core/src/de/samdev/cannonshooter/level/StandardLevel.java +++ b/core/src/de/samdev/cannonshooter/level/StandardLevel.java @@ -1,23 +1,44 @@ package de.samdev.cannonshooter.level; +import java.util.Random; + +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)); + super(owner, TileMap.createEmptyMap(32, 32)); - addBackground(new RepeatingBackground(Textures.texbackground, 32)); + addBackground(new TileAlignedBackground(Textures.texbackground, 1)); + + setMapScaleResolver(new ShowCompleteMapScaleResolver()); + setRawOffset(new Vector2(-(getVisibleMapBox().width - getMap().width)/2, -(getVisibleMapBox().height - getMap().height)/2)); + + + Random R = new Random(80085); + for (int i = 0; i < 24; i++) { + addEntity(new Cannon(R.nextInt(15)*2+1, R.nextInt(15)*2+1)); + } + } + + @Override + public void onResize() { + super.onResize(); + + setRawOffset(new Vector2(-(getVisibleMapBox().width - getMap().width)/2, -(getVisibleMapBox().height - getMap().height)/2)); } @Override public void onUpdate(float arg0) { - // TODO Auto-generated method stub - + //setRawOffset(new Vector2(-(getVisibleMapBox().width - getMap().width)/2, -(getVisibleMapBox().height - getMap().height)/2)); } } diff --git a/lib/absGDX-framework-1.0.jar b/lib/absGDX-framework-1.0.jar index e8b8249..d560f4b 100644 Binary files a/lib/absGDX-framework-1.0.jar and b/lib/absGDX-framework-1.0.jar differ