Added ai player and fixed so player kan create units
This commit is contained in:
parent
e7403858f8
commit
c83605d5c4
22 changed files with 373 additions and 123 deletions
|
|
@ -1,20 +1,40 @@
|
|||
00000000000000000000
|
||||
00000000000000000000
|
||||
00011111111111110000
|
||||
00000000000000100000
|
||||
00000000000001000000
|
||||
00000000000010000000
|
||||
00000000001000000000
|
||||
00000000010000000000
|
||||
00000000100000000000
|
||||
00000001000000000000
|
||||
00000010000000000000
|
||||
00000100000000000000
|
||||
00001000000000000000
|
||||
00010000000000000000
|
||||
00111111111111111000
|
||||
00000000000000000000
|
||||
02222222222222222220
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0001111111111111000000011111111111110000
|
||||
0000000000000010000000000000000000100000
|
||||
0000000000000100000000000000000001000000
|
||||
0000000000001000000000000000000010000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000001000000000000000000010000000000
|
||||
0000000010000000000000000000100000000000
|
||||
0000000100000000000000000001000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000010000000000000000000100000000000000
|
||||
0000100000000000000000001000000000000000
|
||||
0001000000000000000000010000000000000000
|
||||
0011111111111111100000111111111111111000
|
||||
0000000000000000000000000000000000000000
|
||||
0222222222222222222002222222222222222220
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0001111111111111000000011111111111110000
|
||||
0000000000000010000000000000000000100000
|
||||
0000000000000100000000000000000001000000
|
||||
0000000000001000000000000000000010000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000001000000000000000000010000000000
|
||||
0000000010000000000000000000100000000000
|
||||
0000000100000000000000000001000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000010000000000000000000100000000000000
|
||||
0000100000000000000000001000000000000000
|
||||
0001000000000000000000010000000000000000
|
||||
0011111111111111100000111111111111111000
|
||||
0000000000000000000000000000000000000000
|
||||
0222222222222222222002222222222222222220
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
|
|
@ -1,20 +1,40 @@
|
|||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000001111000000000
|
||||
00000000001000000000
|
||||
00000000001000000000
|
||||
00000000001000000000
|
||||
00000000001000000000
|
||||
00000000001000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000010000000000000
|
||||
00000010000000000000
|
||||
00000001100000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
00000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000111100000000000000001111000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000000110000000000000000001100000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000111100000000000000001111000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000100000000000000000001000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000001000000000000000000010000000000000
|
||||
0000000110000000000000000001100000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000
|
||||
|
|
@ -132,6 +132,13 @@ public class LWJGLGameWindow {
|
|||
// Depth Buffer Setup
|
||||
GL11.glClearDepth(1.0f);
|
||||
|
||||
//Enable Blending
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glViewport(0,0,width,height);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
//Select The Projection Matrix
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
|
|
@ -143,14 +150,8 @@ public class LWJGLGameWindow {
|
|||
// Select The Modelview Matrix (controls model orientation)
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
|
||||
//Enable Blending
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
|
||||
Display.setVSyncEnabled(true);
|
||||
//Display.setVSyncEnabled(true);
|
||||
|
||||
|
||||
// The last steps
|
||||
|
|
@ -217,7 +218,7 @@ public class LWJGLGameWindow {
|
|||
private void mainRender() {
|
||||
// clear the screen
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
//GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
|
||||
cam.setWorldTranslationGL();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ public class Node extends Sprite {
|
|||
|
||||
/**
|
||||
* Add a Entity
|
||||
* @param s the Sprite to add
|
||||
* @return false if the Entity alredy exist else true
|
||||
*
|
||||
* @param s The Sprite to add
|
||||
* @return False if the Entity alredy exist else true
|
||||
*/
|
||||
public boolean add(Entity s){
|
||||
if(!entities.contains(s)){
|
||||
|
|
@ -30,8 +31,25 @@ public class Node extends Sprite {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Entity to a specific pos
|
||||
*
|
||||
* @param s The Sprite to add
|
||||
* @param pos the pos to put the entity to
|
||||
* @return False if the Entity alredy exist else true
|
||||
*/
|
||||
public boolean add(Entity s,int pos){
|
||||
if(!entities.contains(s)){
|
||||
MultiPrintStream.out.println("Adding Entity To Node("+getName()+"): "+s.getName());
|
||||
entities.add(pos,s);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a Entity
|
||||
*
|
||||
* @param name the name of Entity to get
|
||||
* @return null if the Entity wasnt found
|
||||
*/
|
||||
|
|
@ -62,7 +80,8 @@ public class Node extends Sprite {
|
|||
}
|
||||
|
||||
/**
|
||||
* remove a Entity
|
||||
* Remove a Entity
|
||||
*
|
||||
* @param name the name of Entity to remove
|
||||
* @return false if the Entity alredy exist else true
|
||||
*/
|
||||
|
|
@ -121,6 +140,7 @@ public class Node extends Sprite {
|
|||
|
||||
/**
|
||||
* Searches for the given name of a Entity
|
||||
*
|
||||
* @param name The name of the Entity
|
||||
* @return The index of the Entity
|
||||
*/
|
||||
|
|
@ -140,4 +160,16 @@ public class Node extends Sprite {
|
|||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return entities.size();
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String msg = "Node[";
|
||||
for(int i=0; i<entities.size() ;i++){
|
||||
msg += entities.get(i).getName()+",";
|
||||
}
|
||||
return msg+"]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class MultiPrintStream extends PrintStream {
|
|||
* prints whit a new line to all the PrintStreams
|
||||
*/
|
||||
public void println(String s){
|
||||
s = getTime() + s;
|
||||
if(!s.equals(""))s = getTime() + s;
|
||||
for(int i=0; i<streams.length ;i++)
|
||||
streams[i].println(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import ei.engine.LWJGLGameWindow;
|
|||
import ei.engine.LWJGLPropertiesDialog;
|
||||
import ei.engine.state.GameStateManager;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.gamestate.LoadingState;
|
||||
import ei.game.gamestate.MenuState;
|
||||
import ei.game.gamestate.SplashState;
|
||||
|
||||
public class EI extends LWJGLGameWindow{
|
||||
public static final boolean debug = false;
|
||||
public static final boolean debug = true;
|
||||
|
||||
public static void main(String[] args){
|
||||
new EI();
|
||||
|
|
@ -21,7 +22,8 @@ public class EI extends LWJGLGameWindow{
|
|||
protected void init(){
|
||||
if(debug){
|
||||
GameStateManager.getInstance().addState(new InGameState("InGameState"));
|
||||
GameStateManager.getInstance().setActive("InGameState");
|
||||
GameStateManager.getInstance().addState(new LoadingState("LoadingState","InGameState"));
|
||||
GameStateManager.getInstance().setActive("LoadingState");
|
||||
}
|
||||
else{
|
||||
GameStateManager.getInstance().addState(new SplashState("SplashState","MenuState"));
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class AStar{
|
|||
|
||||
private int width;
|
||||
private int hight;
|
||||
private AStarNode[][] map;
|
||||
private static AStarNode[][] map;
|
||||
|
||||
protected boolean randomizeMap = true;
|
||||
protected Random RAND = new Random(0);
|
||||
|
|
@ -23,8 +23,13 @@ public class AStar{
|
|||
width = InGameState.getMap().getSize().getX();
|
||||
hight = InGameState.getMap().getSize().getY();
|
||||
initializePathfinder();
|
||||
if(map != null){
|
||||
reset();
|
||||
}
|
||||
else{
|
||||
initializeMap();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AStarNode> startSearch(Vector2i start, Vector2i goal){
|
||||
//map[goal.getX()][goal.getY()].setBlocked(false);
|
||||
|
|
@ -38,13 +43,29 @@ public class AStar{
|
|||
pathfinder = new AStarPathfinder();
|
||||
}
|
||||
|
||||
protected void reset(){
|
||||
for(int y = 0, nodeId = 0; hight > y; y++) {
|
||||
MultiPrintStream.out.println("");
|
||||
for(int x = 0; width > x; x++, nodeId++) {
|
||||
if(!InGameState.getMap().isPosEmpty(x, y)) {
|
||||
map[x][y].setBlocked(true);
|
||||
MultiPrintStream.out.print(1);
|
||||
}
|
||||
else{
|
||||
MultiPrintStream.out.print(""+0);
|
||||
map[x][y].setBlocked(false);
|
||||
}
|
||||
map[x][y].setVisited(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeMap() {
|
||||
System.out.println("Initializing map");
|
||||
// Create the map.
|
||||
map = new AStarNode2D[width][hight];
|
||||
for(int y = 0, nodeId = 0; hight > y; y++) {
|
||||
MultiPrintStream.out.println();
|
||||
MultiPrintStream.out.println("");
|
||||
for(int x = 0; width > x; x++, nodeId++) {
|
||||
map[x][y] = new AStarNode2D(x, y, nodeId);
|
||||
|
||||
|
|
@ -52,10 +73,10 @@ public class AStar{
|
|||
map[x][y].setBlocked(true);
|
||||
MultiPrintStream.out.print(1);
|
||||
}
|
||||
else MultiPrintStream.out.print(0);
|
||||
else MultiPrintStream.out.print(""+0);
|
||||
}
|
||||
}
|
||||
MultiPrintStream.out.println();
|
||||
MultiPrintStream.out.println("");
|
||||
/*
|
||||
for(int x = 0, nodeId = 0; width > x; x++) {
|
||||
for(int y = 0; hight > y; y++, nodeId++) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import ei.engine.state.GameState;
|
|||
import ei.game.hud.InGameHud;
|
||||
import ei.game.input.InGameKeyboardInput;
|
||||
import ei.game.input.InGameMouseInput;
|
||||
import ei.game.player.AiPlayer;
|
||||
import ei.game.player.HumanPlayer;
|
||||
import ei.game.player.PlayerHandler;
|
||||
import ei.game.scene.Map;
|
||||
|
|
@ -36,25 +37,33 @@ public class InGameState extends GameState{
|
|||
|
||||
map = new Map(20,20);
|
||||
map.init("data/map/default");
|
||||
InGameMouseInput mouse = new InGameMouseInput(map);
|
||||
super.getInput().addInput(mouse);
|
||||
InGameKeyboardInput keyboard = new InGameKeyboardInput();
|
||||
super.getInput().addInput(keyboard);
|
||||
|
||||
HumanPlayer player = new HumanPlayer();
|
||||
Tank t1 = new Tank(player);
|
||||
player.addUnit(t1);
|
||||
Tank t2 = new Tank(1,0, player);
|
||||
player.addUnit(t2);
|
||||
InGameMouseInput mouse = new InGameMouseInput(map,player);
|
||||
InGameKeyboardInput keyboard = new InGameKeyboardInput();
|
||||
super.getInput().addInput(mouse);
|
||||
super.getInput().addInput(keyboard);
|
||||
|
||||
player.addUnit(new Tank(0, 0, player));
|
||||
player.addUnit(new Tank(1,0, player));
|
||||
player.addUnit(new Tank(2,0, player));
|
||||
player.addUnit(new Bomber(3, 0, player));
|
||||
player.addUnit(new Bomber(6, 0, player));
|
||||
player.addUnit(new Bomber(7, 0, player));
|
||||
player.addUnit(new APU(4, 0, player));
|
||||
player.addUnit(new APU(5, 0, player));
|
||||
|
||||
PlayerHandler.getInstance().addPlayer(player);
|
||||
|
||||
AiPlayer ai = new AiPlayer();
|
||||
ai.addUnit(new Tank(1,39, ai));
|
||||
ai.addUnit(new Tank(2,39, ai));
|
||||
ai.addUnit(new Bomber(3, 39, ai));
|
||||
ai.addUnit(new Bomber(6, 39, ai));
|
||||
ai.addUnit(new Bomber(7, 39, ai));
|
||||
ai.addUnit(new APU(4, 39, ai));
|
||||
ai.addUnit(new APU(5, 39, ai));
|
||||
PlayerHandler.getInstance().addPlayer(ai);
|
||||
|
||||
rootNode.add(map.getMapNode());
|
||||
rootNode.add(PlayerHandler.getInstance().getNode());
|
||||
rootNode.add(WeaponHandler.getInstance().getNode());
|
||||
|
|
|
|||
|
|
@ -95,15 +95,15 @@ public class InGameBuildHud implements UiListener{
|
|||
public void ActionEvent(UiComponent source){
|
||||
// builds a apu
|
||||
if(source == apuBuildButton){
|
||||
player.getCC().buildUnit(new APU(0,0,player));
|
||||
player.getCC().buildUnit(new APU(player));
|
||||
}
|
||||
// builds a tank
|
||||
else if(source == tankBuildButton){
|
||||
player.getCC().buildUnit(new Tank(0,0,player));
|
||||
player.getCC().buildUnit(new Tank(player));
|
||||
}
|
||||
// builds a bomber
|
||||
else if(source == bomberBuildButton){
|
||||
player.getCC().buildUnit(new Bomber(0,0,player));
|
||||
player.getCC().buildUnit(new Bomber(player));
|
||||
}
|
||||
|
||||
// removes the last unit in the queue
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import ei.engine.scene.Box;
|
|||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.game.hud.InGameHud;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
|
||||
|
|
@ -25,10 +26,12 @@ public class InGameMouseInput extends MouseInput{
|
|||
|
||||
private InGameHud hud;
|
||||
private Map map;
|
||||
private Player player;
|
||||
|
||||
public InGameMouseInput(Map map) {
|
||||
public InGameMouseInput(Map map, Player p) {
|
||||
super("InGameMouseInput","data/cursor/cursor.png");
|
||||
this.map = map;
|
||||
this.player = p;
|
||||
this.selected = new ArrayList<GameEntity>();
|
||||
|
||||
//inits the mouse texture
|
||||
|
|
@ -205,12 +208,15 @@ public class InGameMouseInput extends MouseInput{
|
|||
public void selectUnits(Vector2i startPos, Vector2i stopPos){
|
||||
for(int i=Math.min(startPos.getX(), stopPos.getX()); i<=Math.max(startPos.getX(), stopPos.getX()) ;i++){
|
||||
for(int j=Math.min(startPos.getY(), stopPos.getY()); j<=Math.max(startPos.getY(), stopPos.getY()) ;j++){
|
||||
if(!map.isPosEmpty(i, j)){
|
||||
if(!map.isPosEmpty(i, j) && map.getPos(i, j).getPlayer() == player){
|
||||
selected.add(map.getPos(i, j));
|
||||
map.getPos(i, j).setSelected(true);
|
||||
map.getPos(i, j).setSelected(true,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!selected.isEmpty()){
|
||||
selected.get((int)(Math.random()*selected.size())).setSelected(true,true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -219,7 +225,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
*/
|
||||
public void deselectAllUnits(){
|
||||
for(int i=0; i<selected.size(); i++) {
|
||||
selected.get(i).setSelected(false);
|
||||
selected.get(i).setSelected(false,false);
|
||||
}
|
||||
selected.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import org.lwjgl.input.Keyboard;
|
|||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.input.KeyboardInput;
|
||||
import ei.engine.state.GameStateManager;
|
||||
|
||||
public class MenuKeyboardInput extends KeyboardInput{
|
||||
|
||||
|
|
|
|||
20
src/ei/game/player/AiPlayer.java
Normal file
20
src/ei/game/player/AiPlayer.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package ei.game.player;
|
||||
|
||||
import ei.game.scene.buildings.Building;
|
||||
import ei.game.scene.buildings.CommandCenter;
|
||||
|
||||
public class AiPlayer extends Player{
|
||||
private CommandCenter cc;
|
||||
|
||||
public AiPlayer(){
|
||||
super();
|
||||
cc = new CommandCenter(30,30,this);
|
||||
addUnit(cc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Building getCC() {
|
||||
return cc;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ public abstract class GameEntity{
|
|||
* Sets a unit to be selected or not.
|
||||
* @param b true or false.
|
||||
*/
|
||||
public abstract void setSelected(boolean b);
|
||||
public abstract void setSelected(boolean b, boolean playSound);
|
||||
|
||||
/**
|
||||
* Set if the mouse is over the unit or not
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import java.util.LinkedList;
|
|||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Box;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.util.MultiPrintStream;
|
||||
|
|
@ -112,8 +114,8 @@ public class Map {
|
|||
}
|
||||
}
|
||||
|
||||
private Sprite getPosSprite(int x, int y, String file){
|
||||
Sprite s = new Sprite("MapPos("+x+","+y+")", file);
|
||||
private Entity getPosSprite(int x, int y, String file){
|
||||
Box s = new Box("MapPos("+x+","+y+")", file);
|
||||
s.setLocation(new Vector3f(x*POS_SIZE,y*POS_SIZE,0));
|
||||
s.setSize(new Vector2f(POS_SIZE,POS_SIZE));
|
||||
return s;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import ei.engine.scene.Node;
|
|||
import ei.engine.texture.Texture;
|
||||
|
||||
public class SelectBox {
|
||||
public static final int COLOR_GREEN = 0;
|
||||
public static final int COLOR_RED = 1;
|
||||
private static final float height = 3;
|
||||
private Node selectNode;
|
||||
private Node mouseOverNode;
|
||||
|
|
@ -20,12 +22,17 @@ public class SelectBox {
|
|||
* @param y The size of the selection box
|
||||
* @param max The max health of the object
|
||||
*/
|
||||
public SelectBox(float x, float y, int max){
|
||||
public SelectBox(int color, float x, float y, int max){
|
||||
selectNode = new Node("SelectionNode");
|
||||
mouseOverNode = new Node("MouseOverNode");
|
||||
|
||||
Texture tex = new Texture();
|
||||
if(color == COLOR_RED){
|
||||
tex.setColor(new Vector4f(1.0f, 0.5f, 0.5f,1));
|
||||
}
|
||||
else{
|
||||
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
|
||||
}
|
||||
|
||||
bar = new ProgressBar("Health",x,height,max);
|
||||
bar.getNode().setLocation(new Vector2f(0,-x/2+height/2));
|
||||
|
|
@ -38,7 +45,6 @@ public class SelectBox {
|
|||
Box select = new Box("select",tex);
|
||||
select.setSize(new Vector2f(x,y));
|
||||
selectNode.add(select);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package ei.game.scene.buildings;
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.Player;
|
||||
|
|
@ -20,6 +22,8 @@ public abstract class Building extends GameEntity{
|
|||
private int buildTime;
|
||||
private Node unitNode;
|
||||
private Vector2i oldPos;
|
||||
private Vector2f moveFrom;
|
||||
private Vector2f moveTo;
|
||||
private int size;
|
||||
|
||||
|
||||
|
|
@ -30,9 +34,11 @@ public abstract class Building extends GameEntity{
|
|||
unitNode = new Node("UnitNode");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size));
|
||||
setPos(pos.getX(), pos.getY(), this.size);
|
||||
moveFrom = Map.getPixelByPos(oldPos.getX()+size-2, oldPos.getX()+size-1);
|
||||
moveTo = Map.getPixelByPos( oldPos.getX()+size-2, oldPos.getX()+size);
|
||||
}
|
||||
|
||||
public void setSelected(boolean b) {
|
||||
public void setSelected(boolean b, boolean playSound) {
|
||||
if(b) {
|
||||
unitNode.add(getSelection().getSelectNode());
|
||||
}
|
||||
|
|
@ -110,8 +116,14 @@ public abstract class Building extends GameEntity{
|
|||
*
|
||||
*/
|
||||
public int getBuildProgress(){
|
||||
// TODO return the procentage of completion of the unit
|
||||
return 50;
|
||||
if(buildQueue.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
int progress = (int)(((float)buildTime/buildQueue.peekFirst().getBuildTime())*100);
|
||||
if(progress > 100){
|
||||
progress = 100;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,6 +144,46 @@ public abstract class Building extends GameEntity{
|
|||
destroyed();
|
||||
removeBuilding();
|
||||
}
|
||||
|
||||
if(!buildQueue.isEmpty() && getPlayer().getKredits() >= buildQueue.peekFirst().getPrice()){
|
||||
if(buildTime == 0){
|
||||
getPlayer().addKredits(-buildQueue.peekFirst().getPrice());
|
||||
}
|
||||
buildTime++;
|
||||
if(buildTime >= buildQueue.peekFirst().getBuildTime()){
|
||||
if(!unitNode.contains(buildQueue.peekFirst().getNode())){
|
||||
System.out.println(buildQueue.peekFirst().getNode());
|
||||
unitNode.add(buildQueue.peekFirst().getNode(),unitNode.size()/2);
|
||||
buildQueue.peekFirst().getNode().setLocation(moveFrom);
|
||||
}
|
||||
Vector2i temp = Map.getPosByPixel(moveTo.getX(), moveTo.getY());
|
||||
if(InGameState.getMap().isPosEmpty(temp.getX(),temp.getY())){
|
||||
//The moving is done here.
|
||||
if(moveTo.getX() > buildQueue.peekFirst().getNode().getLocation().getX()) {
|
||||
buildQueue.peekFirst().getNode().getLocation().add(buildQueue.peekFirst().getVelocity(), 0f, 0f);
|
||||
}
|
||||
if(moveTo.getX() < buildQueue.peekFirst().getNode().getLocation().getX()) {
|
||||
buildQueue.peekFirst().getNode().getLocation().add(-buildQueue.peekFirst().getVelocity(), 0f, 0f);
|
||||
}
|
||||
if(moveTo.getY() > buildQueue.peekFirst().getNode().getLocation().getY()) {
|
||||
buildQueue.peekFirst().getNode().getLocation().add(0f, buildQueue.peekFirst().getVelocity(), 0f);
|
||||
}
|
||||
if(moveTo.getY() < buildQueue.peekFirst().getNode().getLocation().getY()) {
|
||||
buildQueue.peekFirst().getNode().getLocation().add(0f, -buildQueue.peekFirst().getVelocity(), 0f);
|
||||
}
|
||||
System.out.println(buildQueue.peekFirst().getNode().getLocation());
|
||||
if(Math.abs(moveTo.getX() - buildQueue.peekFirst().getNode().getLocation().getX()) < buildQueue.peekFirst().getVelocity()+1
|
||||
&& Math.abs(moveTo.getY() - buildQueue.peekFirst().getNode().getLocation().getY())< buildQueue.peekFirst().getVelocity()+1 ){
|
||||
buildTime = 0;
|
||||
unitNode.remove(buildQueue.peekFirst().getNode());
|
||||
buildQueue.peekFirst().forcePos(temp.getX(),temp.getY());
|
||||
getPlayer().addUnit(buildQueue.poll());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Entity getGroundSprite();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ei.game.scene.buildings;
|
|||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
|
|
@ -15,7 +16,8 @@ import ei.game.scene.weapons.WeaponHandler;
|
|||
*/
|
||||
public class CommandCenter extends Building{
|
||||
private SelectBox selectionBox;
|
||||
private Sprite sprite;
|
||||
private Sprite building;
|
||||
private Sprite ground;
|
||||
|
||||
public CommandCenter(Player p) {
|
||||
this(0, 0, p);
|
||||
|
|
@ -23,46 +25,60 @@ public class CommandCenter extends Building{
|
|||
|
||||
public CommandCenter(int x, int y, Player p){
|
||||
super(1000, new Vector2i(x,y), p, 4);
|
||||
this.sprite = new Sprite("APU", "data/buildings/cc/cc.png");
|
||||
sprite.setSize(new Vector2f(200,200));
|
||||
getNode().add(sprite);
|
||||
ground = new Sprite("CC_Ground", "data/buildings/cc/cc_ground.png");
|
||||
ground.setSize(new Vector2f(200,200));
|
||||
getNode().add(ground);
|
||||
building = new Sprite("CC", "data/buildings/cc/cc_building.png");
|
||||
building.setSize(new Vector2f(200,200));
|
||||
getNode().add(building);
|
||||
|
||||
selectionBox = new SelectBox(200,200,getMaxLife());
|
||||
selectionBox = new SelectBox(0,200,200,getMaxLife());
|
||||
}
|
||||
|
||||
protected SelectBox getSelection() {
|
||||
return selectionBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
WeaponHandler.getInstance().addWeapon(new Explotion(new Vector2f(getNode().getLocation().getX(), getNode().getLocation().getY())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesnt matter anyway. Since buildings cant attack.
|
||||
*/
|
||||
public void attack(Vector2i target, boolean play) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the sprite connected to this unit.
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
public void setSprite(Sprite s) {
|
||||
this.sprite = s;
|
||||
building = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the sprite connected to this type
|
||||
* of unit.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
public Entity getSprite() {
|
||||
return building;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getGroundSprite() {
|
||||
return ground;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ public class Stone extends MapEntity{
|
|||
|
||||
public Stone(Vector2i pos, Player p) {
|
||||
super(10000, pos, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
stone = new Sprite("Stone",img[(int)(Math.random()*img.length)]);
|
||||
stone.setSize(new Vector2f(40,40));
|
||||
getNode().add(stone);
|
||||
|
|
@ -37,5 +41,4 @@ public class Stone extends MapEntity{
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,23 +21,27 @@ public class APU extends Unit{
|
|||
private Sprite sprite;
|
||||
|
||||
private Sound gunSound;
|
||||
private Sound moveSound[] = new Sound[2];
|
||||
private Sound[] moveSound;
|
||||
private Sound attackSound;
|
||||
private Sound selectSound;
|
||||
|
||||
public APU(Player p) {
|
||||
this(0, 0, p);
|
||||
super(70, p);
|
||||
}
|
||||
|
||||
public APU(int x, int y, Player p){
|
||||
super(70, new Vector2i(x,y), p);
|
||||
this.sprite = new Sprite("APU", "data/units/apu/apu0000.png");
|
||||
}
|
||||
|
||||
public void init(){
|
||||
sprite = new Sprite("APU", "data/units/apu/apu0000.png");
|
||||
sprite.setSize(new Vector2f(40,40));
|
||||
getNode().add(sprite);
|
||||
setBuildTime(20);
|
||||
setBuildTime(200);
|
||||
setPrice(200);
|
||||
|
||||
gunSound = new Sound("gunSound", "data/sounds/machinegun.wav");
|
||||
moveSound = new Sound[2];
|
||||
moveSound[0] = new Sound("moveSound", "data/sounds/APUmove1.wav");
|
||||
moveSound[1] = new Sound("moveSound", "data/sounds/APUmove2.wav");
|
||||
selectSound = new Sound("selectSound", "data/sounds/APUselect.wav");
|
||||
|
|
@ -49,7 +53,7 @@ public class APU extends Unit{
|
|||
selectSound.setLocation(getNode().getLocation());
|
||||
attackSound.setLocation(getNode().getLocation());
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
selectionBox = new SelectBox(0,40,40,getMaxLife());
|
||||
}
|
||||
|
||||
protected SelectBox getSelection() {
|
||||
|
|
|
|||
|
|
@ -22,16 +22,19 @@ public class Bomber extends Unit{
|
|||
private Sprite sprite;
|
||||
|
||||
private Sound gunSound;
|
||||
private Sound[] moveSound = new Sound[2];
|
||||
private Sound[] moveSound;
|
||||
private Sound attackSound;
|
||||
private Sound selectSound;
|
||||
|
||||
public Bomber(Player p) {
|
||||
this(0, 0, p);
|
||||
super(200, p);
|
||||
}
|
||||
|
||||
public Bomber(int x, int y, Player p){
|
||||
super(200, new Vector2i(x,y), p);
|
||||
}
|
||||
|
||||
public void init(){
|
||||
AnimatedTexture tex = new AnimatedTexture("BomberTexture");
|
||||
tex.addAnimation("normal", new String[]{
|
||||
"data/units/bomber/bomber0000.png",
|
||||
|
|
@ -43,10 +46,11 @@ public class Bomber extends Unit{
|
|||
sprite = new Sprite("Bomber",tex);
|
||||
sprite.setSize(new Vector2f(50,60));
|
||||
getNode().add(sprite);
|
||||
setBuildTime(40);
|
||||
setBuildTime(400);
|
||||
setPrice(800);
|
||||
|
||||
gunSound = new Sound("gunSound", "data/sounds/bomberweapon.wav");
|
||||
moveSound = new Sound[2];
|
||||
moveSound[0] = new Sound("moveSound", "data/sounds/BOMBERmove1.wav");
|
||||
moveSound[1] = new Sound("moveSound", "data/sounds/BOMBERmove2.wav");
|
||||
selectSound = new Sound("selectSound", "data/sounds/BOMBERselect.wav");
|
||||
|
|
@ -58,7 +62,7 @@ public class Bomber extends Unit{
|
|||
selectSound.setLocation(getNode().getLocation());
|
||||
attackSound.setLocation(getNode().getLocation());
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
selectionBox = new SelectBox(0,40,40,getMaxLife());
|
||||
}
|
||||
|
||||
protected SelectBox getSelection() {
|
||||
|
|
|
|||
|
|
@ -21,23 +21,27 @@ public class Tank extends Unit{
|
|||
private Sprite sprite;
|
||||
|
||||
private Sound gunSound;
|
||||
private Sound[] moveSound = new Sound[2];
|
||||
private Sound[] moveSound;
|
||||
private Sound attackSound;
|
||||
private Sound selectSound;
|
||||
|
||||
public Tank(Player p) {
|
||||
this(0, 0, p);
|
||||
super(100, p);
|
||||
}
|
||||
|
||||
public Tank(int x, int y, Player p){
|
||||
super(100, new Vector2i(x,y), p);
|
||||
this.sprite = new Sprite("Tank", "data/units/tank/tank0000.png");
|
||||
}
|
||||
|
||||
public void init(){
|
||||
sprite = new Sprite("Tank", "data/units/tank/tank0000.png");
|
||||
sprite.setSize(new Vector2f(40,40));
|
||||
getNode().add(sprite);
|
||||
setBuildTime(30);
|
||||
setBuildTime(300);
|
||||
setPrice(400);
|
||||
|
||||
gunSound = new Sound("gunSound", "data/sounds/tankweapon.wav");
|
||||
moveSound = new Sound[2];
|
||||
moveSound[0] = new Sound("moveSound", "data/sounds/TANKmove1.wav");
|
||||
moveSound[1] = new Sound("moveSound", "data/sounds/TANKmove2.wav");
|
||||
selectSound = new Sound("selectSound", "data/sounds/TANKselect.wav");
|
||||
|
|
@ -49,7 +53,7 @@ public class Tank extends Unit{
|
|||
selectSound.setLocation(getNode().getLocation());
|
||||
attackSound.setLocation(getNode().getLocation());
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
selectionBox = new SelectBox(0,40,40,getMaxLife());
|
||||
}
|
||||
|
||||
protected SelectBox getSelection() {
|
||||
|
|
|
|||
|
|
@ -49,11 +49,23 @@ public abstract class Unit extends GameEntity{
|
|||
unitNode = new Node("UnitNode");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY()));
|
||||
setPos(pos.getX(), pos.getY());
|
||||
init();
|
||||
}
|
||||
|
||||
public void setSelected(boolean b) {
|
||||
/**
|
||||
* Creates a empty unit
|
||||
*
|
||||
* @param l The max life of the unit
|
||||
*/
|
||||
public Unit(int l, Player p) {
|
||||
super(l, p);
|
||||
unitNode = new Node("UnitNode");
|
||||
init();
|
||||
}
|
||||
|
||||
public void setSelected(boolean b,boolean playSound) {
|
||||
if(b) {
|
||||
getSelectSound().play();
|
||||
if(playSound)getSelectSound().play();
|
||||
unitNode.add(getSelection().getSelectNode());
|
||||
}
|
||||
else{
|
||||
|
|
@ -93,6 +105,14 @@ public abstract class Unit extends GameEntity{
|
|||
InGameState.getMap().setPos(this, x, y);
|
||||
}
|
||||
|
||||
public void forcePos(int x, int y){
|
||||
if(oldPos!=null) {
|
||||
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
||||
}
|
||||
oldPos = new Vector2i(x, y);
|
||||
InGameState.getMap().setPos(this, x, y);
|
||||
unitNode.setLocation(Map.getPixelByPos(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moving a unit to the given pos
|
||||
|
|
@ -164,6 +184,8 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
public abstract Sound getMoveSound();
|
||||
|
||||
public abstract void init();
|
||||
|
||||
|
||||
public void removeUnit(){
|
||||
unitNode.remove(getSprite());
|
||||
|
|
@ -206,7 +228,6 @@ public abstract class Unit extends GameEntity{
|
|||
getSprite().setRotation(new Vector3f(0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
//Diagonally.
|
||||
if(moveVect.getX() > oldVect.getX() && moveVect.getY() > oldVect.getY()
|
||||
&& moveXminus>=2 && moveYminus>=2) {
|
||||
|
|
@ -298,4 +319,12 @@ public abstract class Unit extends GameEntity{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getBuildTime(){
|
||||
return buildTime;
|
||||
}
|
||||
|
||||
public int getPrice(){
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue