void UpdateGameplay(float a_deltaTime) { SetBackgroundColour(SColour(00, 67, 171, 50)); DrawSprite(player.spriteID); enemy.Draw(); enemy2.Draw(); MoveSprite(player.spriteID,player.x, player.y); player.Movement(a_deltaTime, 750, 500); enemy.Movement(a_deltaTime, 500, 500); enemy2.Movement(a_deltaTime, 500, 500); }
void EnemyManager::Draw() { for (int i = 0; i < m_enemies->size(); i++) { Enemy* e = m_enemies->at(i); e->Draw(); } }
int main() { // Init GLFW glfwInit(); // Create a GLFWwindow object that we can use for GLFW's functions Window window = Window(WIDTH, HEIGHT, TITLE); window.DefineViewport(); //glfwSetInputMode(window.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); /// ^(Maybe use this later) // Callback functions glfwSetKeyCallback(window.getWindowPtr() , key_callback); // Init GLEW glewExperimental = GL_TRUE; glewInit(); // Enable alpha channel transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Load and compile shaders to a program Shader ShaderProgram = Shader("../deps/shaders/shadervert.vs", "../deps/shaders/shaderfrag.fs"); // Load explosion graphics extern_Explosion.Init(ShaderProgram.GetProgramID()); // Load texture/Game objects Texture2D texture_background1 = Texture2D("../deps/textures/backgroundSpace_01.1.png", PNG_RGB); SpriteMap Background = SpriteMap(texture_background1, 1.0f, 1.0f, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f, BACKGROUND); Player PlayerShip; PlayerShip.Init(moveSpeed); Enemy Enemies; Enemies.Init(); // Projection matrix: ortho for 2D glm::mat4 proj = glm::ortho(0, window.getWidth(), 0, window.getHeight()); // Game loop while (!window.ShouldClose()) { double startFrame = glfwGetTime(); ///< for FPS limiting // Check if any events have been activiated and call callback function (via GLFW) glfwPollEvents(); // Clear the colorbuffer glClearColor(0.6f, 0.8f, 0.8f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Drawing */ ShaderProgram.Use(); // Background position and drawing calculations - just identity matrix glm::mat4 model; GLint modelLoc = glGetUniformLocation(ShaderProgram.GetProgramID(), "model"); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); Background.BackgroundScroll(scrollSpeed); Background.Draw(); Collision::EnemyHit(&PlayerShip, &Enemies); Collision::PlayerHit(&PlayerShip, &Enemies); Collision::ShipsCollide(&PlayerShip, &Enemies); PlayerShip.Move(keys); PlayerShip.AddShots(keys); PlayerShip.Draw(ShaderProgram.GetProgramID()); Enemies.Move(); Enemies.Shoot(PlayerShip.GetPosition()); Enemies.Draw(ShaderProgram.GetProgramID()); extern_Explosion.Draw(); // FPS Calculation/Limiting float fps = CalculateFPS(); static int printFPS = 0; if (printFPS == 100) { Enemies.Add(EN_0, PlayerShip.GetPosition()); Enemies.Add(EN_1, PlayerShip.GetPosition()); std::cout << fps << std::endl; printFPS = 0; } else { printFPS++; } LimitFPS(FPS, startFrame); if (PlayerShip.GetLives() <= 0) { window.Close(); } // Swap the screen buffers window.SwapBuffers(); } Background.Delete(); PlayerShip.Delete(); Enemies.DeleteAll(); extern_Explosion.DeleteAll(); // Close GLFW glfwTerminate(); return 0; }
int wmain() { #pragma region Other Stuff // Hide cursor SDL_ShowCursor(0); gameState = PLAY; //The window we'll be rendering to SDL_Window* window = NULL; //The surface contained by the window SDL_Surface* screenSurface = NULL; //SDL Renderer r = Renderer(SCREEN_WIDTH, SCREEN_HEIGHT); AudioManager::GetInstance()->Init(); AudioManager::GetInstance()->LoadMedia(); AudioManager::GetInstance()->PlaySoundEffect(1); SDL_Point ePos; ePos.x = 100; ePos.y = 100; Enemy en = Enemy(200, 200, 62 / 3, 77 / 3, r, 0); Enemy en1 = Enemy(400, 100, 62 / 3, 77 / 3, r, 0); Level lvl = Level(r); // MENU SDL_Point bPos; bPos.x = 0; bPos.y = 0; Menu background = Menu(bPos, SCREEN_WIDTH, SCREEN_HEIGHT, r, 0, "background"); SDL_Point pPos; pPos.x = SCREEN_WIDTH / 3; pPos.y = SCREEN_HEIGHT / 4; Menu playBtn = Menu(pPos, 263, 44, r, 0, "playBtn"); SDL_Point e2Pos; e2Pos.x = (SCREEN_WIDTH / 2) - 50; e2Pos.y = (SCREEN_HEIGHT / 2) - 20; Menu exitBtn = Menu(e2Pos, 111, 45, r, 0, "exitBtn"); // Player SDL_Point playerPos; playerPos.x = SCREEN_WIDTH / 2 - 25; playerPos.y = SCREEN_HEIGHT / 2 - 10; Player player = Player(playerPos, 44, 32, r, 0); // THREADS \\ // Run the thread //Player * p = (); // pointer to object void * pv = &player; // pointer to void Player * p2 = static_cast<Player *>(pv); // pointer to the same object int data; SDL_Thread* threadID = SDL_CreateThread(renderThreadFunction, "RenderThread", (void*)p2); // THREADS \\ #pragma endregion #pragma region SDL STUFF bool quit = false; float oldTime = SDL_GetTicks(); float delta = 0.f; float newTime = 0.f; SDL_Event e; fpsTimer.start(); while (!quit) { while (SDL_PollEvent(&e) != 0) { InputManager::GetInstance()->UpdatePolledEvents(e); } if (e.button.button == SDL_SCANCODE_ESCAPE) quit = true; // THREADS \\ // THREADS \\ //controls gameState added in game menu feature r.Begin(); switch (gameState) { case MENU: //detect button click if (e.type == SDL_MOUSEBUTTONDOWN) { //If the left mouse button was pressed if (e.button.button == SDL_BUTTON_LEFT) { //Get the mouse offsets int mouse_x = e.button.x; int mouse_y = e.button.y; if (playBtn.IsClicked(mouse_x, mouse_y)) { gameState = PLAY; } else if (exitBtn.IsClicked(mouse_x, mouse_y)) { quit = true; } } }// End detect button click background.Draw(r); playBtn.Draw(r); exitBtn.Draw(r); break; case PLAY: newTime = SDL_GetTicks(); delta = newTime - oldTime; oldTime = newTime; en.Update(delta); lvl.Draw(r); en.Draw(r); en1.Update(delta); en1.Draw(r); en.Draw(r); player.Update(r, delta); player.Draw(r); //calculateFPS(); break; } InputManager::GetInstance()->UpdateState(); r.End(); } //Remove timer in case the call back was not called SDL_WaitThread(threadID, NULL); return EXIT_SUCCESS; }
void BasicApp::draw() { // this pair of lines is the standard way to clear the screen in OpenGL gl::clear( Color( 0.0f, 0.0f, 0.0f ) ); gl::setMatricesWindow( getWindowSize() ); if(game_state == Game_Demo) { gl::enableAlphaBlending( true ); for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++) { if(itr->m_bHit) { } itr->Draw(); } Font font = Font( "Times New Roman", 50 ); gl::drawString("Atari Asteroids Clone" , Vec2f(app::getWindowWidth()/4,app::getWindowHeight()/4),cinder::ColorA(1,1,1,1), font); gl::drawString("Presse SpaceBar to Play" , Vec2f(app::getWindowWidth()/4,app::getWindowHeight()/2 + 100),cinder::ColorA(1,1,1,1), font); } else if(game_state == GAME_Play) { for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++) { if(itr->m_bHit) { } itr->Draw(); } enemy.Draw(); particleManager.Move(); particleManager.Draw(); particleLineManager.Update(); particleLineManager.Draw(); currentShip.Draw(); for (std::vector<Ship>::iterator itrShip = ships.begin(); itrShip!=ships.end();itrShip++) { if(itrShip->m_state== Ship::Ship_Alive) { itrShip->Draw(); } } stringstream scoreString; scoreString<< score; gl::drawString(" " + scoreString.str(), Vec2f(10,10),cinder::ColorA(1,1,1,1), mFont); } else if (game_state == GAME_End) { gl::drawString("Game Over", Vec2f(getWindowWidth()/2,getWindowHeight()/2),cinder::ColorA(1,1,1,1), mFont); } }