Skip to content

Commit

Permalink
Terrain generation program and tile rendering
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 73 changed files with 2,316 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
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>
17 changes: 17 additions & 0 deletions .project
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>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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 added Graphics/Environ_tileset1.bmp
Binary file not shown.
Binary file added Graphics/MasterTileSetAlpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/Standard2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/grayscaleHeightmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/heightmapTexture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/mans.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/roguelikecreatures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/set_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/tilesetprev7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/village1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bin/Game/ArrayList3D.class
Binary file not shown.
Binary file added bin/Game/Direction.class
Binary file not shown.
Binary file added bin/Game/Handler.class
Binary file not shown.
Binary file added bin/Game/ID.class
Binary file not shown.
Binary file added bin/Game/KeyInput.class
Binary file not shown.
Binary file added bin/Game/LoreCraft.class
Binary file not shown.
Binary file added bin/Game/Window.class
Binary file not shown.
Binary file added bin/GameObjects/Entity.class
Binary file not shown.
Binary file added bin/GameObjects/GameObject.class
Binary file not shown.
Binary file added bin/GameObjects/Player.class
Binary file not shown.
Binary file added bin/GameObjects/Village.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 added bin/Levels/Continent.class
Binary file not shown.
Binary file added bin/Levels/GridUnit.class
Binary file not shown.
Binary file added bin/Levels/LoadableLevel.class
Binary file not shown.
Binary file added bin/Levels/MicroWorld.class
Binary file not shown.
Binary file added bin/Levels/StaticWorldUnit.class
Binary file not shown.
Binary file added bin/Levels/TerrainOrganizer.class
Binary file not shown.
Binary file added bin/Levels/World.class
Binary file not shown.
Binary file added bin/Levels/WorldSquare.class
Binary file not shown.
Binary file not shown.
Binary file added bin/tileSets/Tile.class
Binary file not shown.
Binary file added bin/tileSets/TileSet.class
Binary file not shown.
48 changes: 48 additions & 0 deletions src/Game/ArrayList3D.java
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();
}

}
8 changes: 8 additions & 0 deletions src/Game/Direction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Game;

public enum Direction {
North,
South,
East,
West;
}
101 changes: 101 additions & 0 deletions src/Game/Handler.java
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;
}
}
10 changes: 10 additions & 0 deletions src/Game/ID.java
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();
}
99 changes: 99 additions & 0 deletions src/Game/KeyInput.java
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;
}
}


}
Loading

0 comments on commit c82239b

Please sign in to comment.