示例#1
0
文件: projectile.cpp 项目: eoi/Epiar
/**\brief Constructor
 */
Projectile::Projectile(float damageBooster, float angleToFire, Coordinate worldPosition, Coordinate firedMomentum, Weapon* _weapon)
{
	damageBoost=damageBooster;
	// All Projectiles get these
	ownerID = 0;
	targetID = 0;
	start = Timer::GetTicks();
	SetRadarColor (Color(0x55,0x55,0x55));

	// These are based off of the Ship firing this projectile
	SetWorldPosition( worldPosition );
	SetAngle(angleToFire);

	// These are based off of the Weapon
	weapon = _weapon;
	secondsOfLife = weapon->GetLifetime();
	SetImage(weapon->GetImage());

	Trig *trig = Trig::Instance();
	Coordinate momentum = GetMomentum();
	float angle = static_cast<float>(trig->DegToRad( angleToFire ));

	momentum = firedMomentum +
	           Coordinate( trig->GetCos( angle ) * weapon->GetVelocity(),
	                      -trig->GetSin( angle ) * weapon->GetVelocity() );
	
	SetMomentum( momentum );
}
//-----------------------------------------------------------------------------
//  SetWorldPosition
//-----------------------------------------------------------------------------
//!!
void CPhysicObj::SetWorldPosition (const NxVec3 &vPos)
{
	NxVec3 displ = vPos - GetWorldPosition();
	for (int i=0; i<GetNumParts(); i++) {
		SetWorldPosition(i, GetWorldPosition(i) + displ);
	}
}
示例#3
0
    /// Attempts to initialize the player character from saved game data.
    /// @param[in]  saved_game_data - The saved game data from which to initialize the player.
    /// @return The initialized player, if successful; null otherwise.
    std::unique_ptr<OBJECTS::Noah> GameplayState::InitializePlayer(const SavedGameData& saved_game_data)
    {
        // GET THE TEXTURE FOR NOAH.
        std::shared_ptr<GRAPHICS::Texture> noah_texture = Assets->GetTexture(RESOURCES::NOAH_TEXTURE_ID);
        assert(noah_texture);

        // GET THE AXE TEXTURE FOR NOAH.
        std::shared_ptr<GRAPHICS::Texture> axe_texture = Assets->GetTexture(RESOURCES::AXE_TEXTURE_ID);
        assert(axe_texture);

        // GET THE AXE'S SOUND EFFECT.
        std::shared_ptr<AUDIO::SoundEffect> axe_hit_sound = Assets->GetSound(RESOURCES::AXE_HIT_SOUND_ID);
        assert(axe_hit_sound);

        // CREATE THE AXE.
        std::shared_ptr<OBJECTS::Axe> axe = std::make_shared<OBJECTS::Axe>(axe_texture, axe_hit_sound);

        // CREATE NOAH.
        auto noah_player = std::make_unique<OBJECTS::Noah>(noah_texture, axe);

        // SET NOAH'S INITIAL POSITION.
        noah_player->SetWorldPosition(saved_game_data.PlayerWorldPosition);

        // POPULATE THE REST OF NOAH'S INVENTORY.
        noah_player->Inventory->WoodCount = saved_game_data.WoodCount;
        noah_player->Inventory->BibleVerses.insert(saved_game_data.FoundBibleVerses.cbegin(), saved_game_data.FoundBibleVerses.cend());

        return noah_player;
    }
示例#4
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;
}
示例#5
0
文件: gate.cpp 项目: ebos/Epiar
Gate::Gate(Coordinate pos) {
	top = true;
	SetImage( Image::Get("Resources/Graphics/gate1_top.png") );
	
	// Create the PartnerID Gate
	Gate* partner = new Gate(this->GetID());
	partnerID = partner->GetID();
	exitID = 0;
	SpriteManager::Instance()->Add((Sprite*)partner);

	// Set both Position and Angle at the same time
	SetWorldPosition(pos);
	SetAngle( float( rand() %360 ) );
}
示例#6
0
	Door::Door(RN::Vector3 position, RN::Quaternion rotation, RN::Vector3 scale) :
		_active(false), _counter(0.0f)
	{
		SetWorldPosition(position);
		SetWorldRotation(rotation);
		SetWorldScale(scale);
		
		SetModel(RN::Model::WithFile("Models/door/door_01.sgm"));
		
		RN::SceneNode *collider = new RN::SceneNode();
		collider->SetWorldPosition(position);
		collider->SetWorldRotation(rotation);
		collider->SetWorldScale(scale);
		RN::bullet::RigidBody *body = new RN::bullet::RigidBody(new RN::bullet::BoxShape(RN::Vector3(0.1f, 2.0f, 2.0f)), 0.0f);
		collider->AddAttachment(body->Autorelease());
		collider->Release();
	}
示例#7
0
文件: gate.cpp 项目: DuMuT6p/Epiar
/**\brief Creates a Top Gate as well as a Bottom Gate automatically
 * \todo Remove the SpriteManager Instance access.
 */
Gate::Gate(Coordinate pos, string _name) {
	top = true;
	SetImage( Image::Get("Resources/Graphics/gate1_top.png") );
	
	// Create the PartnerID Gate
	Gate* partner = new Gate(GetID());
	partnerID = partner->GetID();
	exitID = 0;
	SpriteManager::Instance()->Add((Sprite*)partner);

	// Set both Position and Angle at the same time
	SetWorldPosition(pos);
	SetAngle( float( rand() %360 ) );

	if( _name == "" ) {
		stringstream val_ss;
		val_ss << GetID();
		val_ss >> _name;
	}
示例#8
0
/**\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));
}
示例#9
0
/**\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;
}
示例#10
0
/**\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;
}
示例#11
0
文件: player.cpp 项目: DuMuT6p/Epiar
/**\brief Parse one player out of an xml node
 */
bool Player::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;
	Coordinate pos;

	if( (attr = FirstChildNamed(node,"name")) ){
		SetName(NodeToString(doc,attr));
	}

	if( (attr = FirstChildNamed(node, "planet"))){
		string temp;
		xmlNodePtr name = FirstChildNamed(attr,"name");
		lastPlanet = NodeToString(doc,name);
		Planet* p = Planets::Instance()->GetPlanet( lastPlanet );
		if( p != NULL ) {
			SetWorldPosition( p->GetWorldPosition() );
		}
	}else return false;

	if( (attr = FirstChildNamed(node,"model")) ){
		value = NodeToString(doc,attr);
		Model* model = Models::Instance()->GetModel( value );
		if( NULL!=model) {
			SetModel( model );
		} else {
			LogMsg(ERR,"No such model as '%s'", value.c_str());
			return false;
		}
	} else return false;
	
	if( (attr = FirstChildNamed(node,"engine")) ){
		value = NodeToString(doc,attr);
		Engine* engine = Engines::Instance()->GetEngine( value );
		if( NULL!=engine) {
			SetEngine( engine );
		} else {
			LogMsg(ERR,"No such engine as '%s'", value.c_str());
			return false;
		}
	} else return false;


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

	for( attr = FirstChildNamed(node,"weapon"); attr!=NULL; attr = NextSiblingNamed(attr,"weapon") ){
		AddShipWeapon( NodeToString(doc,attr) );
	}

	for( attr = FirstChildNamed(node,"outfit"); attr!=NULL; attr = NextSiblingNamed(attr,"outfit") ){
		AddOutfit( NodeToString(doc,attr) );
	}

	for( attr = FirstChildNamed(node,"cargo"); attr!=NULL; attr = NextSiblingNamed(attr,"cargo") ){
		xmlNodePtr type = FirstChildNamed(attr,"type");
		xmlNodePtr ammt = FirstChildNamed(attr,"amount");
		if(!type || !ammt)
			return false;
		if( NodeToInt(doc,ammt) > 0 )
		{
			StoreCommodities( NodeToString(doc,type), NodeToInt(doc,ammt) );
		}
	}

	for( attr = FirstChildNamed(node,"ammo"); attr!=NULL; attr = NextSiblingNamed(attr,"ammo") ){
		xmlNodePtr type = FirstChildNamed(attr,"type");
		xmlNodePtr ammt = FirstChildNamed(attr,"amount");
		if(!type || !ammt)
			return false;
		AmmoType ammoType = Weapon::AmmoNameToType( NodeToString(doc,type) );
		int ammoCount = NodeToInt(doc,ammt);
		if( ammoType < max_ammo ) {
			AddAmmo( ammoType, ammoCount );
		} else return false;
	}

	for( attr = FirstChildNamed(node,"Mission"); attr!=NULL; attr = NextSiblingNamed(attr,"Mission") ){
		Mission *mission = Mission::FromXMLNode(doc,attr);
		if( mission != NULL ) {
			LogMsg(INFO, "Successfully loaded the %s mission of player '%s'", mission->GetName().c_str(), this->GetName().c_str() );
			missions.push_back( mission );
		} else {
			LogMsg(INFO, "Aborted loading mission of player '%s'", this->GetName().c_str() );
		}
	}

	for( attr = FirstChildNamed(node,"favor"); attr!=NULL; attr = NextSiblingNamed(attr,"favor") ){
		xmlNodePtr alliance = FirstChildNamed(attr,"alliance");
		xmlNodePtr value = FirstChildNamed(attr,"value");
		if(!alliance || !value)
			return false;
		if( NodeToInt(doc,value) > 0 )
		{
			UpdateFavor( NodeToString(doc,alliance), NodeToInt(doc,value) );
		}
	}

	for( attr = FirstChildNamed(node,"hiredEscort"); attr!=NULL; attr = NextSiblingNamed(attr,"hiredEscort") ){
		xmlNodePtr typePtr = FirstChildNamed(attr, "type");
		xmlNodePtr payPtr = FirstChildNamed(attr, "pay");
		assert(typePtr && payPtr);
		if(!typePtr || !payPtr) return false;
		string type = NodeToString(doc, typePtr);
		int pay = atoi( NodeToString(doc, payPtr).c_str() );
		// Adding it with sprite ID -1 means it's up to player.lua to go ahead and create the correct sprite.
		this->AddHiredEscort(type, pay, -1);
	}

	if(this->ConfigureWeaponSlots(doc, node)){
		// great - it worked
		LogMsg( INFO, "Successfully loaded weapon slots");
	}
	else {
		LogMsg( ERR, "Weapon slot XML helper failed to configure weapon slots");
	}

	if( (attr = FirstChildNamed(node,"lastLoadTime")) ){
		lastLoadTime = NodeToInt(doc,attr);
	} else {
		lastLoadTime = (time_t)0;
	}

	RemoveLuaControlFunc();

	return true;
}
示例#12
0
/**\brief Creates a new Effect at specified coordinate with Animation file
 */
Effect::Effect(Coordinate pos, string filename, bool looping) {
	SetWorldPosition(pos);
	visual = new Animation(filename);
	visual->SetLooping(looping);
}
示例#13
0
文件: Node.cpp 项目: acremean/urho3d
void Node::SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale)
{
    SetWorldPosition(position);
    SetWorldRotation(rotation);
    SetWorldScale(scale);
}
示例#14
0
/// Sets the world position of the sprite.
/// @param[in]  world_position - The position of the sprite in the world.
void Sprite::SetWorldPosition(const MATH::Vector2f& world_position)
{
    SetWorldPosition(world_position.X, world_position.Y);
}