uint16 ShootEmUp::run() { CursorMan.showMouse(false); _vm->_graphics->saveScreen(); _vm->fadeOut(); _vm->_graphics->seuDrawTitle(); _vm->fadeIn(); _vm->_graphics->seuLoad(); // Should we show the instructions? while (!_vm->shouldQuit()) { Common::Event event; _vm->getEvent(event); if (event.type == Common::EVENT_KEYDOWN) { if ((event.kbd.keycode == Common::KEYCODE_i) || (event.kbd.keycode == Common::KEYCODE_F1)) instructions(); break; // We don't show the instructions and simply go on with the minigame if not I or F1 was pressed. } } setup(); while ((_time != 0) && (!_vm->shouldQuit())) { uint32 beginLoop = _vm->_system->getMillis(); blankIt(); hitPeople(); plotThem(); moveThem(); moveAvvy(); bumpFolk(); peopleRunning(); animate(); escapeCheck(); collisionCheck(); updateTime(); check321(); readKbd(); _cp = !_cp; _vm->_graphics->refreshScreen(); uint32 delay = _vm->_system->getMillis() - beginLoop; if (delay <= 55) _vm->_system->delayMillis(55 - delay); // Replaces slowdown(); 55 comes from 18.2 Hz (B Flight). }; _vm->fadeOut(); _vm->_graphics->restoreScreen(); _vm->_graphics->removeBackup(); _vm->fadeIn(); CursorMan.showMouse(true); return _score; }
// compute velocity & position (cube included) and draw dot (exploded or not) void Cube::animate(Cube* cubes, const float dts) { static const float deadzone = 2.0f; static const float accelScale = 0.6f; static const float damping = 0.995f; if (lifeCounter <= 0) return; for (uint8_t d=0; d<dot_n; d++) { // if dot neither hidden nor exploded, animate it: if (not (vid.sprites[d].isHidden() || dots[d].exp)) { Float2 accel = id.accel().xy(); if (accel.len2() > deadzone * deadzone) dots[d].vel += accel * accelScale; dots[d].vel *= damping; Float2 step = dots[d].vel * dts; Float2 candidate = dots[d].pos + step; // Does this dot want to leave the cube ? Side mySide = (candidate.y < minPos.y) ? TOP : // 0 (candidate.x < minPos.x) ? LEFT : // 1 (candidate.y > maxPos.y) ? BOTTOM : // 2 (candidate.x > maxPos.x) ? RIGHT : // 3 NO_SIDE; // -1 bool stayHere = true; // default CubeID hisID; // neighbor CubeID Side hisSide = NO_SIDE; // his side number that touches mySide if (mySide != NO_SIDE) { // avoids cubeAt(NO_SIDE) error Neighborhood myNbh(id); hisID = myNbh.cubeAt(mySide); if (hisID.isDefined()) { // ...same with sideOf(NO_SIDE) Neighborhood hisNbh(hisID); hisSide = hisNbh.sideOf(id); stayHere = cubes[hisID].isFull(); } } if (stayHere) { // will this dot stay? if (mySide==TOP || mySide==BOTTOM) // bounce vertically? dots[d].vel.y = -dots[d].vel.y; if (mySide==LEFT || mySide==RIGHT) // ...horizontally? dots[d].vel.x = -dots[d].vel.x; dots[d].pos += dots[d].vel * dts; // finish calculation vid.sprites[d].setImage(DotIMG); // draw the dot vid.sprites[d].move(dots[d].pos); } else { // move to neighbor dots[d].pos += step; // finish calculation moveDot(d, cubes[hisID], mySide, hisSide); } } } collisionCheck(); displayDamages(); }
void PhysicsObject::collisionResponse(const PhysicsObject *object) { CollisionInfo info = collisionCheck(object); if(info.collision) { // m_position = m_oldPosition; m_position += info.direction * info.distance; Vector3 normal = info.direction.normalize(); m_velocity += (normal * (m_velocity * -1.0f).dotProduct(normal) * (1.0f + m_bounciness)); } }
CollisionInfo BoundingBox::collisionCheck(const PhysicsObject *object) const { PhysicsObjectType otherType = object->getType(); switch(otherType) { default: return PhysicsObject::collisionCheck(object); case PHYSICS_OBJECT_TYPE_POINT: return pointInBox(object->getPosition(), m_position, m_bounds); case PHYSICS_OBJECT_TYPE_BOUNDING_BOX: return collisionCheck((const BoundingBox *)object); } }
//-------------------------------------------------------------- void ofApp::update(){ //accelerate and move planets for(int i = 0; i < planets.size(); i++){ indexes = collisionCheck(planets, suns, i);//maybe add to orbits.cpp as part of Planet or Sun if(indexes.size() != 0){ for(int z = 0; z < indexes.size(); z++){ planets.erase(planets.begin()+(indexes[z]));//delete planet or planets that collided from vector } } planets[i].acc(planets, suns,i);//accelerate the planets on themselves and the suns planets[i].move();//move planets } }
void ActionManager::collisionProjectileVsCraft(){ //check for collisions between crafts and projectiles for(unsigned int i = 0; i < craftPool.size(); i++) for(unsigned int j = 0; j < projectilePool.size(); j++) if(collisionCheck(craftPool[i]->getSceneNode(), projectilePool[j]->getAnimatedMeshSceneNode())){ ISceneNode* craftNode = 0; if(craftPool[i]->getSceneNode()->getID() < ENEMY_CRAFT_THRESHOLD) //define type of craft whether it is enemy or not craftNode = craftPool[i]->getSceneNode(); ISceneNode* projectileNode = (ISceneNode*)projectilePool[j]->getAnimatedMeshSceneNode(); if(craftNode && projectileNode){ createExplosion(craftNode->getPosition(), 12); craftPool[i]->remove(); //remove craft delete craftPool[i]; //release its memory craftPool.erase(i); //remove from active pool projectilePool[j]->remove(); //remove projectile delete projectilePool[j]; projectilePool.erase(j); updateScore(10); } } }
void ActionManager::collisionCraftVsCraft(){ for(unsigned int i = 0; i < craftPool.size(); i++) for(unsigned int j = i + 1; j < craftPool.size(); j++) if(collisionCheck(craftPool[i]->getSceneNode(), craftPool[j]->getSceneNode())){ ISceneNode* fighter; ISceneNode* craft; bool isFighter = false; if(craftPool[i]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){ fighter = craftPool[i]->getSceneNode(); craft = craftPool[j]->getSceneNode(); isFighter = true; } else if (craftPool[j]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){ fighter = craftPool[j]->getSceneNode(); craft = craftPool[i]->getSceneNode(); isFighter = true; } if(isFighter){ craft->setVisible(false); fighter->setVisible(false); createExplosion(fighter->getPosition(), 12); gameOver(); } } }
CollisionInfo PhysicsObject::collisionCheck(const PhysicsObject &object) const { return collisionCheck(&object); }
void pacman::changePosition(map *cMap, int &c) { if (item::dead) { cMap->m[pos.intX][pos.intY] = 'n'; item::dead = 0; pos.x = start.x; pos.y = start.y; pos.intY = start.intY; pos.intX = start.intX; pos.direction = 'u'; pacmanDir = pos.direction; M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); cMap->m[pos.intX][pos.intY] = 'p'; pM = glm::mat4(0.0f); //tu mo¿na daæ jakiœ ekran ¿e zmar³ raz } else { if (config::c) { pos.direction = config::c; config::c = NULL; } pM = M; //zapamietanie starego M if (!collisionCheck(cMap)) { switch (pos.direction) { case 'u': { cMap->m[pos.intX][pos.intY] = 'n'; pos.y += config::width; pos.intY--; if (cMap->m[pos.intX][pos.intY] == 'm') { c--; cMap->m[pos.intX][pos.intY] = 'n'; if (!c) config::end = 1; } M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); lastDir = 'u'; cMap->m[pos.intX][pos.intY] = 'p'; pacmanDir = pos.direction; break; } case 'd': { cMap->m[pos.intX][pos.intY] = 'n'; pos.y -= config::width; pos.intY++; if (cMap->m[pos.intX][pos.intY] == 'm') { c--; cMap->m[pos.intX][pos.intY] = 'n'; if (!c) config::end = 1; } M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); lastDir = 'd'; cMap->m[pos.intX][pos.intY] = 'p'; pacmanDir = pos.direction; break; } case 'r': { cMap->m[pos.intX][pos.intY] = 'n'; pos.x += config::width; pos.intX++; if (cMap->m[pos.intX][pos.intY] == 'm') { c--; cMap->m[pos.intX][pos.intY] = 'n'; if (!c) config::end = 1; } M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); lastDir = 'r'; cMap->m[pos.intX][pos.intY] = 'p'; pacmanDir = pos.direction; break; } case 'l': { cMap->m[pos.intX][pos.intY] = 'n'; pos.x -= config::width; pos.intX--; if (cMap->m[pos.intX][pos.intY] == 'm') { c--; cMap->m[pos.intX][pos.intY] = 'n'; if (!c) config::end = 1; } M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); lastDir = 'l'; cMap->m[pos.intX][pos.intY] = 'p'; pacmanDir = pos.direction; break; } default: break; } } } for (int i = 0; i < 4; i++) { if (ghostPos[i][0] == pos.intX && ghostPos[i][1] == pos.intY) { item::nextDead = i + 1; cMap->m[pos.intX][pos.intY] = 'n'; item::dead = 1; pos.x = start.x; pos.y = start.y; pos.intY = start.intY; pos.intX = start.intX; pos.direction = 'u'; pacmanDir = pos.direction; M = glm::mat4(1.0f); M = glm::translate(M, vec3(pos.x, pos.y, pos.z)); cMap->m[pos.intX][pos.intY] = 'p'; } } }
void Scene::updateScene() { if ( _firstUpdate ) { _firstUpdate = false; _timer.start(); return; } float timeSinceLastUpdate = _timer.getMilliseconds()/1000; _secondsPlayed += timeSinceLastUpdate; _updateTime = timeSinceLastUpdate; _landscape.setTimeSinceLastUpdate(timeSinceLastUpdate); _timer.start(); if (_nrKills >= getNrKillsToWin()) { reset(true); return; } else if (_nrDeaths >= getNrDeathsToLose()) { reset(false); return; } /** // save old configuration of enemies and playertank // (this will be used for the collision handling below) */ Point *enemies_pos_old = new Point[getNrEnemies()]; double *enemies_angle_old = new double[getNrEnemies()]; Point player_pos_old = _playerTank.getPosition(); double player_angle_old = _playerTank.getAngle(); for(int i = 0; i < getNrEnemies(); i++) { enemies_pos_old[i] = _enemies[i].getPosition(); enemies_angle_old[i] = _enemies[i].getAngle(); } // let enemies choose their next action for (int i = 0; i < getNrEnemies(); i++) { _enemies[i].updateAction(&_landscape, _playerTank.getPosition()); } /** // Update */ // update tanks _playerTank.update(timeSinceLastUpdate); for (int i = 0; i < getNrEnemies(); i++) { _enemies[i].update(timeSinceLastUpdate); //_enemies[i].setSpeed(3.0); } // update bullets for ( BulletVector::iterator bulletIter = _bullets.begin(); bulletIter != _bullets.end(); bulletIter++) { Bullet &bullet = *bulletIter; bullet.update(timeSinceLastUpdate, _xSlices, _zSlices, _planeX, _planeZ); } // check player tank if it is dead if(_playerTank.getState() == TANK_DYING) { ParticleSystem p; p.setPosition(Point(_playerTank.getPosition().x, _playerTank.getPosition().y + 1.0, _playerTank.getPosition().z)); p.setVelRange(10.0); p.setLifetime(3.0); p.setRGB(0.5, 0.2, 0.0); _psystems.push_back(p); _playerTank.setState(TANK_DEAD); _nrDeaths++; _playerTank.reset(); } // check enemies if they are dead for (int i = 0; i < getNrEnemies(); i++) { if(_enemies[i].getState() == TANK_DYING) { ParticleSystem p; p.setPosition(Point(_enemies[i].getPosition().x, _enemies[i].getPosition().y + 1.0, _enemies[i].getPosition().z)); p.setVelRange(10.0); p.setLifetime(3.0); p.setRGB(0.5, 0.2, 0.0); _psystems.push_back(p); _enemies[i].setState(TANK_DEAD); _nrKills++; _enemies[i].reset(); } } //update particle systems //psystem.setPosition(Point(_playerTank.getPosition().x, _playerTank.getPosition().y + 1.0, _playerTank.getPosition().z)); for (unsigned int i = 0; i < _psystems.size(); i++) _psystems[i].update(timeSinceLastUpdate); /** // Deletion and Death animation */ // bullets for(unsigned int i = 0; i < _bullets.size(); i++) { if(_bullets[i].getState() == BULLET_DELETE) { ParticleSystem p; p.setPosition(Point(_bullets[i].getPosition().x, _bullets[i].getPosition().y + 0.2, _bullets[i].getPosition().z)); p.setVelRange(5.0); p.setLifetime(3.0); p.setPeriod(5.0); p.setRGB(0.1, 0.1, 0.1); if(_bullets[i].getType() == BULLET_MG) p.setNParticles(3); _psystems.push_back(p); _bullets.erase(_bullets.begin()+i); } } // particle systems for(unsigned int i = 0; i < _psystems.size(); i++) { if(_psystems[i].getState() == PSYSTEM_DEAD) { _psystems.erase(_psystems.begin()+i); } } /** // Collision Check */ collisionCheck(enemies_pos_old, enemies_angle_old, player_pos_old, player_angle_old); /** // Cleanup */ delete [] enemies_pos_old; delete [] enemies_angle_old; }
void ld::PlayState::update(const float delta) { /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::T)) { m_player.setLives(0); } */ if (Engine::getInstance().pauseButtonPressed() && !Engine::getInstance().isPaused()) { Engine::getInstance().setPaused(true); m_menuState = Pause; } else if (m_player.getLives() < 1) { m_menuState = GameOver; } if (Engine::getInstance().isPaused()) m_scoreClock.restart(); else if (m_scoreClock.getElapsedTime().asSeconds() > 10.f) { ++m_score; m_scoreClock.restart(); } m_player.update(delta); collisionCheck(); for (int i = 0; i < (int)m_enemies.size(); ++i) { m_enemies[i].update(delta); } for (std::size_t i = 0; i < m_explosions.size(); ++i) { m_explosions[i].update(delta); if (m_explosions[i].hasSoundStopped()) { m_explosions.erase(m_explosions.begin() + i); --i; } } m_spawnTime += delta; countTimeForEnemies(); if (m_Time > m_minTime) m_Time -= delta / 100; else m_Time = m_minTime; for (std::size_t i = 0; i < m_menus.size(); ++i) { if (m_menus[i]) { auto& menu = *m_menus[i]; const float orDelta = Engine::getInstance().getDeltaOverride(); if (i == static_cast<unsigned int>(m_menuState)) menu.fadeInStep(orDelta); else menu.fadeOutStep(orDelta); if (menu.getDelta() >= 0.5f) { menu.update(orDelta); } } } }
void PLANET5::Update(double dt) { if (Application::IsKeyPressed('1')) //enable back face culling glEnable(GL_CULL_FACE); if (Application::IsKeyPressed('2')) //disable back face culling glDisable(GL_CULL_FACE); if (Application::IsKeyPressed('3')) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //default fill mode if (Application::IsKeyPressed('4')) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //wireframe mode if (Application::IsKeyPressed('F')) GameMode::GetInstance()->gameState = 1; camera.Update(dt); if (Application::IsKeyPressed('I')) light[0].position.z -= (float)(LSPEED * dt); if (Application::IsKeyPressed('K')) light[0].position.z += (float)(LSPEED * dt); if (Application::IsKeyPressed('J')) light[0].position.x -= (float)(LSPEED * dt); if (Application::IsKeyPressed('L')) light[0].position.x += (float)(LSPEED * dt); if (Application::IsKeyPressed('O')) light[0].position.y -= (float)(LSPEED * dt); if (Application::IsKeyPressed('P')) light[0].position.y += (float)(LSPEED * dt); if (Application::IsKeyPressed(VK_LBUTTON) && ((camera.position.x < 10) && (camera.position.x > 0) && (camera.position.z < 52) && (camera.position.z > 40))) { spin1 = true; } if (spin1 == true) { rotatespin += (float)(25 * dt); } if ((translateButton > 3.4f) && (spin1 == true)) { translateButton -= (float)(1 * dt); } if (Application::IsKeyPressed(VK_RBUTTON) && ((camera.position.x < 10) && (camera.position.x > 0) && (camera.position.z < 52) && (camera.position.z > 40))) { spin1 = false; } if ((translateButton < 3.55f) && (spin1 == false)) { translateButton += (float)(1 * dt); } if (Application::IsKeyPressed(VK_LBUTTON) && ((camera.position.x < -45) && (camera.position.x > -55) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem1 = true; } if (gem1 == true) { if (flygem1 <= 8.0f) { flygem1 += (float)(3 * dt); } if (flygem1 > 7.99f) { rotategem1 += (float)(150 * dt); } complete1 = true; } if ((translategem1 > 3.4f) && (gem1 == true)) { translategem1 -= (float)(1 * dt); } if (Application::IsKeyPressed(VK_RBUTTON) && ((camera.position.x < -45) && (camera.position.x > -55) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem1 = false; } if ((translategem1 < 3.55f) && (gem1 == false)) { translategem1 += (float)(1 * dt); } if (gem1 == false) { if (flygem1 > 6.0f) { flygem1 -= (float)(3 * dt); } } if (Application::IsKeyPressed(VK_LBUTTON) && ((camera.position.x < -20) && (camera.position.x > -30) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem2 = true; } if (gem2 == true) { if (flygem2 <= 8.1f) { flygem2 += (float)(3 * dt); } if (flygem2 > 8.09f) { rotategem2 += (float)(150 * dt); } complete2 = true; } if ((translategem2 > 3.4f) && (gem2 == true)) { translategem2 -= (float)(1 * dt); } if (Application::IsKeyPressed(VK_RBUTTON) && ((camera.position.x < -20) && (camera.position.x > -30) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem2 = false; } if ((translategem2 < 3.55f) && (gem2 == false)) { translategem2 += (float)(1 * dt); } if (gem2 == false) { if (flygem2 > 6.3f) { flygem2 -= (float)(3 * dt); } } if (Application::IsKeyPressed(VK_LBUTTON) && ((camera.position.x < 5) && (camera.position.x > -5) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem3 = true; } if (gem3 == true) { if (flygem3 <= 7.5f) { flygem3 += (float)(3 * dt); } if (flygem3 > 7.49f) { rotategem3 += (float)(150 * dt); } complete3 = true; } if ((translategem3 > 3.4f) && (gem3 == true)) { translategem3 -= (float)(1 * dt); } if (Application::IsKeyPressed(VK_RBUTTON) && ((camera.position.x < 5) && (camera.position.x > -5) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem3 = false; } if ((translategem3 < 3.55f) && (gem3 == false)) { translategem3 += (float)(1 * dt); } if (gem3 == false) { if (flygem3 > 5.5f) { flygem3 -= (float)(3 * dt); } } if (Application::IsKeyPressed(VK_LBUTTON) && ((camera.position.x < 30) && (camera.position.x > 20) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem4 = true; } if (gem4 == true) { if (flygem4 <= 7.5f) { flygem4 += (float)(3 * dt); } if (flygem4 > 7.49f) { rotategem4 += (float)(150 * dt); } complete4 = true; } if ((translategem4 > 3.4f) && (gem4 == true)) { translategem4 -= (float)(1 * dt); } if (Application::IsKeyPressed(VK_RBUTTON) && ((camera.position.x < 30) && (camera.position.x > 20) && (camera.position.z < -69.5) && (camera.position.z > -93.5))) { gem4 = false; } if ((translategem4 < 3.55f) && (gem4 == false)) { translategem4 += (float)(1 * dt); } if (gem4 == false) { if (flygem4 > 5.5f) { flygem4 -= (float)(3 * dt); } } if (complete1 == true && complete2 == true && complete3 == true && complete4 == true) { if (scaleFinish < 10) { scaleFinish += (float)(1 * dt); } translateEND = 20.0f; } charMovement(MS_reverse, 20.f, MS_rotate, 3.f, dt); collisionCheck(125.f, 0.f, camera, Vector3(2.f, 0.f, 126.f)); collisionCheck(-125.f, 0.f, camera, Vector3(2.f, 0.f, 126.f)); collisionCheck(0.f, 125.f, camera, Vector3(126.f, 0.f, 2.f)); collisionCheck(0.f, -125.f, camera, Vector3(126.f, 0.f, 2.f)); collisionCheck(0.f, 0.f, camera, Vector3(40.f, 0.f, 40.f)); collisionCheck(5.f, 45.f, camera, Vector3(3.f, 0.f, 3.f)); }
bool xaeBlockScene::update(float fDT) { g_BGMPlayer.update(fDT); #ifdef __DEBUG if(xae::Instance().keyup(HGEK_ESCAPE)) { g_bDebugStop ^= true; } if(g_bDebugStop) return false; /** 彩旦:直接赢了 */ if(xae::Instance().keystate(HGEK_CTRL) && xae::Instance().keystate(HGEK_E)) { xaeAVGScene* scene = (xaeAVGScene*)(xaeSceneMgr::Instance().get_scene("AVG")); /** 若死过了而且是PreBoss关 */ if(scene->getRevived() && m_szLevelName == g_Setting.Block.m_szPreBoss) { xaeSceneMgr::Instance().del_scene("AVG"); xaeSceneObject* sceneo = xaeSceneMgr::Instance().create_scene("Welcome", "Welcome"); xaeSceneMgr::Instance().add_scene("Welcome", sceneo); xaeSceneMgr::Instance().set_current_scene("Welcome"); return false; } /** 否则跳到AVG画面 */ scene->parseNextPause(); xaeSceneMgr::Instance().set_current_scene("AVG"); /** Pre Boss干翻了 */ if(m_szLevelName == g_Setting.Block.m_szPreBoss) { scene->setPreBossed(); } return false; } #endif /** 暂停 */ if(xae::Instance().keyup(HGEK_ENTER)) { if(m_emStatus == XBPS_PLAYING) { m_emStatus = XBPS_PAUSE; return false; } else if(m_emStatus == XBPS_PAUSE) { m_emStatus = XBPS_PLAYING; } } if(m_emStatus == XBPS_PAUSE) return false; /** GUI */ float mousex, mousey; m_pHGE->Input_GetMousePos(&mousex, &mousey); m_pGUI->update(fDT, mousex, mousey); /** 挡板左右转 */ float dx = fDT * g_Setting.Block.m_fFlapSpeed; if(xae::Instance().keystate(HGEK_RIGHT)) { if(m_fFlapX + dx + g_Setting.Block.m_nFlapLength * m_dwFlapNum <= 600.0f) { m_fFlapX += dx; if(m_emStatus == XBPS_READY) { m_fBallX += dx; } } else { m_fFlapX = 600.0f - g_Setting.Block.m_nFlapLength * m_dwFlapNum; if(m_emStatus == XBPS_READY) { m_fBallX = 600.0f - (g_Setting.Block.m_nFlapLength * m_dwFlapNum) / 2.0f; } } } if(xae::Instance().keystate(HGEK_LEFT)) { if(m_fFlapX - dx >= 0) { m_fFlapX -= dx; if(m_emStatus == XBPS_READY) { m_fBallX -= dx; } } else { m_fFlapX = 0.0f; if(m_emStatus == XBPS_READY) { m_fBallX = (g_Setting.Block.m_nFlapLength * m_dwFlapNum) / 2.0f; } } } /** 道具更新 */ m_Treasure.update(fDT, m_fFlapX, m_fFlapY); /** 挡板长度 */ float fFlapCenterX = m_fFlapX + (m_dwFlapNum * g_Setting.Block.m_nFlapLength) / 2.0f; m_dwFlapNum = m_Treasure.getFlapNum(); m_fFlapX = fFlapCenterX - (m_dwFlapNum * g_Setting.Block.m_nFlapLength) / 2; if(m_fFlapX < 0) m_fFlapX = 0; else if(m_fFlapX + m_dwFlapNum * g_Setting.Block.m_nFlapLength > 600.0f) m_fFlapX = 600.0f - m_dwFlapNum * g_Setting.Block.m_nFlapLength; /** 空格或者回车 */ if(xae::Instance().keyup(HGEK_SPACE) || xae::Instance().keyup(HGEK_ENTER)) { /** 变成开始状态 */ if(m_emStatus == XBPS_READY) { m_emStatus =XBPS_PLAYING; } else /** 赢了按回车回到AVG画面 */ if(m_emStatus == XBPS_WIN) { xaeAVGScene* scene = (xaeAVGScene*)(xaeSceneMgr::Instance().get_scene("AVG")); /** 若死过了而且是PreBoss关 */ if(scene->getRevived() && m_szLevelName == g_Setting.Block.m_szPreBoss) { xaeSceneMgr::Instance().del_scene("AVG"); xaeSceneObject* sceneo = xaeSceneMgr::Instance().create_scene("Welcome", "Welcome"); xaeSceneMgr::Instance().add_scene("Welcome", sceneo); xaeSceneMgr::Instance().set_current_scene("Welcome"); return false; } /** 否则跳到AVG画面 */ scene->parseNextPause(); xaeSceneMgr::Instance().set_current_scene("AVG"); /** Pre Boss干翻了 */ if(m_szLevelName == g_Setting.Block.m_szPreBoss) { scene->setPreBossed(); } return false; } } /** 游戏在玩的状态 */ if(m_emStatus == XBPS_PLAYING) { /** 球飞啦! */ float fbdx = m_fBallSpeedX * fDT, fbdy = m_fBallSpeedY * fDT; fbdx *= m_Treasure.getSpeedScale(); fbdy *= m_Treasure.getSpeedScale(); /** 横向飞 */ if(m_fBallX + fbdx - g_Setting.Block.m_nBallLength / 2 >= 0.0f && m_fBallX + fbdx + g_Setting.Block.m_nBallLength / 2 <= 600.0f) { m_fBallX += fbdx; } else if(m_fBallX + fbdx - g_Setting.Block.m_nBallLength / 2 < 0.0f) m_fBallX = g_Setting.Block.m_nBallLength / 2, m_fBallSpeedX = -m_fBallSpeedX; else m_fBallX = 600 - g_Setting.Block.m_nBallLength / 2, m_fBallSpeedX = -m_fBallSpeedX; /** 纵向飞 */ if(m_fBallY + fbdy - g_Setting.Block.m_nBallLength / 2 >= 0.0f) { m_fBallY += fbdy; } else if(m_fBallY + fbdy - g_Setting.Block.m_nBallLength / 2 < 0.0f) m_fBallY = g_Setting.Block.m_nBallLength / 2, m_fBallSpeedY = - m_fBallSpeedY; //else m_fBallY = 590.0f, m_fBallSpeedY = - m_fBallSpeedY; /** 碰到挡板:往上弹 */ if(m_fBallY >= g_Setting.Block.m_fFlapY - g_Setting.Block.m_nBallLength / 2 && m_fBallY <= g_Setting.Block.m_fFlapY + 15.0f - g_Setting.Block.m_nBallLength / 2) { /** x轴在挡板范围内 */ if(m_fBallX >= m_fFlapX && m_fBallX <= m_fFlapX + m_dwFlapNum * g_Setting.Block.m_nFlapLength) { /** 根据小球在挡板的位置确定x速度 */ m_fBallSpeedX = (m_fBallX - (m_fFlapX + m_dwFlapNum * g_Setting.Block.m_nFlapLength / 2)) / (m_dwFlapNum * (g_Setting.Block.m_nFlapLength) / 2); m_fBallSpeedX *= g_Setting.Block.m_fMaxHorizontalRate; m_fBallSpeedX *= g_Setting.Block.m_fBallSpeed; /** 确定y轴速度:保证x和y的合速度为g_Setting.Block.m_fBallSpeed */ m_fBallSpeedY = -sqrt(g_Setting.Block.m_fBallSpeed * g_Setting.Block.m_fBallSpeed - m_fBallSpeedX * m_fBallSpeedX); } } /** 飞丢了 */ if(m_fBallY >= 600.0f) { /** 如果已经干翻了Pre Boss,则直接到welcome */ xaeAVGScene* scenea = (xaeAVGScene*)xaeSceneMgr::Instance().get_scene("AVG"); if(scenea->getPreBossed()) { xaeSceneObject* sceneo = xaeSceneMgr::Instance().create_scene("Welcome", "Welcome"); xaeSceneMgr::Instance().add_scene("Welcome", sceneo); xaeSceneMgr::Instance().del_scene("AVG"); xaeSceneMgr::Instance().set_current_scene("Welcome"); return false; } xaeSceneObject* scene = xaeSceneMgr::Instance().create_scene("Revive", "Revive"); if(NULL != scene) { xaeSceneMgr::Instance().add_scene("Revive", scene); } xaeSceneMgr::Instance().set_current_scene("Revive"); ((xaeReviveScene*)scene)->setLevel(m_szLevelName); /** 设置AVG为死过了 */ ((xaeAVGScene*)xaeSceneMgr::Instance().get_scene("AVG"))->setRevived(); return false; } /** 得到小球区域四个角的坐标 */ coor zs(m_fBallX, m_fBallY), zx(m_fBallX, m_fBallY), ys(m_fBallX, m_fBallY), yx(m_fBallX, m_fBallY); zs.x -= (g_Setting.Block.m_nBallLength / 2), zs.y -= (g_Setting.Block.m_nBallLength / 2); ys.x += (g_Setting.Block.m_nBallLength / 2), ys.y -= (g_Setting.Block.m_nBallLength / 2); zx.x -= (g_Setting.Block.m_nBallLength / 2), zx.y += (g_Setting.Block.m_nBallLength / 2); yx.x -= (g_Setting.Block.m_nBallLength / 2), yx.y -= (g_Setting.Block.m_nBallLength / 2); /** 求四个角所在的各方块的下标 */ int zsi = ((int)zs.y) / g_Setting.Block.m_nBlockHeight, zsj = ((int)zs.x) / g_Setting.Block.m_nBlockWidth; int ysi = ((int)ys.y) / g_Setting.Block.m_nBlockHeight, ysj = ((int)ys.x) / g_Setting.Block.m_nBlockWidth; int zxi = ((int)zx.y) / g_Setting.Block.m_nBlockHeight, zxj = ((int)zx.x) / g_Setting.Block.m_nBlockWidth; int yxi = ((int)yx.y) / g_Setting.Block.m_nBlockHeight, yxj = ((int)yx.x) / g_Setting.Block.m_nBlockWidth; /** 碰撞检测 */ coor zspz = collisionCheck(m_hTexClothHot, zsj * g_Setting.Block.m_nBlockWidth, zsi * g_Setting.Block.m_nBlockHeight, g_Setting.Block.m_nBlockWidth, g_Setting.Block.m_nBlockHeight); coor zxpz = collisionCheck(m_hTexClothHot, zxj * g_Setting.Block.m_nBlockWidth, zxi * g_Setting.Block.m_nBlockHeight, g_Setting.Block.m_nBlockWidth, g_Setting.Block.m_nBlockHeight); coor yspz = collisionCheck(m_hTexClothHot, ysj * g_Setting.Block.m_nBlockWidth, ysi * g_Setting.Block.m_nBlockHeight, g_Setting.Block.m_nBlockWidth, g_Setting.Block.m_nBlockHeight); coor yxpz = collisionCheck(m_hTexClothHot, yxj * g_Setting.Block.m_nBlockWidth, yxi * g_Setting.Block.m_nBlockHeight, g_Setting.Block.m_nBlockWidth, g_Setting.Block.m_nBlockHeight); /** 处理碰撞 */ if(zspz.x >= 0.0f && zspz.y >= 0.0f) { /** 这个方块消失 */ m_bClothes[zsi][zsj] = false; /** 方块数减少 */ m_dwBlockLeft--; m_Treasure.generateTreasure(zsj * g_Setting.Block.m_nBlockWidth + g_Setting.Block.m_nBlockWidth / 2, zsi * g_Setting.Block.m_nBlockHeight + g_Setting.Block.m_nBlockHeight / 2); /** 下同 */ } if(zxpz.x >= 0.0f && zxpz.y >= 0.0f && (zsi != zxi || zsj != zxj)) { m_bClothes[zxi][zxj] = false; m_dwBlockLeft--; m_Treasure.generateTreasure(zxj * g_Setting.Block.m_nBlockWidth + g_Setting.Block.m_nBlockWidth / 2, zxi * g_Setting.Block.m_nBlockHeight + g_Setting.Block.m_nBlockHeight / 2); } if(yspz.x >= 0.0f && yspz.y >= 0.0f && (zxi != ysi || zxj != ysj) && (zsi != ysi || zsj != ysj)) { m_bClothes[ysi][ysj] = false; m_dwBlockLeft--; m_Treasure.generateTreasure(ysj * g_Setting.Block.m_nBlockWidth + g_Setting.Block.m_nBlockWidth / 2, ysi * g_Setting.Block.m_nBlockHeight + g_Setting.Block.m_nBlockHeight / 2); } if(yxpz.x >= 0.0f && yxpz.y >= 0.0f && (zxi != yxi || zxj != yxj) && (ysi != yxi || ysj != yxj) && (zsi != yxi || zsj != yxj)) { m_bClothes[yxi][yxj] = false; m_dwBlockLeft--; m_Treasure.generateTreasure(yxj * g_Setting.Block.m_nBlockWidth + g_Setting.Block.m_nBlockWidth / 2, yxi * g_Setting.Block.m_nBlockHeight + g_Setting.Block.m_nBlockHeight / 2); } /** 重新设置速度 */ if(!m_Treasure.getHits()) { if(zspz.x >= 0.0f && zspz.y >= 0.0f) setRebound(zspz); else if(yspz.x >= 0.0f && yspz.y >= 0.0f) setRebound(yspz); else if(zxpz.x >= 0.0f && zxpz.y >= 0.0f) setRebound(zxpz); else if(yxpz.x >= 0.0f && yxpz.y >= 0.0f) setRebound(yxpz); } /** 所有方块打完了就赢了 */ if(m_dwBlockLeft == 0) m_emStatus = XBPS_WIN; } return false; }
bool CollisionCheckingRos::check(const std::vector <FrameWithId>& path, const FrameWithId& actualPose) { bool result = collisionCheck(path, actualPose, 0.1, 100); return result; }
/* Checks local coordinates, and expects such as input. * Returns number of non-player entities */ unsigned int sceneContainer::update(const float dt){ sGrid->reset(); // reset screen grid sEnemyCount = 0; sTerrainCount = 0; // For testing bool vulnerability = true; // First: update each managed entry for (auto& i : sEntityList){ sf::Vector2f pos; pos = i->update(dt); // The player shall not leave the screen if (i->getEntityType() == EntityType::PLAYER){ if (pos.x < sScreen.left + 15) pos.x = sScreen.left + 15; else if (pos.x > sScreen.width - 15) pos.x = sScreen.width - 15; if (pos.y < sScreen.top + 15) pos.y = sScreen.top + 15; else if (pos.y > sScreen.height - 15) pos.y = sScreen.height - 15; i->setPosition(pos); } // On basis of updated position, let's update entity's status if (i->getStatus() != StatusID::EXPLODING && i->getStatus() != StatusID::DESTROYED) i->setStatus(StatusID::ONSCREEN); /* * Now add entities to the screen grid, based on the position of their AABB's * 4 corner points; and update enemy lists. An enemy could eb registered * to multiple cells in the grid, based on the position of its AABB */ if (i->getStatus() == StatusID::ONSCREEN){ Entity* e = i.get(); sf::FloatRect box{e->getAABB()}; sf::Vector2i topleft{ static_cast<int>(box.left / sGridSize.x), static_cast<int>(box.top / sGridSize.y) }; sf::Vector2i topright{ static_cast<int>( (box.left + box.width) / sGridSize.x), static_cast<int>(box.top / sGridSize.y) }; sf::Vector2i botleft{ static_cast<int>(box.left / sGridSize.x), static_cast<int>((box.top + box.height) / sGridSize.y) }; sf::Vector2i botright{ static_cast<int>((box.left + box.width) / sGridSize.x), static_cast<int>((box.top + box.height) / sGridSize.y) }; sGrid->append(topleft.x, topleft.y, e); if (topright != topleft) sGrid->append(topright.x, topright.y, e); if ((botleft != topleft) && (botleft != topright)) sGrid->append(botleft.x, botleft.y, e); if ((botright != botleft) && (botright != topleft) && (botright != topright)) sGrid->append(topright.x, topright.y, e); if (i->getEntityType() == EntityType::ENEMY) sEnemies[sEnemyCount++] = e; if (i->getEntityType() == EntityType::TERRAIN) sTerrain[sTerrainCount++] = e; } } // Okay now do collision checks if (vulnerability) collisionCheck(); /* * Finally, let's go through the updated list of entities and * remove those that are destoryed. Then return the number of * not-destoryed, not-exploding enemies/terrain on scene */ int entityCount = 0; sEntityList.remove_if([](const std::unique_ptr<Entity>& p) {return p->getStatus() == StatusID::DESTROYED; }); for (auto& i : sEntityList){ if ((i->getEntityType == EntityType::ENEMY || i->getEntityType == EntityType::TERRAIN) && i->getStatus() != StatusID::EXPLODING) ++entityCount; } return entityCount; }