diff --git a/defend-android/AndroidManifest.xml b/defend-android/AndroidManifest.xml
index 0f3e17b..f2c4fd4 100644
--- a/defend-android/AndroidManifest.xml
+++ b/defend-android/AndroidManifest.xml
@@ -22,4 +22,5 @@
+
\ No newline at end of file
diff --git a/defend-android/src/com/cdm/defend/MainActivity.java b/defend-android/src/com/cdm/defend/MainActivity.java
index 1b5c04e..a07f759 100644
--- a/defend-android/src/com/cdm/defend/MainActivity.java
+++ b/defend-android/src/com/cdm/defend/MainActivity.java
@@ -13,7 +13,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
- cfg.useGL20 = false;
+ cfg.useGL20 = true;
//AndroidApplicationConfiguration settings = new AndroidApplicationConfiguration();
//settings.resolutionStrategy = new FillResolutionStrategy();
diff --git a/defend/src/com/cdm/defend/DefendGame.java b/defend/src/com/cdm/defend/DefendGame.java
index f5b46b8..839d8b2 100644
--- a/defend/src/com/cdm/defend/DefendGame.java
+++ b/defend/src/com/cdm/defend/DefendGame.java
@@ -48,7 +48,8 @@ public void create() {
highscoreScreen = new HighScoreScreen(this);
inputScreen = new InputScreen(this, c);
SoundFX.Initialize();
- Gdx.graphics.setVSync(true);
+ if (false)
+ Gdx.graphics.setVSync(true);
}
@@ -87,7 +88,7 @@ public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
move();
-
+
screen.render();
}
@@ -108,7 +109,7 @@ private void move() {
}
private void mywait(float delta) {
- if (false)
+ if (true)
return;
try {
int ms = (int) (delta * 1000);
diff --git a/defend/src/com/cdm/gui/BigButton.java b/defend/src/com/cdm/gui/BigButton.java
index 2208aba..d4b6d23 100644
--- a/defend/src/com/cdm/gui/BigButton.java
+++ b/defend/src/com/cdm/gui/BigButton.java
@@ -1,5 +1,6 @@
package com.cdm.gui;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.cdm.gui.anim.Animation;
import com.cdm.gui.anim.AnimationList;
@@ -66,6 +67,7 @@ public boolean opaque(int x, int y) {
@Override
public void clicked(int x, int y, int pointer, int button) {
+ Gdx.input.vibrate(10);
if (buttonPressedListener != null)
buttonPressedListener.buttonPressed(name);
}
diff --git a/defend/src/com/cdm/gui/UnitTypeButton.java b/defend/src/com/cdm/gui/UnitTypeButton.java
index 49b6605..18518e5 100644
--- a/defend/src/com/cdm/gui/UnitTypeButton.java
+++ b/defend/src/com/cdm/gui/UnitTypeButton.java
@@ -1,5 +1,6 @@
package com.cdm.gui;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.cdm.view.IRenderer;
import com.cdm.view.LevelScreen;
@@ -45,9 +46,11 @@ public void touchDown(int x, int y, int pointer, int button) {
return;
super.touchDown(x, y, pointer, button);
- if (listener != null && isEnabled())
+ if (listener != null && isEnabled()) {
listener.unitTypeSelected(type, new Position(x, y,
Position.SCREEN_REF), cost);
+ Gdx.input.vibrate(10);
+ }
}
public IUnitTypeSelected getListener() {
diff --git a/defend/src/com/cdm/view/LevelDisplays.java b/defend/src/com/cdm/view/LevelDisplays.java
index e8e9b4b..ea203ad 100644
--- a/defend/src/com/cdm/view/LevelDisplays.java
+++ b/defend/src/com/cdm/view/LevelDisplays.java
@@ -42,6 +42,8 @@ void draw(IRenderer renderer) {
Gdx.graphics.getHeight(), getLevelText(), moneyColor);
renderer.drawText(Gdx.graphics.getWidth() - 140,
Gdx.graphics.getHeight() - 30, getEnergyText(), moneyColor);
+ renderer.drawText(Gdx.graphics.getWidth() - 140,
+ Gdx.graphics.getHeight() - 80, getFPSText(), moneyColor);
if (up) {
if (color.a >= 0.01f) {
color.a -= 0.01f;
@@ -88,9 +90,8 @@ void draw(IRenderer renderer) {
private CharSequence getGameoverText() {
textBuffer.setLength(0);
textBuffer.append("You've got ").append(level.getPoints())
- .append( " Points \nand ")
- .append(level.getBonus())
- .append(" Bonus POiNts");
+ .append(" Points \nand ").append(level.getBonus())
+ .append(" Bonus POiNts");
return textBuffer;
}
@@ -100,6 +101,12 @@ private CharSequence getEnergyText() {
return textBuffer;
}
+ private CharSequence getFPSText() {
+ textBuffer.setLength(0);
+ textBuffer.append("FPS ").append(level.getFps());
+ return textBuffer;
+ }
+
private CharSequence getLevelText() {
textBuffer.setLength(0);
textBuffer.append("Level ").append(campaign.getLevelNo());
diff --git a/defend/src/com/cdm/view/LevelScreen.java b/defend/src/com/cdm/view/LevelScreen.java
index d2b3b83..0d36eec 100644
--- a/defend/src/com/cdm/view/LevelScreen.java
+++ b/defend/src/com/cdm/view/LevelScreen.java
@@ -6,6 +6,7 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.utils.Json;
import com.cdm.Game;
import com.cdm.gui.IButtonPressed;
import com.cdm.gui.IUnitTypeSelected;
@@ -95,8 +96,6 @@ public synchronized void render() {
}
private void draw() {
- // drawBackground();
-
if (gettingReady && !readonly)
drawGetReady();
else {
@@ -115,25 +114,11 @@ public void drawGetReady() {
renderer.drawText(Gdx.graphics.getWidth() / 2,
Gdx.graphics.getHeight() / 2 - 30, "GET READY", Color.WHITE,
1.5f + (float) Math.sin(textPhase * 3) * 0.2f, true, true);
-
- if (true)
- return;
- if (Gdx.gl10 != null)
- Gdx.gl10.glPushMatrix();
- else {
- Renderer.pushMatrix();
- }
- Position.LEVEL_REF.apply();
-
- level.drawBox(unitRenderer);
- if (Gdx.gl10 != null) {
- Gdx.gl10.glPopMatrix();
- } else {
- Renderer.popMatrix();
- }
}
public void move(float delta) {
+ if (delta > 0)
+ level.setFps((int) (1.0f / delta));
if (gettingReady && !readonly) {
textPhase += delta;
return;
@@ -230,6 +215,7 @@ public boolean touchDown(int x, int y, int pointer, int button) {
upgradeView.setTargetUnit(selectedUnit);
selectedUnit.selected(true);
+ vibrateShort();
}
}
@@ -249,6 +235,7 @@ public boolean touchUp(int x, int y, int pointer, int button) {
if (gettingReady) {
gettingReady = false;
+ vibrateShort();
return false;
}
@@ -258,6 +245,7 @@ public boolean touchUp(int x, int y, int pointer, int button) {
selectedUprade.doAction(selectedUnit);
int price = selectedUprade.getCostForNext();
level.setMoney(level.getMoney() - price);
+ vibrateShort();
}
selectedUnit.selected(false);
@@ -291,11 +279,16 @@ private void stopDragging() {
if (level.gameover())
return;
if (dragElement != null) {
+ vibrateShort();
level.add(dragElement);
}
dragElement = null;
}
+ private void vibrateShort() {
+ Gdx.input.vibrate(10);
+ }
+
public boolean touchDragged(int x, int y, int pointer) {
if (gettingReady)
return false;
@@ -398,6 +391,16 @@ public boolean keyDown(int keycode) {
if (keycode == 44) {
paused = !paused;
}
+ if (keycode == 47) {
+
+ Json json = new Json();
+ String text = json.toJson(level);
+ System.out.println("JSON " + text);
+
+ level = json.fromJson(Level.class, text);
+ level.init(game, this);
+
+ }
System.out.println("KEYCODE " + keycode);
return false;
}
diff --git a/defend/src/com/cdm/view/elements/BackgroundElement.java b/defend/src/com/cdm/view/elements/BackgroundElement.java
index fd6532e..1bda1df 100644
--- a/defend/src/com/cdm/view/elements/BackgroundElement.java
+++ b/defend/src/com/cdm/view/elements/BackgroundElement.java
@@ -144,11 +144,13 @@ public void startRotation() {
@Override
public void draw(IRenderer renderer) {
- renderer.drawPoly(pos, boxes, 0, c0, size);
+ if (false) {
+ renderer.drawPoly(pos, boxes, 0, c0, size);
- renderer.drawPoly(pos, boxes0, 0, c1, size);
+ renderer.drawPoly(pos, boxes0, 0, c1, size);
- renderer.drawLines(pos, lines, 0, c0, size);
+ renderer.drawLines(pos, lines, 0, c0, size);
+ }
}
@Override
diff --git a/defend/src/com/cdm/view/elements/Grid.java b/defend/src/com/cdm/view/elements/Grid.java
index 4e4c1c0..b858c2f 100644
--- a/defend/src/com/cdm/view/elements/Grid.java
+++ b/defend/src/com/cdm/view/elements/Grid.java
@@ -5,6 +5,9 @@
import java.util.Set;
import java.util.TreeSet;
+import com.badlogic.gdx.utils.Json;
+import com.badlogic.gdx.utils.Json.Serializable;
+import com.badlogic.gdx.utils.OrderedMap;
import com.cdm.view.Position;
import com.cdm.view.elements.paths.PathPos;
import com.cdm.view.elements.units.PlayerUnit;
@@ -12,12 +15,12 @@
import com.cdm.view.enemy.EnemyUnit;
// review1
-public class Grid {
+public class Grid implements Serializable {
public enum CellType {
FREE, BLOCK, EMPTY
};
- public class GridElement {
+ public static class GridElement implements Serializable {
private Set currentElements;
private int distanceToEnd;
@@ -27,6 +30,10 @@ public class GridElement {
private CellType cellType = CellType.EMPTY;
int x, y;
+ public GridElement() {
+
+ }
+
public GridElement(int x, int y) {
this.x = x;
this.y = y;
@@ -152,6 +159,27 @@ public Unit getFirstUnit(Class extends Unit> klass) {
return null;
}
+ @Override
+ public void write(Json json) {
+ json.writeValue("distanceToEnd", distanceToEnd);
+ json.writeValue("computationValue", computationValue);
+ json.writeValue("distanceToEnd", distanceToEnd);
+ json.writeValue("cellType", cellType);
+ json.writeValue("x", x);
+ json.writeValue("y", y);
+
+ }
+
+ @Override
+ public void read(Json json, OrderedMap jsonData) {
+ json.readValue("distanceToEnd", Integer.class, jsonData);
+ json.readValue("computationValue", Integer.class, jsonData);
+ json.readValue("distanceToEnd", Integer.class, jsonData);
+ json.readValue("cellType", CellType.class, jsonData);
+ json.readValue("x", Integer.class, jsonData);
+ json.readValue("y", Integer.class, jsonData);
+ }
+
}
private GridElement[] cells;
@@ -160,6 +188,10 @@ public Unit getFirstUnit(Class extends Unit> klass) {
private List endPositions;
private List playerUnitDef = new ArrayList();
+ public Grid() {
+
+ }
+
public Grid(int w2, int h2) {
w = w2;
h = h2;
@@ -262,4 +294,23 @@ public List getDefs() {
return playerUnitDef;
}
+ @Override
+ public void write(Json json) {
+ json.writeValue("width", w);
+ json.writeValue("height", h);
+ json.writeValue("start", startPositions);
+ json.writeValue("end", endPositions);
+ json.writeValue("cells", cells);
+
+ }
+
+ @Override
+ public void read(Json json, OrderedMap jsonData) {
+ w = json.readValue("width", Integer.class, jsonData);
+ h = json.readValue("height", Integer.class, jsonData);
+ startPositions = json.readValue("start", List.class, jsonData);
+ endPositions = json.readValue("end", List.class, jsonData);
+ cells = json.readValue("cells", GridElement[].class, jsonData);
+ }
+
}
diff --git a/defend/src/com/cdm/view/elements/GridDrawing.java b/defend/src/com/cdm/view/elements/GridDrawing.java
index 616b8cc..2f1c5dc 100644
--- a/defend/src/com/cdm/view/elements/GridDrawing.java
+++ b/defend/src/com/cdm/view/elements/GridDrawing.java
@@ -36,6 +36,8 @@ public GridDrawing(Grid pgrid) {
}
public void draw(IRenderer renderer) {
+ if (false)
+ return;
for (int i = 0; i < es.size(); i++) {
Element e = es.get(i);
if (e.getPosition().onScreen())
diff --git a/defend/src/com/cdm/view/elements/Level.java b/defend/src/com/cdm/view/elements/Level.java
index eee7d65..69d6f9c 100644
--- a/defend/src/com/cdm/view/elements/Level.java
+++ b/defend/src/com/cdm/view/elements/Level.java
@@ -7,8 +7,10 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import com.badlogic.gdx.utils.Json;
+import com.badlogic.gdx.utils.Json.Serializable;
+import com.badlogic.gdx.utils.OrderedMap;
import com.cdm.Game;
-import com.cdm.gui.effects.SoundFX;
import com.cdm.gui.effects.SoundFX.Type;
import com.cdm.view.IRenderer;
import com.cdm.view.LevelScreen;
@@ -29,7 +31,7 @@
import com.cdm.view.enemy.EnemyPlayer;
import com.cdm.view.enemy.EnemyUnit;
-public class Level {
+public class Level implements Serializable {
private Grid grid;
private Selector selector = null;
private EnemyPlayer player;
@@ -48,12 +50,27 @@ public class Level {
private List shotsToAdd = new ArrayList();
private List decals = new ArrayList();
private Game game;
+ private int fps;
+
+ public Level() {
+
+ }
public Level(Game pGame, Grid pGrid, LevelScreen pfinishedListener,
PlayerState pState) {
- game = pGame;
- playerState = pState;
grid = pGrid;
+ playerState = pState;
+
+ init(pGame, pfinishedListener);
+ for (PlayerUnitDef def : grid.getDefs()) {
+ add(def.pos, def.type);
+ }
+ displayEffects.add(new ZoomInEffect(this));
+
+ }
+
+ public void init(Game pGame, LevelScreen pfinishedListener) {
+ game = pGame;
Position.LEVEL_REF.setWidth(grid.getW());
Position.LEVEL_REF.setHeight(grid.getH());
@@ -64,10 +81,7 @@ public Level(Game pGame, Grid pGrid, LevelScreen pfinishedListener,
PathFinder.breadthSearch(grid, PathFinder.GOAL_ACCESSOR,
getEnemyStartPosition(), getEnemyEndPosition(), null, false);
- displayEffects.add(new ZoomInEffect(this));
- for (PlayerUnitDef def : pGrid.getDefs()) {
- add(def.pos, def.type);
- }
+
}
public void add(Position pos, UnitType type) {
@@ -110,20 +124,25 @@ public synchronized void move(float time) {
for (Decal decal : decals) {
decal.move(time);
}
- displayEffects.addAll(shotsToAdd);
- shotsToAdd.clear();
+ cleanup();
+ gridDrawing.move(time);
+ }
+
+ private void cleanup() {
for (Unit unit : unitsToRemove) {
units.remove(unit);
removeMeFromGrid(unit.getPosition(), unit);
}
unitsToRemove.clear();
+ displayEffects.addAll(shotsToAdd);
+ shotsToAdd.clear();
for (DisplayEffect shot : displayEffectsToRemove) {
displayEffects.remove(shot);
}
displayEffectsToRemove.clear();
displayEffects.addAll(displayEffectsToAdd);
displayEffectsToAdd.clear();
- gridDrawing.move(time);
+
}
public void draw(IRenderer renderer) {
@@ -460,4 +479,32 @@ public void play(Type hit2) {
game.play(hit2);
}
+ @Override
+ public void write(Json json) {
+ cleanup();
+
+ json.writeValue("grid", grid);
+ if (false) {
+ json.writeValue("enemy", player);
+ json.writeValue("speedFactor", speedFactor);
+ json.writeValue("units", units);
+ json.writeValue("playerState", playerState);
+ json.writeValue("displayEffects", displayEffects);
+ json.writeValue("decals", decals);
+ }
+ }
+
+ @Override
+ public void read(Json json, OrderedMap jsonData) {
+ grid = json.readValue("grid", Grid.class, jsonData);
+ }
+
+ public int getFps() {
+ return fps;
+ }
+
+ public void setFps(int fps) {
+ this.fps = fps;
+ }
+
}
diff --git a/defend/src/com/cdm/view/elements/paths/PathPos.java b/defend/src/com/cdm/view/elements/paths/PathPos.java
index d684a15..17a52cf 100644
--- a/defend/src/com/cdm/view/elements/paths/PathPos.java
+++ b/defend/src/com/cdm/view/elements/paths/PathPos.java
@@ -3,12 +3,15 @@
import java.util.Arrays;
import java.util.List;
+import com.badlogic.gdx.utils.Json;
+import com.badlogic.gdx.utils.Json.Serializable;
+import com.badlogic.gdx.utils.OrderedMap;
import com.cdm.view.Position;
-public class PathPos implements Comparable {
+public class PathPos implements Comparable, Serializable {
public int x, y;
public int value;
- private static Position tmp=new Position(0,0,Position.LEVEL_REF);
+ private static Position tmp = new Position(0, 0, Position.LEVEL_REF);
public PathPos(Position pos) {
x = (int) pos.x;
@@ -21,24 +24,25 @@ public PathPos(int _x, int _y, int _v) {
y = _y;
value = _v;
}
-
public PathPos() {
x = y = value = -1;
}
+
public Position tmp() {
- tmp.x=x;
- tmp.y=y;
+ tmp.x = x;
+ tmp.y = y;
return tmp;
}
public String toString() {
- //return "[" + value + "]";
+ // return "[" + value + "]";
return "[" + x + "," + y + ";" + value + "]";
}
+
public boolean equals(Object p) {
- if(p instanceof PathPos) {
- return equals((PathPos)p);
+ if (p instanceof PathPos) {
+ return equals((PathPos) p);
}
return false;
}
@@ -83,4 +87,20 @@ public void assign(PathPos t) {
}
+ @Override
+ public void write(Json json) {
+ json.writeValue("x", x);
+ json.writeValue("y", y);
+ json.writeValue("value", value);
+
+ }
+
+ @Override
+ public void read(Json json, OrderedMap jsonData) {
+ x = json.readValue("x", Integer.class,jsonData);
+ y = json.readValue("y", Integer.class,jsonData);
+ value = json.readValue("value", Integer.class,jsonData);
+
+ }
+
}