iMovingObject* csBlobManager::CheckCollision (iMovingObject* b) { int layer = b->GetLayer (); iBlobViewPort* vp = b->GetViewPort (); if (vp) { csBlobViewPort* viewport = static_cast<csBlobViewPort*> (vp); for (size_t i = 0 ; i < viewport->objects.GetSize () ; i++) { iMovingObject* o = viewport->objects.Get (i); if (o != b && o->GetLayer () == layer && CheckCollision (b, o)) return o; } } else { for (size_t i = 0 ; i < movingobjects[layer].GetSize () ; i++) { iMovingObject* o = movingobjects[layer].Get (i); if (o != b && o->GetViewPort () == 0 && CheckCollision (b, o)) return o; } } return 0; }
/* Checks if the ball hit a wall or a goal post. * In case it did the ball will bounce off. * The parameter is the future positions of the * center of the ball. It's used to check the collision * with the goal posts. */ void Game::WallHitCheck(){ Point2d ball_pos = ball->GetObject()->axiscenter; // Collision with the ball if (ball_pos.x - BALL_CIRCLE_RAY <= Field::LEFTUCORNER.x + Field::LINE_WIDTH || ball_pos.x + BALL_CIRCLE_RAY >= Field::RIGHTUCORNER.x){ deltax *= -1; m_team_last = -1; m_player_last = -1; } else if (ball_pos.y + BALL_CIRCLE_RAY >= Field::RIGHTUCORNER.y || ball_pos.y - BALL_CIRCLE_RAY <= Field::RIGHTLCORNER.y + Field::LINE_WIDTH){ deltay *= -1; m_team_last = -1; m_player_last = -1; } Point2d ball_center(ball_pos.x + SPEED * deltax * m_dt, ball_pos.y + SPEED * deltay * m_dt); // Collision with one of the goal posts if (CheckCollision(ball_center, Field::UP_MIDDLE_LEFT) > 0 || CheckCollision(ball_center, Field::UP_MIDDLE_RIGHT) > 0 || CheckCollision(ball_center, Field::BOTTOM_MIDDLE_LEFT) > 0 || CheckCollision(ball_center, Field::BOTTOM_MIDDLE_RIGHT) > 0) { deltay *= -1; m_team_last = -1; m_player_last = -1; } }
void AMobileEnemy::Tick(float DeltaSeconds) { DeltaSeconds = TimeManager::Instance()->GetDeltaTime(DeltaSeconds); m_lastPosition = GetActorLocation(); m_nextPosition = m_lastPosition; EnemyAnimationMesh->bPauseAnims = TimeManager::Instance()->IsPaused(); if (!m_player) { for (TActorIterator< APawn > ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (ActorItr->ActorHasTag("Player")) { m_player = (APlayerOvi*)*ActorItr; m_jumpSpeed = m_player->JumpSpeed; m_accelerationJump = m_player->AccelerationJump; break; } } } m_tickCounter++; if (!HasTrigger || (HasTrigger && m_initMovement)) { CheckCollision(); doMovement(DeltaSeconds); CalculateGravity(DeltaSeconds); CheckCollision(); SetActorLocation(m_nextPosition); } }
int CollisionResult() { // collision with bad shroom if ( CheckCollision(&g_hippy, &g_shroom) || CheckCollision(&g_hippy, &g_fireBall) ) { g_lives--; if (g_lives < 0) { //ham_DeleteObj(g_hippy.sprite); //ham_DeleteObj(g_shroom.sprite); return 1; } else { // set life counter frame ham_UpdateObjGfx(g_lifeCount.sprite, (void *)&lives_bitmap[g_lifeCount.w * g_lifeCount.h * g_lives]); return -1; } } // collision with key shroom if ( CheckCollision(&g_hippy, &g_key) ) { ham_DeleteObj(g_hippy.sprite); ham_DeleteObj(g_shroom.sprite); ham_DeleteObj(g_key.sprite); ham_DeleteObj(g_fireBall.sprite); return 3; } return 0; }
void Animal::Move(World &world) { if (m_isAlive) { m_vitesse.x = 0.05; m_vitesse.z = 0.05; if (m_ClockTarget.getElapsedTime().asSeconds() < m_timeNextTarget) { Vector3<float> deplacementVector = Vector3<float>(sin(m_HorizontalRot / 180 * PI), 0.f, cos(m_HorizontalRot / 180 * PI)); deplacementVector.Normalize(); //Avance en x m_pos.x += deplacementVector.x * m_vitesse.x; if (CheckCollision(world)) { m_pos.x -= deplacementVector.x * m_vitesse.x; Jump(); } //En z m_pos.z += deplacementVector.z * m_vitesse.z; if (CheckCollision(world)) { m_pos.z -= deplacementVector.z * m_vitesse.z; Jump(); } } else { m_HorizontalRot += rand() % 200 - 100; m_timeNextTarget = rand() % 10; m_ClockTarget.restart(); } //Chute m_pos.y -= m_vitesse.y; //Si collision if (CheckCollision(world)) { //Si on a touche le sol if (m_vitesse.y > 0) m_isInAir = false; //annule m_pos.y += m_vitesse.y; m_vitesse.y = 0; } else m_isInAir = true; //Acceleration m_vitesse.y += 0.013f; } }
void CCollision::SpellCollision(CMap *MapPointer,CEntityManager *EntityPointer,CSpell *SpellPointer) { if (MapPointer->m_spell.empty()) return; for (int i = MapPointer->m_spell.size()-1; i >= 0; i--) { // check if player was hit by a spell if (CheckCollision((int)MapPointer->m_playerX,(int)MapPointer->m_playerY,(int)MapPointer->m_spell[i].x,(int)MapPointer->m_spell[i].y,TILE_SIZE)) { // check to see if the spell was not created by player if (MapPointer->m_spell[i].parent != -1) { // spell casted by enemy int hp = EntityPointer->m_pPlayer->GetHP(); int mp = EntityPointer->m_pPlayer->GetMP(); SpellPointer->SpellHit(MapPointer->m_spell[i].imgID,MapPointer->m_spell[i].lvl,hp,mp); EntityPointer->m_pPlayer->SetHP(hp); EntityPointer->m_pPlayer->SetMP(mp); MapPointer->m_spell.erase(MapPointer->m_spell.begin()+i); continue; } } //checking if an enemy has been hit by a spell for (size_t j = 0; j < MapPointer->m_closeEnemyXY.size(); j++) { if (CheckCollision((int)MapPointer->m_closeEnemyXY[j].x,(int)MapPointer->m_closeEnemyXY[j].y,(int)MapPointer->m_spell[i].x,(int)MapPointer->m_spell[i].y,TILE_SIZE)) { int hp = EntityPointer->m_VCloseEnemy[j].GetHP(); int mp = EntityPointer->m_VCloseEnemy[j].GetMP(); if (MapPointer->m_spell[i].parent == -1) { // spell casted by player SpellPointer->SpellHit(MapPointer->m_spell[i].imgID,MapPointer->m_spell[i].lvl,hp,mp); } EntityPointer->m_VCloseEnemy[j].SetHP(hp); EntityPointer->m_VCloseEnemy[j].SetMP(mp); // enemies created on map must be created in the same order in EntityManager so that the same index can be used to access both MapPointer->m_spell.erase(MapPointer->m_spell.begin()+i); break; } } } }
//handles collision for missiles and player bool CollisionManager::PlayerMissileCollision(Player& player, EnemyMissile& missile, Explosions& explosion) { for (unsigned int i = 0; i < missile.missiles.size(); i++) { if (CheckCollision(player.box_1, missile.missiles[i]->box) || CheckCollision(player.box_2, missile.missiles[i]->box)) { explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2); missile.missiles[i]->isAlive = false; return true; } } return false; }
bool CollisionManager::EnemyBulletCollisions(Enemy1Bullet& bullet, Player& player, Explosions& explosion) { //loop through the enemy bullet vector to check if any hit the player //if the player is hit destroy the bullet and decrease player health by 1 for (unsigned int i = 0; i < bullet.enemyBullets.size(); i++) { if (CheckCollision(bullet.enemyBullets[i]->box, player.box_1) || CheckCollision(bullet.enemyBullets[i]->box, player.box_2)) { explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2); //this will play an explosion on the player when it gets hit bullet.enemyBullets[i]->isAlive = false; return true; } } return false; }
void CBaseGolem::Update(float fDT) { CBaseEntity::Update(fDT); /*if( GetFlag_prev_MovementState() == FLAG_MOVESTATE_MOVING) { if(this->GetFlag_MovementState() == FLAG_MOVESTATE_ATDESTINATION) { int objectID = MObjectManager::GetInstance()->FindLayer( this->m_nIdentificationNumber ).GetFlake( OBJECT_OBJECT ).GetInfoAtIndex( GetIndexPosX() , GetIndexPosY() ) ; IUnitInterface* object = (MObjectManager::GetInstance()->GetUnit(objectID)) ; CheckCollision( object , true ); } }*/ if(( GetDistanceLeft() <= 32 && GetDistanceLeft() >= 30 ) || (GetDistanceLeft() <= 16 && GetDistanceLeft() >= 14 ) ) CSGD_FModManager::GetInstance()->PlaySound2D( m_nStepSoundID, CGamePlayState::GetInstance()->testVaribale, this->m_nIdentificationNumber) ; //UpdateAI(); if( LastDistance > 0.0f && GetDistanceLeft() < 0.1f ) { CheckCollision( MObjectManager::GetInstance()->GetUnit( MObjectManager::GetInstance()->FindLayer( m_nIdentificationNumber ).GetFlake( OBJECT_OBJECT ).GetInfoAtIndex( GetIndexPosX(), GetIndexPosY() ) ), true ); } LastDistance = GetDistanceLeft(); }
void GuiItem::Update(GuiElement* hover, GuiElement* focus) { //If there's no dragged_item, when clicking over the item, it's freed from the inventory if (!(App->gui->dragged_item)) { if (CheckCollision(App->input->GetMousePosition())) { //Feedback :D inventory->SetSlotsState(this, GREEN); mousehover = true; if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN) { inventory->FreeItem(this); } } else mousehover = false; } if (App->gui->dragged_item == this) { mousehover = false; } }
void UNIT::Update(float deltaTime) { //update unit animation time m_time += deltaTime * 0.8f * m_speed; //if the unit is moving... if(m_moving) { if(m_movePrc < 1.0f)m_movePrc += deltaTime * m_speed; if(m_movePrc > 1.0f)m_movePrc = 1.0f; //waypoint reached if(m_movePrc == 1.0f) { if(m_activeWP + 1 >= (int)m_path.size()) //goal reached { m_moving = false; SetAnimation("Still"); } else if(!CheckCollision(m_path[m_activeWP + 1])) //Next Waypoint { m_activeWP++; SetAnimation("Run"); MoveUnit(m_path[m_activeWP]); } } //Interpolate position between m_lastWP and m_nextWP m_position = m_lastWP * (1.0f - m_movePrc) + m_nextWP * m_movePrc; } }
bool CollisionManager::PlayerEnemyCollisions(EnemyShip1& enemy, Player& player, Explosions& explosion) { //check if the enemy and player collide //if they do, destroy the enemy and decrease player health for (unsigned int i = 0; i < enemy.enemies.size(); i++) { if (CheckCollision(player.box_1, enemy.enemies[i]->box_1) || CheckCollision(player.box_1, enemy.enemies[i]->box_2) || CheckCollision(player.box_2, enemy.enemies[i]->box_1) || CheckCollision(player.box_2, enemy.enemies[i]->box_2)) { explosion.ExplosionHandler(enemy.enemies[i]->box.x, enemy.enemies[i]->box.y, 1);//add an explosion when an enemy dies explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2); enemy.enemies[i]->isAlive = false; return true; } } return false; }
int CMonsterClubB1::DoAction(/*CScreen* scr, */IObjectManager* objMan) { mYMove= (CGTimer::Time()-oldmove)*mSpeed; oldmove=CGTimer::Time(); int i = CheckCollision(objMan); if(mJumpDirect==1) { if (GetBit(i,2)==1) { mJumpDirect=0; } else mYPos=mYPos-mYMove; } if(mJumpDirect==0) { if (GetBit(i,3)==1) { return -1; } else mYPos=mYPos+mYMove; } NextFrame(); return 1; }
// Update the skeleton transforms based on the dragger. void IvObjectDragger::UpdateSkeleton() { ItemPtr selectedItem = GetSelectedItem(); if( !selectedItem ) { return; } RaveTransform<float> tbox; const float* q = _transformBox->rotation.getValue().getValue(); tbox.rot = Vector(q[3], q[0], q[1], q[2]); SbVec3f v = _transformBox->translation.getValue(); tbox.trans = Vector(v[0], v[1], v[2]); Transform told; told.trans = -_ab.pos; RaveTransform<float> tnew = tbox*told*_toffset; SetSoTransform(selectedItem->GetIvTransform(), tnew); KinBodyItemPtr pbody = boost::dynamic_pointer_cast<KinBodyItem>(selectedItem); if( !!pbody ) { pbody->UpdateFromIv(); CheckCollision(_checkCollision); } // other motion handler calls _viewer.lock()->_UpdateCameraTransform(0); }
void CPartSnowFlake::Think( float flTime ) { if( m_flBrightness < 130.0 && !m_bTouched ) m_flBrightness += 4.5; Fade( flTime ); Spin( flTime ); if( m_flSpiralTime <= gEngfuncs.GetClientTime() ) { m_bSpiral = !m_bSpiral; m_flSpiralTime = gEngfuncs.GetClientTime() + UTIL_RandomLong( 2, 4 ); } else { } if( m_bSpiral && !m_bTouched ) { const float flDelta = flTime - g_Environment.GetOldTime(); const float flSpin = sin( flTime * 5.0 + reinterpret_cast<int>( this ) ); m_vOrigin = m_vOrigin + m_vVelocity * flDelta; m_vOrigin.x += ( flSpin * flSpin ) * 0.3; } else { CalculateVelocity( flTime ); } CheckCollision( flTime ); }
int RTPSources::GetRTCPSourceData(uint32_t ssrc, const RTPAddress *senderaddress, RTPInternalSourceData **srcdat2, bool *newsource) { int status; bool created; RTPInternalSourceData *srcdat; *srcdat2 = 0; if ((status = ObtainSourceDataInstance(ssrc, &srcdat, &created)) < 0) return status; if (created) { if ((status = srcdat->SetRTCPDataAddress(senderaddress)) < 0) return status; } else // got a previously existing source { if (CheckCollision(srcdat, senderaddress, false)) return 0; // ignore packet on collision } *srcdat2 = srcdat; *newsource = created; return 0; }
void UpdateContent(LevelContent* m_content,SDL_Rect camera) { for (unsigned int i = 0; i < m_content->ennemies.size(); ++i) { m_content->ennemies.at(i).Update(m_content->tileMap); for (unsigned int j = 0; j < m_content->bullets.size(); ++j) { if (CheckCollision(m_content->ennemies.at(i).GetRect(), m_content->bullets.at(j).GetRect())) { m_content->bullets.erase(m_content->bullets.begin() + j); m_content->ennemies.erase(m_content->ennemies.begin() + i); break; } } } for (unsigned int i = 0; i < m_content->items.size(); ++i) { if (isOutScreen(camera, m_content->items.at(i).GetRect())) m_content->items.erase(m_content->items.begin() + i); else m_content->items.at(i).Update(m_content->tileMap); } for (unsigned int j = 0; j < m_content->bullets.size(); ++j) { m_content->bullets.at(j).Update(m_content->tileMap); if (m_content->bullets.at(j).isEnd() || isOutScreen(camera, m_content->bullets.at(j).GetRect())) m_content->bullets.erase(m_content->bullets.begin() + j); } }
/** \param fDeltaTime: time since last Update */ void Player::Update(shoot::f32 fDeltaTime) { super::Update(fDeltaTime); bool bRightPressed = shoot::InputManager::Instance()->IsKeyPressed(shoot::InputManager::KT_Right); bool bLeftPressed = shoot::InputManager::Instance()->IsKeyPressed(shoot::InputManager::KT_Left); if(bRightPressed) { m_vVelocity = m_vSlidingDirection*m_fAcceleration; } else if(bLeftPressed) { m_vVelocity = m_vSlidingDirection*-m_fAcceleration; } bool bWasInTheAir = IsInTheAir(); if(bWasInTheAir) { m_vVelocity.Y += m_fGravity; } if(IsInTheAir() || (bRightPressed || bLeftPressed)) { CheckCollision(m_vPosition, m_vVelocity, m_vPosition, m_vVelocity); if(bWasInTheAir && !IsInTheAir()) { shoot::Print("*** bWasInTheAir && !IsInTheAir()\n"); } m_vPosition += m_vVelocity; } }
void UNIT::Goto(INTPOINT mp) { if(m_pTerrain == NULL)return; //Clear old path m_path.clear(); m_activeWP = 0; if(m_moving) //If unit is currently moving { //Finish the active waypoint m_path.push_back(m_mappos); std::vector<INTPOINT> tmpPath = m_pTerrain->GetPath(m_mappos, mp); //add new path for(int i=0;i<(int)tmpPath.size();i++) m_path.push_back(tmpPath[i]); } else //Create new path from scratch... { m_path = m_pTerrain->GetPath(m_mappos, mp); if(m_path.size() > 0) //if a path was found { m_moving = true; //Check that the next tile is free if(!CheckCollision(m_path[m_activeWP])) { MoveUnit(m_path[m_activeWP]); SetAnimation("Run"); } } } }
void BlockControl::HandleDown(const Uint8 *state, float frame_time, std::vector<Square> board_squares) { if (!CheckCollision(current_block.block_squares, Block::DOWN, board_squares)) { if (state[SDL_SCANCODE_DOWN]) { velocity = 120; } if (!state[SDL_SCANCODE_DOWN]) { if (velocity == 120) { velocity = 60; } } } }
/** * Moves the current piece to the left. */ void TetraminoesManager::InnerData::MoveLeft() { int aux = pieceX; pieceX--; if(CheckCollision()) { pieceX = aux; } }
void EnemyBase::Update() { if(isAlive) { Move(); CheckCollision(); } }
// 임의 위치 선택 함수 struct Position PickARandPos() { struct Position pos; while(1) { pos.x = rand()%columns_of_map; pos.y = rand()%rows_of_map; if(CheckCollision(&pos) == FLOOR) return pos; } }
void Player::CheckEnemyCollision(Enemy& e) { if (e.IsSpawned() && !e.IsDying() && CheckCollision(&e)) { ApplyDamage(e.GetContactDamage()); e.SetHasCollidedWithPlayer(true); //_collidedWithPlayer = true; } }
void Player::update(sf::Time timeElasped){ keyboardInput(timeElasped); genAnimFrame(timeElasped); CheckCollision(timeElasped); m_Position.x += m_Velocity.x * timeElasped.asSeconds(); m_Position.y += m_Velocity.y * timeElasped.asSeconds(); m_Sprite->setPosition(m_Position); }
bool CollisionManager::EnemyCollisions(EnemyShip1& enemy, Bullet& bullet, Explosions& explosion) { //loop through the enemy and player bullet vectors and check for the collision //if there is a collision then destroy the bullet and enemy for(unsigned int i = 0; i < enemy.enemies.size(); i++) { for(unsigned int j = 0; j < bullet.bullets.size(); j++) { if (CheckCollision(enemy.enemies[i]->box_1, bullet.bullets[j]->box) || CheckCollision(enemy.enemies[i]->box_2, bullet.bullets[j]->box)) { explosion.ExplosionHandler(enemy.enemies[i]->box.x, enemy.enemies[i]->box.y, 1); //add an explosion when an enemy dies enemy.enemies[i]->isAlive = false; bullet.bullets[j]->isAlive = false; return true; } } } return false; }
void MainLoop() { DrawWindow(); wrefresh(win); wrefresh(status); usleep(1000000); do { MovePacman(); DrawWindow(); CheckCollision(); MoveGhosts(); DrawWindow(); CheckCollision(); if(Points > FreeLife) { Lives++; FreeLife *= 2;} Delay(); } while (Food > 0); DrawWindow(); usleep(1000000); }
void Projectile::Logic() { Position.x() += speed * sinf(heading); Position.y() -= speed * cosf(heading); if (fadetimeout < SDL_GetTicks() && a > 0) { a -= 0.15; fadetimeout = SDL_GetTicks()+offset; } if (a <= 0 || CheckCollision()) isAlive = false; }
void World::Update(float dt) { if(mActive == true) { UpdateGameObjects(dt); SpawnEnemies(dt); FireBullets(); CheckCollision(); } }
void BlockControl::HandleUp(SDL_Renderer* ren, const Uint8* state, std::vector<Square> board_squares) { // Before attempting to rotate, we check for collision in any direction // for the block in it's current state. if (state[SDL_SCANCODE_UP] && !CheckCollision(current_block.block_squares, Block::UP, board_squares) && !CheckCollision(current_block.block_squares, Block::DOWN, board_squares) && !CheckCollision(current_block.block_squares, Block::LEFT, board_squares) && !CheckCollision(current_block.block_squares, Block::RIGHT, board_squares)) { Rotate(ren, board_squares); time_updated = game_timer.GetTimeSeconds(); } }