コード例 #1
0
ファイル: Level.c プロジェクト: Mayple7/SausageFox150
void LevelCompletion(void)
{
	WhiteOverlay->Position.x = GetCameraXPosition();
	BlackOverlay->Position.x = GetCameraXPosition();

	if (WhiteOverlay->Alpha > 1)
	{
		//Allow player to upgrade their player if upgrades are available
		if (UpgradeComplete)
		{
			//Continue onto the map
			if (BlackOverlay->Alpha > 1)
			{
				if(GetCurrentState() == GS_Level1)
					SetNextState(GS_Narr1);
				else
					SetNextState(GS_MapLevel);
			}
			else
				BlackOverlay->Alpha += GetDeltaTime();
		}
		else if (!UpgradeComplete)
			UpdateUpgradeScreenObjects();
	}
	else
		WhiteOverlay->Alpha += 2 * GetDeltaTime();
}
コード例 #2
0
ファイル: Level.c プロジェクト: Mayple7/SausageFox150
void UpdatePlayerHurt(Player *CurrentPlayer)
{
	IndiOverlay->Position.x = GetCameraXPosition();

	HurtOverlay->Position.x = GetCameraXPosition();

	if (HurtOverlay->ScaleX < 6.0f)
	{
		HurtOverlay->ScaleX += 2 * GetDeltaTime();
		HurtOverlay->ScaleY += 2 * GetDeltaTime();
	}

	//Displayer that player damage layer
	if (lastHealth > CurrentPlayer->CurrentPlayerStats.CurrentHealth && lastHealth > 0 && lastDefense == CurrentPlayer->PlayerWeapon->BonusDefense)
	{
		float overlayScalar = 1.0f + 1.5f * ((float)CurrentPlayer->CurrentPlayerStats.CurrentHealth / CurrentPlayer->CurrentPlayerStats.MaxHealth);
		if (overlayScalar < 1)
			overlayScalar = 1.0f;
		HurtOverlay->ScaleX = overlayScalar;
		HurtOverlay->ScaleY = overlayScalar;
	}

	lastDefense = CurrentPlayer->PlayerWeapon->BonusDefense; //Player won't get hurt when picking weapon with less defense
	lastHealth  = CurrentPlayer->CurrentPlayerStats.CurrentHealth;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: BownDown/2DGameEngineGL
int main()
{
		
		Initialize(1024,720,false,"Game");

		////////takes in 1-9,A,B,C,D,E,F
		Sprite Player = Sprite("./rescources/Diva_Saya.jpg",640,480,"1.0f","1.0f","1.0f","1.0f");
		std::vector<Sprite> ex;
		ex.push_back(Player);
		ex.reserve(ex.size() +1);

		
		while (update()){ 
			_update_fps_counter (window);
			ClearScreen();

			ex[0].Input();
			ex[0].Draw();
			//Player.Input();
			//Player.Draw();
			double Delta = GetDeltaTime();
		}

		ShutDown();
		return 0; 
}
コード例 #4
0
ファイル: Game.cpp プロジェクト: hburnett/NetworkedCheckers
void Game::Update()
{
	m_pGameStateManager->UpdateGameStates(GetDeltaTime());
	
	if(g_inputManager.KeyPressedOnce(GLFW_KEY_ESCAPE))
		m_bGameOver = true;

	if(g_inputManager.KeyPressedOnce( GLFW_KEY_F1 ))
	{
		if( m_vSyncEnabled == false)
		{
			m_vSyncEnabled = true;
		}

		else if( m_vSyncEnabled == true)
		{
			m_vSyncEnabled = false;
		}
			VSyncEnabled( m_vSyncEnabled );
			m_fTotalTime	 = 0;
			m_iTotalFrames	 = 0;
	}

	g_inputManager.ProcessKeyboardCommands();
	g_inputManager.ProcessMouseCommands();
}
コード例 #5
0
ファイル: Level.c プロジェクト: Mayple7/SausageFox150
void UpdatePlayerRank(Player *CurrentPlayer)
{
	int nextExperience = GetMaxExperience(CurrentPlayer);

	//Increase the rank if XP has mer it's goal
	if (CurrentPlayer->CurrentPlayerStats.Experience >= nextExperience)
	{
		CurrentPlayer->CurrentPlayerStats.Rank++;
		CurrentPlayer->CurrentPlayerStats.Experience -= nextExperience;

		//This will be the amount a player has leveled up.
		CurrentPlayer->CurrentPlayerStats.Upgrades++;

		//Pop up
		GuudJub->ItemType = PopUp_Rise;
		holdTime = 2;
	}

	GuudJub->Position.x = GetCameraXPosition();
	switch (GuudJub->ItemType)
	{
	case PopUp_Rise:
		if (GuudJub->Position.y < 0)
			GuudJub->Position.y += 360 * GetDeltaTime();
		else
		{
			GuudJub->ItemType = PopUp_Hold;
			GuudJub->Position.y = 0;
		}
		break;
	case PopUp_Hold:
		if (holdTime > 0)
			holdTime -= GetDeltaTime();
		else
			GuudJub->ItemType = PopUp_Fall;
		break;
	case PopUp_Fall:
		if (GuudJub->Position.y > -182)
			GuudJub->Position.y -= 360 * GetDeltaTime();
		break;
	}
}
コード例 #6
0
ファイル: SmithGame.cpp プロジェクト: haved/DafLanguage
void SmithGame::NextFrame() {
    camTarget += walkVector*(GetDeltaTime()*8);
    camPos=camTarget+glm::vec3(0, -4, 10);
    if(!pause) {
        UpdateIngameTime();
        scene->Update();
    }
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glm::mat4 view = glm::lookAt(camPos, camTarget, glm::vec3(0, 1, 0));
    scene->Render(projectionMatrix*view);
    m_fpsCounter.NextFrame();
}
コード例 #7
0
ファイル: AIE_Py.cpp プロジェクト: blueskies9041/Blue
//////////////////////////////////////////////////////////////////////////
// Gets the Delta Time
//////////////////////////////////////////////////////////////////////////
PyObject* AIE_GetDeltaTime(PyObject *self, PyObject *args)
{
	//Manually added by me! Beware! 
	float fDeltaTime;
	if (!PyArg_ParseTuple( args, "f", &fDeltaTime ) ) 
	{
		ParsePyTupleError( __func__, __LINE__ );
		return nullptr;
	}
	fDeltaTime = GetDeltaTime();
	return Py_BuildValue("f", fDeltaTime);
}
コード例 #8
0
ファイル: Level.c プロジェクト: Mayple7/SausageFox150
void GameCompletion(void)
{
	BlackOverlay->Position.x = GetCameraXPosition();

	//Continue onto the map
	if (BlackOverlay->Alpha > 1)
	{
		// Change to narrative
		SetNextState(GS_Narr2);
	}
	else
		BlackOverlay->Alpha += GetDeltaTime();

}
コード例 #9
0
void UpdateGameState(){
	float fDeltaT = GetDeltaTime();
	//draw cannon to screen
	DrawSprite(player.spriteId);
	MoveSprite(player.spriteId, player.x, player.y);

	//draw scores to screen
	DrawString("SCORE < 1 >", iScreenWidth * 0.025f, iScreenHeight - 2);
	DrawString("HIGH SCORE", iScreenWidth * 0.4f, iScreenHeight - 2);
	DrawString("SCORE < 2 >", iScreenWidth * 0.75f, iScreenHeight - 2);
	DrawString("CREDIT 00", iScreenWidth *.7f, iScreenHeight * .05f);
	DrawString("Lives", iScreenWidth *.075f, iScreenHeight * .05f);
	DrawLine(32.f, 45.f, 640.f, 45.f, SColour(0x00, 0xFC, 0x00, 0xFF));

	//draw aliens to screen
	for (int i = 0; i < 18; i++)
	{
		DrawSprite(Aliens[i].spriteId);
		Aliens[i].Move(fDeltaT, 1);
		if (Aliens[i].x <= Aliens[i].min + Aliens[i].width * .5f)
		{
			for (int a = 0; a < 6; a++)
			{
				Aliens[i + a].y = Aliens[i].y;
				DrawSprite(Aliens[i + a].spriteId);
				Aliens[i + a].direction = Aliens[i].direction;
				//Aliens[i + a].speed += 100;
				//Aliens[i + a].Move(fDeltaT, 1);
			}
			i += 6;
			//Aliens[i].tracker == false;
		}
		Aliens[i].SetMoveExtremes(32.f, 625.f);
		//cout << Aliens[i].max;
		if (Aliens[i].x >= Aliens[i].max /*+ Aliens[i].width * .5f*/)
		{
			for (int a = 0; a < 6; a++)
			{
				Aliens[i - a].y = Aliens[i].y;
				DrawSprite(Aliens[i - a].spriteId);
				Aliens[i - a].direction = Aliens[i].direction;
				//Aliens[i + a].speed += 100;
				//Aliens[i + a].Move(fDeltaT, 1);
			}
			i += 6;
		}
	}
}
コード例 #10
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    double dt = GetDeltaTime();
    terrain.draw(waterLevel, slope);
    if(terrain.current_view == terrain.perspective_view)
    {
        glEnable(GL_DEPTH_TEST);
        glLoadIdentity();
        gluLookAt(-3,-3,7,  3,3,0,  0,0,1);
    }
    else if(terrain.current_view == terrain.top_view)
    {
        glDisable(GL_DEPTH_TEST);
        glLoadIdentity();
    }
    else // current_view == eye_view
    {
        double HOVER_HEIGHT = .2;
        glEnable(GL_DEPTH_TEST);
        glLoadIdentity();
        double z_level = 2.0;
        double x = person.get_x();
        double y = person.get_y();
        double z = fmax(terrain.get_z(x, y, slope), WATER_HEIGHT)+HOVER_HEIGHT;
        double dx = person.get_dx();
        double dy = person.get_dy();
        double at_x = x + dx;
        double at_y = y + dy;
        double at_z = fmax(terrain.get_z(at_x, at_y, slope), WATER_HEIGHT)+HOVER_HEIGHT;
        gluLookAt(x,y,z,  at_x, at_y, at_z,  0,0,1);
    }
    if (left_button_down)
    {
        person.turnLeft(dt);
    }
    if (right_button_down)
    {
        person.turnRight(dt);
    }
    if (middle_button_down)
    {
        person.move(dt, terrain);
    }
	glutSwapBuffers();
    glutPostRedisplay();
}
コード例 #11
0
ファイル: graphics1.cpp プロジェクト: n8armstrong/cs3600
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    glLoadIdentity();
    double dt = GetDeltaTime();
    if (gFirstPerson)
    {
        double rad = gRat.getDegrees()/180.0 * M_PI;
        double dx = cos(rad) * MOVE_SPEED * dt;
        double dy = sin(rad) * MOVE_SPEED * dt;

        double hover = 2.0;
        double terrainHeight = gMaze.getZ(gRat.getX() + dx, gRat.getY() + dy);
        double waterHeight = gWaterHeight + .4;
        double H = fmax(terrainHeight, waterHeight) + hover;
        double currentTerrainHeight = fmax(waterHeight, gMaze.getZ(gRat.getX(), gRat.getY()));
        double tilt = (fmax(terrainHeight, waterHeight) - currentTerrainHeight);
        double lookZ = H + tilt;
        gluLookAt(gRat.getX(), gRat.getY(), H, gRat.getX() + dx, gRat.getY() + dy, lookZ, 0, 0, 1);
        // when doing rat, calculate at point but z will stay.
    }
    else
    {
        gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
    }

	gMaze.draw(gWaterHeight);
    gRat.draw(gFirstPerson);
    if (gLeft) gRat.spinLeft(dt);
    if (gRight) gRat.spinRight(dt);
    if (gMiddle) gRat.move(dt);

    if (gFirstPerson)
    {
        gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
    }
    else
    {
        gluPerspective(40, (double)screen_x/screen_y, RES*.5, 3*(RES+RES));
    }

	glutSwapBuffers();
	glutPostRedisplay();
}
コード例 #12
0
ファイル: main.cpp プロジェクト: coringuyen/OnePieceUltimate
int main(int argc, char* argv[])
{

	//\ Lets initialise the AIE Framework and give the window it creates an appropriate title
	Initialise(iScreenWidth, iScreenHeight, false, "One of Piece");
	SetBackgroundColour(SColour(0x00, 0x00, 0x00, 0xFF));
	AddFont("./fonts/invaders.fnt");

	g_AssetManager.Load("Player", "./images/invaders/luffyPlayer.png", 40, 64);
	g_AssetManager.Load("Bullet", "./images/invaders/chopperBullet.png", 24, 36);
	g_AssetManager.Load("Enemy", "./images/invaders/tumblrEnemy.png", 36, 42);
	g_AssetManager.Load("BG", "./images/invaders/OPbackground.png", iScreenWidth, iScreenHeight);
	g_AssetManager.Load("GameBG", "./images/invaders/Logo (2).png", iScreenWidth, iScreenHeight);
	g_AssetManager.Load("VicBG", "./images/invaders/Luffy_One_Piece_Chibi.png", 400, 500);

	new Player();
	Entity::init();
	GameState ecurrentState = gs_MENU;
	ScoreDB &ref = ScoreDB::getInstance();


	ref.Open();
	//ScoreData myScore = { 0, "Your Timer: " };


	do
	{
		ClearScreen();
		float fDeltaT = GetDeltaTime();

		SetFont("./fonts/invaders.fnt");
		Playgame(fDeltaT);
		
		std::string timeFrame = "DeltaTime: ";
		timeFrame.append(std::to_string(fDeltaT));
		SetFont(nullptr);

	} while (FrameworkUpdate() == false && running);

	ref.Close();
	g_AssetManager.FreeAll();
	Shutdown();

	return 0;
}
コード例 #13
0
ファイル: app.cpp プロジェクト: lasty/ld_warmup30
void App::Run()
{
	lastframe_time = SDL_GetTicks(); //Init timers
	running = true;

	while(running)
	{
		ProcessEvents();

		float dt = GetDeltaTime();
		FPSUpdate(dt);
		Update(dt);

		Render();

		Present();
	}
}
コード例 #14
0
int main( int argc, char* argv[] )
{	

	Initialise( iScreenWidth, iScreenHeight, false, "Just Another Retro Pew Pew" );
	SetBackgroundColour( SColour( 000, 000, 000, 000 ) );

//	player.SetSpriteID(CreateSprite( "./images/player.png", player.GetWidth(), player.GetHeight(), true));

	GameStates eCurrentState = eMAIN_MENU;

	do 
	{
		ClearScreen();
		float fDeltaT = GetDeltaTime();
		switch (eCurrentState)
		{
	case eMAIN_MENU:
		UpdateMainMenu();
			if( IsKeyDown( KEY_ENTER) )
			{
				eCurrentState = eGAMEPLAY;
				
			
			}
			break;
	case eGAMEPLAY:
		UpdateGameState();
		if( IsKeyDown( KEY_ESCAPE) )
			{
				eCurrentState = eMAIN_MENU;

			}

		break;
	default:
		break;
		}
			
	} while ( FrameworkUpdate() == false );

	Shutdown();

	return 0;
}
コード例 #15
0
ファイル: Application.cpp プロジェクト: Mantora/GA
//---------------------------------------------------------------------------------------------------------------------
void
CApplication::MessageLoop()
{
	assert(m_hAppWindow && "application window has not been created!");

	MSG xMessage = {0, 0, 0, 0, 0, 0}; 
	while (xMessage.message != WM_QUIT)
	{
		if (PeekMessage(&xMessage, NULL, 0U, 0U, PM_REMOVE) != 0)
		{
			TranslateMessage(&xMessage);
			DispatchMessage(&xMessage);
		}
		else
		{
			float fDeltaTime = GetDeltaTime();
			OnIdle(fDeltaTime);
		}
	}
}
コード例 #16
0
ファイル: Sprite.cpp プロジェクト: iancarnation/AIE_Projects
// default constructor
Sprite::Sprite()
{
	SetType("Default");
	m_fWidth = 10;
	m_fHeight = 10;
	m_oPosition = Vector2D();
	m_oVelocity = Vector2D();
	m_oForce = Vector2D();
	m_fMass = 1;
	m_fMovementForce = 1;
	m_iSpriteId = -1; //**figure out where to initialize/check for this
	m_iAmmoSlot = 0;
	m_bAlive = false;
	m_cpTextureName = "";
	m_dDeltaTime = GetDeltaTime();

	m_fTop = m_oPosition.m_fY - (m_fHeight / 2);
	m_fBottom = m_oPosition.m_fY + (m_fHeight / 2);
	m_fLeft = m_oPosition.m_fX - (m_fWidth / 2);
	m_fRight = m_oPosition.m_fX + (m_fWidth / 2);
}
コード例 #17
0
ファイル: graphics1.cpp プロジェクト: n8armstrong/cs3600
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);

  glLoadIdentity();
  double dt = GetDeltaTime();
  if (gFirstPerson)
  {
    double rad = gRat.getDegrees()/180.0 * M_PI;
    double dx = cos(rad) * MOVE_SPEED * dt;
    double dy = sin(rad) * MOVE_SPEED * dt;
    gluLookAt(gRat.getX(), gRat.getY(), gRatHeight, gRat.getX() + dx, gRat.getY() + dy, gRatHeight, 0, 0, 1);
    // when doing rat, calculate at point but z will stay.
  }
  else
  {
    gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
  }

	gMaze.draw();
  gRat.draw(gFirstPerson);

  if (gLeft) gRat.spinLeft(dt);
  if (gRight) gRat.spinRight(dt);
  if (gMiddle) gRat.move(dt);

  if (gFirstPerson)
  {
    gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
  }
  else
  {
    gluPerspective(40, (double)screen_x/screen_y, N*.5, 3*(M+N));
  }

	glutSwapBuffers();
	glutPostRedisplay();

}
コード例 #18
0
void Hero::CheckForFire()/// change back to bool
{


	if(GetMouseButtonDown(MOUSE_BUTTON_1))
	{
		time += GetDeltaTime();
		if(time > .1){
			time = 0;
		for (std::list<Bullet>::iterator it=HBullets.begin(); it != HBullets.end(); ++it)
		{
			//HBullets.FireBullet(GetPosition());
			if(!it->IsAlive())
			{
				it->FireBullet(GetPosition());
				return;
			}
		}
		}
	}
	
}
コード例 #19
0
ファイル: timingUtility.cpp プロジェクト: KerryL/rpi
//==========================================================================
// Class:			TimingUtility
// Function:		TimeLoop
//
// Description:		Performs timing and sleeping to maintain specified time
//					step.  Must be called exactly once per loop and AT
//					THE TOP OF THE LOOP!.  If not placed at the top of the loop,
//					the first and second passes through the loop both occur
//					prior to the first sleep.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		bool, true for success, false otherwise
//
//==========================================================================
bool TimingUtility::TimeLoop()
{
	if (counts[0] > 0)
	{
		struct timespec now;
		if (!GetCurrentTime(now))
		{
			outStream << "Failed to get current time:  " << std::strerror(errno) << std::endl;
			return false;
		}

		const double warningThreshold(1.01);// 1% threshold
		elapsed = TimespecToSeconds(GetDeltaTime(now, loopTime));
		if (elapsed > timeStep * warningThreshold)
			outStream << "Warning:  Elapsed time is greater than time step ("
				<< elapsed << " > " << timeStep << ")" << std::endl;
		else
			usleep(1000000 * (timeStep - elapsed));
	}
	else
	{
		elapsed = 0.0;
		assert(currentIndex == 0);
	}

	if (!GetCurrentTime(loopTime))
	{
		outStream << "Failed to get current time:  " << std::strerror(errno) << std::endl;
		return false;
	}

	UpdateTimingStatistics();
	counts[currentIndex]++;

	return true;
}
コード例 #20
0
ファイル: TextCreation.c プロジェクト: Mayple7/SausageFox150
void AnimateFloatingText(TextGlyphs *FirstLetter)
{
	TextGlyphs *nextLetter;
	nextLetter = FirstLetter;

	if(nextLetter && nextLetter->Glyph && nextLetter->Glyph->Alpha <= 0.0f)
	{
		FreeFloatingText(FirstLetter);
		return;
	}

	while(nextLetter)
	{
		if(nextLetter->letter == ' ')
		{
			nextLetter = nextLetter->NextLetter;
			continue;
		}
		if(!(nextLetter->Glyph))
			break;
		if(nextLetter->Glyph->Alpha > 0.9f)
		{
			nextLetter->Glyph->Alpha -= 0.06f * GetDeltaTime();
			nextLetter->Glyph->Position.y += 90.0f * GetDeltaTime();
		}
		else if(nextLetter->Glyph->Alpha > 0.3f)
		{
			nextLetter->Glyph->Alpha -= 1.2f * GetDeltaTime();
			nextLetter->Glyph->Position.y += 90.0f * GetDeltaTime();
		}
		else
		{
			nextLetter->Glyph->Alpha -= 2.4f * GetDeltaTime();
			nextLetter->Glyph->Position.y += 90.0f * GetDeltaTime();
		}
		nextLetter = nextLetter->NextLetter;
	}
}
コード例 #21
0
ファイル: MainMenu.c プロジェクト: Mayple7/SausageFox150
void UpdateMainMenu(void)
{

	PlayAudio(&MenuBackSnd);

	//Handle input and run background animation
	if (DogScroll->CurrentFrame == 17)
	{
		DogScroll->AnimationActive = FALSE;
	}
	
	//If the position is greater than the final position
	if(DogScrollBottom->Position.y >= -345)
	{
		//Blaze the bottom down based on the total distance traveled divided by the number of frames and frames per change
		DogScrollBottom->Position.y -= (420) / 18 / DogScroll->AnimationSpeed;
	}
	
	if (DogScrollBottom->Position.y < OptionsButton->ButtonSprite->Position.y)
	{
		OptionsButton->ButtonSprite->Visible = TRUE;
	}

	if (DogScrollBottom->Position.y < QuitGameButton->ButtonSprite->Position.y)
	{
		QuitGameButton->ButtonSprite->Visible = TRUE;
	}

	if (FoxScroll->CurrentFrame == 17)
		FoxScroll->AnimationActive = FALSE;
	
	if(FoxScrollBottom->Position.y >= -345)
	{
		//Blaze the bottom down based on the total distance traveled divided by the number of frames and frames per change
		FoxScrollBottom->Position.y -= (420) / 18 / FoxScroll->AnimationSpeed;
	}

	if (FoxScrollBottom->Position.y < LoadGameButton->ButtonSprite->Position.y)
	{
		LoadGameButton->ButtonSprite->Visible = TRUE;
	}

	if (FoxScrollBottom->Position.y < CreditsButton->ButtonSprite->Position.y)
	{
		CreditsButton->ButtonSprite->Visible = TRUE;
	}

	//Menu navigation help
	if (TimerGoingUp)
		GettingImpatientTimer += GetDeltaTime();
	else
		GettingImpatientTimer -= GetDeltaTime();
	if (GettingImpatientTimer > 0)
	{
		ChangeTextAlpha(SillyGooseUseMouse, GettingImpatientTimer);

		if (GettingImpatientTimer > 1)
			TimerGoingUp = FALSE;
		else if (GettingImpatientTimer < 0.4)
			TimerGoingUp = TRUE;
	}

#if defined _DEBUG
	// REMOVE FOR RELEASE BUILD
	if(FoxInput_KeyTriggered(VK_HOME))
	{
		SetNextState(GS_EPMenu);
	}
#endif

	InputHandling();
	BackgroundAnimation();
}
コード例 #22
0
ファイル: Main.cpp プロジェクト: Gijs-W/kmint1
int main(int args[])
{

	srand(time(0));
	//auto window = Window::CreateSDLWindow();
	auto application = new FWApplication();
	if (!application->GetWindow())
	{
		LOG("Couldn't create window...");
		return EXIT_FAILURE;
	}

	application->SetTargetFPS(60);
	application->SetColor(Color(255, 10, 40, 255));

	Game* game = new Game(application);

	//while (true){}
	while (application->IsRunning())
	{
		application->StartTick();
		SDL_Event event;
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
			case SDL_QUIT:
				application->Quit();
				break;
			case SDL_KEYDOWN:
				switch (event.key.keysym.scancode){
				case SDL_SCANCODE_SPACE:
					game->Pause();
					break;
				default:
					break;
				}
			}
		}

		application->UpdateGameObjects();
		if (!game->IsPause()){
			game->Update(application->GetDeltaTime());
		}
		application->RenderGameObjects();

		application->SetColor(Color(0, 0, 0, 255));// For the letter colour
		application->DrawTextWithWhiteBorder("[Round] " + std::to_string(game->GetRoundNumber()), SCREEN_WIDTH / 2, 20);
		application->DrawTextWithWhiteBorder("[Seconds Remaining] " + std::to_string(game->GetTimeRemaining()), SCREEN_WIDTH / 2, 40);
		if (game->IsPause()){
			application->DrawTextWithWhiteBorder("[PAUSE]", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
			application->SetColor(Color(238, 233, 233, 255));// For the background
		}
		else{
			application->SetColor(Color(255, 255, 255, 255));// For the background
		}


		if (game->GameOver()){
			application->Quit();
		}
		application->EndTick();


	}
		
	return EXIT_SUCCESS;
}
コード例 #23
0
ファイル: main.cpp プロジェクト: flickenmaste/Python_Stuff
int main(int argc, char *argv[])
{
	
    
	//\================================================================================================
	//\ Initialise Python
	//\================================================================================================
	Py_Initialize();
	//\================================================================================================
	//\Add our current directory to the path lookup for Python imports
	//\================================================================================================
	PySys_SetArgv(argc, argv);
	//PyRun_SimpleString( "from sys import path\nfrom os import getcwd\nprint \"Current Dir\" \, getcwd()\npath.append( getcwd() + \"/scripts\" )\n" );
	PyObject* sysPath = PySys_GetObject((char*)"path");
	PyList_Append(sysPath, PyString_FromString("./scripts"));
	//\================================================================================================
	//\Import the AIE C Functions into Python so that we can call them from there
	//\ we will need to add "import AIE" to any Python files that we wish to use these functions in
	//\================================================================================================
	Py_InitModule("AIE", AIE_Functions);
	//\================================================================================================
	//\ Here we are loading our Python Entry point this is the name of the game.py file that we will be 
	//\ using for this project.
	//\ ** feel free to change this to anything you would like to, "game" is purely intended as a 
	//\    suitable example.
	//\================================================================================================
	PyObject* pModule = ImportPythonModule( "game" );
	
	if (pModule != NULL) 
	{
		//\============================================================================================
		//\ Here we are attempting to resolve a function to call inside our python file
		//\ In this scenario we are looking for the main function inside our game.py file
		//\============================================================================================
		if( AIE::InitialiseFramework( pModule ) )
		{
			AIE::Load(pModule);
			do 
			{

				ClearScreen();
				float fDeltaTime = GetDeltaTime();
				AIE::UpdatePython( pModule, fDeltaTime );

			}while( !FrameworkUpdate() );

			AIE::ShutdownFramework( pModule );
		}
		Py_DECREF(pModule);
    }
    Py_Finalize();

	if( g_pWindowTitle )
	{
		delete[] g_pWindowTitle;
	}

	std::cin.get();

    return 0;
}
コード例 #24
0
ファイル: gamebase.cpp プロジェクト: mockthebear/bearshader
void Game::Update(){
    float dt = std::min(GetDeltaTime(),1.2f );
    stateStack.top()->Update(dt);
}
コード例 #25
0
ファイル: Application.cpp プロジェクト: Shadow864/DirectX11
void Application::Update()
{
	__super::Update();

	for (auto obj : m_ModelObjects)
		obj->Update(GetDeltaTime());

	if (m_MouseDown)
	{
		m_Theta		+= DirectX::XMConvertToRadians((float)(m_LastPos.y - m_MousePos.y));// * GetDeltaTime();
		m_Phi	    += DirectX::XMConvertToRadians((float)(m_LastPos.x - m_MousePos.x));// * GetDeltaTime();
	}

	if (m_Phi > 2.0f * DirectX::XM_PI)
		m_Phi -= 2.0f * DirectX::XM_PI;

	if (m_Phi < -2.0f * DirectX::XM_PI)
		m_Phi += 2.0f * DirectX::XM_PI;


	if (m_Theta >= DirectX::XM_PI/2.f - 0.001f)
		m_Theta = DirectX::XM_PI/2.f - 0.001f;

	if (m_Theta <= -DirectX::XM_PI/2.f + 0.001f)
		m_Theta = -DirectX::XM_PI/2.f + 0.001f;

	m_LastPos.x = m_MousePos.x;
	m_LastPos.y = m_MousePos.y;

	std::wostringstream outs;   
	outs.precision(6);
	outs << L"m_Theta: " << m_Theta << " ";
	outs << L"m_Phi: " << m_Phi << " ";
	outs << L"Frame Time: " << GetDeltaTime() * 1000.0f << L" (ms)";
	outs << L"Triangles: "	<< m_Triangles; 

	m_WindowTitle = outs.str();

	// Convert Spherical to Cartesian coordinates.
	float x = m_Radius * cosf(m_Theta) * sinf(m_Phi);
	float z = -m_Radius * cosf(m_Theta) * cosf(m_Phi);
	float y = m_Radius * sinf(m_Theta);

	// Build the view matrix.
	DirectX::XMVECTOR pos    = DirectX::XMVectorSet(x, y, z, 1.0f);
	DirectX::XMVECTOR target = DirectX::XMVectorZero();
	DirectX::XMVECTOR up     = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	DirectX::XMMATRIX V = DirectX::XMMatrixLookAtLH(pos, target, up);
	DirectX::XMStoreFloat4x4(&m_View, V);

	m_EyePos = DirectX::XMFLOAT3(x, y, z);

	if (m_ModelObjects.empty() || !m_ModelObjects[0]->IsDynamic())
		return;

	D3D11_MAPPED_SUBRESOURCE mappedData;

	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem	= m_ModelObjects[0]->GetMeshData()->GetVerticesPtr();

	HRESULT result = m_DeviceContextPtr->Map(m_VerticesBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData);
	// = (md3dImmediateContext->Map(mWavesVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
	MeshData::Vertex* v = reinterpret_cast<MeshData::Vertex*>(mappedData.pData);
	for (auto object = m_ModelObjects.begin(); object != m_ModelObjects.end(); ++object)
	{
		for (UINT i = 0; i < (*object)->GetMeshData()->GetVerticesNumber(); ++i)
		{
			v[i].Position = (*object)->GetMeshData()->m_Vertices[i].Position;
			v[i].Normal = (*object)->GetMeshData()->m_Vertices[i].Normal;
		}
	}
	m_DeviceContextPtr->Unmap(m_VerticesBuffer, 0);
}
コード例 #26
0
ファイル: Level.c プロジェクト: Mayple7/SausageFox150
void UpdateUpgradeScreenObjects(void)
{
	float camX = GetCameraXPosition();
	char CharTemp[32];

	int worldX, worldY;
	Vec2 MouseClick;
	Vec2 NewPosition;

	FoxInput_GetWorldPosition(&worldX, &worldY);
	Vec2Set(&MouseClick, (float)worldX, (float)worldY);

	//Update the particles
	ParticleSystemUpdate();

	//Check if there are upgrades
	if (!UpgradesToUpgrade)
	{
		if (CurrentPlayer.CurrentPlayerStats.Upgrades > 0)
			UpgradesToUpgrade = TRUE;
		else if (CurrentPlayer.CurrentPlayerStats.Upgrades < 1)
		{
			//No upgrade points, get out
			UpgradeComplete = TRUE;
			return;
		}
	}

	//Title
	if (CurrentPlayer.CurrentPlayerStats.Strength >= UPGRADE_MAX
	 && CurrentPlayer.CurrentPlayerStats.Agility >= UPGRADE_MAX
	 && CurrentPlayer.CurrentPlayerStats.Defense >= UPGRADE_MAX
	 && !allUpgradesFull)
	{
		//If no more upgrades remain, let them know
		allUpgradesFull = TRUE;
		ChangeTextString(UpgradesName, "All Upgrades Complete!");
		ChangeTextZIndex(UpgradesName, 4003);
	}
	Vec2Set(&NewPosition, camX, 470);
	ChangeTextPosition(UpgradesName, NewPosition, Center);

	//Upgrades remaining
	if (lastUpgrades != CurrentPlayer.CurrentPlayerStats.Upgrades)
	{
		//Do some flavor text warnings for differnt UP amounts
		if (allUpgradesFull)
			sprintf(CharTemp, "Good Work! Keep Mashing!");
		else if (CurrentPlayer.CurrentPlayerStats.Upgrades == 1)
			sprintf(CharTemp, "%i Point Remaining!", CurrentPlayer.CurrentPlayerStats.Upgrades);
		else if (CurrentPlayer.CurrentPlayerStats.Upgrades < 1)
			sprintf(CharTemp, "No Points! Level Up More!");
		else
			sprintf(CharTemp, "%i Points to Spend!", CurrentPlayer.CurrentPlayerStats.Upgrades);
		ChangeTextString(UpgradesLeft, CharTemp);
		ChangeTextZIndex(UpgradesLeft, 4003);
		TextAllVisible(UpgradesLeft);
		lastUpgrades = CurrentPlayer.CurrentPlayerStats.Upgrades;
	}
	Vec2Set(&NewPosition, camX, 380);
	ChangeTextPosition(UpgradesLeft, NewPosition, Center);

	//Upgrade buttons, all 3
	UpdateButtonPosition(UpgradeButton1, 545 + camX, 200);
	UpdateCollisionPosition(&UpgradeButton1->ButtonCollider, &UpgradeButton1->ButtonSprite->Position);
	UpdateButtonPosition(UpgradeButton2, 545 + camX, 0);
	UpdateCollisionPosition(&UpgradeButton2->ButtonCollider, &UpgradeButton2->ButtonSprite->Position);
	UpdateButtonPosition(UpgradeButton3, 545 + camX, -200);
	UpdateCollisionPosition(&UpgradeButton3->ButtonCollider, &UpgradeButton3->ButtonSprite->Position);

	//Upgrade bars
	UpgradeBar1->Position.x = camX;
	UpgradeBar1->Position.y = 200;
	UpgradeBar2->Position.x = camX;
	UpgradeBar2->Position.y = 0;
	UpgradeBar3->Position.x = camX;
	UpgradeBar3->Position.y = -200;

	//Particle / Haze back
	HazeBackground->Position.x = camX + 480;
	HazeBackground->Position.y = 0;
	SystemOne->Position.y = 0;
	SystemOne->Position.x = camX;
	SystemOne->amountTotal = -1;

	if (HazeBackground->Alpha < 1)
		HazeBackground->Alpha += 2 * GetDeltaTime();
	else
		HazeBackground->Alpha = 1;

	//Upgrade bar colors
	//Str --
	UpgradeBarColor1->Position.x = camX - 61 - 52.0f * (UPGRADE_MAX - CurrentPlayer.CurrentPlayerStats.Strength);
	UpgradeBarColor1->Position.y = 200;
	UpgradeBarColor1->ScaleX     = 1.0f * ((float)CurrentPlayer.CurrentPlayerStats.Strength / UPGRADE_MAX);
	UpgradeBarColor1->ScaleY     = 1.1f;
	//Agi --
	UpgradeBarColor2->Position.x = camX - 61 - 52.0f * (UPGRADE_MAX - CurrentPlayer.CurrentPlayerStats.Agility);
	UpgradeBarColor2->Position.y = 0;
	UpgradeBarColor2->ScaleX     = 1.0f * ((float)CurrentPlayer.CurrentPlayerStats.Agility / UPGRADE_MAX);
	UpgradeBarColor2->ScaleY     = 1.1f;
	//Def --
	UpgradeBarColor3->Position.x = camX - 61 - 52.0f * (UPGRADE_MAX - CurrentPlayer.CurrentPlayerStats.Defense);
	UpgradeBarColor3->Position.y = -200;
	UpgradeBarColor3->ScaleX     = 1.0f * ((float)CurrentPlayer.CurrentPlayerStats.Defense / UPGRADE_MAX);
	UpgradeBarColor3->ScaleY     = 1.1f;

	//Upgrades used placement
	//Str --
	sprintf(CharTemp, "%i", CurrentPlayer.CurrentPlayerStats.Strength);
	ChangeTextString(UpgradeAmount1, CharTemp);
	ChangeTextZIndex(UpgradeAmount1, 4003);
	TextAllVisible(UpgradeAmount1);
	Vec2Set(&NewPosition, camX - 590, 200);
	ChangeTextPosition(UpgradeAmount1, NewPosition, Center);
	//Agi --
	sprintf(CharTemp, "%i", CurrentPlayer.CurrentPlayerStats.Agility);
	ChangeTextString(UpgradeAmount2, CharTemp);
	ChangeTextZIndex(UpgradeAmount2, 4003);
	TextAllVisible(UpgradeAmount2);
	Vec2Set(&NewPosition, camX - 590, 0);
	ChangeTextPosition(UpgradeAmount2, NewPosition, Center);
	//Def --
	sprintf(CharTemp, "%i", CurrentPlayer.CurrentPlayerStats.Defense);
	ChangeTextString(UpgradeAmount3, CharTemp);
	ChangeTextZIndex(UpgradeAmount3, 4003);
	TextAllVisible(UpgradeAmount3);
	Vec2Set(&NewPosition, camX - 590, -200);
	ChangeTextPosition(UpgradeAmount3, NewPosition, Center);

	//Done upgrading button
	UpdateButtonPosition(MainMapButton, 400 + camX, -400);
	UpdateCollisionPosition(&MainMapButton->ButtonCollider, &MainMapButton->ButtonSprite->Position);

	//STRENGTH (No up allowed if maxed)
	if (CurrentPlayer.CurrentPlayerStats.Upgrades > 0 && PointRectCollision(&UpgradeButton1->ButtonCollider, &MouseClick)
	 && CurrentPlayer.CurrentPlayerStats.Strength < UPGRADE_MAX)
	{
		UpgradeButton1->ButtonSprite->ScaleX = 1.12f;
		UpgradeButton1->ButtonSprite->ScaleY = 1.12f;

		//Make the button react
		if(FoxInput_MouseTriggered(MOUSE_BUTTON_LEFT))
		{
			CurrentPlayer.CurrentPlayerStats.Upgrades--;
			CurrentPlayer.CurrentPlayerStats.Strength++;

			UpgradeButton1->ButtonSprite->ScaleX = 1.16f;
			UpgradeButton1->ButtonSprite->ScaleY = 1.16f;
			PlayAudio(CurrentPlayer.CurrentPlayerSounds.KeyPickUp);
		}
	}
	else
	{
		if (UpgradeButton1->ButtonSprite->ScaleX > 1.0f)
		{
			UpgradeButton1->ButtonSprite->ScaleX -= GetDeltaTime() * 2;
			UpgradeButton1->ButtonSprite->ScaleY -= GetDeltaTime() * 2;
		}
	}
	//AGILITY (No up allowed if maxed)
	if (CurrentPlayer.CurrentPlayerStats.Upgrades > 0 && PointRectCollision(&UpgradeButton2->ButtonCollider, &MouseClick)
	 && CurrentPlayer.CurrentPlayerStats.Agility < UPGRADE_MAX)
	{
		UpgradeButton2->ButtonSprite->ScaleX = 1.12f;
		UpgradeButton2->ButtonSprite->ScaleY = 1.12f;

		//Make the button react
		if(FoxInput_MouseTriggered(MOUSE_BUTTON_LEFT))
		{
			CurrentPlayer.CurrentPlayerStats.Upgrades--;
			CurrentPlayer.CurrentPlayerStats.Agility++;

			UpgradeButton2->ButtonSprite->ScaleX = 1.16f;
			UpgradeButton2->ButtonSprite->ScaleY = 1.16f;
			PlayAudio(CurrentPlayer.CurrentPlayerSounds.KeyPickUp);
		}
	}
	else
	{
		if (UpgradeButton2->ButtonSprite->ScaleX > 1.0f)
		{
			UpgradeButton2->ButtonSprite->ScaleX -= GetDeltaTime() * 2;
			UpgradeButton2->ButtonSprite->ScaleY -= GetDeltaTime() * 2;
		}
	}
	//DEFENSE (No up allowed if maxed)
	if (CurrentPlayer.CurrentPlayerStats.Upgrades > 0 && PointRectCollision(&UpgradeButton3->ButtonCollider, &MouseClick)
	 && CurrentPlayer.CurrentPlayerStats.Defense < UPGRADE_MAX)
	{
		UpgradeButton3->ButtonSprite->ScaleX = 1.12f;
		UpgradeButton3->ButtonSprite->ScaleY = 1.12f;

		//Make the button react
		if(FoxInput_MouseTriggered(MOUSE_BUTTON_LEFT))
		{
			CurrentPlayer.CurrentPlayerStats.Upgrades--;
			CurrentPlayer.CurrentPlayerStats.Defense++;

			UpgradeButton3->ButtonSprite->ScaleX = 1.16f;
			UpgradeButton3->ButtonSprite->ScaleY = 1.16f;
			PlayAudio(CurrentPlayer.CurrentPlayerSounds.KeyPickUp);
		}
	}
	else
	{
		if (UpgradeButton3->ButtonSprite->ScaleX > 1.0f)
		{
			UpgradeButton3->ButtonSprite->ScaleX -= GetDeltaTime() * 2;
			UpgradeButton3->ButtonSprite->ScaleY -= GetDeltaTime() * 2;
		}
	}

	//MAIN MENU
	if(PointRectCollision(&MainMapButton->ButtonCollider, &MouseClick))
	{
		MainMapButton->ButtonSprite->ScaleX = 1.2f;
		MainMapButton->ButtonSprite->ScaleY = 1.2f;

		//Make the button react
		if(FoxInput_MouseTriggered(MOUSE_BUTTON_LEFT))
		{
			UpgradeComplete = TRUE;
		}
	}
	else
	{
		MainMapButton->ButtonSprite->ScaleX = 1.0f;
		MainMapButton->ButtonSprite->ScaleY = 1.0f;
	}
}
コード例 #27
0
ファイル: main.cpp プロジェクト: QuinnJMosher/spaceInvaders
int main( int argc, char* argv[] )
{	

	Initialise(iScreenWidth, iScreenHeight, false, "Space Invaders");
    
	SetBackgroundColour(SColour(0x00, 0x00, 0x00, 0xFF));

	//player settings
	player.SetSize(64.0f, 32.0f);
	player.iSpriteID = CreateSprite("./images/cannon.png", player.fWidth, player.fHeight, true);
	player.SetMovementExtremes(0.0f, iScreenWidth);
	player.SetMovementKeys(65, 68);
	player.x = iScreenWidth * 0.5f;
	player.y = 88.0f;

	//create Marquee sprite
	iArcadeMarquee = CreateSprite("./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true);

	//enemy creation
	CreateEnemies();
	enemyDirection = eRIGHT;
	nextDirection = eRIGHT;

	//font setting
	AddFont(pInvadersFont);

	//game state declaration
	GAMESTATES eCurrentState = eMAIN_MENU;

    //Game Loop
    do
    {
		float fDeltaT = GetDeltaTime();

		switch (eCurrentState) {
		case eMAIN_MENU:

			UpdateMainMenu();

			//input
			if (IsKeyDown(257) && !IsKeyDown(256)) {
				eCurrentState = eGAMEPLAY;
				ResetEnemies();
			}

			break;

		case eGAMEPLAY:

			UpdateGameState(fDeltaT);

			//ChangeState
			if (IsKeyDown(256)) {
				eCurrentState = eMAIN_MENU;
			}

			break;

		default:
			break;
		}

		//clear screen
		ClearScreen();


    } while(!FrameworkUpdate());

	Shutdown();

    return 0;
}
コード例 #28
0
ファイル: MainMenu.c プロジェクト: Mayple7/SausageFox150
void BackgroundAnimation(void)
{
	//If the first sprite is being animated
	if(firstAnimated)
	{
		//Update the move timer
		firstMoveTimer += GetDeltaTime();
		switch(firstStartLocation)
		{
		// Top right
		case 0:
			//Update the position
			FirstBackground->Position.x -= 640 / (10 / GetDeltaTime());
			FirstBackground->Position.y -= 360 / (10 / GetDeltaTime());
			//Fade out is complete
			if(firstMoveTimer >= 10)
			{
				//Ensure the alphas are correct and get a new texture for the first background
				firstAnimated = FALSE;
				FirstBackground->Alpha = 0.0f;
				SecondBackground->Alpha = 1.0f;
				firstTextureNum = RandomNewTexture(FirstBackground, secondTextureNum);
			}
			//Start fading out the first background and fading in the second background
			else if(firstMoveTimer > 8)
			{
				FirstBackground->Alpha -= GetDeltaTime() / 2.0f;
				SecondBackground->Alpha += GetDeltaTime() / 2.0f;
				//Start animating the second background and set its random location
				if(!secondAnimated)
				{
					secondMoveTimer = 0;
					secondStartLocation = rand() % 4;
					SetStartLocation(&SecondBackground->Position.x, &SecondBackground->Position.y, secondStartLocation);
					secondAnimated = TRUE;
				}
			}
			break;
		// Bottom right
		case 1:
			FirstBackground->Position.x -= 640 / (10 / GetDeltaTime());
			FirstBackground->Position.y -= -360 / (10 / GetDeltaTime());
			if(firstMoveTimer >= 10)
			{
				firstAnimated = FALSE;
				FirstBackground->Alpha = 0.0f;
				SecondBackground->Alpha = 1.0f;
				firstTextureNum = RandomNewTexture(FirstBackground, secondTextureNum);
			}
			else if(firstMoveTimer > 8)
			{
				FirstBackground->Alpha -= GetDeltaTime() / 2.0f;
				SecondBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!secondAnimated)
				{
					secondMoveTimer = 0;
					secondStartLocation = rand() % 4;
					SetStartLocation(&SecondBackground->Position.x, &SecondBackground->Position.y, secondStartLocation);
					secondAnimated = TRUE;
				}
			}
			break;
		// Top left
		case 2:
			FirstBackground->Position.x -= -640 / (10 / GetDeltaTime());
			FirstBackground->Position.y -= 360 / (10 / GetDeltaTime());
			if(firstMoveTimer >= 10)
			{
				firstAnimated = FALSE;
				FirstBackground->Alpha = 0.0f;
				SecondBackground->Alpha = 1.0f;
				firstTextureNum = RandomNewTexture(FirstBackground, secondTextureNum);
			}
			else if(firstMoveTimer > 8)
			{
				FirstBackground->Alpha -= GetDeltaTime() / 2.0f;
				SecondBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!secondAnimated)
				{
					secondMoveTimer = 0;
					secondStartLocation = rand() % 4;
					SetStartLocation(&SecondBackground->Position.x, &SecondBackground->Position.y, secondStartLocation);
					secondAnimated = TRUE;
				}
			}
			break;
		// Bottom left
		case 3:
			FirstBackground->Position.x -= -640 / (10 / GetDeltaTime());
			FirstBackground->Position.y -= -360 / (10 / GetDeltaTime());
			if(firstMoveTimer >= 10)
			{
				firstAnimated = FALSE;
				FirstBackground->Alpha = 0.0f;
				SecondBackground->Alpha = 1.0f;
				firstTextureNum = RandomNewTexture(FirstBackground, secondTextureNum);
			}
			else if(firstMoveTimer > 8)
			{
				FirstBackground->Alpha -= GetDeltaTime() / 2.0f;
				SecondBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!secondAnimated)
				{
					secondMoveTimer = 0;
					secondStartLocation = rand() % 4;
					SetStartLocation(&SecondBackground->Position.x, &SecondBackground->Position.y, secondStartLocation);
					secondAnimated = TRUE;
				}
			}
			break;
		}
	}
	//Same code as above, but swapped for the second button
	if(secondAnimated)
	{
		secondMoveTimer += GetDeltaTime();
		switch(secondStartLocation)
		{
		// Top right
		case 0:
			SecondBackground->Position.x -= 640 / (10 / GetDeltaTime());
			SecondBackground->Position.y -= 360 / (10 / GetDeltaTime());
			if(secondMoveTimer >= 10)
			{
				secondAnimated = FALSE;
				SecondBackground->Alpha = 0.0f;
				FirstBackground->Alpha = 1.0f;
				secondTextureNum = RandomNewTexture(SecondBackground, firstTextureNum);
			}
			else if(secondMoveTimer > 8)
			{
				SecondBackground->Alpha -= GetDeltaTime() / 2.0f;
				FirstBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!firstAnimated)
				{
					firstMoveTimer = 0;
					firstStartLocation = rand() % 4;
					SetStartLocation(&FirstBackground->Position.x, &FirstBackground->Position.y, firstStartLocation);
					firstAnimated = TRUE;
				}
			}
			break;
		// Bottom right
		case 1:
			SecondBackground->Position.x -= 640 / (10 / GetDeltaTime());
			SecondBackground->Position.y -= -360 / (10 / GetDeltaTime());
			if(secondMoveTimer >= 10)
			{
				secondAnimated = FALSE;
				SecondBackground->Alpha = 0.0f;
				FirstBackground->Alpha = 1.0f;
				secondTextureNum = RandomNewTexture(SecondBackground, firstTextureNum);
			}
			else if(secondMoveTimer > 8)
			{
				SecondBackground->Alpha -= GetDeltaTime() / 2.0f;
				FirstBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!firstAnimated)
				{
					firstMoveTimer = 0;
					firstStartLocation = rand() % 4;
					SetStartLocation(&FirstBackground->Position.x, &FirstBackground->Position.y, firstStartLocation);
					firstAnimated = TRUE;
				}
			}
			break;
		// Top left
		case 2:
			SecondBackground->Position.x -= -640 / (10 / GetDeltaTime());
			SecondBackground->Position.y -= 360 / (10 / GetDeltaTime());
			if(secondMoveTimer >= 10)
			{
				secondAnimated = FALSE;
				SecondBackground->Alpha = 0.0f;
				FirstBackground->Alpha = 1.0f;
				secondTextureNum = RandomNewTexture(SecondBackground, firstTextureNum);
			}
			else if(secondMoveTimer > 8)
			{
				SecondBackground->Alpha -= GetDeltaTime() / 2.0f;
				FirstBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!firstAnimated)
				{
					firstMoveTimer = 0;
					firstStartLocation = rand() % 4;
					SetStartLocation(&FirstBackground->Position.x, &FirstBackground->Position.y, firstStartLocation);
					firstAnimated = TRUE;
				}
			}
			break;
		// Bottom left
		case 3:
			SecondBackground->Position.x -= -640 / (10 / GetDeltaTime());
			SecondBackground->Position.y -= -360 / (10 / GetDeltaTime());
			if(secondMoveTimer >= 10)
			{
				secondAnimated = FALSE;
				SecondBackground->Alpha = 0.0f;
				FirstBackground->Alpha = 1.0f;
				secondTextureNum = RandomNewTexture(SecondBackground, firstTextureNum);
			}
			else if(secondMoveTimer > 8)
			{
				SecondBackground->Alpha -= GetDeltaTime() / 2.0f;
				FirstBackground->Alpha += GetDeltaTime() / 2.0f;
				if(!firstAnimated)
				{
					firstMoveTimer = 0;
					firstStartLocation = rand() % 4;
					SetStartLocation(&FirstBackground->Position.x, &FirstBackground->Position.y, firstStartLocation);
					firstAnimated = TRUE;
				}
			}
			break;
		}
	}
}
コード例 #29
0
ファイル: gamebase.cpp プロジェクト: mockthebear/bearshader
void Game::Run(){
    if (storedState != NULL){
        stateStack.emplace(storedState);
        storedState =NULL;
    }

    while (!SDL_QuitRequested() and not stateStack.top()->RequestedQuit()){
        restart_cycle:
        frameStart = dt;
        CalculateDeltaTime();

        InputManager::GetInstance().Update();
        if (ConfigManager::GetInstance().IsResized())
            goto restart_cycle;
        Update();
        if (InputManager::GetInstance().KeyPress(SDLK_F11)){
            static bool full = false;
            if (!full)
                SDL_SetWindowFullscreen(window, SDL_TRUE);
            else
                SDL_SetWindowFullscreen(window, SDL_FALSE);
            full = !full;
        }

        Render();
        SDL_RenderPresent(GetRenderer() );

        //Limitar dinamicamente o tempo de cada frame para atingir sempre que possivel 30 fps
        float n = GetDeltaTime()*100.0;

        if (stateStack.top()->RequestedDeleted()){
            if (stateStack.empty() && storedState == NULL){
                break;
            }else{
                stateStack.pop();
            }
        }

        if (storedState != NULL){
            stateStack.emplace(storedState);
            stateStack.top()->Begin();
            storedState =NULL;
        }


        n = n-(1000.0/MAXFPS);
        n  = n < 0 ? 0 : n;
        n  = (1000.0/MAXFPS)-n < 0 ? 0 : n;


        //SDL_Delay( std::max( (1000.0/MAXFPS)-n - 5, 0.0) );

        frames++;

        UpdateTitleAsFps((1000.0/MAXFPS)-n  );

    }
    isClosing = true;


};
コード例 #30
-1
ファイル: gamebase.cpp プロジェクト: mockthebear/bearshader
void Game::UpdateTitleAsFps(float w8){

    if (nextUpdate <= SDL_GetTicks()){
        char Buff[100];
        FPS = frames;
        sprintf(Buff,"%s (FPS: %f) = %f  = %f",title,frames*1000.0/(1000.0-(SDL_GetTicks()-olt)),GetDeltaTime(),w8);
        SDL_SetWindowTitle(window, Buff);
        olt = SDL_GetTicks()+1000;
        nextUpdate = olt;
        updateFPS=true;
        frames = 0;
    }else{
        updateFPS= false;
    }
}