void checkCollisions() { for (int i=0;i<bullets.size();++i) { if (isCollidingWith(bullets[i])) { bullets[i].isActive = false; this->isActive = false; } } if (isCollidingWith(player)) { player->isActive = false; } }
void checkCollisions() { for (int i=0;i<bullets.size();++i) { if (isCollidingWith(bullets[i])) { sfxs.push_back(new BulletPop(bullets[i].x, bullets[i].y)); bullets[i].isActive = false; this->isActive = false; } } if (isCollidingWith(player)) { player->isActive = false; } }
void monster::doCollision(Entity* pOther) { /* read type of Entity. * if enemy/powerup: * return * if friendly: (i.e. bad for monsters) * find out if collision * if true, call reactToCollision on both Entities */ switch(pOther->getType()) { case RT_FRIENDLY: // hero ship and bullets are "friendly" { if (isCollidingWith(pOther)) { this->reactToCollision(pOther); pOther->reactToCollision(this); } }break; case RT_POWERUP: case RT_ENEMY: case RT_NEUTRAL: default: { return; } } }
void Hero::doCollision(Entity* pOther) { /* read type of Entity. * if neutral/friend: * return * if enemy/powerup: * find out if collision * if true, call reactToCollision on both Entities */ switch(pOther->getType()) { case RT_ENEMY: case RT_POWERUP: { if (isCollidingWith(pOther)) { this->reactToCollision(pOther); pOther->reactToCollision(this); } }break; case RT_FRIENDLY: case RT_NEUTRAL: default: { return; } } }
void FlyingEnemy::update() { if(!dead) { buddy->move(getX() - level->getXOffs(), getY() - level->getYOffs()); if(dir == -1) { //If going left if(level->testCollision(getX() - 1, getY())) { dir = 1; } } else if(dir == 1) { //If going right if(level->testCollision(getX() + Entity::SIZE + 1, getY())) { dir = -1; } } addX(hSpeed * dir); Player* p = level->getPlayer(); if(isCollidingWith(p)) { QRect test(getX(), getY(), getWidth(), 32); if(p->isInvincible() || test.contains(p->getX(), p->getY() + p->getHeight()) || test.contains(p->getX() + p->getWidth(), p->getY() + p->getHeight())) { Network::instance().send("Enemy " + QString::number(id)); dead = true; p->setVib(true); } else { p->setDead(true); } } if(dir == 1) { buddy->setPixmap(feRight); } else if(dir == -1) { buddy->setPixmap(feLeft); } } else { if(curHeight > 8) { curHeight -= 8; buddy->setGeometry(getX() + (Entity::SIZE / 2 - curHeight / 2) - level->getXOffs(), getY() + (Entity::SIZE / 2 - curHeight / 2) - level->getYOffs(), curHeight, curHeight); } else { Sound::instance().killedEnemy(); buddy->deleteLater(); level->removeEntity(this); } } }
void Collectible::update() { if(!removing) { if(buddy) buddy->move(getX() - level->getXOffs(), getY() - level->getYOffs()); if(isCollidingWith(level->getPlayer())) { removing = true; Network::instance().send("Collectible " + QString::number(getX()) + " " + QString::number(getY())); Sound::instance().collect(); ScoreManager::instance().addToScore(pointPlus); } } else { if(curSize < maxSize) { curSize += 8; buddy->setGeometry(getX() + (Entity::SIZE / 2 - curSize / 2) - level->getXOffs(), getY() + (Entity::SIZE / 2 - curSize / 2) - level->getYOffs(), curSize, curSize); } else { deleteCollectible(); } } }
void Bullet::doCollision(Entity* pOther) { switch(pOther->getType()) { case RT_ENEMY: { if (isCollidingWith(pOther)) { this->reactToCollision(pOther); pOther->reactToCollision(this); } }break; case RT_POWERUP: //JG TODO: should bullets interact with powerups? case RT_FRIENDLY: case RT_NEUTRAL: default: { return; } } }