From: <diz...@us...> - 2007-08-14 20:13:18
|
Revision: 71 http://fortress.svn.sourceforge.net/fortress/?rev=71&view=rev Author: dizzutch Date: 2007-08-14 13:13:13 -0700 (Tue, 14 Aug 2007) Log Message: ----------- adding first steps of mapgeneration tool/api Added Paths: ----------- trunk/mapgen/ trunk/mapgen/.MapGenerator.java.swp trunk/mapgen/.MapSection.java.swp trunk/mapgen/.Test.java.swp trunk/mapgen/MapGenerator.java trunk/mapgen/MapSection.java trunk/mapgen/Test.java Added: trunk/mapgen/.MapGenerator.java.swp =================================================================== (Binary files differ) Property changes on: trunk/mapgen/.MapGenerator.java.swp ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/mapgen/.MapSection.java.swp =================================================================== (Binary files differ) Property changes on: trunk/mapgen/.MapSection.java.swp ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/mapgen/.Test.java.swp =================================================================== (Binary files differ) Property changes on: trunk/mapgen/.Test.java.swp ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/mapgen/MapGenerator.java =================================================================== --- trunk/mapgen/MapGenerator.java (rev 0) +++ trunk/mapgen/MapGenerator.java 2007-08-14 20:13:13 UTC (rev 71) @@ -0,0 +1,57 @@ +import java.util.Random; + +public class MapGenerator { + private MapSection[][] map; + private int width; + private int height; + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public MapSection getMapSection(int height, int width) { + return map[height][width]; + } + + //Constructor + public MapGenerator(int width, int height) { + this.width = width; + this.height = height; + this.map = new MapSection[this.width][this.height]; + for(int h = 0; h < height; h++) { + for(int w = 0; w < width; w++) { + this.map[h][w] = new MapSection(); + } + } + } + + public void printMap() { + for(int h = 0; h < this.height; h++) { + for (int w = 0; w < this.width; w++) { + System.out.print(this.map[h][w].getHeight() + " "); + } + System.out.println(); + } + } + + public void generateMap_HillAlgorithm() { + Random rand = new Random(); + for (int i = 0; i < 1; i++) { + //generate random centerpoint + int x1 = rand.nextInt(this.height); + int y1 = rand.nextInt(this.width); + //generate random radius + int radius = rand.nextInt(this.width/2); + //for each point on the map, calculate height + for (int x2 = 0; x2 < this.height; x2++) { + for (int y2 = 0; y2 < this.width; y2++) { + map[x2][y2].setHeight((float)java.lang.Math.pow(radius, 2) - ((float)java.lang.Math.pow(x2-x1,2)) + ((float)java.lang.Math.pow(y2-y1,2))); + } + } + } + } +} Added: trunk/mapgen/MapSection.java =================================================================== --- trunk/mapgen/MapSection.java (rev 0) +++ trunk/mapgen/MapSection.java 2007-08-14 20:13:13 UTC (rev 71) @@ -0,0 +1,26 @@ +public class MapSection { + private float height; + private int type; + + //Constructor + public MapSection () { + this.height = 0; + this.type = 0; + } + + public float getHeight() { + return this.height; + } + + public int getType() { + return this.type; + } + + public void setHeight(float new_height) { + this.height = new_height; + } + + public void setType(int new_type) { + this.type = new_type; + } +} Added: trunk/mapgen/Test.java =================================================================== --- trunk/mapgen/Test.java (rev 0) +++ trunk/mapgen/Test.java 2007-08-14 20:13:13 UTC (rev 71) @@ -0,0 +1,8 @@ +public class Test { + public static void main(String argv[]) { + MapGenerator mg = new MapGenerator(10,10); + mg.printMap(); + mg.generateMap_HillAlgorithm(); + mg.printMap(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |