示例#1
0
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();
	}
}
示例#2
0
void BulletSys::shootBullet(const RenderWindow &window, const Time& deltaTime, const TextureLoader& tl, EnemySys& enemySys)
{
	float delta = deltaTime.asSeconds()*50;

	float SHOOT_INTERVAL = 0.1f;
	float SHOTGUN_INTERVAL = 0.05f;

	if( delta > 1)
	{
		SHOTGUN_INTERVAL*=delta;
		SHOTGUN_INTERVAL*=delta;
	}
	
	shoot_switch = false;
	shoot_shotgun_switch = false;

	if(shoot_clock.getElapsedTime().asSeconds()>=SHOOT_INTERVAL)
	{
	checkBullet(window);
	
	std::vector<Enemy*>temp;
	temp = enemySys.getVect();

	for(int i = 0; i < temp.size();i++)
	{
		if(temp[i]->type == 'n')
		{

			if(shoot_clock.getElapsedTime().asSeconds()>=SHOOT_INTERVAL && checkSize())
			bullet_vector.push_back(Bullet(temp[i]->getPosition(),temp[i]->getRotation(),tl,1));
			shoot_switch = true;
		
		}

		if(temp[i]->type == 's')
		{

		if(shoot_clock_shotgun.getElapsedTime().asSeconds()>=SHOTGUN_INTERVAL && checkSize())
		{
			bullet_vector.push_back(Bullet(temp[i]->getPosition(),temp[i]->getRotation(),tl,0.8));
			bullet_vector.push_back(Bullet(temp[i]->getPosition(),temp[i]->getRotation()+5,tl,0.8));
			bullet_vector.push_back(Bullet(temp[i]->getPosition(),temp[i]->getRotation()-5,tl,0.8));
			shoot_shotgun_switch = true;
		}
		}
	}

if(shoot_switch)
shoot_clock.restart();

if(shoot_shotgun_switch)
shoot_clock_shotgun.restart();
	
	//std::cout << "Bang" << std::endl;	
	//std::cout << bullet_vector.size() << std::endl;
	
	}

	std::vector<Bullet>::iterator it = bullet_vector.begin();

	while(it != bullet_vector.end())
	{
		(*it).move(deltaTime);
		it++;
	}
	
}