This is a big commit. Added mouse cursors and a load bar. Started whit the game. and many many other things
This commit is contained in:
parent
448fca2fdf
commit
4e7722fedb
34 changed files with 597 additions and 95 deletions
|
|
@ -3,6 +3,7 @@ package ei.game;
|
|||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.state.GameStateManager;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.gamestate.LoadingState;
|
||||
|
||||
public class EI extends LWJGLGameWindow{
|
||||
public static void main(String[] args){
|
||||
|
|
@ -15,6 +16,7 @@ public class EI extends LWJGLGameWindow{
|
|||
|
||||
protected void init(){
|
||||
GameStateManager.getInstance().addState(new InGameState("InGameState"));
|
||||
GameStateManager.getInstance().setActive("InGameState");
|
||||
GameStateManager.getInstance().addState(new LoadingState("LoadingState","InGameState"));
|
||||
GameStateManager.getInstance().setActive("LoadingState");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,32 @@
|
|||
package ei.game.gamestate;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.effects.Particles;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.sound.Sound;
|
||||
import ei.engine.state.GameState;
|
||||
import ei.game.input.InGameMouseInput;
|
||||
import ei.game.scene.Map;
|
||||
|
||||
|
||||
public class InGameState extends GameState{
|
||||
private Node rootNode;
|
||||
private Sprite sprite1;
|
||||
private Sound sound1;
|
||||
private Particles p;
|
||||
private Map map;
|
||||
|
||||
public InGameState(String name){
|
||||
super(name);
|
||||
rootNode = new Node("InGameNode");
|
||||
InGameMouseInput mouse = new InGameMouseInput();
|
||||
super.getInput().addInput(mouse);
|
||||
|
||||
map = new Map(20,20);
|
||||
rootNode.add(map.getMapNode());
|
||||
|
||||
sprite1 = new Sprite("tank","data/units/tank.png");
|
||||
//sprite1.setScale(new Vector2f(0.5f,0.5f));
|
||||
//sprite1.setLocation(new Vector2f(300,300));
|
||||
rootNode.add(sprite1);
|
||||
|
||||
p = new Particles("particle");
|
||||
p.setLocation(sprite1.getLocation());
|
||||
rootNode.add(p);
|
||||
|
||||
sound1 = new Sound("sound","data/sounds/center.wav");
|
||||
sound1.loop();
|
||||
sound1.setLocation(sprite1.getLocation());
|
||||
rootNode.add(sound1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
rootNode.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
LWJGLGameWindow.getCamera().getLocation().add(new Vector2f(-1.5f,-1.5f));
|
||||
sprite1.getRotation().add(0, 0, 0.5f);
|
||||
rootNode.update();
|
||||
}
|
||||
|
||||
|
|
|
|||
115
src/ei/game/gamestate/LoadingState.java
Normal file
115
src/ei/game/gamestate/LoadingState.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
package ei.game.gamestate;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.sound.SoundLoader;
|
||||
import ei.engine.state.GameState;
|
||||
import ei.engine.state.GameStateManager;
|
||||
import ei.engine.texture.TextureLoader;
|
||||
|
||||
/**
|
||||
* This class handels the loading of the
|
||||
* images and sounds to the memmory.
|
||||
*
|
||||
* @author Ziver
|
||||
*/
|
||||
public class LoadingState extends GameState{
|
||||
// The things to load
|
||||
private Queue<String> loadTextures;
|
||||
private Queue<String> loadSounds;
|
||||
// The name of the next state to activate after loading
|
||||
private String nextState;
|
||||
|
||||
// Temp things for the loadingbar
|
||||
private int status;
|
||||
private Sprite bar;
|
||||
private Sprite loadBar;
|
||||
private Sprite background;
|
||||
|
||||
/**
|
||||
* Creates a loadingstate
|
||||
* @param name The name of the state
|
||||
*/
|
||||
public LoadingState(String name,String nextState) {
|
||||
super(name);
|
||||
this.nextState = nextState;
|
||||
status = 0;
|
||||
loadTextures = new LinkedList<String>();
|
||||
loadSounds = new LinkedList<String>();
|
||||
bar = new Sprite("Bar","data/loadbar_front.png");
|
||||
bar.setLocation(new Vector3f(
|
||||
(LWJGLGameWindow.getWidth()/2),
|
||||
(LWJGLGameWindow.getHeight()/2),0.0f));
|
||||
loadBar = new Sprite("LoadingBar","data/loadbar.png");
|
||||
loadBar.setLocation(new Vector3f(
|
||||
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth(),
|
||||
(LWJGLGameWindow.getHeight()/2)+3,0.0f));
|
||||
background = new Sprite("Bar","data/loadbar_back.png");
|
||||
background.setLocation(new Vector3f(
|
||||
(LWJGLGameWindow.getWidth()/2),
|
||||
(LWJGLGameWindow.getHeight()/2),0.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a texture to be loaded
|
||||
* @param url
|
||||
*/
|
||||
public void addTexture(String url){
|
||||
loadTextures.add(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sound to be loaded
|
||||
* @param url
|
||||
*/
|
||||
public void addSound(String url){
|
||||
loadSounds.add(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the things
|
||||
*/
|
||||
public void update() {
|
||||
if(!loadTextures.isEmpty()){
|
||||
TextureLoader.getTextureLoaderInstance().getTexture(loadTextures.poll());
|
||||
status++;
|
||||
}
|
||||
else if(!loadSounds.isEmpty()){
|
||||
SoundLoader.getInstnace().loadSound(loadSounds.poll());
|
||||
status++;
|
||||
}
|
||||
else{
|
||||
status++;
|
||||
if(status >= 100){
|
||||
//deactivate this state and activate the next one
|
||||
GameStateManager.getInstance().removeState(this);
|
||||
GameStateManager.getInstance().setActive(nextState);
|
||||
}
|
||||
|
||||
}
|
||||
background.update();
|
||||
loadBar.update();
|
||||
bar.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the load bar
|
||||
*/
|
||||
public void render() {
|
||||
// Calculate the procentage
|
||||
float procent = (float)status/100;//(loadTextures.size()+loadSounds.size());
|
||||
System.out.println("lol: "+procent);
|
||||
loadBar.setLocation(new Vector3f(
|
||||
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth()+(loadBar.getWidth()*procent),
|
||||
(LWJGLGameWindow.getHeight()/2)+6,0.0f));
|
||||
//render the bar
|
||||
background.render();
|
||||
loadBar.render();
|
||||
bar.render();
|
||||
}
|
||||
|
||||
}
|
||||
5
src/ei/game/input/InGameKeyboardInput.java
Normal file
5
src/ei/game/input/InGameKeyboardInput.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ei.game.input;
|
||||
|
||||
public class InGameKeyboardInput {
|
||||
|
||||
}
|
||||
54
src/ei/game/input/InGameMouseInput.java
Normal file
54
src/ei/game/input/InGameMouseInput.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package ei.game.input;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.input.MouseInput;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
||||
public class InGameMouseInput extends MouseInput{
|
||||
private static final int CAMERA_MOVE_BORDER = 40;
|
||||
private static final float CAMERA_MOVE_SPEED = 6.0f;
|
||||
|
||||
public InGameMouseInput() {
|
||||
super("InGameMouseInput","data/cursor.png");
|
||||
Sprite s = getSprite();
|
||||
s.getTexture().setTextureWidth(50);
|
||||
s.getTexture().setTextureHeight(50);
|
||||
s.getTexture().setWidth(50);
|
||||
s.getTexture().setHeight(50);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUpdate(int x, int y, int w) {
|
||||
// mov cam to the left
|
||||
if(x < CAMERA_MOVE_BORDER){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(-CAMERA_MOVE_SPEED,0,0);
|
||||
}
|
||||
// mov cam to the right
|
||||
if(x > LWJGLGameWindow.getWidth()-CAMERA_MOVE_BORDER){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(CAMERA_MOVE_SPEED,0,0);
|
||||
}
|
||||
// mov cam upp
|
||||
if(y < CAMERA_MOVE_BORDER){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
// mov cam down
|
||||
if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(0,-CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
//System.out.println(x+"-"+y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(int event,int x, int y) {
|
||||
System.out.println("DOWN("+event+"): "+x+"-"+y);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int event,int x, int y) {
|
||||
System.out.println("UP("+event+"): "+x+"-"+y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
src/ei/game/player/Human.java
Normal file
5
src/ei/game/player/Human.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ei.game.player;
|
||||
|
||||
public class Human {
|
||||
|
||||
}
|
||||
26
src/ei/game/scene/GameEntity.java
Normal file
26
src/ei/game/scene/GameEntity.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package ei.game.scene;
|
||||
|
||||
public abstract class GameEntity{
|
||||
private int life;
|
||||
|
||||
public GameEntity(int l){
|
||||
life = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the life
|
||||
*
|
||||
* @return The life
|
||||
*/
|
||||
public int getLife(){
|
||||
return life;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the life
|
||||
* @param l The life to set to
|
||||
*/
|
||||
public void setLife(int l){
|
||||
life = l;
|
||||
}
|
||||
}
|
||||
92
src/ei/game/scene/Map.java
Normal file
92
src/ei/game/scene/Map.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package ei.game.scene;
|
||||
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
||||
public class Map {
|
||||
private static final int POS_SIZE = 50;
|
||||
private int width;
|
||||
private int hight;
|
||||
private GameEntity[][] map;
|
||||
private Node mapNode;
|
||||
|
||||
public Map(int w, int h){
|
||||
this.width = w;
|
||||
this.hight = h;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
map = new GameEntity[width][hight];
|
||||
|
||||
// init textures
|
||||
mapNode = new Node("MapNode");
|
||||
for(int i=0; i<width ;i++){
|
||||
for(int j=0; j<hight ;j++){
|
||||
Sprite s = new Sprite("MapPos("+i+","+j+")","data/map/sand.jpg");
|
||||
s.setLocation(new Vector3f(i*POS_SIZE,j*POS_SIZE,0));
|
||||
s.getTexture().setTextureWidth(POS_SIZE+1.2f);
|
||||
s.getTexture().setTextureHeight(POS_SIZE+1.2f);
|
||||
s.getTexture().setWidth(POS_SIZE+1);
|
||||
s.getTexture().setHeight(POS_SIZE+1);
|
||||
mapNode.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the pos inthe map is empty
|
||||
*
|
||||
* @param x The x pos
|
||||
* @param y The y pos
|
||||
* @return True if empty else false
|
||||
*/
|
||||
public boolean isPosEmpty(int x, int y){
|
||||
if(map[x][y] != null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object at the pos
|
||||
*
|
||||
* @param x The x pos
|
||||
* @param y The y pos
|
||||
* @return The object in that pos
|
||||
*/
|
||||
public GameEntity getPos(int x, int y){
|
||||
return map[x][y];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an object at the pos
|
||||
*
|
||||
* @param e The object
|
||||
* @param x The x pos
|
||||
* @param y The y pos
|
||||
*/
|
||||
public void setPos(GameEntity e, int x, int y){
|
||||
map[x][y] = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a object from that pos
|
||||
*
|
||||
* @param x The x pos
|
||||
* @param y The y pos
|
||||
*/
|
||||
public void removePos(int x, int y){
|
||||
map[x][y] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map node
|
||||
*
|
||||
* @return The map node
|
||||
*/
|
||||
public Node getMapNode(){
|
||||
return mapNode;
|
||||
}
|
||||
}
|
||||
17
src/ei/game/scene/buildings/Building.java
Normal file
17
src/ei/game/scene/buildings/Building.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package ei.game.scene.buildings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.units.Unit;
|
||||
|
||||
public abstract class Building extends GameEntity{
|
||||
private ArrayList<Unit> availableUnits;
|
||||
private ArrayList<Unit> buildQueue;
|
||||
|
||||
public Building(int l) {
|
||||
super(l);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
12
src/ei/game/scene/units/Unit.java
Normal file
12
src/ei/game/scene/units/Unit.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package ei.game.scene.units;
|
||||
|
||||
import ei.game.scene.GameEntity;
|
||||
|
||||
public abstract class Unit extends GameEntity{
|
||||
|
||||
public Unit(int l) {
|
||||
super(l);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
5
src/ei/game/scene/weapons/Weapon.java
Normal file
5
src/ei/game/scene/weapons/Weapon.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ei.game.scene.weapons;
|
||||
|
||||
public abstract class Weapon {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue