Skip to content

Commit

Permalink
Refactored the CellScript so that it is more intelligent and capable of
Browse files Browse the repository at this point in the history
having items "MoveTo" the attached object.  This abstracts lots of complicated
positioning of elements in the world, putting everything in world-space.
Furthermore, there are accessors and meta-data to allow for units to
interact with the map in high-level ways.  Partially worked funneling
selection through the CellScript, so all UI will be from camScript to
Cell Script to whatever inhabits the cell.
  • Loading branch information
Alex Morais committed Nov 25, 2012
1 parent 9c282ca commit 491b9c3
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 248 deletions.
Binary file modified Assets/Base.blend
Binary file not shown.
Binary file modified Assets/Base.prefab
Binary file not shown.
67 changes: 52 additions & 15 deletions Assets/BaseScript.js
Expand Up @@ -14,13 +14,15 @@ var unit_creation_waypoint : Vector2;
private var current_construction : String;
private var construction_in_progress : boolean = false;
private var construction_progress : float = 0;
private var world_position : Vector2;
private var world_position : Vector2 = Vector2(-1,-1);

var MAX_UNITS_PER_BASE = 15;
var CONSTRUCTION_TIME : float = 2;
var UNIT_DROP_X : float = 0;
var UNIT_DROP_Y : float = 0;

var target_position : Vector2;

function Start ()
{
// There are some limitations to this function wrt transform
Expand Down Expand Up @@ -77,6 +79,26 @@ function InitializeBase()
function SetPosition(x : int, y : int)
{
world_position = new Vector2(x,y);
target_position = new Vector2(x,y);
}

function GetPosition() : Vector2
{
return world_position;
}

function SetTarget(x : int, y : int)
{
target_position = new Vector2(x,y);
}

function Selected(selected : boolean) : boolean
{
// TODO: Do a Selected animation

// TODO: React to being selected in some way

return true;
}

function SetBaseType(type : String)
Expand All @@ -97,17 +119,17 @@ function SetBaseType(type : String)
}
}

function GetBaseType()
function GetBaseType() : String
{
return baseType;
}

function GetForkerCount()
function GetForkerCount() : int
{
return forkerCount;
}

function GetBrancherCount()
function GetBrancherCount() : int
{
return brancherCount;
}
Expand All @@ -116,7 +138,7 @@ function SetPlayerType(isPlayer : boolean)
{
player = isPlayer;
}
function IsPlayer()
function IsPlayer() : boolean
{
return player;
}
Expand All @@ -127,7 +149,7 @@ function SetBaseColor(color : Color)
gameObject.transform.GetChild(0).renderer.material.color = color;
}

function FormatUnitName(unit : String)
function FormatUnitName(unit : String) : String
{
return String.Format("{0}_{1}_{2}",
unit,
Expand All @@ -139,8 +161,9 @@ function CreateUnit(unit : String)
{
var name : String = FormatUnitName(unit);
var modifier : int = 1;
var newUnit : Transform;

if(15 > gameObject.transform.position.x)
if(15 > world_position.y)
{
modifier *= -1;
}
Expand All @@ -151,42 +174,56 @@ function CreateUnit(unit : String)
switch(unit)
{
case "forker":
CreateForker(UNIT_DROP_X, UNIT_DROP_Y, name);
newUnit = CreateForker(UNIT_DROP_X, UNIT_DROP_Y, name);
break;
case "brancher":
CreateBrancher(UNIT_DROP_X, UNIT_DROP_Y, name);
newUnit = CreateBrancher(UNIT_DROP_X, UNIT_DROP_Y, name);
break;
}

var unitScript = GameObject.Find(name).GetComponent(UnitScript);
var unitScript : UnitScript = newUnit.GetComponent(UnitScript);
unitScript.SetTeam(player);
unitScript.SetHomeBase(gameObject.transform);
unitScript.SetPosition(UNIT_DROP_X,UNIT_DROP_Y);
}

/*
function SetupPiece(piece : Transform, x : int, y : int, z : float, name : String)
{
GameObject.Find("HexPlain").GetComponent(HexBoardScript).SetupPiece(piece, x, y, z, name);
}
*/

function CreateForker(x : int, y : int, name : String)
function MoveTo(piece : Transform, x : int, y : int)
{
GameObject.Find(String.Format("HexPlain/_{0}_{1}_", x, y)).GetComponent(CellScript).MoveTo(piece);
}

function CreateForker(x : int, y : int, name : String) : Transform
{
var forkerClone : Transform = Instantiate(forker);
forkerClone.name = name;

SetupPiece(forkerClone, x, y, z_placement, name);
/*SetupPiece(forkerClone, x, y, z_placement, name);*/
MoveTo(forkerClone, x, y);

forkerCount++;
number_of_forkers_alive++;

return forkerClone;
}

function CreateBrancher(x : int, y : int, name : String)
function CreateBrancher(x : int, y : int, name : String) : Transform
{
var brancherClone : Transform = Instantiate(brancher);
brancherClone.name = name;

SetupPiece(brancherClone, x, y, z_placement, name);
/*SetupPiece(brancherClone, x, y, z_placement, name);*/
MoveTo(brancherClone, x, y);

brancherCount++;
number_of_branchers_alive++;

return brancherClone;
}

function UnitDeath(unit : String)
Expand Down
Binary file modified Assets/Branch.prefab
Binary file not shown.
Binary file modified Assets/BranchBush.prefab
Binary file not shown.
45 changes: 28 additions & 17 deletions Assets/BushScript.js
Expand Up @@ -3,53 +3,64 @@
var branch : Transform;

private var branchCount : int = 4;
private var world_position : Vector2;
private var world_position : Vector2 = Vector2(-1,-1);

function Start ()
{
}

function Update ()
{
if(0 >= branchCount)
{
Destroy(gameObject);
}
}

function Selected(selected : boolean) : boolean
{
return false;
}

function SetPosition(x : int, y : int)
{
world_position = new Vector2(x,y);
}

function CreateBranch(x : int, y : int)
function GetPosition() : Vector2
{
var name : String = String.Format("branch_{0}", branchCount);
var branchClone : Transform = Instantiate(branch);

GameObject.Find("HexPlain").GetComponent(HexBoardScript).SetupPiece(branchClone, x, y, 2, name);

GameObject.Find(name).GetComponent(PickupScript).SetPosition(x,y);
branchCount++;
return world_position;
}

function TakeBranch()
function GetBranch(x : int, y : int) : Transform
{
branchCount--;
var branch : Transform = null;

if(0 < branchCount)
{
var name : String = String.Format("branch_{0}", branchCount);
branchCount--;
branch = Instantiate(branch);
}

return branch;
}

function GetBranchCount()
{
return branchCount;
}

function GetCellScript()
function GetCellScript() : CellScript
{
return GameObject.Find(String.Format("HexPlain/_{0}_{1}_", world_position.x, world_position.y)).GetComponent(CellScript);
}


function Target()
function Targeted(selection : Transform)
{
GetCellScript().Targeted(true);
}
function UnTarget()

function DoSelectedGUI(rect : Rect)
{
GetCellScript().Targeted(false);
}

0 comments on commit 491b9c3

Please sign in to comment.