okidoki
This commit is contained in:
parent
99a30c2e8d
commit
90d685195d
5 changed files with 160 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
package ei.game.scene;
|
package ei.game.scene;
|
||||||
|
|
||||||
|
import ei.engine.math.Vector2f;
|
||||||
|
import ei.engine.math.Vector2i;
|
||||||
import ei.engine.scene.Entity;
|
import ei.engine.scene.Entity;
|
||||||
|
|
||||||
public abstract class GameEntity{
|
public abstract class GameEntity{
|
||||||
|
|
@ -75,4 +77,7 @@ public abstract class GameEntity{
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
|
|
||||||
public abstract Entity getNode();
|
public abstract Entity getNode();
|
||||||
|
|
||||||
|
public abstract void attack(Vector2i target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package ei.game.scene;
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
import ei.engine.math.Vector2i;
|
import ei.engine.math.Vector2i;
|
||||||
import ei.engine.math.Vector3f;
|
import ei.engine.math.Vector3f;
|
||||||
|
import ei.engine.scene.Box;
|
||||||
import ei.engine.scene.Node;
|
import ei.engine.scene.Node;
|
||||||
import ei.engine.scene.Sprite;
|
import ei.engine.scene.Sprite;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import ei.game.gamestate.InGameState;
|
||||||
import ei.game.scene.GameEntity;
|
import ei.game.scene.GameEntity;
|
||||||
import ei.game.scene.Map;
|
import ei.game.scene.Map;
|
||||||
import ei.game.scene.weapons.Weapon;
|
import ei.game.scene.weapons.Weapon;
|
||||||
|
import ei.game.scene.weapons.WeaponHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Unit class, handles the units in the game.
|
* The Unit class, handles the units in the game.
|
||||||
|
|
@ -92,6 +93,14 @@ public abstract class Unit extends GameEntity{
|
||||||
setPos(temp.getX(), temp.getY());
|
setPos(temp.getX(), temp.getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Lets a unit attack another unit or object in the world;
|
||||||
|
*/
|
||||||
|
public void attack(Vector2i target) {
|
||||||
|
Weapon wep = new Weapon(10, new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()));
|
||||||
|
wep.launch(target);
|
||||||
|
WeaponHandler.getInstance().addWeapon(wep);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updating the unit
|
* Updating the unit
|
||||||
|
|
@ -100,13 +109,12 @@ public abstract class Unit extends GameEntity{
|
||||||
|
|
||||||
if(moveTo != null) {
|
if(moveTo != null) {
|
||||||
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
||||||
//Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
|
|
||||||
|
|
||||||
int moveXminus = moveVect.getX()-oldVect.getX();
|
int moveXminus = moveVect.getX()-oldVect.getX();
|
||||||
int moveYminus = moveVect.getY()-oldVect.getY();
|
int moveYminus = moveVect.getY()-oldVect.getY();
|
||||||
|
|
||||||
float divideY = (moveVect.getY()+1)/(oldVect.getY()+1);
|
float divideY = (moveVect.getY()+2)/(oldVect.getY()+2);
|
||||||
float divideX = (moveVect.getX()+1)/(oldVect.getX()+1);
|
float divideX = (moveVect.getX()+2)/(oldVect.getX()+2);
|
||||||
|
|
||||||
//The rotation animation is done here.
|
//The rotation animation is done here.
|
||||||
if(moveVect.getX() < oldVect.getX() && divideY==1) {
|
if(moveVect.getX() < oldVect.getX() && divideY==1) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,63 @@
|
||||||
package ei.game.scene.weapons;
|
package ei.game.scene.weapons;
|
||||||
|
|
||||||
public abstract class Weapon {
|
import ei.engine.effects.Particles;
|
||||||
|
import ei.engine.math.Vector2f;
|
||||||
|
import ei.engine.math.Vector2i;
|
||||||
|
import ei.engine.scene.Entity;
|
||||||
|
import ei.game.scene.Map;
|
||||||
|
|
||||||
|
public class Weapon {
|
||||||
|
private int range;
|
||||||
|
private Vector2i target;
|
||||||
|
private int velocity;
|
||||||
|
private Particles part;
|
||||||
|
private Vector2f startPos;
|
||||||
|
|
||||||
|
public Weapon(int range, Vector2f startPos) {
|
||||||
|
this.range = range;
|
||||||
|
this.startPos = startPos;
|
||||||
|
part = new Particles("weapon");
|
||||||
|
part.setLocation(startPos);
|
||||||
|
part.MaxSpeedX=500;
|
||||||
|
part.MaxSpeedY=400;
|
||||||
|
part.MaxSpeedZ=600;
|
||||||
|
|
||||||
|
part.size=5;
|
||||||
|
|
||||||
|
}
|
||||||
|
public void launch(Vector2i target) {
|
||||||
|
this.target = target;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public void update() {
|
||||||
|
System.out.println("target getx :"+target.getX());
|
||||||
|
System.out.println("startpos getx :"+startPos.getX());
|
||||||
|
System.out.println("target getx :"+target.getY());
|
||||||
|
System.out.println("startpos gety :"+startPos.getY());
|
||||||
|
|
||||||
|
System.out.println("part getLoc: "+part.getLocation().getX());
|
||||||
|
|
||||||
|
Vector2f vect = Map.getPixelByPos(target.getX(), target.getY());
|
||||||
|
float percentage = (vect.getX()-startPos.getX()) / (vect.getY()-startPos.getY());
|
||||||
|
System.out.println("Percentage; "+percentage);
|
||||||
|
|
||||||
|
if(target.getX() > part.getLocation().getX()) {
|
||||||
|
part.getLocation().add(4f*percentage, 0f, 0f);
|
||||||
|
}
|
||||||
|
if(target.getX() < part.getLocation().getX()) {
|
||||||
|
part.getLocation().add(-4.0f*percentage, 0f, 0f);
|
||||||
|
}
|
||||||
|
if(target.getY() > part.getLocation().getY()) {
|
||||||
|
part.getLocation().add(0f, 4.0f, 0f);
|
||||||
|
}
|
||||||
|
if(target.getY() < part.getLocation().getY()) {
|
||||||
|
part.getLocation().add(0f, -4.0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public Entity getNode() {
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
84
src/ei/game/scene/weapons/WeaponHandler.java
Normal file
84
src/ei/game/scene/weapons/WeaponHandler.java
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
package ei.game.scene.weapons;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import ei.engine.scene.Entity;
|
||||||
|
import ei.engine.scene.Node;
|
||||||
|
import ei.game.player.Player;
|
||||||
|
import ei.game.player.PlayerHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The WeaponHandler class handles weapons.
|
||||||
|
* @author Jesper Lundin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class WeaponHandler {
|
||||||
|
private Node weaponNode;
|
||||||
|
private ArrayList<Weapon> weapons;
|
||||||
|
private static WeaponHandler instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created a weaponhandler.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public WeaponHandler() {
|
||||||
|
weapons = new ArrayList<Weapon>();
|
||||||
|
weaponNode = new Node("weapon");
|
||||||
|
|
||||||
|
}
|
||||||
|
public boolean addWeapon(Weapon w){
|
||||||
|
if(!weapons.contains(w)){
|
||||||
|
weapons.add(w);
|
||||||
|
weaponNode.add(w.getNode());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a player from the handler
|
||||||
|
* @param p The player to remove
|
||||||
|
* @return true if succesful else false
|
||||||
|
*/
|
||||||
|
public boolean removeWeapon(Weapon w){
|
||||||
|
if(weapons.contains(w)){
|
||||||
|
weapons.remove(w);
|
||||||
|
weaponNode.remove(w.getNode());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Updates all the weapons.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void update(){
|
||||||
|
for(int i=0; i<weapons.size() ;i++){
|
||||||
|
weapons.get(i).update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* return the current weaponNode.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Entity getNode() {
|
||||||
|
return weaponNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the instance of this class
|
||||||
|
*
|
||||||
|
* @return The instance
|
||||||
|
*/
|
||||||
|
public static WeaponHandler getInstance(){
|
||||||
|
if(instance == null){
|
||||||
|
instance = new WeaponHandler();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue