yo
This commit is contained in:
parent
f707008ffb
commit
92e08382a8
10 changed files with 95 additions and 4 deletions
|
|
@ -182,7 +182,7 @@ public class LWJGLGameWindow {
|
|||
GameStateManager.getInstance().update();
|
||||
mainUpdate();
|
||||
mainRender();
|
||||
Display.sync(fps);
|
||||
//Display.sync(fps);
|
||||
//Display.sync2(fps);
|
||||
//Display.sync3(fps);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package ei.game.player;
|
|||
|
||||
import ei.game.scene.buildings.Building;
|
||||
import ei.game.scene.buildings.CommandCenter;
|
||||
import ei.game.scene.units.APU;
|
||||
import ei.game.scene.units.Bomber;
|
||||
import ei.game.scene.units.Tank;
|
||||
|
||||
public class AiPlayer extends Player{
|
||||
private CommandCenter cc;
|
||||
|
|
@ -16,5 +19,30 @@ public class AiPlayer extends Player{
|
|||
public Building getCC() {
|
||||
return cc;
|
||||
}
|
||||
public void update() {
|
||||
super.update();
|
||||
if(getKredits() >= 800 && cc.getBuildQueueSize()==0) {
|
||||
int unitToBuild = (int)(Math.random()*2);
|
||||
if(unitToBuild==0) {
|
||||
cc.buildUnit(new APU(this));
|
||||
}
|
||||
else if(unitToBuild==1) {
|
||||
cc.buildUnit(new Tank(this));
|
||||
}
|
||||
else if(unitToBuild==2) {
|
||||
cc.buildUnit(new Bomber(this));
|
||||
}
|
||||
}
|
||||
if(unitCount()>=10) {
|
||||
for(int i=0; i < unitCount(); i++) {
|
||||
if(!getUnit(i).isAttacking()){
|
||||
|
||||
getUnit(i).move(false, getUnit(i).getPos().getX()-2, getUnit(i).getPos().getY()-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ public abstract class GameEntity{
|
|||
public int getLife(){
|
||||
return life;
|
||||
}
|
||||
public abstract boolean isTerrain();
|
||||
|
||||
public abstract Vector2i getPos();
|
||||
|
||||
public abstract boolean isAttacking();
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -87,6 +87,9 @@ public abstract class Building extends GameEntity{
|
|||
public Node getNode(){
|
||||
return unitNode;
|
||||
}
|
||||
public boolean isTerrain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the pos of the unit in the map
|
||||
|
|
@ -205,5 +208,12 @@ public abstract class Building extends GameEntity{
|
|||
}
|
||||
|
||||
public abstract Entity getGroundSprite();
|
||||
|
||||
public Vector2i getPos() {
|
||||
return oldPos;
|
||||
}
|
||||
public boolean isAttacking() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,4 +81,5 @@ public class CommandCenter extends Building{
|
|||
public Entity getGroundSprite() {
|
||||
return ground;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ public abstract class MapEntity extends Unit{
|
|||
}
|
||||
public void attack(Vector2i target, boolean play) {
|
||||
}
|
||||
public boolean isTerrain(){
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void move(int x, int y, boolean b) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ public class Bomber extends Unit{
|
|||
getNode().add(sprite);
|
||||
setBuildTime(400);
|
||||
setPrice(800);
|
||||
autoAttack(false);
|
||||
|
||||
gunSound = new Sound("gunSound", "data/sounds/bomberweapon.wav");
|
||||
moveSound = new Sound[2];
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ public abstract class Unit extends GameEntity{
|
|||
private int price;
|
||||
// The wepon reload timer
|
||||
private int weponTimer;
|
||||
private int autoAttackTimer;
|
||||
// The path to travel
|
||||
private LinkedList<AStarNode> path;
|
||||
private Vector2i target;
|
||||
private boolean autoAttack;
|
||||
|
||||
/**
|
||||
* Creates a empty unit
|
||||
|
|
@ -50,6 +52,7 @@ public abstract class Unit extends GameEntity{
|
|||
unitNode = new Node("UnitNode");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY()));
|
||||
setPos(pos.getX(), pos.getY());
|
||||
autoAttack = true;
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +64,7 @@ public abstract class Unit extends GameEntity{
|
|||
public Unit(int l, Player p) {
|
||||
super(l, p);
|
||||
unitNode = new Node("UnitNode");
|
||||
autoAttack = true;
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +111,12 @@ public abstract class Unit extends GameEntity{
|
|||
public Node getNode(){
|
||||
return unitNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current pos of the unit
|
||||
*/
|
||||
public Vector2i getPos() {
|
||||
return oldPos;
|
||||
}
|
||||
/**
|
||||
* Changes the pos of the unit in the map
|
||||
*
|
||||
|
|
@ -157,6 +166,12 @@ public abstract class Unit extends GameEntity{
|
|||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
}
|
||||
public boolean isAttacking() {
|
||||
if(attack==null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Moving a unit to the given pos
|
||||
*
|
||||
|
|
@ -188,6 +203,9 @@ public abstract class Unit extends GameEntity{
|
|||
this.target = target;
|
||||
attack = InGameState.getMap().getPos(target.getX(),target.getY());
|
||||
}
|
||||
public void autoAttack(boolean auto) {
|
||||
autoAttack = auto;
|
||||
}
|
||||
|
||||
public abstract Weapon getWeapon(Vector2f startPos);
|
||||
|
||||
|
|
@ -335,6 +353,28 @@ public abstract class Unit extends GameEntity{
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(autoAttack && (autoAttackTimer%50==0)) {
|
||||
Weapon wep = getWeapon(Map.getPixelByPos(oldPos.getX(), oldPos.getY()));
|
||||
for(int i=oldPos.getX()-(wep.getRange()/50); i<=oldPos.getX()+(wep.getRange()/50); i++ ) {
|
||||
for(int j=oldPos.getY()-(wep.getRange()/50); j<=oldPos.getY()+(wep.getRange()/50); j++) {
|
||||
//System.out.println("i :"+i+" j: "+j);
|
||||
|
||||
if(InGameState.getMap().posExist(i, j)&& !InGameState.getMap().isPosEmpty(i, j)
|
||||
&& getPlayer()!=InGameState.getMap().getPos(i, j).getPlayer() && wep.onRange(Map.getPixelByPos(i, j))
|
||||
&& InGameState.getMap().getPos(i, j).isTerrain()==false) {
|
||||
//System.out.println("ziver is shit");
|
||||
attack(new Vector2i(i, j), false);
|
||||
i = oldPos.getX()+(wep.getRange()/50)+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
autoAttackTimer++;
|
||||
|
||||
}
|
||||
public boolean isTerrain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getBuildTime(){
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class BomberWeapon extends Weapon{
|
|||
part.size=10;
|
||||
float colors[][][]= // Rainbow Of Colors
|
||||
{
|
||||
{{0.0f,0.5f,1.0f},{0.0f,0.5f,1.0f}}
|
||||
{{0.5f,0.5f,1.0f},{0.5f,0.5f,1.0f}}
|
||||
|
||||
};
|
||||
part.colors = colors;
|
||||
|
|
@ -49,7 +49,7 @@ public class BomberWeapon extends Weapon{
|
|||
|
||||
if(!hit) {
|
||||
for(int i=position.getX()-1; i<=position.getX()+1; i++ ) {
|
||||
for(int j=position.getY(); j<=position.getY()+2; j++) {
|
||||
for(int j=position.getY()-1; j<=position.getY()+1; j++) {
|
||||
System.out.println("i :"+i+" j: "+j);
|
||||
if(InGameState.getMap().posExist(i, j)&& !InGameState.getMap().isPosEmpty(i, j)) {
|
||||
System.out.println("Damaged");
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ public abstract class Weapon {
|
|||
public int getReload(){
|
||||
return reload;
|
||||
}
|
||||
public int getRange(){
|
||||
return range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the weapon type.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue