Added a Gaia player and added some random stones
3
raw/ei
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: ei.game.EI
|
||||
|
||||
BIN
raw/media/map/redstone.max
Normal file
BIN
raw/media/map/stone.max
Normal file
BIN
raw/media/map/tree.max
Normal file
BIN
raw/media/sounds/Explosions.mp3
Normal file
BIN
raw/media/sounds/Explosions_2.mp3
Normal file
BIN
raw/media/sounds/Explosions_3.mp3
Normal file
BIN
raw/media/sounds/SmartbombPhoton01b.ogg
Normal file
BIN
raw/media/sounds/SmartbombPlasma01b.ogg
Normal file
BIN
raw/media/sounds/explosion6.wav
Normal file
BIN
raw/media/sounds/gunshot_bang.mp3
Normal file
BIN
raw/media/sounds/lh1-1a.ogg
Normal file
BIN
raw/media/sounds/lh1-1b.ogg
Normal file
BIN
raw/media/sounds/lh1-1c.ogg
Normal file
BIN
raw/media/sounds/mp1-100ms9a.ogg
Normal file
BIN
src/data/map/Grass.png
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
src/data/map/redmud.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
src/data/map/redstone/redstone0000.png
Normal file
|
After Width: | Height: | Size: 321 KiB |
BIN
src/data/map/redstone/redstone0001.png
Normal file
|
After Width: | Height: | Size: 323 KiB |
BIN
src/data/map/redstone/redstone0002.png
Normal file
|
After Width: | Height: | Size: 322 KiB |
BIN
src/data/map/redstone/redstone0003.png
Normal file
|
After Width: | Height: | Size: 318 KiB |
BIN
src/data/map/stone/stone0000.png
Normal file
|
After Width: | Height: | Size: 358 KiB |
BIN
src/data/map/stone/stone0001.png
Normal file
|
After Width: | Height: | Size: 344 KiB |
BIN
src/data/map/stone/stone0002.png
Normal file
|
After Width: | Height: | Size: 361 KiB |
BIN
src/data/map/stone/stone0003.png
Normal file
|
After Width: | Height: | Size: 359 KiB |
BIN
src/data/units/apu/Thumbs.db
Normal file
BIN
src/data/units/bomber/Thumbs.db
Normal file
BIN
src/data/units/tank/Thumbs.db
Normal file
|
|
@ -21,7 +21,7 @@ public class InGameState extends GameState{
|
|||
rootNode = new Node("InGameNode");
|
||||
|
||||
map = new Map(20,20);
|
||||
rootNode.add(map.getMapNode());
|
||||
map.init();
|
||||
InGameMouseInput mouse = new InGameMouseInput(map);
|
||||
super.getInput().addInput(mouse);
|
||||
|
||||
|
|
@ -36,9 +36,10 @@ public class InGameState extends GameState{
|
|||
player.addUnit(new Bomber(3, 0, player));
|
||||
player.addUnit(new APU(4, 0, player));
|
||||
|
||||
rootNode.add(player.getNode());
|
||||
PlayerHandler.getInstance().addPlayer(player);
|
||||
|
||||
rootNode.add(map.getMapNode());
|
||||
rootNode.add(PlayerHandler.getInstance().getNode());
|
||||
rootNode.add(WeaponHandler.getInstance().getNode());
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,10 +112,10 @@ public class InGameMouseInput extends MouseInput{
|
|||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
removeDead();
|
||||
//map.printAllUnits();
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
//selecting unit.
|
||||
if(event==LEFT_MOUSE_BUTTON){
|
||||
//map.printAllUnits();
|
||||
if(leftKlickPos == null){
|
||||
leftKlickPos = new Vector2f(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
|
|
|
|||
37
src/ei/game/player/GaiaPlayer.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package ei.game.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.units.Unit;
|
||||
|
||||
public class GaiaPlayer extends Player{
|
||||
private ArrayList<GameEntity> units;
|
||||
private Node unitsNode;
|
||||
|
||||
public GaiaPlayer(){
|
||||
units = new ArrayList<GameEntity>();
|
||||
unitsNode = new Node("GaiaPlayerNode");
|
||||
}
|
||||
|
||||
public void addUnit(Unit u){
|
||||
units.add(u);
|
||||
unitsNode.add(u.getNode());
|
||||
}
|
||||
|
||||
public void removeUnit(Unit u){
|
||||
units.remove(u);
|
||||
unitsNode.remove(u.getNode());
|
||||
}
|
||||
|
||||
public Node getNode(){
|
||||
return unitsNode;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
for(int i=0; i<units.size() ;i++){
|
||||
units.get(i).update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public class HumanPlayer extends Player{
|
|||
|
||||
public HumanPlayer(){
|
||||
units = new ArrayList<GameEntity>();
|
||||
unitsNode = new Node("UnitsNode");
|
||||
unitsNode = new Node("HumanPlayerNode");
|
||||
}
|
||||
|
||||
public void addUnit(Unit u){
|
||||
|
|
|
|||
|
|
@ -2,11 +2,14 @@ package ei.game.player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ei.engine.scene.Node;
|
||||
|
||||
public class PlayerHandler {
|
||||
// The instance of this class
|
||||
private static PlayerHandler instance;
|
||||
// The player list
|
||||
private ArrayList<Player> players;
|
||||
private Node playerNode;
|
||||
|
||||
/**
|
||||
* Creates a PlayerHandler
|
||||
|
|
@ -14,6 +17,16 @@ public class PlayerHandler {
|
|||
*/
|
||||
public PlayerHandler(){
|
||||
players = new ArrayList<Player>();
|
||||
playerNode = new Node("PlayerNode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a node with all the players units
|
||||
*
|
||||
* @return A node with all the players units
|
||||
*/
|
||||
public Node getNode(){
|
||||
return playerNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -25,6 +38,7 @@ public class PlayerHandler {
|
|||
public boolean addPlayer(Player p){
|
||||
if(!players.contains(p)){
|
||||
players.add(p);
|
||||
playerNode.add(p.getNode());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -38,6 +52,7 @@ public class PlayerHandler {
|
|||
public boolean removePlayer(Player p){
|
||||
if(players.contains(p)){
|
||||
players.remove(p);
|
||||
playerNode.remove(p.getNode());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import ei.engine.math.Vector2i;
|
|||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.GaiaPlayer;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.player.PlayerHandler;
|
||||
import ei.game.scene.map.Stone;
|
||||
|
||||
public class Map {
|
||||
private static final int POS_SIZE = 50;
|
||||
|
|
@ -16,10 +21,10 @@ public class Map {
|
|||
public Map(int w, int h){
|
||||
this.width = w;
|
||||
this.hight = h;
|
||||
init();
|
||||
//init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
public void init(){
|
||||
map = new GameEntity[width][hight];
|
||||
|
||||
// init textures
|
||||
|
|
@ -32,6 +37,12 @@ public class Map {
|
|||
mapNode.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
Player gaia = new GaiaPlayer();
|
||||
PlayerHandler.getInstance().addPlayer(gaia);
|
||||
for(int i=0; i<5 ;i++){
|
||||
gaia.addUnit(new Stone(new Vector2i((int)(Math.random()*width),(int)(Math.random()*hight)),gaia));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
50
src/ei/game/scene/map/MapEntity.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package ei.game.scene.map;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.units.Unit;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
|
||||
public abstract class MapEntity extends Unit{
|
||||
|
||||
public MapEntity(int l, Vector2i pos, Player p) {
|
||||
super(l, pos, p);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(getLife()<=0) {
|
||||
removeUnit();
|
||||
}
|
||||
}
|
||||
|
||||
protected void move(int x, int y, boolean b) {}
|
||||
|
||||
public void setSelected(boolean b) {}
|
||||
|
||||
public void setMouseOver(boolean b) {}
|
||||
|
||||
@Override
|
||||
public float getVelocity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weapon getWeapon(Vector2f startPos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyed() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectBox getSelection() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
35
src/ei/game/scene/map/Stone.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package ei.game.scene.map;
|
||||
|
||||
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;
|
||||
|
||||
public class Stone extends MapEntity{
|
||||
private static final String[] img = {
|
||||
"data/map/stone/stone0000.png",
|
||||
"data/map/stone/stone0001.png",
|
||||
"data/map/stone/stone0002.png",
|
||||
"data/map/stone/stone0003.png",
|
||||
"data/map/redstone/redstone0000.png",
|
||||
"data/map/redstone/redstone0001.png",
|
||||
"data/map/redstone/redstone0002.png",
|
||||
"data/map/redstone/redstone0003.png"
|
||||
};
|
||||
|
||||
private Sprite stone;
|
||||
|
||||
public Stone(Vector2i pos, Player p) {
|
||||
super(10000, pos, p);
|
||||
stone = new Sprite("Stone",img[(int)(Math.random()*img.length)]);
|
||||
stone.setSize(new Vector2f(40,40));
|
||||
getNode().add(stone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getSprite() {
|
||||
return stone;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ public class APU extends Unit{
|
|||
|
||||
public APU(int x, int y, Player p){
|
||||
super(100, new Vector2i(x,y), p);
|
||||
this.sprite = new Sprite("Tank", "data/units/apu/apu0000.png");
|
||||
this.sprite = new Sprite("APU", "data/units/apu/apu0000.png");
|
||||
sprite.setSize(new Vector2f(40,40));
|
||||
getNode().add(sprite);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class Bomber extends Unit{
|
|||
|
||||
public Bomber(int x, int y, Player p){
|
||||
super(200, new Vector2i(x,y), p);
|
||||
this.sprite = new Sprite("Tank", "data/units/bomber/bomber0000.png");
|
||||
this.sprite = new Sprite("Bomber", "data/units/bomber/bomber0000.png");
|
||||
sprite.setSize(new Vector2f(50,60));
|
||||
getNode().add(sprite);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public abstract class Unit extends GameEntity{
|
|||
*/
|
||||
public Unit(int l, Vector2i pos, Player p) {
|
||||
super(l, p);
|
||||
unitNode = new Node("unit");
|
||||
unitNode = new Node("UnitNode");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY()));
|
||||
setPos(pos.getX(), pos.getY());
|
||||
}
|
||||
|
|
@ -87,7 +87,6 @@ public abstract class Unit extends GameEntity{
|
|||
}
|
||||
oldPos = new Vector2i(x, y);
|
||||
InGameState.getMap().setPos(this, x, y);
|
||||
System.out.println(oldPos);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -108,7 +107,7 @@ public abstract class Unit extends GameEntity{
|
|||
* @param y The y pos to move to
|
||||
* @param b True to clear old orders else false
|
||||
*/
|
||||
private void move(int x, int y, boolean b) {
|
||||
protected void move(int x, int y, boolean b) {
|
||||
if(b){
|
||||
attack = null;
|
||||
}
|
||||
|
|
@ -133,15 +132,19 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
public abstract float getVelocity();
|
||||
|
||||
public void removeUnit(){
|
||||
unitNode.remove(getSprite());
|
||||
getPlayer().removeUnit(this);
|
||||
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updating the unit
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
if(getLife()<=0) {
|
||||
unitNode.remove("Tank");
|
||||
getPlayer().removeUnit(this);
|
||||
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
||||
removeUnit();
|
||||
}
|
||||
else if(moveTo != null) {
|
||||
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
||||
|
|
@ -173,25 +176,25 @@ public abstract class Unit extends GameEntity{
|
|||
//Diagonally.
|
||||
if(moveVect.getX() > oldVect.getX() && moveVect.getY() > oldVect.getY()
|
||||
&& moveXminus>=2 && moveYminus>=2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -45));
|
||||
getSprite().setRotation(new Vector3f(0, 0, -45));
|
||||
}
|
||||
|
||||
if(moveVect.getX() < oldVect.getX() && moveVect.getY() < oldVect.getY()
|
||||
&& moveXminus<=-2 && moveYminus<=-2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 135));
|
||||
getSprite().setRotation(new Vector3f(0, 0, 135));
|
||||
}
|
||||
|
||||
if(moveVect.getX() > oldVect.getX() && moveVect.getY() < oldVect.getY()
|
||||
&& moveXminus>=2 && moveYminus<=-2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -135));
|
||||
getSprite().setRotation(new Vector3f(0, 0, -135));
|
||||
}
|
||||
|
||||
if(moveVect.getX() < oldVect.getX() && moveVect.getY() > oldVect.getY()
|
||||
&& moveXminus<=-2 && moveYminus>=2) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 45));
|
||||
getSprite().setRotation(new Vector3f(0, 0, 45));
|
||||
}
|
||||
|
||||
//System.out.println(unitNode.get("Tank").getRotation());
|
||||
//System.out.println(getSprite().getRotation());
|
||||
|
||||
|
||||
//The moving is done here.
|
||||
|
|
|
|||