| 01-23-2004, 12:22 AM | #1 |
Ok I got half bored today, so I decided to try out making a class using the Fraction class as a template. I created a PointXY class, which is essentially just an x and y coordinate. Not sure how much of a use people will have for this, but here it is anyway: Code:
//Class: PointXY
//Function: Somewhat replicates locations using XY coords
//Constuctors
//Takes an X and Y coord
function CreatePointXY takes string name,real x, real y returns nothing
call StoreReal(InitGameCache("PointXY.w3v"), name, "x", x)
call StoreReal(InitGameCache("PointXY.w3v"), name, "y", y)
endfunction
//Takes a widget
function CreatePointXY_Widget takes string name, widget whichWidget returns nothing
call StoreReal(InitGameCache("PointXY.w3v"), name, "x", GetWidgetX(whichWidget))
call StoreReal(InitGameCache("PointXY.w3v"), name, "y", GetWidgetY(whichWidget))
endfunction
//Takes X and Y coords, stores polar projection
function CreatePointXY_Polar takes string name, real x, real y, real angle, real distance returns nothing
call StoreReal(InitGameCache("PointXY.w3v"), name, "x", x + CosBJ(angle) * distance)
call StoreReal(InitGameCache("PointXY.w3v"), name, "y", y + SinBJ(angle) * distance)
endfunction
//deconstructor
function DestroyPointXY takes string name returns nothing
call FlushStoredMission(InitGameCache("PointXY.w3v"),name)
endfunction
//accessor methods
function GetX takes string name returns real
return GetStoredReal(InitGameCache("PointXY.w3v"),name,"x")
endfunction
function GetY takes string name returns real
return GetStoredReal(InitGameCache("PointXY.w3v"),name,"y")
endfunction
//modifier methods
function SetX takes string name,integer newX returns nothing
call StoreReal(InitGameCache("PointXY.w3v"),name,"x",newX)
endfunction
function SetY takes string name,integer newY returns nothing
call StoreReal(InitGameCache("PointXY.w3v"),name,"x",newY)
endfunction
//comparison methods
function PointXYEqual takes string point1, string point2 returns boolean
return (GetX(point1) == GetX(point2)) and (GetY(point1) == GetY(point2))
endfunction
//conversion methods
function PointXY2S takes string name returns string
return ("(" + R2S(GetX(name)) + ", " + R2S(GetY(name)) + ")")
endfunction
//other
function IssuePointXYOrder takes unit whichUnit, string order, string point returns nothing
call IssuePointOrder(whichUnit,order, GetX(point), GetY(point))
endfunction
function AngleBetweenPointXY takes string point1, string point2 returns real
return Atan2BJ(GetY(point1) - GetY(point2), GetX(point1) - GetX(point2))
endfunction
function DistanceBetweenPointXY takes string point1, string point2 returns real
local real dx = GetX(point1) - GetX(point2)
local real dy = GetY(point1) - GetY(point2)
return SquareRoot(dx * dx + dy * dy)
endfunction |
| 01-23-2004, 04:09 PM | #2 |
It would be more Usefull if you added a Z point as private data as whell . Good job so far. You clould add some more code and create your own location system. |
