LOLOOOOOOL

This commit is contained in:
Jesper Lundin 2007-04-04 16:28:57 +00:00
parent 69adb14553
commit 88d92f1b96
4 changed files with 62 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import java.awt.Rectangle;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import ei.engine.math.Vector2f;
import ei.engine.texture.Texture; import ei.engine.texture.Texture;
import ei.engine.texture.TextureLoader; import ei.engine.texture.TextureLoader;
@ -18,6 +19,7 @@ import ei.engine.texture.TextureLoader;
public class Sprite extends Entity { public class Sprite extends Entity {
/** The texture that stores the image for this sprite */ /** The texture that stores the image for this sprite */
private Texture texture; private Texture texture;
private Vector2f moveTo;
/** /**
* Create a new empty sprite * Create a new empty sprite
@ -75,7 +77,29 @@ public class Sprite extends Entity {
} }
return texture.getImageHeight(); return texture.getImageHeight();
} }
public void move(Vector2f vector) {
moveTo = vector;
}
public void update() {
if(moveTo!=null) {
if(moveTo.getX()>getLocation().getX()) {
getLocation().add(0.5f, 0f, 0f);
}
if(moveTo.getY()>getLocation().getY()) {
getLocation().add(0f, 0.5f, 0f);
}
if(moveTo.getX()<getLocation().getX()) {
getLocation().add(-0.5f, 0f, 0f);
}
if(moveTo.getY()<getLocation().getY()) {
getLocation().add(0f, -0.5f, 0f);
}
if(moveTo.getX()==getLocation().getX() && moveTo.getY()==getLocation().getY()) {
moveTo = null;
}
}
}
/** /**
* Returns the texture * Returns the texture
* @return The texture * @return The texture

View file

@ -5,25 +5,32 @@ import ei.engine.state.GameState;
import ei.game.input.InGameMouseInput; import ei.game.input.InGameMouseInput;
import ei.game.player.Human; import ei.game.player.Human;
import ei.game.scene.Map; import ei.game.scene.Map;
import ei.game.scene.units.Tank;
public class InGameState extends GameState{ public class InGameState extends GameState{
private Node rootNode; private Node rootNode;
private Map map; private static Map map;
private Human player; private static Human player;
public InGameState(String name){ public InGameState(String name){
super(name); super(name);
rootNode = new Node("InGameNode"); rootNode = new Node("InGameNode");
map = new Map(20,20); map = new Map(20,20);
rootNode.add(map.getMapNode()); rootNode.add(map.getMapNode());
InGameMouseInput mouse = new InGameMouseInput(map); InGameMouseInput mouse = new InGameMouseInput(map);
super.getInput().addInput(mouse); super.getInput().addInput(mouse);
player = new Human(); player = new Human();
rootNode.add(player.getNode()); rootNode.add(player.getNode());
Tank tank = new Tank();
player.addUnit(tank);
tank.move(10, 10);
}
public static Human getHuman(){
return player;
} }
public void render() { public void render() {
@ -33,5 +40,8 @@ public class InGameState extends GameState{
public void update() { public void update() {
rootNode.update(); rootNode.update();
} }
public static Map getMap() {
return map;
}
} }

View file

@ -4,8 +4,11 @@ import ei.engine.math.Vector2f;
import ei.engine.scene.Sprite; import ei.engine.scene.Sprite;
public class Tank extends Unit{ public class Tank extends Unit{
public Tank() {
this(5, 5);
}
public Tank(){ public Tank(int x, int y){
super(10); super(10);
setSprite(new Sprite("Tank", "data/units/tank.png")); setSprite(new Sprite("Tank", "data/units/tank.png"));
getSprite().setLocation(new Vector2f(200, 200)); getSprite().setLocation(new Vector2f(200, 200));

View file

@ -1,7 +1,10 @@
package ei.game.scene.units; package ei.game.scene.units;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i; import ei.engine.math.Vector2i;
import ei.engine.scene.Sprite; import ei.engine.scene.Sprite;
import ei.game.gamestate.InGameState;
import ei.game.player.Human;
import ei.game.scene.GameEntity; import ei.game.scene.GameEntity;
import ei.game.scene.weapons.Weapon; import ei.game.scene.weapons.Weapon;
@ -9,10 +12,12 @@ public abstract class Unit extends GameEntity{
private Sprite looks; private Sprite looks;
private Weapon weapon; private Weapon weapon;
private Vector2i oldPos;
public Unit(int l) { public Unit(int l) {
super(l); super(l);
// TODO Auto-generated constructor stub looks = new Sprite("none");
InGameState.getHuman().addUnit(this);
} }
public Sprite getSprite(){ public Sprite getSprite(){
@ -21,5 +26,18 @@ public abstract class Unit extends GameEntity{
public void setSprite(Sprite image) { public void setSprite(Sprite image) {
looks = image; looks = image;
} }
public void setPos(int x, int y) {
oldPos = new Vector2i(x, y);
InGameState.getMap().setPos(this, x, y);
}
public void move(int x, int y) {
if(oldPos!=null) {
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
}
setPos(x, y);
looks.move(new Vector2f(x, y));
oldPos = new Vector2i(x, y);
}
} }