-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terrain generation program and tile rendering
Began as a massive project - intended to create fully interactive world with universal reputation system. Got stuck in the design of a lot of features, but did end up with a wonderful tile renderer and terrain generation system. Uses diamond square algorithm to generate terrain - but can be generated tile by tile, allowing for (potentially) infinite worlds without having extreme memory issues. I will probably end up rewriting this and removing all the fluff so it can be implemented into future projects. Really flexible grid based terrain generation.
- Loading branch information
philipandresen
authored and
philipandresen
committed
Jul 20, 2015
1 parent
1fee7e3
commit c82239b
Showing
73 changed files
with
2,316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>LoreCraft</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.62 KB
bin/Levels/AStar_algorithm_by_kevin_glass/AStarPathFinder$SortedList.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package Game; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ArrayList3D<T> { | ||
private ArrayList<ArrayList<ArrayList<T>>> theArray = new ArrayList<ArrayList<ArrayList<T>>>(); | ||
|
||
public ArrayList3D(int hSize, int vSize){ | ||
for (int i = 0 ; i< hSize; i++){ | ||
theArray.add(i, new ArrayList<ArrayList<T>>()); | ||
for (int j = 0 ; j < vSize ; j++){ | ||
theArray.get(i).add(j, new ArrayList<T>()); | ||
} | ||
} | ||
} | ||
|
||
public T get3D(int x, int y, int z){ | ||
return theArray.get(x).get(y).get(z); | ||
} | ||
|
||
public void add3D(T newObject, int x, int y, int z){ | ||
theArray.get(x).get(y).add(z, newObject); | ||
} | ||
public void addLast3D(T newObject,int x, int y){ | ||
int z = theArray.get(x).get(y).size(); | ||
theArray.get(x).get(y).add(z, newObject); | ||
} | ||
public void removeFirst3D(int x, int y){ | ||
theArray.get(x).get(y).remove(0); | ||
} | ||
public void removeLast3D(int x, int y){ | ||
int index = theArray.get(x).get(y).size(); | ||
theArray.get(x).get(y).remove(index); | ||
} | ||
public int getDims() { | ||
return theArray.size(); | ||
} | ||
public int getDims(int x){ | ||
return theArray.get(x).size(); | ||
} | ||
public int getDims(int x, int y){ | ||
return theArray.get(x).get(y).size(); | ||
} | ||
public void clearTiles(int x, int y){ | ||
theArray.get(x).get(y).clear(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Game; | ||
|
||
public enum Direction { | ||
North, | ||
South, | ||
East, | ||
West; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package Game; | ||
|
||
import GameObjects.*; | ||
import Levels.World; | ||
|
||
import java.awt.Color; | ||
import java.awt.Font; | ||
import java.awt.Graphics2D; | ||
import java.awt.geom.AffineTransform; | ||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
|
||
|
||
public class Handler{ | ||
|
||
static KeyInput keyinput; | ||
static int gridSize = LoreCraft.GRIDSIZE; | ||
static ArrayList<Entity> EntityList = new ArrayList<Entity>(); | ||
|
||
public Handler(KeyInput keyinput){ | ||
Handler.keyinput = keyinput; | ||
} | ||
|
||
static ArrayList<GameObject> objectlist = new ArrayList<GameObject>(); | ||
public static AffineTransform windowTform = new AffineTransform(); | ||
public static double viewWScale = 0.2, viewHScale = 0.2; | ||
public static ID viewTarget = ID.Player; | ||
public static double windowX = 0, windowY = 0, windowWidth, windowHeight; | ||
static boolean didtick = false; | ||
|
||
public static void tick(){ | ||
windowWidth=LoreCraft.WIDTH/viewWScale; | ||
windowHeight=LoreCraft.HEIGHT/viewHScale; | ||
for(int i = 0; i < objectlist.size(); i++){ | ||
GameObject tempobject = objectlist.get(i); | ||
tempobject.tick(keyinput); | ||
if(tempobject.id == viewTarget){ | ||
//windowX=tempobject.getX()*gridSize-windowWidth/2; | ||
//windowY=tempobject.getY()*gridSize-windowHeight/2; | ||
} | ||
} | ||
} | ||
|
||
public static void render(Graphics2D g2){ | ||
windowTform.setToIdentity(); | ||
windowTform.scale(viewWScale, viewHScale); | ||
windowTform.translate(-windowX,-windowY); | ||
g2.setTransform(Handler.windowTform); | ||
/*g2.setColor(new Color(0.5F, 0.5F, 0.5F, 1F)); | ||
for(int i = 0; i<HelloWorld.currentLevel.Width ; i = i+200){ | ||
g2.drawLine(i,0,i,HelloWorld.currentLevel.Height); | ||
} | ||
for(int j = 0; j<HelloWorld.currentLevel.Height ; j = j+200){ | ||
g2.drawLine(0,j,HelloWorld.currentLevel.Width,j); | ||
}*/ | ||
|
||
LoreCraft.currentLevel.render(g2); | ||
g2.setColor(Color.WHITE); | ||
String debugstr = Boolean.toString(didtick); | ||
g2.setFont(new Font("Serif",Font.PLAIN,12)); | ||
g2.drawString(debugstr, 16, 16); | ||
didtick=false; | ||
|
||
for(int i = 0; i < objectlist.size(); i++){ | ||
GameObject tempobject = objectlist.get(i); | ||
/*if(!(tempobject.getX()*gridSize<windowX) && !(tempobject.getX()*gridSize>windowX+windowWidth) | ||
&& !(tempobject.getY()*gridSize<windowY) && !(tempobject.getY()*gridSize>windowY+windowHeight)){ | ||
tempobject.render(g2); | ||
}8]*/ | ||
} | ||
g2.setColor(Color.WHITE); | ||
/*String debugstr = Integer.toString(objectlist.size()); | ||
g2.setFont(new Font("Serif",Font.PLAIN,12)); | ||
g2.drawString(debugstr, 16, 16);*/ | ||
|
||
} | ||
|
||
public static void addObject(GameObject newObject){ | ||
objectlist.add(newObject); | ||
} | ||
public static void removeObject(GameObject oldObject){ | ||
objectlist.remove(oldObject); | ||
oldObject = null; | ||
} | ||
|
||
public static void addEntity(GameObject newObject, World world, int x, int y){ | ||
|
||
} | ||
|
||
|
||
|
||
public static LinkedList<GameObject> findObject(ID checkID){ | ||
LinkedList<GameObject> objList = new LinkedList<GameObject>(); | ||
for(GameObject tempObj : objectlist){ | ||
if(tempObj.id == checkID){ | ||
objList.add(tempObj); | ||
} | ||
} | ||
return objList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package Game; | ||
|
||
public enum ID { | ||
Player(), | ||
Enemy(), | ||
Particle(), | ||
Water(), | ||
Solid(), | ||
Village(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package Game; | ||
|
||
|
||
import java.awt.event.KeyAdapter; /// WHAT | ||
import java.awt.event.KeyEvent; | ||
import java.util.ArrayList; | ||
|
||
|
||
public class KeyInput extends KeyAdapter{ | ||
|
||
private ArrayList<Integer> KeyList = new ArrayList<Integer>(); | ||
private ArrayList<Integer> IgnoreList = new ArrayList<Integer>(); | ||
|
||
public KeyInput (){//constructor | ||
|
||
} | ||
|
||
public void keyPressed(KeyEvent e){ | ||
int key = e.getKeyCode(); | ||
addKey(key, KeyList); | ||
} | ||
|
||
public void keyReleased(KeyEvent e){ | ||
int key = e.getKeyCode(); | ||
removeKey(key, KeyList); | ||
removeKey(key, IgnoreList); | ||
} | ||
|
||
private boolean addKey(int key, ArrayList<Integer> list){ //add a key to the list of keys being held down | ||
int Found = 0; | ||
for(int i = 0; i < list.size(); i++){ | ||
if (list.get(i) == key){ | ||
Found = 1; | ||
break; | ||
} | ||
} | ||
if (Found == 1){ | ||
return false; | ||
} else { | ||
list.add(key); | ||
return true; | ||
} | ||
} | ||
|
||
private boolean removeKey(int key, ArrayList<Integer> list){ //remove a key from the list of keys being held down | ||
int Found = 0; | ||
int FoundAt = 0; | ||
for(int i = 0; i < list.size(); i++){ | ||
if (list.get(i) == key){ | ||
Found = 1; | ||
FoundAt = i; | ||
break; | ||
} | ||
} | ||
if (Found == 1){ | ||
list.remove(FoundAt); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public ArrayList<Integer> getKeyList(){//return the list of keys pressed | ||
return KeyList; | ||
} | ||
|
||
public boolean isPressed(int key){ //return if key is contained in list | ||
int Found = 0; | ||
for(int i = 0; i < KeyList.size(); i++){ | ||
if (KeyList.get(i) == key){ | ||
Found = 1; | ||
break; | ||
} | ||
} | ||
if (Found == 1){ | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public boolean justPressed(int key){ //same as isPressed but should only happen once per press. | ||
boolean ignored = false; | ||
for(int i = 0; i < IgnoreList.size(); i++){ | ||
if(IgnoreList.get(i) == key){ | ||
ignored = true; | ||
break; | ||
} | ||
} | ||
if(isPressed(key) && (ignored == false)){ | ||
addKey(key, IgnoreList); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.