void updateBulletPool(BulletPool *bp){ int i; for (i = 0; i < 5; i++) { if (bp->particles_[i]->inUse == 1 && bp->particles_[i]->explosion_counter == 0){ moveBullet(bp->particles_[i]); if(checkScreenCollision(bp->particles_[i])){ bp->particles_[i]->inUse = 0; bp->particles_[i]->explosion_counter = 1; bp->particles_[i]->bullet_exp = loadBitmap("/home/lcom/Tanks/res/Spark1.bmp"); } } else if(bp->particles_[i]->inUse == 0 && bp->particles_[i]->explosion_counter == 5) bp->particles_[i] = CreateBullet(0); } }
void Game::initialize() { m_pBulletTimer = new QTimer(this); // Blokkokat hozunk letre igy egyertelmubb m_pField = new BattleField(QColor("lightblue"), FSIZEX, FSIZEY, FCELLSIZE); m_pScene->addItem(m_pField); // egybol hozzaadjuk mert hatha elfelejtjuk kesobb m_pTestTank = new Tank("red", 1, 2); m_pScene->addItem(m_pTestTank); m_pBullet = new Bullet(); m_pScene->addItem(m_pBullet); // Egybol adjuk hozza, kulonben ha elfelejtjuk akkor memoria szivargas (memory leak) lesz. m_pBullet->setVisible(false); // Elrejtjuk connect(m_pBulletTimer, SIGNAL(timeout()), this, SLOT(moveBullet())); shoot(1, 2, 4, 3); }
int main(){ int xposS = 370; char c; //user input int xdist = 0, ydist =0; int dx = 1; int Bnum = 0; int posB[2][10] = {0}; unsigned int i, j; gfx_open(SIZEX, SIZEY, "Space Invaders"); //open window initializeBullets(posB); while(true){ gfx_clear(); //clear screen dispScore(); uShooter(xposS); drawAliens(xdist, ydist); if(gfx_event_waiting()){ //if true c = gfx_wait(); //find choice if (c == 'b'){ xposS-=10; if (xposS <= 0) xposS = 0; }else if (c == 'n'){ xposS +=10; if (xposS >= SIZEX-30) xposS = SIZEX-30; }else if (c == ' '){ for(i=0; i<10; i++){ if(posB[0][i] == -1){ posB[0][i] = drawBullet(xposS); posB[1][i] = YPOS; } } }else if (c == 'q') return 0; else continue; } xdist+=dx; if(xdist>=370 || xdist <=-100){ dx*=-1; } if(xdist == 370 || xdist ==-100){ ydist +=5; } if(ydist == 225) return 0; //change lives num for(j=0; j<10; j++){ if(posB[0][j] != -1){ moveBullet(posB, j); } checkBullet(posB,j); } usleep(25000); gfx_flush(); } }
void Bullets::update(float dt) { moveBullet(); }