void Bullet::moveUp( std::vector<SDL_Rect>& otherColliders ) { mVelY++; //Move the dot left or right mPosX += mVelX; shiftColliders(); //If the dot collided or went too far to the left or right if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) ) { if (!bulletsUp.empty()) { bulletsUp.pop_back(); } mVelY = 0; } //Move the dot up or down mPosY -= mVelY; shiftColliders(); //If the dot collided or went too far up or down if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) ) { if (!bulletsUp.empty()) { bulletsUp.pop_back(); mVelY = 0; } } }
void LevelPlaySelect::checkMouse(ImageManager &imageManager, SDL_Renderer &renderer){ int x,y; //Get the current mouse location. SDL_GetMouseState(&x,&y); //Check if we should replay the record. if(selectedNumber!=NULL){ SDL_Rect mouse={x,y,0,0}; if(!bestTimeFilePath.empty()){ SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-130,372,32}; if(checkCollision(box,mouse)){ Game::recordFile=bestTimeFilePath; levels->setCurrentLevel(selectedNumber->getNumber()); setNextState(STATE_GAME); return; } } if(!bestRecordingFilePath.empty()){ SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-98,372,32}; if(checkCollision(box,mouse)){ Game::recordFile=bestRecordingFilePath; levels->setCurrentLevel(selectedNumber->getNumber()); setNextState(STATE_GAME); return; } } } //Call the base method from the super class. LevelSelect::checkMouse(imageManager, renderer); }
void Enemy::move( std::vector<SDL_Rect>& otherColliders ) { mVelY++; //Move the dot left or right mPosX += mVelX; shiftColliders(); //If the dot collided or went too far to the left or right if( ( mPosX < 0 ) || ( mPosX + ENEMY_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) ) { //Move back POINTS +=100; mPosX = randomRange(0, SCREEN_WIDTH); mVelX = 0; shiftColliders(); } //Move the dot up or down mPosY += mVelY - mPosY/2; shiftColliders(); //If the dot collided or went too far up or down if( ( mPosY < 0 ) || ( mPosY + ENEMY_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) ) { //Move back POINTS +=100; mPosY = randomRange(0, SCREEN_HEIGHT); mVelY = 0; shiftColliders(); } }
void BallController::updateCollision(Grid* grid) { for (int i = 0; i < grid->_cells.size(); i++) { int x = i % grid->_numXCells; int y = i / grid->_numXCells; Cell* cell = grid->getCell(x, y); for (int j = 0; j < cell->balls.size(); j++) { Ball* ball = cell->balls[j]; checkCollision(ball, cell->balls, j+1); if (x > 0) { checkCollision(ball, grid->getCell(x - 1, y)->balls, 0); if (y > 0) { checkCollision(ball, grid->getCell(x-1,y-1)->balls, 0); } if (y < grid->_numYCells - 1) { checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0); } } if (y > 0) { checkCollision(ball, grid->getCell(x, y - 1)->balls, 0); } } } }
void Dot::move( SDL_Rect& wall ) { //Move the dot left or right mPosX += mVelX; mCollider.x = mPosX; //If the dot collided or went too far to the left or right if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mCollider, wall ) ) { //Move back mPosX -= mVelX; mCollider.x = mPosX; } //Move the dot up or down mPosY += mVelY; mCollider.y = mPosY; //If the dot collided or went too far up or down if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mCollider, wall ) ) { //Move back mPosY -= mVelY; mCollider.y = mPosY; } }
void CGame::collideShellsWithEnemies() { //get list of all plane shells std::list<std::unique_ptr<SDL_Rect>> *shells = plane.getShellsFired(); //iterate over enemies for (std::list<std::unique_ptr<CEnemy>>::iterator enemy = enemyList.begin(); enemy != enemyList.end(); enemy++) { //check if enemy is on screen, and is alive if (checkCollision(plane.getCamera(), (*enemy)->getBox()) && (*enemy)->isAlive()) { //iterate over plane shells for (std::list<std::unique_ptr<SDL_Rect>>::iterator shell = shells->begin(); shell != shells->end(); shell++) { SDL_Rect shell_rect = {(*shell)->x, (*shell)->y, (*shell)->w, (*shell)->h }; if (checkCollision(shell_rect, (*enemy)->getBox())) { shell->release(); shells->erase(shell++); if ((*enemy)->type == BRIDGE) { //if killed a bridge, set new starting pos SDL_Rect bridge = (*enemy)->getBox(); plane.setStartingPos(bridge.x + bridge.w / 2, bridge.y - bridge.h); updateScoreTexture(1000); } (*enemy)->kill(); updateScoreTexture(1000); break; } } } } }
void Dot::move( std::vector<SDL_Rect>& otherColliders ) { //Move the dot left or right mPosX += mVelX; shiftColliders(); //If the dot collided or went too far to the left or right if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) ) { //Move back mPosX -= mVelX; shiftColliders(); } //Move the dot up or down mPosY += mVelY; shiftColliders(); //If the dot collided or went too far up or down if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) ) { //Move back mPosY -= mVelY; shiftColliders(); } }
void getAdjacents(int i, int j, int* a) { a[0] = (checkCollision(i,j-1) == COLLISION_SOLID); a[1] = (checkCollision(i+1,j) == COLLISION_SOLID); a[2] = (checkCollision(i,j+1) == COLLISION_SOLID); a[3] = (checkCollision(i-1,j) == COLLISION_SOLID); }
void BallController::updateCollision(Grid* grid) { for (int i = 0; i < grid->m_cells.size(); i++) { int x = i % grid->m_numXCells; int y = i / grid->m_numXCells; Cell& cell = grid->m_cells[i]; // Loop through all balls in a cell for (int j = 0; j < cell.balls.size(); j++) { Ball* ball = cell.balls[j]; /// Update with the residing cell checkCollision(ball, cell.balls, j + 1); /// Update collision with neighbor cells if (x > 0) { // Left checkCollision(ball, grid->getCell(x - 1, y)->balls, 0); if (y > 0) { /// Top left checkCollision(ball, grid->getCell(x - 1, y - 1)->balls, 0); } if (y < grid->m_numYCells - 1) { // Bottom left checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0); } } // Up cell if (y > 0) { checkCollision(ball, grid->getCell(x, y - 1)->balls, 0); } } } }
void Bullet::enemyMove( std::vector<SDL_Rect>& otherColliders ) { mVelX++; mVelY++; //Move the dot left or right mPosX -= mVelX; shiftColliders(); //If the dot collided or went too far to the left or right if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH >= SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) ) { if (!enemyBullets.empty()) { enemyBullets.pop_back(); } } //Move the dot up or down mPosY += mVelY; shiftColliders(); //If the dot collided or went too far up or down if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT >= SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) ) { if (!enemyBullets.empty()) { enemyBullets.pop_back(); } } }
//Eat pac-dots and the power pallets void Pacman::eat() { for (unsigned int row = 0; row < map->size(); row++) { for (unsigned int col = 0; col < (*map)[row].size(); col++) { //Detect is it collided with the pac-dots //Add 100 score if true and erase the dot from the map if ((*map)[row][col] == "o") { if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) { Mix_PlayChannel(-1, sound_food, 0); (*map)[row][col] = " "; score += 100; return; } } //Detect is it collided with the power pallets //Add 500 score if true and erase the power palletes from the map if ((*map)[row][col] == "p") { if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) { Mix_PlayChannel(-1, sound_powerup, 0); (*map)[row][col] = " "; score += 500; setPowerUp(true); return; } } } } }
void Hero::motion( SDL_Rect rect ) { /* Dla kazdego warunku - jesli uzytkownik kliknal LEFT to postac porusza sie w lewo z okreslona predkoscia, itd... */ if( key[ SDL_SCANCODE_LEFT ] ) { if( x > 0 ) { x -= speed; } /* Dla kazdego warunku - jesli wystapila kolizja to cofa postac jeszcze przed wyrenderowaniem calej sytuacji */ if( checkCollision( rect ) ) { x += speed; } } else if( key[ SDL_SCANCODE_RIGHT ] ) { if( x < 800 - texture.getWidth() ) { x += speed; } if( checkCollision( rect ) ) { x -= speed; } } if( key[ SDL_SCANCODE_UP ] ) { if( y > 104 ) { y -= speed; } if( checkCollision( rect ) ) { y += speed; } } else if( key[ SDL_SCANCODE_DOWN ] ) { if( y < 600 - texture.getHeight() ) { y += speed; } if( checkCollision( rect ) ) { y -= speed; } } }
void LevelPlaySelect::render(ImageManager& imageManager, SDL_Renderer &renderer){ //First let the levelselect render. LevelSelect::render(imageManager,renderer); int x,y,dy=0; //Get the current mouse location. SDL_GetMouseState(&x,&y); if(levelScrollBar) dy=levelScrollBar->value; //Upper bound of levels we'd like to display. y+=dy*64; SDL_Rect mouse={x,y,0,0}; //Show currently selected level (if any) if(selectedNumber!=NULL){ selectedNumber->show(renderer, 0); levelInfoRender.render(renderer); //Only show the replay button if the level is completed (won). if(selectedNumber->getNumber()>=0 && selectedNumber->getNumber()<levels->getLevelCount()) { if(levels->getLevel(selectedNumber->getNumber())->won){ if(!bestTimeFilePath.empty()){ SDL_Rect r={0,0,32,32}; const SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-130,372,32}; if(checkCollision(box,mouse)){ r.x=32; SDL_SetRenderDrawColor(&renderer, 0xFF,0xCC,0xCC,0xCC); SDL_RenderDrawRect(&renderer, &box); } const SDL_Rect dstRect = {SCREEN_WIDTH-80,SCREEN_HEIGHT-130,r.w,r.h}; SDL_RenderCopy(&renderer,playButtonImage.get(),&r, &dstRect); } if(!bestRecordingFilePath.empty()){ SDL_Rect r={0,0,32,32}; const SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-98,372,32}; if(checkCollision(box,mouse)){ r.x=32; SDL_SetRenderDrawColor(&renderer, 0xFF,0xCC,0xCC,0xCC); SDL_RenderDrawRect(&renderer, &box); } const SDL_Rect dstRect = {SCREEN_WIDTH-80,SCREEN_HEIGHT-98,r.w,r.h}; SDL_RenderCopy(&renderer,playButtonImage.get(),&r, &dstRect); } } } } }
/* refresh pacmans position */ void refreshPacman(void) { checkCollision(); updatePacmanPosition(); updatePacmanMovement(); checkPacmanMovement(); addScores(); checkCollision(); }
//Método principal para atualização do game em tempo real void Game::gameUpdate(){ //Limite de Frame Rate gameWindow.setFramerateLimit(60); //Checa se algum dos players completou as 3 voltas isRaceOver(); //Verifica se a tecla ESC é pressionada, abrindo o menuPause renderPause(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) menuPause.abrirMenu(); //Toca a música que será reproduzida durante a corrida raceBGM.playMusic(); raceBGM.setVolume(100); //Ativa os métodos de entrada de keyboard para os controles de ambos os players player[0].ativarMovimentos(0); player[1].ativarMovimentos(1); //Checa todas as colisões possíveis dentro da partida para cada Player checkCollision(0); checkCollision(1); //Checa se os players estão no sentido correto da pista (caso eles percorram ao contrário), seus //carros explodirão player[0].checarSentido(); player[1].checarSentido(); //Checa durante a partida quando a linha de chegada é ultrapassada checkLap(); //Centralizando cada câmera em seu respectivo player player[0].centralizarCamera(); player[1].centralizarCamera(); //Renderizações na tela do Player1 gameWindow.setView(player[0].getCamera()); renderMap(); gameWindow.draw(player[0].getSprite()); gameWindow.draw(player[1].getSprite()); renderProjeteis(); renderGUI(0); //Renderizações na tela do Player 2 gameWindow.setView(player[1].getCamera()); renderMap(); gameWindow.draw(player[1].getSprite()); gameWindow.draw(player[0].getSprite()); renderProjeteis(); renderGUI(1); gameWindow.display(); gameWindow.clear(); }
bool CGame::standingOnCollapsingBridge(SDL_Rect A) { for (std::list<std::unique_ptr<CEnemy>>::iterator it = enemyList.begin(); it != enemyList.end(); it++) { //checks all bridges on screen, and returns whether A is standing on dead brigde if ((*it)->type == BRIDGE && checkCollision((*it)->getBox(), plane.getCamera()) && !(*it)->isAlive()) { return checkCollision(A, (*it)->getBox()); } } return false; }
/*********************************************************************** ; Name: checkCharHitChar ; Description: This function checks for collisions between the attack ; of one character and the position of another character. ; It doesn't matter which character calls the function, ; it performs correctly. ;***********************************************************************/ char checkCharHitChar(struct character *self, char attackx, char attacky, unsigned char attackw, unsigned char attackh) { char ret = 0; if (self->player == 0) { ret = checkCollision(attackx, attacky, attackw, attackh, player1.x, player1.y, player1.framew, player1.frameh); } else { ret = checkCollision(attackx, attacky, attackw, attackh, player0.x, player0.y, player0.framew, player0.frameh); } return ret; }
bool ShapeRay::checkCollision( ShapeRect const *const other ) const { // TODO: Do this properly (not with ray approximation ShapeRay bltr; bltr.pos = other->getCorner( diBOTTOMLEFT ); bltr.target = other->getCorner( diTOPRIGHT ); ShapeRay brtl; brtl.pos = other->getCorner( diBOTTOMRIGHT ); brtl.target = other->getCorner( diTOPLEFT ); if ( checkCollision( &bltr ) || checkCollision( &brtl ) ) return true; return false; }
void PlayState::update() { if (TheInputHandler::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE)) { TheGame::Instance()->getStateMachine()->pushState(new PauseState()); } for (int i = 0; i < m_gameObjects.size(); i++) { m_gameObjects[i]->update(); } //dynamic_cast<SDLGameObject*>(m_gameObjects[1])-> //if (m_gameObjects[0]->g); //dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getBullet()->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX()); //dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getVIBullet()[0]->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX()); //dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getPlay for (int i = 2; i < m_gameObjects.size(); i++) { if (checkCollision( dynamic_cast<SDLGameObject*>(m_gameObjects[1]), dynamic_cast<SDLGameObject*>(m_gameObjects[i]))) { std::string textureID = "bullet"; std::string typeID = "Bullet"; //pGameObject->load(new LoaderParams(x, y, width, height, textureID, numFrames, callbackID, animSpeed)); m_gameObjects.erase(m_gameObjects.begin() + i); //m_gameObjects.erase(m_gameObjects.begin() + 1); //GameObject* pGameObject = TheGameObjectFactory::Instance()->create(typeID); m_gameObjects[1] = TheGameObjectFactory::Instance()->create(typeID);; m_gameObjects[1]->load(new LoaderParams(200, 350, 21, 21, textureID, 1, 0, 1)); //m_gameObjects.push_back(pGameObject); //std::string _textID = "Bullet"; //(x, y, width, height, textureID, numFrames, callbackID, animSpeed)) //m_gameObjects[1]->load(LoaderParams(100, 100, 100, 100, _textID, 1, 0, 0)); //StateParser stateParser; //stateParser.parseState("text.xml", s_playID, &m_gameObjects, &m_textureIDList); } if (checkCollision( dynamic_cast<SDLGameObject*>(m_gameObjects[0]), dynamic_cast<SDLGameObject*>(m_gameObjects[i]))) { TheGame::Instance()->setState(State::GameOver); } } }
void Bomb::explode() { _explodeTime = Director::getInstance()->getTotalFrames(); _isFire = true; _isRemote = false; _tick = 9999; GameSounds::Instance().playSound(ES_BOMB, false); if (_player) { _player->explodeBomb(); _player = nullptr; } if (_brick) { _brick->explodeBomb(); _brick = nullptr; } animate(_sprite, FCENTER); checkCollision(_sprite); _fires.push_back(_sprite); for (auto p : sPoints) { for (int i = 1; i <= _size; i++) { FireType type = i == _size ? FTAIL : FBODY; auto sprite = Sprite::createWithSpriteFrameName(typeStr[type] + "_1.png"); sprite->setPosition(_sprite->getPosition() + p * i); Direction dir = pointToDir(p); if (dir == RIGHT) { sprite->setRotation(90); } else if (dir == LEFT) { sprite->setRotation(270); } else if (dir == DOWN) { sprite->setFlippedY(true); } animate(sprite, type); if (checkCollision(sprite)) break; _fires.push_back(sprite); addChild(sprite); } } }
void MyRect::move() { bool isColliding= checkCollision(); //move down if(isColliding==false){ if(pos().y()< 600){ setPos(x(),y()+30); //setPos(x(),600); //qDebug()<<"position change"; } else{ qDebug()<<"count:"<<count; points+=2; myGame.printText(QString("Nice 2 Points: "),700,count,1.5); myGame.printText(QString::number(points),900,count,1.5); count+=50; if(count>=500){ count=30; } isRowFilled(pos().y()+15); //qDebug()<<"rim"; time->stop(); myGame.spawn(); } } else if(pos().y() < 29 &&isColliding){ qDebug()<<"lose"; scene()->clear(); // scene()->removeItem(this); // delete this; QString yolo = QString ("You Lose"); myGame.printText(yolo,425,250,3); } else if(checkCollision()){ points+=2; myGame.printText(QString("Nice 2 Points: "),700,count,1.5); myGame.printText(QString::number(points),900,count,1.5); count+=50; if(count>=500){ count=30; } isRowFilled(pos().y()+15); qDebug()<<"spawning"; time->stop(); myGame.spawn(); } }
void Bullet::update(){ float deltaX = 0; float deltaY = 0; deltaX = sin(this->angle) * this->moveSpeed; deltaY = -cos(this->angle) * this->moveSpeed; if(!inShop){ if(this->playerShot){ for(int i = 0; i < MAX_ZOMBIES; i++){ if(zombieList[i] != NULL && zombieList[i]->checkActive()){ if(checkCollision(this->posX, this->posY, zombieList[i]->posX, zombieList[i]->posY, this->width, this->height, zombieList[i]->width, zombieList[i]->height)){ zombieList[i]->health -= this->damage; this->active = false; } } } }else{ if(checkCollision(this->posX, this->posY, playerCenterX, playerCenterY, this->width, this->height, playerWidth, playerHeight)){ playerHealth -= this->damage; this->active = false; } } if(isPassable(this->posX+deltaX, this->posY, this->width, this->height, deltaX, deltaY)){ this->posX += deltaX; }else{ this->active = false; } if(isPassable(this->posX, this->posY+deltaY, this->width, this->height, deltaX, deltaY)){ this->posY += deltaY; }else{ this->active = false; } }else{ if(this->posX+deltaX >= 0 && this->posX+deltaX + this->width < 400 && this->posY >= 0 && this->posY + this->height < 400){ this->posX += deltaX; }else{ this->active = false; } if(this->posX >= 0 && this->posX + this->width < 400 && this->posY+deltaY >= 0 && this->posY+deltaY + this->height < 400){ this->posY += deltaY; }else{ this->active = false; } } }
float Item::checkCollision(BaseObject* object, float dt) { auto collisionBody = (CollisionBody*)_listComponent["CollisionBody"]; auto objeciId = object->getId(); eDirection direction; if (collisionBody->checkCollision(object, direction, dt)) { if (objeciId == eID::LAND || objeciId == eID::BRIDGE) // => ?? { if (this->getVelocity().y > 0) return 0.0; if (direction == eDirection::TOP) { auto gravity = (Gravity*)this->_listComponent["Gravity"]; gravity->setStatus(eGravityStatus::SHALLOWED); gravity->setGravity(VECTOR2ZERO); auto move = (Movement*) this->_listComponent["Movement"]; move->setVelocity(VECTOR2ZERO); } } if (objeciId == eID::BILL) { this->setStatus(eStatus::DESTROY); ((Bill*)object)->changeBulletType(this->_type); } } return 0.0f; }
void Layer::handleCollisions() { std::vector<Projectile*>& pProjectiles = TheProjectileManager::Instance()->getProjectiles(); for (int i = 0; i < pProjectiles.size(); i++) { //Loop though all bullets for (int j = 0; j < mGameObjects.size(); j++) { SDLGameObject* object = dynamic_cast<SDLGameObject*>(mGameObjects.at(j)); if ((pProjectiles.at(i))->getTag() != object->getTag()) { if (checkCollision(pProjectiles.at(i), object)) { TheProjectileManager::Instance()->destroyProjectile(pProjectiles.at(i)); dynamic_cast<Ship*>(object)->damage(1); if (!dynamic_cast<Ship*>(object)->isAlive()) { //Ship is dead dynamic_cast<Ship*>(object)->clean(); delete object; mGameObjects.erase(mGameObjects.begin() + j); j--; } } } } } }
/* Hard drop */ static void dropTetromino(StcGame *game) { #ifdef STC_SHOW_GHOST_PIECE /* Shadow has already calculated the landing position. */ game->fallingBlock.y += game->shadowGap; /* Force lock. */ moveTetromino(game, 0, 1); /* Update score */ if (game->showShadow) { game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) / SCORE_DROP_WITH_SHADOW_DIVISOR); } else { game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) / SCORE_DROP_DIVISOR); } #else int y = 0; /* Calculate number of cells to drop */ while (!checkCollision(game, 0, ++y)); moveTetromino(game, 0, y - 1); moveTetromino(game, 0, 1); /* Force lock */ /* Update score */ game->stats.score += (long)(SCORE_2_FILLED_ROW * (game->stats.level + 1) / SCORE_DROP_DIVISOR); #endif }
bool Player::touchesLevelObject(SDL_Rect box, std::list <LevelObject> levelObjects) { std::list<LevelObject>::iterator it = levelObjects.begin(); while (it != levelObjects.end()) { if (it->Type() == LevelObjectType::PLATFORM) { if ((box.y + 4) <= it->LevelObjectBox().y) { if (checkCollision(box, it->LevelObjectBox())) { if (it->Flip()) playerBox.x -= 1; else if (!it->Flip()) playerBox.x += 1; return true; } } } it++; } return false; }
void Robot::update(int deltaTime) { Vector3 v = velocity * float(deltaTime); translate(v); if (!checkCollision()) { translate(-v); setRandDirection(); } if (shotCooldown) { shotTimer += deltaTime; if (shotTimer >= shotTimerMax) { shotTimer = 0; shotCooldown = false; } } Room * playerRoom = Game::instance->roomAt(Game::instance->player->getWorldPos()); Room * room = Game::instance->roomAt(getWorldPos()); if (playerRoom == room) { Vector3 dir = Game::instance->player->getWorldPos() - getWorldPos(); float ang = atan2f(dir.z, dir.x); ang *= (1.0f / DEG2RAD); setRotation(Vector3(0, -ang + 90, 0)); if (!shotCooldown) { spawnBullet(); shotCooldown = true; } } }
void gameClass::moveProjectiles(float deltaTime) { for (int i = 0; i < projectiles.size(); i++) { int dirX, dirY; projectiles[i].getDirection(dirX, dirY); glm::vec2 oldPos = projectiles[i].tile.getPos(); float velocity = projectiles[i].getSpeed() * deltaTime; glm::vec2 newPos = { velocity * dirX, velocity * dirY }; projectiles[i].tile.adjustPos(newPos); bool eraseFlag = false; *activeProjectile = projectiles[i]; if (checkCollision(activeProjectile, eraseFlag) || !projectiles[i].tile.isOnScreen(renderingPort)) { projectiles.erase(projectiles.begin() + i); } else { projectiles[i].increaseAnimationTime(deltaTime); if (projectiles[i].getAnimationTime() >= Constants::animationFrameTime) { projectiles[i].increaseIndex(); projectiles[i].resetAnimationTime(); } } } }
void cubiverse::VoxelEditor::render(float playerX, float playerY, float playerZ) { //Zeichne einen Kreis float x = 0.0f; float z = 0.0f; float radius = 10.0f; glBegin(GL_POLYGON); for( double theta = 0.0; theta < M_PI; theta += M_PI / 360.0 ) { x = ( cos( theta ) * radius ); z = ( sin( theta ) * radius); glVertex3f( x, 20.0f, z ); } vaEngine::Vector coll = checkCollision(playerX, playerY, playerZ); //if(coll->y != playerY) { // Cube::pointer_t newCube = boost::make_shared<Cube>(1); // voxels[0][make_pair(coll->x,make_pair(coll->y,coll->z))] = newCube; //} //Und dann die Meshs //for(int mesh = 0; mesh < meshs.size(); mesh++) //meshs[mesh]->render(); //if(coll->y != playerY) { // delVoxel(coll->x, coll->y, coll->z, 0); //} }
const std::vector<BoundingShape*> CollisionDetect::checkAgainstGroup( BoundingShape* bounding, const std::string& group ) { // the list of boundings collisions are occurring with std::vector<BoundingShape*> collisions; // iterate over detectors in the group for ( std::vector<CollisionDetector*>::iterator detector = m_groups[group].begin(); detector != m_groups[group].end(); ++detector ) { // iterate over the boundings in the detector for ( std::vector<std::unique_ptr<BoundingShape>>::iterator bd = (*detector)->m_boundings.begin(); bd != (*detector)->m_boundings.end(); ++bd ) { // check collision if ( checkCollision( bounding, bd->get() ) ) { // a collision was found, record it in the list collisions.push_back( bd->get() ); } } } return collisions; }