Added a main menu and fixed som things. added explotions to and fixed the economy
This commit is contained in:
parent
5bb373573d
commit
88771fad29
56 changed files with 1859 additions and 1999 deletions
|
|
@ -3,11 +3,11 @@ package ei.game;
|
|||
import ei.engine.LWJGLGameWindow;
|
||||
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 = true;
|
||||
public static final boolean debug = false;
|
||||
|
||||
public static void main(String[] args){
|
||||
new EI();
|
||||
|
|
@ -23,10 +23,11 @@ public class EI extends LWJGLGameWindow{
|
|||
GameStateManager.getInstance().setActive("InGameState");
|
||||
}
|
||||
else{
|
||||
GameStateManager.getInstance().addState(new InGameState("InGameState"));
|
||||
GameStateManager.getInstance().addState(new LoadingState("LoadingState","InGameState"));
|
||||
GameStateManager.getInstance().addState(new SplashState("SplashState","LoadingState"));
|
||||
GameStateManager.getInstance().addState(new SplashState("SplashState","MenuState"));
|
||||
GameStateManager.getInstance().addState(new MenuState("MenuState"));
|
||||
GameStateManager.getInstance().setActive("SplashState");
|
||||
}
|
||||
}
|
||||
|
||||
protected void update() {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import ei.engine.scene.Node;
|
|||
import ei.engine.sound.Sound;
|
||||
import ei.engine.state.GameState;
|
||||
import ei.game.hud.InGameHud;
|
||||
import ei.game.input.InGameKeyboardInput;
|
||||
import ei.game.input.InGameMouseInput;
|
||||
import ei.game.player.HumanPlayer;
|
||||
import ei.game.player.PlayerHandler;
|
||||
|
|
@ -22,12 +23,21 @@ public class InGameState extends GameState{
|
|||
|
||||
public InGameState(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
PlayerHandler.getInstance().clear();
|
||||
WeaponHandler.getInstance().clear();
|
||||
|
||||
rootNode = new Node("InGameNode");
|
||||
|
||||
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);
|
||||
|
|
@ -40,7 +50,6 @@ public class InGameState extends GameState{
|
|||
player.addUnit(new Bomber(7, 0, player));
|
||||
player.addUnit(new APU(4, 0, player));
|
||||
player.addUnit(new APU(5, 0, player));
|
||||
//player.addUnit(new CommandCenter(10, 10, player));
|
||||
|
||||
PlayerHandler.getInstance().addPlayer(player);
|
||||
|
||||
|
|
@ -53,7 +62,7 @@ public class InGameState extends GameState{
|
|||
rootNode.add(hud.getNode());
|
||||
|
||||
music = new Sound("music", "data/sounds/ei.ogg");
|
||||
music.loop();
|
||||
music.loop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,5 +90,4 @@ public class InGameState extends GameState{
|
|||
public static Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package ei.game.gamestate;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
|
|
@ -9,6 +12,7 @@ import ei.engine.sound.SoundLoader;
|
|||
import ei.engine.state.GameState;
|
||||
import ei.engine.state.GameStateManager;
|
||||
import ei.engine.texture.TextureLoader;
|
||||
import ei.engine.util.FileFinderHasher;
|
||||
|
||||
/**
|
||||
* This class handels the loading of the
|
||||
|
|
@ -17,6 +21,13 @@ import ei.engine.texture.TextureLoader;
|
|||
* @author Ziver
|
||||
*/
|
||||
public class LoadingState extends GameState{
|
||||
//The extensions of the files
|
||||
private static final String[] TEXTURES = {
|
||||
"jpg","png","bmp"
|
||||
};
|
||||
private static final String[] SOUNDS = {
|
||||
"wav","ogg"
|
||||
};
|
||||
// The things to load
|
||||
private Queue<String> loadTextures;
|
||||
private Queue<String> loadSounds;
|
||||
|
|
@ -32,6 +43,10 @@ public class LoadingState extends GameState{
|
|||
public LoadingState(String name,String nextState) {
|
||||
super(name);
|
||||
this.nextState = nextState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
loadTextures = new LinkedList<String>();
|
||||
loadSounds = new LinkedList<String>();
|
||||
|
||||
|
|
@ -40,6 +55,33 @@ public class LoadingState extends GameState{
|
|||
progress.setBarTexture(new Sprite("ProgressBar","data/loadbar_front.png"));
|
||||
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
|
||||
progress.setBackgroundTexture(new Sprite("progressBackground","data/loadbar_back.png"));
|
||||
|
||||
try {
|
||||
File dir = new File(getClass().getClassLoader().getResource("data/").toURI());
|
||||
ArrayList<File> files = FileFinderHasher.Search(dir);
|
||||
for(int i=0; i<files.size() ;i++){
|
||||
String ext = files.get(i).getName();
|
||||
ext = ext.substring(ext.lastIndexOf ('.')+1,ext.length());
|
||||
|
||||
if(contains(TEXTURES,ext)){
|
||||
addTexture(files.get(i).getPath().substring(files.get(i).getPath().lastIndexOf("data"), files.get(i).getPath().length()));
|
||||
}
|
||||
else if(contains(SOUNDS,ext)){
|
||||
addSound(files.get(i).getPath().substring(files.get(i).getPath().lastIndexOf("data"), files.get(i).getPath().length()));
|
||||
}
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contains(String[] array, String search){
|
||||
for(int i=0; i<array.length ;i++){
|
||||
if(array[i].equals(search)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,7 +115,7 @@ public class LoadingState extends GameState{
|
|||
progress.setValue(progress.getValue()+1);
|
||||
}
|
||||
else{
|
||||
progress.setValue(progress.getValue()+1);
|
||||
//progress.setValue(progress.getValue()+1);
|
||||
if(progress.getProcent() >= 100){
|
||||
//deactivate this state and activate the next one
|
||||
GameStateManager.getInstance().removeState(this);
|
||||
|
|
|
|||
104
src/ei/game/gamestate/MenuState.java
Normal file
104
src/ei/game/gamestate/MenuState.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package ei.game.gamestate;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.state.GameState;
|
||||
import ei.engine.state.GameStateManager;
|
||||
import ei.engine.ui.Button;
|
||||
import ei.engine.ui.UiComponent;
|
||||
import ei.engine.ui.UiHandler;
|
||||
import ei.engine.ui.UiListener;
|
||||
import ei.game.input.MenuKeyboardInput;
|
||||
import ei.game.input.MenuMouseInput;
|
||||
|
||||
public class MenuState extends GameState implements UiListener{
|
||||
private Node menuNode;
|
||||
|
||||
private Button resume;
|
||||
private Button newGame;
|
||||
private Button quit;
|
||||
|
||||
public MenuState(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
menuNode = new Node("MenuNode");
|
||||
|
||||
int x = LWJGLGameWindow.getWidth()/2;
|
||||
|
||||
Sprite logo = new Sprite("Logo","data/logo.png");
|
||||
logo.setLocation(new Vector2f(x,100));
|
||||
menuNode.add(logo);
|
||||
|
||||
UiHandler ui = new UiHandler("MainMenu");
|
||||
|
||||
Sprite s1 = new Sprite("ResumeButton","data/ui/resume.png");
|
||||
resume = new Button("Resume", s1.getSize());
|
||||
resume.setButtonSprite(s1);
|
||||
resume.setOnTopButtonSprite(new Sprite("ResumeButton_Selected","data/ui/resume_ontop.png"));
|
||||
resume.setDisabledButtonSprite(new Sprite("ResumeButton_Disabled","data/ui/resume_disabled.png"));
|
||||
resume.getNode().setLocation(new Vector2f(x,250));
|
||||
resume.addListener(this);
|
||||
resume.setEnabled(false);
|
||||
ui.addUi(resume);
|
||||
|
||||
Sprite s2 = new Sprite("NewButton","data/ui/new.png");
|
||||
newGame = new Button("New", s2.getSize());
|
||||
newGame.setButtonSprite(s2);
|
||||
newGame.setOnTopButtonSprite(new Sprite("NewButton_Selected","data/ui/new_ontop.png"));
|
||||
newGame.getNode().setLocation(new Vector2f(x,300));
|
||||
newGame.addListener(this);
|
||||
ui.addUi(newGame);
|
||||
|
||||
Sprite s3 = new Sprite("QuitButton","data/ui/quit.png");
|
||||
quit = new Button("Quit", s3.getSize());
|
||||
quit.setButtonSprite(s3);
|
||||
quit.setOnTopButtonSprite(new Sprite("QuitButton_Selected","data/ui/quit_ontop.png"));
|
||||
quit.getNode().setLocation(new Vector2f(x,350));
|
||||
quit.addListener(this);
|
||||
ui.addUi(quit);
|
||||
|
||||
menuNode.add(ui.getNode());
|
||||
|
||||
MenuMouseInput mouse = new MenuMouseInput(ui);
|
||||
super.getInput().addInput(mouse);
|
||||
super.getInput().addInput(new MenuKeyboardInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
menuNode.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
menuNode.update();
|
||||
if(GameStateManager.getInstance().getState("InGameState") != null){
|
||||
resume.setEnabled(true);
|
||||
}
|
||||
else{
|
||||
resume.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ActionEvent(UiComponent source){
|
||||
if(resume == source){
|
||||
GameStateManager.getInstance().setDeActive(this.getName());
|
||||
GameStateManager.getInstance().setActive("InGameState");
|
||||
}
|
||||
else if(newGame == source){
|
||||
GameStateManager.getInstance().removeStateByName("InGameState");
|
||||
GameStateManager.getInstance().addState(new InGameState("InGameState"));
|
||||
GameStateManager.getInstance().addState(new LoadingState("LoadingState","InGameState"));
|
||||
GameStateManager.getInstance().setDeActive(this.getName());
|
||||
GameStateManager.getInstance().setActive("LoadingState");
|
||||
}
|
||||
else if(quit == source){
|
||||
LWJGLGameWindow.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,11 @@ public class SplashState extends GameState{
|
|||
public SplashState(String name,String next) {
|
||||
super(name);
|
||||
nextState = next;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
splash = new Fade("Splash");
|
||||
|
||||
Sprite s = new Sprite("Splash","data/splash.png");
|
||||
|
|
@ -26,7 +31,7 @@ public class SplashState extends GameState{
|
|||
|
||||
time = 200;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
splash.render();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import ei.game.scene.units.Tank;
|
|||
* @author Ziver
|
||||
*
|
||||
*/
|
||||
public class InGameBuildHud {
|
||||
public class InGameBuildHud implements UiListener{
|
||||
private UiHandler ui;
|
||||
private Player player;
|
||||
private BitmapText queueSize;
|
||||
|
|
@ -33,14 +33,13 @@ public class InGameBuildHud {
|
|||
ui = new UiHandler("BuildMenu");
|
||||
|
||||
Vector2f size = new Vector2f(40,40);
|
||||
HudListener listener = new HudListener(this);
|
||||
|
||||
removeLastQueue = new Button("TankButton", size);
|
||||
queueSize = new BitmapText("QueueSize");
|
||||
queueSize.setText("0");
|
||||
removeLastQueue.setButtonSprite(queueSize);
|
||||
removeLastQueue.getNode().setLocation(new Vector2f(x,y));
|
||||
removeLastQueue.addListener(listener);
|
||||
removeLastQueue.addListener(this);
|
||||
ui.addUi(removeLastQueue);
|
||||
|
||||
apuBuildButton = new Button("TankButton", size);
|
||||
|
|
@ -51,7 +50,7 @@ public class InGameBuildHud {
|
|||
s2.setSize(size);
|
||||
apuBuildButton.setOnTopButtonSprite(s2);
|
||||
apuBuildButton.getNode().setLocation(new Vector2f(x+(size.getX()*2),y));
|
||||
apuBuildButton.addListener(listener);
|
||||
apuBuildButton.addListener(this);
|
||||
ui.addUi(apuBuildButton);
|
||||
|
||||
tankBuildButton = new Button("TankButton", size);
|
||||
|
|
@ -62,7 +61,7 @@ public class InGameBuildHud {
|
|||
s4.setSize(size);
|
||||
tankBuildButton.setOnTopButtonSprite(s4);
|
||||
tankBuildButton.getNode().setLocation(new Vector2f(x+(size.getX()*4),y));
|
||||
tankBuildButton.addListener(listener);
|
||||
tankBuildButton.addListener(this);
|
||||
ui.addUi(tankBuildButton);
|
||||
|
||||
bomberBuildButton = new Button("TankButton", size);
|
||||
|
|
@ -73,7 +72,7 @@ public class InGameBuildHud {
|
|||
s6.setSize(size);
|
||||
bomberBuildButton.setOnTopButtonSprite(s6);
|
||||
bomberBuildButton.getNode().setLocation(new Vector2f(x+(size.getX()*6),y));
|
||||
bomberBuildButton.addListener(listener);
|
||||
bomberBuildButton.addListener(this);
|
||||
ui.addUi(bomberBuildButton);
|
||||
}
|
||||
|
||||
|
|
@ -93,31 +92,23 @@ public class InGameBuildHud {
|
|||
return player;
|
||||
}
|
||||
|
||||
class HudListener implements UiListener{
|
||||
private InGameBuildHud hud;
|
||||
|
||||
public HudListener(InGameBuildHud h){
|
||||
hud = h;
|
||||
public void ActionEvent(UiComponent source){
|
||||
// builds a apu
|
||||
if(source == apuBuildButton){
|
||||
player.getCC().buildUnit(new APU(0,0,player));
|
||||
}
|
||||
// builds a tank
|
||||
else if(source == tankBuildButton){
|
||||
player.getCC().buildUnit(new Tank(0,0,player));
|
||||
}
|
||||
// builds a bomber
|
||||
else if(source == bomberBuildButton){
|
||||
player.getCC().buildUnit(new Bomber(0,0,player));
|
||||
}
|
||||
|
||||
public void ActionEvent(UiComponent source){
|
||||
// builds a apu
|
||||
if(source == hud.apuBuildButton){
|
||||
hud.getPlayer().getCC().buildUnit(new APU(0,0,player));
|
||||
}
|
||||
// builds a tank
|
||||
else if(source == hud.tankBuildButton){
|
||||
hud.getPlayer().getCC().buildUnit(new Tank(0,0,player));
|
||||
}
|
||||
// builds a bomber
|
||||
else if(source == hud.bomberBuildButton){
|
||||
hud.getPlayer().getCC().buildUnit(new Bomber(0,0,player));
|
||||
}
|
||||
|
||||
// removes the last unit in the queue
|
||||
else if(source == hud.removeLastQueue){
|
||||
hud.getPlayer().getCC().removeLast();
|
||||
}
|
||||
// removes the last unit in the queue
|
||||
else if(source == removeLastQueue){
|
||||
player.getCC().removeLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ public class InGameHud {
|
|||
money.setText(""+player.getKredits());
|
||||
money.setLocation(new Vector2f(LWJGLGameWindow.getWidth()-money.getBound().width,5));
|
||||
|
||||
player.addKredits(100);
|
||||
buildBar.setValue(player.getCC().getBuildProgress());
|
||||
|
||||
buildHud.update();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,31 @@
|
|||
package ei.game.input;
|
||||
|
||||
public class InGameKeyboardInput {
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.input.KeyboardInput;
|
||||
import ei.engine.state.GameStateManager;
|
||||
|
||||
public class InGameKeyboardInput extends KeyboardInput{
|
||||
|
||||
public InGameKeyboardInput() {
|
||||
super("InGameKeyboardInput");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyDown(int keycode) {
|
||||
if (Keyboard.KEY_ESCAPE == keycode) {
|
||||
if(GameStateManager.getInstance().getState("MenuState") != null){
|
||||
GameStateManager.getInstance().setDeActive("InGameState");
|
||||
GameStateManager.getInstance().setActive("MenuState");
|
||||
}
|
||||
else{
|
||||
LWJGLGameWindow.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyUp(int keycode) {}
|
||||
|
||||
}
|
||||
|
|
|
|||
25
src/ei/game/input/MenuKeyboardInput.java
Normal file
25
src/ei/game/input/MenuKeyboardInput.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package ei.game.input;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.input.KeyboardInput;
|
||||
import ei.engine.state.GameStateManager;
|
||||
|
||||
public class MenuKeyboardInput extends KeyboardInput{
|
||||
|
||||
public MenuKeyboardInput() {
|
||||
super("InGameKeyboardInput");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyDown(int keycode) {
|
||||
if (Keyboard.KEY_ESCAPE == keycode) {
|
||||
LWJGLGameWindow.exit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyUp(int keycode) {}
|
||||
|
||||
}
|
||||
35
src/ei/game/input/MenuMouseInput.java
Normal file
35
src/ei/game/input/MenuMouseInput.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package ei.game.input;
|
||||
|
||||
import ei.engine.input.MouseInput;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.ui.UiHandler;
|
||||
|
||||
public class MenuMouseInput extends MouseInput{
|
||||
private UiHandler ui;
|
||||
|
||||
public MenuMouseInput(UiHandler ui) {
|
||||
super("MenuMouseInput","data/cursor/cursor.png");
|
||||
this.ui = ui;
|
||||
|
||||
//inits the mouse texture
|
||||
Sprite s = getSprite();
|
||||
s.setSize(new Vector2f(38,50));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUpdate(int x, int y, int w) {
|
||||
ui.mousePos(x, y);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(int event,int x, int y) {
|
||||
ui.mouseDown(x, y, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int event,int x, int y) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,14 @@ public abstract class Player {
|
|||
unitsNode.remove(u.getNode());
|
||||
}
|
||||
|
||||
public GameEntity getUnit(int i){
|
||||
return units.get(i);
|
||||
}
|
||||
|
||||
public int unitCount(){
|
||||
return units.size();
|
||||
}
|
||||
|
||||
public Node getNode(){
|
||||
return unitsNode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ public class PlayerHandler {
|
|||
// The player list
|
||||
private ArrayList<Player> players;
|
||||
private Node playerNode;
|
||||
// economy stuff
|
||||
private static final int fundsDelay = 60*30;
|
||||
private static final int funds = 1000;
|
||||
private int fundsTimmer;
|
||||
|
||||
/**
|
||||
* Creates a PlayerHandler
|
||||
|
|
@ -18,6 +22,7 @@ public class PlayerHandler {
|
|||
public PlayerHandler(){
|
||||
players = new ArrayList<Player>();
|
||||
playerNode = new Node("PlayerNode");
|
||||
fundsTimmer = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,6 +64,22 @@ public class PlayerHandler {
|
|||
}
|
||||
|
||||
public void update(){
|
||||
// sends the funds to the players
|
||||
fundsTimmer++;
|
||||
if(fundsTimmer >= fundsDelay){
|
||||
for(int i=0; i<players.size() ;i++){
|
||||
int maintenance = 0;
|
||||
for(int j=0; j<players.get(i).unitCount() ;j++){
|
||||
maintenance += players.get(i).getUnit(j).getMaintenanceCost();
|
||||
}
|
||||
int kredit = funds - maintenance;
|
||||
if(kredit > 0){
|
||||
players.get(i).addKredits(kredit);
|
||||
}
|
||||
}
|
||||
fundsTimmer = 0;
|
||||
}
|
||||
// updates the players
|
||||
for(int i=0; i<players.size() ;i++){
|
||||
players.get(i).update();
|
||||
}
|
||||
|
|
@ -75,4 +96,10 @@ public class PlayerHandler {
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
players.clear();
|
||||
playerNode.clear();
|
||||
fundsTimmer = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,5 +96,7 @@ public abstract class GameEntity{
|
|||
public abstract void attack(Vector2i target, boolean play);
|
||||
|
||||
public abstract Entity getSprite();
|
||||
|
||||
public abstract int getMaintenanceCost();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,9 +127,9 @@ public abstract class Building extends GameEntity{
|
|||
/**
|
||||
* Updating the unit
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
public void update() {
|
||||
if(getLife()<=0) {
|
||||
destroyed();
|
||||
removeBuilding();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@ import ei.engine.math.Vector2i;
|
|||
import ei.engine.scene.Sprite;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.Explotion;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
public class CommandCenter extends Building{
|
||||
private SelectBox selectionBox;
|
||||
private Sprite sprite;
|
||||
|
||||
public CommandCenter(Player p) {
|
||||
this(0, 0, p);
|
||||
}
|
||||
|
|
@ -29,7 +32,7 @@ public class CommandCenter extends Building{
|
|||
* 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.
|
||||
|
|
@ -52,4 +55,9 @@ public class CommandCenter extends Building{
|
|||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,11 @@ public class Stone extends MapEntity{
|
|||
public Entity getSprite() {
|
||||
return stone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ import ei.engine.scene.Sprite;
|
|||
import ei.engine.sound.Sound;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.Explotion;
|
||||
import ei.game.scene.weapons.MachineGun;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
public class APU extends Unit{
|
||||
private SelectBox selectionBox;
|
||||
|
|
@ -59,7 +61,7 @@ public class APU extends Unit{
|
|||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
|
||||
WeaponHandler.getInstance().addWeapon(new Explotion(new Vector2f(getNode().getLocation().getX(), getNode().getLocation().getY())));
|
||||
}
|
||||
public Sound getGunSound() {
|
||||
return gunSound;
|
||||
|
|
@ -95,4 +97,9 @@ public class APU extends Unit{
|
|||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ import ei.engine.texture.AnimatedTexture;
|
|||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.BomberWeapon;
|
||||
import ei.game.scene.weapons.Explotion;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
public class Bomber extends Unit{
|
||||
private SelectBox selectionBox;
|
||||
|
|
@ -68,7 +70,7 @@ public class Bomber extends Unit{
|
|||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
|
||||
WeaponHandler.getInstance().addWeapon(new Explotion(new Vector2f(getNode().getLocation().getX(), getNode().getLocation().getY())));
|
||||
}
|
||||
public Sound getGunSound() {
|
||||
return gunSound;
|
||||
|
|
@ -104,4 +106,9 @@ public class Bomber extends Unit{
|
|||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import ei.engine.sound.Sound;
|
|||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.CannonBall;
|
||||
import ei.game.scene.weapons.Explotion;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
public class Tank extends Unit{
|
||||
private SelectBox selectionBox;
|
||||
|
|
@ -71,7 +73,7 @@ public class Tank extends Unit{
|
|||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
|
||||
WeaponHandler.getInstance().addWeapon(new Explotion(new Vector2f(getNode().getLocation().getX(), getNode().getLocation().getY())));
|
||||
}
|
||||
/**
|
||||
* returns the velocity of the unit type.
|
||||
|
|
@ -95,4 +97,9 @@ public class Tank extends Unit{
|
|||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaintenanceCost() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ public abstract class Unit extends GameEntity{
|
|||
private GameEntity attack;
|
||||
private int buildTime;
|
||||
private int price;
|
||||
private int maintenance;
|
||||
// The wepon reload timer
|
||||
private int weponTimer;
|
||||
// The path to travel
|
||||
|
|
@ -178,6 +177,7 @@ public abstract class Unit extends GameEntity{
|
|||
public void update() {
|
||||
weponTimer++;
|
||||
if(getLife()<=0) {
|
||||
destroyed();
|
||||
removeUnit();
|
||||
}
|
||||
else if(moveTo != null) {
|
||||
|
|
|
|||
43
src/ei/game/scene/weapons/Explotion.java
Normal file
43
src/ei/game/scene/weapons/Explotion.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package ei.game.scene.weapons;
|
||||
|
||||
import ei.engine.effects.Particles;
|
||||
import ei.engine.math.Vector2f;
|
||||
|
||||
public class Explotion extends Weapon{
|
||||
private Particles part;
|
||||
|
||||
public Explotion(Vector2f startPos) {
|
||||
super(startPos);
|
||||
setVelocity(4);
|
||||
setRange(Integer.MIN_VALUE);
|
||||
setDamage(Integer.MIN_VALUE);
|
||||
setReload(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Particles getWeapon() {
|
||||
part = new Particles("bomber");
|
||||
part = new Particles("weapon");
|
||||
part.MaxSpeedX=700;
|
||||
part.MaxSpeedY=700;
|
||||
part.MaxSpeedZ=0;
|
||||
part.slowdown = 1;
|
||||
part.rainbow = false;
|
||||
part.regenerate = false;
|
||||
part.size=10;
|
||||
float colors[][][]= // Rainbow Of Colors
|
||||
{
|
||||
{{1.0f,1.0f,0.0f},{0.74f,0.74f,0.74f}}
|
||||
|
||||
};
|
||||
part.colors = colors;
|
||||
return part;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(part.isDead()) {
|
||||
WeaponHandler.getInstance().removeWeapon(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,9 +11,9 @@ import ei.engine.scene.Node;
|
|||
*
|
||||
*/
|
||||
public class WeaponHandler {
|
||||
private static WeaponHandler instance;
|
||||
private Node weaponNode;
|
||||
private ArrayList<Weapon> weapons;
|
||||
private static WeaponHandler instance;
|
||||
|
||||
/**
|
||||
* Created a weaponhandler.
|
||||
|
|
@ -21,9 +21,9 @@ public class WeaponHandler {
|
|||
*/
|
||||
public WeaponHandler() {
|
||||
weapons = new ArrayList<Weapon>();
|
||||
weaponNode = new Node("weapon");
|
||||
|
||||
weaponNode = new Node("weapon");
|
||||
}
|
||||
|
||||
public boolean addWeapon(Weapon w){
|
||||
if(!weapons.contains(w)){
|
||||
weapons.add(w);
|
||||
|
|
@ -35,6 +35,7 @@ public class WeaponHandler {
|
|||
|
||||
/**
|
||||
* Removes a player from the handler
|
||||
*
|
||||
* @param p The player to remove
|
||||
* @return true if succesful else false
|
||||
*/
|
||||
|
|
@ -46,6 +47,7 @@ public class WeaponHandler {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all the weapons.
|
||||
*
|
||||
|
|
@ -55,8 +57,10 @@ public class WeaponHandler {
|
|||
weapons.get(i).update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the current weaponNode.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Entity getNode() {
|
||||
|
|
@ -75,7 +79,10 @@ public class WeaponHandler {
|
|||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public void clear(){
|
||||
weapons.clear();
|
||||
weaponNode.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue