This commit is contained in:
Jesper Lundin 2007-04-24 12:57:38 +00:00
parent 2cf489403d
commit 515281351c
10 changed files with 64 additions and 17 deletions

View file

@ -127,14 +127,29 @@ public class InGameMouseInput extends MouseInput{
//unit action.
else if(event==RIGHT_MOUSE_BUTTON) {
if(!map.isPosEmpty(pos.getX(), pos.getY())){
int rand = (int)(Math.random()*selected.size());
for(int i=0; i<selected.size(); i++) {
selected.get(i).attack(new Vector2i(pos.getX(), pos.getY()));
if(rand==i) {
selected.get(i).attack(new Vector2i(pos.getX(), pos.getY()), true);
}
else{
selected.get(i).attack(new Vector2i(pos.getX(), pos.getY()), false);
}
}
}
else{
//MultiPrintStream.out.println("Moving: "+pos.getX()+", "+pos.getY());
int rand = (int)(Math.random()*selected.size());
for(int i=0; i<selected.size() ;i++){
selected.get(i).move(pos.getX(),pos.getY());
if(rand==i) {
selected.get(i).move(true, pos.getX(),pos.getY());
}
else{
selected.get(i).move(false, pos.getX(),pos.getY());
}
}
}
}

View file

@ -85,7 +85,7 @@ public abstract class GameEntity{
protected abstract SelectBox getSelection();
public void move(int x, int y) {
public void move(boolean play, int x, int y) {
}
@ -93,7 +93,7 @@ public abstract class GameEntity{
public abstract Entity getNode();
public abstract void attack(Vector2i target);
public abstract void attack(Vector2i target, boolean play);
public abstract Entity getSprite();
}

View file

@ -11,6 +11,11 @@ import ei.game.scene.GameEntity;
import ei.game.scene.Map;
import ei.game.scene.units.Unit;
/**
* The Building class, handles buildings, this case CommandCenter class.
* @author Jesper Lundin
*
*/
public abstract class Building extends GameEntity{
private Queue<Unit> buildQueue;
private int buildTime;

View file

@ -34,7 +34,7 @@ public class CommandCenter extends Building{
/**
* Doesnt matter anyway. Since buildings cant attack.
*/
public void attack(Vector2i target) {
public void attack(Vector2i target, boolean play) {
}
/**

View file

@ -19,7 +19,9 @@ public abstract class MapEntity extends Unit{
removeUnit();
}
}
public void move(int x, int y){
public void move(boolean play, int x, int y){
}
public void attack(Vector2i target, boolean play) {
}
protected void move(int x, int y, boolean b) {}

View file

@ -23,10 +23,12 @@ public class APU extends Unit{
}
public APU(int x, int y, Player p){
super(100, new Vector2i(x,y), p);
super(70, new Vector2i(x,y), p);
this.sprite = new Sprite("APU", "data/units/apu/apu0000.png");
sprite.setSize(new Vector2f(40,40));
getNode().add(sprite);
setBuildTime(20);
setPrice(200);
gunSound = new Sound("gunSound", "data/sounds/machinegun.wav");
moveSound[0] = new Sound("moveSound", "data/sounds/APUmove1.wav");

View file

@ -27,6 +27,8 @@ public class Bomber extends Unit{
this.sprite = new Sprite("Bomber", "data/units/bomber/bomber0000.png");
sprite.setSize(new Vector2f(50,60));
getNode().add(sprite);
setBuildTime(40);
setPrice(800);
gunSound = new Sound("gunSound", "data/sounds/bomberweapon.wav");
moveSound[0] = new Sound("moveSound", "data/sounds/BOMBERmove1.wav");
@ -76,7 +78,7 @@ public class Bomber extends Unit{
* @return
*/
public float getVelocity() {
return 2;
return 2.5f;
}
/**
* Manages the sprite connected to this unit.

View file

@ -27,6 +27,8 @@ public class Tank extends Unit{
this.sprite = new Sprite("Tank", "data/units/tank/tank0000.png");
sprite.setSize(new Vector2f(40,40));
getNode().add(sprite);
setBuildTime(30);
setPrice(400);
gunSound = new Sound("gunSound", "data/sounds/tankweapon.wav");
moveSound[0] = new Sound("moveSound", "data/sounds/TANKmove1.wav");

View file

@ -2,7 +2,6 @@ package ei.game.scene.units;
import java.util.LinkedList;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i;
import ei.engine.math.Vector3f;
@ -32,6 +31,9 @@ public abstract class Unit extends GameEntity{
// Order variables
private Vector2f moveTo;
private GameEntity attack;
private int buildTime;
private int price;
private int maintenance;
// The wepon reload timer
private int weponTimer;
// The path to travel
@ -95,15 +97,30 @@ public abstract class Unit extends GameEntity{
/**
* Moving a unit to the given pos
*
* @param play if play, play sound
* @param x The x pos to move to
* @param y The y pos to move to
*/
public void move(int x, int y){
public void move(boolean play, int x, int y){
if(play){
getMoveSound().play();
}
move(x,y,true);
}
/**
* Specifies a building time for this unit
* @param time, time to build.
*/
public void setBuildTime(int time) {
this.buildTime = time;
}
/**
* Specifies a price for this unit.
* @param price, the cost.
*/
public void setPrice(int price) {
this.price = price;
}
/**
* Moving a unit to the given pos
*
@ -128,8 +145,10 @@ public abstract class Unit extends GameEntity{
/**
* Lets a unit attack another unit or object in the world;
*/
public void attack(Vector2i target) {
public void attack(Vector2i target, boolean play) {
if(play){
getAttackSound().play();
}
this.target = target;
attack = InGameState.getMap().getPos(target.getX(),target.getY());
}
@ -241,7 +260,7 @@ public abstract class Unit extends GameEntity{
setPos(temp.getX(), temp.getY());
}
else if(!path.isEmpty()){
move(path.getLast().getX(), path.getLast().getY());
move(false, path.getLast().getX(), path.getLast().getY());
}
}
else{

View file

@ -9,7 +9,7 @@ public class CannonBall extends Weapon{
super(startPos);
setVelocity(4);
setRange(500);
setDamage(5);
setDamage(15);
setReload(100);
}
public Particles getWeapon() {