1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
class Unit
{
private:
double x,y;
double xSpeed,ySpeed;
double angle;
double angleGoal;
int xGoal,yGoal;
int memberOf;
int gateOf;
int enzymeOf;
Status status;
int ID;
UnitType type;
double maxSpeed;
bool selected;
public:
Unit();
Unit( int X, int Y, UnitType t );
void step();
void set_goal( int X, int Y );
void show();
double getX();
double getY();
void select();
void unselect();
bool getSelected();
};
Unit::Unit()
{
}
Unit::Unit( int X, int Y, UnitType t )
{
x = X;
y = Y;
xSpeed = 0;
ySpeed = 0;
angle = 0;
angleGoal = 0;
xGoal = -1;
yGoal = -1;
memberOf = -1;
gateOf = -1;
enzymeOf = -1;
status = IDLE;
ID = unitCurrentID;
unitCurrentID++;
if ( unitCurrentID == MAX_UNITS )
{
unitCurrentID = 0;
}
type = t;
maxSpeed = 0.5;
selected = false;
}
void Unit::step()
{
x += xSpeed;
y += ySpeed;
if ( ( abs(xGoal-x)<=1 ) && ( abs(yGoal-y)<=1 ) )
{
xSpeed = 0;
ySpeed = 0;
}
}
void Unit::set_goal( int X, int Y )
{
xGoal = X;
yGoal = Y;
xSpeed = lengthdir_x( x, y, X, Y, maxSpeed );
ySpeed = lengthdir_y( x, y, X, Y, maxSpeed );
}
void Unit::show()
{
switch( type )
{
case UT_CIRCLE: DrawCircle( (float)x, (float)y, 10, 20, true, 0.0f, 1.0f, 0.0f );
if ( selected )
{
DrawCircle( (float)x, (float)y, 12, 25, false, 1.0f, 0.0f, 0.0f );
}
break;
case UT_RECT: glBegin( GL_QUADS );
glColor3f( 1.0f, 0.0f, 0.0f );
glVertex2i( (GLint)x-10, (GLint)y-5 );
glVertex2i( (GLint)x+10, (GLint)y-5 );
glVertex2i( (GLint)x+10, (GLint)y+5 );
glVertex2i( (GLint)x-10, (GLint)y+5 );
glEnd();
break;
case UT_SQUARE: glBegin( GL_QUADS );
glColor3f( 0.0f, 0.0f, 1.0f );
glVertex2i( (GLint)x-10, (GLint)y-10 );
glVertex2i( (GLint)x+10, (GLint)y-10 );
glVertex2i( (GLint)x+10, (GLint)y+10 );
glVertex2i( (GLint)x-10, (GLint)y+10 );
glEnd();
break;
default: ;
}
}
double Unit::getX()
{
return x;
}
double Unit::getY()
{
return y;
}
void Unit::select()
{
selected = true;
}
void Unit::unselect()
{
selected = false;
}
bool Unit::getSelected()
{
return selected;
}
|