void CoreApp::UpdatePlayerBullet(Entity& pBullet) { // Called during fixedupdate if( !pBullet.active ) return; pBullet.y += BULLET_SPEED * deltaTime; if( pBullet.y > GRD_TOP ) { pBullet.active = false; } else { for( Entity& thisEnemy : enemies ) { if( pBullet.IsCollidingWith(thisEnemy)) { thisEnemy.active = false; pBullet.active = false; score++; enmTickWait += ENM_MOVEMENT_TICK_INCREMENT; enmRemaining--; if( enmRemaining <= 0 ) { GotoGame(); } break; } } } // Move // Check collisions // Destroy enemy // Increase enemy tick // +Score // Check Win // OR Reposition when offscreen }
void CoreApp::UpdateAndRender() { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) { done = true; } else if( event.type == SDL_KEYDOWN) { if( event.key.keysym.scancode == SDL_SCANCODE_SPACE && state == GAME ) { PlayerShoot(); } else if( event.key.keysym.scancode == SDL_SCANCODE_RETURN ) { if( state == GAMEOVER ) { GotoMainMenu(); } else if ( state == MENU ) { GotoGame(); } else { // GotoGameOver(); } } } } float ticks = (float)SDL_GetTicks()/1000.0; deltaTime = ticks - lastFrameTicks; lastFrameTicks= ticks; Update(); glClearColor( .1f, .1f, .1f, 1.0f); if( clearColorBit ) glClear(GL_COLOR_BUFFER_BIT); glUseProgram(program->programID); program->setModelMatrix(modelMatrix); program->setViewMatrix(viewMatrix); program->setProjectionMatrix(projectionMatrix); switch (state) { case MENU: DrawText(fontTexture, "INVADERS FROM", 1.0, 0, -7.0f, 4.0f); DrawText(fontTexture, "SPACE", 2.0, 0, -6.5f, 2.5f); DrawText(fontTexture, "CREATIVE COMMONS EDITION ", 0.3, 0, -7.0f, 1.0f); DrawText(fontTexture, "SPACE TO FIRE", 0.3, 0, -7.0f, -5.5f); DrawText(fontTexture, "ENTER TO BEGIN", 0.5, 0, -7.0f, -6.0f); player.Render( program ); break; case GAME: player.Render(program); for( Entity& thisEnemy : enemies ) { thisEnemy.Render(program); } playerBullet.Render(program); enemyBullet.Render(program); DrawText(fontTexture, "SCORE: " + to_string(score), 0.5, 0, -4.0f, 7.0f); break; case GAMEOVER: for( Entity& thisEnemy : enemies ) { thisEnemy.Render(program); } DrawText(fontTexture, "GAMEOVER", 1.0, 0, -4.0f, 4.0f); DrawText(fontTexture, "SCORE: " + to_string(score), 0.5, 0, -4.0f, 3.0f); break; } // draw objects SDL_GL_SwapWindow(displayWindow); }
// ------------------------------------------------------------------------ // This handles incomming commands. Anything passed into this function // is assumed to be a complete command from a client. // ------------------------------------------------------------------------ void Logon::Handle( string p_data ) { if( m_errors == 5 ) { m_connection->Protocol().SendString( *m_connection, red + bold + "Too many incorrect responses, closing connection..." + newline ); m_connection->Close(); return; } if( m_state == NEWCONNECTION ) // has not entered name yet { if( BasicLib::LowerCase( p_data ) == "new" ) { m_state = NEWUSER; m_connection->Protocol().SendString( *m_connection, yellow + "Please enter your desired name: " + reset ); } else { PlayerDatabase::iterator itr = PlayerDatabase::findfull( p_data ); if( itr == PlayerDatabase::end() ) { // name does not exist m_errors++; m_connection->Protocol().SendString( *m_connection, bold + red + "Sorry, the user \"" + white + p_data + red + "\" does not exist.\r\n" + "Please enter your name, or \"new\" if you are new: " + reset ); } else { // name exists, go to password entrance. m_state = ENTERPASS; m_name = p_data; m_pass = itr->Password(); m_connection->Protocol().SendString( *m_connection, white + bold + "Welcome, " + p_data + "!" + newline + yellow + "Please enter your password: "******"Sorry, the name \"" + white + p_data + red + "\" has already been taken." + newline + yellow + "Please enter your desired name: " + reset ); } else { if( !AcceptibleName( p_data ) ) { m_errors++; m_connection->Protocol().SendString( *m_connection, red + bold + "Sorry, the name \"" + white + p_data + red + "\" is unacceptible." + newline + yellow + "Please enter your desired name: " + reset ); } else { m_state = ENTERNEWPASS; m_name = p_data; m_connection->Protocol().SendString( *m_connection, yellow + "Please enter your desired password: "******"INVALID PASSWORD!" + yellow + "Please enter your desired password: "******"Thank you! You are now entering the game..." + newline ); Player p; p.Name() = m_name; p.Password() = p_data; // make the player the administrator if he's the first to log in. if( PlayerDatabase::size() == 0 ) { p.Rank() = ADMIN; p.ID() = 1; } else { p.ID() = PlayerDatabase::LastID() + 1; } // add the player PlayerDatabase::AddPlayer( p ); // enter the game as a newbie. GotoGame( true ); return; } if( m_state == ENTERPASS ) { if( m_pass == p_data ) { m_connection->Protocol().SendString( *m_connection, white + "Thank you! You are now entering the game..." + newline ); // enter the game GotoGame(); } else { m_errors++; m_connection->Protocol().SendString( *m_connection, red + bold + "INVALID PASSWORD!" + newline + yellow + "Please enter your password: " + reset ); } return; } }