Skip to content

Commit

Permalink
opt tries
Browse files Browse the repository at this point in the history
  • Loading branch information
godrin committed Oct 8, 2012
1 parent 2662611 commit e6d596a
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 50 deletions.
1 change: 1 addition & 0 deletions defend-android/AndroidManifest.xml
Expand Up @@ -22,4 +22,5 @@
</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
2 changes: 1 addition & 1 deletion defend-android/src/com/cdm/defend/MainActivity.java
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions defend/src/com/cdm/defend/DefendGame.java
Expand Up @@ -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);

}

Expand Down Expand Up @@ -87,7 +88,7 @@ public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

move();

screen.render();

}
Expand All @@ -108,7 +109,7 @@ private void move() {
}

private void mywait(float delta) {
if (false)
if (true)
return;
try {
int ms = (int) (delta * 1000);
Expand Down
2 changes: 2 additions & 0 deletions 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;
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion 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;
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 10 additions & 3 deletions defend/src/com/cdm/view/LevelDisplays.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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());
Expand Down
39 changes: 21 additions & 18 deletions defend/src/com/cdm/view/LevelScreen.java
Expand Up @@ -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;
Expand Down Expand Up @@ -95,8 +96,6 @@ public synchronized void render() {
}

private void draw() {
// drawBackground();

if (gettingReady && !readonly)
drawGetReady();
else {
Expand All @@ -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;
Expand Down Expand Up @@ -230,6 +215,7 @@ public boolean touchDown(int x, int y, int pointer, int button) {
upgradeView.setTargetUnit(selectedUnit);

selectedUnit.selected(true);
vibrateShort();
}
}

Expand All @@ -249,6 +235,7 @@ public boolean touchUp(int x, int y, int pointer, int button) {

if (gettingReady) {
gettingReady = false;
vibrateShort();
return false;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions defend/src/com/cdm/view/elements/BackgroundElement.java
Expand Up @@ -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
Expand Down
55 changes: 53 additions & 2 deletions defend/src/com/cdm/view/elements/Grid.java
Expand Up @@ -5,19 +5,22 @@
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;
import com.cdm.view.elements.units.Unit;
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<Element> currentElements;
private int distanceToEnd;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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;
Expand All @@ -160,6 +188,10 @@ public Unit getFirstUnit(Class<? extends Unit> klass) {
private List<PathPos> endPositions;
private List<PlayerUnitDef> playerUnitDef = new ArrayList<PlayerUnitDef>();

public Grid() {

}

public Grid(int w2, int h2) {
w = w2;
h = h2;
Expand Down Expand Up @@ -262,4 +294,23 @@ public List<PlayerUnitDef> 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<String, Object> 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);
}

}
2 changes: 2 additions & 0 deletions defend/src/com/cdm/view/elements/GridDrawing.java
Expand Up @@ -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())
Expand Down

0 comments on commit e6d596a

Please sign in to comment.