LOLOOOOOOL
This commit is contained in:
parent
69adb14553
commit
88d92f1b96
4 changed files with 62 additions and 7 deletions
|
|
@ -4,6 +4,7 @@ import java.awt.Rectangle;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.engine.texture.TextureLoader;
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ import ei.engine.texture.TextureLoader;
|
|||
public class Sprite extends Entity {
|
||||
/** The texture that stores the image for this sprite */
|
||||
private Texture texture;
|
||||
private Vector2f moveTo;
|
||||
|
||||
/**
|
||||
* Create a new empty sprite
|
||||
|
|
@ -75,7 +77,29 @@ public class Sprite extends Entity {
|
|||
}
|
||||
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
|
||||
* @return The texture
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import ei.engine.state.GameState;
|
|||
import ei.game.input.InGameMouseInput;
|
||||
import ei.game.player.Human;
|
||||
import ei.game.scene.Map;
|
||||
import ei.game.scene.units.Tank;
|
||||
|
||||
|
||||
public class InGameState extends GameState{
|
||||
private Node rootNode;
|
||||
private Map map;
|
||||
private Human player;
|
||||
private static Map map;
|
||||
private static Human player;
|
||||
|
||||
public InGameState(String name){
|
||||
super(name);
|
||||
|
|
@ -18,12 +19,18 @@ public class InGameState extends GameState{
|
|||
|
||||
map = new Map(20,20);
|
||||
rootNode.add(map.getMapNode());
|
||||
|
||||
InGameMouseInput mouse = new InGameMouseInput(map);
|
||||
super.getInput().addInput(mouse);
|
||||
|
||||
|
||||
player = new Human();
|
||||
rootNode.add(player.getNode());
|
||||
Tank tank = new Tank();
|
||||
player.addUnit(tank);
|
||||
tank.move(10, 10);
|
||||
}
|
||||
public static Human getHuman(){
|
||||
return player;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
|
@ -33,5 +40,8 @@ public class InGameState extends GameState{
|
|||
public void update() {
|
||||
rootNode.update();
|
||||
}
|
||||
public static Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ import ei.engine.math.Vector2f;
|
|||
import ei.engine.scene.Sprite;
|
||||
|
||||
public class Tank extends Unit{
|
||||
|
||||
public Tank() {
|
||||
this(5, 5);
|
||||
}
|
||||
|
||||
public Tank(int x, int y){
|
||||
super(10);
|
||||
setSprite(new Sprite("Tank", "data/units/tank.png"));
|
||||
getSprite().setLocation(new Vector2f(200, 200));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package ei.game.scene.units;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.Human;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
|
||||
|
|
@ -9,10 +12,12 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
private Sprite looks;
|
||||
private Weapon weapon;
|
||||
private Vector2i oldPos;
|
||||
|
||||
public Unit(int l) {
|
||||
super(l);
|
||||
// TODO Auto-generated constructor stub
|
||||
looks = new Sprite("none");
|
||||
InGameState.getHuman().addUnit(this);
|
||||
}
|
||||
|
||||
public Sprite getSprite(){
|
||||
|
|
@ -21,5 +26,18 @@ public abstract class Unit extends GameEntity{
|
|||
public void setSprite(Sprite 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue