Added a Gaia player and added some random stones

This commit is contained in:
Ziver Koc 2007-04-21 21:18:27 +00:00
parent 397fb7ebd0
commit 65747bd267
40 changed files with 1316 additions and 45 deletions

BIN
src/data/map/Grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

BIN
src/data/map/redmud.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

View file

@ -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,

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

View file

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

View file

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

View file

@ -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));
}
}
/**

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

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

View file

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

View file

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

View file

@ -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.