void MyPS2Application::GameOver() { if (!game_over_loaded) { printf("Loading Game Over sprite\n"); LoadGameOver(); } RenderGameOver(); if ((pad[0].buttons & PAD_START)) { printf("Reseting da f*****g game!"); ResetGame(); } }
void GameApp::Render(){ glClear(GL_COLOR_BUFFER_BIT); switch (state){ case MAIN_MENU: RenderMainMenu(); break; case GAMEPLAY: RenderGamePlay(); break; case GAME_OVER: RenderGameOver(); break; case PAUSE: RenderPause(); break; } SDL_GL_SwapWindow(displayWindow); }
void gameApp::Render() { glClearColor(0.2f, 0.2f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); switch (state) { case MAIN_MENU: { RenderMainMenu(); Mix_FadeInMusic(titlemewsic, -1, 500); } case MAIN_QUEST: { RenderQuest(); Mix_FadeInMusic(stagemewsic, -1, 1000); } case MAIN_DEATH: { RenderGameOver(); Mix_FadeInMusic(gameovermewsic, -1, 300); } } }
void ClassDemoApp::UpdateGameLevel(float elapsed) { const Uint8 *keys = SDL_GetKeyboardState(NULL); if (keys[SDL_SCANCODE_LEFT]) { player->x -= elapsed * 6.0f; if( player->x < -3.55f + player->width / 2.0f) { player->x = -3.55f + player->width / 2.0f; } } if (keys[SDL_SCANCODE_RIGHT]) { player->x += elapsed * 6.0f; if (player->x > 3.55f - player->width / 2.0f) { player->x = 3.55f - player->width / 2.0f; } } timeCount += elapsed; if (timeCount > 0.15f) { for (Entity& enemy : enemies) { if (enemy.active) { if (player->collidesWith(enemy)) { RenderGameOver(); } if (moveEnemyDown) { enemy.y -= 0.3f; } else { enemy.x += 0.1f * enemyDirection; if (enemy.x < -3.0f || enemy.x > 3.0f) { enemyHitWall = true; } } } } moveEnemyDown = false; if (enemyHitWall) { moveEnemyDown = true; enemyDirection *= -1.0f; enemyHitWall = false; } timeCount -= 0.15f; } if (bullet.active) { bullet.y += 10.0f * elapsed; if (bullet.y > 2.0f) { bullet.active = false; } else { for (Entity& enemy : enemies) { if (bullet.collidesWith(enemy)) { enemy.active = false; bullet.active = false; score++; numOfEnemies--; if (numOfEnemies <= 0) { RenderMainMenu(); } break; } } } } }
void BacteroidsState::Render() { Renderer &renderer = GetRenderer(); renderer.SetTime(m_time.GetTimeMicros()); renderer.SetView(m_playView); renderer.BindColorShader(); renderer.SetColor(Color(0.05f, 0.13f, 0.15f)); renderer.DrawFilledRectangle(PLAY_AREA_LEFT, PLAY_AREA_BOTTOM, PLAY_AREA_RIGHT, PLAY_AREA_TOP); for (size_t_32 i = 0; i < m_objects.Size(); i++) { GameObject *obj = m_objects[i]; vec2f p = obj->GetPosition(); float r = obj->GetRadius() * 1.1f; if ((p.x > PLAY_AREA_LEFT - r && p.x < PLAY_AREA_RIGHT + r && p.y > PLAY_AREA_BOTTOM - r && p.y < PLAY_AREA_TOP + r) == false) { continue; } renderer.BindShader(obj->GetShader()); const vec2f vel2 = obj->GetVelocity(); const vec4f velocity(vel2.x, vel2.y, 0.0f, 0.0f); renderer.GetGraphics()->SetUniform(m_uniforms.m_velocity, velocity); obj->Render(&renderer, m_uniforms); } renderer.BindColorShader(); m_damageFade.Render(&renderer); m_pauseFade.Render(&renderer); renderer.SetView(GetDefaultView()); if (m_time.IsPaused()) { RenderPause(); } else if (m_player.IsDead()) { RenderGameOver(); } { TextLayout layout(renderer, 0.0f, 0.0f); renderer.BindFontShader(); renderer.SetColor(Color(1.0f, 1.0f, 1.0f)); renderer.SetFontScale(1.0f); char buf[64]; StringPrintF(buf, "Score: %i", m_score); layout.AddText(buf, 0.0f); layout.AddLine(); StringPrintF(buf, "Kills: %i", m_kills); layout.AddText(buf, 0.0f); layout.AddLine(); const float ptPerKill = (m_kills) ? (m_score / float(m_kills)) : 0; StringPrintF(buf, "pt per kill: %.1f", ptPerKill); layout.AddText(buf, 0.0f); layout.AddLine(); const float hx = 10.0f; const float hy = layout.m_cursor.y + 10.0f; renderer.BindColorShader(); renderer.SetColor(Color(0.5f, 0.5f, 0.5f)); renderer.DrawFilledRectangle(hx, hy, hx + 100.0f, hy + 10.0f); renderer.SetColor(Color(0.85f, 0.05f, 0.05f)); renderer.DrawFilledRectangle(hx, hy, hx + m_player.GetHealth(), hy + 10.0f); } { const Viewport vp = renderer.GetView().m_viewport; TextLayout layout(renderer, 0.0f, vp.h); renderer.BindFontShader(); renderer.SetColor(Color(1.0f, 1.0f, 1.0f)); renderer.SetFontScale(1.0f); char buf[64]; StringPrintF(buf, "[M] - Muted: %s", GetAudio().IsMuted() ? "yes" : "no"); layout.AddLines(-1); layout.AddText(buf, 0.0f); } }
void ClassDemoApp::UpdateGameLevel(float elapsed) { const Uint8 *keys = SDL_GetKeyboardState(NULL); player->velocity_x = 5.0f; if (keys[SDL_SCANCODE_LEFT]) { player->acceleration_x = -10.0f; } else if (keys[SDL_SCANCODE_RIGHT]) { player->acceleration_x = 10.0f; } else { player->acceleration_x = 0.0f; } if (keys[SDL_SCANCODE_UP] && player->velocity_y < 10.0f) { Mix_PlayChannel(-1, someSound, 0); player->velocity_y += 1.5f; player->collidedBottom = false; } for (size_t i = 0; i < enemies.size(); i++) { enemies[i].Update(elapsed); int gridX = 0, gridY = 0; worldToTileCoordinates(enemies[i].position_x - enemies[i].width / 2, enemies[i].position_y, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { enemies[i].velocity_y *= -1; } worldToTileCoordinates(enemies[i].position_x + enemies[i].width / 2, enemies[i].position_y, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { enemies[i].velocity_y *= -1; } worldToTileCoordinates(enemies[i].position_x, enemies[i].position_y + enemies[i].height / 2, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { enemies[i].velocity_y *= -1; } worldToTileCoordinates(enemies[i].position_x, enemies[i].position_y - enemies[i].height / 2, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { enemies[i].velocity_y *= -1; } float ydiff = enemies[i].position_y - player->position_y; float xdiff = enemies[i].position_x - player->position_x; if (xdiff < 5.0f) { enemies[i].position_y -= ydiff / 100.0f; enemies[i].position_x -= xdiff / 100.0f; } } for (size_t i = 0; i < entities.size(); i++) { if (!entities[i]->isStatic) { entities[i]->Update(elapsed); int gridX = 0, gridY = 0; worldToTileCoordinates(entities[i]->position_x - entities[i]->width / 2, entities[i]->position_y, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { entities[i]->position_x = (gridX + 1) * TILE_SIZE + entities[i]->width / 2 + 0.005f; entities[i]->velocity_x = 0; entities[i]->collidedLeft = true; } worldToTileCoordinates(entities[i]->position_x + entities[i]->width / 2, entities[i]->position_y, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { entities[i]->position_x = gridX * TILE_SIZE - entities[i]->width / 2 - 0.005f; entities[i]->velocity_x = 0; entities[i]->collidedRight = true; } worldToTileCoordinates(entities[i]->position_x, entities[i]->position_y + entities[i]->height / 2, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { entities[i]->position_y = (-gridY - 1) * TILE_SIZE - entities[i]->height / 2 - 0.005f; entities[i]->velocity_y = 0; entities[i]->collidedTop = true; } worldToTileCoordinates(entities[i]->position_x, entities[i]->position_y - entities[i]->height / 2, &gridX, &gridY); if (checkIfSolid(gridX, gridY, levelData)) { entities[i]->position_y = -gridY * TILE_SIZE + entities[i]->height / 2 + 0.005f; entities[i]->velocity_y = 0; entities[i]->collidedBottom = true; } } for (Entity& enemy : enemies) { if (enemy.active) { if (player->collidesWith(enemy)) { RenderGameOver(); } } } for (Entity& key : keyv) { if (key.active) { if (player->collidesWith(key)) { score++; key.active = false; } } } } }