diff --git a/src/data/buildings/commandcenter.png b/src/data/buildings/commandcenter.png deleted file mode 100644 index 358337d..0000000 Binary files a/src/data/buildings/commandcenter.png and /dev/null differ diff --git a/src/data/ui/apu_button.png b/src/data/ui/apu_button.png new file mode 100644 index 0000000..9f352b6 Binary files /dev/null and b/src/data/ui/apu_button.png differ diff --git a/src/data/ui/apu_button_selected.png b/src/data/ui/apu_button_selected.png new file mode 100644 index 0000000..9729ce1 Binary files /dev/null and b/src/data/ui/apu_button_selected.png differ diff --git a/src/data/ui/bomber_button.png b/src/data/ui/bomber_button.png new file mode 100644 index 0000000..1bdef1c Binary files /dev/null and b/src/data/ui/bomber_button.png differ diff --git a/src/data/ui/bomber_button_selected.png b/src/data/ui/bomber_button_selected.png new file mode 100644 index 0000000..51065c5 Binary files /dev/null and b/src/data/ui/bomber_button_selected.png differ diff --git a/src/data/ui/start.png b/src/data/ui/start.png new file mode 100644 index 0000000..bcd6c70 Binary files /dev/null and b/src/data/ui/start.png differ diff --git a/src/data/ui/start_ontop.png b/src/data/ui/start_ontop.png new file mode 100644 index 0000000..4d1d7e9 Binary files /dev/null and b/src/data/ui/start_ontop.png differ diff --git a/src/data/ui/tank_button.png b/src/data/ui/tank_button.png new file mode 100644 index 0000000..03557e8 Binary files /dev/null and b/src/data/ui/tank_button.png differ diff --git a/src/data/ui/tank_button_selected.png b/src/data/ui/tank_button_selected.png new file mode 100644 index 0000000..4e1577f Binary files /dev/null and b/src/data/ui/tank_button_selected.png differ diff --git a/src/data/units/apu/Thumbs.db b/src/data/units/apu/Thumbs.db deleted file mode 100644 index 490c58f..0000000 Binary files a/src/data/units/apu/Thumbs.db and /dev/null differ diff --git a/src/data/units/apu/apu_body0000.png b/src/data/units/apu/apu_body0000.png deleted file mode 100644 index a3eba4d..0000000 Binary files a/src/data/units/apu/apu_body0000.png and /dev/null differ diff --git a/src/data/units/apu/apu_body0001.png b/src/data/units/apu/apu_body0001.png deleted file mode 100644 index 9507ee5..0000000 Binary files a/src/data/units/apu/apu_body0001.png and /dev/null differ diff --git a/src/data/units/apu/apu_body0002.png b/src/data/units/apu/apu_body0002.png deleted file mode 100644 index 85a869c..0000000 Binary files a/src/data/units/apu/apu_body0002.png and /dev/null differ diff --git a/src/data/units/apu/apu_wepon.png b/src/data/units/apu/apu_wepon.png deleted file mode 100644 index 2db1991..0000000 Binary files a/src/data/units/apu/apu_wepon.png and /dev/null differ diff --git a/src/data/units/bomber/Thumbs.db b/src/data/units/bomber/Thumbs.db deleted file mode 100644 index 8dc6501..0000000 Binary files a/src/data/units/bomber/Thumbs.db and /dev/null differ diff --git a/src/data/units/tank/Thumbs.db b/src/data/units/tank/Thumbs.db deleted file mode 100644 index fa2b453..0000000 Binary files a/src/data/units/tank/Thumbs.db and /dev/null differ diff --git a/src/data/units/tank/tank_body0000.png b/src/data/units/tank/tank_body0000.png deleted file mode 100644 index 5fe3257..0000000 Binary files a/src/data/units/tank/tank_body0000.png and /dev/null differ diff --git a/src/data/units/tank/tank_body0001.png b/src/data/units/tank/tank_body0001.png deleted file mode 100644 index da46c06..0000000 Binary files a/src/data/units/tank/tank_body0001.png and /dev/null differ diff --git a/src/data/units/tank/tank_body0002.png b/src/data/units/tank/tank_body0002.png deleted file mode 100644 index 663bb0c..0000000 Binary files a/src/data/units/tank/tank_body0002.png and /dev/null differ diff --git a/src/data/units/tank/tank_wepon.png b/src/data/units/tank/tank_wepon.png deleted file mode 100644 index cc9ce45..0000000 Binary files a/src/data/units/tank/tank_wepon.png and /dev/null differ diff --git a/src/ei/engine/input/MouseInput.java b/src/ei/engine/input/MouseInput.java index bb900ce..8f7c8fa 100644 --- a/src/ei/engine/input/MouseInput.java +++ b/src/ei/engine/input/MouseInput.java @@ -75,7 +75,7 @@ public abstract class MouseInput extends Input{ if(cursor != null){ GL11.glPushMatrix(); Vector3f v = LWJGLGameWindow.getCamera().getLocation(); - GL11.glTranslatef(v.getX(),v.getY(), v.getZ()); + GL11.glTranslatef(v.getX()+cursor.getSize().getX()/2,v.getY()+cursor.getSize().getY()/2, v.getZ()); cursor.render(); GL11.glPopMatrix(); } diff --git a/src/ei/engine/scene/Node.java b/src/ei/engine/scene/Node.java index cd7b3d1..66ff81d 100644 --- a/src/ei/engine/scene/Node.java +++ b/src/ei/engine/scene/Node.java @@ -43,6 +43,24 @@ public class Node extends Sprite { return null; } + /** + * Removes all the entities in this node + * + */ + public void clear(){ + entities.clear(); + } + + /** + * Checks if the given entity is present in the node + * + * @param e The entity to look for + * @return True if the entity exists else false + */ + public boolean contains(Entity e){ + return entities.contains(e); + } + /** * remove a Entity * @param name the name of Entity to remove diff --git a/src/ei/engine/texture/AnimatedTexture.java b/src/ei/engine/texture/AnimatedTexture.java index c1cd562..dcd4367 100644 --- a/src/ei/engine/texture/AnimatedTexture.java +++ b/src/ei/engine/texture/AnimatedTexture.java @@ -13,6 +13,8 @@ public class AnimatedTexture extends Texture { private HashMap textures; private String currentAnimation; private int textureId; + private int delay; + private int delayTimer; /** * Create a new empty AnimatedSprite @@ -24,7 +26,8 @@ public class AnimatedTexture extends Texture { super(); textures = new HashMap(); currentAnimation = null; - textureId = -1; + textureId = 0; + delay = 1; } /** @@ -36,6 +39,7 @@ public class AnimatedTexture extends Texture { */ public boolean addAnimation(String name, Texture[] t){ if(!textures.containsKey(name)){ + if(textures.isEmpty())currentAnimation = name; textures.put(name,t); return true; } @@ -81,10 +85,14 @@ public class AnimatedTexture extends Texture { */ public void bindGL() { if(currentAnimation != null){ + delayTimer++; textures.get(currentAnimation)[textureId].bindGL(); - textureId++; - if(textures.get(currentAnimation).length >= textureId){ - textureId = 0; + if(delayTimer > delay){ + textureId++; + if(textures.get(currentAnimation).length <= textureId){ + textureId = 0; + } + delayTimer = 0; } } } @@ -169,4 +177,13 @@ public class AnimatedTexture extends Texture { public void setTextureWidth(float texWidth) { textures.get(currentAnimation)[textureId].setTextureWidth(texWidth); } + + /** + * Set the delay between texures in frame count + * + * @param d The number of frames to whait until changing texture + */ + public void setDelay(int d){ + delay = d; + } } \ No newline at end of file diff --git a/src/ei/engine/ui/Button.java b/src/ei/engine/ui/Button.java new file mode 100644 index 0000000..f82d0fb --- /dev/null +++ b/src/ei/engine/ui/Button.java @@ -0,0 +1,69 @@ +package ei.engine.ui; + +import ei.engine.math.Vector2f; +import ei.engine.math.Vector3f; +import ei.engine.scene.Node; +import ei.engine.scene.Sprite; + +public class Button extends UiComponent{ + private Sprite normalButton; + private Sprite ontopButton; + private Sprite presedButton; + private Node buttonNode; + private Vector2f size; + + public Button(String name, Vector2f s){ + super(name); + buttonNode = new Node(name+"Node"); + size = s; + } + + public void setButtonSprite(Sprite s){ + normalButton = s; + } + + public void setOnTopButtonSprite(Sprite s){ + ontopButton = s; + } + + public void setPressedButtonSprite(Sprite s){ + presedButton = s; + } + + public void mousePos(int x, int y){ + if(size != null){ + Vector3f pos = buttonNode.getLocation(); + if( x >= (pos.getX()-(size.getX()/2)) && x <= (pos.getX()+(size.getX()/2)) + && y >= (pos.getY()-(size.getY()/2)) && y <= (pos.getY()+(size.getY()/2))){ + if(ontopButton != null && !buttonNode.contains(ontopButton)){ + buttonNode.clear(); + buttonNode.add(ontopButton); + } + } + else{ + if(normalButton != null && !buttonNode.contains(normalButton)){ + buttonNode.clear(); + buttonNode.add(normalButton); + } + } + } + } + + public void mouseDown(int x, int y, int event){ + if(size != null){ + Vector3f pos = buttonNode.getLocation(); + if( x >= (pos.getX()-(size.getX()/2)) && x <= (pos.getX()+(size.getX()/2)) + && y >= (pos.getY()-(size.getY()/2)) && y <= (pos.getY()+(size.getY()/2))){ + if(presedButton != null && !buttonNode.contains(presedButton)){ + buttonNode.clear(); + buttonNode.add(presedButton); + } + castEvent(); + } + } + } + + public Node getNode(){ + return buttonNode; + } +} diff --git a/src/ei/engine/ui/UiComponent.java b/src/ei/engine/ui/UiComponent.java new file mode 100644 index 0000000..2cba92b --- /dev/null +++ b/src/ei/engine/ui/UiComponent.java @@ -0,0 +1,61 @@ +package ei.engine.ui; + +import java.util.ArrayList; + +import ei.engine.scene.Entity; + + +public abstract class UiComponent { + /** The list of listeners for this component */ + private ArrayList listeners; + /** The name of the component */ + private String name; + + public UiComponent(String name){ + this.name = name; + listeners = new ArrayList(); + } + + /** + * Add a listener to this component + * + * @param l The listener to add + */ + public void addListener(UiListener l) { + listeners.add(l); + } + + /** + * Remove a listener from this component + * + * @param l The listener to remove + */ + public void removeListener(UiListener l) { + listeners.remove(l); + } + + /** + * Casts a event to all the listeners + * + */ + protected void castEvent(){ + for (int i=0;i ui; + private Node uiNode; + + /** + * Creates a ui handler + * + * @param name The name of the ui handler + */ + public UiHandler(String name){ + ui = new ArrayList(); + uiNode = new Node(name); + } + + /** + * Add An ui component to the handler + * + * @param u The component to add + * @return True if successfully added else false + */ + public boolean addUi(UiComponent u){ + if(!ui.contains(u)){ + ui.add(u); + uiNode.add(u.getNode()); + return true; + } + return false; + } + + /** + * Removes a component from the handler + * + * @param u The component to remove + * @return True if successfully removed else false + */ + public boolean removeUi(UiComponent u){ + if(ui.contains(u)){ + ui.remove(u); + uiNode.remove(u.getNode()); + return true; + } + return false; + } + + /** + * Removes a component from the handler by its name + * + * @param name The name of the component to remove + * @return True if successfully removed else false + */ + public boolean addUi(String name){ + for(int i=0; i LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){ + if(y > LWJGLGameWindow.getHeight()-10){ LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0); } Vector2i pos = Map.getPosByPixel( - LWJGLGameWindow.getCamera().getLocation().getX()+x, - LWJGLGameWindow.getCamera().getLocation().getY()+y); + LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2, + LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2); - if(map.posExist(pos.getX(), pos.getY())){ + //checks if the mous is on the buildbar + if(x >= (LWJGLGameWindow.getWidth()/2)-hud.getBuildBar().getSize().getX()/2 && + x <= (LWJGLGameWindow.getWidth()/2)+hud.getBuildBar().getSize().getX()/2 && + y >= LWJGLGameWindow.getHeight()-hud.getBuildBar().getSize().getY() && + y <= LWJGLGameWindow.getHeight()){} + // checks wich position the mouse is on top of + else if(map.posExist(pos.getX(), pos.getY())){ // The marking box is sized and positioned if(leftKlickPos != null){ float markingSizeX = 0; @@ -83,7 +92,7 @@ public class InGameMouseInput extends MouseInput{ markingSizeY = -Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y)); } - markingBox.setSize(new Vector2f(markingSizeX+getSprite().getSize().getX()/2,markingSizeY+getSprite().getSize().getY()/2)); + markingBox.setSize(new Vector2f(markingSizeX,markingSizeY)); markingBox.setLocation(new Vector2f( leftKlickPos.getX()-markingBox.getSize().getX()/2, leftKlickPos.getY()-markingBox.getSize().getY()/2)); @@ -109,11 +118,17 @@ public class InGameMouseInput extends MouseInput{ @Override public void mouseDown(int event,int x, int y) { Vector2i pos = Map.getPosByPixel( - LWJGLGameWindow.getCamera().getLocation().getX()+x, - LWJGLGameWindow.getCamera().getLocation().getY()+y); + LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2, + LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2); removeDead(); //map.printAllUnits(); - if(map.posExist(pos.getX(), pos.getY())){ + //checks if the mous is on the buildbar + if(x >= (LWJGLGameWindow.getWidth()/2)-hud.getBuildBar().getSize().getX()/2 && + x <= (LWJGLGameWindow.getWidth()/2)+hud.getBuildBar().getSize().getX()/2 && + y >= LWJGLGameWindow.getHeight()-hud.getBuildBar().getSize().getY() && + y <= LWJGLGameWindow.getHeight()){} + // checks wich position the mouse presed + else if(map.posExist(pos.getX(), pos.getY())){ //selecting unit. if(event==LEFT_MOUSE_BUTTON){ if(leftKlickPos == null){ @@ -159,13 +174,14 @@ public class InGameMouseInput extends MouseInput{ @Override public void mouseUp(int event,int x, int y) { Vector2i pos = Map.getPosByPixel( - LWJGLGameWindow.getCamera().getLocation().getX()+x, - LWJGLGameWindow.getCamera().getLocation().getY()+y); + LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2, + LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2); + if(hud != null)hud.getBuildHud().getUi().mouseDown(x, y, event); removeDead(); if(map.posExist(pos.getX(), pos.getY())){ if(leftKlickPos != null){ deselectAllUnits(); - selectUnits(Map.getPosByPixel(leftKlickPos.getX(), leftKlickPos.getY()),pos); + selectUnits(Map.getPosByPixel((leftKlickPos.getX()+Map.POS_SIZE/2), (leftKlickPos.getY())+Map.POS_SIZE/2),pos); leftKlickPos = null; getNode().remove(markingBox); } @@ -207,5 +223,9 @@ public class InGameMouseInput extends MouseInput{ } selected.clear(); } + + public void setHud(InGameHud u){ + hud = u; + } } diff --git a/src/ei/game/scene/Map.java b/src/ei/game/scene/Map.java index a7cd3fc..75d4473 100644 --- a/src/ei/game/scene/Map.java +++ b/src/ei/game/scene/Map.java @@ -23,7 +23,7 @@ public class Map { public static final int OBJ_STONE = 1; - private static final int POS_SIZE = 50; + public static final int POS_SIZE = 50; private int width; private int hight; private GameEntity[][] map; diff --git a/src/ei/game/scene/buildings/Building.java b/src/ei/game/scene/buildings/Building.java index 69c0cfa..11b074c 100644 --- a/src/ei/game/scene/buildings/Building.java +++ b/src/ei/game/scene/buildings/Building.java @@ -30,7 +30,6 @@ public abstract class Building extends GameEntity{ buildQueue = new LinkedList(); 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); } diff --git a/src/ei/game/scene/buildings/CommandCenter.java b/src/ei/game/scene/buildings/CommandCenter.java index 51cb544..f32b044 100644 --- a/src/ei/game/scene/buildings/CommandCenter.java +++ b/src/ei/game/scene/buildings/CommandCenter.java @@ -15,7 +15,7 @@ public class CommandCenter extends Building{ 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"); + this.sprite = new Sprite("APU", "data/buildings/cc/cc.png"); sprite.setSize(new Vector2f(200,200)); getNode().add(sprite); diff --git a/src/ei/game/scene/units/Bomber.java b/src/ei/game/scene/units/Bomber.java index f91c1e1..07aca53 100644 --- a/src/ei/game/scene/units/Bomber.java +++ b/src/ei/game/scene/units/Bomber.java @@ -4,6 +4,7 @@ import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.scene.Sprite; import ei.engine.sound.Sound; +import ei.engine.texture.AnimatedTexture; import ei.game.player.Player; import ei.game.scene.SelectBox; import ei.game.scene.weapons.BomberWeapon; @@ -24,7 +25,15 @@ public class Bomber extends Unit{ public Bomber(int x, int y, Player p){ super(200, new Vector2i(x,y), p); - this.sprite = new Sprite("Bomber", "data/units/bomber/bomber0000.png"); + AnimatedTexture tex = new AnimatedTexture("BomberTexture"); + tex.addAnimation("normal", new String[]{ + "data/units/bomber/bomber0000.png", + "data/units/bomber/bomber0001.png", + "data/units/bomber/bomber0002.png", + "data/units/bomber/bomber0003.png" + }); + tex.setDelay(5); + sprite = new Sprite("Bomber",tex); sprite.setSize(new Vector2f(50,60)); getNode().add(sprite); setBuildTime(40);