static void CreateArmy(std::vector<Alien> &aliens, const ISprite& alien1, const ISprite& alien2){ for (int i = 0; i < 4; i++){//row for (int j = 0; j < 8; j++){//col if (i<2) aliens.push_back(Alien(Vec2f(j * 64, i * 64),alien2)); else aliens.push_back(Alien(Vec2f(j * 64, i * 64), alien1)); } } }
void TitleState::logic() { //Move or remove aliens for(std::list<Alien>::iterator itAlien = activeAliens.begin(); itAlien != activeAliens.end(); ++itAlien) { if(itAlien->getXPos() < 0 || itAlien->getXPos() > SCREEN_WIDTH || itAlien->getYPos() < 0 || itAlien->getYPos() > SCREEN_HEIGHT) { itAlien = activeAliens.erase(itAlien); --itAlien; } else { itAlien->move(0, 2); } } ticksUntilNextAlien--; if(ticksUntilNextAlien == 0) { activeAliens.push_back(Alien(20, 0)); activeAliens.push_back(Alien(60, 0)); activeAliens.push_back(Alien(SCREEN_WIDTH - 20, 0)); activeAliens.push_back(Alien(SCREEN_WIDTH - 60, 0)); ticksUntilNextAlien = ALIEN_TICK_INTERVAL; } }
void ConjAliens::init(int niv) { srand(time(NULL)); dir_actual = DRE; dir_actualitzada = DRE; dir_anterior = NO; for (int i = 0; i < COLUMNES; i++) for (int j = 0; j < FILES; j++) aliens[i][j] = Alien(game, sf::Vector2f(30 + i * SIZE_COLUMNA, 10 + j * SIZE_FILA), j); position = sf::Vector2f(20, 10); spriteActual = 0; contadorCanviSprite = 0; contadorAvall = 0; speedMult = 1.0f + 0.2f * (niv - 1); num_aliens = COLUMNES * FILES; }
void MainState::logic() { ship.updatePosition(); //Erase any bullet that is not on screen, or move them is they are on screen for(std::list<Bullet>::iterator itBullet = activeBullets.begin(); itBullet != activeBullets.end(); ++itBullet) { if(itBullet->getXPos() < 0 || itBullet->getXPos() > SCREEN_WIDTH || itBullet->getYPos() < 0 || itBullet->getYPos() > SCREEN_HEIGHT) { itBullet = activeBullets.erase(itBullet); --itBullet; } else { itBullet->move(0, -20); } } //Move or remove aliens for(std::list<Alien>::iterator itAlien = activeAliens.begin(); itAlien != activeAliens.end(); ++itAlien) { if(itAlien->getXPos() < 0 || itAlien->getXPos() > SCREEN_WIDTH || itAlien->getYPos() < 0 || itAlien->getYPos() > SCREEN_HEIGHT) { itAlien = activeAliens.erase(itAlien); --itAlien; } else { itAlien->move(0, 2); for(std::list<Bullet>::iterator itBullet = activeBullets.begin(); itBullet != activeBullets.end(); ++itBullet) { if(itAlien->collidesWith(*itBullet)) { itAlien->takeDamage(10); itBullet = activeBullets.erase(itBullet); --itBullet; } } if(itAlien->getCurrentHP() <= 0) { itAlien = activeAliens.erase(itAlien); --itAlien; } } } for(std::list<Star>::iterator it = activeStars.begin(); it != activeStars.end(); ++it) { if(it->getYPos() > SCREEN_HEIGHT) { it = activeStars.erase(it); --it; } else { it->move(0, 1); } } //Spawn new aliens if the time is right ticksUntilNextAlien--; if(ticksUntilNextAlien == 0) { int numAliens = (rand() % 3) + 1; for(int i = 0; i < numAliens; i++) { activeAliens.push_back(Alien((rand() % (SCREEN_WIDTH - 20) + 20), 30)); } ticksUntilNextAlien = ALIEN_TICK_INTERVAL; } ticksUntilNextStar--; if(ticksUntilNextStar == 0) { activeStars.push_back(Star()); //std::cout << activeStars.size() << std::endl; ticksUntilNextStar = STAR_TICK_INTERVAL; } }
void Aliens::addAlien() { aliens_.push_back(Alien()); }
Alien Alien::getAlien(Game * g){ return Alien(*g); }