|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis project's primary objective is to observe C#'s behavior, when delivering hundreds of vision enabled objects, to be drawn by the DirectDraw wrapper (DDW) for Managed Code. If primary objective is achieved and C#/DDW evaluates to be a solid project foundry working environment, the project's direction goes to creating a game-like tile world, with hundreds of visible standing and moving objects. Using the codeBy design, all methods should return null on success, or in case of failure, the exception generated within. Here is a list of class descriptions.
As states may accumulate (in future use), unit might want to STAND but also public enum ACTION_BASIC
{
STOPPED=0,
STOPPING,
ROTATE_LEFT,
ROTATE_RIGTH,
MOVE_FORWARD,
MOVE_BACKWARD,
RUN_FORWARD,
RUN_BACKWARD,
UNABLE_TO_MOVE,
SLIDE_LEFT,
SLIDE_RIGTH,
}
public BitArray m_ACTION_BASIC = new BitArray(new bool[11]
{true,false,false,false,false,false,false,false,false,false,false});
Calls are made with very simple get/set methods: //
if (this.m_ACTION_BASIC.Get((int)ACTION_BASIC.ROTATE_LEFT))
this.Angle += this.m_TurnVelocity / m_FPS;//
m_ACTION_BASIC.Set((int)ACTION_BASIC.STOPPED,true);
Most important call to DDW is s.Draw( // Surface to write to
new Rectangle( // writeto: In this case the screen coordinates rectangle
(int)m_X,
(int)m_Y,
m_CSprite.m_FrameWidth,
m_CSprite.m_FrameHeigth
),
m_CSprite.m_Surface.m_Surface, // Surface to read from
new Rectangle( // readfrom: In this case the sprite coordinates rectangle
(m_Frame % m_CSprite.m_NFrameX)*m_CSprite.m_FrameWidth,
(m_Frame / m_CSprite.m_NFrameX)*m_CSprite.m_FrameHeigth,
m_CSprite.m_FrameWidth,
m_CSprite.m_FrameHeigth
),
DrawFlags.KeySource|DrawFlags.Wait // drawing flags
);
Easy reading, readers say. Actually it's very very easy, the first rectangle holds the surface to write to The second rectangle holds the surface to read from, surface from
Bitmap file loaded and stored as CUnitManagerResponsible for initializing units. Holds all initialized units on a linked list named public class UNITLIST
{
private object pPrev;
private object pNext;
private CUnit pItem;
public UNITLIST _PREV {get{return (UNITLIST)pPrev;}
set{pPrev = (UNITLIST)value;}}
public UNITLIST _NEXT {get{return (UNITLIST)pNext;}
set{pNext = (UNITLIST)value;}}
public CUnit _UNIT {get{return pItem;}set{pItem = value;}}
}
In the example method below, public System.Exception Draw(Microsoft.DirectX.DirectDraw.Surface s)
{
try
{
UNITLIST ul = pHead;
for (int i = 0; i < m_Count; i++)
{
ul._UNIT.Draw(s);
ul = ul._NEXT;
}
return null;
}
catch(Exception e)
{
this.m_Trace.T("CUnitManager::Draw>"+e);
return e;
}
}
CUtilsThis class holds 2D math actually. Each unit position is characterized as a x,y,angle VECTOR structure. These methods have small use in the present version but they will be very important when, in next version, as example: units try to move from point p1 to mouse-clicked point p2. The decision to include them in the present version demonstrates the concern about the accuracy of these calculations and gives readers time to criticize. Go nuts // thank you. DistancePercentageFromOrigin(VECTOR vInicial,VECTOR vFinal,VECTOR vCurrent)public double DistancePercentageFromOrigin(VECTOR vInicial,
VECTOR vFinal, VECTOR vCurrent)
{
double dInicial=Math.Sqrt(Math.Pow((vFinal.x-vInicial.x),2) +
Math.Pow((vFinal.y-vInicial.y),2));
double dCurrent=Math.Sqrt(Math.Pow((vFinal.x-vCurrent.x),2) +
Math.Pow((vFinal.y-vCurrent.y),2));
if (dInicial==0)
return 0;
return dCurrent*100/dInicial;
}
InternalProduct(VECTOR v1, VECTOR v2) public double InternalProduct(VECTOR v1, VECTOR v2)
{
return v1.x*v2.x+v1.y*v2.y;
}
Modulus(VECTOR v1)public double Modulus(VECTOR v1)
{
return Math.Sqrt(Math.Pow(v1.x,2)+Math.Pow(v1.y,2));
}
AngleBetweenTwoVectorsWithSameOrigin(VECTOR v1, VECTOR v2)public double AngleBetweenTwoVectorsWithSameOrigin(VECTOR v1, VECTOR v2)
{
double m1=Modulus(v1)*Modulus(v2);
if (m1==0)
return 0;
double m2=InternalProduct(v1,v2)/m1;
return Math.Acos(m2);
}
DecideLeftRigthOnAngle(VECTOR v1, double dAngle)public int DecideLeftRigthOnAngle(VECTOR v1, double dAngle)
{
if (v1.x*-1*Math.Sin(dAngle)<=Math.Cos(dAngle)*v1.y)
return -1;
return 1;
}
CTraceAs this is a full-screen application and there is no IDE, thus no debug; the project includes a text file debug engine. Points of Interest
History
|
||||||||||||||||||||||