Esempio n. 1
0
void
Game::SpawnExplosion(int x, int y)
{
	Sprite* aS = m_pBackBuffer->CreateSprite("assets\\explosion.png");
	// create an explosion object
	Explosion* explosion = new Explosion();

	// initialize the texture
	if (!explosion->Initialise(*aS->GetTexture())) {
		LogManager::GetInstance().Log("Explosion Init Fail!");
		return;
	}

	
	// set the width and speed of the animation
	int fw = aS->GetWidth() / 5;
	explosion->SetFrameWidth(fw);	// 5 frames in the animation
	explosion->SetFrameSpeed(0.1f);
	for (int i = 0; i < 5; i++) {
		explosion->AddFrame(i * fw);
	}

	// set the center points for visual alignment
	explosion->SetCenter(fw / 2, aS->GetHeight() / 2);

	// set the x and y
	explosion->SetX(x - explosion->GetCenterX() / 2);
	explosion->SetY(y - explosion->GetCenterY() / 2);
	
	// add to the explosion container
	m_explosion.push_back(explosion);

}
Esempio n. 2
0
uint16 WorkerActor::GetHeight(void) const
{
	Assert(m_unitSpriteGroup != NULL);
	if (m_unitSpriteGroup == NULL) return 0;

	Sprite *    theSprite = m_unitSpriteGroup->GetGroupSprite((GAME_ACTION)m_curUnitAction);
    return (theSprite) ? theSprite->GetHeight() : 0;
}
Vector2 Animation::GetSize()
{
    // To get the size of the animation, we'll just get the size of the first frame.
    // If other frames are different sizes, then the concept of a size for the animation itself
    // is meaningless, so we don't really care about that part.
    Sprite *pFirstFrameSprite = frameList[0]->GetSprite();
    return Vector2(pFirstFrameSprite->GetWidth(), pFirstFrameSprite->GetHeight());
}
Esempio n. 4
0
void DrawBulletsRemaining(Weapon* DrawMe, int timediff)
{
	Sprite* BulletSprite;
	Sprite* MySprite;
	Bullet* TheBullet;
	char* Name = "INVALID BULLETS";
	RECT Client;
	GetClientRect(TheDisplay.GetHWnd(), &Client);

	
	TheBullet = GetGlobalBulletData(DrawMe->mBulletID);
	if(!TheBullet)
		return;
	Name = TheBullet->mName;
	BulletSprite = GetGlobalSpriteData(TheBullet->mFullBulletSpriteID);
	if(!BulletSprite)
		return;

	MySprite = new Sprite;
	MySprite->InitializeSpriteCopy(BulletSprite);
	POINT FontOrigin;
	FontOrigin.x = Client.right - DrawMe->mMaxRounds * BulletSprite->GetWidth();
	int StrWidth = GetFontBySizeIndex(WEAPONSELECTOR_BULLET_FONT_ID)->GetStringWidth(Name);
	if(FontOrigin.x + StrWidth > Client.right)
		FontOrigin.x -= (FontOrigin.x + StrWidth) - Client.right + 20;
	FontOrigin.y = Client.bottom - BulletSprite->GetHeight() - GetFontBySizeIndex(WEAPONSELECTOR_BULLET_FONT_ID)->GetCharHeight() - 5;
	int FullWidth = DrawMe->mCurrentRounds * BulletSprite->GetWidth();
	if(FullWidth > Client.right - Client.left)
		return;
	GameWeaponSelector.BulletName->SetLoc(FontOrigin);
	GameWeaponSelector.BulletName->SetWidth(Client.right - Client.left);
	int FullHeight = BulletSprite->GetHeight();
	POINT Loc;
	Loc.x = Client.right - FullWidth;
	Loc.y = Client.bottom - FullHeight;
	for(int i = 0; i < DrawMe->mCurrentRounds; i++)
	{
		MySprite->SetLoc(Loc);
		MySprite->Draw(TheDisplay);
		Loc.x += BulletSprite->GetWidth();
	}
	GameWeaponSelector.BulletName->Update(timediff);
	GameWeaponSelector.BulletName->Draw(TheDisplay);
	delete MySprite;
}
Esempio n. 5
0
void BackBuffer::DrawSprite(Sprite& sprite)
{
	SDL_Rect dest;

	dest.x = sprite.GetX();
	dest.y = sprite.GetY();
	dest.w = sprite.GetWidth();
	dest.h = sprite.GetHeight();

	SDL_RenderCopy(m_pRenderer, sprite.GetTexture()->GetTexture(), 0, &dest);
}
Esempio n. 6
0
uint16 EffectActor::GetHeight(void) const
{
    Assert(m_effectSpriteGroup);
    if (!m_effectSpriteGroup) return 0;

    Sprite * theSprite = m_effectSpriteGroup->GetGroupSprite((GAME_ACTION)m_curEffectAction);

    if (!theSprite && (m_curEffectAction != EFFECTACTION_PLAY))
    {
        theSprite = m_effectSpriteGroup->GetGroupSprite((GAME_ACTION)EFFECTACTION_PLAY);
    }

    return theSprite ? theSprite->GetHeight() : 0;
}
Esempio n. 7
0
uint16 TradeActor::GetHeight(void)
{
	Assert(m_goodSpriteGroup != NULL);
	if (m_goodSpriteGroup == NULL) return 0;

	Sprite	*theSprite;

	theSprite = m_goodSpriteGroup->GetGroupSprite((GAME_ACTION)m_curGoodAction);
	if (theSprite != NULL) {
		return theSprite->GetHeight();
	} else {
		return 0;
	}
}
void ActionSetVisibilityPoint::Redo()
{
	Sprite* visibilityToolSprite = visibilityToolProxy->GetSprite();
	RenderManager::Instance()->SetRenderTarget(visibilityToolSprite);
	RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f);

	cursorSprite->SetPosition(redoVisibilityPoint - cursorSprite->GetSize() / 2.f);
	cursorSprite->Draw();

	RenderManager::Instance()->RestoreRenderTarget();

	visibilityToolProxy->UpdateVisibilityPointSet(true);
	visibilityToolProxy->UpdateRect(Rect(0.f, 0.f, visibilityToolSprite->GetWidth(), visibilityToolSprite->GetHeight()));
	visibilityToolProxy->SetVisibilityPoint(redoVisibilityPoint);
}
Esempio n. 9
0
ControlsPositionData ControlsAdjustSizeCommand::ApplyAjustedSize(HierarchyTreeController::SELECTEDCONTROLNODES& controls)
{
	ControlsPositionData resultData;
	
	for (HierarchyTreeController::SELECTEDCONTROLNODES::iterator iter = controls.begin(); iter != controls.end(); ++iter)
	{
		HierarchyTreeControlNode* control = (*iter);
		UIControl* uiControl = control->GetUIObject();
		int32 nodeId = control->GetId();
		
		if (uiControl)
		{
			// Get sprite
			Sprite* sprite = uiControl->GetSprite();
			Rect prevRect = uiControl->GetRect();
			Rect updatedRect = prevRect;
			
			if (sprite)
			{
				// Save control size data for undo
				resultData.AddControl(uiControl);
				// Set new size of updated rect
				updatedRect.dx = sprite->GetWidth();
				updatedRect.dy = sprite->GetHeight();
			
				BaseMetadata* baseMetadata = GetMetadataForTreeNode(nodeId);

   				// This command is NOT state-aware and contains one and only param.
   				baseMetadata->SetActiveParamID(0);
  		 		baseMetadata->ApplyResize(prevRect, updatedRect);
    
  		  		SAFE_DELETE(baseMetadata);
			}
		}
	}
	
	return resultData;
}
void BackGroundPropertyGridWidget::SetStretchCapMaxValues()
{
	WidgetSignalsBlocker blocker(ui->drawTypeComboBox);
	
	// Get current drawType combo value
	int selectedIndex = ui->drawTypeComboBox->currentIndex();
	UIControlBackground::eDrawType drawType = BackgroundGridWidgetHelper::GetDrawType(selectedIndex);
	
	// Set default values
	int horizontalStretchMax = 999;
	int verticalStretchMax = 999;
	
	// For DRAW_TILED option we should set horizontal and vertical stretch maximum values
	// Tiling the sprite to more than half of its size have no sence
	if (drawType == UIControlBackground::DRAW_TILED)
	{
		QString spriteName =  ui->spriteLineEdit->text();
		if (!spriteName.isEmpty())
		{
			Sprite* sprite = Sprite::Create(spriteName.toStdString());
			
			if (sprite)
			{
				// Get sprite's active size
				float32 texDx = sprite->GetWidth();
				float32 texDy = sprite->GetHeight();
				// Calculate maximum stretch values
				horizontalStretchMax = texDx / 2 - 1;
				verticalStretchMax = texDy / 2 - 1;
            }
        	SafeRelease(sprite);
		}
	}

	ui->lrSpinBox->setMaximum(horizontalStretchMax);
	ui->tbSpinBox->setMaximum(verticalStretchMax);
}
Esempio n. 11
0
    Character::Character(int aNumberOfLimbs, glm::vec2 aRangeOfLimbSize, glm::vec2 aRangeOfStats, glm::vec2 aPosition, bool aIsPlayer)
    {
        m_SwingLeft = false;
        m_Timer = nullptr;
        m_DamageTimer = nullptr;
        
        m_Destroyed = false;
        m_DestroyPlayer = false;
        m_SlatedForDestruction = false;
        
        m_Health = DEFAULT_HEALTH;
        m_Strength = DEFAULT_STRENGTH;
        m_Speed = DEFAULT_SPEED;

        m_IsPlayer = aIsPlayer;
        
        m_NumberOfLimbs = aNumberOfLimbs;
        bool leftArm = true;
        bool leftLeg = true;
        string limbType;
        Random* random = new Random();
        
        for(float i = 0; i < m_NumberOfLimbs; i++)
        {
            //TODO: Fine tune the positioning based off of image size
            //Assume all characters face the same direction on spawn
            vec2 position = aPosition;
            random->RandomizeSeed();
            
            //TODO: Make a local variable, give it a 1% chance of becoming a second head. If it is, set the local variable to i, i to 1 (for head), make the head, then set i to the local variable

            if (i == 0)
            {
                //Torso, do nothing
                if(m_IsPlayer == true)
                    limbType = "CharTorso"; //TODO: Make these constants
                else
                    limbType = "DemonTorso";
            }
            else if (i == 1)
            {
                //Gives visibility to the body better. Decide if we want to do this
                position.y -= 2;
                if(m_IsPlayer == true)
                    limbType = "CharHead";
                else
                    limbType = "DemonHead";
            }
            else
            {
                if ((int)i % 2 == 0)
                {
                    if (leftArm == true)
                    {
                        position.x -= 16;
                        if(m_IsPlayer == true)
                            limbType = "CharArmLeft";
                        else
                            limbType = "DemonArmLeft";
                    }
                    else
                    {
                        position.x += 16;
                        if(m_IsPlayer == true)
                            limbType = "CharArmRight";
                        else
                            limbType = "DemonArmRight";
                    }

                    position.y += i;// / m_NumberOfLimbs;
                    leftArm = !leftArm;
                }
                else
                {
                    if (leftLeg == true)
                    {
                        position.x -= 8;   //TODO: Change this to be based on the image width of m_Limbs.at(0)
                        if(m_IsPlayer == true)
                            limbType = "CharLegLeft";
                        else
                            limbType = "DemonLegLeft";
                    }
                    else
                    {
                        position.x += 8;
                        if(m_IsPlayer == true)
                            limbType = "CharLegRight";
                        else
                            limbType = "DemonLegRight";
                    }

                    position.y -= 16;
                    leftLeg = !leftLeg;
                }
            }
            
            Sprite* sprite = new Sprite(limbType);
            
            glm::vec2 size = glm::vec2(sprite->GetWidth(), sprite->GetHeight());
            
            size.x *= ((float)random->RandomRange(aRangeOfLimbSize.x * 10, aRangeOfLimbSize.y * 10)) / 10.0f; //The multiple and divide is done because the function returns an int
            size.y *= ((float)random->RandomRange(aRangeOfLimbSize.x * 10, aRangeOfLimbSize.y * 10)) / 10.0f;
            
            if(size.x == 0)
                size.x = sprite->GetWidth();
            if(size.y == 0)
                size.y = sprite->GetHeight();
            
            vec3 stats = vec3(10, 10, 10);
            stats.x *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f; //The multiple and divide is done because the function returns an int
            stats.y *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f;
            stats.x *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f;
            
            Limb* limb = CreateALimb(limbType, position, size, stats, 0.0f);
            
            //Attach the shape to the physics object
            ServiceLocator::GetShapeCache()->AddFixtures(limb->GetLimb(), limbType);
            vec2 anchorPoint = ServiceLocator::GetShapeCache()->GetAnchorPoint(limbType);
            
            sprite->SetAnchorPoint(anchorPoint.x, anchorPoint.y);
            limb->GetLimb()->AddChild(sprite, true);

            m_Limbs.push_back(limb);
            
            if(i == 2)
            {
                Sprite* swordSprite = new Sprite("Sword");
                glm::vec2 swordSize = glm::vec2(swordSprite->GetWidth(), swordSprite->GetHeight());
                
                vec3 swordStats = vec3(10, 10, 10);
                swordStats.x *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f;
                swordStats.y *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f;
                swordStats.x *= ((float)random->RandomRange(aRangeOfStats.x * 10, aRangeOfStats.y * 10)) / 10.0f;
                
                // Weapon(std::string type, glm::vec2 position = vec2(0, 0), glm::vec2 size = vec2(32, 32), glm::vec3 stats = vec3(10, 10, 10), float angle = 0.0f);

                m_Weapon = new Weapon("Sword", m_Limbs.at(2)->GetLimb()->GetLocalPosition() - swordSize, swordSize, swordStats, 180.0f);
                m_Weapon->GetWeapon()->SetType("WEAPON");
                
                //Attach the shape to the physics object
                ServiceLocator::GetShapeCache()->AddFixtures(m_Weapon->GetWeapon(), "Sword");
                vec2 swordAnchorPoint = ServiceLocator::GetShapeCache()->GetAnchorPoint("Sword");
                
                swordSprite->SetAnchorPoint(swordAnchorPoint.x, swordAnchorPoint.y);
                m_Weapon->GetWeapon()->AddChild(swordSprite, true);
                
                m_Weapon->GetWeapon()->SetLocalPosition(m_Limbs.at(2)->GetLimb()->GetLocalPosition() + vec2(0, 20));   //TODO: Tweak this
            }
        }
        
        SafeDelete(random);
    }
Esempio n. 12
0
void LabeledSprite(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height)
{
    Sprite *image = new Sprite(mgr);
    image->SetImage(mgr->GetResourceManager()->GetImage(ARROW_HANDLE));
    image->AddTransformation(new AnchorTransformation());
    image->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2));
    OrbitTransformation *orbiter = new OrbitTransformation(150, 5000, 0, CounterClockwise);
    image->AddTransformation(orbiter);
    mgr->RegisterGameObject(image);

    TextSprite *text = new TextSprite(mgr, (char *)"Normal");
    text->AddTransformation(new AnchorTransformation());
    text->AddTransformation(new AnchorToTransformation(image, image, (float)(text->GetHeight() / 2 + image->GetHeight() / 2 + 10), 0, RelativeToNormal));
    text->AddTransformation(new OrientToTransformation((IDirectional*)image, OrientAlongOrientation));
    mgr->RegisterGameObject(text);
}
Esempio n. 13
0
	void Sample::Start()
	{

		cache_ = GetSubsystem<ResourceCache>();
		ui_ = GetSubsystem<UI>();
		graphics_ = GetSubsystem<Graphics>();
		
		//////////////////////////////////////////////////////////////////////////
		// Get default styles
		XMLFile* styleFile = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml");
		ui_->GetRoot()->SetDefaultStyle(styleFile);
		// create main ui
		rootUI_ = ui_->GetRoot()->CreateChild<UIElement>("IDERoot");
		rootUI_->SetSize(ui_->GetRoot()->GetSize());
		rootUI_->SetTraversalMode(TM_DEPTH_FIRST);     // This is needed for root-like element to prevent artifacts
		rootUI_->SetDefaultStyle(styleFile);

		//////////////////////////////////////////////////////////////////////////
		/// Create console
		console_ = engine_->CreateConsole();
		console_->SetDefaultStyle(styleFile);

		//////////////////////////////////////////////////////////////////////////
		/// Create debug HUD.
		debugHud_ = engine_->CreateDebugHud();
		debugHud_->SetDefaultStyle(styleFile);

		//////////////////////////////////////////////////////////////////////////
		/// Subscribe key down event
		SubscribeToEvent(E_KEYDOWN, HANDLER(Sample, HandleKeyDown));

		// edit clear color, set background color
		Renderer* renderer = GetSubsystem<Renderer>();
		Zone* zone = renderer->GetDefaultZone();
		zone->SetFogColor(Color(0.3f, 0.3f, 0.4f)); // Set background color for the scene

		//////////////////////////////////////////////////////////////////////////
		/// Create Cursor
// 		Cursor* cursor_ = new Cursor(context_);
// 		cursor_->SetStyleAuto(styleFile);
// 		ui_->SetCursor(cursor_);
// 		if (GetPlatform() == "Android" || GetPlatform() == "iOS")
// 			ui_->GetCursor()->SetVisible(false);
		/// Show Platform Cursor
		Input* input = GetSubsystem<Input>();
		input->SetMouseVisible(true);

		//////////////////////////////////////////////////////////////////////////
		/// create an svg image
		rootUI_->AddChild(CreateSVGSprite("GameData/svg/23.svg"));

		Sprite* drawing = CreateSVGSprite("GameData/svg/drawing.svg");
		if (drawing)
		{
			// Set logo sprite hot spot
			drawing->SetHotSpot(0, drawing->GetHeight());
			drawing->SetAlignment(HA_LEFT, VA_BOTTOM);
			rootUI_->AddChild(drawing);
		}
		Sprite* nano = CreateSVGSprite("GameData/svg/nano.svg");
		if (nano)
		{
			// Set logo sprite hot spot
			nano->SetHotSpot(0, -nano->GetHeight());
			nano->SetAlignment(HA_LEFT, VA_TOP);
			rootUI_->AddChild(nano);
		}
		
	}
Esempio n. 14
0
    void Game::Loop()
    {
        // Splash screen
        SDL_Surface* sdl_surface = m_screen->GetSDLSurface();
        SDL_FillRect(sdl_surface, 0, SDL_MapRGB(sdl_surface->format, 101, 192, 49));
        Sprite* sprite = Sprite::CreateFromTexture(*m_gfx_manager, "splash");
        sprite->Render(*m_screen, (m_screen->GetWidth() / 2) - (sprite->GetWidth() / 2), (m_screen->GetHeight() / 2) - (sprite->GetHeight() / 2));
        SDL_Flip(sdl_surface);
        SDL_Event event;
        bool running = true;
        bool exit = false;
        unsigned int interval = 0;
        m_timer->Reset();
        while (running && interval < 3000)
        {
            while (SDL_PollEvent(&event))
            {
                switch (event.type)
                {
                    case SDL_QUIT:
                        running = false;
                        exit = true;
                        break;
                    case SDL_KEYDOWN:
                        running = false;
                        break;
                    default:
                        break;
                }
            }
            m_timer->Update();
            interval += m_timer->GetInterval();
        }
        Sprite::DestroySprite(sprite);

        if (!exit)
        {
            m_timer->Reset();
            running = true;
            while (running)
            {
                while (SDL_PollEvent(&event))
                {
                    switch (event.type)
                    {
                        case SDL_QUIT:
                            running = false;
                            break;
                        case SDL_KEYDOWN:
                            // Exit game
                            if (event.key.keysym.sym == SDLK_ESCAPE)
                            {
                                if (m_menu)
                                {
                                    running = false;
                                }
                                else
                                {
                                    StartNewGame(true);
                                }
                            }
                            // New game
                            else if (event.key.keysym.sym == SDLK_F2)
                            {
                                StartNewGame(false);
                            }
                            // Pause game
                            else if (event.key.keysym.sym == SDLK_p)
                            {
                                if (!m_menu)
                                {
                                    m_pause = !m_pause;
                                }
                            }
                            // Sound on/off
                            else if (event.key.keysym.sym == SDLK_s)
                            {
                                int volume = Mix_Volume(-1, -1);
                                if (volume == 0)
                                {
                                    Mix_Volume(-1, MIX_MAX_VOLUME);
                                }
                                else
                                {
                                    Mix_Volume(-1, 0);
                                }
                            }
                            // Screenshot
                            else if (event.key.keysym.sym == SDLK_F11)
                            {
                                m_screen->Capture();
                            }
                            break;
                        default:
                            break;
                    }
                }

                // Update
                if (m_snake->IsAlive())
                {
                    m_timer->Update();
                    if (!m_pause)
                    {
                        Uint8* key_state = SDL_GetKeyState(NULL);
                        m_controller->KeyboardInput(key_state);
                        m_snake->Update();
                        m_map->Update();
                        m_controller->Update();
                    }
                }
                else if (m_autoplay)
                {
                    StartNewGame(true);
                }

                // Render scene
                m_view->SetFocus(m_snake->GetX(), m_snake->GetY());
                sdl_surface = m_screen->GetSDLSurface();
                SDL_FillRect(sdl_surface, 0, SDL_MapRGB(sdl_surface->format, 0, 0, 0));
                m_view->Render();
                if (!m_autoplay)
                {
                    m_status->Render();
                }
                if (m_menu)
                {
                    m_menu->Render();
                }
                SDL_Flip(sdl_surface);
            }
        }

        // Credits screen
        sdl_surface = m_screen->GetSDLSurface();
        SDL_FillRect(sdl_surface, 0, SDL_MapRGB(sdl_surface->format, 101, 192, 49));
        sprite = Sprite::CreateFromTexture(*m_gfx_manager, "credits");
        sprite->Render(*m_screen, (m_screen->GetWidth() / 2) - (sprite->GetWidth() / 2), (m_screen->GetHeight() / 2) - (sprite->GetHeight() / 2));
        SDL_Flip(sdl_surface);
        running = true;
        interval = 0;
        m_timer->Reset();
        while (running && interval < 3000)
        {
            while (SDL_PollEvent(&event))
            {
                switch (event.type)
                {
                    case SDL_KEYDOWN:
                        running = false;
                        break;
                    default:
                        break;
                }
            }
            m_timer->Update();
            interval += m_timer->GetInterval();
        }
        Sprite::DestroySprite(sprite);
    }
Esempio n. 15
0
bool MyGame::LoadResource()
{
    // Build scene graph
    ContainerNode* root = new ContainerNode();
    OrthographicProjectionNode* ortho = new OrthographicProjectionNode();

    Texture* texTile = Texture::Get("!tile.png");
    Texture* texStair = Texture::Get("!stair.png");
    Font* texFont = Font::Get("!DroidSans.ttf|texture_size=256");


    Cube* floor = new Cube(Vector3f(50.f, 1.f, 50.f), 50.f, "Floor");
    floor->SetTexture(texTile);
    root->AddChild(floor);
    floor->AddToPhysic(0, Vector3f(0, -.5f, 0));


    // Stair
    float sw = 1.f; // stair depth
    float sh = 1.0f; // stair height
    for(int i = 0; i < 5; ++i)
    {
        Cube* stair = new Cube(Vector3f(6.f, sh, sw), 4);
        stair->SetTexture(texStair);
        root->AddChild(stair);
        stair->AddToPhysic(0, Vector3f(0, sh / 2.f + (i * sh), 5 + (i * sw)));
    }

    TextNode* title = new TextNode(texFont, 12.f, "TAK game sample");
    title->SetShader(Shader::Get("!nolight"));
    title->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 25, 0);
    ortho->AddChild(title);

    TextNode* instruction = new TextNode(texFont, 12.f, "Drag and hold left mouse button to rotate, hold right mouse button to zoom");
    instruction->SetShader(Shader::Get("!nolight"));
    instruction->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 45, 0);
    ortho->AddChild(instruction);

    m_txtFps = new TextNode(texFont);
    m_txtFps->SetShader(Shader::Get("!nolight"));
    m_txtFps->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 65, 0);
    ortho->AddChild(m_txtFps);

    m_txtCubeCount = new TextNode(texFont);
    m_txtCubeCount->SetShader(Shader::Get("!nolight"));
    m_txtCubeCount->SetPositionAbsolute(10, GetScene().GetParams().GetHeight() - 85, 0);
    ortho->AddChild(m_txtCubeCount);



    Cube* pc1;

    // front wall
    pc1 = new Cube(Vector3f(5.5f, 7.f, .5f), 10.f);
    pc1->SetTexture(texTile);
    root->AddChild(pc1);
    pc1->AddToPhysic(0, Vector3f(0, pc1->GetSize().y / 2.f, 9.75f));

    // right wall
    pc1 = new Cube(Vector3f(.5f, 7.f, 10.f), 10.f);
    pc1->SetTexture(texTile);
    root->AddChild(pc1);
    pc1->AddToPhysic(0, Vector3f(-3, pc1->GetSize().y / 2.f, 5));

    // right wall
    pc1 = new Cube(Vector3f(.5f, 7.f, 10.f), 10.f);
    pc1->SetTexture(texTile);
    root->AddChild(pc1);
    pc1->AddToPhysic(0, Vector3f(3, pc1->GetSize().y / 2.f, 5));

    // Flag engine logo
    Sprite* flag = new Sprite(128, 128, Texture::Get("!engineflag.png"));
    flag->SetShader(Shader::Get("!nolight"));
    flag->SetPositionAbsolute(GetScene().GetParams().GetWidth() - flag->GetWidth() / 2.f, flag->GetHeight() / 2.f - 20.f, 0);
    ortho->AddChild(flag);

    root->AddChild(ortho);
    GetScene().SetRoot(root);

    // Setup camera:
    Camera* camera = new LookAtCamera(Vector3f(0, 0, 5), 25.f);
    GetScene().SetCamera(camera);

    return true;
}
Esempio n. 16
0
int main()
{

	Window window(1200, 600, "This is window!");
	Render render(window.GetWidth(), window.GetHeight());

	ResourceManager* res = ResourceManager::Create();

	Texture* card;
	card = &res->LoadTextureFromFile("Test.png");
	Texture* bg = &res->LoadTextureFromFile("Background.png");
	Texture bulletTex = res->LoadTextureFromFile("Bullet.png");
	Texture chipTex = res->LoadTextureFromFile("suitsChip.png");

	Sprite Background, Card;
	Background.SetTexture(*bg);
	Background.Scale(1.5);
	Background.SetPosition(-800, -600);
	Card.SetTexture(*card);
	Card.SetPosition(400, 300);

	std::vector<Sprite> bullets, chips;

	int r = 0, c = 0;
	for (int i = 0; i < 12; i++)
	{
		r = i % 4;
		c = i % 3;
		Sprite temp;
		temp.SetTexture(chipTex);
		temp.SetPosition(r*350, c*225);
		chips.push_back(temp);
	}

	window.SetClearColor(100, 50, 150);
	float rotation = 0;
	float cardSpeed = 10.0f, rotationSpeed = 2.0f, bulletSpeed = 15.0f;
	float chipScale = 1.0f;
	bool grow = true;

	float timer = 0;

	while (window.IsOpen())
	{
		timer++;

		if (Input::Hold(Button::W))
		{
			Card.SetPosition(Card.GetX(), Card.GetY()-cardSpeed);
		}
		if (Input::Hold(Button::A))
		{
			Card.SetPosition(Card.GetX()-cardSpeed, Card.GetY());
		}
		if (Input::Hold(Button::S))
		{
			Card.SetPosition(Card.GetX(), Card.GetY()+cardSpeed);
		}
		if (Input::Hold(Button::D))
		{
			Card.SetPosition(Card.GetX()+cardSpeed, Card.GetY());
		}


		if (Input::Hold(Button::UP))
		{
			rotation += rotationSpeed;
		}
		if (Input::Hold(Button::LEFT))
		{
			rotation -= rotationSpeed;
		}
		if (Input::Hold(Button::DOWN))
		{
			rotation -= rotationSpeed;
		}
		if (Input::Hold(Button::RIGHT))
		{
			rotation += rotationSpeed;
		}

		Card.Rotate(rotation);
		Background.Rotate(-rotation);

		if (Input::Press(Button::SPACE))
		{
			Sprite temp;
			temp.SetTexture(bulletTex);
			temp.Rotate(rotation);
			temp.SetPosition((Card.GetX()+(Card.GetWidth()*0.5 - temp.GetWidth()*0.5)), (Card.GetY()+(Card.GetHeight()*0.5 - temp.GetHeight()*0.5)));
			bullets.push_back(temp);
		}

		if (chipScale >= 1.0251f)
			grow = false;
		if (chipScale <= 0.975f)
			grow = true;

		if (grow)
		{
			chipScale += 0.001f;
		}
		else if (!grow)
		{
			chipScale -= 0.001f;
		}
		for (int i = 0; i < chips.size(); i++)
		{
			chips[i].Scale(chipScale);
		}

		for (int i = 0; i < bullets.size(); i++)
		{
			float tempX = bullets[i].GetX(), tempY = bullets[i].GetY();
			float tempRot = glm::radians(bullets[i].GetRotation());
			tempX += bulletSpeed*glm::sin(tempRot);
			tempY -= bulletSpeed*glm::cos(tempRot);
			bullets[i].SetPosition(tempX, tempY);
		}

		window.Clear();
		
		render.DrawSprite(Background);	
		for (int i = 0; i < chips.size(); i++)
		{
			render.DrawSprite(chips[i]);
		}
		render.DrawSprite(Card);
		for (int i = 0; i < bullets.size(); i++)
		{
			render.DrawSprite(bullets[i]);
		}

	

		window.Display();
	}

	return 0;
}