Ejemplo n.º 1
0
void Unit::ChangeWeapon( )
{
	if (!IsAlive())
		return;

	if( !gSecondaryWeapon || !gCurrentWeapon )
		return;
	if( gWeaponState != Hold )
		return;

	if( gCurrentWeapon->GetState() == Reloading || gCurrentWeapon->GetInfo().ReloadTime.first > 0 )
		gCurrentWeapon->CancelReload();

	if( gCurrentWeapon == gPrimaryWeapon )
	{
		gPrimaryWeapon->SetState( Hidden );
		gCurrentWeapon	=	gSecondaryWeapon;
		gCurrentWeapon->SetState( Alive );
		AddGameObject( gSecondaryWeapon );
	}
	else
	{
		gSecondaryWeapon->SetState( Hidden );
		gCurrentWeapon	=	gPrimaryWeapon;
		gCurrentWeapon->SetState( Alive );
		AddGameObject( gPrimaryWeapon );
	}
	SetWeaponState( Hold );
}
Ejemplo n.º 2
0
void GameManager::Initialize()
{
	//Initialize the resource manager
	_resourceManager.Initialize(&_graphicsDevice);

	//Create the main camera object
	GameObject* mainCamera = new GameObject();
	mainCamera->GetTransform().SetPosition(-20,15,30);
	Camera* cameraComponent = (Camera*)mainCamera->AddComponent(new Camera(mainCamera, CameraType::Perspective()));

	AddGameObject(mainCamera); //Takes over the ownership of the game object

	//Initialize the renderer
	_renderEngine.Initialize(cameraComponent, &_resourceManager, &_graphicsDevice);
	_renderEngine.SetClearColor(Color::CornflowerBlue());

	//Create the 2D camera
	GameObject* camera2D = new GameObject();
	//camera2D->GetTransform().SetPosition(Vector3(0.0f,0.0f,-0.1f));
	Camera* camera2DComponent = (Camera*)camera2D->AddComponent(new Camera(camera2D, CameraType::Orthographic()));
	camera2DComponent->SetNearClip(-1.0f);
	camera2DComponent->SetFarClip(1.0f);
	AddGameObject(camera2D); //Takes over the ownership of the game object
	//Initialize the 2D renderer
	_renderEngine2D.Initialize(camera2DComponent, _renderEngine.GetWindowPointer(), &_graphicsDevice);

	LoadDebugComponents();
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RacetrackScreen::AddAICar(AICar* aiCar)
{
  AddGameObject(aiCar, true, true);
  m_startingPositions.pop_front();
  m_cars.push_back(aiCar);
  //AddCollisionObject(aiCar);
}
Ejemplo n.º 4
0
void GameManager::LoadDebugComponents()
{
	Font* debugFont = _resourceManager.GetFont("../data/fonts/SourceSansPro-Bold.otf");
	debugFont->SetFontSize(12);
	_resourceManager.StoreAndInitMaterial("FontMaterial", 
										new FontMaterial(_resourceManager.GetShaderProgram("Font2D", "../data/FontMaterial.vert", "../data/FontMaterial.frag"),
										Color::Yellow()));

	GameObject* FPS = new GameObject();
	FPS->GetTransform().SetPosition(Vector3(10,16,0));
	FPS->AddComponent(new FontRenderer(FPS,_resourceManager.GetMaterial("FontMaterial"), debugFont, "FPS:", GetGraphicsDevice()));
	FPS->AddComponent(new PrintFPS(FPS));
	AddGameObject(FPS);


	GameObject* avgFPS = new GameObject();
	avgFPS->GetTransform().SetPosition(Vector3(10,32,0));
	avgFPS->AddComponent(new FontRenderer(avgFPS,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Avg FPS:", GetGraphicsDevice()));
	avgFPS->AddComponent(new PrintAvgFPS(avgFPS));
	AddGameObject(avgFPS);

    GameObject* drawCall3D = new GameObject();
	drawCall3D->GetTransform().SetPosition(Vector3(10,48,0));
	drawCall3D->AddComponent(new FontRenderer(drawCall3D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Draw Calls(3D):", GetGraphicsDevice()));
	drawCall3D->AddComponent(new Print3DDrawCalls(drawCall3D, &_renderEngine));
	AddGameObject(drawCall3D);

	GameObject* drawCall2D = new GameObject();
	drawCall2D->GetTransform().SetPosition(Vector3(10,64,0));
	drawCall2D->AddComponent(new FontRenderer(drawCall2D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Draw Calls(2D):", GetGraphicsDevice()));
	drawCall2D->AddComponent(new Print2DDrawCalls(drawCall2D, &_renderEngine2D));
	AddGameObject(drawCall2D);

	GameObject* triCount3D = new GameObject();
	triCount3D->GetTransform().SetPosition(Vector3(10,80,0));
	triCount3D->AddComponent(new FontRenderer(triCount3D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Triangles(3D):", GetGraphicsDevice()));
	triCount3D->AddComponent(new Print3DTriangles(triCount3D, &_renderEngine));
	AddGameObject(triCount3D);

	GameObject* triCount2D = new GameObject();
	triCount2D->GetTransform().SetPosition(Vector3(10,96,0));
	triCount2D->AddComponent(new FontRenderer(triCount2D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Triangles(2D):", GetGraphicsDevice()));
	triCount2D->AddComponent(new Print2DTriangles(triCount2D, &_renderEngine2D));
	AddGameObject(triCount2D);

	GameObject* drawDebugObjects = new GameObject();
	drawDebugObjects->GetTransform().SetPosition(Vector3(10,704,0));
	drawDebugObjects->AddComponent(new FontRenderer(drawDebugObjects,_resourceManager.GetMaterial("FontMaterial"), debugFont, 
		"Press 'B' to toggle bounding boxes", GetGraphicsDevice()));
	AddGameObject(drawDebugObjects);

	GameObject* drawWireframe = new GameObject();
	drawWireframe->GetTransform().SetPosition(Vector3(10,688,0));
	drawWireframe->AddComponent(new FontRenderer(drawWireframe,_resourceManager.GetMaterial("FontMaterial"), debugFont, 
		"Press 'N' to toggle wireframe", GetGraphicsDevice()));
	AddGameObject(drawWireframe);
}
Ejemplo n.º 5
0
bool LevelWorkerGameObjects::AddFeature(Level* pLevel)
{
    m_pGo->SetLevel(pLevel);
    //m_pGo->SetRoomId(pLevel->GetRoom()->GetId());
    // Use this function so we keep track of which LevelWorker added which object.
    AddGameObject(pLevel, m_pGo.GetPtr());

    return true;
}
Ejemplo n.º 6
0
void Unit::DropWeapon()
{
	if ( gCurrentWeapon && gWeaponState == Hold )
	{
		if( !gCurrentWeapon->IsDropable() || gCurrentWeapon->IsReloading() )
			return;
		if( gCurrentWeapon->GetState() == Reloading )
			gCurrentWeapon->CancelReload();

		WeaponOnGround*	tWoG	=	new WeaponOnGround( gCurrentWeapon );
		tWoG->MoveTo( gCurrentWeapon->GetFloat3Value( Position ) );

		//tWoG->SetRotation( GetQuaternation() );

		AddGameObject( tWoG );
		tWoG->Update(0, 0);

		gSecondaryWeapon=	0;
		gCurrentWeapon	=	gPrimaryWeapon;
		gCurrentWeapon->SetState( Alive );
		AddGameObject( gCurrentWeapon );
	}
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RacetrackScreen::AddPlayerCar(PlayerCar* playerCar)
{
  // Should only have one player car on the racetrack screen
  assert(!m_playerCar);
  // Don't want the startingline position and player starting position y to be the same otherwise we have problems detecting lap numbers
  assert(m_playerStartingPosition.y != m_startingLine->GetWorldPosition().y);

  AddGameObject(playerCar, true, true);
  m_playerStartingPosition = playerCar->GetWorldPosition();
  m_startingPositions.pop_front();
  m_cars.push_back(playerCar);

  m_playerCar = playerCar;
  //AddCollisionObject(playerCar);
}
Ejemplo n.º 8
0
// Runs the game
void Game::Run()
{
	// Add a test text renderer
	{
		auto go = AddGameObject("TestTextRenderer");
		auto tm = go->AddComponent<TextMaterial>();
		tr = go->AddComponent<TextRenderer>();

		std::shared_ptr<Font> font = std::make_shared<Font>();
		assert(font->LoadFromFile("Fonts\\OpenSans-Regular.ttf"));
		tr->SetFont(font);
		tr->SetFontSize(12U);
		tr->SetText("Hello, world!");
		tm->SetTextColor(vec4(1, 0, 0, 1));

		go->GetTransform()->SetPosition(glm::vec3(5, 5, 0));
	}

	gameManager = std::make_shared<BilliardGameManager>();
	gameManager->CreateTable();
	gameManager->PreparePoolBalls();


    Time::Start();

    // Set the window to visible then begin the game loop
    _window->SetVisible( true );
    while ( _window->IsOpen() )
    {
        // Clear the screen
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        // Update and draw the game
        Update();
        Draw();

        // Update the time values
        Time::Update();
        Physics::Update();
        Input::Update( _window->_window );

        // Poll for events and swap the buffers
        _window->SwapBuffers();
        _window->PollEvents();
    }
}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RacetrackScreen::LoadCollisionTiles()
{
  LevelObjects collisionTiles;
  m_raceScreenData->FindCollisionTiles(collisionTiles);

  for (const LevelObjectInfo& info : collisionTiles)
  {
    GameObject* gameObject = new GameObject(info.m_position, info.m_dataAsset, BaseObject::LoadType::kTexture);
    gameObject->SetLocalRotation(info.m_rotation);

    AddGameObject(gameObject, true, true);

    if (info.m_shouldHaveCollider)
    {
      AddCollisionObject(gameObject, true);
    }
  }
}
Ejemplo n.º 10
0
void GameStage::UpdateSurvival()
{
	Plane* pObj;

	if( Rules_GameMode == GAMEMODE_SURVIVAL )
	{
		SurvivalDelay = (SurvivalDelay + 1) % FRAMES_PER_SECOND;
		if( SurvivalDelay == 0 )
		{
			SurvivalTotalTimer++;
			SurvivalTimer++;
			pObj = 0;
			if( SurvivalTimer >= SurvivalArrivals[SurvivalIndex] )
			{
				SurvivalTimer = 0;
				pObj = AddPlayer( (ALLEGRO_JOYSTICK*)-1 );
				if( SurvivalPlayer != 0 )
				{
					SurvivalPlayer->Score++;
				}
				if( SurvivalIndex < SURVIVAL_INTERVALS - 1 )
				{
					SurvivalIndex++;
				} else {
					if( rand() % 3 == 0 )
					{
						int tmpY;
						if( Rules_HasGround )
						{
							tmpY = rand() % ((Framework::SystemFramework->GetDisplayHeight() / graphicsMultiplier) - 32);
						} else {
							tmpY = rand() % (Framework::SystemFramework->GetDisplayHeight() / graphicsMultiplier);
						}
						AddGameObject( new Cloud( new Vector2( Framework::SystemFramework->GetDisplayWidth(), tmpY ), (double)(rand() % 300) / 10.0, 180.0 ) );
					}
				}
			}
			if( pObj != 0 )
			{
				pObj->Team = (Objects.size() % 7) + 1;
			}
		}
	}
}
bool LevelWorkerAddCharacters::AddFeature(Level* pLevel)
{
  int numChars = m_charNames.size();
  for (int i = 0; i < numChars; i++)
  {
    // Make a simple cube for the character bounding box.
    //float s = 2.0f; // box size
    //BoundingBox bb(0, s, 0, s, 0, s);

    Orientation initialOr((float)(i * 2), 13, (float)(i * 2), 0, 0, 0);

    // GOLF
    CharacterGameObject* pCharacter = new PoolCharacter;

    pCharacter->SetLevel(pLevel);
    pCharacter->SetId(1 + i); // TODO CONFIG ?
    pCharacter->SetRoomId(pLevel->GetRoomId());

    // Set the attributes which are not loaded.
    std::string characterName = m_charNames[i];

    File f;
    std::string s = characterName;
    s += ".txt";
    if (!f.OpenRead(s.c_str()))
    {
      f.ReportError("Failed to open character file.");
      return false;
    }
    pCharacter->Load(&f);

    pCharacter->SetState(UNKNOWN);
    pCharacter->ClearMeshes();
    pCharacter->AddMesh(CharacterManager::Instance()->GetCharacter(characterName));
    pCharacter->SetOrientation(initialOr);

    // Use this function so we keep track of which LevelWorker added which object.
    AddGameObject(pLevel, pCharacter);
  }

  return true;
}
Ejemplo n.º 12
0
void GameStage::Begin()
{
	GameObject::Game = this;

	switch( Rules_GameMode )
	{
		case GAMEMODE_SURVIVAL:
			Rules_PlaneToPlaneCollisions = false;
			Rules_BulletToBulletCollisions = false;
			Rules_FriendlyFire = true;
			Rules_HasGround = true;
			Framework::SystemFramework->ProgramStages->Push( (Stage*)new SurvivalControllerSelectStage() );
			break;
		case GAMEMODE_FREEFLIGHT:
			Rules_PlaneToPlaneCollisions = false;
			Rules_BulletToBulletCollisions = false;
			Rules_FriendlyFire = false;
			Rules_HasGround = false;
			for( int i = 0; i < FREEFLIGHT_CLOUD_COUNT; i++ )
			{
				Cloud* c = new Cloud(new Vector2( rand() % Framework::SystemFramework->GetDisplayWidth(), rand() % Framework::SystemFramework->GetDisplayHeight() ), (float)(rand() % 80) / 10, 180.0 );
				c->SetTileScale( graphicsMultiplier );
				AddGameObject( c );
			}
			Framework::SystemFramework->ProgramStages->Push( (Stage*)new MultipleControllerSelectStage() );
			break;
		case GAMEMODE_LASTMANSTANDING:
			Rules_PlaneToPlaneCollisions = false;
			Rules_BulletToBulletCollisions = false;
			Rules_FriendlyFire = true;
			Rules_HasGround = true;
			Framework::SystemFramework->ProgramStages->Push( (Stage*)new MultipleControllerSelectStage() );
			break;
		case GAMEMODE_TEAMBATTLES:
			Rules_PlaneToPlaneCollisions = false;
			Rules_BulletToBulletCollisions = false;
			Rules_FriendlyFire = false;
			Rules_HasGround = true;
			Framework::SystemFramework->ProgramStages->Push( (Stage*)new MultipleControllerSelectStage() );
			break;
	}
}
Ejemplo n.º 13
0
Plane* GameStage::AddPlayer( ALLEGRO_JOYSTICK* Controller )
{
	int Xpos = rand() % (Framework::SystemFramework->GetDisplayWidth() / graphicsMultiplier);
	int Ypos = rand() % (((Framework::SystemFramework->GetDisplayHeight() / graphicsMultiplier) / 4) * 3);

	Plane* ply = new Plane( Controller, new Vector2( Xpos, Ypos ), PLANE_VELOCITY_MAX, 0.0 );
	if( rand() % 2 == 1 )
	{
		ply->Angle = 180.0;
		ply->Flipped = true;
	}
	AddGameObject( ply );

	if( Controller != (ALLEGRO_JOYSTICK*)-1 )
	{
		SurvivalPlayer = ply;
	}

	return ply;
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RacetrackScreen::LoadStartingPoints()
{
  LevelObjects startingPoints;
  m_raceScreenData->FindStartingPoints(startingPoints);

  for (const LevelObjectInfo& info : startingPoints)
  {
    GameObject* gameObject = new GameObject(info.m_position, info.m_dataAsset, BaseObject::LoadType::kTexture);
    gameObject->SetLocalRotation(info.m_rotation);

    AddGameObject(gameObject, true, true);

    if (info.m_shouldHaveCollider)
    {
      AddCollisionObject(gameObject, true);
    }

    m_startingPositions.push_back(info.m_position);
  }
}
Ejemplo n.º 15
0
GameObject* GameManager::CreateGameObjectsFromModel(std::string filePath)
{
	std::vector<Mesh*> model = _resourceManager.GetModelFromFile(filePath);

	//Create all the necessary materials
	for(unsigned int i = 0; i < model.size(); i++)
	{
		std::string texturePath = FileUtility::LocalFileDirectory() + model[i]->GetDefaultDiffuseTextureName();
		if(!_resourceManager.CheckIfMaterialExist(texturePath))
		{
			_resourceManager.StoreAndInitMaterial(texturePath, 
			new Diffuse(_resourceManager.GetShaderProgram("Diffuse", "../data/Diffuse.vert", "../data/Diffuse.frag"),
			_resourceManager.GetTexture2D(texturePath)));
		}
	}

	GameObject* previousMesh = NULL;
	GameObject* rootObject = NULL;
	for(unsigned int i = 0; i < model.size(); i++)
	{
		GameObject* meshObject = new GameObject();

		//Correct the transforms
		if(previousMesh != NULL)
		{
			meshObject->GetTransform().SetParent(&previousMesh->GetTransform());
		}
		else
		{
			rootObject = meshObject;
		}

		std::string texturePath = FileUtility::LocalFileDirectory() + model[i]->GetDefaultDiffuseTextureName();
		meshObject->AddComponent(new MeshRenderer(meshObject, model[i], _resourceManager.GetMaterial(texturePath)));

		AddGameObject(meshObject);
		previousMesh = meshObject;
	}

	return rootObject;
}
Ejemplo n.º 16
0
GameObject* GameObjectManager::CreateGameObject(int type, const Ogre::Vector3& position, void* data, const Ogre::String& id){
	GameObject* go = (this->*m_create_fptr[type])(position, data, id);
	go->SetGameObjectManager(this);
	AddGameObject(go);
	return go;
}
Ejemplo n.º 17
0
bool LevelWorkerAddStupids::AddFeature(Level* pLevel)
{
  // Assume the zeroth character held by Character Manager is reserved 
  // for the player character.

  // For each type of stupid (i.e. name recognised by CharacterManager)
  int levelNum = pLevel->GetId();

  // How many Stupids to add for this level ?
  // Start with 1, easiest.
  int numStupids = 1 + levelNum; 
  int max = (int)Engine::Instance()->GetConfigFloat("max_stupids"); 
  if (numStupids > max)
  {
    numStupids = max;
  }

  std::vector<std::string> characterNames; 
  CharacterManager::Iterator it = CharacterManager::Instance()->Begin();
  ++it; // skip player character
  for ( ;
       it != CharacterManager::Instance()->End(); 
       ++it)
  {
    characterNames.push_back(*it);
  }

  int numAvailableCharacters = characterNames.size();
  int characterIndex = levelNum;
  characterIndex %= numAvailableCharacters;
  float dir = 0;
  float turnDir = 90.0f;

  // Get a list of the character names we will use.
  // Then we want to sort the character names before adding them, to minimise texture changes.
  // This is a desperate attempt to try to speed things up on slow graphics cards.
  typedef std::vector<std::string> StringVec;
  StringVec namevec; 
  
  int i;

  for (i = 0; i < numStupids; i++)
  {
    std::string characterName = characterNames[characterIndex];
    // Work backwards from index so in level N we get the characters from level
    // N - 1 plus one new one (up until all the characters are used).
    --characterIndex;
    if (characterIndex < 0) 
    {
      characterIndex = characterNames.size() - 1;
    }
    namevec.push_back(characterName);
  }

  // Sort the list of character names. The end result of this is that characters with the
  // same texture will be drawn consecutively. This will minimise texture changes for characters.
  std::sort(namevec.begin(), namevec.end());

  for (i = 0; i < numStupids; i++)
  {
    // Make a simple cube for the character bounding box.
    float s = 2.0f; // box size
    BoundingBox bb(0, s, 0, s, 0, s);

    Orientation initialOr;
    if (!GetOrientation(bb, pLevel->GetPlayAreaSize(), &initialOr))
    {
      return false; // play area too small
    }

    //float shadowSize = 1.0f; // TODO should be a Character attribute

    float thisInitialDir = dir;
    dir += 90.0f;
    if (dir >= 359.0f)
    {
      dir = 0;
    }

    float thisTurnDir = turnDir;
    turnDir = -turnDir;

    // Speed
    //float stupidSpeed = 5.0f; // TODO Should be a character attribute

    // Bounding Sphere and collision vol: use defaults loaded from file

    Stupid* pStupid = new Stupid;
    pStupid->SetLevel(pLevel);
    pStupid->SetId(GetUniqueId());
    pStupid->SetRoomId(0);
    // Choose a file to load from.
    // Load the Stupid.
    // TODO set up in ctor
    File f;
    f.OpenRead("stupid1.txt"); // TODO TEMP TEST
    pStupid->Load(&f);
    // Set the appearance delay.
    pStupid->SetAppearanceDelay((float)i * 2.0f + 2.0f); // TODO TEMP TEST

    // Set the attributes which are not loaded.
    std::string characterName = namevec[i];
    pStupid->ClearMeshes();
    pStupid->AddMesh(CharacterManager::Instance()->GetCharacter(characterName));
    pStupid->SetOrientation(initialOr);
    pStupid->SetInitialDirection(thisInitialDir);
    pStupid->SetTurnDirection(thisTurnDir);
    /*
    pStupid->SetMaxSpeed(0); // TODO Should be character attrib
    pStupid->SetShadowSize(0); // TODO Should be character attrib
    pStupid->SetTurnVel(0); // TODO Should be character attrib
    */

    // Use this function so we keep track of which LevelWorker added which object.
    AddGameObject(pLevel, pStupid);
  }

  return true;
}
 float SubSectionMenu::LoadContent()
 {
     //Get the screen width and height
     float width = (float)ServiceLocator::GetPlatformLayer()->GetWidth();
     float height = (float)ServiceLocator::GetPlatformLayer()->GetHeight();
 
     //Create a overlay
     m_Overlay = new Rect(0.0f, 0.0f, width, height);
     m_Overlay->SetColor(Color::OnyxColor(0.0f));
     AddGameObject(m_Overlay);
     
     //Determine how many buttons we need and allocate an array to keep track of the buttons
     const unsigned int buttonCount = WORLD_NUMBER_OF_SUBSECTIONS.x * WORLD_NUMBER_OF_SUBSECTIONS.y;
     m_Buttons = new Button*[buttonCount];
     
     //Calculate the available width and height for an inidivual button
     float buttonWidth = width / WORLD_NUMBER_OF_SUBSECTIONS.x;
     float buttonHeight = height / WORLD_NUMBER_OF_SUBSECTIONS.y;
     
     //Calculate a small spacer between the buttons
     vec2 buttonSpacer = vec2(buttonWidth / 8, buttonHeight / 8);
     
     //Re-calculate the button width and height, factoring in the spacer
     buttonWidth = (width - (buttonSpacer.x * (WORLD_NUMBER_OF_SUBSECTIONS.x + 1))) / WORLD_NUMBER_OF_SUBSECTIONS.x;
     buttonHeight = (height - (buttonSpacer.y * (WORLD_NUMBER_OF_SUBSECTIONS.y + 1))) / WORLD_NUMBER_OF_SUBSECTIONS.y;
     
     //Set the button size vector
     vec2 buttonSize = vec2 (buttonWidth, buttonHeight);
     
     //The string stream will be used below to see each's button label text
     stringstream ss;
     
     //Cycle through the buttonCount and create a new button object
     for(unsigned int i = 0; i < buttonCount; i++)
     {
         //Calculate the coordinates based on the button index
         uvec2 coordinates = uvec2(0,0);
         coordinates.x = (i % WORLD_NUMBER_OF_SUBSECTIONS.x);
         coordinates.y = ((i - coordinates.x) / WORLD_NUMBER_OF_SUBSECTIONS.x);
     
         //Use those coordinates to set the button label
         ss.str("");
         ss << "(" << coordinates.x << "," << coordinates.y << ")";
         
         //Create the button and initialize its properties
         m_Buttons[i] = new Button("Ubuntu-B", "ttf", 48);
         m_Buttons[i]->SetText(ss.str());
         m_Buttons[i]->SetBackgroundColor(Color::CornflowerBlueColor(), ButtonStateNormal);
         m_Buttons[i]->SetBackgroundColor(Color::CornflowerBlueColor(), ButtonStateSelected);
         m_Buttons[i]->SetBackgroundColor(Color::CornflowerBlueColor(), ButtonStateDisabled);
         m_Buttons[i]->SetTextColor(Color::WhiteColor(), ButtonStateNormal);
         m_Buttons[i]->SetTextColor(Color::WhiteColor(), ButtonStateSelected);
         m_Buttons[i]->SetTextColor(Color::WhiteColor(), ButtonStateDisabled);
         m_Buttons[i]->SetPreferredSize(buttonSize);
         m_Buttons[i]->SetAnchorPoint(0.5f, 0.5f);
         m_Buttons[i]->AddEventListener(this, BUTTON_ACTION);
         
         //Calculate the button's exact position and set it
         float buttonX = buttonSpacer.x + (buttonSize.x / 2.0f) + (buttonSpacer.x + buttonSize.x) * coordinates.x;
         float buttonY = buttonSpacer.y + (buttonSize.y / 2.0f) + (buttonSpacer.y + buttonSize.y) * coordinates.y;
         m_Buttons[i]->SetLocalPosition(buttonX, buttonY);
         
         //Add the button object to the scene
         AddGameObject(m_Buttons[i]);
     }
 
     return 1.0f;
 }
Ejemplo n.º 19
0
Scene::Scene()
{
	GameObject *cam = new GameObject();
	camera = cam->AddComponent<Camera>();
	AddGameObject(cam);
}
void WintergraspWorkshopData::Init(uint8 team)
{
    // Outside Workshops
    if (m_workshopId < BATTLEFIELD_WG_WORKSHOP_KEEP_WEST)
    {
        // Set worldstate and nameId
        m_WorldState = CapturableWorkshops[m_workshopId].worldState;
        m_NameId = CapturableWorkshops[m_workshopId].nameId;

        // Spawning Workshop
        WintergraspObjectPositionData workshop = CapturableWorkshops[m_workshopId].GameObjectMain[0];
        GameObject* pWorkshop = m_WG->SpawnGameObject(workshop.entryHorde, workshop.x, workshop.y, workshop.z, workshop.o);
        if (!pWorkshop)
            return;

        // Spawning Engineer, save them separate
        WintergraspObjectPositionData engineer = CapturableWorkshops[m_workshopId].Engineer;
        if (Creature* pEngineer = m_WG->SpawnCreature(engineer.entryHorde, engineer.x, engineer.y, engineer.z, engineer.o, TEAM_HORDE))
            m_Engineer[TEAM_HORDE] = pEngineer->GetGUID();
        if (Creature* pEngineer = m_WG->SpawnCreature(engineer.entryAlliance, engineer.x, engineer.y, engineer.z, engineer.o, TEAM_ALLIANCE))
            m_Engineer[TEAM_ALLIANCE] = pEngineer->GetGUID();

        // Spawning Spirit Keeper and link him to the graveyard
        if (BfGraveyard* pGrave = m_WG->GetGraveyardById(m_workshopId))
        {
            WintergraspObjectPositionData spirit = CapturableWorkshops[m_workshopId].SpiritGuide;
            if (Creature* pSpirit = m_WG->SpawnCreature(spirit.entryHorde, spirit.x, spirit.y, spirit.z, spirit.o, TEAM_HORDE))
                // Link spirit to graveyard
                pGrave->SetSpirit(pSpirit, TEAM_HORDE);
            if (Creature* pSpirit = m_WG->SpawnCreature(spirit.entryAlliance, spirit.x, spirit.y, spirit.z, spirit.o, TEAM_ALLIANCE))
                // Link spirit to graveyard
                pGrave->SetSpirit(pSpirit, TEAM_ALLIANCE);
        }

        // Spawning Creature and NPC
        for (uint8 i = 0; i < CapturableWorkshops[m_workshopId].nbCreature; ++i)
            AddCreature(CapturableWorkshops[m_workshopId].Creature[i]);

        // Spawning Banner
        for (uint8 i = 0; i < CapturableWorkshops[m_workshopId].nbBanner; ++i)
            AddGameObject(CapturableWorkshops[m_workshopId].GameObjectBanner[i]);

        // Spawning Rocket Launcher
        for (uint8 i = 0; i < CapturableWorkshops[m_workshopId].nbRocketLauncher; ++i)
            AddRocketLauncher(CapturableWorkshops[m_workshopId].RocketLauncher[i]);
    }
    // Fortress Workshops
    else
    {
        // Array support (only 2 elements - 4, 5 are m_workshopIds)
        uint8 workshopId = m_workshopId - WG_CAPTURABLE_WORKSHOP;

        // Set worldstate
        m_WorldState = FortressWorkshops[workshopId].worldState;

        // Spawning Workshop
        WintergraspObjectPositionData workshop = FortressWorkshops[workshopId].Workshop;
        GameObject* pWorkshop = m_WG->SpawnGameObject(workshop.entryHorde, workshop.x, workshop.y, workshop.z, workshop.o);
        if (!pWorkshop)
            return;

        // Spawning Engineer
        WintergraspObjectPositionData engineer = FortressWorkshops[workshopId].Engineer;
        if (Creature* pEngineer = m_WG->SpawnCreature(engineer.entryHorde, engineer.x, engineer.y, engineer.z, engineer.o, TEAM_HORDE))
            m_Engineer[TEAM_HORDE] = pEngineer->GetGUID();
        if (Creature* pEngineer = m_WG->SpawnCreature(engineer.entryAlliance, engineer.x, engineer.y, engineer.z, engineer.o, TEAM_ALLIANCE))
            m_Engineer[TEAM_ALLIANCE] = pEngineer->GetGUID();

        // Spawning Spirit Keeper and link him to the graveyard (only one graveyard in the keep - linked to the west)
        if (m_workshopId == BATTLEFIELD_WG_WORKSHOP_KEEP_WEST)
        {
            if (BfGraveyard* pGrave = m_WG->GetGraveyardById(m_workshopId))
            {
                WintergraspObjectPositionData spirit = FortressWorkshops[workshopId].SpiritGuide;
                if (Creature* pSpirit = m_WG->SpawnCreature(spirit.entryHorde, spirit.x, spirit.y, spirit.z, spirit.o, TEAM_HORDE))
                    // Link spirit to graveyard
                    pGrave->SetSpirit(pSpirit, TEAM_HORDE);
                if (Creature* pSpirit = m_WG->SpawnCreature(spirit.entryAlliance, spirit.x, spirit.y, spirit.z, spirit.o, TEAM_ALLIANCE))
                    // Link spirit to graveyard
                    pGrave->SetSpirit(pSpirit, TEAM_ALLIANCE);
            }
        }
    }

    // Finally change faction
    GiveControlTo(team);
}