This commit is contained in:
parent
5c5084f211
commit
a92a0c021e
20 changed files with 281 additions and 12 deletions
BIN
src/data/sounds/APUattack.wav
Normal file
BIN
src/data/sounds/APUattack.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/APUmove1.wav
Normal file
BIN
src/data/sounds/APUmove1.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/APUselect.wav
Normal file
BIN
src/data/sounds/APUselect.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/APUyes.wav
Normal file
BIN
src/data/sounds/APUyes.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/BOMBERattack.wav
Normal file
BIN
src/data/sounds/BOMBERattack.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/BOMBERmove1.wav
Normal file
BIN
src/data/sounds/BOMBERmove1.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/BOMBERmove2.wav
Normal file
BIN
src/data/sounds/BOMBERmove2.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/BOMBERselect.wav
Normal file
BIN
src/data/sounds/BOMBERselect.wav
Normal file
Binary file not shown.
BIN
src/data/sounds/machinegun.wav
Normal file
BIN
src/data/sounds/machinegun.wav
Normal file
Binary file not shown.
|
|
@ -6,6 +6,7 @@ import ei.game.input.InGameMouseInput;
|
|||
import ei.game.player.HumanPlayer;
|
||||
import ei.game.player.PlayerHandler;
|
||||
import ei.game.scene.Map;
|
||||
import ei.game.scene.buildings.CommandCenter;
|
||||
import ei.game.scene.units.APU;
|
||||
import ei.game.scene.units.Bomber;
|
||||
import ei.game.scene.units.Tank;
|
||||
|
|
@ -35,6 +36,8 @@ public class InGameState extends GameState{
|
|||
player.addUnit(new Tank(2,0, player));
|
||||
player.addUnit(new Bomber(3, 0, player));
|
||||
player.addUnit(new APU(4, 0, player));
|
||||
player.addUnit(new APU(5, 0, player));
|
||||
player.addUnit(new CommandCenter(10, 10, player));
|
||||
|
||||
PlayerHandler.getInstance().addPlayer(player);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ei.game.player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.units.Unit;
|
||||
|
|
@ -15,12 +16,12 @@ public class GaiaPlayer extends Player{
|
|||
unitsNode = new Node("GaiaPlayerNode");
|
||||
}
|
||||
|
||||
public void addUnit(Unit u){
|
||||
public void addUnit(GameEntity u){
|
||||
units.add(u);
|
||||
unitsNode.add(u.getNode());
|
||||
}
|
||||
|
||||
public void removeUnit(Unit u){
|
||||
public void removeUnit(GameEntity u){
|
||||
units.remove(u);
|
||||
unitsNode.remove(u.getNode());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ public class HumanPlayer extends Player{
|
|||
unitsNode = new Node("HumanPlayerNode");
|
||||
}
|
||||
|
||||
public void addUnit(Unit u){
|
||||
public void addUnit(GameEntity u){
|
||||
units.add(u);
|
||||
unitsNode.add(u.getNode());
|
||||
}
|
||||
|
||||
public void removeUnit(Unit u){
|
||||
public void removeUnit(GameEntity u){
|
||||
units.remove(u);
|
||||
unitsNode.remove(u.getNode());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package ei.game.player;
|
||||
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.units.Unit;
|
||||
|
||||
public abstract class Player {
|
||||
|
||||
public abstract void addUnit(Unit u);
|
||||
public abstract void addUnit(GameEntity u);
|
||||
|
||||
public abstract void removeUnit(Unit u);
|
||||
public abstract void removeUnit(GameEntity u);
|
||||
|
||||
public abstract Node getNode();
|
||||
|
||||
|
|
|
|||
|
|
@ -199,6 +199,21 @@ public class Map {
|
|||
float yf = (POS_SIZE*y);
|
||||
return new Vector2f(xf,yf);
|
||||
}
|
||||
public static Vector2f getPixelByPos(int x, int y, int size){
|
||||
if(size%2!=0) {
|
||||
size = (size/2)+1;
|
||||
float xf = (POS_SIZE)*(x+size);
|
||||
float yf = (POS_SIZE)*(y+size);
|
||||
return new Vector2f(xf,yf);
|
||||
}
|
||||
size = (size/2)-1;
|
||||
float xDiff = Math.abs((getPixelByPos(x+size, 0).getX())-(getPixelByPos(size+x+1, 0).getX()))/2;
|
||||
float yDiff = Math.abs((getPixelByPos(0, size+y).getY())-(getPixelByPos(0, size+y+1).getY()))/2;
|
||||
|
||||
return new Vector2f(getPixelByPos(x+size, 0).getX()+xDiff, getPixelByPos(0, y+size).getY()+yDiff);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the pos inthe map is empty
|
||||
|
|
@ -213,6 +228,24 @@ public class Map {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns true if the pos in the map is empty
|
||||
* @param x pos
|
||||
* @param y pos
|
||||
* @param size, size to check
|
||||
* @return true if pos is empty, else false
|
||||
*/
|
||||
public boolean isPosEmpty(int x, int y, int size) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
if(posExist(i,j) && map[i][j] == null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given pos exists on the map
|
||||
|
|
@ -247,7 +280,36 @@ public class Map {
|
|||
public void setPos(GameEntity e, int x, int y){
|
||||
map[x][y] = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object in a rectangle of size*size, starting at x,y
|
||||
* @param e object
|
||||
* @param x pos
|
||||
* @param y pos
|
||||
* @param size
|
||||
*/
|
||||
public void setBuildPos(GameEntity e, int x, int y, int size) {
|
||||
if(isPosEmpty(x, y, size)) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
map[i][j] = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove an object from this position
|
||||
* @param e, the object
|
||||
* @param x pos of object
|
||||
* @param y pos of object
|
||||
* @param size of object
|
||||
*/
|
||||
public void removeBuildPos(int x, int y, int size) {
|
||||
for(int i=x; i<size+x; i++) {
|
||||
for(int j=y; j<size+y; j++) {
|
||||
map[i][j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes a object from that pos
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,19 +1,107 @@
|
|||
package ei.game.scene.buildings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.algo.AStar;
|
||||
import ei.game.algo.AStarNode;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
import ei.game.scene.units.Unit;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
public abstract class Building extends GameEntity{
|
||||
private ArrayList<Unit> availableUnits;
|
||||
private Queue<Unit> buildQueue;
|
||||
private Node unitNode;
|
||||
private Vector2i oldPos;
|
||||
private int size;
|
||||
|
||||
|
||||
public Building(int l, Vector2i pos, Player p, int size) {
|
||||
super(l, p);
|
||||
this.size = size;
|
||||
unitNode = new Node("UnitNode");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size));
|
||||
System.out.println("location: "+unitNode.getLocation());
|
||||
setPos(pos.getX(), pos.getY(), this.size);
|
||||
}
|
||||
|
||||
public Building(int l, Player p) {
|
||||
super(l,p);
|
||||
// TODO Auto-generated constructor stub
|
||||
public void setSelected(boolean b) {
|
||||
if(b) {
|
||||
unitNode.add(getSelection().getSelectNode());
|
||||
}
|
||||
else{
|
||||
unitNode.remove(getSelection().getSelectNode());
|
||||
}
|
||||
}
|
||||
|
||||
public void setMouseOver(boolean b) {
|
||||
if(b) {
|
||||
unitNode.add(getSelection().getMouseOverNode());
|
||||
}
|
||||
else{
|
||||
unitNode.remove(getSelection().getMouseOverNode());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets the size of the building.
|
||||
* @param size
|
||||
*/
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
/**
|
||||
* Returns the sprite for the unit
|
||||
*
|
||||
* @return The sprite for the unit
|
||||
*/
|
||||
public Node getNode(){
|
||||
return unitNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the pos of the unit in the map
|
||||
*
|
||||
* @param x The x pos to move to
|
||||
* @param y The y pos to move to
|
||||
*/
|
||||
public void setPos(int x, int y, int size) {
|
||||
if(oldPos!=null) {
|
||||
InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), size);
|
||||
}
|
||||
oldPos = new Vector2i(x, y);
|
||||
InGameState.getMap().setBuildPos(this, x, y, size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes this unit from the game.
|
||||
*
|
||||
*/
|
||||
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) {
|
||||
removeUnit();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
55
src/ei/game/scene/buildings/CommandCenter.java
Normal file
55
src/ei/game/scene/buildings/CommandCenter.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package ei.game.scene.buildings;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
|
||||
public class CommandCenter extends Building{
|
||||
private SelectBox selectionBox;
|
||||
private Sprite sprite;
|
||||
public CommandCenter(Player p) {
|
||||
this(0, 0, p);
|
||||
}
|
||||
|
||||
public CommandCenter(int x, int y, Player p){
|
||||
super(1000, new Vector2i(x,y), p, 4);
|
||||
this.sprite = new Sprite("APU", "data/buildings/commandcenter.png");
|
||||
sprite.setSize(new Vector2f(200,200));
|
||||
getNode().add(sprite);
|
||||
|
||||
selectionBox = new SelectBox(200,200,getMaxLife());
|
||||
}
|
||||
|
||||
protected SelectBox getSelection() {
|
||||
return selectionBox;
|
||||
}
|
||||
/**
|
||||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
|
||||
}
|
||||
/**
|
||||
* Doesnt matter anyway. Since buildings cant attack.
|
||||
*/
|
||||
public void attack(Vector2i target) {
|
||||
|
||||
}
|
||||
/**
|
||||
* Manages the sprite connected to this unit.
|
||||
* @param s
|
||||
*/
|
||||
public void setSprite(Sprite s) {
|
||||
this.sprite = s;
|
||||
}
|
||||
/**
|
||||
* returns the sprite connected to this type
|
||||
* of unit.
|
||||
* @return
|
||||
*/
|
||||
public Sprite getSprite() {
|
||||
return this.sprite;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package ei.game.scene.units;
|
|||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.sound.Sound;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.MachineGun;
|
||||
|
|
@ -11,6 +12,12 @@ import ei.game.scene.weapons.Weapon;
|
|||
public class APU extends Unit{
|
||||
private SelectBox selectionBox;
|
||||
private Sprite sprite;
|
||||
|
||||
private Sound gunSound;
|
||||
private Sound moveSound;
|
||||
private Sound attackSound;
|
||||
private Sound selectSound;
|
||||
|
||||
public APU(Player p) {
|
||||
this(0, 0, p);
|
||||
}
|
||||
|
|
@ -20,6 +27,9 @@ public class APU extends Unit{
|
|||
this.sprite = new Sprite("APU", "data/units/apu/apu0000.png");
|
||||
sprite.setSize(new Vector2f(40,40));
|
||||
getNode().add(sprite);
|
||||
gunSound = new Sound("gunSound", "data/sounds/machinegun.wav");
|
||||
moveSound = new Sound("moveSound", "data/sounds/APUmove1.wav");
|
||||
selectSound = new Sound("selectSound", "data/sounds/APUselect.wav");
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
setLife(50);
|
||||
|
|
@ -40,6 +50,15 @@ public class APU extends Unit{
|
|||
*/
|
||||
public void destroyed(){
|
||||
|
||||
}
|
||||
public Sound getGunSound() {
|
||||
return gunSound;
|
||||
}
|
||||
public Sound getMoveSound() {
|
||||
return moveSound;
|
||||
}
|
||||
public Sound getSelectSound() {
|
||||
return selectSound;
|
||||
}
|
||||
/**
|
||||
* returns the velocity of the unit type.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ei.game.scene.units;
|
|||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.sound.Sound;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.BomberWeapon;
|
||||
|
|
@ -11,6 +12,12 @@ import ei.game.scene.weapons.Weapon;
|
|||
public class Bomber extends Unit{
|
||||
private SelectBox selectionBox;
|
||||
private Sprite sprite;
|
||||
|
||||
private Sound gunSound;
|
||||
private Sound[] moveSound = new Sound[2];
|
||||
private Sound attackSound;
|
||||
private Sound selectSound;
|
||||
|
||||
public Bomber(Player p) {
|
||||
this(0, 0, p);
|
||||
}
|
||||
|
|
@ -20,6 +27,10 @@ public class Bomber extends Unit{
|
|||
this.sprite = new Sprite("Bomber", "data/units/bomber/bomber0000.png");
|
||||
sprite.setSize(new Vector2f(50,60));
|
||||
getNode().add(sprite);
|
||||
gunSound = new Sound("gunSound", "data/sounds/machinegun.wav");
|
||||
moveSound[0] = new Sound("moveSound", "data/sounds/BOMBERmove1.wav");
|
||||
moveSound[1] = new Sound("moveSound", "data/sounds/BOMBERmove2.wav");
|
||||
selectSound = new Sound("selectSound", "data/sounds/BOMBERselect.wav");
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
setLife(180);
|
||||
|
|
@ -40,6 +51,15 @@ public class Bomber extends Unit{
|
|||
*/
|
||||
public void destroyed(){
|
||||
|
||||
}
|
||||
public Sound getGunSound() {
|
||||
return gunSound;
|
||||
}
|
||||
public Sound getMoveSound() {
|
||||
return moveSound[(int)(Math.random()*2)];
|
||||
}
|
||||
public Sound getSelectSound() {
|
||||
return selectSound;
|
||||
}
|
||||
/**
|
||||
* returns the velocity of the unit type.
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import ei.engine.math.Vector2f;
|
|||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.sound.Sound;
|
||||
import ei.game.algo.AStar;
|
||||
import ei.game.algo.AStarNode;
|
||||
import ei.game.gamestate.InGameState;
|
||||
|
|
@ -35,6 +36,7 @@ public abstract class Unit extends GameEntity{
|
|||
private int weponTimer;
|
||||
// The path to travel
|
||||
private LinkedList<AStarNode> path;
|
||||
private Vector2i target;
|
||||
|
||||
/**
|
||||
* Creates a empty unit
|
||||
|
|
@ -50,6 +52,7 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
public void setSelected(boolean b) {
|
||||
if(b) {
|
||||
getSelectSound().play();
|
||||
unitNode.add(getSelection().getSelectNode());
|
||||
}
|
||||
else{
|
||||
|
|
@ -97,6 +100,7 @@ public abstract class Unit extends GameEntity{
|
|||
* @param y The y pos to move to
|
||||
*/
|
||||
public void move(int x, int y){
|
||||
getMoveSound().play();
|
||||
move(x,y,true);
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +129,7 @@ public abstract class Unit extends GameEntity{
|
|||
* Lets a unit attack another unit or object in the world;
|
||||
*/
|
||||
public void attack(Vector2i target) {
|
||||
this.target = target;
|
||||
attack = InGameState.getMap().getPos(target.getX(),target.getY());
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +137,12 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
public abstract float getVelocity();
|
||||
|
||||
public abstract Sound getGunSound();
|
||||
|
||||
public abstract Sound getSelectSound();
|
||||
|
||||
public abstract Sound getMoveSound();
|
||||
|
||||
public void removeUnit(){
|
||||
unitNode.remove(getSprite());
|
||||
getPlayer().removeUnit(this);
|
||||
|
|
@ -236,7 +247,15 @@ public abstract class Unit extends GameEntity{
|
|||
}
|
||||
else if(attack != null){
|
||||
Weapon wepon = getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()));
|
||||
Vector2i enamyPos = InGameState.getMap().getPosIndex(attack);
|
||||
Vector2i enamyPos;
|
||||
if(InGameState.getMap().getPos(target.getX(), target.getY())!=attack) {
|
||||
enamyPos = InGameState.getMap().getPosIndex(attack);
|
||||
}
|
||||
else{
|
||||
enamyPos = target.getCopy();
|
||||
}
|
||||
|
||||
|
||||
if(attack.getLife() <= 0 || enamyPos == null){
|
||||
attack = null;
|
||||
}
|
||||
|
|
@ -244,6 +263,7 @@ public abstract class Unit extends GameEntity{
|
|||
if(wepon.onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){
|
||||
if(weponTimer >= wepon.getReload()){
|
||||
wepon.launch(enamyPos);
|
||||
getGunSound().play();
|
||||
WeaponHandler.getInstance().addWeapon(wepon);
|
||||
weponTimer = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class MachineGun extends Weapon{
|
|||
setVelocity(4);
|
||||
setRange(500);
|
||||
setDamage(2);
|
||||
setReload(10);
|
||||
setReload(20);
|
||||
}
|
||||
public Particles getWeapon() {
|
||||
Particles part = new Particles("cannon");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue