Skip to content

Commit

Permalink
Merge branch 'release/v0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelCz committed May 17, 2014
2 parents 648e960 + 9b3ea45 commit 91a4379
Show file tree
Hide file tree
Showing 35 changed files with 521 additions and 190 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<classpathentry kind="lib" path="lib/lwjgl_util.jar"/>
<classpathentry kind="lib" path="lib/lwjgl.jar">
<attributes>
<attribute name="javadoc_location" value="http://slick.ninjacave.com/javadoc/"/>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="TowerDefense/dll/windows"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/slick.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
</classpath>
7 changes: 5 additions & 2 deletions src/data/files/enemies/enemies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
100, 0.1, enemy/v1n.png, 32, 20, 0.5
200, 0.25, enemy/v2n.png, 32, 100, 0.4
10000, 0.03, enemy/v1n.png, 32, 1000, 0.7
50, 0.3, enemy/Enemy_1_klein.png, 15, 30, 0.4
200, 0.25, enemy/v2n.png, 25, 100, 0.4
400, 0.1, enemy/Enemy_2_klein.png, 25, 60, 0.6
700, 0.15, enemy/Enemy_3_klein.png, 20, 100, 0.9
10000, 0.03, enemy/v1n.png, 32, 1000, 0.7
24 changes: 12 additions & 12 deletions src/data/files/waves/1.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
1, 100, 0, 0
2, 100, 0, 0
2, 100, 0, 0
3, 95, 5, 0
6, 90, 10, 0
6, 70, 30, 0
9, 80, 20, 0
15, 80, 20, 0
12, 50, 50, 0
30, 70, 30, 0
50, 50, 50, 0
1, 0, 0, 100
1, 100, 0, 0, 0, 0, 0
2, 100, 0, 0, 0, 0, 0
2, 100, 0, 0, 0, 0, 0
3, 80, 5, 15, 0, 0, 0
6, 80, 10, 10, 0, 0, 0
6, 20, 30, 20, 30, 0, 0
9, 30, 20, 20, 30, 0, 0
15, 40, 20, 30, 10, 0, 0
12, 10, 10, 40, 10, 30, 0
30, 10, 30, 20, 10, 30, 0
50, 0, 20, 20, 30, 30, 0
1, 0, 0, 0, 0, 0, 100
Binary file modified src/data/graphics/enemy/v1.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 src/data/graphics/enemy/v2.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 src/data/graphics/tower/Tower2.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 src/data/graphics/tower/t1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions src/engine/Camera.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package engine;

import towerDefense.Gameplay;
import towerDefense.TowerDefense;

public class Camera extends Entity {
private Gameplay game;

public Camera(float x, float y, Gameplay game) {
super(x, y);
this.game = game;
}

public void addX(float amount) {
this.setX(amount + this.getX());

}

public void addY(float amount) {
this.setY(amount + this.getY());

}

public void setX(float x) {
this.x = x;
float cameraWidth = Gameplay.INTERFACE_START_X;
if (Gameplay.getCameraX() < 0) {
this.setX(0);
} else if ((Gameplay.getCameraX() + cameraWidth) / Gameplay.CURRENT_GAME_SCALE > this.game.getHorizontalTiles()
* Gameplay.DEFAULT_SIZE) {
this.setX((this.game.getHorizontalTiles() * Gameplay.DEFAULT_SIZE) * Gameplay.CURRENT_GAME_SCALE - cameraWidth);

}
}

public void setY(float y) {
this.y = y;
float cameraHeight = TowerDefense.getHeight();
if (Gameplay.getCameraY() < 0) {
this.setY(0);
} else if ((Gameplay.getCameraY() + cameraHeight) / Gameplay.CURRENT_GAME_SCALE > this.game.getVerticalTiles()
* Gameplay.DEFAULT_SIZE) {
this.setY((this.game.getVerticalTiles() * Gameplay.DEFAULT_SIZE) * Gameplay.CURRENT_GAME_SCALE - cameraHeight);

}
}

}
17 changes: 16 additions & 1 deletion src/engine/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Enemy extends Entity implements Drawable {
protected int direction;
private int worth;
private boolean dead = false;
private boolean wobble = true;
private double wobbleFactor;
private int wobbleTimer = 0;

private Enemy(int maxHealth, float speed, Sprite sprite, Waypoint startingWaypoint, Gameplay game, float radius, int worth) {
super(startingWaypoint.getX() * Gameplay.DEFAULT_SIZE, startingWaypoint.getY() * Gameplay.DEFAULT_SIZE);
Expand Down Expand Up @@ -46,6 +49,10 @@ public void setY(float y) {
}

public void update(int delta) {
if (this.wobble) {
this.wobbleTimer += delta;
this.wobbleFactor = (Math.sin(this.wobbleTimer / 200.0) + 6) / 8;
}
if (this.health > 0) {
this.x += this.velocity.getX() * delta;
this.y += this.velocity.getY() * delta;
Expand Down Expand Up @@ -94,7 +101,15 @@ private void newDirection() {
@Override
public void draw() {
if (this.health > 0) {
this.sprite.draw((this.x) * Gameplay.GLOBAL_GAME_SCALE, (this.y) * Gameplay.GLOBAL_GAME_SCALE, Gameplay.GLOBAL_GAME_SCALE);
if (this.wobble) {
float scale = (float) this.wobbleFactor;
float size = (Gameplay.DEFAULT_SIZE - this.sprite.getWidth() * scale) / 2;
this.sprite.draw((this.x + size) * Gameplay.CURRENT_GAME_SCALE- Gameplay.getCameraX(),
(this.y + size) * Gameplay.CURRENT_GAME_SCALE- Gameplay.getCameraY(), scale * Gameplay.CURRENT_GAME_SCALE);
} else {
this.sprite.draw((this.x) * Gameplay.CURRENT_GAME_SCALE, (this.y) * Gameplay.CURRENT_GAME_SCALE,
Gameplay.CURRENT_GAME_SCALE);
}
}
}

Expand Down
45 changes: 22 additions & 23 deletions src/engine/GameComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import towerDefense.Gameplay;
import towerDefense.TowerDefense;
import engine.gui.Clickable;
import engine.gui.GUI;
Expand All @@ -16,6 +17,7 @@ public abstract class GameComponent {

protected List<GUI> guiElements;
protected List<Clickable> clickables;
private boolean mouseWasClicked;

protected TowerDefense game;
private Clickable wasClicked;
Expand Down Expand Up @@ -45,42 +47,39 @@ public void render(GameContainer container, Graphics graphics) throws SlickExcep
}

private void updateClickables(GameContainer container, int delta) {
for (Clickable clickable : this.clickables) {
clickable.update(container, 1f);
}
Input input = container.getInput();
float x = input.getMouseX();
float y = input.getMouseY();
if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {

float x = input.getMouseX();
float y = input.getMouseY();

boolean buttonWasPressed = false;
this.mouseWasClicked = true;
for (Clickable clickable : this.clickables) {
if (clickable.collides((int) x, (int) y, 1f)) {
buttonWasPressed = true;
clickable.onClick();
this.wasClicked = clickable;
this.game.getSoundHandler().play("press");
}
clickable.update(x, y, container);
}

}
// checks if mouse button was released again after being pressed
if (this.wasClicked != null && !input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {

this.wasClicked.onRelease();
this.wasClicked = null;

} else {
if (this.mouseWasClicked) {
this.mouseWasClicked = false;
for (Clickable clickable : this.clickables) {
if (!clickable.isStayClicked()) {
if (clickable.isClicked()) {
clickable.onRelease();
}
}
}
}
}
}

public SoundHandler getSoundHandler() {
return this.game.getSoundHandler();
}

private void releaseAllClickables() {
public void releaseAllClickablesExcept(Clickable excluded) {
for (Clickable clickable : this.clickables) {
clickable.onRelease();
if (clickable != excluded) {
clickable.onRelease();
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Level(String levelPath, Gameplay game) {
private void initLevel(List<String> lines, Gameplay game) {

this.map = new MapLayout(lines.get(0), Gameplay.DEFAULT_SIZE, lines.get(1));
this.mapBackgound = new BackgroundTiles(0.5f, lines.get(2), this.map.getNumberTilesWidth(), this.map.getNumberTilesWidth());
this.mapBackgound = new BackgroundTiles(0.5f, lines.get(2), this.map.getNumberTilesWidth(), this.map.getNumberTilesWidth(), game);
this.waves = new WaveHandler(game, 2000, lines.get(3));
this.enemies = new EnemyTypeHandler(game, lines.get(4));

Expand Down
6 changes: 4 additions & 2 deletions src/engine/graphics/Background.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

public class Background implements Drawable {
protected Sprite picture;
protected Gameplay game;

public Background(float scale, String backgroundPath) {
public Background(float scale, String backgroundPath, Gameplay game) {
this.picture = new Sprite(backgroundPath, scale);
this.game = game;
}

@Override
public void draw() {
this.picture.draw(0, 0, Gameplay.GLOBAL_GAME_SCALE);
this.picture.draw(0, 0, Gameplay.CURRENT_GAME_SCALE);

}

Expand Down
14 changes: 8 additions & 6 deletions src/engine/graphics/BackgroundTiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class BackgroundTiles extends Background {
private int horizontalTiles, verticalTiles;
private Sprite pictureOutOfBounds;

public BackgroundTiles(float scale, String backgroundPath, int horizontalTiles, int verticalTiles) {
super(scale, backgroundPath);
public BackgroundTiles(float scale, String backgroundPath, int horizontalTiles, int verticalTiles, Gameplay game) {
super(scale, backgroundPath, game);
this.horizontalTiles = horizontalTiles;
this.verticalTiles = verticalTiles;
this.pictureOutOfBounds = new Sprite(backgroundPath);
Expand All @@ -20,12 +20,14 @@ public BackgroundTiles(float scale, String backgroundPath, int horizontalTiles,

@Override
public void draw() {
for (int i = 0; i < TowerDefense.getWidth() / Gameplay.SIZE; ++i) {
for (int j = 0; j < TowerDefense.getHeight() / Gameplay.SIZE; ++j) {
for (int i = 0; i < this.game.getHorizontalTiles() + 1; ++i) {
for (int j = 0; j < this.game.getVerticalTiles() + 1; ++j) {
if (i < this.horizontalTiles && j < this.verticalTiles) {
this.picture.draw(i * Gameplay.SIZE, j * Gameplay.SIZE, Gameplay.GLOBAL_GAME_SCALE);
this.picture.draw(i * Gameplay.SIZE - Gameplay.getCameraX(), j * Gameplay.SIZE - Gameplay.getCameraY(),
Gameplay.CURRENT_GAME_SCALE);
} else {
this.pictureOutOfBounds.draw(i * Gameplay.SIZE, j * Gameplay.SIZE, Gameplay.GLOBAL_GAME_SCALE);
this.pictureOutOfBounds.draw(i * Gameplay.SIZE - Gameplay.getCameraX(), j * Gameplay.SIZE - Gameplay.getCameraY(),
Gameplay.CURRENT_GAME_SCALE);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/engine/graphics/PathTiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void render() {
for (int y = 0; y < this.tiles.length; ++y) {
for (int x = 0; x < this.tiles[0].length; ++x) {
if (this.tiles[y][x] != null) {
this.tiles[y][x].draw(x * Gameplay.SIZE, y * Gameplay.SIZE, Gameplay.GLOBAL_GAME_SCALE);
this.tiles[y][x].draw(x * Gameplay.SIZE - Gameplay.getCameraX(), y * Gameplay.SIZE - Gameplay.getCameraY(),
Gameplay.CURRENT_GAME_SCALE);
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/engine/gui/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ public class Button extends Clickable {
private Sprite unclickedButton;
private Sprite clickedButton;

public Button(float x, float y, String unclickedButtonPath, String clickedButtonPath) {
this(x,y,new Sprite(unclickedButtonPath), new Sprite(clickedButtonPath));
public Button(float x, float y, String unclickedButtonPath, String clickedButtonPath, Gameplay game, boolean stayClicked) {
this(x, y, new Sprite(unclickedButtonPath), new Sprite(clickedButtonPath), game, stayClicked);
}
public Button(float x, float y, Sprite unclickedButton, Sprite clickedButton) {
super(x, y);

public Button(float x, float y, Sprite unclickedButton, Sprite clickedButton, Gameplay game, boolean stayClicked) {
super(x, y, game, stayClicked);
this.unclickedButton = unclickedButton;
this.clickedButton = clickedButton;
this.collisionWidth = this.unclickedButton.getWidth();
Expand Down Expand Up @@ -40,7 +41,7 @@ public void onUnHover() {
// TODO Auto-generated method stub

}

public void setUnclickedButton(Sprite picture) {
this.unclickedButton = picture;
}
Expand Down
39 changes: 29 additions & 10 deletions src/engine/gui/Clickable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;

import towerDefense.Gameplay;

public abstract class Clickable extends GUI {
protected float collisionWidth, collisionHeight;
protected boolean clicked = false;
protected Gameplay game;
protected boolean stayClicked;

public Clickable(float x, float y) {
public Clickable(float x, float y, Gameplay game, boolean stayClicked) {
super(x, y);
this.game = game;
this.stayClicked = stayClicked;
}

public void update(float mouseX, float mouseY, GameContainer container) {
if (this.collides((int) mouseX, (int) mouseY, Gameplay.GLOBAL_GUI_SCALE)) {
if (this.clicked) {
this.onRelease();
} else {
this.game.releaseAllClickablesExcept(this);
this.onClick();

}
this.game.getSoundHandler().play("press");

}

}

public void onClick() {
Expand All @@ -28,14 +49,12 @@ public boolean collides(int x, int y, float globalScale) {
* globalScale);
}

public void update(GameContainer container, float globalScale) {
Input input = container.getInput();
float x = input.getMouseX();
float y = input.getMouseY();
if (!this.clicked && this.collides((int) x, (int) y, globalScale)) {
this.onHover();
} else if (!this.clicked) {
this.onUnHover();
}
public boolean isStayClicked() {
return this.stayClicked;
}

public boolean isClicked() {
return this.clicked;
}

}
5 changes: 3 additions & 2 deletions src/engine/gui/ClickableText.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import org.newdawn.slick.Color;

import towerDefense.Gameplay;
import engine.graphics.Text;

public class ClickableText extends Clickable {
private Text text;

public ClickableText(float x, float y, String text, float globalScale) {
super(x, y);
public ClickableText(float x, float y, String text, float globalScale, Gameplay game, boolean stayClicked) {
super(x, y, game, stayClicked);
this.text = new Text(15, text, Color.white, globalScale);
this.collisionWidth = this.text.getWidth();
this.collisionHeight = this.text.getHeight();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/gui/ExitClickable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ExitClickable extends ClickableText {
private TowerDefense towerDefense;

public ExitClickable(float x, float y, TowerDefense towerDefense) {
super(x, y, "Exit Game", 1f);
super(x, y, "Exit Game", 1f, towerDefense.getGameplay(), false);
this.towerDefense = towerDefense;
}

Expand Down
Loading

0 comments on commit 91a4379

Please sign in to comment.