@@ -4,6 +4,8 @@
* Contact: cj@cjcurrie.net
*/

// @INFO: This script is responsible for rendering zone data and performing simulation at the zone level

using UnityEngine;
using System;
using System.Collections;
@@ -12,19 +14,8 @@

public class ZoneManager : MonoBehaviour
{
[Serializable]
public class Count
{
public int minimum, maximum;

public Count(int min, int max)
{
maximum = max;
minimum = min;
}
}

// === Public ===
public GameObject boardPrefab;

public int columns = 8, rows = 8;

@@ -47,8 +38,17 @@ public Count(int min, int max)
float lastStep = 0.145f; //dy from top tile to first bot tile
bool right = false;

GameObject currentZoneObject;
public Zone currentZone;

public void Initialize ()
{
currentZone = new Zone();
currentZone.Generate(64);

currentZoneObject = RenderZone(currentZone);

/*
if (gridPositions == null)
gridPositions = new List<Vector2>();
else
@@ -71,25 +71,168 @@ public void Initialize ()
gridPositions.Add(new Vector2(x,y));
}
}
*/
}

GameObject RenderZone(Zone zone)
{
float side = .25f; // Main scaling unit for the hexagon

float root3 = Mathf.Sqrt(3);
float halfSide = side/2;
float height = root3 * side / 2;
float doubleHeight = height*2;
float sideAndAHalf = halfSide * 3;

Vector3 zonePlacement = new Vector3(-1*height*zone.width, 0, sideAndAHalf*zone.width/-2);
GameObject output = (GameObject)Instantiate(boardPrefab, zonePlacement, Quaternion.identity);

Renderer myRend = output.GetComponent<Renderer>();
MeshFilter myFilter = output.GetComponent<MeshFilter>();
MeshCollider myCollider = output.GetComponent<MeshCollider>();

List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
List<Vector3> normals = new List<Vector3>();
List<Vector2>uvs = new List<Vector2>();


Vector3 origin,
v1 = new Vector3(0,0,side),
v2 = new Vector3(height, 0, halfSide),
v3 = new Vector3(height, 0, -halfSide),
v4 = new Vector3(0,0,-side),
v5 = new Vector3(-height,0,-halfSide),
v6 = new Vector3(-height, 0, halfSide);

float texHeight = 868;
float texWidth = 1006;
Vector2 uv0 = new Vector2(503/texWidth,434/texHeight),
uv1 = new Vector2(754/texWidth, 1),
uv2 = new Vector2(1,.5f),
uv3 = new Vector2(uv1.x, 0),
uv4 = new Vector2(252/texWidth,0),
uv5 = new Vector2(0,.5f),
uv6 = new Vector2(uv4.x,1);

int counter = 0;

for (int x=0; x<zone.width; x++)
{
for (int y=0;y<zone.width; y++)
{
/*
1 = 0,side
6 2=height, side/2
origin(0)
5 3=height, -side/2
4= 0,-side
*/

float xOffset = x*doubleHeight;

if (y%2==1)
xOffset += height;
origin = new Vector3(xOffset, 0, y*sideAndAHalf);

// Add the first hexagon
vertices.Add(origin);
normals.Add(Vector3.up);
uvs.Add(uv0);

vertices.Add(origin+v1);
normals.Add(Vector3.up);
uvs.Add(uv1);

vertices.Add(origin+v2);
normals.Add(Vector3.up);
uvs.Add(uv2);

vertices.Add(origin+v3);
normals.Add(Vector3.up);
uvs.Add(uv3);

vertices.Add(origin+v4);
normals.Add(Vector3.up);
uvs.Add(uv4);

vertices.Add(origin+v5);
normals.Add(Vector3.up);
uvs.Add(uv5);

vertices.Add(origin+v6);
normals.Add(Vector3.up);
uvs.Add(uv6);
/*
.....
/ 6| /\
/ \ |1/ \
/ 5 \|/ 2 \
\ /4|3\ /
\/..|..\/
*/

// Triangle 1
triangles.Add(counter);
triangles.Add(counter+1);
triangles.Add(counter+2);
// Triangle 2
triangles.Add(counter);
triangles.Add(counter+2);
triangles.Add(counter+3);
// Triangle 3
triangles.Add(counter);
triangles.Add(counter+3);
triangles.Add(counter+4);
// Triangle 4
triangles.Add(counter);
triangles.Add(counter+4);
triangles.Add(counter+5);
// Triangle 5
triangles.Add(counter);
triangles.Add(counter+5);
triangles.Add(counter+6);
// Triangle 6
triangles.Add(counter);
triangles.Add(counter+6);
triangles.Add(counter+1);

counter += 7;
}
}


Mesh m = new Mesh();
m.vertices = vertices.ToArray();
m.triangles = triangles.ToArray();
m.normals = normals.ToArray();
m.uv = uvs.ToArray();

myCollider.sharedMesh = m;
myFilter.sharedMesh = m;

return output;
}

public void Update()
{
if(Input.GetKeyDown (KeyCode.LeftArrow))
{
right = false;
Rotate (right);
}
else if (Input.GetKeyDown (KeyCode.RightArrow))
{
right = true;
Rotate (right);
}
/*
if(Input.GetKeyDown (KeyCode.LeftArrow))
{
right = false;
Rotate (right);
}
else if (Input.GetKeyDown (KeyCode.RightArrow))
{
right = true;
Rotate (right);
}
*/
}

public void BoardSetup()
{
boardHolder = new GameObject("Zone Board").transform;
boardHolder = new GameObject("Zone Board").transform;
Transform bt = boardHolder.transform;

Hex hex = new Hex(hexRadius);
@@ -98,25 +241,25 @@ public void BoardSetup()
{
for (int x=0; x<columns; x++)
{
int randomHeight = Random.Range (0, 9);
int randomBorder = Random.Range(0, floorBorderTiles.Length);
int randomTiles = Random.Range (0, floorTiles.Length);
float topTileOffset = randomHeight*stepHeight+lastStep;
Vector2 tileCenter = hex.TileCenter (new Vector2(x,y));
//Vector2 topTile = hex.TileCenter (new Vector2(x,y+topTileOffset));
GameObject topInstantiate = floorTiles[randomTiles];
GameObject botInstantiate = floorBottomTiles[randomTiles]; //so, the top tiles and bottom tiles must have corresponding array indexes

int randomHeight = Random.Range (0, 9);
int randomBorder = Random.Range(0, floorBorderTiles.Length);
int randomTiles = Random.Range (0, floorTiles.Length);
float topTileOffset = randomHeight*stepHeight+lastStep;
Vector2 tileCenter = hex.TileCenter (new Vector2(x,y));
//Vector2 topTile = hex.TileCenter (new Vector2(x,y+topTileOffset));
GameObject topInstantiate = floorTiles[randomTiles];
GameObject botInstantiate = floorBottomTiles[randomTiles]; //so, the top tiles and bottom tiles must have corresponding array indexes
if(x == 0 || x == columns-1 || y == 0 || y == rows-1)
{
{
topInstantiate = floorBorderTiles [randomBorder];
botInstantiate = floorBottomBorderTiles [randomBorder];
}
GameObject instance = (GameObject)Instantiate (topInstantiate, tileCenter, Quaternion.identity);
Transform t = instance.transform;
t.Translate(0,topTileOffset,0);
t.parent = bt;
tiles.Add(instance);
botInstantiate = floorBottomBorderTiles [randomBorder];
}
GameObject instance = (GameObject)Instantiate (topInstantiate, tileCenter, Quaternion.identity);
Transform t = instance.transform;
t.Translate(0,topTileOffset,0);
t.parent = bt;
tiles.Add(instance);

//Now we need to fill below the top tiles we just made.
while(randomHeight > 0)
@@ -147,18 +290,18 @@ public void Rotate(bool right)
Right now this just rebuilds the board randomly when you press left or right arrows.
*/
if(right == false)
{
//Do something to make the board rotate left when board setup is called
BoardClear ();
BoardSetup();
}
else
{
//Do right
BoardClear ();
BoardSetup ();
}
if(right == false)
{
//Do something to make the board rotate left when board setup is called
BoardClear ();
BoardSetup();
}
else
{
//Do right
BoardClear ();
BoardSetup ();
}
}

public void BoardClear() //This deletes tiles correctly but it needs to destroy the zone board game object created in BoardSetup

This file was deleted.

@@ -0,0 +1,31 @@
using UnityEngine;
using System;
using System.Collections;

public enum TileType {None, Grass, Hill};

[Serializable]
public class Tile
{
public int height;

public TileType type;

public Tile(){}

public Tile(int h)
{
height = h;
}

public virtual void OnUnitEnter(){}
}

public class Tile_Grass : Tile
{
public override void OnUnitEnter()
{
Debug.Log("The grass rustles as a unit enters.");
// Some custom tile logic here
}
}
@@ -0,0 +1,101 @@
using UnityEngine;
using System;
using System.Collections;

public class Util
{

}

[Serializable]
public class Count
{
public int minimum, maximum;

public Count(int min, int max)
{
maximum = max;
minimum = min;
}
}

[Serializable]
public struct IntCoord
{
public int x,y;
public IntCoord(int a, int b)
{
x=a;
y=b;
}
}

[Serializable]
public class Line
{
public int x1, y1, x2, y2;

public Line(int xa, int ya, int xb, int yb)
{
/*
// Always sort the ends of a line so that x1<x2, or if x1=x2, then y1<y2
if (xa>xb)
{
x1=xb;y1=yb;x2=xa;y2=ya;
}
else if (xa==xb)
{
if(ya>yb)
{
x1=xb;y1=yb;
x2=xa;y2=ya;
}
else
{
x1=xa;y1=ya;
x2=xb;y2=yb;
}
}
else
{
// Do not perform any swap
x1 = xa; y1 = ya; x2 = xb; y2 = yb;
}
*/

x1 = xa; y1 = ya; x2 = xb; y2 = yb;
}

public override bool Equals(object ob)
{
if (ob is Line)
return LinesEqual(this, (Line)ob);
else
return false;
}

public static bool LinesEqual(Line l1, Line l2)
{
try
{
// L1 p1 matches L2 p1 and L1 p2 mtches L2 p2
if (( l1.x1==l2.x1 && l1.y1==l2.y1 ) && (l1.x2==l2.x2 && l1.y2==l2.y2))
return true;
// L1 p1 matches L2 p2 and L1 p2 mtches L2 p1 (reflection)
else if (( l1.x1==l2.x2 && l1.y1==l2.y2 ) && (l1.x2==l2.x1 && l1.y2==l2.y1))
return true;
else
return false;
}
catch
{
return false;
}
}

public override int GetHashCode()
{
// Note that hash tables won't work properly with this implementation
return 1234567890;
}
}

This file was deleted.

@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;

public enum WorldSize {None, Small, Medium, Large};
public enum WorldType {None, Verdant, Icy, Ocean, Barren, Volcanic, Radioactive, Gaseous};
public enum AxisTilt {None, Slight, Moderate, Severe}; // Affects intensity of difficulty scaling during seasons
public enum Season {None, Spring, Summer, Fall, Winter};


public class World {

public string name;

public WorldSize size;
public WorldType type;
public AxisTilt axisTilt;
public Season currentSeason;

Zone[] allZones;

}
@@ -0,0 +1,30 @@
using UnityEngine;
using System.Collections;

public class Zone {

Tile[,] tiles;
public int width;

ZoneRelationship[] neighbors;

public void Generate(int w)
{
width = w;
tiles = new Tile[width, width];

for (int x=0; x<width; x++)
{
for (int y=0; y<width; y++)
{
tiles[x,y] = new Tile(Random.Range(0,3));
}
}
}
}

public class ZoneRelationship
{
Zone other;
Vector3 otherDirection; // This is used to calculate apprx. where the door to the other zone should be placed
}
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;

public class ZoneViewCamera : MonoBehaviour {

Transform myTrans;
float speed = .1f;

public void Initialize ()
{
myTrans = transform;
}

// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
myTrans.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);

Debug.Log(touchDeltaPosition);
}

if (Input.GetMouseButton(0))
{
Vector2 touchDeltaPosition = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
myTrans.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
@@ -0,0 +1,2 @@
m_EditorVersion: 5.1.3f1
m_StandardAssetsVersion: 0
@@ -0,0 +1,2 @@
!.gitignore
*