Added a main menu and fixed som things. added explotions to and fixed the economy

This commit is contained in:
Ziver Koc 2007-04-28 22:09:39 +00:00
parent 5bb373573d
commit 88771fad29
56 changed files with 1859 additions and 1999 deletions

View file

@ -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;
}
}

View file

@ -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);

View 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();
}
}
}

View file

@ -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();