예제 #1
0
파일: hud.cpp 프로젝트: moses7/Epiar
void Radar::WorldToBlip( Coordinate &w, Coordinate &b ) {
	Player *p = Player::Instance();
	Coordinate player = p->GetWorldPosition();
	
	b.SetX( ( ( w.GetX() - player.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - player.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}
예제 #2
0
파일: gate.cpp 프로젝트: ebos/Epiar
bool Gate::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;
	Coordinate pos;

	if( (attr = FirstChildNamed(node,"x")) ){
		value = NodeToString(doc,attr);
		pos.SetX( atof( value.c_str() ));
	} else return false;

	if( (attr = FirstChildNamed(node,"y")) ){
		value = NodeToString(doc,attr);
		pos.SetY( atof( value.c_str() ));
	} else return false;

	SetWorldPosition( pos );

	if( (attr = FirstChildNamed(node,"exit")) ){
		value = NodeToString(doc,attr);
		Gate* exit = Gates::Instance()->GetGate( value );
		if( exit != NULL ) {
			Gate::SetPair(this,exit);
		}
	}

	return true;
}
예제 #3
0
파일: hud.cpp 프로젝트: cthielen/epiar
/**\brief Draws the radar.
 */
void Radar::Draw( Camera* camera, SpriteManager* sprites ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;
	Coordinate focus = camera->GetFocusCoordinate();

	/*if(largeMode) {
		if( visibility <= QUADRANTSIZE )
		{
			Map* map = (Map*)UI::Search( "/Map/" );
			assert(map); // large mode should only be on when there is a map.
			if(map) {
				map->SetCenter( focus );
				map->SetScale( 300.0 / (2*visibility) );
			}
		}
		return;
	}*/

	list<Sprite*> *spriteList = sprites->GetSpritesNear(camera->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;

		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( focus, wpos, blip );

		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar

		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );

		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT / 4.0));

		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}

	delete spriteList;
}
예제 #4
0
파일: planets.cpp 프로젝트: Maka7879/Epiar
/**\brief Constructor using a full Full Description
 */
Planet::Planet( string _name, float _x, float _y, Image* _image, Alliance* _alliance, bool _landable, int _traffic, int _militiaSize, int _sphereOfInfluence, list<Technology*> _technologies):
	alliance(_alliance),
	landable(_landable),
	traffic(_traffic),
	militiaSize(_militiaSize),
	sphereOfInfluence(_sphereOfInfluence),
	technologies(_technologies)
{
	// Check the inputs
	assert(_image);
	assert(_alliance);

	Coordinate pos;
	pos.SetX(_x);
	pos.SetY(_y);
	SetWorldPosition( pos );
	SetName(_name);
	SetImage(_image);
	Image::Store(name,GetImage());
	SetRadarColor(Color::Get(48, 160, 255));
}
예제 #5
0
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		// Use the OpenGL Crop Rectangle to ensure that the blip is on the radar
		
		/* Convert to screen coords */
		blip.SetX( blip.GetX() + radar_mid_x );
		blip.SetY( blip.GetY() + radar_mid_y );
		
		radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
		
		if( radarSize >= 1 ) {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, radarSize, 2, WHITE );
			else
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
		} else {
			if(sprite->GetID() == Hud::GetTarget() && Timer::GetTicks() % 1000 < 100)
				Video::DrawCircle( blip, 1, 2, WHITE );
			else
				Video::DrawPoint( blip, sprite->GetRadarColor() );
		}
	}
	delete spriteList;
}
예제 #6
0
파일: planets.cpp 프로젝트: Maka7879/Epiar
/**\brief Copy Constructor
 */
Planet& Planet::operator=(const Planet& other) {
	// Check the other Sprite
	assert( other.GetImage() );
	assert( other.GetAlliance() );

	name = other.name;
	alliance = other.alliance;
	landable = other.landable;
	traffic = other.traffic;
	militiaSize = other.militiaSize;
	sphereOfInfluence = other.sphereOfInfluence;
	technologies = other.technologies;

	// Set the Sprite Stuff
	Coordinate pos;
	pos.SetX(other.GetWorldPosition().GetX());
	pos.SetY(other.GetWorldPosition().GetY());
	SetWorldPosition( pos );
	SetImage( other.GetImage() );
	Image::Store(name,GetImage());

	return *this;
}
예제 #7
0
파일: hud.cpp 프로젝트: akollias/Epiar
/**\brief Draws the radar.
 */
void Radar::Draw( void ) {
	short int radar_mid_x = RADAR_MIDDLE_X + Video::GetWidth() - 129;
	short int radar_mid_y = RADAR_MIDDLE_Y + 5;
	int radarSize;

	list<Sprite*> *spriteList = SpriteManager::Instance()->GetSpritesNear(Camera::Instance()->GetFocusCoordinate(), (float)visibility);
	for( list<Sprite*>::const_iterator iter = spriteList->begin(); iter != spriteList->end(); iter++)
	{
		Coordinate blip;
		Sprite *sprite = *iter;
		
		//if( sprite->GetDrawOrder() == DRAW_ORDER_PLAYER ) continue;
		
		// Calculate the blip coordinate for this sprite
		Coordinate wpos = sprite->GetWorldPosition();
		WorldToBlip( wpos, blip );
		
		if( blip.ViolatesBoundary( -(RADAR_HEIGHT / 2.0), (RADAR_WIDTH / 2.0), (RADAR_HEIGHT / 2.0), -(RADAR_WIDTH / 2.0) ) == false ) {
			/* blip is on the radar */
			
			/* Convert to screen coords */
			blip.SetX( blip.GetX() + radar_mid_x );
			blip.SetY( blip.GetY() + radar_mid_y );

			radarSize = int((sprite->GetRadarSize() / float(visibility)) * (RADAR_HEIGHT/4.0));
			
			
			if( radarSize >= 1 ) {
				Video::DrawCircle( blip, radarSize, 1, sprite->GetRadarColor() );
			} else {
				Video::DrawPoint( blip, sprite->GetRadarColor() );
			}
		}
	}
	delete spriteList;
}
예제 #8
0
파일: planets.cpp 프로젝트: Maka7879/Epiar
/**\brief Parse one player out of an xml node.
 */
bool Planet::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;
	Coordinate pos;

	if( (attr = FirstChildNamed(node,"alliance")) ){
		value = NodeToString(doc,attr);
		alliance = Alliances::Instance()->GetAlliance(value);
		if(alliance==NULL)
		{
			LogMsg(ERR, "Could not create Planet '%s'. Unknown Alliance '%s'.", this->GetName().c_str(), value.c_str());
			return false;
		}
	} else return false;

	if( (attr = FirstChildNamed(node,"x")) ){
		value = NodeToString(doc,attr);
		pos.SetX( atof( value.c_str() ));
	} else return false;

	if( (attr = FirstChildNamed(node,"y")) ){
		value = NodeToString(doc,attr);
		pos.SetY( atof( value.c_str() ));
	} else return false;

	SetWorldPosition( pos );

	if( (attr = FirstChildNamed(node,"landable")) ){
		value = NodeToString(doc,attr);
		landable = ( atoi( value.c_str() ) != 0);
	} else return false;

	if( (attr = FirstChildNamed(node,"traffic")) ){
		value = NodeToString(doc,attr);
		traffic = (short int) atoi( value.c_str() );
	} else return false;

	if( (attr = FirstChildNamed(node,"image")) ){
		Image* image = Image::Get( NodeToString(doc,attr) );
		Image::Store(name, image);
		SetImage(image);
	} else return false;

	if( (attr = FirstChildNamed(node,"militia")) ){
		value = NodeToString(doc,attr);
		militiaSize = (short int) atoi( value.c_str() );
	} else return false;

	if( (attr = FirstChildNamed(node,"sphereOfInfluence")) ){
		value = NodeToString(doc,attr);
		sphereOfInfluence = atoi( value.c_str() );
	} else return false;

	for( attr = FirstChildNamed(node,"technology"); attr!=NULL; attr = NextSiblingNamed(attr,"technology") ){
		value = NodeToString(doc,attr);
		Technology *tech = Technologies::Instance()->GetTechnology( value );
		technologies.push_back(tech);
	}
	technologies.unique();

	return true;
}
예제 #9
0
/**\brief Gets the radar position based on world coordinate
 * \param w Pointer to world coordinate
 * \retval b Pointer to radar coordinate
 */
void Radar::WorldToBlip( Coordinate &w, Coordinate &b ) {
	Coordinate focus = Camera::Instance()->GetFocusCoordinate();
	
	b.SetX( ( ( w.GetX() - focus.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - focus.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}
예제 #10
0
파일: hud.cpp 프로젝트: cthielen/epiar
/**\brief Gets the radar position based on world coordinate
 * \param w Pointer to world coordinate
 * \retval b Pointer to radar coordinate
 */
void Radar::WorldToBlip( Coordinate focus, Coordinate &w, Coordinate &b ) {
	b.SetX( ( ( w.GetX() - focus.GetX() ) / float(visibility) ) * ( RADAR_WIDTH / 2.0 ) );
	b.SetY( ( ( w.GetY() - focus.GetY() ) / float(visibility) ) * ( RADAR_HEIGHT / 2.0 ) );
}