Skip to content

Commit

Permalink
Working prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonracz committed Aug 20, 2013
1 parent 5245e50 commit 40b751f
Show file tree
Hide file tree
Showing 22 changed files with 1,037 additions and 66 deletions.
Binary file added isometric-game-template-android/libs/artemis.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.chaonis.isometric.screens.Isometric;

public class MainActivity extends AndroidApplication {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.chaonis.isometric.screens.Isometric;

public class Main {
public static void main(String[] args) {
Expand Down
Binary file added isometric-game-template/libs/artemis-src.jar
Binary file not shown.
Binary file added isometric-game-template/libs/artemis.jar
Binary file not shown.
66 changes: 0 additions & 66 deletions isometric-game-template/src/com/chaonis/isometric/Isometric.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.chaonis.isometric.assets;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;

public final class Assets {

public static AssetManager manager;

private static Assets instance;

//Not synchronized
public static Assets instance() {
if (instance == null) {
instance = new Assets();
}
return instance;
}

private Assets() {
manager = new AssetManager();
}

public static final String loaderTexture = "data/loader/loader.png";
public static final String rocketTexture = "data/rocket/rocket.png";

public void loadRocketAssets() {
manager.load(rocketTexture, Texture.class);
}

public void loadLoaderAssets() {
manager.load(loaderTexture, Texture.class);
}

public void disposeRocketAssets() {
manager.unload(rocketTexture);
}

public void disposeLoaderAssets() {
manager.unload(loaderTexture);
}

public static final String BG0_0 = "data/background/bg0_0.etc1";
public static final String BG1_0 = "data/background/bg1_0.etc1";
public static final String BG2_0 = "data/background/bg2_0.etc1";
public static final String BG3_0 = "data/background/bg3_0.etc1";
public static final String BG0_1 = "data/background/bg0_1.etc1";
public static final String BG1_1 = "data/background/bg1_1.etc1";
public static final String BG2_1 = "data/background/bg2_1.etc1";
public static final String BG3_1 = "data/background/bg3_1.etc1";

public void loadBGAssets() {
manager.load(BG0_0, Texture.class);
manager.load(BG1_0, Texture.class);
manager.load(BG2_0, Texture.class);
manager.load(BG3_0, Texture.class);
manager.load(BG0_1, Texture.class);
manager.load(BG1_1, Texture.class);
manager.load(BG2_1, Texture.class);
manager.load(BG3_1, Texture.class);
}

public void disposeBGAssets() {
manager.unload(BG0_0);
manager.unload(BG1_0);
manager.unload(BG2_0);
manager.unload(BG3_0);
manager.unload(BG0_1);
manager.unload(BG1_1);
manager.unload(BG2_1);
manager.unload(BG3_1);
}

public void loadGameAssets() {
loadRocketAssets();
loadBGAssets();
}

public void disposeGameAssets() {
disposeRocketAssets();
disposeBGAssets();
}

public static void clear() {
Assets.manager.clear();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.chaonis.isometric.model;

/**
* Global constants for the World, e.g. Viewport, Tile sizes, Original Camera coordinates, Zoom levels
*/
public class Globals {

//static viewport width and height
public final static int VIEWP_W = 1280;
public final static int VIEWP_H = 720;

public final static int BG_TILE_W = 1024;
public final static int BG_TILE_H = 1024;

public final static int ORIG_CAM_X = 512;
public final static int ORIG_CAM_Y = 1024;

public final static float ORIG_ZOOM_LEVEL = 1.0f;
public final static float MIN_ZOOM_LEVEL = 0.4f;
public final static float MAX_ZOOM_LEVEL = 1.3f;

public final static int TILE_W = 64;
public final static int TILE_H = 32;

public final static int BORDER = 128;

//static class
private Globals() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.chaonis.isometric.model;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;

/**
* An OrthographicCamera with additional functions, e.g. worldToGrid(), gridToWorld().
*/
public class IsoCamera extends OrthographicCamera {

private final static Matrix4 gridToWorld;
private final static Matrix4 worldToGrid;

static {
gridToWorld = new Matrix4(new float[] {
32f, -16f, 0f, 0f,
-32f, -16f, 0f, 0f,
0f, 0f, 1f, 0f,
2048f, 1912f, 0f, 1f
});
worldToGrid = new Matrix4(gridToWorld).inv();
}

public static void worldToGrid(Vector3 worldCoordinate) {
worldCoordinate.mul(worldToGrid);
}

public static void gridToWorld(Vector3 gridCoordinate) {
gridCoordinate.mul(gridToWorld);
}

public final static float GRID_SIZE_X = 32f;
public final static float GRID_SIZE_Y = 16f;

public void clearScreen() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_COLOR_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chaonis.isometric.model.components;

import com.artemis.Component;

/**
* Background coordinates in Game World. Maybe this component is a bit overkill.
*/
public class BackgroundPosition extends Component {

public int x;
public int y;

public BackgroundPosition(int x, int y) {
this.x = x;
this.y = y;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.chaonis.isometric.model.components;

import com.artemis.Component;
import com.badlogic.gdx.graphics.g2d.Sprite;

/**
* This component stores grid coordinates for the given entity. The left
* coordinates are inclusive the right coordinates exclusive regarding the
* occupation of the given grid. (e.g. the smallest entity at (x,y) occupies
* (x,y), but not (x+1,y) or (x, y+1) and neither (x+1,y+1). Even moving objects
* should have one and only one fixed GridPosition. (Namely the position it is
* located at the moment, or the position it is heading now.)
*/

public class GridPosition extends Component {

public Sprite staticSprite = null;

// For the smallest entities
public GridPosition(int x, int y) {
this(x, y, 1, 1, null);
}

public GridPosition(int x, int y, int w, int h) {
this(x, y, w, h, null);
}

public GridPosition(int x, int y, int w, int h, Sprite textureRegion) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.staticSprite = textureRegion;
}

public int x;
public int y;

public int w;
public int h;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.chaonis.isometric.model.components;

import com.artemis.Component;

// This component stores the current position for the given entity for movable objects.
// These are Game World coordinates.

public class MovablePosition extends Component {

public float x;
public float y;

public float oldX;
public float oldY;

public float startTime = 0;
public float currentTime = 0;

public boolean moving = false;

public MovablePosition(float x, float y) {
this.x = x;
this.y = y;
this.oldX = x;
this.oldY = y;
}
}
Loading

0 comments on commit 40b751f

Please sign in to comment.