Browse files

v2

Chose landing region based on search criteria
Identify all mountains
Identify nearby mountains relative to landing region
  • Loading branch information...
1 parent 00b4060 commit 73eda2ee9eb11d779d569a1c5567a4303a5e4a41 @UnknownGuardian committed Apr 29, 2012
Showing with 108 additions and 11 deletions.
  1. BIN bin/City2.swf
  2. +63 −0 src/Explorer.as
  3. +10 −2 src/Main.as
  4. +35 −9 src/Settler.as
View
BIN bin/City2.swf
Binary file not shown.
View
63 src/Explorer.as
@@ -0,0 +1,63 @@
+package
+{
+ import flash.display.BitmapData;
+ import flash.geom.Point;
+ import flash.geom.Rectangle;
+ /**
+ * ...
+ * @author UnknownGuardian
+ */
+ public class Explorer
+ {
+ public static var betterPoints:Array;
+ public var divisions:int = 10;
+ public var mountainColor:int = 0xFFAA0000
+ public var betterColor:int = 0xFFDD0000
+ public var explorerTravelDistance:int = 200;
+ public function Explorer()
+ {
+
+ }
+
+ public function start(startLoc:Point):void
+ {
+
+ var w:BitmapData = Main.world;
+ var o:BitmapData = Main.infoOverlay;
+
+ var v:Vector.<uint> = w.getVector(new Rectangle(0, 0, w.width, w.height));
+ var goodPoints:Array = [];
+ for (var i:int = 0; i < w.width; i += divisions)
+ {
+ for (var j:int = 0; j < w.width; j += divisions)
+ {
+ var c:uint = w.getPixel(i, j);
+ if (c < 0x666666 && c > Main.WATER_COLOR)
+ {
+ o.setPixel32(i, j, mountainColor);
+ goodPoints.push(i, j);
+ }
+ }
+ }
+
+ betterPoints = [];
+ for (var s:int = 0; s < goodPoints.length; s+=2)
+ {
+ if (getDistanceSquared(goodPoints[s], goodPoints[s + 1],startLoc.x,startLoc.y) < explorerTravelDistance*explorerTravelDistance)
+ {
+ o.fillRect(new Rectangle(goodPoints[s] - 2, goodPoints[s + 1] - 2, 4, 4), betterColor);
+ betterPoints.push(new Point(goodPoints[s], goodPoints[s + 1]));
+ }
+ }
+
+
+ }
+
+ static public function getDistanceSquared(dx:Number, dy:Number, tx:Number, ty:Number):Number
+ {
+ return (dx - tx) * (dx - tx) + (dy - ty)*(dy - ty);
+ }
+
+ }
+
+}
View
12 src/Main.as
@@ -4,6 +4,7 @@ package
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
+ import flash.geom.Point;
/**
* ...
@@ -13,8 +14,10 @@ package
{
public var ter:TerrainGenerator = new TerrainGenerator();
public static var world:BitmapData = new BitmapData(800, 600, false);
+ public static var infoOverlay:BitmapData = new BitmapData(800, 600, true,0x00000000);
//public static var world2:BitmapData = new BitmapData(400, 600, false);
public static var worldHolder:Bitmap = new Bitmap(world);
+ public static var overlayHolder:Bitmap = new Bitmap(infoOverlay);
//public static var worldHolder2:Bitmap = new Bitmap(world2);
public static var WATER_COLOR:uint = 40;
@@ -27,18 +30,23 @@ package
else addEventListener(Event.ADDED_TO_STAGE, init);
}
- private function init(e:Event = null):void
+ private function init(event:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
addChild(worldHolder);
+ addChild(overlayHolder);
//worldHolder2.x = 800;
//addChild(worldHolder2);
ter.start();
var s:Settler = new Settler();
- s.start();
+ var startLoc:Point = s.start();
+
+ var e:Explorer = new Explorer();
+ e.start(startLoc);
+
}
}
View
44 src/Settler.as
@@ -1,22 +1,29 @@
package
{
import flash.display.BitmapData;
+ import flash.geom.Point;
+ import flash.geom.Rectangle;
/**
* ...
* @author UnknownGuardian
*/
public class Settler
{
public var divisions:int = 10;
- public var divisionColor:uint = 0xFF00FF;
+ public var divisionColor:uint = 0xFF00AA00;
+ public var goodPointsColor:uint = 0xFF00DD00;
+ public var betterPointsColor:uint = 0xFF00FF00;
+ public var chosenColor:uint = 0xFF00FF00;
+ public var betterPointsEdgeThreshold:int = 60;
public function Settler()
{
}
- public function start():void
+ public function start():Point
{
var w:BitmapData = Main.world;
+ var o:BitmapData = Main.infoOverlay;
var goodPoints:Array = [];
@@ -27,32 +34,51 @@ package
{
if (w.getPixel(i, j) == Main.WATER_COLOR)
{
- w.setPixel(i, j, 0xFF00FF);
+ o.setPixel32(i, j, divisionColor);
var neighborsColor:Array = [w.getPixel(i + 10, j + 10), w.getPixel(i + 10, j - 10), w.getPixel(i - 10, j + 10), w.getPixel(i - 10, j - 10)];
- if (neighborsColor[0] != Main.WATER_COLOR && neighborsColor[0]!= divisionColor )
+ if (neighborsColor[0] != Main.WATER_COLOR )
{
goodPoints.push(i + 10, j + 10);
}
- if (neighborsColor[1] != Main.WATER_COLOR && neighborsColor[1]!= divisionColor )
+ if (neighborsColor[1] != Main.WATER_COLOR )
{
goodPoints.push(i + 10, j - 10);
}
- if (neighborsColor[2] != Main.WATER_COLOR && neighborsColor[2]!= divisionColor )
+ if (neighborsColor[2] != Main.WATER_COLOR )
{
goodPoints.push(i - 10, j + 10);
}
- if (neighborsColor[3] != Main.WATER_COLOR && neighborsColor[3]!= divisionColor )
+ if (neighborsColor[3] != Main.WATER_COLOR )
{
goodPoints.push(i - 10, j - 10);
}
}
}
}
-
+ var betterPoints:Array = [];
for (var s:int = 0; s < goodPoints.length; s+=2)
{
- w.setPixel(goodPoints[s], goodPoints[s + 1], 0x00FF00);
+ o.setPixel32(goodPoints[s], goodPoints[s + 1], goodPointsColor);
+ if (goodPoints[s] > betterPointsEdgeThreshold && goodPoints[s] < w.width - betterPointsEdgeThreshold && goodPoints[s + 1] > betterPointsEdgeThreshold && goodPoints[s + 1] < w.height - betterPointsEdgeThreshold)
+ {
+ o.fillRect(new Rectangle(goodPoints[s] - 1, goodPoints[s + 1] - 1, 3, 3), betterPointsColor);
+ betterPoints.push(new Point(goodPoints[s], goodPoints[s + 1]));
+ }
+ }
+
+ //junk map check
+ if (betterPoints.length == 0)
+ {
+ betterPoints[0] = new Point(w.width / 2, w.height / 2);
}
+
+ var theChosenOne:Point = betterPoints[int(Math.random() * betterPoints.length)];
+ o.fillRect(new Rectangle(theChosenOne.x-3, theChosenOne.y - 3, 7, 7), chosenColor);
+ o.fillRect(new Rectangle(theChosenOne.x-1, theChosenOne.y - 1, 3, 3), 0x00000000);
+
+
+ return theChosenOne;
+
}
}

0 comments on commit 73eda2e

Please sign in to comment.