Skip to content

Commit

Permalink
Added Blocks to the field
Browse files Browse the repository at this point in the history
  • Loading branch information
djschilling committed Feb 22, 2013
1 parent 998b74c commit dc44212
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 40 deletions.
71 changes: 45 additions & 26 deletions src/com/pongo/towerdefense/gl/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Renderer {

private Mesh enemy;
private Mesh tower;
private Mesh block;
private ArrayList<Mesh> blocks;
private Mesh linie;
private GameField field;

Expand All @@ -35,25 +35,47 @@ public Renderer(GL10 gl, TowerDefense activity, GameField field) {
enemy.color(0, 1, 0, 1);
enemy.vertex(25, 50, 0);

block = new Mesh(gl, 4, false, false, false);
block.vertex(0, 20, 0);
block.vertex(20, 20, 0);
block.vertex(20, 0, 0);
block.vertex(0, 0, 0);
blocks = new ArrayList<Mesh>();
for (Block actualBlock : field.blocks) {
blocks.add(new Mesh(gl, 4, true, false, false));
int size = blocks.size();
blocks.get(size - 1).color(0.5f, 0.2f, 0.05f, 1f);
blocks.get(size - 1).vertex(actualBlock.position.x,
actualBlock.position.y + actualBlock.height, 0);
blocks.get(size - 1).color(0.5f, 0.2f, 0.05f, 1f);
blocks.get(size - 1).vertex(
actualBlock.position.x + actualBlock.width,
actualBlock.position.y + actualBlock.height, 0);
blocks.get(size - 1).color(0.5f, 0.2f, 0.05f, 1f);
blocks.get(size - 1).vertex(
actualBlock.position.x + actualBlock.width,
actualBlock.position.y, 0);
blocks.get(size - 1).color(0.5f, 0.2f, 0.05f, 1f);
blocks.get(size - 1).vertex(actualBlock.position.x,
actualBlock.position.y, 0);
}

tower = new Mesh(gl, 1, true, false, false);
tower = new Mesh(gl, 4, true, false, false);
tower.color(1, 0, 0, 1);
tower.vertex(0, 0, 0);

// linie = new Mesh(gl, 2, true, false, false);
// linie.color(255, 140, 0, 1);
// linie.vertex(25, 25, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(700, 700, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(400, 400, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(150, 450, 0);
tower.color(1, 0, 0, 1);
tower.vertex(10, 0, 0);
tower.color(1, 0, 0, 1);
tower.vertex(10, 10, 0);
tower.color(1, 0, 0, 1);
tower.vertex(0, 10, 0);



// linie = new Mesh(gl, 2, true, false, false);
// linie.color(255, 140, 0, 1);
// linie.vertex(25, 25, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(700, 700, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(400, 400, 0);
// linie.color(255, 140, 0, 1);
// linie.vertex(150, 450, 0);

}

Expand All @@ -74,11 +96,11 @@ public void render(GL10 gl, TowerDefense activity, GameField field,
// GLU.gluLookAt(gl, inputManager.screenX, inputManager.screenY, 1,
// inputManager.screenX, inputManager.screenY, 0, 0, 1, 0);

renderBlocks(gl);
renderEnemies(gl, field.getWalkingEnemies());
renderTower(gl, field.getTower());

renderBlocks(gl);
// renderLinie(gl);
// renderLinie(gl);

}

Expand All @@ -89,12 +111,9 @@ private void renderLinie(GL10 gl) {
}

private void renderBlocks(GL10 gl) {
for (Block actualBlock : field.blocks) {
for (Mesh actualBlock : blocks) {
gl.glPushMatrix();
gl.glTranslatef(actualBlock.position.x, actualBlock.position.y,
actualBlock.position.z);

block.render(PrimitiveType.TriangleFan);
actualBlock.render(PrimitiveType.TriangleFan);
gl.glPopMatrix();

}
Expand Down Expand Up @@ -124,12 +143,12 @@ private void renderEnemies(GL10 gl, ArrayList<Enemy> enemies) {

private void renderTower(GL10 gl, Vector<Tower> towerList) {

gl.glPointSize(30);

for (Tower actualTower : towerList) {
gl.glPushMatrix();
gl.glTranslatef(actualTower.position.x, actualTower.position.y,
actualTower.position.z);
tower.render(PrimitiveType.Points);
tower.render(PrimitiveType.TriangleFan);
gl.glPopMatrix();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/pongo/towerdefense/model/Aussichtsturm.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Aussichtsturm extends Tower{

private static final int RANGE = 100;
private static final int RANGE = 300;
private static final int DAMAGE = 40;
private static final int RELOAD_TIME = 1;
public Aussichtsturm(Vector position) {
Expand Down
2 changes: 2 additions & 0 deletions src/com/pongo/towerdefense/model/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class Block {

public Block(Vector position, int width, int height){
this.position = position;
this.width = width;
this.height = height;
}

}
10 changes: 7 additions & 3 deletions src/com/pongo/towerdefense/model/GameField.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class GameField {
public ArrayList<Block> blocks;
public int width;
public int height;
public final int BLOCK_SIZE = 10;

public GameField(ArrayList<Enemy> enemies, ArrayList<Block> blocks,
int width, int height) {
public GameField(ArrayList<Enemy> enemies, int width, int height) {
this.startEnemies = false;
this.waitingEnemies = enemies;
this.walkingEnemies = new ArrayList<Enemy>();
Expand All @@ -32,7 +32,7 @@ public GameField(ArrayList<Enemy> enemies, ArrayList<Block> blocks,
this.deadEnemies = new ArrayList<Enemy>();
this.totalTime = 0;
this.enemyCounter = 0;
this.blocks = blocks;
this.blocks = new ArrayList<Block>();
this.width = width;
this.height = height;
this.towerToBuild = new ArrayList<Tower>();
Expand All @@ -57,6 +57,10 @@ public void startAction(float deltaTime) {
fireTowers(deltaTime);
}

public void addBlocks(int bottom, int top, int left, int right) {
blocks.add(new Block(new com.pongo.towerdefense.model.Vector(left, bottom, 0), right-left, top-bottom));
}

private void fireTowers(float deltaTime) {
for (Tower actualTower : tower) {
Enemy enemy = actualTower.update(walkingEnemies, deltaTime);
Expand Down
2 changes: 1 addition & 1 deletion src/com/pongo/towerdefense/model/Ninja.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;

public class Ninja extends Enemy {
public static final int SPEED = 80;
public static final int SPEED = 200;
public static final int LIFE = 100;
public static final int WIDTH = 50;
public static final int HEIGHT = 25;
Expand Down
67 changes: 58 additions & 9 deletions src/com/pongo/towerdefense/screens/GameLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.pongo.towerdefense.gl.Renderer;
import com.pongo.towerdefense.input.InputManager;
import com.pongo.towerdefense.model.Aussichtsturm;
import com.pongo.towerdefense.model.Block;
import com.pongo.towerdefense.model.Enemy;
import com.pongo.towerdefense.model.GameField;
import com.pongo.towerdefense.model.Ninja;
Expand All @@ -27,6 +26,15 @@ public class GameLoop implements GameScreen {
private InputManager inputManager;

public GameLoop(GL10 gl, TowerDefense activity) {
initalizeField2();

field.startEnemies();
inputManager = new InputManager(0, 0, field.width, field.height,field);
renderer = new Renderer(gl, activity, field);

}

private void initalizeField() {
ArrayList<Vector> route = new ArrayList<Vector>();
route.add(new Vector(0, 200, 0));
route.add(new Vector(100, 200, 0));
Expand All @@ -45,18 +53,59 @@ public GameLoop(GL10 gl, TowerDefense activity) {
for (int i = 0; i < 4; i++) {
enemies.add(new Panzer(route, Richtung.Osten));
}
ArrayList<Block> blocks = new ArrayList<Block>();
for(int i = 0; i < 10; i++){
blocks.add(new Block(new Vector(i*20, 500, 0), 20, 20));
}
field = new GameField(enemies, blocks, 1000, 1000);

field = new GameField(enemies, 2000, 1200);
field.addBlocks(0, 20, 0, 20);
field.addBlocks(30, 100, 30, 100);
field.addTower(new Aussichtsturm(new Vector(50, 400, 0)));
field.addTower(new Tower1(new Vector(1000, 400, 0)));
}
private void initalizeField2() {
ArrayList<Vector> route = new ArrayList<Vector>();
route.add(new Vector(0, 650, 0));
route.add(new Vector(250, 650, 0));
route.add(new Vector(250, 250, 0));
route.add(new Vector(550, 250, 0));
route.add(new Vector(550, 1000, 0));
route.add(new Vector(200, 1000, 0));
route.add(new Vector(200, 1300, 0));
route.add(new Vector(1300, 1300, 0));
route.add(new Vector(1300, 850, 0));
route.add(new Vector(1500, 850, 0));
route.add(new Vector(1500, 550, 0));
route.add(new Vector(1050, 550, 0));
route.add(new Vector(1050, 250, 0));
route.add(new Vector(1750, 250, 0));
route.add(new Vector(1750, 1600, 0));
route.add(new Vector(1250, 1600, 0));
route.add(new Vector(1250, 2000, 0));


field.startEnemies();
inputManager = new InputManager(0, 0, 2040, 1000,field);
renderer = new Renderer(gl, activity, field);
ArrayList<Enemy> enemies = new ArrayList<Enemy>();
for (int i = 0; i < 50; i++) {
enemies.add(new Ninja(route, Richtung.Osten));
}

field = new GameField(enemies, 2000, 2000);
field.addBlocks(0, 600, 0, 200);
field.addBlocks(0, 200, 200, 2000);
field.addBlocks(300, 950, 300, 500);
field.addBlocks(700, 950, 0, 300);
field.addBlocks(950, 1350, 0, 150);
field.addBlocks(1350, 2000, 0, 1200);
field.addBlocks(1050, 1250, 250, 600);
field.addBlocks(200, 1250, 600, 1000);
field.addBlocks(700, 950, 0, 300);
field.addBlocks(600, 1250, 1000, 1250);
field.addBlocks(600, 800, 1250, 1450);
field.addBlocks(300, 500, 1100, 1700);
field.addBlocks(500, 900, 1550, 1700);
field.addBlocks(900, 1350, 1350, 1700);
field.addBlocks(1350, 1550, 1200, 1700);
field.addBlocks(200, 1650, 1800, 2000);
field.addBlocks(1650, 2000, 1300, 2000);
// field.addTower(new Aussichtsturm(new Vector(50, 400, 0)));
// field.addTower(new Tower1(new Vector(1000, 400, 0)));
}

public GameLoop(GL10 gl, TowerDefense activity, GameField field) {
Expand Down

0 comments on commit dc44212

Please sign in to comment.