Exemplo n.º 1
0
void moveTankBullet(){

	if(tankBullet.type != INACTIVE_BULLET){ //bullet is active
		tankBullet.y -= TANK_BULLET_PIXELS_PER_MOVE;
		undrawTankBullet();
		ScreenPoint hitCoord = tankBulletCollision();

		if(tankBullet.y <= TOP_OF_PLAYABLE_AREA ){
			tankBullet.type = INACTIVE_BULLET; //bullet has gone offscreen so deactivate the bullet
			clearTankBullet();
		}
		else if(hitCoord.xcoord >= 0 && hitCoord.ycoord >= 0){
			if(DB_ON1) xil_printf("This is oops: %d, %d\n\r",hitCoord.xcoord, hitCoord.ycoord);
			clearTankBullet();
			tankBullet.type = INACTIVE_BULLET; //bullet has hit something
			deactiveFireTankBulletSound();
			if(allAliensDead()){
				drawAliens();
				alienArray[lastAlienKilled] = NO_ALIEN;
				drawAliens();
				runGameOver(1);
			}
			//chooseBunkerBlockToDamage(hitCoord);
		}
		drawTankBullet();
	}

}
Exemplo n.º 2
0
void redraw(unsigned int* framePointer)
{
	drawAliens();
	drawHUD();
	drawBullets(0x00FF0000);
	draw_bunker(0x0000FF00);
	draw_tank(0x0000FF00);
	drawAliens();
	drawHUD();
	drawBullets(0x00FF0000);
	draw_bunker(0x0000FF00);
	draw_tank(0x0000FF00);
}
Exemplo n.º 3
0
void updateAlienBlock() {
	int stage;
	// This waits a full second in FIT ticks, and updates cumulative seconds if there are no button presses.
	if (fit_timer_count >= getAlienTicks()) {
		drawAliens();
		stage = getMarchingStage();
		switch(stage) {
		case (1):
												setMarchingFlag(1);
		break;
		case (2):
												setMarchingFlag2(1);
		break;
		case (3):
												setMarchingFlag3(1);
		break;
		case (4):
												setMarchingFlag4(1);
		break;
		default:
			xil_printf("default\n\r");
			//setMarchingFlag(1);
			break;
		}
		//setMarchingFlag(1);

		//fifo_writer(fastinvader1SoundData, fastinvader1SoundRate, fastinvader1SoundFrames);
		fit_timer_count = 0;			// Reset the counter.
	}
}
Exemplo n.º 4
0
// Render the screen.
void render() {
	initAliveAliens();
	drawAliens(framePointer0);
	drawTank(false, 0, 0);
	drawBunkers(framePointer0);
	drawStats(framePointer0);
}
Exemplo n.º 5
0
int chooseAlienToKill(int x, int y){
	int i;
	int* alienBMP;
	for(i = 0; i < ALIEN_ROWS*ALIENS_PER_ROW; i++){
		if(alienArray[i] > DEAD_ALIEN){
			if((y >= (alienOriginY + i/ALIENS_PER_ROW*ALIEN_HEIGHT)) && (y < (alienOriginY + i/ALIENS_PER_ROW*ALIEN_HEIGHT+ALIEN_HEIGHT))){
				//xil_printf("Made it into checking the alien Y bounds for alien %d.\n\r",i);
				int myLeftBound = alienOriginX + i%ALIENS_PER_ROW*ALIEN_WIDTH;
				int myRightBound = alienOriginX + i%ALIENS_PER_ROW*ALIEN_WIDTH+ALIEN_WIDTH;
				if((x >= (myLeftBound)) && (x < (myRightBound))){
					if(DB_ON1){ xil_printf("You've hit alien %d! Blarg!\n\r",i);}
					/*alienArray[i] = DEAD_ALIEN;
					return 1;*/
					switch(alienArray[i]){
					case BIG_SQUID:
						alienBMP = (alienInOut == 0 ? bigSquidIn :
						bigSquidOut);
						addToScore(HIT_BIG_SQUID);
						break;
					case LITTLE_SQUID:
						alienBMP = (alienInOut == 0 ? littleSquidIn :
						littleSquidOut);
						addToScore(HIT_SMALL_SQUID);
						if(DB_ON1) xil_printf("We're in the little squid space.\n\r");
						break;
					case JUMPING_JACK:
						alienBMP = (alienInOut == 0 ? jumpingJackIn :
						jumpingJackOut);
						addToScore(HIT_JUMPING_JACK);
						break;
					default:
						alienBMP = noAlien;
						break;
					}
					alienArray[i] = DEAD_ALIEN;   //i like boys
					activeInvaderDieSound(); //activeInvaderDieSound();
					drawAliens();
					lastAlienKilled = i;

					return 1;
				}
			}

		}
	}

	return 0;
}
Exemplo n.º 6
0
//updates the origin location by the predefined amount
void moveAliens(){
	//call move aliens sound
	//moveInvadersSound();
	activeInvaderMoveSound();

	//what to do if aliens are on the left side of the screen
	if(alienDirection == LEFT && (alienOriginX - PIXELS_PER_MOVE < -1*(ALIEN_WIDTH * firstColAliveAliens))){
		alienOriginY += PIXELS_PER_MOVE;
		undrawAliens(DOWN);
		alienDirection = RIGHT;

	}
	//aliens are on the right side of the screen
	else if(alienDirection == RIGHT && (alienOriginX + alienFarRightOffset + PIXELS_PER_MOVE > (SCREEN_X_PIXELS + (ALIENS_PER_ROW - lastColAliveAliens - 1)*ALIEN_WIDTH))){
		alienOriginY += PIXELS_PER_MOVE;
		undrawAliens(DOWN);
		alienDirection = LEFT;
	}
	//aliens are free to move as normal
	else{
		alienOriginX += alienDirection == RIGHT ? PIXELS_PER_MOVE : PIXELS_PER_MOVE * -1;
		undrawAliens(alienDirection);
	}
	int in;
	for(in = 0; in < NUM_BUNKERS; in++){
		drawBunker(in);
	}
	drawAliens();
	firstColAliveAliens = findFirstAliveColumn();
	lastColAliveAliens = findLastAliveColumn();
	lastRowAliveAliens = findLastAliveRow();
	int j;
	for(j = 0; j < NUM_ALIEN_BULLETS; j++){
		drawAlienBullet(j);
	}
	//drawAliens();

	if((alienOriginY + (lastRowAliveAliens+1) * ALIEN_HEIGHT)  >= (BUNKER_INITIAL_Y + 3*BUNKER_HEIGHT)){
		runGameOver(0);
	}
}
Exemplo n.º 7
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();
	}
}