diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/DroneMovement.java b/src/main/java/com/fossgalaxy/games/ggj2017/DroneMovement.java new file mode 100644 index 0000000000000000000000000000000000000000..8d98afbb05b045af88dec715550b217179c74f65 --- /dev/null +++ b/src/main/java/com/fossgalaxy/games/ggj2017/DroneMovement.java @@ -0,0 +1,27 @@ +package com.fossgalaxy.games.ggj2017; + +import org.codetome.hexameter.core.api.CubeCoordinate; + +import com.fossgalaxy.games.rts.GameState; +import com.fossgalaxy.games.rts.entity.Entity; +import com.fossgalaxy.games.rts.order.MoveOrder; + +public class DroneMovement extends MoveOrder { + + public DroneMovement(CubeCoordinate move) { + super(move); + } + + @Override + public void doOrder(Entity entity, GameState state) { + + if (!JamApp.isZoneOfControl(state, entity)) { + return; + } + + super.doOrder(entity, state); + } + + + +} diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java b/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java index cd877676c55ce93c84b3861b86574669cf6e11e3..1ed314def79fcf977e5672476f643b5bb2cff19c 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/JamApp.java @@ -36,6 +36,23 @@ import com.fossgalaxy.games.rts.ui.UIController; */ public class JamApp { + + public static boolean isZoneOfControl(GameState state, Entity curr) { + Collection<Entity> entities = state.getOwnedEntities(curr.getOwner()); + + for (Entity e : entities) { + Integer zoneDistance = e.getType().getProperty("controlSignal"); + if (zoneDistance != null) { + int distance = state.getDistance(e.getPos(), curr.getPos()); + if (distance <= zoneDistance) { + return true; + } + } + } + + return false; + } + public static void main( String[] args ) { @@ -116,6 +133,7 @@ public class JamApp frame.add(view); JToolBar toolbar = new JToolBar(); + toolbar.setFloatable(false); JButton moveBtn = new JButton("Move"); moveBtn.addActionListener(a -> { @@ -132,7 +150,15 @@ public class JamApp }); toolbar.add(rangedAttackBtn); - toolbar.add(new JButton("Deploy Pigeon")); + + JButton turnDone = new JButton("done"); + turnDone.addActionListener(a -> { + model.done(); + view.repaint(); + }); + toolbar.addSeparator(); + toolbar.add(turnDone); + frame.add(toolbar, BorderLayout.SOUTH); frame.pack(); diff --git a/src/main/java/com/fossgalaxy/games/ggj2017/MoveAction.java b/src/main/java/com/fossgalaxy/games/ggj2017/MoveAction.java index a606df1aca27ce2050a9ca11c316b159e9b7b41f..ed3fdd87d682e315385d0960c3fb611c79392759 100644 --- a/src/main/java/com/fossgalaxy/games/ggj2017/MoveAction.java +++ b/src/main/java/com/fossgalaxy/games/ggj2017/MoveAction.java @@ -3,9 +3,11 @@ package com.fossgalaxy.games.ggj2017; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Area; +import java.awt.image.BufferedImage; import java.util.Collection; import org.codetome.hexameter.core.api.CubeCoordinate; @@ -14,6 +16,7 @@ import org.codetome.hexameter.core.api.Hexagon; import com.fossgalaxy.games.rts.GameState; import com.fossgalaxy.games.rts.entity.Entity; import com.fossgalaxy.games.rts.entity.HexagonTile; +import com.fossgalaxy.games.rts.io.SpriteRegistry; import com.fossgalaxy.games.rts.order.MoveOrder; import com.fossgalaxy.games.rts.order.Order; import com.fossgalaxy.games.rts.ui.GameAction; @@ -29,8 +32,18 @@ public class MoveAction implements GameAction { return; } + if (!JamApp.isZoneOfControl(s, actor)) { + SpriteRegistry sr = SpriteRegistry.INSTANCE; + BufferedImage img = sr.getImage("ui/no-signal"); + + Hexagon<HexagonTile> ht = s.cube2hex(actor.getPos()); + + g.drawImage(img, (int)ht.getCenterX() - 25, (int)ht.getCenterY() - 25, 50, 50, null); + + return; + } + Collection<Hexagon<HexagonTile>> range = s.getRange(actor.getPos(), actor.getType().getMovement()); - System.out.println(range); Area area = new Area(); @@ -55,7 +68,7 @@ public class MoveAction implements GameAction { @Override public Order generateOrder(CubeCoordinate co, GameState s) { - return new MoveOrder(co); + return new DroneMovement(co); } @Override diff --git a/src/main/resources/img/ui/no-signal.png b/src/main/resources/img/ui/no-signal.png new file mode 100644 index 0000000000000000000000000000000000000000..7ce3721b0b8400a3b164c9599d3766e759237d9a Binary files /dev/null and b/src/main/resources/img/ui/no-signal.png differ diff --git a/src/main/resources/types.json b/src/main/resources/types.json index 361a04e2523a9d7f1a94c67f9032fbe50694c6e4..d9fe8b61c60ac4af34488b392aa0e3065aa180dd 100644 --- a/src/main/resources/types.json +++ b/src/main/resources/types.json @@ -1,7 +1,9 @@ [ { "name": "blue_drone", - "image": "blue/enemyBlue1", + "sprite": { + "image": "blue/enemyBlue1" + }, "movement": 2, "health": 10, "attackRange": 2, @@ -14,7 +16,9 @@ }, { "name": "blue_worker", - "image": "blue/enemyBlue4", + "sprite": { + "image": "blue/enemyBlue4" + }, "movement": 2, "health": 10, "attackRange": 0, @@ -27,7 +31,12 @@ }, { "name": "blue_base", - "image": "blue/ufoBlue", + "sprite": { + "image": "blue/ufoBlue" + }, + "properties": { + "controlSignal": 10 + }, "movement": 0, "health": 10, "attackRange": 2, @@ -40,7 +49,9 @@ }, { "name": "red_drone", - "image": "red/enemyRed1", + "sprite": { + "image": "red/enemyRed1" + }, "movement": 2, "health": 10, "attackRange": 2, @@ -53,7 +64,9 @@ }, { "name": "red_worker", - "image": "red/enemyRed4", + "sprite": { + "image": "red/enemyRed4" + }, "movement": 2, "health": 10, "attackRange": 2, @@ -66,7 +79,9 @@ }, { "name": "red_base", - "image": "/ufoRed", + "sprite": { + "image": "red/ufoRed" + }, "movement": 0, "health": 10, "attackRange": 2,