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