Skip to content

Commit

Permalink
Added scores and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
gkushev committed Jun 23, 2015
1 parent f25c718 commit 4033931
Show file tree
Hide file tree
Showing 140 changed files with 253 additions and 116 deletions.
Binary file added android/assets/enemyhealth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/assets/enemyhealthbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/assets/font/Peinture Fraiche.ttf
Binary file not shown.
Binary file added android/assets/font/Roboto-Black.ttf
Binary file not shown.
Binary file added android/assets/font/Roboto-Bold.ttf
Binary file not shown.
Binary file added android/assets/font/Roboto-Regular.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion android/assets/levels/level1.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<property name="waypoints" value="1,0|1,7|13,7|13,1|5,1|5,3|11,3|11,5|3,5|3,0"/>
</properties>
<tileset firstgid="1" name="tiles" tilewidth="46" tileheight="46" spacing="2" margin="2">
<image source="../tiles.png" width="128" height="256"/>
<image source="tiles.png" width="128" height="256"/>
</tileset>
<layer name="wall_layer" width="15" height="9">
<data encoding="base64" compression="zlib">
Expand Down
File renamed without changes
File renamed without changes.
9 changes: 0 additions & 9 deletions android/assets/pics/Terms of Use.txt

This file was deleted.

Binary file removed android/assets/pics/background-tilesets/01.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/02.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/03.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/04.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/05.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/06.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/07.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/08.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/09.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/10.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/11.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/12.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/13-1.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/13-2.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/13-3.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/13.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/14.png
Binary file not shown.
Binary file removed android/assets/pics/background-tilesets/15.png
Binary file not shown.
Binary file removed android/assets/pics/creep/creep-1-blue/1.png
Binary file not shown.
Binary file removed android/assets/pics/creep/creep-1-blue/2.png
Binary file not shown.
Binary file removed android/assets/pics/creep/creep-1-blue/3.png
Binary file not shown.
Binary file removed android/assets/pics/creep/creep-1-blue/4.png
Binary file not shown.
Binary file removed android/assets/pics/creep/creep-1-blue/5.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-blue/6.png
Diff not rendered.
8 changes: 0 additions & 8 deletions android/assets/pics/creep/creep-1-frames.txt

This file was deleted.

Binary file removed android/assets/pics/creep/creep-1-green/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-green/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-green/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-green/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-green/5.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-green/6.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/5.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-red/6.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/5.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-1-yellow/6.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-blue/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-blue/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-blue/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-blue/4.png
Diff not rendered.
6 changes: 0 additions & 6 deletions android/assets/pics/creep/creep-2-frames.txt

This file was deleted.

Binary file removed android/assets/pics/creep/creep-2-green/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-green/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-green/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-green/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-red/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-red/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-red/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-red/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-yellow/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-yellow/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-yellow/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-2-yellow/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-blue/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-blue/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-blue/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-blue/4.png
Diff not rendered.
6 changes: 0 additions & 6 deletions android/assets/pics/creep/creep-3-frames.txt

This file was deleted.

Binary file removed android/assets/pics/creep/creep-3-green/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-green/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-green/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-green/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-red/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-red/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-red/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-red/4.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-yellow/1.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-yellow/2.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-yellow/3.png
Diff not rendered.
Binary file removed android/assets/pics/creep/creep-3-yellow/4.png
Diff not rendered.
Binary file removed android/assets/pics/tiles/tile-1-center.gif
Diff not rendered.
Diff not rendered.
Binary file removed android/assets/pics/tiles/tile-1-corner-left-top.gif
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed android/assets/pics/tiles/tile-1-horizontal.gif
Diff not rendered.
Binary file removed android/assets/pics/tiles/tile-1-vertical.gif
Diff not rendered.
Binary file removed android/assets/pics/tower-defense-screenshot.jpg_
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/boss-1.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/boss-2.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/boss-3.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/boss-4.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/hangar-ship.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/stat-current.png
Diff not rendered.
Binary file removed android/assets/pics/tower-defense/stat-upgrade.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed android/assets/texture/texture_n.png
Diff not rendered.
27 changes: 12 additions & 15 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
android {
buildToolsVersion "21.1.2"
buildToolsVersion '22.0.1'
compileSdkVersion 22
sourceSets {
main {
Expand All @@ -15,22 +15,20 @@ android {
instrumentTest.setRoot('tests')
}
}


// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/x86/").mkdirs();

configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if (outputDir != null) {
copy {
from zipTree(jar)
into outputDir
Expand All @@ -39,7 +37,6 @@ task copyAndroidNatives() {
}
}
}

task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
Expand All @@ -61,7 +58,6 @@ task run(type: Exec) {
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'bg.ittalents.tower_defense.android/bg.ittalents.tower_defense.android.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
Expand All @@ -78,8 +74,8 @@ eclipse {
}

classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
plusConfigurations += [project.configurations.compile]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}

project {
Expand All @@ -92,12 +88,11 @@ eclipse {
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}

// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
scopes = [COMPILE: [plus: [project.configurations.compile]]]

iml {
withXml {
Expand All @@ -107,11 +102,13 @@ idea {
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
option(name: "UPDATE_PROPERTY_FILES", value: "true")
}
}
}
}
}
}
}
dependencies {
}
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
Expand All @@ -59,6 +60,10 @@ project(":android") {
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
}
}

Expand All @@ -72,6 +77,7 @@ project(":html") {
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
}
Expand All @@ -84,6 +90,7 @@ project(":core") {
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
}
}

Expand Down
86 changes: 50 additions & 36 deletions core/src/bg/ittalents/tower_defense/game/Level.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package bg.ittalents.tower_defense.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
Expand All @@ -16,46 +13,51 @@
import bg.ittalents.tower_defense.game.objects.AbstractProjectile;
import bg.ittalents.tower_defense.game.objects.AbstractTower;
import bg.ittalents.tower_defense.game.objects.Assets;
import bg.ittalents.tower_defense.game.objects.Background;
import bg.ittalents.tower_defense.game.objects.Creep;
import bg.ittalents.tower_defense.game.objects.Tower;

public class Level implements Disposable {

public static final int STARTING_LIVES = 10;
public static final int STARTING_MONEY = 100;

public static final String TAG = Level.class.getName();

private int lives;
private int money;
private int score;

private int tileRows;
private int tileColumns;
private int tileWidth;
private int tileHeight;
Vector2 startPosition;

private TiledMap tiledMap;
private OrthogonalTiledMapRenderer mapRenderer;
private Background background;


private Array<AbstractTower> towers;
private Array<AbstractCreep> creeps;
private Array<AbstractProjectile> projectiles;
private Array<Vector2> wayponts;

private Batch batch;
// private Batch batch;

public Level(String fileName) {
public Level(TiledMap tiledMap) {

money = STARTING_MONEY;
lives = STARTING_LIVES;

towers = new Array<AbstractTower>();
creeps = new Array<AbstractCreep>();
wayponts = new Array<Vector2>();
projectiles = new Array<AbstractProjectile>();

startPosition = new Vector2();
init(fileName);
background = new Background(getWidth(), getHeight());

loadLevelData(tiledMap);
init();
}

private void init(String fileName) {
load(fileName);
loadWayPoints(fileName);
private void init() {

Tower tower1 = new Tower(2.5f * tileWidth, 6.5f * tileHeight,
Assets.instance.towers.tower[0]);
Expand All @@ -80,15 +82,11 @@ private void init(String fileName) {
towers.add(tower7);
}


private void load(String fileName) {
tiledMap = new TmxMapLoader().load(fileName);
private void loadLevelData(TiledMap tiledMap) {
tileColumns = tiledMap.getProperties().get("width", Integer.class);
tileRows = tiledMap.getProperties().get("height", Integer.class);
tileWidth = tiledMap.getProperties().get("tilewidth", Integer.class);
tileHeight = tiledMap.getProperties().get("tileheight", Integer.class);
mapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
batch = mapRenderer.getBatch();

loadWayPoints(tiledMap.getProperties().get("waypoints", String.class));
}
Expand Down Expand Up @@ -119,15 +117,31 @@ public void spawnCreep() {
}

public void update(float deltaTime) {
updateCreeps(deltaTime);
updateProjectiles(deltaTime);
updateTowers(deltaTime);

// Gdx.app.debug(TAG, "Money: " + money + ", Score: " + score + ", Lives: " + lives);
}

private void updateCreeps(float deltaTime) {
for (Iterator<AbstractCreep> creepIterator = creeps.iterator(); creepIterator.hasNext();) {
AbstractCreep creep = creepIterator.next();
if (creep.isVisible()) {
creep.update(deltaTime);
} else {
if (creep.isDead()) {
money += creep.getReward();
score += creep.getReward();
} else {
lives--;
}
creepIterator.remove();
}
}
}

private void updateProjectiles(float deltaTime) {
for (Iterator<AbstractProjectile> projectileIterator = projectiles.iterator(); projectileIterator.hasNext();) {
AbstractProjectile projectile = projectileIterator.next();
if (projectile.isVisible()) {
Expand All @@ -136,7 +150,9 @@ public void update(float deltaTime) {
projectileIterator.remove();
}
}
}

private void updateTowers(float deltaTime) {
for (AbstractTower tower : towers) {
if (!tower.hasTarget()) {
for (AbstractCreep creep : creeps) {
Expand All @@ -147,7 +163,7 @@ public void update(float deltaTime) {
}
}
tower.update(deltaTime);
if(tower.isReady() && tower.hasTarget()) {
if(tower.isReadyToShoot() && tower.hasTarget()) {
projectiles.add(tower.shoot());
}
}
Expand All @@ -161,37 +177,35 @@ public int getHeight() {
return tileRows * tileHeight;
}

public void render(OrthographicCamera camera) {
public int getLives() {
return lives;
}

batch.setProjectionMatrix(camera.combined);
batch.begin();
public int getMoney() {
return money;
}

background.render(batch);
public int getScore() {
return score;
}

batch.end();
mapRenderer.setView(camera);
mapRenderer.render();
public void render(Batch batch) {
batch.begin();

for (AbstractCreep creep : creeps) {
if(creep.isVisible()) {
creep.render(batch);
}
creep.render(batch);
}
for (AbstractTower tower : towers) {
tower.render(batch);
}
for (AbstractProjectile projectile : projectiles) {
if(projectile.isVisible()) {
projectile.render(batch);
}
projectile.render(batch);
}

batch.end();
}

@Override
public void dispose() {
mapRenderer.dispose();
tiledMap.dispose();
}
}
Loading

0 comments on commit 4033931

Please sign in to comment.