diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..52384fe --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index c40d7dc..8254325 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,38 @@ +bin/* bin/ *.class JavaDoc/* *.class .classpath .DS_Store -.settings/ \ No newline at end of file +.settings/ + +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + +# TeXlipse plugin +.texlipse + +.DS_STORE \ No newline at end of file diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2487c9b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,73 @@ +#Sun Nov 24 07:00:48 IST 2013 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Build/Grame.jar b/Build/Grame.jar index 8a3fb78..8189b86 100644 Binary files a/Build/Grame.jar and b/Build/Grame.jar differ diff --git a/src/com/moomoohk/Grame/.DS_Store b/src/com/moomoohk/Grame/.DS_Store new file mode 100644 index 0000000..647683e Binary files /dev/null and b/src/com/moomoohk/Grame/.DS_Store differ diff --git a/src/com/moomoohk/Grame/AI/AStarPathfindingMovementAI.java b/src/com/moomoohk/Grame/Basics/AI/AStarPathfindingMovementAI.java similarity index 73% rename from src/com/moomoohk/Grame/AI/AStarPathfindingMovementAI.java rename to src/com/moomoohk/Grame/Basics/AI/AStarPathfindingMovementAI.java index 4eca04e..4c793c5 100644 --- a/src/com/moomoohk/Grame/AI/AStarPathfindingMovementAI.java +++ b/src/com/moomoohk/Grame/Basics/AI/AStarPathfindingMovementAI.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.AI; +package com.moomoohk.Grame.Basics.AI; import java.awt.Color; import java.io.Serializable; @@ -6,16 +6,16 @@ import com.moomoohk.Grame.Basics.Dir; import com.moomoohk.Grame.Basics.Entity; +import com.moomoohk.Grame.Basics.MovementAI; import com.moomoohk.Grame.Basics.Schematic; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameObjectLayer; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Graphics.PlainGridRender; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.MainGrameClass; -import com.moomoohk.Grame.Interfaces.MovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObjectLayer; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.CleanGridRender; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class AStarPathfindingMovementAI extends MovementAI implements MainGrameClass { @@ -37,23 +37,23 @@ public String author() } @Override - public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2) + public Coordinates getNext(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2) { - if (ent1.getPos(b.ID).distance(ent2.getPos(b.ID)) == 1) + if (ent1.getPos(g.ID).distance(ent2.getPos(g.ID)) == 1) return pos; if (cachedTargetPos != null) if (cachedTargetPos.equals(targetPos)) { Node last = getLast(cachedNodePath.get(cachedNodePath.size() - 1)); - if (cachedNodePath.remove(last)) //TODO: Fix this list + if (cachedNodePath.remove(last)) return last.getPos(); } else { if (showVisualization) - b.setFloorColor(Color.white); + g.setFloorColor(Color.white); if (showCosts) - RenderManager.clearText(b.ID); + RenderManager.clearText(g.ID); cachedTargetPos = targetPos; } else @@ -70,11 +70,11 @@ public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entit if (!current.getPos().equals(pos)) closed.add(current); open.remove(current); - if (current.getPos().distance(ent2.getPos(b.ID)) == 1) + if (current.getPos().distance(ent2.getPos(g.ID)) == 1) break; - for (Coordinates sur : current.getPos().getAllSurrounding(b)) + for (Coordinates sur : current.getPos().getAllSurrounding(g)) { - if (!b.isInBase(sur) || b.isOccupied(sur) || contains(closed, sur)) + if (!g.isInGrid(sur) || g.isOccupied(sur) || contains(closed, sur)) { open.remove(getNodeFromList(open, sur)); continue; @@ -93,15 +93,14 @@ public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entit while (current.getPos() != targetPos); //FIXME: NullPointerException when can't reach target Node node = getLast(closed.get(closed.size() - 1)); - // visualizationColor = new Color(new Random().nextFloat(), new Random().nextFloat(), new Random().nextFloat()); if (showCosts || showVisualization) for (int i = 0; i < closed.size(); i++) { if (showVisualization) - b.setFloorColor(closed.get(i).getPos(), new Color((255 - ((255 - visualizationColor.getRed()) / closed.size() * i)), (255 - ((255 - visualizationColor.getGreen()) / closed.size() * i)), (255 - ((255 - visualizationColor.getBlue()) / closed.size() * i)))); + g.setFloorColor(closed.get(i).getPos(), new Color((255 - ((255 - visualizationColor.getRed()) / closed.size() * i)), (255 - ((255 - visualizationColor.getGreen()) / closed.size() * i)), (255 - ((255 - visualizationColor.getBlue()) / closed.size() * i)))); if (showCosts) - RenderManager.setText(b.ID, new Coordinates(closed.get(i).getPos().getY(), closed.get(i).getPos().getX()), /*"F" + (int)(calcG(current, closed.get(i).getPos()) + calcH(closed.get(i).getPos(), targetPos))*/ - "G" + (int) calcG(current, closed.get(i).getPos()) + "H" + (int) calcH(closed.get(i).getPos(), targetPos), costColor); + RenderManager.setText(g.ID, new Coordinates(closed.get(i).getPos().getY(), closed.get(i).getPos().getX()), /*"F" + (int)(calcG(current, closed.get(i).getPos()) + calcH(closed.get(i).getPos(), targetPos))*/ + "G" + (int) calcG(current, closed.get(i).getPos()) + "H" + (int) calcH(closed.get(i).getPos(), targetPos), costColor); } cachedNodePath = closed; @@ -166,9 +165,26 @@ private Node findLowestFCost(ArrayList open) } @Override - public boolean isValid(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2) + public boolean isValid(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2) { - return !pos.isSurrounded(b); + // boolean[][] checked = new boolean[b.getRows()][b.getColumns()]; + // for (int i = 0; i < checked.length; i++) + // for (int j = 0; j < checked[0].length; j++) + // checked[i][j] = false; + // return floodCheck(checked, pos, targetPos, b); + return true; + } + + public boolean floodCheck(boolean[][] checked, Coordinates pos, Coordinates targetPos, Grid g) + { + g.setFloorColor(pos, GrameUtils.randomColor()); + if (pos.equals(targetPos)) + return true; + checked[pos.getY()][pos.getX()] = true; + for (Coordinates sur : pos.getSurrounding(g)) + if (!checked[sur.getY()][sur.getX()]) + return floodCheck(checked, sur, targetPos, g); + return true; } @Override @@ -247,25 +263,25 @@ public static void main(String[] args) @Override public void newGame() { - Base b = new Base(20, 20); - b.setWraparound(true); + Grid g = new Grid(20, 20); + g.setWraparound(true); Entity player = new Entity("Player", Color.gray); Entity monster = new Entity("Monster", Color.red); - b.addGrameObjectLayer(new GrameObjectLayer(b.getColumns(), b.getRows()), 1); - player.makePlayer(1, true, b.ID); + g.addGrameObjectLayer(new GrameObjectLayer(g.getColumns(), g.getRows()), 1); + player.makePlayer(1, true, g.ID); player.setSpeed(1); monster.setTarget(player.ID); AStarPathfindingMovementAI aStar = new AStarPathfindingMovementAI(); - monster.addAI(aStar, b.ID); + monster.addAI(aStar, g.ID); monster.setSpeed(5); - b.addGrameObject(player, new Coordinates(0, 0)); - b.addGrameObject(monster, new Coordinates(18, 10), 1); + g.addGrameObject(player, new Coordinates(10, 10)); + g.addGrameObject(monster, new Coordinates(18, 10), 1); for (int i = 1; i <= 10; i++) - new Schematic().load(b, GrameUtils.randomCoordinates(b)); + new Schematic().load(g, GrameUtils.randomCoordinates(g)); // Schematic s = new Schematic(1); // System.out.println(s.toString()); // s.load(b, new Coordinates(10, 10)); - RenderManager.render(b.ID, new PlainGridRender()); + RenderManager.render(g.ID, new CleanGridRender()); RenderManager.setVisible(true); aStar.showVisualization = true; // for (int i = 0; i < b.getColumns(); i++) diff --git a/src/com/moomoohk/Grame/AI/PlayerMovementAI.java b/src/com/moomoohk/Grame/Basics/AI/PlayerMovementAI.java similarity index 57% rename from src/com/moomoohk/Grame/AI/PlayerMovementAI.java rename to src/com/moomoohk/Grame/Basics/AI/PlayerMovementAI.java index 102c80d..5b00542 100644 --- a/src/com/moomoohk/Grame/AI/PlayerMovementAI.java +++ b/src/com/moomoohk/Grame/Basics/AI/PlayerMovementAI.java @@ -1,12 +1,12 @@ -package com.moomoohk.Grame.AI; +package com.moomoohk.Grame.Basics.AI; import com.moomoohk.Grame.Basics.Dir; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.Interfaces.MovementAI; +import com.moomoohk.Grame.Basics.MovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.Grid; /** * AI that lets the user control {@link GrameObject}s using the keyboard. @@ -32,27 +32,27 @@ public PlayerMovementAI(int player) this.player = player; } - public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public Coordinates getNext(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { Dir d = player == 1 ? GrameManager.dir1 : player == 2 ? GrameManager.dir2 : null; if (d == null) return pos; int layer = -1; - for (int i = 0; i < b.getGrameObjectLayers().size(); i++) - if (b.getGrameObjectLayers().get(i).contains(ent1.ID)) + for (int i = 0; i < g.getGrameObjectLayers().size(); i++) + if (g.getGrameObjectLayers().get(i).contains(ent1.ID)) layer = i; - if (!b.isInBase(MovementAI.slide(b, pos, d, layer))) - if (b.getWraparound()) - return MovementAI.wraparound(b, MovementAI.slide(b, pos, d, layer), d); + if (!g.isInGrid(MovementAI.slide(g, pos, d, layer))) + if (g.getWraparound()) + return MovementAI.wraparound(g, MovementAI.slide(g, pos, d, layer), d); else return pos; else - return MovementAI.slide(b, pos, d, layer); + return MovementAI.slide(g, pos, d, layer); } - public boolean isValid(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public boolean isValid(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { - return ent1.isPlayer(b.ID); + return ent1.isPlayer(g.ID); } public boolean isOverride() diff --git a/src/com/moomoohk/Grame/AI/PlayerSimAI.java b/src/com/moomoohk/Grame/Basics/AI/PlayerSimAI.java similarity index 71% rename from src/com/moomoohk/Grame/AI/PlayerSimAI.java rename to src/com/moomoohk/Grame/Basics/AI/PlayerSimAI.java index f8d2707..ea7b3ed 100644 --- a/src/com/moomoohk/Grame/AI/PlayerSimAI.java +++ b/src/com/moomoohk/Grame/Basics/AI/PlayerSimAI.java @@ -1,12 +1,12 @@ -package com.moomoohk.Grame.AI; +package com.moomoohk.Grame.Basics.AI; import java.util.Random; import com.moomoohk.Grame.Basics.Dir; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Interfaces.MovementAI; +import com.moomoohk.Grame.Basics.MovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Grid; /** * AI that is supposed to simulate a player. @@ -30,7 +30,7 @@ public PlayerSimAI() { super(); this.step = 0; - this.tries=0; + this.tries = 0; } @Override @@ -40,37 +40,37 @@ public String author() } @Override - public Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2) + public Coordinates getNext(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2) { if (this.step == 0) this.direction = generateDir(); Coordinates next = pos.addDir(this.direction); - if (b.getWraparound()) - next = MovementAI.wraparound(b, pos, this.direction); + if (g.getWraparound()) + next = MovementAI.wraparound(g, pos, this.direction); else - if (!b.isInBase(next)) + if (!g.isInGrid(next)) { this.step = 0; return pos; } - if(b.isOccupied(next)) + if (g.isOccupied(next)) { - this.step=0; + this.step = 0; this.tries++; - if(this.tries==10) + if (this.tries == 10) { - this.tries=0; + this.tries = 0; return pos; } - return getNext(pos, targetPos, b, ent1, ent2); + return getNext(pos, targetPos, g, ent1, ent2); } - this.tries=0; + this.tries = 0; this.step--; return next; } @Override - public boolean isValid(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2) + public boolean isValid(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2) { return true; } @@ -86,7 +86,7 @@ private Dir generateDir() this.step = new Random().nextInt(30) + 10; return Dir.getAllDirs()[new Random().nextInt(Dir.getAllDirs().length)]; } - + public String toString() { return "Player sim"; diff --git a/src/com/moomoohk/Grame/AI/SimpleChaseAI.java b/src/com/moomoohk/Grame/Basics/AI/SimpleChaseAI.java similarity index 65% rename from src/com/moomoohk/Grame/AI/SimpleChaseAI.java rename to src/com/moomoohk/Grame/Basics/AI/SimpleChaseAI.java index 9d503c1..d10d530 100644 --- a/src/com/moomoohk/Grame/AI/SimpleChaseAI.java +++ b/src/com/moomoohk/Grame/Basics/AI/SimpleChaseAI.java @@ -1,12 +1,12 @@ -package com.moomoohk.Grame.AI; +package com.moomoohk.Grame.Basics.AI; import com.moomoohk.Grame.Basics.Dir; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; -import com.moomoohk.Grame.Interfaces.MovementAI; +import com.moomoohk.Grame.Basics.MovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.Grid; /** * This AI is designed to chase objects. @@ -21,7 +21,7 @@ public class SimpleChaseAI extends MovementAI { private static final long serialVersionUID = 4361422461574615758L; - public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public Coordinates getNext(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { if (target == null) { @@ -29,15 +29,15 @@ public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity e return pos; } int layer = -1; - for (int i = 0; i < b.getGrameObjectLayers().size(); i++) - if (b.getGrameObjectLayers().get(i).contains(ent1.ID)) + for (int i = 0; i < g.getGrameObjectLayers().size(); i++) + if (g.getGrameObjectLayers().get(i).contains(ent1.ID)) layer = i; - if (!b.getWraparound()) + if (!g.getWraparound()) { Dir d = new Dir(pos, target); - if (!b.isOccupied(pos.addDir(d))) + if (!g.isOccupied(pos.addDir(d))) return pos.addDir(d); - return MovementAI.slide(b, pos, d, layer); + return MovementAI.slide(g, pos, d, layer); } else { @@ -48,42 +48,42 @@ public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity e while (temp.distance(target) > 0) { Dir dir = new Dir(target, temp); - if (!wrapped && !b.isInBase(temp.addDir(dir))) + if (!wrapped && !g.isInGrid(temp.addDir(dir))) { - temp = MovementAI.wraparound(b, MovementAI.slide(b, temp, dir, layer), dir); + temp = MovementAI.wraparound(g, MovementAI.slide(g, temp, dir, layer), dir); wrapped = true; } else if (!wrapped) { Dir dir2 = new Dir(temp, target); - Dir wall = closestWall(temp, b); + Dir wall = closestWall(temp, g); if (wall.getX() != 0) dir2.setX(wall.getX()); if (wall.getY() != 0) dir2.setY(wall.getY()); - temp = MovementAI.slide(b, temp, dir2, layer); + temp = MovementAI.slide(g, temp, dir2, layer); } else - temp = MovementAI.slide(b, temp, new Dir(temp, target), layer); + temp = MovementAI.slide(g, temp, new Dir(temp, target), layer); distanceThroughWall++; } if (normalDistance <= distanceThroughWall) - return MovementAI.slide(b, pos, new Dir(pos, target), layer); + return MovementAI.slide(g, pos, new Dir(pos, target), layer); else { Dir dir2 = new Dir(pos, target); - Dir wall = closestWall(pos, b); + Dir wall = closestWall(pos, g); if (wall.getX() != 0) dir2.setX(wall.getX()); if (wall.getY() != 0) dir2.setY(wall.getY()); - return MovementAI.wraparound(b, /*MovementAI.slide(b, pos, dir2)*/pos, dir2); + return MovementAI.wraparound(g, /*MovementAI.slide(b, pos, dir2)*/pos, dir2); } } } - public boolean isValid(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public boolean isValid(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { if (pos == null) return false; @@ -92,12 +92,12 @@ public boolean isValid(Coordinates pos, Coordinates target, Base b, Entity ent1, GrameUtils.print("Crucial parameters missing! Returning not valid. (" + ent1.getName() + ")", MessageLevel.ERROR); return false; } - if (ent1.getPos(b.ID).distance(ent2.getPos(b.ID)) > ent1.getRange()) + if (ent1.getPos(g.ID).distance(ent2.getPos(g.ID)) > ent1.getRange()) { return false; } - if (ent1.getPos(b.ID).isSurrounded(b)) + if (ent1.getPos(g.ID).isSurrounded(g)) { return false; } @@ -119,7 +119,7 @@ public String author() return "moomoohk"; } - public Dir closestWall(Coordinates pos, Base b) + public Dir closestWall(Coordinates pos, Grid b) { int up = pos.getY(), down = b.getRows() - pos.getY() - 1, left = pos.getX(), right = b.getColumns() - pos.getX() - 1; int min = Math.min(up, Math.min(down, Math.min(left, right))); diff --git a/src/com/moomoohk/Grame/AI/SimpleStrollAI.java b/src/com/moomoohk/Grame/Basics/AI/SimpleStrollAI.java similarity index 54% rename from src/com/moomoohk/Grame/AI/SimpleStrollAI.java rename to src/com/moomoohk/Grame/Basics/AI/SimpleStrollAI.java index a04cc37..8463583 100644 --- a/src/com/moomoohk/Grame/AI/SimpleStrollAI.java +++ b/src/com/moomoohk/Grame/Basics/AI/SimpleStrollAI.java @@ -1,10 +1,10 @@ -package com.moomoohk.Grame.AI; +package com.moomoohk.Grame.Basics.AI; import com.moomoohk.Grame.Basics.Dir; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Interfaces.MovementAI; +import com.moomoohk.Grame.Basics.MovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Grid; /** * This AI is designed to simulate neutral random movement. @@ -17,30 +17,30 @@ public class SimpleStrollAI extends MovementAI { private static final long serialVersionUID = 5810610984037692653L; - public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public Coordinates getNext(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { - Coordinates[] sur = pos.getAllSurrounding(b); + Coordinates[] sur = pos.getAllSurrounding(g); Coordinates next = sur[(int) (Math.random() * sur.length)]; try { - if ((int) (Math.random() * 15)>13) - if (b.getWraparound()) + if ((int) (Math.random() * 15) > 13) + if (g.getWraparound()) { - if (!b.isInBase(next)) - next=MovementAI.wraparound(b, next, new Dir(pos, next)); - if (b.isOccupied(next)) + if (!g.isInGrid(next)) + next = MovementAI.wraparound(g, next, new Dir(pos, next)); + if (g.isOccupied(next)) return pos; else return next; } else { - if (b.isOccupied(next)) - for (int i = 0; i < sur.length || (!b.isOccupied(next) && b.isInBase(next)); i++) + if (g.isOccupied(next)) + for (int i = 0; i < sur.length || (!g.isOccupied(next) && g.isInGrid(next)); i++) next = sur[i]; - if(!b.isInBase(next)) - next=pos; + if (!g.isInGrid(next)) + next = pos; } else next = pos; @@ -52,11 +52,11 @@ public Coordinates getNext(Coordinates pos, Coordinates target, Base b, Entity e return next; } - public boolean isValid(Coordinates pos, Coordinates target, Base b, Entity ent1, Entity ent2) + public boolean isValid(Coordinates pos, Coordinates target, Grid g, Entity ent1, Entity ent2) { - if(pos==null) + if (pos == null) return false; - return !pos.isSurrounded(b); + return !pos.isSurrounded(g); } public boolean isOverride() diff --git a/src/com/moomoohk/Grame/Basics/AI/package-info.java b/src/com/moomoohk/Grame/Basics/AI/package-info.java new file mode 100644 index 0000000..5189da3 --- /dev/null +++ b/src/com/moomoohk/Grame/Basics/AI/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains some MovementAI classes. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.Basics.AI; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Basics/DefaultRandomGen.java b/src/com/moomoohk/Grame/Basics/DefaultRandomGen.java index 0526e15..baebe4e 100644 --- a/src/com/moomoohk/Grame/Basics/DefaultRandomGen.java +++ b/src/com/moomoohk/Grame/Basics/DefaultRandomGen.java @@ -1,7 +1,5 @@ package com.moomoohk.Grame.Basics; -import com.moomoohk.Grame.Interfaces.EntityGenerator; - /** * This generator will generate a random name and type. * @@ -32,10 +30,8 @@ public String nameGen() if (i == 0) random = random.toUpperCase(); } - String[] suffixes = - { "tron", "man", "nar", "ram", "berg", "san" }; - char[] vowels = - { 'a', 'e', 'i', 'o', 'u' }; + String[] suffixes = { "tron", "man", "nar", "ram", "berg", "san" }; + char[] vowels = { 'a', 'e', 'i', 'o', 'u' }; boolean lastVowel = false; for (int i = 0; i < vowels.length; i++) if (random.charAt(random.length() - 1) == vowels[i]) @@ -53,8 +49,7 @@ public String nameGen() public String typeGen() { - String[] types = - { "elf", "orc", "human" }; + String[] types = { "elf", "orc", "human" }; return types[(int) (Math.random() * 3)]; } diff --git a/src/com/moomoohk/Grame/Basics/Dir.java b/src/com/moomoohk/Grame/Basics/Dir.java index f793f46..9ebeed6 100644 --- a/src/com/moomoohk/Grame/Basics/Dir.java +++ b/src/com/moomoohk/Grame/Basics/Dir.java @@ -1,6 +1,6 @@ package com.moomoohk.Grame.Basics; -import com.moomoohk.Grame.Essentials.Coordinates; +import com.moomoohk.Grame.Core.Coordinates; /** * Represents directions. diff --git a/src/com/moomoohk/Grame/Basics/Entity.java b/src/com/moomoohk/Grame/Basics/Entity.java index 02dba5b..eed3e33 100644 --- a/src/com/moomoohk/Grame/Basics/Entity.java +++ b/src/com/moomoohk/Grame/Basics/Entity.java @@ -4,15 +4,13 @@ import java.util.ArrayList; import java.util.HashMap; -import com.moomoohk.Grame.AI.PlayerMovementAI; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Basics.AI.PlayerMovementAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; import com.moomoohk.Grame.GrassMuncher.Coin; -import com.moomoohk.Grame.Interfaces.EntityGenerator; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.Interfaces.MovementAI; public class Entity extends GrameObject { @@ -85,75 +83,75 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { - determineAI(bID); - Coordinates c = getPos(bID); + determineAI(gID); + Coordinates c = getPos(gID); Coordinates target = null; if (this.targetID != -1) - target = GrameManager.findGrameObject(this.targetID).getPos(bID); - if (this.activeAI.size() != 0 && this.activeAI.get(bID) != null) - c = this.activeAI.get(bID).getNext(getPos(bID), target, GrameManager.findBase(bID), this, (Entity) GrameManager.findGrameObject(targetID)); - setPos(bID, c); + target = GrameManager.findGrameObject(this.targetID).getPos(gID); + if (this.activeAI.size() != 0 && this.activeAI.get(gID) != null) + c = this.activeAI.get(gID).getNext(getPos(gID), target, GrameManager.findGrid(gID), this, (Entity) GrameManager.findGrameObject(targetID)); + setPos(gID, c); } - private void determineAI(int bID) + private void determineAI(int gID) { - if (!GrameManager.findBase(bID).containsGrameObject(ID) || (this.AI.get(bID) == null && this.overrideAI.get(bID) == null) || (this.AI.get(bID) != null && this.AI.get(bID).size() == 0 && this.overrideAI.get(bID) == null)) + if (!GrameManager.findGrid(gID).containsGrameObject(ID) || (this.AI.get(gID) == null && this.overrideAI.get(gID) == null) || (this.AI.get(gID) != null && this.AI.get(gID).size() == 0 && this.overrideAI.get(gID) == null)) { - this.activeAI.remove(bID); + this.activeAI.remove(gID); return; } - if (this.overrideAI.size() == 0 || this.overrideAI.get(bID) == null) + if (this.overrideAI.size() == 0 || this.overrideAI.get(gID) == null) { MovementAI temp = null; - for (int i = 0; i < this.AI.get(bID).size(); i++) + for (int i = 0; i < this.AI.get(gID).size(); i++) { Coordinates target = null; if (targetID != -1) - target = GrameManager.findGrameObject(targetID).getPos(bID); - if (!this.AI.get(bID).get(i).isValid(getPos(bID), target, GrameManager.findBase(bID), this, (Entity) GrameManager.findGrameObject(targetID))) + target = GrameManager.findGrameObject(targetID).getPos(gID); + if (!this.AI.get(gID).get(i).isValid(getPos(gID), target, GrameManager.findGrid(gID), this, (Entity) GrameManager.findGrameObject(targetID))) continue; - temp = (MovementAI) this.AI.get(bID).get(i); + temp = (MovementAI) this.AI.get(gID).get(i); break; } - this.activeAI.put(bID, temp); + this.activeAI.put(gID, temp); } else { - this.activeAI.put(bID, this.overrideAI.get(bID)); + this.activeAI.put(gID, this.overrideAI.get(gID)); } } - public void addAI(MovementAI AI, int bID) + public void addAI(MovementAI AI, int gID) { if (!AI.isOverride()) { - if (this.AI.get(bID) == null) - this.AI.put(bID, new ArrayList()); - this.AI.get(bID).add(AI); + if (this.AI.get(gID) == null) + this.AI.put(gID, new ArrayList()); + this.AI.get(gID).add(AI); } else GrameUtils.print(AI + " is an override AI, it doens't belong in my AI list!", MessageLevel.ERROR); } - + public void printAI() { GrameUtils.print("Override AIs:", MessageLevel.NORMAL); if (overrideAI.size() != 0) - for (int bID : overrideAI.keySet()) - GrameUtils.print(bID + ": " + overrideAI.get(bID) + " (" + overrideAI.get(bID).author() + ")", MessageLevel.NORMAL); + for (int gID : overrideAI.keySet()) + GrameUtils.print(gID + ": " + overrideAI.get(gID) + " (" + overrideAI.get(gID).author() + ")", MessageLevel.NORMAL); else GrameUtils.print("[Empty]", MessageLevel.NORMAL); GrameUtils.print("Active AIs:", MessageLevel.NORMAL); if (activeAI.size() != 0) - for (int bID : activeAI.keySet()) - GrameUtils.print(bID + ": " + activeAI.get(bID) + " (" + activeAI.get(bID).author() + ")", MessageLevel.NORMAL); + for (int gID : activeAI.keySet()) + GrameUtils.print(gID + ": " + activeAI.get(gID) + " (" + activeAI.get(gID).author() + ")", MessageLevel.NORMAL); else GrameUtils.print("[Empty]", MessageLevel.NORMAL); - for (int bID : AI.keySet()) + for (int gID : AI.keySet()) { - GrameUtils.print("For base ID:" + bID, MessageLevel.NORMAL); + GrameUtils.print("For grid ID:" + gID, MessageLevel.NORMAL); String st = "null"; if (this.AI.size() == 0) GrameUtils.print("My AI list is empty!", MessageLevel.ERROR); @@ -162,12 +160,11 @@ public void printAI() { st = "null"; if (this.AI.get(i) != null) - st = this.AI.get(i) + " (" + ((MovementAI) this.AI.get(bID).get(i)).author() + ")"; + st = this.AI.get(i) + " (" + ((MovementAI) this.AI.get(gID).get(i)).author() + ")"; GrameUtils.print(i + 1 + ") " + st, MessageLevel.NORMAL); } } - } - + } public void clearAI() { @@ -176,10 +173,10 @@ public void clearAI() this.overrideAI = null; } - public void setOverrideAI(MovementAI mai, int bID) + public void setOverrideAI(MovementAI mai, int gID) { if (mai.isOverride()) - this.overrideAI.put(bID, mai); + this.overrideAI.put(gID, mai); else GrameUtils.print(mai + " is not an override AI!", MessageLevel.ERROR); } @@ -191,25 +188,25 @@ public void consume(GrameObject go) this.points += ((Coin) go).getWorth(); } - public boolean isPlayer(int bID) + public boolean isPlayer(int gID) { - if (this.player.get(bID) == null) + if (this.player.get(gID) == null) return false; - return this.player.get(bID); + return this.player.get(gID); } - public void makePlayer(int player, boolean f, int bID) + public void makePlayer(int player, boolean f, int gID) { if (f) { - this.player.put(bID, true); - this.overrideAI.put(bID, new PlayerMovementAI(player)); + this.player.put(gID, true); + this.overrideAI.put(gID, new PlayerMovementAI(player)); } else - if (this.player.get(bID)) + if (this.player.get(gID)) { - this.player.put(bID, false); - this.overrideAI.remove(bID); + this.player.put(gID, false); + this.overrideAI.remove(gID); } else GrameUtils.print("Not a player!", MessageLevel.ERROR); diff --git a/src/com/moomoohk/Grame/Interfaces/EntityGenerator.java b/src/com/moomoohk/Grame/Basics/EntityGenerator.java similarity index 81% rename from src/com/moomoohk/Grame/Interfaces/EntityGenerator.java rename to src/com/moomoohk/Grame/Basics/EntityGenerator.java index 25a5050..5704da0 100644 --- a/src/com/moomoohk/Grame/Interfaces/EntityGenerator.java +++ b/src/com/moomoohk/Grame/Basics/EntityGenerator.java @@ -1,11 +1,8 @@ -package com.moomoohk.Grame.Interfaces; - +package com.moomoohk.Grame.Basics; /** - * This interface is used to create generators which generate names and types - * for Entities. + * This interface is used to create generators which generate names and types for Entities. * - * @see OldEntity * @author Meshulam Silk * @version 1.0 * @since 2013-04-05 diff --git a/src/com/moomoohk/Grame/Interfaces/MovementAI.java b/src/com/moomoohk/Grame/Basics/MovementAI.java similarity index 59% rename from src/com/moomoohk/Grame/Interfaces/MovementAI.java rename to src/com/moomoohk/Grame/Basics/MovementAI.java index 2114c8f..416ad29 100644 --- a/src/com/moomoohk/Grame/Interfaces/MovementAI.java +++ b/src/com/moomoohk/Grame/Basics/MovementAI.java @@ -1,12 +1,11 @@ -package com.moomoohk.Grame.Interfaces; +package com.moomoohk.Grame.Basics; import java.io.Serializable; -import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.Grid; /** * Class to calculate the AIs of {@link GrameObject}s. @@ -28,68 +27,68 @@ public MovementAI() } /** - * Wraps {@link Coordinates} around a "wraparound" {@link Base}. + * Wraps {@link Coordinates} around a "wraparound" {@link Grid}. * - * @param b - * The "wraparound" {@link Base}. + * @param g + * The "wraparound" {@link Grid}. * @param pos * The {@link Coordinates} to wrap. * @param d * The {@link Dir} to apply. * @return The wrapped {@link Coordinates}. - * @see Base#getWraparound() + * @see Grid#getWraparound() */ - public static Coordinates wraparound(Base b, Coordinates pos, Dir d) + public static Coordinates wraparound(Grid g, Coordinates pos, Dir d) { if (pos.addDir(d).getX() <= -1 && pos.addDir(d).getY() <= -1) - return new Coordinates(b.getColumns() - 1, b.getRows() - 1); - if (pos.addDir(d).getX() <= -1 && pos.addDir(d).getY() >= b.getRows()) - return new Coordinates(b.getColumns() - 1, 0); - if (pos.addDir(d).getX() >= b.getColumns() && pos.addDir(d).getY() <= -1) - return new Coordinates(0, b.getRows() - 1); - if (pos.addDir(d).getX() >= b.getColumns() && pos.addDir(d).getY() >= b.getRows()) + return new Coordinates(g.getColumns() - 1, g.getRows() - 1); + if (pos.addDir(d).getX() <= -1 && pos.addDir(d).getY() >= g.getRows()) + return new Coordinates(g.getColumns() - 1, 0); + if (pos.addDir(d).getX() >= g.getColumns() && pos.addDir(d).getY() <= -1) + return new Coordinates(0, g.getRows() - 1); + if (pos.addDir(d).getX() >= g.getColumns() && pos.addDir(d).getY() >= g.getRows()) return new Coordinates(0, 0); if (pos.addDir(d).getX() <= -1) - return new Coordinates(b.getColumns() - 1, pos.getY()); + return new Coordinates(g.getColumns() - 1, pos.getY()); if (pos.addDir(d).getY() <= -1) - return new Coordinates(pos.getX(), b.getRows() - 1); - if (pos.addDir(d).getX() >= b.getColumns()) + return new Coordinates(pos.getX(), g.getRows() - 1); + if (pos.addDir(d).getX() >= g.getColumns()) return new Coordinates(0, pos.getY()); - if (pos.addDir(d).getY() >= b.getRows()) + if (pos.addDir(d).getY() >= g.getRows()) return new Coordinates(pos.getX(), 0); return pos.addDir(d); } /** - * Slides {@link Coordinates} on obstacles in a {@link Base}. + * Slides {@link Coordinates} on obstacles in a {@link Grid}. * - * @param b - * The {@link Base}. + * @param g + * The {@link Grid}. * @param pos * The {@link Coordinates} to slide. * @param d * The {@link Dir} to apply. * @return The slided {@link Coordinates}. */ - public static Coordinates slide(Base b, Coordinates pos, Dir d, int layer) + public static Coordinates slide(Grid g, Coordinates pos, Dir d, int layer) { if (!d.isDiag()) return pos.addDir(d); - if (b.isInBase(pos.addDir(d)) && !b.isOccupied(pos.addDir(d), layer)) + if (g.isInGrid(pos.addDir(d)) && !g.isOccupied(pos.addDir(d), layer)) return pos.addDir(d); - if (!b.isInBase(pos.addDir(d))) - if (!b.getWraparound()) + if (!g.isInGrid(pos.addDir(d))) + if (!g.getWraparound()) { - if (b.isInBase(pos.addDir(d.split()[0]))) + if (g.isInGrid(pos.addDir(d.split()[0]))) return pos.addDir(d.split()[0]); - if (b.isInBase(pos.addDir(d.split()[1]))) + if (g.isInGrid(pos.addDir(d.split()[1]))) return pos.addDir(d.split()[1]); } else - return wraparound(b, pos, d); - if (!b.isOccupied(pos.addDir(d.split()[0]), layer)) + return wraparound(g, pos, d); + if (!g.isOccupied(pos.addDir(d.split()[0]), layer)) return pos.addDir(d.split()[0]); - if (!b.isOccupied(pos.addDir(d.split()[1]), layer)) + if (!g.isOccupied(pos.addDir(d.split()[1]), layer)) return pos.addDir(d.split()[1]); return pos.addDir(d); } @@ -108,15 +107,15 @@ public static Coordinates slide(Base b, Coordinates pos, Dir d, int layer) * The current {@link Coordinates} of the {@link GrameObject}. * @param targetPos * The {@link Coordinates} of the {@link GrameObject}'s target. - * @param b - * The {@link Base}. + * @param g + * The {@link Grid}. * @param ent1 * The {@link GrameObject}. * @param ent2 * The {@link GrameObject}'s target. * @return The next {@link Coordinates} to which the {@link GrameObject} should move. */ - public abstract Coordinates getNext(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2); + public abstract Coordinates getNext(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2); /** * Checks whether this AI is valid. @@ -125,15 +124,15 @@ public static Coordinates slide(Base b, Coordinates pos, Dir d, int layer) * The current {@link Coordinates} of the {@link GrameObject}. * @param targetPos * The {@link Coordinates} of the {@link GrameObject}'s target. - * @param b - * The {@link Base}. + * @param g + * The {@link Grid}. * @param ent1 * The {@link GrameObject}. * @param ent2 * The {@link GrameObject}'s target. * @return True if this AI is valid, else false. */ - public abstract boolean isValid(Coordinates pos, Coordinates targetPos, Base b, Entity ent1, Entity ent2); + public abstract boolean isValid(Coordinates pos, Coordinates targetPos, Grid g, Entity ent1, Entity ent2); /** * Checks whether this AI is an override AI. diff --git a/src/com/moomoohk/Grame/Basics/Schematic.java b/src/com/moomoohk/Grame/Basics/Schematic.java index ef5b4a1..3929fca 100644 --- a/src/com/moomoohk/Grame/Basics/Schematic.java +++ b/src/com/moomoohk/Grame/Basics/Schematic.java @@ -2,10 +2,10 @@ import java.awt.Color; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.Grid; /** * This class is a collection of {@link Wall}s which is arranged in a certain pattern. @@ -46,201 +46,201 @@ public Schematic(int type) this.map[i][j] = null; switch (this.type) { - case 0: - def(2, 0); - def(2, 1); - def(1, 2); - def(2, 2); - def(3, 2); - def(2, 3); - def(2, 4); - break; - case 1: - def(0, 2); - def(1, 2); - def(2, 1); - def(2, 2); - def(2, 3); - def(3, 2); - def(4, 2); - break; - case 2: - def(0, 0); - def(1, 0); - def(2, 0); - def(0, 1); - def(0, 2); - break; - case 3: - def(0, 0); - def(0, 1); - def(0, 2); - def(0, 3); - def(1, 0); - def(2, 0); - def(3, 0); - break; - case 4: - def(0, 0); - def(1, 0); - def(2, 0); - def(4, 0); - def(0, 2); - def(2, 2); - def(3, 2); - def(4, 2); - def(0, 4); - def(1, 4); - def(2, 4); - def(4, 4); - break; - case 5: - def(0, 0); - def(0, 1); - def(0, 2); - def(0, 4); - def(2, 0); - def(2, 2); - def(2, 3); - def(2, 4); - def(4, 0); - def(4, 1); - def(4, 2); - def(4, 4); - break; - case 6: - def(0, 0); - def(1, 0); - def(2, 0); - def(3, 0); - def(4, 0); - def(2, 1); - def(2, 2); - def(2, 3); - def(0, 4); - def(1, 4); - def(2, 4); - def(3, 4); - def(4, 4); - break; - case 7: - def(0, 0); - def(0, 1); - def(0, 2); - def(0, 3); - def(0, 4); - def(1, 2); - def(2, 2); - def(3, 2); - def(4, 0); - def(4, 1); - def(4, 2); - def(4, 3); - def(4, 4); - break; - case 8: - def(0, 0); - def(1, 0); - def(3, 0); - def(4, 0); - def(1, 1); - def(2, 1); - def(3, 1); - def(1, 3); - def(2, 3); - def(3, 3); - def(0, 4); - def(1, 4); - def(3, 4); - def(4, 4); - break; - case 9: - def(0, 0); - def(0, 1); - def(0, 3); - def(0, 4); - def(1, 1); - def(1, 2); - def(1, 3); - def(3, 1); - def(3, 2); - def(3, 3); - def(4, 0); - def(4, 1); - def(4, 3); - def(4, 4); - break; - case 10: - def(1, 0); - def(4, 0); - def(0, 1); - def(1, 1); - def(3, 1); - def(1, 3); - def(3, 3); - def(4, 3); - def(0, 4); - def(3, 4); - break; - case 11: - def(0, 0); - def(3, 0); - def(1, 1); - def(3, 1); - def(4, 1); - def(0, 3); - def(1, 3); - def(3, 3); - def(1, 4); - def(4, 4); - break; - case 12: - def(0, 0); - def(1, 0); - def(3, 0); - def(4, 0); - def(0, 1); - def(4, 1); - def(2, 2); - def(0, 3); - def(4, 3); - def(0, 4); - def(1, 4); - def(3, 4); - def(4, 4); - break; - case 13: - def(0, 0); - def(1, 0); - trig(2, 0); - def(3, 0); - def(4, 0); - def(0, 1); - def(4, 1); - trig(0, 2); - def(0, 3); - def(4, 3); - def(0, 4); - def(1, 4); - trig(2, 4); - def(3, 4); - def(4, 4); - trig(4, 2); - break; - case 14: - def(1, 1); - def(2, 1); - def(3, 1); - def(1, 2); - def(3, 2); - def(1, 3); - def(2, 3); - def(3, 3); - break; - case 15: - for (int i = 0; i < this.map.length; i++) - for (int j = 0; j < this.map.length; j++) - def(i, j); + case 0: + def(2, 0); + def(2, 1); + def(1, 2); + def(2, 2); + def(3, 2); + def(2, 3); + def(2, 4); + break; + case 1: + def(0, 2); + def(1, 2); + def(2, 1); + def(2, 2); + def(2, 3); + def(3, 2); + def(4, 2); + break; + case 2: + def(0, 0); + def(1, 0); + def(2, 0); + def(0, 1); + def(0, 2); + break; + case 3: + def(0, 0); + def(0, 1); + def(0, 2); + def(0, 3); + def(1, 0); + def(2, 0); + def(3, 0); + break; + case 4: + def(0, 0); + def(1, 0); + def(2, 0); + def(4, 0); + def(0, 2); + def(2, 2); + def(3, 2); + def(4, 2); + def(0, 4); + def(1, 4); + def(2, 4); + def(4, 4); + break; + case 5: + def(0, 0); + def(0, 1); + def(0, 2); + def(0, 4); + def(2, 0); + def(2, 2); + def(2, 3); + def(2, 4); + def(4, 0); + def(4, 1); + def(4, 2); + def(4, 4); + break; + case 6: + def(0, 0); + def(1, 0); + def(2, 0); + def(3, 0); + def(4, 0); + def(2, 1); + def(2, 2); + def(2, 3); + def(0, 4); + def(1, 4); + def(2, 4); + def(3, 4); + def(4, 4); + break; + case 7: + def(0, 0); + def(0, 1); + def(0, 2); + def(0, 3); + def(0, 4); + def(1, 2); + def(2, 2); + def(3, 2); + def(4, 0); + def(4, 1); + def(4, 2); + def(4, 3); + def(4, 4); + break; + case 8: + def(0, 0); + def(1, 0); + def(3, 0); + def(4, 0); + def(1, 1); + def(2, 1); + def(3, 1); + def(1, 3); + def(2, 3); + def(3, 3); + def(0, 4); + def(1, 4); + def(3, 4); + def(4, 4); + break; + case 9: + def(0, 0); + def(0, 1); + def(0, 3); + def(0, 4); + def(1, 1); + def(1, 2); + def(1, 3); + def(3, 1); + def(3, 2); + def(3, 3); + def(4, 0); + def(4, 1); + def(4, 3); + def(4, 4); + break; + case 10: + def(1, 0); + def(4, 0); + def(0, 1); + def(1, 1); + def(3, 1); + def(1, 3); + def(3, 3); + def(4, 3); + def(0, 4); + def(3, 4); + break; + case 11: + def(0, 0); + def(3, 0); + def(1, 1); + def(3, 1); + def(4, 1); + def(0, 3); + def(1, 3); + def(3, 3); + def(1, 4); + def(4, 4); + break; + case 12: + def(0, 0); + def(1, 0); + def(3, 0); + def(4, 0); + def(0, 1); + def(4, 1); + def(2, 2); + def(0, 3); + def(4, 3); + def(0, 4); + def(1, 4); + def(3, 4); + def(4, 4); + break; + case 13: + def(0, 0); + def(1, 0); + trig(2, 0); + def(3, 0); + def(4, 0); + def(0, 1); + def(4, 1); + trig(0, 2); + def(0, 3); + def(4, 3); + def(0, 4); + def(1, 4); + trig(2, 4); + def(3, 4); + def(4, 4); + trig(4, 2); + break; + case 14: + def(1, 1); + def(2, 1); + def(3, 1); + def(1, 2); + def(3, 2); + def(1, 3); + def(2, 3); + def(3, 3); + break; + case 15: + for (int i = 0; i < this.map.length; i++) + for (int j = 0; j < this.map.length; j++) + def(i, j); } } @@ -286,13 +286,13 @@ public Color getColor(Coordinates c) } /** - * Shows this Schematic in a {@link Base}. + * Shows this Schematic in a {@link Grid}. *

* For debug purposes. */ public void show() { - Base b = new Base(5, 5, "Schematic " + type); + Grid b = new Grid(5, 5, "Schematic " + type); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) b.setFloorColor(new Coordinates(j, i), this.map[i][j]); @@ -396,14 +396,14 @@ public void setColor(Coordinates pos, Color c) } /** - * Loads the Schematic into a given {@link Base} at given {@link Coordinates}. + * Loads the Schematic into a given {@link Grid} at given {@link Coordinates}. * - * @param b - * {@link Base} in which to load this Schematic. + * @param g + * {@link Grid} in which to load this Schematic. * @param loc * {@link Coordinates} at which to load this Schematic. */ - public void load(Base b, Coordinates loc) + public void load(Grid g, Coordinates loc) { int sx = 0; int sy = 0; @@ -415,8 +415,8 @@ public void load(Base b, Coordinates loc) for (int j = loc.getX(); j < loc.getX() + this.width; j++) { mapx = j; - if (this.map[sy][sx] != null && b.isInBase(new Coordinates(mapx, mapy)) && !b.isOccupied(new Coordinates(mapx, mapy))) - b.addGrameObject(new Wall(getColor(new Coordinates(sx, sy))), new Coordinates(mapx, mapy)); + if (this.map[sy][sx] != null && g.isInGrid(new Coordinates(mapx, mapy)) && !g.isOccupied(new Coordinates(mapx, mapy))) + g.addGrameObject(new Wall(getColor(new Coordinates(sx, sy))), new Coordinates(mapx, mapy)); sx++; } sx = 0; diff --git a/src/com/moomoohk/Grame/Basics/Spriteable.java b/src/com/moomoohk/Grame/Basics/Spriteable.java index 0e96cbe..495d9c5 100644 --- a/src/com/moomoohk/Grame/Basics/Spriteable.java +++ b/src/com/moomoohk/Grame/Basics/Spriteable.java @@ -5,7 +5,7 @@ import javax.imageio.ImageIO; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.GrameObject; public abstract class Spriteable extends GrameObject { diff --git a/src/com/moomoohk/Grame/Basics/Wall.java b/src/com/moomoohk/Grame/Basics/Wall.java index a4eb474..37ce8b4 100644 --- a/src/com/moomoohk/Grame/Basics/Wall.java +++ b/src/com/moomoohk/Grame/Basics/Wall.java @@ -2,7 +2,7 @@ import java.awt.Color; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.GrameObject; /** * Walls are ready to use {@link GrameObject}s which are supposed to represent ordinary walls. @@ -37,7 +37,7 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { } diff --git a/src/com/moomoohk/Grame/Basics/package-info.java b/src/com/moomoohk/Grame/Basics/package-info.java new file mode 100644 index 0000000..05a5817 --- /dev/null +++ b/src/com/moomoohk/Grame/Basics/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains some helpful classes which utilize the core. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.Basics; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Essentials/ColorLayer.java b/src/com/moomoohk/Grame/Core/ColorLayer.java similarity index 76% rename from src/com/moomoohk/Grame/Essentials/ColorLayer.java rename to src/com/moomoohk/Grame/Core/ColorLayer.java index b2c0032..885f5f1 100644 --- a/src/com/moomoohk/Grame/Essentials/ColorLayer.java +++ b/src/com/moomoohk/Grame/Core/ColorLayer.java @@ -1,12 +1,13 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.awt.Color; import java.io.Serializable; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; /** * ColorLayers provide an easy way to implement a color matrix. + * * @author Meshulam Silk * @version 1.0 * @since 2013-04-05 @@ -16,23 +17,29 @@ public class ColorLayer implements Serializable private static final long serialVersionUID = 4166643485256534497L; private Color[] colors; private int width, height; - + /** * Constructor - * @param width Width of ColorLayer - * @param height Height of ColorLayer + * + * @param width + * Width of ColorLayer + * @param height + * Height of ColorLayer */ public ColorLayer(int width, int height) { this.width = width; this.height = height; - this.colors=new Color[width*height]; + this.colors = new Color[width * height]; } /** * Sets the color of a place in this layer. - * @param pos {@link Coordinates} of place to set color. - * @param c Color to set. + * + * @param pos + * {@link Coordinates} of place to set color. + * @param c + * Color to set. */ public void setColor(Coordinates pos, Color c) { @@ -44,7 +51,9 @@ public void setColor(Coordinates pos, Color c) /** * Sets the color of all the places in this layer. - * @param c Color to set. + * + * @param c + * Color to set. */ public void setAll(Color c) { @@ -55,7 +64,9 @@ public void setAll(Color c) /** * Gets the color of a place in this layer. - * @param pos {@link Coordinates} of place. + * + * @param pos + * {@link Coordinates} of place. * @return The color of the place. */ public Color getColor(Coordinates pos) @@ -68,6 +79,7 @@ public Color getColor(Coordinates pos) /** * Returns the width of this layer. + * * @return The width of this layer. */ public int getWidth() @@ -77,18 +89,19 @@ public int getWidth() /** * Returns the height of this layer. + * * @return The height of this layer. */ public int getHeight() { return this.height; } - + /** * Prints the dimensions of this layer. */ public String toString() { - return this.width+"x"+this.height; + return this.width + "x" + this.height; } } diff --git a/src/com/moomoohk/Grame/commands/AddEntityAICommand.java b/src/com/moomoohk/Grame/Core/Commands/AddEntityAICommand.java similarity index 91% rename from src/com/moomoohk/Grame/commands/AddEntityAICommand.java rename to src/com/moomoohk/Grame/Core/Commands/AddEntityAICommand.java index c40b452..3b0f6b6 100644 --- a/src/com/moomoohk/Grame/commands/AddEntityAICommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/AddEntityAICommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class AddEntityAICommand extends Command @@ -65,7 +65,7 @@ public String getHelpMessage() @Override public String getUsage() { - return "addentityai "; + return "addentityai "; } @Override diff --git a/src/com/moomoohk/Grame/commands/AddGrameObjectCommand.java b/src/com/moomoohk/Grame/Core/Commands/AddGrameObjectCommand.java similarity index 65% rename from src/com/moomoohk/Grame/commands/AddGrameObjectCommand.java rename to src/com/moomoohk/Grame/Core/Commands/AddGrameObjectCommand.java index c776146..a48d59f 100644 --- a/src/com/moomoohk/Grame/commands/AddGrameObjectCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/AddGrameObjectCommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class AddGrameObjectCommand extends Command @@ -22,15 +22,15 @@ public boolean check(String[] params) this.outputColor = Color.red; return false; } - if (GrameManager.findBase(Integer.parseInt(params[1])) == null) + if (GrameManager.findGrid(Integer.parseInt(params[1])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } - if (!GrameManager.findBase(Integer.parseInt(params[1])).isInBase(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2])))) + if (!GrameManager.findGrid(Integer.parseInt(params[1])).isInGrid(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2])))) { - this.outputMessage = "Coordinates (" + params[1] + ", " + params[2] + ") are not in Base with ID:" + params[1]; + this.outputMessage = "Coordinates (" + params[1] + ", " + params[2] + ") are not in Grid with ID:" + params[1]; this.outputColor = Color.red; return false; } @@ -40,7 +40,7 @@ public boolean check(String[] params) @Override public void execute(String[] params) { - GrameManager.findBase(Integer.parseInt(params[1])).addGrameObject(GrameManager.findGrameObject(Integer.parseInt(params[0])), new Coordinates(Integer.parseInt(params[2]), Integer.parseInt(params[3]))); + GrameManager.findGrid(Integer.parseInt(params[1])).addGrameObject(GrameManager.findGrameObject(Integer.parseInt(params[0])), new Coordinates(Integer.parseInt(params[2]), Integer.parseInt(params[3]))); } @Override @@ -52,13 +52,13 @@ public String getCommand() @Override public String getHelpMessage() { - return "Adds a Grame Object to a Base"; + return "Adds a Grame Object to a Grid"; } @Override public String getUsage() { - return "addobject "; + return "addobject "; } @Override diff --git a/src/com/moomoohk/Grame/commands/ClearEntityAI.java b/src/com/moomoohk/Grame/Core/Commands/ClearEntityAI.java similarity index 93% rename from src/com/moomoohk/Grame/commands/ClearEntityAI.java rename to src/com/moomoohk/Grame/Core/Commands/ClearEntityAI.java index 1762af2..7b27f32 100644 --- a/src/com/moomoohk/Grame/commands/ClearEntityAI.java +++ b/src/com/moomoohk/Grame/Core/Commands/ClearEntityAI.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class ClearEntityAI extends Command diff --git a/src/com/moomoohk/Grame/commands/CreateEntityCommand.java b/src/com/moomoohk/Grame/Core/Commands/CreateEntityCommand.java similarity index 94% rename from src/com/moomoohk/Grame/commands/CreateEntityCommand.java rename to src/com/moomoohk/Grame/Core/Commands/CreateEntityCommand.java index ae8a8b4..8f60754 100644 --- a/src/com/moomoohk/Grame/commands/CreateEntityCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/CreateEntityCommand.java @@ -1,11 +1,11 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import java.util.HashMap; import com.moomoohk.Grame.Basics.DefaultRandomGen; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameUtils; +import com.moomoohk.Grame.Core.GrameUtils; import com.moomoohk.MooCommands.Command; import com.moomoohk.MooCommands.CommandsManager; diff --git a/src/com/moomoohk/Grame/commands/DrawCoordinatesCommand.java b/src/com/moomoohk/Grame/Core/Commands/DrawCoordinatesCommand.java similarity index 90% rename from src/com/moomoohk/Grame/commands/DrawCoordinatesCommand.java rename to src/com/moomoohk/Grame/Core/Commands/DrawCoordinatesCommand.java index 08a0bc7..f2ddb67 100644 --- a/src/com/moomoohk/Grame/commands/DrawCoordinatesCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/DrawCoordinatesCommand.java @@ -1,8 +1,8 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Graphics.RenderManager; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.MooCommands.Command; public class DrawCoordinatesCommand extends Command diff --git a/src/com/moomoohk/Grame/commands/isOccupiedCommand.java b/src/com/moomoohk/Grame/Core/Commands/IsOccupiedCommand.java similarity index 60% rename from src/com/moomoohk/Grame/commands/isOccupiedCommand.java rename to src/com/moomoohk/Grame/Core/Commands/IsOccupiedCommand.java index 1fa0f4d..a2d4ff7 100644 --- a/src/com/moomoohk/Grame/commands/isOccupiedCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/IsOccupiedCommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class IsOccupiedCommand extends Command @@ -18,41 +18,41 @@ public boolean check(String[] params) { if (GrameManager.findGrameObject(Integer.parseInt(params[0])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } - if (!GrameManager.findBase(Integer.parseInt(params[0])).isInBase(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2])))) + if (!GrameManager.findGrid(Integer.parseInt(params[0])).isInGrid(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2])))) { - this.outputMessage = "Coordinates (" + params[1] + ", " + params[2] + ") are not in Base ID:" + params[0]; + this.outputMessage = "Coordinates (" + params[1] + ", " + params[2] + ") are not in Grid ID:" + params[0]; this.outputColor = Color.red; return false; } - return super.check(params); + return true; } @Override public void execute(String[] params) { - this.outputMessage = "" + GrameManager.findBase(Integer.parseInt(params[0])).isOccupied(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2]))); + this.outputMessage = "" + GrameManager.findGrid(Integer.parseInt(params[0])).isOccupied(new Coordinates(Integer.parseInt(params[1]), Integer.parseInt(params[2]))); } @Override public String getCommand() { - return "isinbase"; + return "isoccupied"; } @Override public String getHelpMessage() { - return "Checks whether Coordinates in a Base are occupied by a Grame object"; + return "Checks whether Coordinates in a Grid are occupied by a Grame object"; } @Override public String getUsage() { - return "isoccupied "; + return "isoccupied "; } @Override diff --git a/src/com/moomoohk/Grame/commands/MakePlayerCommand.java b/src/com/moomoohk/Grame/Core/Commands/MakePlayerCommand.java similarity index 90% rename from src/com/moomoohk/Grame/commands/MakePlayerCommand.java rename to src/com/moomoohk/Grame/Core/Commands/MakePlayerCommand.java index 3575915..9c6f820 100644 --- a/src/com/moomoohk/Grame/commands/MakePlayerCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/MakePlayerCommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class MakePlayerCommand extends Command @@ -53,7 +53,7 @@ public String getHelpMessage() @Override public String getUsage() { - return "makeplayer "; + return "makeplayer "; } @Override diff --git a/src/com/moomoohk/Grame/commands/MoveGrameObjectCommand.java b/src/com/moomoohk/Grame/Core/Commands/MoveGrameObjectCommand.java similarity index 75% rename from src/com/moomoohk/Grame/commands/MoveGrameObjectCommand.java rename to src/com/moomoohk/Grame/Core/Commands/MoveGrameObjectCommand.java index 7dc8b9c..006ce9b 100644 --- a/src/com/moomoohk/Grame/commands/MoveGrameObjectCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/MoveGrameObjectCommand.java @@ -1,10 +1,10 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class MoveGrameObjectCommand extends Command @@ -23,19 +23,19 @@ public boolean check(String[] params) this.outputColor = Color.red; return false; } - if (GrameManager.findBase(Integer.parseInt(params[1])) == null) + if (GrameManager.findGrid(Integer.parseInt(params[1])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } - if (params.length == 3 && !GrameManager.findBase(Integer.parseInt(params[1])).isInBase(GrameManager.findGrameObject(Integer.parseInt(params[0])).getPos(Integer.parseInt(params[1])).addDir(new Dir(params[2])))) + if (params.length == 3 && !GrameManager.findGrid(Integer.parseInt(params[1])).isInGrid(GrameManager.findGrameObject(Integer.parseInt(params[0])).getPos(Integer.parseInt(params[1])).addDir(new Dir(params[2])))) { this.outputMessage = "Can't move there!"; this.outputColor = Color.red; return false; } - if (params.length == 4 && !GrameManager.findBase(Integer.parseInt(params[1])).isInBase(new Coordinates(Integer.parseInt(params[2]), Integer.parseInt(params[3])))) + if (params.length == 4 && !GrameManager.findGrid(Integer.parseInt(params[1])).isInGrid(new Coordinates(Integer.parseInt(params[2]), Integer.parseInt(params[3])))) { this.outputMessage = "Can't move there!"; this.outputColor = Color.red; @@ -68,7 +68,7 @@ public String getHelpMessage() @Override public String getUsage() { - return "move

"; + return "move "; } @Override diff --git a/src/com/moomoohk/Grame/commands/PrintEntityAICommand.java b/src/com/moomoohk/Grame/Core/Commands/PrintEntityAICommand.java similarity index 93% rename from src/com/moomoohk/Grame/commands/PrintEntityAICommand.java rename to src/com/moomoohk/Grame/Core/Commands/PrintEntityAICommand.java index 9ba0513..e6dc8f4 100644 --- a/src/com/moomoohk/Grame/commands/PrintEntityAICommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/PrintEntityAICommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class PrintEntityAICommand extends Command diff --git a/src/com/moomoohk/Grame/commands/QuitCommand.java b/src/com/moomoohk/Grame/Core/Commands/QuitCommand.java similarity index 92% rename from src/com/moomoohk/Grame/commands/QuitCommand.java rename to src/com/moomoohk/Grame/Core/Commands/QuitCommand.java index b5a912d..d4a957e 100644 --- a/src/com/moomoohk/Grame/commands/QuitCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/QuitCommand.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import com.moomoohk.MooCommands.Command; diff --git a/src/com/moomoohk/Grame/commands/RenderBaseCommand.java b/src/com/moomoohk/Grame/Core/Commands/RenderGridCommand.java similarity index 73% rename from src/com/moomoohk/Grame/commands/RenderBaseCommand.java rename to src/com/moomoohk/Grame/Core/Commands/RenderGridCommand.java index 8a24134..99dbec4 100644 --- a/src/com/moomoohk/Grame/commands/RenderBaseCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/RenderGridCommand.java @@ -1,15 +1,15 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Graphics.RenderManager; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.MooCommands.Command; -public class RenderBaseCommand extends Command +public class RenderGridCommand extends Command { - public RenderBaseCommand() + public RenderGridCommand() { super(); } @@ -31,7 +31,7 @@ public boolean check(String[] params) } if (GrameManager.findGrameObject(Integer.parseInt(params[0])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } @@ -53,13 +53,13 @@ public String getCommand() @Override public String getHelpMessage() { - return "Renders a base using a render in the Render list"; + return "Renders a grid using a render in the Render list"; } @Override public String getUsage() { - return "render "; + return "render "; } @Override diff --git a/src/com/moomoohk/Grame/commands/SetEntityOverrideAICommand.java b/src/com/moomoohk/Grame/Core/Commands/SetEntityOverrideAICommand.java similarity index 90% rename from src/com/moomoohk/Grame/commands/SetEntityOverrideAICommand.java rename to src/com/moomoohk/Grame/Core/Commands/SetEntityOverrideAICommand.java index 26cc26f..5ff58c4 100644 --- a/src/com/moomoohk/Grame/commands/SetEntityOverrideAICommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/SetEntityOverrideAICommand.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class SetEntityOverrideAICommand extends Command @@ -30,7 +30,7 @@ protected boolean check(String[] params) } if (GrameManager.findGrameObject(Integer.parseInt(params[0])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } @@ -75,7 +75,7 @@ public String getHelpMessage() @Override public String getUsage() { - return "setentityoverrideai "; + return "setentityoverrideai "; } @Override diff --git a/src/com/moomoohk/Grame/Core/Commands/SetSpeedCommand.java b/src/com/moomoohk/Grame/Core/Commands/SetSpeedCommand.java new file mode 100644 index 0000000..8b94cd6 --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Commands/SetSpeedCommand.java @@ -0,0 +1,68 @@ +package com.moomoohk.Grame.Core.Commands; + +import java.awt.Color; + +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.MooCommands.Command; + +public class SetSpeedCommand extends Command +{ + + public SetSpeedCommand() + { + super(); + } + + public boolean check(String[] params) + { + if (GrameManager.findGrameObject(Integer.parseInt(params[0])) == null) + { + this.outputMessage = "Grame Object with ID:" + params[0] + " does not exist!"; + this.outputColor = Color.red; + return false; + } + if (GrameManager.findGrid(Integer.parseInt(params[1])) == null) + { + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; + this.outputColor = Color.red; + return false; + } + return true; + } + + @Override + public void execute(String[] params) + { + GrameManager.findGrameObject(Integer.parseInt(params[0])).setSpeed(Integer.parseInt(params[1])); + } + + @Override + public String getCommand() + { + return "setspeed"; + } + + @Override + public String getHelpMessage() + { + return "Sets the speed of a specified Grame Object in a specified Grid"; + } + + @Override + public String getUsage() + { + return "setspeed "; + } + + @Override + public int getMaxParams() + { + return 2; + } + + @Override + public int getMinParams() + { + return 2; + } +} diff --git a/src/com/moomoohk/Grame/commands/SetSpriteCommand.java b/src/com/moomoohk/Grame/Core/Commands/SetSpriteCommand.java similarity index 96% rename from src/com/moomoohk/Grame/commands/SetSpriteCommand.java rename to src/com/moomoohk/Grame/Core/Commands/SetSpriteCommand.java index 2a132cd..268bf35 100644 --- a/src/com/moomoohk/Grame/commands/SetSpriteCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/SetSpriteCommand.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; import java.io.File; diff --git a/src/com/moomoohk/Grame/commands/setVisibleCommand.java b/src/com/moomoohk/Grame/Core/Commands/SetVisibleCommand.java similarity index 69% rename from src/com/moomoohk/Grame/commands/setVisibleCommand.java rename to src/com/moomoohk/Grame/Core/Commands/SetVisibleCommand.java index 2916376..57ffda4 100644 --- a/src/com/moomoohk/Grame/commands/setVisibleCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/SetVisibleCommand.java @@ -1,8 +1,8 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Graphics.RenderManager; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.MooCommands.Command; public class SetVisibleCommand extends Command @@ -15,17 +15,18 @@ public SetVisibleCommand() public boolean check(String[] params) { - try - { - Boolean.parseBoolean(params[0]); - } - catch (Exception e) - { - this.outputMessage = "Only true or false are accepted inputs!"; - this.outputColor = Color.red; - return false; - } - return super.check(params); + if (params.length > 0) + try + { + Boolean.parseBoolean(params[0]); + } + catch (Exception e) + { + this.outputMessage = "Only true or false are accepted inputs!"; + this.outputColor = Color.red; + return false; + } + return true; } @Override diff --git a/src/com/moomoohk/Grame/commands/SetWraparoundCommand.java b/src/com/moomoohk/Grame/Core/Commands/SetWraparoundCommand.java similarity index 74% rename from src/com/moomoohk/Grame/commands/SetWraparoundCommand.java rename to src/com/moomoohk/Grame/Core/Commands/SetWraparoundCommand.java index 57ca44f..e61a36a 100644 --- a/src/com/moomoohk/Grame/commands/SetWraparoundCommand.java +++ b/src/com/moomoohk/Grame/Core/Commands/SetWraparoundCommand.java @@ -1,8 +1,8 @@ -package com.moomoohk.Grame.commands; +package com.moomoohk.Grame.Core.Commands; import java.awt.Color; -import com.moomoohk.Grame.Essentials.GrameManager; +import com.moomoohk.Grame.Core.GrameManager; import com.moomoohk.MooCommands.Command; public class SetWraparoundCommand extends Command @@ -22,7 +22,7 @@ public boolean check(String[] params) } if (GrameManager.findGrameObject(Integer.parseInt(params[0])) == null) { - this.outputMessage = "Base with ID:" + params[1] + " does not exist!"; + this.outputMessage = "Grid with ID:" + params[1] + " does not exist!"; this.outputColor = Color.red; return false; } @@ -32,7 +32,7 @@ public boolean check(String[] params) @Override public void execute(String[] params) { - GrameManager.findBase(Integer.parseInt(params[0])).setWraparound(Boolean.parseBoolean(params[1])); + GrameManager.findGrid(Integer.parseInt(params[0])).setWraparound(Boolean.parseBoolean(params[1])); } @Override @@ -44,13 +44,13 @@ public String getCommand() @Override public String getHelpMessage() { - return "Sets whether the specified Base supports wraparound"; + return "Sets whether the specified Grid supports wraparound"; } @Override public String getUsage() { - return "setwraparound "; + return "setwraparound "; } @Override diff --git a/src/com/moomoohk/Grame/Core/Commands/ShowDialogCommand.java b/src/com/moomoohk/Grame/Core/Commands/ShowDialogCommand.java new file mode 100644 index 0000000..3b1cd33 --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Commands/ShowDialogCommand.java @@ -0,0 +1,51 @@ +package com.moomoohk.Grame.Core.Commands; + +import java.util.ArrayList; + +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.test.Dialog; +import com.moomoohk.MooCommands.Command; + +public class ShowDialogCommand extends Command +{ + + @Override + public String getCommand() + { + return "dialog"; + } + + @Override + public String getHelpMessage() + { + return "DEBUG: Prints some dialog on a specified Grame Object"; + } + + @Override + public String getUsage() + { + return "dialog "; + } + + @Override + public int getMaxParams() + { + return 1; + } + + @Override + public int getMinParams() + { + return 1; + } + + @Override + protected void execute(String[] params) + { + ArrayList lines = new ArrayList(); + lines.add("My name is Inigo Montoya"); + lines.add("You killed my father"); + lines.add("Prepare to die"); + new Dialog(lines, 5000, GrameManager.findGrameObject(Integer.parseInt(params[0]))).start(); + } +} diff --git a/src/com/moomoohk/Grame/Core/Commands/package-info.java b/src/com/moomoohk/Grame/Core/Commands/package-info.java new file mode 100644 index 0000000..672e729 --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Commands/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains commands for the console. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.Core.Commands; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Essentials/Coordinates.java b/src/com/moomoohk/Grame/Core/Coordinates.java similarity index 72% rename from src/com/moomoohk/Grame/Essentials/Coordinates.java rename to src/com/moomoohk/Grame/Core/Coordinates.java index f19e869..fdeb7ef 100644 --- a/src/com/moomoohk/Grame/Essentials/Coordinates.java +++ b/src/com/moomoohk/Grame/Core/Coordinates.java @@ -1,10 +1,9 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.io.Serializable; import java.util.ArrayList; import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Interfaces.GrameObject; /** * This class massively simplifies the way coordinates are processed. @@ -121,30 +120,30 @@ public String toString() } /** - * Will return an Coordinates[] which contains all the sets of coordinates which are adjacent to this set in a certain {@link Base} and are also in that same {@link Base}. + * Will return an Coordinates[] which contains all the sets of coordinates which are adjacent to this set in a certain {@link Grid} and are also in that same {@link Grid}. * - * @param b - * The {@link Base} in which to check. - * @return An array containing all the sets of coordinates which are adjacent to this set in a certain {@link Base} and are also in that same {@link Base}. + * @param g + * The {@link Grid} in which to check. + * @return An array containing all the sets of coordinates which are adjacent to this set in a certain {@link Grid} and are also in that same {@link Grid}. */ - public Coordinates[] getSurrounding(Base b) + public Coordinates[] getSurrounding(Grid g) { ArrayList sur = new ArrayList(); - if (b.isInBase(this.addDir(Dir.UP)) && !b.isOccupied(this.addDir(Dir.UP))) + if (g.isInGrid(this.addDir(Dir.UP)) && !g.isOccupied(this.addDir(Dir.UP))) sur.add(this.addDir(Dir.UP)); - if (b.isInBase(this.addDir(Dir.DOWN)) && !b.isOccupied(this.addDir(Dir.DOWN))) + if (g.isInGrid(this.addDir(Dir.DOWN)) && !g.isOccupied(this.addDir(Dir.DOWN))) sur.add(this.addDir(Dir.DOWN)); - if (b.isInBase(this.addDir(Dir.LEFT)) && !b.isOccupied(this.addDir(Dir.LEFT))) + if (g.isInGrid(this.addDir(Dir.LEFT)) && !g.isOccupied(this.addDir(Dir.LEFT))) sur.add(this.addDir(Dir.LEFT)); - if (b.isInBase(this.addDir(Dir.RIGHT)) && !b.isOccupied(this.addDir(Dir.RIGHT))) + if (g.isInGrid(this.addDir(Dir.RIGHT)) && !g.isOccupied(this.addDir(Dir.RIGHT))) sur.add(this.addDir(Dir.RIGHT)); - if (b.isInBase(this.addDir(new Dir(1, 1))) && !b.isOccupied(this.addDir(new Dir(1, 1)))) + if (g.isInGrid(this.addDir(new Dir(1, 1))) && !g.isOccupied(this.addDir(new Dir(1, 1)))) sur.add(this.addDir(new Dir(1, 1))); - if (b.isInBase(this.addDir(new Dir(-1, 1))) && !b.isOccupied(this.addDir(new Dir(-1, 1)))) + if (g.isInGrid(this.addDir(new Dir(-1, 1))) && !g.isOccupied(this.addDir(new Dir(-1, 1)))) sur.add(this.addDir(new Dir(-1, 1))); - if (b.isInBase(this.addDir(new Dir(1, -1))) && !b.isOccupied(this.addDir(new Dir(1, -1)))) + if (g.isInGrid(this.addDir(new Dir(1, -1))) && !g.isOccupied(this.addDir(new Dir(1, -1)))) sur.add(this.addDir(new Dir(1, -1))); - if (b.isInBase(this.addDir(new Dir(-1, -1))) && !b.isOccupied(this.addDir(new Dir(-1, -1)))) + if (g.isInGrid(this.addDir(new Dir(-1, -1))) && !g.isOccupied(this.addDir(new Dir(-1, -1)))) sur.add(this.addDir(new Dir(-1, -1))); Coordinates[] temp = new Coordinates[sur.size()]; for (int i = 0; i < sur.size(); i++) @@ -153,29 +152,29 @@ public Coordinates[] getSurrounding(Base b) } /** - * Will return an Coordinates[] which contains all the sets of coordinates which are adjacent to this set in a certain {@link Base} but are not necessarily in that same {@link Base}. + * Will return an Coordinates[] which contains all the sets of coordinates which are adjacent to this set in a certain {@link Grid} but are not necessarily in that same {@link Grid}. * - * @param b - * The {@link Base} in which to check. - * @return An array containing all the sets of coordinates which are adjacent to this set in a certain {@link Base} but are not necessarily in that same {@link Base}. + * @param g + * The {@link Grid} in which to check. + * @return An array containing all the sets of coordinates which are adjacent to this set in a certain {@link Grid} but are not necessarily in that same {@link Grid}. */ - public Coordinates[] getAllSurrounding(Base b) + public Coordinates[] getAllSurrounding(Grid g) { return new Coordinates[] { this.addDir(Dir.UP), this.addDir(Dir.LEFT), this.addDir(Dir.RIGHT), this.addDir(Dir.DOWN), this.addDir(new Dir(1, 1)), this.addDir(new Dir(-1, 1)), this.addDir(new Dir(1, -1)), this.addDir(new Dir(-1, -1)) }; } /** - * Checks whether all the adjacent sets of coordinates contain a {@link GrameObject} in a certain {@link Base}. + * Checks whether all the adjacent sets of coordinates contain a {@link GrameObject} in a certain {@link Grid}. * - * @param b - * {@link Base} in which to check. + * @param g + * {@link Grid} in which to check. * @return True if all the adjacent sets of coordinates contain a {@link GrameObject}, else false. */ - public boolean isSurrounded(Base b) + public boolean isSurrounded(Grid g) { - Coordinates[] sur = getSurrounding(b); + Coordinates[] sur = getSurrounding(g); for (Coordinates pos : sur) - if (!b.isOccupied(pos)) + if (!g.isOccupied(pos)) return false; return true; } diff --git a/src/com/moomoohk/Grame/Essentials/CrashManager.java b/src/com/moomoohk/Grame/Core/CrashManager.java similarity index 99% rename from src/com/moomoohk/Grame/Essentials/CrashManager.java rename to src/com/moomoohk/Grame/Core/CrashManager.java index d3b438a..06b3ca2 100644 --- a/src/com/moomoohk/Grame/Essentials/CrashManager.java +++ b/src/com/moomoohk/Grame/Core/CrashManager.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.awt.Dimension; import java.awt.EventQueue; @@ -37,7 +37,7 @@ import javax.swing.JTextPane; import javax.swing.KeyStroke; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; /** * Manages crashes and exceptions. diff --git a/src/com/moomoohk/Grame/Core/EngineState.java b/src/com/moomoohk/Grame/Core/EngineState.java new file mode 100644 index 0000000..3353ebd --- /dev/null +++ b/src/com/moomoohk/Grame/Core/EngineState.java @@ -0,0 +1,163 @@ +package com.moomoohk.Grame.Core; + +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +/** + * Represents the state of the engine. Used for saving games. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +public class EngineState implements Serializable +{ + private static final long serialVersionUID = 374960940802675271L; + + private ArrayList grids; + private ArrayList grameObjects; + private Calendar dateCreated; + private Date dateSaved; + private int mainGrid; + private Render mainRender; + + /** + * Constructor + */ + public EngineState() + { + this.grids = new ArrayList(); + this.grameObjects = new ArrayList(); + this.dateCreated = new GregorianCalendar(); + this.mainGrid = -1; + this.mainRender = null; + } + + /** + * Adds a {@link GrameObject} to the list of {@link GrameObject}s this state is tracking. + * + * @param go + * {@link GrameObject} to add + */ + public void addGrameObject(GrameObject go) + { + this.grameObjects.add(go); + } + + /** + * Adds a {@link Grid} to the list of {@link Grid}s this state is tracking. + * + * @param g + * {@link Grid} to add + */ + public void addGrid(Grid g) + { + this.grids.add(g); + } + + /** + * Sets the main {@link Grid} of this state. + * + * @param gID + * {@link Grid} to make main + */ + public void setMainGrid(int gID) + { + this.mainGrid = gID; + } + + /** + * Sets the main {@link Render} of this state. + * + * @param r + * {@link Render} to make main + */ + public void setMainRender(Render r) + { + this.mainRender = r; + } + + /** + * Sets the date of the saving of this state. + * + * @param d + * Date to set + */ + public void setSaved(Date d) + { + this.dateSaved = d; + } + + /** + * Gets the list of {@link Grid}s that this state is tracking. + * + * @return A list of {@link Grid}s that this state is tracking + */ + public ArrayList getGrids() + { + return this.grids; + } + + /** + * Gets the list of {@link GrameObject}s that this state is tracking. + * + * @return A list of {@link GrameObject}s that this state is tracking + */ + public ArrayList getGrameObjects() + { + return this.grameObjects; + } + + /** + * Gets the date of this state's creation. + * + * @return The date of this state's creation + */ + public Calendar getDateCreated() + { + return dateCreated; + } + + /** + * Gets the {@link Grid#ID} of the main {@link Grid} of this state. + * + * @return The {@link Grid#ID} of the main {@link Grid} of this state + */ + public int getMainGrid() + { + return this.mainGrid; + } + + /** + * Gets the main {@link Render} of this state. + * + * @return The main {@link Render} of this state + */ + public Render getMainRender() + { + return this.mainRender; + } + + /** + * Gets the date of this state's last save. + * + * @return The date of this state's last save + */ + public Date getSaved() + { + return this.dateSaved; + } + + /** + * Gets some human readable info about this state. + * + * @return Some human readable info about this state + */ + public String details() + { + return "Grids: " + this.grids.size() + ", GrameObjects: " + this.grameObjects.size() + ", Date Created: " + new SimpleDateFormat("hh:mm:ss dd/MM/yyyy").format(dateCreated.getTime()) + ", Main Grid: " + this.mainGrid + ", Main Render: " + this.mainRender; + } +} diff --git a/src/com/moomoohk/Grame/Essentials/GrameManager.java b/src/com/moomoohk/Grame/Core/GrameManager.java similarity index 94% rename from src/com/moomoohk/Grame/Essentials/GrameManager.java rename to src/com/moomoohk/Grame/Core/GrameManager.java index 8666d33..cb86113 100644 --- a/src/com/moomoohk/Grame/Essentials/GrameManager.java +++ b/src/com/moomoohk/Grame/Core/GrameManager.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.awt.Color; import java.awt.Component; @@ -42,13 +42,10 @@ import javax.swing.border.EmptyBorder; import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; -import com.moomoohk.Grame.Graphics.GridRender; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.Interfaces.MainGrameClass; -import com.moomoohk.Grame.Interfaces.MovementAI; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Basics.MovementAI; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.Graphics.DefaultGridRender; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.Grame.test.MenuConfiguration; import com.moomoohk.Mootilities.FileUtils.FileUtils; import com.moomoohk.Mootilities.FrameDragger.FrameDragger; @@ -59,7 +56,7 @@ /** * The Grame Manager takes care of all the internal Grame operations. *

- * Indexes and ticks any {@link GrameObject}s and {@link Base}s that are created automatically. + * Indexes and ticks any {@link GrameObject}s and {@link Grid}s that are created automatically. * * @author Meshulam Silk * @version 1.0 @@ -70,7 +67,7 @@ public class GrameManager implements Runnable /** * The Grame version number. */ - public static final String VERSION_NUMBER = "4.0.3"; + public static final String VERSION_NUMBER = "4.1"; /** * The WASD keys parsed to a {@link Dir}. */ @@ -96,7 +93,7 @@ public class GrameManager implements Runnable private static InputHandler input; private static Thread thread; private static int fps = 0; - private static Render defaultRender = new GridRender(); + private static Render defaultRender = new DefaultGridRender(); private static File savePath; private static MainMenu mainMenu; private static MenuConfiguration menuConfiguration; @@ -206,7 +203,7 @@ public void run() { tick(input.key); tickGrameObjects(); - tickBases(); + tickGrids(); } RenderManager.tick(); } @@ -275,10 +272,10 @@ private static void tickGrameObjects() GrameObject go = engineState.getGrameObjects().get(i); if (go == null) continue; - if (engineState.getBases() != null) - for (int bID = 0; bID < engineState.getBases().size(); bID++) - if (findBase(bID).containsGrameObject(go.ID) && go.getSpeed() != 0 && time % go.getSpeed() == 0 && !go.isPaused()) - go.tick(bID); + if (engineState.getGrids() != null) + for (int gID = 0; gID < engineState.getGrids().size(); gID++) + if (findGrid(gID).containsGrameObject(go.ID) && go.getSpeed() != 0 && time % go.getSpeed() == 0 && !go.isPaused()) + go.tick(gID); } } catch (Exception e) @@ -287,19 +284,19 @@ private static void tickGrameObjects() } } - private static void tickBases() + private static void tickGrids() { - if (engineState.getBases() == null) + if (engineState.getGrids() == null) return; - synchronized (engineState.getBases()) + synchronized (engineState.getGrids()) { try { - for (Base b : engineState.getBases()) + for (Grid g : engineState.getGrids()) { - if (b == null) + if (g == null) continue; - b.tick(); + g.tick(); } } catch (Exception e) @@ -310,18 +307,18 @@ private static void tickBases() } /** - * Disposes of all the {@link GrameObject}s and {@link Base}s. + * Disposes of all the {@link GrameObject}s and {@link Grid}s. */ public static void disposeAll() { - GrameUtils.print("Disposing of all the Bases in the Base list...", MessageLevel.NORMAL); + GrameUtils.print("Disposing of all the Grids in the Grid list...", MessageLevel.NORMAL); if (engineState != null) - for (int i = 0; i < engineState.getBases().size(); i++) + for (int i = 0; i < engineState.getGrids().size(); i++) { - GrameUtils.print("Disposing of " + engineState.getBases().get(i).ID, MessageLevel.NORMAL); - engineState.getBases().remove(i); + GrameUtils.print("Disposing of " + engineState.getGrids().get(i).ID, MessageLevel.NORMAL); + engineState.getGrids().remove(i); } - GrameUtils.print("Done disposing of Bases.", MessageLevel.NORMAL); + GrameUtils.print("Done disposing of Grids.", MessageLevel.NORMAL); } /** @@ -351,29 +348,29 @@ public static int add(GrameObject go) } /** - * Adds a {@link Base} to the Base list. + * Adds a {@link Grid} to the Grid list. *

* The user should never have to call this method. * - * @param b - * {@link Base} to add. - * @return The ID number for the Base. + * @param g + * {@link Grid} to add. + * @return The ID number for the Grid. */ - public static int add(Base b) + public static int add(Grid g) { if (!initialized) { - System.out.println("FATAL: Grame Manager not initialized! All Base instantiations should be made from in the newGame method."); + System.out.println("FATAL: Grame Manager not initialized! All Grid instantiations should be made in the newGame method."); System.exit(0); } - if (engineState.getBases().contains(b)) + if (engineState.getGrids().contains(g)) { - GrameUtils.print(b.toString() + " already exists in the Grame Object list!", MessageLevel.ERROR); + GrameUtils.print(g.toString() + " already exists in the Grame Object list!", MessageLevel.ERROR); return -1; } - engineState.getBases().add(b); - GrameUtils.print("Added a Base to the Base list (ID:" + (engineState.getBases().size() - 1) + ")", MessageLevel.NORMAL); - return engineState.getBases().size() - 1; + engineState.getGrids().add(g); + GrameUtils.print("Added a Grid to the Grid list (ID:" + (engineState.getGrids().size() - 1) + ")", MessageLevel.NORMAL); + return engineState.getGrids().size() - 1; } /** @@ -399,22 +396,22 @@ public static GrameObject findGrameObject(int id) } /** - * Finds and returns a {@link Base} from the Base list.
- * If the {@link Base} is not found, null will be returned. + * Finds and returns a {@link Grid} from the Grid list.
+ * If the {@link Grid} is not found, null will be returned. * * @param id - * The ID of the {@link Base} to find. - * @return The {@link Base} with that ID. If not in the list, null will be returned. + * The ID of the {@link Grid} to find. + * @return The {@link Grid} with that ID. If not in the list, null will be returned. */ - public static Base findBase(int id) + public static Grid findGrid(int id) { try { - return engineState.getBases().get(id); + return engineState.getGrids().get(id); } catch (Exception e) { - GrameUtils.print("Base with ID:" + id + " not found! Returning null instead.", MessageLevel.ERROR); + GrameUtils.print("Grid with ID:" + id + " not found! Returning null instead.", MessageLevel.ERROR); } return null; } @@ -601,9 +598,9 @@ public static int getObjectListLength() return engineState.getGrameObjects().size(); } - public static int getBaseListLength() + public static int getGridListLength() { - return engineState.getBases().size(); + return engineState.getGrids().size(); } /** @@ -616,14 +613,14 @@ public static int getFPS() return fps; } - public static void setMainBase(int bID) + public static void setMainGrid(int gID) { - engineState.setMainBase(bID); + engineState.setMainGrid(gID); } - public static int getMainBase() + public static int getMainGrid() { - return engineState.getMainBase(); + return engineState.getMainGrid(); } public static void setMainRender(Render r) @@ -1126,7 +1123,7 @@ protected void confirm() RenderManager.initialize(); RenderManager.clearAllText(); engineState = saves.get(selectedEngineStateName); - RenderManager.render(engineState.getMainBase(), engineState.getMainRender()); + RenderManager.render(engineState.getMainGrid(), engineState.getMainRender()); RenderManager.setVisible(true); start(); paused = false; diff --git a/src/com/moomoohk/Grame/Interfaces/GrameObject.java b/src/com/moomoohk/Grame/Core/GrameObject.java similarity index 71% rename from src/com/moomoohk/Grame/Interfaces/GrameObject.java rename to src/com/moomoohk/Grame/Core/GrameObject.java index 20164a8..101e262 100644 --- a/src/com/moomoohk/Grame/Interfaces/GrameObject.java +++ b/src/com/moomoohk/Grame/Core/GrameObject.java @@ -1,17 +1,13 @@ -package com.moomoohk.Grame.Interfaces; +package com.moomoohk.Grame.Core; import java.awt.Color; import java.io.Serializable; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameObjectLayer; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; /** - * Grame Objects are objects which are placed in {@link Base}s. + * Grame Objects are objects which are placed in {@link Grid}s. + * * @author Meshulam Silk * @version 1.0 * @since 2013-04-05 @@ -137,34 +133,34 @@ public boolean isPaused() } /** - * Gets the position of this object in a certain {@link Base}.
- * If this object doesn't exist in the {@link Base} null will be returned. + * Gets the position of this object in a certain {@link Grid}.
+ * If this object doesn't exist in the {@link Grid} null will be returned. * - * @param bID - * {@link Base#ID} of {@link Base}. - * @return {@link Coordinates} of this object in the {@link Base}. If this object isn't in the {@link Base}, null will be returned. + * @param gID + * {@link Grid#ID} of {@link Grid}. + * @return {@link Coordinates} of this object in the {@link Grid}. If this object isn't in the {@link Grid}, null will be returned. */ - public Coordinates getPos(int bID) + public Coordinates getPos(int gID) { - if (GrameManager.findBase(bID).containsGrameObject(ID)) - return GrameManager.findBase(bID).getGrameObjectPos(ID); - GrameUtils.print("Base with ID:" + bID + " does not contain Entity with ID:" + ID + ". Returning null.", MessageLevel.ERROR); + if (GrameManager.findGrid(gID).containsGrameObject(ID)) + return GrameManager.findGrid(gID).getGrameObjectPos(ID); + GrameUtils.print("Grid with ID:" + gID + " does not contain Entity with ID:" + ID + ". Returning null.", MessageLevel.ERROR); return null; } /** - * Sets the position of this object in a certain {@link Base}. + * Sets the position of this object in a certain {@link Grid}. * - * @param bID - * {@link Base#ID} of {@link Base}. + * @param gID + * {@link Grid#ID} of {@link Grid}. * @param pos * New position to set. */ - public void setPos(int bID, Coordinates pos) + public void setPos(int gID, Coordinates pos) { - if (GrameManager.findBase(bID).containsGrameObject(ID)) + if (GrameManager.findGrid(gID).containsGrameObject(ID)) { - GrameManager.findBase(bID).moveGrameObject(ID, pos); + GrameManager.findGrid(gID).moveGrameObject(ID, pos); return; } } @@ -185,10 +181,10 @@ public void setPos(int bID, Coordinates pos) *

* Users will never need to call this method (The {@link GrameManager} takes care of ticking everything). * - * @param bID - * The {@link Base#ID} of the {@link Base} in which to tick. + * @param gID + * The {@link Grid#ID} of the {@link Grid} in which to tick. */ - public abstract void tick(int bID); + public abstract void tick(int gID); /** * This method gets called if this object is collidable and it tries to occupy the position of a non collidable object. diff --git a/src/com/moomoohk/Grame/Essentials/GrameObjectLayer.java b/src/com/moomoohk/Grame/Core/GrameObjectLayer.java similarity index 95% rename from src/com/moomoohk/Grame/Essentials/GrameObjectLayer.java rename to src/com/moomoohk/Grame/Core/GrameObjectLayer.java index 23104a9..c693284 100644 --- a/src/com/moomoohk/Grame/Essentials/GrameObjectLayer.java +++ b/src/com/moomoohk/Grame/Core/GrameObjectLayer.java @@ -1,9 +1,8 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.io.Serializable; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; /** * GrameObjectLayers provide an easy way to store {@link GrameObject}s. diff --git a/src/com/moomoohk/Grame/Essentials/GrameUtils.java b/src/com/moomoohk/Grame/Core/GrameUtils.java similarity index 88% rename from src/com/moomoohk/Grame/Essentials/GrameUtils.java rename to src/com/moomoohk/Grame/Core/GrameUtils.java index 00e33c0..b449046 100644 --- a/src/com/moomoohk/Grame/Essentials/GrameUtils.java +++ b/src/com/moomoohk/Grame/Core/GrameUtils.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.awt.Color; import java.awt.Cursor; @@ -28,28 +28,28 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; -import com.moomoohk.Grame.AI.AStarPathfindingMovementAI; -import com.moomoohk.Grame.AI.PlayerMovementAI; -import com.moomoohk.Grame.AI.PlayerSimAI; -import com.moomoohk.Grame.AI.SimpleChaseAI; -import com.moomoohk.Grame.AI.SimpleStrollAI; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.commands.AddEntityAICommand; -import com.moomoohk.Grame.commands.AddGrameObjectCommand; -import com.moomoohk.Grame.commands.ClearEntityAI; -import com.moomoohk.Grame.commands.CreateEntityCommand; -import com.moomoohk.Grame.commands.DrawCoordinatesCommand; -import com.moomoohk.Grame.commands.IsOccupiedCommand; -import com.moomoohk.Grame.commands.MakePlayerCommand; -import com.moomoohk.Grame.commands.MoveGrameObjectCommand; -import com.moomoohk.Grame.commands.PrintEntityAICommand; -import com.moomoohk.Grame.commands.QuitCommand; -import com.moomoohk.Grame.commands.RenderBaseCommand; -import com.moomoohk.Grame.commands.SetEntityOverrideAICommand; -import com.moomoohk.Grame.commands.SetSpeedCommand; -import com.moomoohk.Grame.commands.SetSpriteCommand; -import com.moomoohk.Grame.commands.SetVisibleCommand; -import com.moomoohk.Grame.commands.SetWraparoundCommand; +import com.moomoohk.Grame.Basics.AI.AStarPathfindingMovementAI; +import com.moomoohk.Grame.Basics.AI.PlayerMovementAI; +import com.moomoohk.Grame.Basics.AI.PlayerSimAI; +import com.moomoohk.Grame.Basics.AI.SimpleChaseAI; +import com.moomoohk.Grame.Basics.AI.SimpleStrollAI; +import com.moomoohk.Grame.Core.Commands.AddEntityAICommand; +import com.moomoohk.Grame.Core.Commands.AddGrameObjectCommand; +import com.moomoohk.Grame.Core.Commands.ClearEntityAI; +import com.moomoohk.Grame.Core.Commands.CreateEntityCommand; +import com.moomoohk.Grame.Core.Commands.DrawCoordinatesCommand; +import com.moomoohk.Grame.Core.Commands.IsOccupiedCommand; +import com.moomoohk.Grame.Core.Commands.MakePlayerCommand; +import com.moomoohk.Grame.Core.Commands.MoveGrameObjectCommand; +import com.moomoohk.Grame.Core.Commands.PrintEntityAICommand; +import com.moomoohk.Grame.Core.Commands.QuitCommand; +import com.moomoohk.Grame.Core.Commands.RenderGridCommand; +import com.moomoohk.Grame.Core.Commands.SetEntityOverrideAICommand; +import com.moomoohk.Grame.Core.Commands.SetSpeedCommand; +import com.moomoohk.Grame.Core.Commands.SetSpriteCommand; +import com.moomoohk.Grame.Core.Commands.SetVisibleCommand; +import com.moomoohk.Grame.Core.Commands.SetWraparoundCommand; +import com.moomoohk.Grame.Core.Commands.ShowDialogCommand; import com.moomoohk.MooCommands.CommandsManager; import com.moomoohk.MooConsole.Console; import com.moomoohk.MooConsole.HelpCommand; @@ -191,13 +191,13 @@ public static Color randomColor() } /** - * Will generate a random set of {@link Coordinates} which exist in the given {@link Base}. + * Will generate a random set of {@link Coordinates} which exist in the given {@link Grid}. * * @param b - * The {@link Base} in which to get {@link Coordinates}. - * @return A random set of {@link Coordinates} which exist in the given {@link Base}. + * The {@link Grid} in which to get {@link Coordinates}. + * @return A random set of {@link Coordinates} which exist in the given {@link Grid}. */ - public static Coordinates randomCoordinates(Base b) + public static Coordinates randomCoordinates(Grid b) { return new Coordinates(new Random().nextInt(b.getColumns()), new Random().nextInt(b.getRows())); } @@ -465,7 +465,7 @@ private static void loadBasicCommands() new HelpCommand(); new SetVisibleCommand(); new MoveGrameObjectCommand(); - new RenderBaseCommand(); + new RenderGridCommand(); new QuitCommand(); new CreateEntityCommand(); new AddGrameObjectCommand(); @@ -479,6 +479,7 @@ private static void loadBasicCommands() new SetSpeedCommand(); new SetSpriteCommand(); new SetWraparoundCommand(); + new ShowDialogCommand(); print("Loaded " + (CommandsManager.getAllCommands().size() - prevLength) + " commands.", MessageLevel.DEBUG); } diff --git a/src/com/moomoohk/Grame/Core/Graphics/CleanGridRender.java b/src/com/moomoohk/Grame/Core/Graphics/CleanGridRender.java new file mode 100644 index 0000000..7ce37ff --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Graphics/CleanGridRender.java @@ -0,0 +1,47 @@ +package com.moomoohk.Grame.Core.Graphics; + +import java.io.Serializable; + +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Render; + +/** + * Renders {@link Grid}s in a grid without grouting lines. + * + * @author Meshulam Silk + * @version 1.0 + * @since 2013-04-05 + */ +public class CleanGridRender implements Render, Serializable +{ + private static final long serialVersionUID = 1269305794830678142L; + + public int[] getPixels(int[] pixels, Grid b, int width, int height) + { + for (int x = 0; x < width; x++) + for (int y = 0; y < height; y++) + { + Coordinates currSquare = new Coordinates((x) / ((width) / (b.getColumns())), (y) / (height / b.getRows())); + if (currSquare.getX() >= b.getColumns()) + currSquare.setX(b.getColumns() - 1); + if (currSquare.getY() >= b.getRows()) + currSquare.setY(b.getRows() - 1); + if (b.isInGrid(currSquare)) + try + { + pixels[x + y * width] = b.getColor(currSquare).getRGB(); + } + catch (Exception e) + { + System.out.println(x + " " + width); + } + } + return pixels; + } + + public String getName() + { + return "Clean_grid_render"; + } +} diff --git a/src/com/moomoohk/Grame/Graphics/GridRender.java b/src/com/moomoohk/Grame/Core/Graphics/DefaultGridRender.java similarity index 71% rename from src/com/moomoohk/Grame/Graphics/GridRender.java rename to src/com/moomoohk/Grame/Core/Graphics/DefaultGridRender.java index be97beb..b39cf3a 100644 --- a/src/com/moomoohk/Grame/Graphics/GridRender.java +++ b/src/com/moomoohk/Grame/Core/Graphics/DefaultGridRender.java @@ -1,44 +1,40 @@ -package com.moomoohk.Grame.Graphics; +package com.moomoohk.Grame.Core.Graphics; import java.awt.Color; import java.io.Serializable; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Render; /** - * Render {@link Base}s in a grid with grouting lines. + * Render {@link Grid}s in a grid with grouting lines. * * @author Meshulam Silk * @version 1.0 * @since 2013-04-05 */ -public class GridRender implements Render, Serializable +public class DefaultGridRender implements Render, Serializable { private static final long serialVersionUID = 2057716349989082233L; - public int[] getPixels(int[] pixels, Base b, int width, int height) + public int[] getPixels(int[] pixels, Grid b, int width, int height) { for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int squareW = (width) / (b.getColumns()), squareH = (height / b.getRows()); - if(squareH==0) + if (squareH == 0) { - pixels[x+y*width]=Color.black.getRGB(); + pixels[x + y * width] = Color.black.getRGB(); continue; } int pixelX = (x) / (squareW), pixelY = y / squareH; Coordinates currSquare = new Coordinates(pixelX, pixelY); - if (b.isInBase(currSquare)) - { + if (b.isInGrid(currSquare)) pixels[x + y * width] = b.getColor(currSquare).getRGB(); - } if (x % (width / b.getColumns()) == 0 || (x + 1) % (width / b.getColumns()) == 0 || y % (height / b.getRows()) == 0 || (y + 1) % (height / b.getRows()) == 0) - { pixels[x + y * width] = Color.black.getRGB(); - } /*else { int squareW = (width) / (b.getColumns()), squareH = (height / b.getRows()); @@ -57,7 +53,7 @@ public int[] getPixels(int[] pixels, Base b, int width, int height) public String getName() { - return "Grid_render"; + return "Default_grid_render"; } } diff --git a/src/com/moomoohk/Grame/Core/Graphics/GaussianFilter.java b/src/com/moomoohk/Grame/Core/Graphics/GaussianFilter.java new file mode 100644 index 0000000..684dcbf --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Graphics/GaussianFilter.java @@ -0,0 +1,127 @@ +package com.moomoohk.Grame.Core.Graphics; + +import java.awt.image.BufferedImage; +import java.awt.image.Kernel; + +public class GaussianFilter +{ + protected Kernel kernel; + + public GaussianFilter() + { + setRadius(6.0f); + } + + public void setRadius(float radius) + { + kernel = makeKernel(radius); + } + + public BufferedImage filter(BufferedImage src) + { + int width = src.getWidth(); + int height = src.getHeight(); + + int[] inPixels = new int[width * height]; + int[] outPixels = new int[width * height]; + src.getRGB(0, 0, width, height, inPixels, 0, width); + + convolveAndTranspose(kernel, inPixels, outPixels, width, height, true, 1); + convolveAndTranspose(kernel, outPixels, inPixels, height, width, true, 1); + + BufferedImage temp = src; + temp.setRGB(0, 0, width, height, inPixels, 0, width); + return temp; + } + + public static void convolveAndTranspose(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) + { + float[] matrix = kernel.getKernelData(null); + int cols = kernel.getWidth(); + int cols2 = cols / 2; + + for (int y = 0; y < height; y++) + { + int index = y; + int ioffset = y * width; + for (int x = 0; x < width; x++) + { + float r = 0, g = 0, b = 0, a = 0; + int moffset = cols2; + for (int col = -cols2; col <= cols2; col++) + { + float f = matrix[moffset + col]; + + if (f != 0) + { + int ix = x + col; + if (ix < 0) + { + if (edgeAction == 1) + ix = 0; + } + else + if (ix >= width) + { + if (edgeAction == 1) + ix = width - 1; + } + int rgb = inPixels[ioffset + ix]; + a += f * ((rgb >> 24) & 0xff); + r += f * ((rgb >> 16) & 0xff); + g += f * ((rgb >> 8) & 0xff); + b += f * (rgb & 0xff); + } + } + int ia = alpha ? clamp((int) (a + 0.5)) : 0xff; + int ir = clamp((int) (r + 0.5)); + int ig = clamp((int) (g + 0.5)); + int ib = clamp((int) (b + 0.5)); + outPixels[index] = (ia << 24) | (ir << 16) | (ig << 8) | ib; + index += height; + } + } + } + + public static int clamp(int c) + { + if (c < 0) + return 0; + if (c > 255) + return 255; + return c; + } + + public static Kernel makeKernel(float radius) + { + int r = (int) Math.ceil(radius); + int rows = r * 2 + 1; + float[] matrix = new float[rows]; + float sigma = radius / 3; + float sigma22 = 2 * sigma * sigma; + float sigmaPi2 = 2 * (float) Math.PI * sigma; + float sqrtSigmaPi2 = (float) Math.sqrt(sigmaPi2); + float radius2 = radius * radius; + float total = 0; + int index = 0; + for (int row = -r; row <= r; row++) + { + float distance = row * row; + if (distance > radius2) + matrix[index] = 0; + else + matrix[index] = (float) Math.exp(-(distance) / sigma22) / sqrtSigmaPi2; + total += matrix[index]; + index++; + } + for (int i = 0; i < rows; i++) + matrix[i] /= total; + + return new Kernel(rows, 1, matrix); + } + + public String toString() + { + return "Blur/Gaussian Blur..."; + } +} \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/Label.java b/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/Label.java new file mode 100644 index 0000000..a706bcd --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/Label.java @@ -0,0 +1,126 @@ +package com.moomoohk.Grame.Core.Graphics.PostProcessing; + +import java.awt.Color; +import java.awt.Font; + +public class Label +{ + private int paddingTop, paddingLeft, paddingRight, paddingBottom, centerX, centerY; + private String text; + private Color textColor, backColor; + private Font font; + + public Label(int centerX, int centerY, String text, Font font, Color textColor, Color backColor, int paddingTop, int paddingLeft, int paddingRight, int paddingBottom) + { + this.centerX = centerX; + this.centerY = centerY; + this.text = text; + this.font = font; + this.textColor = textColor; + this.backColor = backColor; + this.paddingTop = paddingTop; + this.paddingLeft = paddingLeft; + this.paddingRight = paddingRight; + this.paddingBottom = paddingBottom; + } + + public void setPaddingRight(int paddingRight) + { + this.paddingRight = paddingRight; + } + + public int getPaddingRight() + { + return paddingRight; + } + + public void setCenterX(int centerX) + { + this.centerX = centerX; + } + + public int getCenterX() + { + return centerX; + } + + public void setPaddingLeft(int paddingLeft) + { + this.paddingLeft = paddingLeft; + } + + public int getPaddingLeft() + { + return paddingLeft; + } + + public void setPaddingBottom(int paddingBottom) + { + this.paddingBottom = paddingBottom; + } + + public int getPaddingBottom() + { + return paddingBottom; + } + + public void setPaddingTop(int paddingTop) + { + this.paddingTop = paddingTop; + } + + public int getPaddingTop() + { + return paddingTop; + } + + public void setText(String text) + { + this.text = text; + } + + public String getText() + { + return text; + } + + public void setTextColor(Color textColor) + { + this.textColor = textColor; + } + + public Color getTextColor() + { + return textColor; + } + + public void setCenterY(int centerY) + { + this.centerY = centerY; + } + + public int getCenterY() + { + return centerY; + } + + public void setBackColor(Color backColor) + { + this.backColor = backColor; + } + + public Color getBackColor() + { + return backColor; + } + + public void setFont(Font font) + { + this.font = font; + } + + public Font getFont() + { + return font; + } +} \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/package-info.java b/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/package-info.java new file mode 100644 index 0000000..e170552 --- /dev/null +++ b/src/com/moomoohk/Grame/Core/Graphics/PostProcessing/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains special override graphics stuff + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.Core.Graphics.PostProcessing; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Graphics/RandomRender.java b/src/com/moomoohk/Grame/Core/Graphics/RandomRender.java similarity index 64% rename from src/com/moomoohk/Grame/Graphics/RandomRender.java rename to src/com/moomoohk/Grame/Core/Graphics/RandomRender.java index 89430be..cef6cec 100644 --- a/src/com/moomoohk/Grame/Graphics/RandomRender.java +++ b/src/com/moomoohk/Grame/Core/Graphics/RandomRender.java @@ -1,9 +1,9 @@ -package com.moomoohk.Grame.Graphics; +package com.moomoohk.Grame.Core.Graphics; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Render; /** * Randomizes a bunch of pixels. @@ -16,7 +16,7 @@ */ public class RandomRender implements Render { - public int[] getPixels(int[] pixels, Base b, int width, int height) + public int[] getPixels(int[] pixels, Grid b, int width, int height) { for (int i = 0; i < pixels.length; i++) pixels[i] = GrameUtils.randomColor().getRGB(); diff --git a/src/com/moomoohk/Grame/Graphics/RenderManager.java b/src/com/moomoohk/Grame/Core/Graphics/RenderManager.java similarity index 54% rename from src/com/moomoohk/Grame/Graphics/RenderManager.java rename to src/com/moomoohk/Grame/Core/Graphics/RenderManager.java index b1d0008..3cf3808 100644 --- a/src/com/moomoohk/Grame/Graphics/RenderManager.java +++ b/src/com/moomoohk/Grame/Core/Graphics/RenderManager.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.Graphics; +package com.moomoohk.Grame.Core.Graphics; import java.awt.Canvas; import java.awt.Color; @@ -10,20 +10,23 @@ import java.awt.Toolkit; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; +import java.util.ArrayList; import java.util.HashMap; import javax.swing.JFrame; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Render; +import com.moomoohk.Grame.Core.Graphics.PostProcessing.Label; /** * Manages all the rendering operations. @@ -36,6 +39,7 @@ public class RenderManager { private static HashMap renders; private static HashMap text; + private static ArrayList

* This ID is unique and cannot be changed.
- * It is this Base's place in the {@link GrameManager}'s list of Bases. + * It is this Grid's place in the {@link GrameManager}'s list of Grids. */ public final int ID; private ArrayList layers; @@ -36,11 +35,11 @@ public class Base implements Serializable * Constructor. * * @param width - * Width of the Base. + * Width of the Grid. * @param height - * Height of the Base. + * Height of the Grid. */ - public Base(int width, int height) + public Grid(int width, int height) { this(width, height, Color.white, ""); } @@ -49,13 +48,13 @@ public Base(int width, int height) * Constructor. * * @param width - * Width of the Base. + * Width of the Grid. * @param height - * Height of the Base. + * Height of the Grid. * @param title - * Title of the Base. + * Title of the Grid. */ - public Base(int width, int height, String title) + public Grid(int width, int height, String title) { this(width, height, Color.white, title); } @@ -64,13 +63,13 @@ public Base(int width, int height, String title) * Constructor. * * @param width - * Width of the Base. + * Width of the Grid. * @param height - * Height of the Base. + * Height of the Grid. * @param floorColor - * Floor color of the Base. + * Floor color of the Grid. */ - public Base(int width, int height, Color floorColor) + public Grid(int width, int height, Color floorColor) { this(width, height, floorColor, ""); } @@ -79,15 +78,15 @@ public Base(int width, int height, Color floorColor) * Constructor. * * @param width - * Width of the Base. + * Width of the Grid. * @param height - * Height of the Base. + * Height of the Grid. * @param floorColor - * Floor color of the Base. + * Floor color of the Grid. * @param title - * Title of the Base. + * Title of the Grid. */ - public Base(int width, int height, Color floorColor, String title) + public Grid(int width, int height, Color floorColor, String title) { this.layers = new ArrayList(); this.colors = new Color[width * height]; @@ -107,7 +106,7 @@ public Base(int width, int height, Color floorColor, String title) } /** - * Ticks the Base. + * Ticks the Grid. *

* Users will never need to call this method (The {@link GrameManager} takes care of ticking everything). */ @@ -123,7 +122,7 @@ public void tick() } /** - * Calculates the color of a square based on the objects that are occupying it. + * Calculates the color of a square gridd on the objects that are occupying it. * * @param pos * Set of {@link Coordinates} to calculate the color of. @@ -145,7 +144,7 @@ private Color calcColor(Coordinates pos) */ /** - * Gets the number of rows (height) of this Base. + * Gets the number of rows (height) of this Grid. * * @return Row count. */ @@ -155,7 +154,7 @@ public int getRows() } /** - * Gets the number of columns (width) of this Base. + * Gets the number of columns (width) of this Grid. * * @return Column count. */ @@ -165,19 +164,19 @@ public int getColumns() } /** - * Checks whether a set of {@link Coordinates} are in this Base. + * Checks whether a set of {@link Coordinates} are in this Grid. * * @param pos * {@link Coordinates} to check. - * @return True if the {@link Coordinates} are in this Base, else false. + * @return True if the {@link Coordinates} are in this Grid, else false. */ - public boolean isInBase(Coordinates pos) + public boolean isInGrid(Coordinates pos) { return (pos.y >= 0) && (pos.y <= this.height - 1) && (pos.x >= 0) && (pos.x <= this.width - 1); } /** - * Gets the current color of a square in this Base. + * Gets the current color of a square in this Grid. * * @param pos * {@link Coordinates} of square to get color of. @@ -189,12 +188,12 @@ public Color getColor(Coordinates pos) } /** - * Adds a {@link GrameObjectLayer} to this base at a specified layer. + * Adds a {@link GrameObjectLayer} to this grid at a specified layer. * * @param gol * {@link GrameObjectLayer} to add. * @param place - * Place within this Base's list of {@link GrameObjectLayer}s. + * Place within this Grid's list of {@link GrameObjectLayer}s. */ public void addGrameObjectLayer(GrameObjectLayer gol, int place) { @@ -203,7 +202,7 @@ public void addGrameObjectLayer(GrameObjectLayer gol, int place) this.layers.add(place, gol); if (place <= this.goLayer) this.goLayer++; - GrameUtils.print("Added layer " + gol.toString() + " to Base ID:" + ID, MessageLevel.DEBUG); + GrameUtils.print("Added layer " + gol.toString() + " to Grid ID:" + ID, MessageLevel.DEBUG); } else { @@ -213,7 +212,7 @@ public void addGrameObjectLayer(GrameObjectLayer gol, int place) } /** - * Sets the floor color for all the squares in this Base. + * Sets the floor color for all the squares in this Grid. * * @param c * The color to use. @@ -224,7 +223,7 @@ public void setFloorColor(Color c) } /** - * Sets the floor color of a square in this Base. + * Sets the floor color of a square in this Grid. * * @param pos * {@link Coordinates} of square to switch. @@ -237,7 +236,7 @@ public void setFloorColor(Coordinates pos, Color c) } /** - * Gets the floor color of a square in this Base. + * Gets the floor color of a square in this Grid. * * @param pos * {@link Coordinates} of square to get. @@ -249,7 +248,7 @@ public Color getFloorColor(Coordinates pos) } /** - * Adds a {@link GrameObject} to this Base. + * Adds a {@link GrameObject} to this Grid. * * @param go * {@link GrameObject} to add. @@ -257,7 +256,7 @@ public Color getFloorColor(Coordinates pos) * {@link Coordinates} to add the object to. * @param layer * The layer number to add the object to. - * @see Base#addGrameObject(GrameObject, Coordinates) + * @see Grid#addGrameObject(GrameObject, Coordinates) */ public void addGrameObject(GrameObject go, Coordinates pos, int layer) { @@ -276,13 +275,13 @@ public void addGrameObject(GrameObject go, Coordinates pos, int layer) } /** - * Adds a {@link GrameObject} to the default layer of this Base. + * Adds a {@link GrameObject} to the default layer of this Grid. * * @param go * {@link GrameObject} to add. * @param pos * {@link Coordinates} to add the object to. - * @see Base#addGrameObject(GrameObject, Coordinates, int) + * @see Grid#addGrameObject(GrameObject, Coordinates, int) */ public void addGrameObject(GrameObject go, Coordinates pos) { @@ -290,11 +289,11 @@ public void addGrameObject(GrameObject go, Coordinates pos) } /** - * Checks whether this Base contains a certain {@link GrameObject}. + * Checks whether this Grid contains a certain {@link GrameObject}. * * @param goID * ID of {@link GrameObject} to look for. - * @return True if this Base contains the {@link GrameObject}, else false. + * @return True if this Grid contains the {@link GrameObject}, else false. */ public boolean containsGrameObject(int goID) { @@ -319,7 +318,7 @@ public GrameObject getGrameObject(Coordinates pos, int layer) } /** - * Returns the position of a {@link GrameObject} that is in this Base. + * Returns the position of a {@link GrameObject} that is in this Grid. * * @param goID * {@link GrameObject#ID} of the {@link GrameObject}. @@ -334,9 +333,9 @@ public Coordinates getGrameObjectPos(int goID) } /** - * Return a list of the {@link GrameObjectLayer}s of this Base. + * Return a list of the {@link GrameObjectLayer}s of this Grid. * - * @return A list of the {@link GrameObjectLayer}s of this Base. + * @return A list of the {@link GrameObjectLayer}s of this Grid. */ public ArrayList getGrameObjectLayers() { @@ -344,9 +343,9 @@ public ArrayList getGrameObjectLayers() } /** - * Returns the default {@link GrameObjectLayer} of this Base. + * Returns the default {@link GrameObjectLayer} of this Grid. * - * @return The default {@link GrameObjectLayer} of this Base. + * @return The default {@link GrameObjectLayer} of this Grid. */ public GrameObjectLayer getGrameObjectLayer() { @@ -386,7 +385,7 @@ public void moveGrameObject(int goID, Coordinates pos) * @param pos * {@link Coordinates} to check. * @return True if the {@link Coordinates} are occupied on the default layer, else false. - * @see Base#isOccupied(Coordinates, int) + * @see Grid#isOccupied(Coordinates, int) */ public boolean isOccupied(Coordinates pos) { @@ -410,9 +409,9 @@ public boolean isOccupied(Coordinates pos, int layer) } /** - * Sets the "wraparound" aspect of this Base. + * Sets the "wraparound" aspect of this Grid. *

- * "Wraparound" means that if a {@link GrameObject} tries to go off one side of this Base it will be placed on the other side.
+ * "Wraparound" means that if a {@link GrameObject} tries to go off one side of this Grid it will be placed on the other side.
* Think of Snake and Pac-Man. * * @param f @@ -424,12 +423,12 @@ public void setWraparound(boolean f) } /** - * Gets the "wraparound" aspect of this Base. + * Gets the "wraparound" aspect of this Grid. *

- * "Wraparound" means that if a {@link GrameObject} tries to go off one side of this Base it will be placed on the other side.
+ * "Wraparound" means that if a {@link GrameObject} tries to go off one side of this Grid it will be placed on the other side.
* Think of Snake and Pac-Man. * - * @return True if this Base is a wraparound Base, else false. + * @return True if this Grid is a wraparound Grid, else false. */ public boolean getWraparound() { @@ -437,9 +436,9 @@ public boolean getWraparound() } /** - * Returns the length of the diagonal of this Base. + * Returns the length of the diagonal of this Grid. * - * @return The length of the diagonal of this Base. + * @return The length of the diagonal of this Grid. */ public int getDiagonal() { @@ -447,7 +446,7 @@ public int getDiagonal() } /** - * Sets the title of this Base. + * Sets the title of this Grid. * * @param title * The title to use. @@ -458,9 +457,9 @@ public void setTitle(String title) } /** - * Returns the title of this Base. + * Returns the title of this Grid. * - * @return The title of this Base. + * @return The title of this Grid. */ public String getTitle() { @@ -468,9 +467,9 @@ public String getTitle() } /** - * Gets the amount of layers in this Base. + * Gets the amount of layers in this Grid. * - * @return The amount of layers in this Base. + * @return The amount of layers in this Grid. */ public int getLayerCount() { @@ -478,11 +477,11 @@ public int getLayerCount() } /** - * Prints useful information about this Base. + * Prints useful information about this Grid. */ public String toString() { - String st = "Base ID:" + ID + "\n"; + String st = "Grid ID:" + ID + "\n"; st += "Contains: " + this.layers.size() + " Grame Object layers.\n"; st += "Contains "; int count = 0; diff --git a/src/com/moomoohk/Grame/Essentials/InputHandler.java b/src/com/moomoohk/Grame/Core/InputHandler.java similarity index 93% rename from src/com/moomoohk/Grame/Essentials/InputHandler.java rename to src/com/moomoohk/Grame/Core/InputHandler.java index 252e2c8..2247eb2 100644 --- a/src/com/moomoohk/Grame/Essentials/InputHandler.java +++ b/src/com/moomoohk/Grame/Core/InputHandler.java @@ -1,10 +1,10 @@ -package com.moomoohk.Grame.Essentials; +package com.moomoohk.Grame.Core; import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; /** * Handles keyboard input. diff --git a/src/com/moomoohk/Grame/Interfaces/MainGrameClass.java b/src/com/moomoohk/Grame/Core/MainGrameClass.java similarity index 70% rename from src/com/moomoohk/Grame/Interfaces/MainGrameClass.java rename to src/com/moomoohk/Grame/Core/MainGrameClass.java index d9ca2bf..6a05e6c 100644 --- a/src/com/moomoohk/Grame/Interfaces/MainGrameClass.java +++ b/src/com/moomoohk/Grame/Core/MainGrameClass.java @@ -1,4 +1,4 @@ -package com.moomoohk.Grame.Interfaces; +package com.moomoohk.Grame.Core; public interface MainGrameClass { diff --git a/src/com/moomoohk/Grame/Interfaces/Render.java b/src/com/moomoohk/Grame/Core/Render.java similarity index 68% rename from src/com/moomoohk/Grame/Interfaces/Render.java rename to src/com/moomoohk/Grame/Core/Render.java index 0801678..4af8f41 100644 --- a/src/com/moomoohk/Grame/Interfaces/Render.java +++ b/src/com/moomoohk/Grame/Core/Render.java @@ -1,10 +1,9 @@ -package com.moomoohk.Grame.Interfaces; +package com.moomoohk.Grame.Core; -import com.moomoohk.Grame.Essentials.Base; /** - * Objects to render {@link Base}s. + * Objects to render {@link Grid}s. * * @author Meshulam Silk * @version 1.0 @@ -15,12 +14,12 @@ public interface Render /** * Method to calculate the pixels. * @param pixels An int array of pixels. - * @param b The {@link Base} to render. + * @param g The {@link Grid} to render. * @param width The width of the main canvas. * @param height The height of the main canvas. * @return The pixel array, edited with the new render pixels. */ - public int[] getPixels(int[] pixels, Base b, int width, int height); + public int[] getPixels(int[] pixels, Grid g, int width, int height); /** * The name of this render. * @return The name of this render. diff --git a/src/com/moomoohk/Grame/Core/package-info.java b/src/com/moomoohk/Grame/Core/package-info.java new file mode 100644 index 0000000..416702f --- /dev/null +++ b/src/com/moomoohk/Grame/Core/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains the core classes of the engine. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.Core; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/Graphics/PlainGridRender.java b/src/com/moomoohk/Grame/Graphics/PlainGridRender.java deleted file mode 100644 index 4144f0a..0000000 --- a/src/com/moomoohk/Grame/Graphics/PlainGridRender.java +++ /dev/null @@ -1,50 +0,0 @@ - -package com.moomoohk.Grame.Graphics; - -import java.io.Serializable; - -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Interfaces.Render; - -/** - * Renders {@link Base}s in a grid without grouting lines. - * - * @author Meshulam Silk - * @version 1.0 - * @since 2013-04-05 - */ -public class PlainGridRender implements Render, Serializable -{ - private static final long serialVersionUID = 1269305794830678142L; - - public int[] getPixels(int[] pixels, Base b, int width, int height) - { - for (int x = 0; x < width; x++) - for (int y = 0; y < height; y++) - { - Coordinates currSquare = new Coordinates((x ) / ((width) /( b.getColumns())), (y ) / (height / b.getRows())); - if(currSquare.getX()>=b.getColumns()) - currSquare.setX(b.getColumns()-1); - if( currSquare.getY()>=b.getRows()) - currSquare.setY(b.getRows()-1); - if (b.isInBase(currSquare)) - try - { - pixels[x + y * width] = b.getColor(currSquare).getRGB(); - } - catch(Exception e) - { - System.out.println(x+" "+width); - } - } - return pixels; - } - - public String getName() - { - return "Plain_grid_render"; - } - -} - diff --git a/src/com/moomoohk/Grame/GrassMuncher/Chaser.java b/src/com/moomoohk/Grame/GrassMuncher/Chaser.java index 0623213..41b022a 100644 --- a/src/com/moomoohk/Grame/GrassMuncher/Chaser.java +++ b/src/com/moomoohk/Grame/GrassMuncher/Chaser.java @@ -1,17 +1,17 @@ - package com.moomoohk.Grame.GrassMuncher; import java.awt.Color; import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; public class Chaser extends GrameObject { private static final long serialVersionUID = -3075457796713552182L; private GrameObject target; + public Chaser() { super("Chaser", 4, Color.red, false); @@ -24,31 +24,32 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { - if(getPos(bID).distance(target.getPos(bID))==1) + if (getPos(gID).distance(target.getPos(gID)) == 1) MainScript.lose(); - GrameManager.findBase(bID).moveGrameObject(ID, getNext(bID)); + GrameManager.findGrid(gID).moveGrameObject(ID, getNext(gID)); } @Override public void consume(GrameObject go) { - } - private Coordinates getNext(int bID) + } + + private Coordinates getNext(int gID) { - Dir d = new Dir(getPos(bID), this.target.getPos(bID)); - if (!GrameManager.findBase(bID).isOccupied(getPos(bID).addDir(d), 1)) - return getPos(bID).addDir(d); - if(!GrameManager.findBase(bID).isOccupied(getPos(bID).addDir(d.split()[0]), 1)) - return getPos(bID).addDir(d.split()[0]); - if(!GrameManager.findBase(bID).isOccupied(getPos(bID).addDir(d.split()[1]), 1)) - return getPos(bID).addDir(d.split()[1]); - return getPos(bID); + Dir d = new Dir(getPos(gID), this.target.getPos(gID)); + if (!GrameManager.findGrid(gID).isOccupied(getPos(gID).addDir(d), 1)) + return getPos(gID).addDir(d); + if (!GrameManager.findGrid(gID).isOccupied(getPos(gID).addDir(d.split()[0]), 1)) + return getPos(gID).addDir(d.split()[0]); + if (!GrameManager.findGrid(gID).isOccupied(getPos(gID).addDir(d.split()[1]), 1)) + return getPos(gID).addDir(d.split()[1]); + return getPos(gID); } + public void setTarget(GrameObject go) { - this.target=go; + this.target = go; } } - diff --git a/src/com/moomoohk/Grame/GrassMuncher/Coin.java b/src/com/moomoohk/Grame/GrassMuncher/Coin.java index 466009a..b6ab44b 100644 --- a/src/com/moomoohk/Grame/GrassMuncher/Coin.java +++ b/src/com/moomoohk/Grame/GrassMuncher/Coin.java @@ -1,23 +1,24 @@ - package com.moomoohk.Grame.GrassMuncher; import java.awt.Color; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.GrameObject; public class Coin extends GrameObject { private static final long serialVersionUID = 3955843569288863271L; private int worth; + public Coin() { super("Coin", 0, Color.green, false); - this.worth=1; + this.worth = 1; } + public Coin(int worth) { super("Coin", 0, Color.green, false); - this.worth=worth; + this.worth = worth; } @Override @@ -27,17 +28,18 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { - + } + public int getWorth() { return this.worth; } + @Override public void consume(GrameObject go) { } } - diff --git a/src/com/moomoohk/Grame/GrassMuncher/MainScript.java b/src/com/moomoohk/Grame/GrassMuncher/MainScript.java index 4cec59b..8e9a704 100644 --- a/src/com/moomoohk/Grame/GrassMuncher/MainScript.java +++ b/src/com/moomoohk/Grame/GrassMuncher/MainScript.java @@ -7,18 +7,18 @@ import javax.swing.SwingUtilities; import com.moomoohk.Grame.Basics.Wall; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameObjectLayer; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.MainGrameClass; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObjectLayer; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.Grame.test.SpriteRender; public class MainScript implements MainGrameClass { - public static Base b; + public static Grid g; public static Player p; public static Chaser c; public static int maxCoins = 0; @@ -57,36 +57,36 @@ public void run() @Override public void newGame() { - b = new Base(20, 20); + g = new Grid(20, 20); p = new Player(); c = new Chaser(); GrameManager.pauseAllGrameObjects(true); c.setTarget(p); c.setSpeed(20); p.setSpeed(5); - b.addGrameObjectLayer(new GrameObjectLayer(b.getColumns(), b.getRows()), 1); - b.addGrameObject(p, new Coordinates(0, 0), 0); - b.addGrameObject(c, new Coordinates(b.getColumns() - 1, b.getRows() - 1), 1); - b.setFloorColor(new Color(139, 69, 19)); + g.addGrameObjectLayer(new GrameObjectLayer(g.getColumns(), g.getRows()), 1); + g.addGrameObject(p, new Coordinates(0, 0), 0); + g.addGrameObject(c, new Coordinates(g.getColumns() - 1, g.getRows() - 1), 1); + g.setFloorColor(new Color(139, 69, 19)); for (int i = 1; i <= 339; i++) { - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp) || temp.equals(new Coordinates(0, 0)) || temp.equals(new Coordinates(b.getColumns() - 1, b.getRows() - 1))) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(new Coin(), temp, 0); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp) || temp.equals(new Coordinates(0, 0)) || temp.equals(new Coordinates(g.getColumns() - 1, g.getRows() - 1))) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(new Coin(), temp, 0); maxCoins++; } for (int i = 1; i <= 60; i++) { - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp)) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(new Wall(), temp, 0); - b.addGrameObject(new Wall(), temp, 1); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp)) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(new Wall(), temp, 0); + g.addGrameObject(new Wall(), temp, 1); } SpriteRender.objects.put(p.ID, "player"); SpriteRender.objects.put(c.ID, "monster"); - RenderManager.render(b.ID, new SpriteRender()); + RenderManager.render(g.ID, new SpriteRender()); RenderManager.setVisible(true); JOptionPane.showMessageDialog(new JFrame(), "Ready to begin?", "Grass Muncher!", JOptionPane.PLAIN_MESSAGE); GrameManager.pauseAllGrameObjects(false); diff --git a/src/com/moomoohk/Grame/GrassMuncher/Player.java b/src/com/moomoohk/Grame/GrassMuncher/Player.java index c75851f..bf03f2d 100644 --- a/src/com/moomoohk/Grame/GrassMuncher/Player.java +++ b/src/com/moomoohk/Grame/GrassMuncher/Player.java @@ -1,22 +1,22 @@ - package com.moomoohk.Grame.GrassMuncher; import java.awt.Color; import com.moomoohk.Grame.Basics.Dir; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.Grid; public class Player extends GrameObject { private static final long serialVersionUID = 1615372944054959042L; private int points; + public Player() { super("Player", 2, Color.DARK_GRAY, false); - this.points=-1; + this.points = -1; } @Override @@ -26,45 +26,44 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { - setPos(bID, getNext(bID)); - if(this.points+1==MainScript.maxCoins) + setPos(gID, getNext(gID)); + if (this.points + 1 == MainScript.maxCoins) MainScript.win(); - if(getPos(bID).distance(MainScript.c.getPos(bID))==1) + if (getPos(gID).distance(MainScript.c.getPos(gID)) == 1) MainScript.lose(); } @Override public void consume(GrameObject go) { - if(!(go instanceof Coin)) + if (!(go instanceof Coin)) return; - Coin coin=(Coin)go; - points+=coin.getWorth(); + Coin coin = (Coin) go; + points += coin.getWorth(); } - private Coordinates getNext(int bID) + private Coordinates getNext(int gID) { - Dir d=GrameManager.dir1; + Dir d = GrameManager.dir1; if (d == null) - return getPos(bID); - Base b=GrameManager.findBase(bID); - if(!b.isInBase(getPos(bID).addDir(d))) - return getPos(bID); - if(b.isOccupied(getPos(bID).addDir(d))) + return getPos(gID); + Grid b = GrameManager.findGrid(gID); + if (!b.isInGrid(getPos(gID).addDir(d))) + return getPos(gID); + if (b.isOccupied(getPos(gID).addDir(d))) { - if(!b.isOccupied(getPos(bID).addDir(d.split()[0]))) - return getPos(bID).addDir(d.split()[0]); - if(!b.isOccupied(getPos(bID).addDir(d.split()[1]))) - return getPos(bID).addDir(d.split()[1]); + if (!b.isOccupied(getPos(gID).addDir(d.split()[0]))) + return getPos(gID).addDir(d.split()[0]); + if (!b.isOccupied(getPos(gID).addDir(d.split()[1]))) + return getPos(gID).addDir(d.split()[1]); } - return getPos(bID).addDir(d); + return getPos(gID).addDir(d); } public int getPoints() { - return this.points+1; + return this.points + 1; } } - diff --git a/src/com/moomoohk/Grame/GrassMuncher/package-info.java b/src/com/moomoohk/Grame/GrassMuncher/package-info.java new file mode 100644 index 0000000..9eb3b7f --- /dev/null +++ b/src/com/moomoohk/Grame/GrassMuncher/package-info.java @@ -0,0 +1,7 @@ +/** + * A demo game I made with Grame. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.GrassMuncher; \ No newline at end of file diff --git a/src/com/moomoohk/Grame/test/AISystemTest.java b/src/com/moomoohk/Grame/test/AISystemTest.java index 4a6a4d3..9dc140b 100644 --- a/src/com/moomoohk/Grame/test/AISystemTest.java +++ b/src/com/moomoohk/Grame/test/AISystemTest.java @@ -2,17 +2,17 @@ import java.awt.Color; -import com.moomoohk.Grame.AI.PlayerSimAI; -import com.moomoohk.Grame.AI.SimpleChaseAI; -import com.moomoohk.Grame.AI.SimpleStrollAI; import com.moomoohk.Grame.Basics.Entity; import com.moomoohk.Grame.Basics.Wall; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.MainGrameClass; +import com.moomoohk.Grame.Basics.AI.PlayerSimAI; +import com.moomoohk.Grame.Basics.AI.SimpleChaseAI; +import com.moomoohk.Grame.Basics.AI.SimpleStrollAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class AISystemTest implements MainGrameClass { @@ -21,39 +21,39 @@ public static void main(String[] args) GrameManager.initialize(new AISystemTest()); } - public static void generateStrollers(int amount, Base b) + public static void generateStrollers(int amount, Grid g) { for (int i = 0; i < amount; i++) { Entity ent = new Entity(); - ent.addAI(new SimpleStrollAI(), b.ID); + ent.addAI(new SimpleStrollAI(), g.ID); ent.setSpeed(5); ent.setColor(Color.blue); - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp)) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(ent, temp); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp)) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(ent, temp); } } - public static void generateChasers(Base b, int amount, Entity target) + public static void generateChasers(Grid g, int amount, Entity target) { for (int i = 1; i <= amount; i++) { Entity ent = new Entity(Color.red); - ent.addAI(new SimpleChaseAI(), b.ID); - ent.setRange(b.getDiagonal()); + ent.addAI(new SimpleChaseAI(), g.ID); + ent.setRange(g.getDiagonal()); ent.setTarget(target.ID); ent.setColor(Color.red); ent.setSpeed(2); - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp)) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(ent, temp); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp)) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(ent, temp); } } - public static void generatePlayers(int number, int amount, Base b) + public static void generatePlayers(int number, int amount, Grid b) { for (int i = 1; i <= amount; i++) { @@ -68,29 +68,29 @@ public static void generatePlayers(int number, int amount, Base b) } } - public static void generatePlayerSims(int amount, Base b) + public static void generatePlayerSims(int amount, Grid g) { for (int i = 1; i <= amount; i++) { Entity ent = new Entity(); ent.setColor(Color.yellow); - ent.setOverrideAI(new PlayerSimAI(), b.ID); + ent.setOverrideAI(new PlayerSimAI(), g.ID); ent.setSpeed(1); - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp)) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(ent, temp); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp)) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(ent, temp); } } - public static void generateWalls(int amount, Base b) + public static void generateWalls(int amount, Grid g) { for (int i = 1; i <= amount; i++) { - Coordinates temp = GrameUtils.randomCoordinates(b); - while (b.isOccupied(temp)) - temp = GrameUtils.randomCoordinates(b); - b.addGrameObject(new Wall(), temp); + Coordinates temp = GrameUtils.randomCoordinates(g); + while (g.isOccupied(temp)) + temp = GrameUtils.randomCoordinates(g); + g.addGrameObject(new Wall(), temp); } } @@ -99,18 +99,18 @@ public void newGame() { GrameManager.setDebug(true); GrameManager.setSpam(false); - Base b = new Base(20, 20); - b.setWraparound(true); - generatePlayers(1, 1, b); - generatePlayerSims(1, b); - generateStrollers(5, b); - generateChasers(b, 3, (Entity) GrameManager.findGrameObject(1)); - generateChasers(b, 3, (Entity) GrameManager.findGrameObject(0)); - RenderManager.render(b.ID); + Grid g = new Grid(20, 20); + g.setWraparound(true); + generatePlayers(1, 1, g); + generatePlayerSims(1, g); + generateStrollers(5, g); + generateChasers(g, 3, (Entity) GrameManager.findGrameObject(1)); + generateChasers(g, 3, (Entity) GrameManager.findGrameObject(0)); + RenderManager.render(g.ID); RenderManager.setVisible(true); - RenderManager.setText(b.ID, new Coordinates(6, 6), "test", Color.red); - RenderManager.setText(b.ID, new Coordinates(19, 19), "penis", Color.yellow); - RenderManager.setText(b.ID, new Coordinates(5, 5), "hohohohoh", Color.green); + RenderManager.setText(g.ID, new Coordinates(6, 6), "test", Color.red); + RenderManager.setText(g.ID, new Coordinates(19, 19), "phallus", Color.yellow); + RenderManager.setText(g.ID, new Coordinates(5, 5), "hohohohoh", Color.green); } @Override diff --git a/src/com/moomoohk/Grame/test/ConsumeTest.java b/src/com/moomoohk/Grame/test/ConsumeTest.java index 16efb97..5e3f9ce 100644 --- a/src/com/moomoohk/Grame/test/ConsumeTest.java +++ b/src/com/moomoohk/Grame/test/ConsumeTest.java @@ -1,13 +1,13 @@ package com.moomoohk.Grame.test; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Graphics.RenderManager; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.RenderManager; import com.moomoohk.Grame.GrassMuncher.Coin; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.Interfaces.MainGrameClass; public class ConsumeTest implements MainGrameClass { @@ -29,15 +29,15 @@ public static void main(String[] args) @Override public void newGame() { - Base b = new Base(20, 20); + Grid g = new Grid(20, 20); Player p = new Player(); - b.addGrameObject(p, new Coordinates(0, 0)); - for (int i = 0; i < b.getRows(); i++) - for (int j = 0; j < b.getColumns(); j++) - if (!b.isOccupied(new Coordinates(i, j))) - b.addGrameObject(new Coin(), new Coordinates(i, j)); - p.makePlayer(1, true, b.ID); - RenderManager.render(b.ID); + g.addGrameObject(p, new Coordinates(0, 0)); + for (int i = 0; i < g.getRows(); i++) + for (int j = 0; j < g.getColumns(); j++) + if (!g.isOccupied(new Coordinates(i, j))) + g.addGrameObject(new Coin(), new Coordinates(i, j)); + p.makePlayer(1, true, g.ID); + RenderManager.render(g.ID); RenderManager.setVisible(true); } diff --git a/src/com/moomoohk/Grame/test/Dialog.java b/src/com/moomoohk/Grame/test/Dialog.java new file mode 100644 index 0000000..21b4314 --- /dev/null +++ b/src/com/moomoohk/Grame/test/Dialog.java @@ -0,0 +1,70 @@ +package com.moomoohk.Grame.test; + +import java.awt.Color; +import java.util.ArrayList; + +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.Graphics.RenderManager; +import com.moomoohk.Grame.Core.Graphics.PostProcessing.Label; + +public class Dialog implements Runnable +{ + private ArrayList lines; + private Label label; + private long interval; + private GrameObject go; + + public Dialog(ArrayList lines, long interval, GrameObject go) + { + this.label = new Label(); + this.label.setBackColor(Color.black); + this.label.setTextColor(Color.white); + this.label.setPadding(10); + this.lines = lines; + this.interval = interval; + this.go = go; + RenderManager.addLabel(this.label); + } + + public void start() + { + new Thread(this).start(); + } + + @Override + public void run() + { + GrameManager.pauseAllGrameObjects(true); + int squareWidth = RenderManager.getMainCanvas().getWidth() / GrameManager.findGrid(RenderManager.getMainGrid()).getColumns(), squareHeight = RenderManager.getMainCanvas().getHeight() / GrameManager.findGrid(RenderManager.getMainGrid()).getRows(); + Coordinates goPos = this.go.getPos(RenderManager.getMainGrid()); + this.label.setCenterX(goPos.getX() * squareWidth + squareWidth / 2); + this.label.setCenterY(goPos.getY() * squareHeight); + for (String line : this.lines) + { + for (int i = 0; i <= line.length(); i++) + { + this.label.setText(line.substring(0, i)); + try + { + Thread.sleep(50); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + try + { + Thread.sleep(this.interval); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + RenderManager.removeLabel(this.label); + GrameManager.pauseAllGrameObjects(false); + } +} diff --git a/src/com/moomoohk/Grame/test/GrameLogo.java b/src/com/moomoohk/Grame/test/GrameLogo.java index 4e61d2f..ffed9e9 100644 --- a/src/com/moomoohk/Grame/test/GrameLogo.java +++ b/src/com/moomoohk/Grame/test/GrameLogo.java @@ -1,36 +1,34 @@ - package com.moomoohk.Grame.test; import java.awt.Color; import com.moomoohk.Grame.Basics.Wall; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Graphics.PlainGridRender; -import com.moomoohk.Grame.Graphics.RenderManager; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Graphics.CleanGridRender; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class GrameLogo { public static void main(String[] args) { - Base b=new Base(6, 6); - TestGrameObject player=new TestGrameObject("player", 1, Color.gray, false); - TestGrameObject monster=new TestGrameObject("monster", 1, Color.red, false); - b.addGrameObject(player, new Coordinates(0, 0)); - b.addGrameObject(new Wall(), new Coordinates(1, 1)); - b.addGrameObject(new Wall(), new Coordinates(1, 2)); - b.addGrameObject(new Wall(), new Coordinates(1, 3)); - b.addGrameObject(new Wall(), new Coordinates(1, 4)); - b.addGrameObject(new Wall(), new Coordinates(2, 1)); - b.addGrameObject(new Wall(), new Coordinates(3, 1)); - b.addGrameObject(new Wall(), new Coordinates(4, 1)); - b.addGrameObject(new Wall(), new Coordinates(2, 4)); - b.addGrameObject(new Wall(), new Coordinates(3, 4)); - b.addGrameObject(new Wall(), new Coordinates(4, 4)); - b.addGrameObject(new Wall(), new Coordinates(4, 3)); - b.addGrameObject(monster, new Coordinates(5, 5)); - RenderManager.render(b.ID, new PlainGridRender()); + Grid g = new Grid(6, 6); + TestGrameObject player = new TestGrameObject("player", 1, Color.gray, false); + TestGrameObject monster = new TestGrameObject("monster", 1, Color.red, false); + g.addGrameObject(player, new Coordinates(0, 0)); + g.addGrameObject(new Wall(), new Coordinates(1, 1)); + g.addGrameObject(new Wall(), new Coordinates(1, 2)); + g.addGrameObject(new Wall(), new Coordinates(1, 3)); + g.addGrameObject(new Wall(), new Coordinates(1, 4)); + g.addGrameObject(new Wall(), new Coordinates(2, 1)); + g.addGrameObject(new Wall(), new Coordinates(3, 1)); + g.addGrameObject(new Wall(), new Coordinates(4, 1)); + g.addGrameObject(new Wall(), new Coordinates(2, 4)); + g.addGrameObject(new Wall(), new Coordinates(3, 4)); + g.addGrameObject(new Wall(), new Coordinates(4, 4)); + g.addGrameObject(new Wall(), new Coordinates(4, 3)); + g.addGrameObject(monster, new Coordinates(5, 5)); + RenderManager.render(g.ID, new CleanGridRender()); RenderManager.setVisible(true); } } - diff --git a/src/com/moomoohk/Grame/test/GrameObjectsTest.java b/src/com/moomoohk/Grame/test/GrameObjectsTest.java index 53cdcdf..382f14b 100644 --- a/src/com/moomoohk/Grame/test/GrameObjectsTest.java +++ b/src/com/moomoohk/Grame/test/GrameObjectsTest.java @@ -3,12 +3,12 @@ import java.awt.Color; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Graphics.PlainGridRender; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.MainGrameClass; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.CleanGridRender; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class GrameObjectsTest implements MainGrameClass { @@ -24,13 +24,13 @@ public static void main(String[] args) @Override public void newGame() { - Base b = new Base(20, 20); + Grid g = new Grid(20, 20); Entity ent = new Entity(); - b.addGrameObject(ent, new Coordinates(10, 10)); - b.setWraparound(true); - ent.makePlayer(1, true, b.ID); + g.addGrameObject(ent, new Coordinates(10, 10)); + g.setWraparound(true); + ent.makePlayer(1, true, g.ID); ent.setSpeed(1); - RenderManager.render(b.ID, new PlainGridRender()); + RenderManager.render(g.ID, new CleanGridRender()); RenderManager.setVisible(true); } diff --git a/src/com/moomoohk/Grame/test/NewSpriteRender.java b/src/com/moomoohk/Grame/test/NewSpriteRender.java index b29f74e..87a66f1 100644 --- a/src/com/moomoohk/Grame/test/NewSpriteRender.java +++ b/src/com/moomoohk/Grame/test/NewSpriteRender.java @@ -3,29 +3,29 @@ import java.awt.Color; import java.awt.image.BufferedImage; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.Render; public class NewSpriteRender implements Render { public static String floorPath; @Override - public int[] getPixels(int[] pixels, Base b, int width, int height) + public int[] getPixels(int[] pixels, Grid g, int width, int height) { - for (int xSquare = 0; xSquare < b.getColumns(); xSquare++) - for (int ySquare = 0; ySquare < b.getRows(); ySquare++) + for (int xSquare = 0; xSquare < g.getColumns(); xSquare++) + for (int ySquare = 0; ySquare < g.getRows(); ySquare++) { try { - drawSprite(xSquare, ySquare, width, height, pixels, b, sprites.get("grass")); - for (int layer = 0; layer < b.getLayerCount(); layer++) - if (b.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null && objects.containsKey(b.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID)) - drawSprite(xSquare, ySquare, width, height, pixels, b, sprites.get(objects.get(b.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID))); + drawSprite(xSquare, ySquare, width, height, pixels, g, sprites.get("grass")); + for (int layer = 0; layer < g.getLayerCount(); layer++) + if (g.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null && objects.containsKey(g.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID)) + drawSprite(xSquare, ySquare, width, height, pixels, g, sprites.get(objects.get(g.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID))); else - if (b.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null) - drawSquare(xSquare, ySquare, width, height, pixels, b, b.getGrameObject(new Coordinates(xSquare, ySquare), layer).getColor()); + if (g.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null) + drawSquare(xSquare, ySquare, width, height, pixels, g, g.getGrameObject(new Coordinates(xSquare, ySquare), layer).getColor()); } catch (Exception e) { @@ -35,7 +35,7 @@ public int[] getPixels(int[] pixels, Base b, int width, int height) return pixels; } - private void drawSprite(int xSquare, int ySquare, int width, int height, int[] pixels, Base b, BufferedImage sprite) + private void drawSprite(int xSquare, int ySquare, int width, int height, int[] pixels, Grid g, BufferedImage sprite) { for (int y = 0; y < sprite.getHeight(); y++) { @@ -54,7 +54,7 @@ private void drawSprite(int xSquare, int ySquare, int width, int height, int[] p } } - private void drawSquare(int xSquare, int ySquare, int width, int height, int[] pixels, Base b, Color c) + private void drawSquare(int xSquare, int ySquare, int width, int height, int[] pixels, Grid g, Color c) { for (int y = 0; y < 30; y++) { diff --git a/src/com/moomoohk/Grame/test/SaveTest.java b/src/com/moomoohk/Grame/test/SaveTest.java index e8209ef..f102e22 100644 --- a/src/com/moomoohk/Grame/test/SaveTest.java +++ b/src/com/moomoohk/Grame/test/SaveTest.java @@ -1,32 +1,29 @@ package com.moomoohk.Grame.test; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.MainGrameClass; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class SaveTest implements MainGrameClass { public static void main(String[] args) { - MenuConfiguration menuConfig = new MenuConfiguration(); - GrameManager.initialize(new SaveTest(), menuConfig); + GrameManager.initialize(new SaveTest()); } - @Override public void newGame() { - Base b = new Base(20, 20); + Grid g = new Grid(20, 20); Entity e = new Entity(); - e.makePlayer(1, true, b.ID); - b.addGrameObject(e, GrameUtils.randomCoordinates(b)); - RenderManager.render(b.ID); + e.makePlayer(1, true, g.ID); + g.addGrameObject(e, GrameUtils.randomCoordinates(g)); + RenderManager.render(g.ID); RenderManager.setVisible(true); } - @Override public String getGameName() { return "Save Test"; diff --git a/src/com/moomoohk/Grame/test/SpriteRender.java b/src/com/moomoohk/Grame/test/SpriteRender.java index c03e6dd..2babf2b 100644 --- a/src/com/moomoohk/Grame/test/SpriteRender.java +++ b/src/com/moomoohk/Grame/test/SpriteRender.java @@ -8,11 +8,11 @@ import javax.imageio.ImageIO; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Essentials.GrameUtils.MessageLevel; -import com.moomoohk.Grame.Interfaces.Render; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Render; +import com.moomoohk.Grame.Core.GrameUtils.MessageLevel; public class SpriteRender implements Render { @@ -28,20 +28,20 @@ public class SpriteRender implements Render } @Override - public int[] getPixels(int[] pixels, Base b, int width, int height) + public int[] getPixels(int[] pixels, Grid g, int width, int height) { - for (int xSquare = 0; xSquare < b.getColumns(); xSquare++) - for (int ySquare = 0; ySquare < b.getRows(); ySquare++) + for (int xSquare = 0; xSquare < g.getColumns(); xSquare++) + for (int ySquare = 0; ySquare < g.getRows(); ySquare++) { try { - drawSprite(xSquare, ySquare, width, height, pixels, b, sprites.get("grass")); - for (int layer = 0; layer < b.getLayerCount(); layer++) - if (b.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null && objects.containsKey(b.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID)) - drawSprite(xSquare, ySquare, width, height, pixels, b, sprites.get(objects.get(b.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID))); + drawSprite(xSquare, ySquare, width, height, pixels, g, sprites.get("grass")); + for (int layer = 0; layer < g.getLayerCount(); layer++) + if (g.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null && objects.containsKey(g.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID)) + drawSprite(xSquare, ySquare, width, height, pixels, g, sprites.get(objects.get(g.getGrameObject(new Coordinates(xSquare, ySquare), layer).ID))); else - if (b.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null) - drawSquare(xSquare, ySquare, width, height, pixels, b, b.getGrameObject(new Coordinates(xSquare, ySquare), layer).getColor()); + if (g.getGrameObject(new Coordinates(xSquare, ySquare), layer) != null) + drawSquare(xSquare, ySquare, width, height, pixels, g, g.getGrameObject(new Coordinates(xSquare, ySquare), layer).getColor()); } catch (Exception e) { @@ -51,7 +51,7 @@ public int[] getPixels(int[] pixels, Base b, int width, int height) return pixels; } - private void drawSprite(int xSquare, int ySquare, int width, int height, int[] pixels, Base b, BufferedImage sprite) + private void drawSprite(int xSquare, int ySquare, int width, int height, int[] pixels, Grid g, BufferedImage sprite) { for (int y = 0; y < sprite.getHeight(); y++) { @@ -70,7 +70,7 @@ private void drawSprite(int xSquare, int ySquare, int width, int height, int[] p } } - private void drawSquare(int xSquare, int ySquare, int width, int height, int[] pixels, Base b, Color c) + private void drawSquare(int xSquare, int ySquare, int width, int height, int[] pixels, Grid g, Color c) { for (int y = 0; y < 30; y++) { diff --git a/src/com/moomoohk/Grame/test/TestGrameObject.java b/src/com/moomoohk/Grame/test/TestGrameObject.java index ecc9c11..12e3967 100644 --- a/src/com/moomoohk/Grame/test/TestGrameObject.java +++ b/src/com/moomoohk/Grame/test/TestGrameObject.java @@ -1,14 +1,14 @@ - package com.moomoohk.Grame.test; import java.awt.Color; -import com.moomoohk.Grame.Interfaces.GrameObject; +import com.moomoohk.Grame.Core.GrameObject; public class TestGrameObject extends GrameObject { private static final long serialVersionUID = -480851231518169067L; - private int time=0; + private int time = 0; + public TestGrameObject(String name, int speed, Color color, boolean paused) { super(name, speed, color, paused); @@ -21,7 +21,7 @@ public boolean isCollidable() } @Override - public void tick(int bID) + public void tick(int gID) { //this.color=GrameUtils.randomColor(); time++; @@ -33,4 +33,3 @@ public void consume(GrameObject go) { } } - diff --git a/src/com/moomoohk/Grame/test/TestScript.java b/src/com/moomoohk/Grame/test/TestScript.java index ea4104d..e24ff0f 100644 --- a/src/com/moomoohk/Grame/test/TestScript.java +++ b/src/com/moomoohk/Grame/test/TestScript.java @@ -2,16 +2,16 @@ import java.awt.Color; -import com.moomoohk.Grame.AI.SimpleChaseAI; -import com.moomoohk.Grame.AI.SimpleStrollAI; import com.moomoohk.Grame.Basics.Entity; -import com.moomoohk.Grame.Essentials.Base; -import com.moomoohk.Grame.Essentials.Coordinates; -import com.moomoohk.Grame.Essentials.GrameManager; -import com.moomoohk.Grame.Essentials.GrameUtils; -import com.moomoohk.Grame.Graphics.RenderManager; -import com.moomoohk.Grame.Interfaces.GrameObject; -import com.moomoohk.Grame.Interfaces.MainGrameClass; +import com.moomoohk.Grame.Basics.AI.SimpleChaseAI; +import com.moomoohk.Grame.Basics.AI.SimpleStrollAI; +import com.moomoohk.Grame.Core.Coordinates; +import com.moomoohk.Grame.Core.GrameManager; +import com.moomoohk.Grame.Core.GrameObject; +import com.moomoohk.Grame.Core.GrameUtils; +import com.moomoohk.Grame.Core.Grid; +import com.moomoohk.Grame.Core.MainGrameClass; +import com.moomoohk.Grame.Core.Graphics.RenderManager; public class TestScript implements MainGrameClass { @@ -23,23 +23,23 @@ public static void main(String[] args) @Override public void newGame() { - Base b = new Base(20, 20); - b.setWraparound(true); + Grid g = new Grid(20, 20); + g.setWraparound(true); Entity ent = new Entity(Color.blue); ent.setSpeed(1); Entity ent2 = new Entity(); ent2.setTarget(ent.ID); ent2.setSpeed(7); - ent2.setRange(b.getDiagonal()); - ent2.addAI(new SimpleChaseAI(), b.ID); - ent2.addAI(new SimpleStrollAI(), b.ID); - ent.makePlayer(1, true, b.ID); + ent2.setRange(g.getDiagonal()); + ent2.addAI(new SimpleChaseAI(), g.ID); + ent2.addAI(new SimpleStrollAI(), g.ID); + ent.makePlayer(1, true, g.ID); GrameObject go = new GrameObject("test", 1, Color.black, false) { private static final long serialVersionUID = -7904811686747660223L; @Override - public void tick(int bID) + public void tick(int gID) { this.color = GrameUtils.randomColor(); } @@ -57,11 +57,10 @@ public void consume(GrameObject go) }; SpriteRender.objects.put(ent.ID, "player"); SpriteRender.objects.put(ent2.ID, "monster"); - b.addGrameObject(ent2, GrameUtils.randomCoordinates(b)); - b.addGrameObject(ent, new Coordinates(10, 10)); - b.addGrameObject(go, GrameUtils.randomCoordinates(b)); - GrameManager.addRender(new SpriteRender()); - RenderManager.render(b.ID, new SpriteRender()); + g.addGrameObject(ent2, GrameUtils.randomCoordinates(g)); + g.addGrameObject(ent, new Coordinates(10, 10)); + g.addGrameObject(go, GrameUtils.randomCoordinates(g)); + RenderManager.render(g.ID, new SpriteRender()); RenderManager.setVisible(true); } diff --git a/src/com/moomoohk/Grame/test/package-info.java b/src/com/moomoohk/Grame/test/package-info.java new file mode 100644 index 0000000..1d9605a --- /dev/null +++ b/src/com/moomoohk/Grame/test/package-info.java @@ -0,0 +1,7 @@ +/** + * Contains some test classes which shouldn't be touched or interacted with. + * + * @author Meshulam Silk (moomoohk@ymail.com) + * @since Feb 6, 2014 + */ +package com.moomoohk.Grame.test; \ No newline at end of file