@ -0,0 +1,337 @@ | |||
#include "alien.h" | |||
int leftLim; | |||
int rightLim; | |||
void renderAlien(unsigned int* framePointer) { | |||
if(getGuise() == 0) { | |||
setGuise(1); | |||
renderAlien1(framePointer); | |||
}else { | |||
setGuise(0); | |||
renderAlien2(framePointer); | |||
} | |||
} | |||
void renderAlien1(unsigned int* framePointer) { | |||
short alienx, alieny; | |||
alienx = getAlienBlockPositionX(); | |||
alieny = getAlienBlockPositionY(); | |||
short row=0, col=0; | |||
short line = 0; | |||
short position = 0; | |||
short* aliens = getAliens(); | |||
for(line = 0; line < 10; line++) { | |||
if(line % 2 == 1) { | |||
alieny += 10; | |||
} | |||
else { | |||
if(line == 0) { | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((topAlien1[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if(aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
if(line == 2 || line == 4) { | |||
position += 11; | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((middleAlien1[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if(aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
if(line == 6 || line == 8) { | |||
position += 11; | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((bottomAlien1[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if( aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
void renderAlien2(unsigned int* framePointer) { | |||
short alienx, alieny; | |||
alienx = getAlienBlockPositionX(); | |||
alieny = getAlienBlockPositionY(); | |||
short row=0, col=0; | |||
short line = 0; | |||
short position = 0; | |||
short* aliens = getAliens(); | |||
for(line = 0; line < 10; line++) { | |||
if(line % 2 == 1) { | |||
alieny += 10; | |||
} | |||
else { | |||
if(line == 0) { | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((topAlien2[row%16] & (1<<(32-1-col)))) && aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if(aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
if(line == 2 || line == 4) { | |||
position += 11; | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((middleAlien2[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if(aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
if(line == 6 || line == 8) { | |||
position += 11; | |||
for(row=0; row<16; row++) { | |||
short position_helper = -1; | |||
for(col=0; col<352; col++) { | |||
if (((bottomAlien2[row%16] & (1<<(32-1-col))))&& aliens[position+position_helper] == 1) { | |||
framePointer[alieny*640 + alienx] = 0x00FFFFFF; | |||
} | |||
// else if(aliens[position+position_helper] == 0) { | |||
// | |||
// } | |||
else { | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
} | |||
if(col % 32 == 0) { | |||
position_helper++; | |||
} | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
void blankAlien(unsigned int* framePointer){ | |||
short alienx, alieny; | |||
alienx = getAlienBlockPositionX(); | |||
alieny = getAlienBlockPositionY(); | |||
short row=0, col=0; | |||
for(row = 0; row < 130; row++){ | |||
for(col = 0; col < 352; col++){ | |||
framePointer[alieny*640 + alienx] = 0x00000000; | |||
alienx++; | |||
} | |||
alienx=getAlienBlockPositionX(); | |||
alieny++; | |||
} | |||
} | |||
void dyingAlien(unsigned int* framePointer, short alienx, short alieny) { | |||
short row=0, col=0; | |||
for(row = 0; row < 16; row++){ | |||
for(col = 0; col < 32; col++){ | |||
if ((dying_alien[row%16] & (1<<(32-1-col)))) { | |||
framePointer[(alieny+row)*640 + alienx+col] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(alieny+row)*640 + alienx+col] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
void dyingAlienHelper(unsigned int* framePointer, short alienx, short alieny) { | |||
short row=0, col=0; | |||
for(row = 0; row < 16; row++){ | |||
for(col = 0; col < 32; col++){ | |||
framePointer[(alieny+row)*640 + alienx+col] = 0x00000000; | |||
} | |||
} | |||
} | |||
int columnCheck(int value) { | |||
short* aliens = getAliens(); | |||
if(aliens[value] == 0 && aliens[value+11] == 0 && aliens[value+22] == 0 && aliens[value+33] == 0 && aliens[value+44] == 0) { | |||
return 0; | |||
} | |||
return 1; | |||
} | |||
int setRightMax() { | |||
int max = 352; | |||
if(!columnCheck(10)) { | |||
max = 320; | |||
if(!columnCheck(9)) { | |||
max = 288; | |||
if(!columnCheck(8)) { | |||
max = 256; | |||
if(!columnCheck(7)) { | |||
max = 224; | |||
if(!columnCheck(6)) { | |||
max = 192; | |||
if(!columnCheck(5)) { | |||
max = 160; | |||
if(!columnCheck(4)) { | |||
max = 128; | |||
if(!columnCheck(3)) { | |||
max = 96; | |||
if(!columnCheck(2)) { | |||
max = 64; | |||
if(!columnCheck(1)) { | |||
max = 32; | |||
if(!columnCheck(0)) { | |||
max = 0; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
return max; | |||
} | |||
int setLeftMin() { | |||
int min = 0; | |||
if(!columnCheck(0)) { | |||
min = 32; | |||
if(!columnCheck(1)) { | |||
min = 64; | |||
if(!columnCheck(2)) { | |||
min = 96; | |||
if(!columnCheck(3)) { | |||
min = 128; | |||
if(!columnCheck(4)) { | |||
min = 160; | |||
if(!columnCheck(5)) { | |||
min = 192; | |||
if(!columnCheck(6)) { | |||
min = 224; | |||
if(!columnCheck(7)) { | |||
min = 256; | |||
if(!columnCheck(8)) { | |||
min = 288; | |||
if(!columnCheck(9)) { | |||
min = 320; | |||
if(!columnCheck(10)) { | |||
min = 352; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
return min; | |||
} | |||
void moveAlien(unsigned int* framePointer) { | |||
short dir = getDirection(); | |||
short alienx, alieny; | |||
alienx = getAlienBlockPositionX(); | |||
alieny = getAlienBlockPositionY(); | |||
int right = setRightMax(); | |||
if((alienx+right) == 640 && dir == 0) { | |||
setDirection(1); | |||
blankAlien(framePointer); | |||
alieny += 8; | |||
setAlienBlockPosition(alienx, alieny); | |||
} | |||
int left = 0 - setLeftMin(); | |||
if(alienx == left && dir == 1) { | |||
setDirection(0); | |||
blankAlien(framePointer); | |||
alieny += 8; | |||
setAlienBlockPosition(alienx, alieny); | |||
} | |||
if(dir == 0) { | |||
alienx += 4; | |||
setAlienBlockPosition(alienx, alieny); | |||
} | |||
else { | |||
alienx -= 4; | |||
setAlienBlockPosition(alienx, alieny); | |||
} | |||
} | |||
@ -0,0 +1,158 @@ | |||
#ifndef ALIEN_H_ | |||
#define ALIEN_H_ | |||
#define ALIEN_HEIGHT 16 | |||
// Packs each horizontal line of the figures into a single 32 bit word. | |||
#define packWord32(b31,b30,b29,b28,b27,b26,b25,b24,b23,b22,b21,b20,b19,b18,b17,b16,b15,b14,b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \ | |||
((b31 << 31) | (b30 << 30) | (b29 << 29) | (b28 << 28) | (b27 << 27) | (b26 << 26) | (b25 << 25) | (b24 << 24) | \ | |||
(b23 << 23) | (b22 << 22) | (b21 << 21) | (b20 << 20) | (b19 << 19) | (b18 << 18) | (b17 << 17) | (b16 << 16) | \ | |||
(b15 << 15) | (b14 << 14) | (b13 << 13) | (b12 << 12) | (b11 << 11) | (b10 << 10) | (b9 << 9 ) | (b8 << 8 ) | \ | |||
(b7 << 7 ) | (b6 << 6 ) | (b5 << 5 ) | (b4 << 4 ) | (b3 << 3 ) | (b2 << 2 ) | (b1 << 1 ) | (b0 << 0 ) ) | |||
int topAlien1[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
}; | |||
int topAlien2[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
}; | |||
int middleAlien1[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
}; | |||
int middleAlien2[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0), | |||
}; | |||
int bottomAlien1[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0), | |||
}; | |||
int bottomAlien2[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0), | |||
}; | |||
int dying_alien[ALIEN_HEIGHT] = | |||
{ | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0), | |||
packWord32(0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0), | |||
}; | |||
void renderAlien(unsigned int*); | |||
void renderAlien1(unsigned int*); | |||
void renderAlien2(unsigned int*); | |||
void blankAlien(unsigned int*); | |||
void moveAlien(unsigned int*); | |||
#endif /* ALIEN_H_ */ |
@ -0,0 +1,226 @@ | |||
#include "bullet.h" | |||
void renderBullet(unsigned int* framePointer) { | |||
if(getGuiseBullet() == 0) { | |||
setGuiseBullet(1); | |||
renderBullet1(framePointer); | |||
}else { | |||
setGuiseBullet(0); | |||
renderBullet2(framePointer); | |||
} | |||
} | |||
void renderBullet1(unsigned int* framePointer) { | |||
if(getTankBulletState() == 1) { | |||
short initial_x = getTankBulletPositionX(); | |||
short initial_y = getTankBulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((tankBullet[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien1BulletState() == 1) { | |||
short initial_x = getAlien1BulletPositionX(); | |||
short initial_y = getAlien1BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet1_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien2BulletState() == 1) { | |||
short initial_x = getAlien2BulletPositionX(); | |||
short initial_y = getAlien2BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet2_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien3BulletState() == 1) { | |||
short initial_x = getAlien3BulletPositionX(); | |||
short initial_y = getAlien3BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet3_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien4BulletState() == 1) { | |||
short initial_x = getAlien4BulletPositionX(); | |||
short initial_y = getAlien4BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet1_1[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
void renderBullet2(unsigned int* framePointer) { | |||
if(getTankBulletState() == 1) { | |||
short initial_x = getTankBulletPositionX(); | |||
short initial_y = getTankBulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((tankBullet[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien1BulletState() == 1) { | |||
short initial_x = getAlien1BulletPositionX(); | |||
short initial_y = getAlien1BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet1_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien2BulletState() == 1) { | |||
short initial_x = getAlien2BulletPositionX(); | |||
short initial_y = getAlien2BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet2_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien3BulletState() == 1) { | |||
short initial_x = getAlien3BulletPositionX(); | |||
short initial_y = getAlien3BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet3_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
if(getAlien4BulletState() == 1) { | |||
short initial_x = getAlien4BulletPositionX(); | |||
short initial_y = getAlien4BulletPositionY(); | |||
int x, y; | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((alienBullet1_2[x%10] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00FFFFFE; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
void blankTankBullet(unsigned int* framePointer){ | |||
short tankx, tanky; | |||
tankx = getTankBulletPositionX(); | |||
tanky = getTankBulletPositionY(); | |||
short row=0, col=0; | |||
for(row = 0; row < BLOCK_HEIGHT; row++){ | |||
for(col = 0; col < BLOCK_WIDTH; col++){ | |||
framePointer[(tanky+row)*640 + tankx+col] = 0x00000000; | |||
} | |||
} | |||
} | |||
void blankAlienBullet(unsigned int* framePointer, short alienx, short alieny) { | |||
short row=0, col=0; | |||
for(row = 0; row < BLOCK_HEIGHT; row++){ | |||
for(col = 0; col < BLOCK_WIDTH; col++){ | |||
framePointer[(alieny+row)*640 + alienx+col] = 0x00000000; | |||
} | |||
} | |||
} | |||
void moveBullets(unsigned int* framePointer) { | |||
if(getTankBulletState() == 1) { | |||
if(getTankBulletPositionY() == 30) { | |||
blankTankBullet(framePointer); | |||
setTankBulletState(0); | |||
} | |||
else { | |||
setTankBulletPositionY(getTankBulletPositionY()-1); | |||
} | |||
} | |||
if(getAlien1BulletState() == 1) { | |||
if(getAlien1BulletPositionY() == 450) { | |||
blankAlienBullet(framePointer, getAlien1BulletPositionX(), getAlien1BulletPositionY()); | |||
setAlien1BulletState(0); | |||
} | |||
else { | |||
setAlien1BulletPositionY(getAlien1BulletPositionY()+1); | |||
} | |||
} | |||
if(getAlien2BulletState() == 1) { | |||
if(getAlien2BulletPositionY() == 450) { | |||
blankAlienBullet(framePointer, getAlien2BulletPositionX(), getAlien2BulletPositionY()); | |||
setAlien2BulletState(0); | |||
} | |||
else { | |||
setAlien2BulletPositionY(getAlien2BulletPositionY()+1); | |||
} | |||
} | |||
if(getAlien3BulletState() == 1) { | |||
if(getAlien3BulletPositionY() == 450) { | |||
blankAlienBullet(framePointer, getAlien3BulletPositionX(), getAlien3BulletPositionY()); | |||
setAlien3BulletState(0); | |||
} | |||
else { | |||
setAlien3BulletPositionY(getAlien3BulletPositionY()+1); | |||
} | |||
} | |||
if(getAlien4BulletState() == 1) { | |||
if(getAlien4BulletPositionY() == 450) { | |||
blankAlienBullet(framePointer, getAlien4BulletPositionX(), getAlien4BulletPositionY()); | |||
setAlien4BulletState(0); | |||
} | |||
else { | |||
setAlien4BulletPositionY(getAlien4BulletPositionY()+1); | |||
} | |||
} | |||
} |
@ -0,0 +1,109 @@ | |||
#ifndef BULLET_H_ | |||
#define BULLET_H_ | |||
#define BLOCK_HEIGHT 10 | |||
#define BLOCK_WIDTH 6 | |||
#define packWord24(b5,b4,b3,b2,b1,b0) \ | |||
((b5 << 5 ) | (b4 << 4 ) | (b3 << 3 ) | (b2 << 2 ) | (b1 << 1 ) | (b0 << 0 )) | |||
int alienBullet1_1[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(1,1,1,1,1,1), | |||
packWord24(1,1,1,1,1,1), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int alienBullet1_2[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(1,1,1,1,1,1), | |||
packWord24(1,1,1,1,1,1), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int alienBullet2_1[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(0,0,0,0,1,1), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,0,0,1,1), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int alienBullet2_2[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,0,0,1,1), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int alienBullet3_1[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(1,1,0,0,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(1,1,0,0,0,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int alienBullet3_2[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(1,1,0,0,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(1,1,0,0,0,0), | |||
packWord24(0,1,1,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,1,1,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
int tankBullet[BLOCK_HEIGHT] = | |||
{ | |||
packWord24(0,0,0,0,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,1,1,0,0), | |||
packWord24(0,0,0,0,0,0), | |||
}; | |||
void renderBullet(unsigned int*); | |||
void moveBullets(unsigned int*); | |||
#endif /* BULLET_H_ */ |
@ -0,0 +1,638 @@ | |||
#include "bunker.h" | |||
#include "stdlib.h" | |||
#include "xintc_l.h" // Provides handy macros for the interrupt controller. | |||
int x_y[4] = {BUNKER1_X, BUNKER2_X, BUNKER3_X, BUNKER4_X}; | |||
int initial_x = 70; | |||
int initial_y = 300; | |||
int tank_y_position = 420; | |||
void renderBunker(unsigned int* framePointer) { // draw for the first time | |||
short x=0, y=0; | |||
int i,j; | |||
for(j = 0; j < 4; j++) { | |||
initial_x = x_y[j]; | |||
for(i=0; i<10; i++){ | |||
switch(i){ | |||
case 0: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_left0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 1: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 2: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 3: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_right0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 4: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 5: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_center_left0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 6: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_center_right0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*2] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 7: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 8: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
case 9: | |||
for(x = 0; x < BLOCK_HEIGHT; x++) { | |||
for(y = 0; y < BLOCK_WIDTH; y++){ | |||
if ((block_normal0[x%16] & (1<<(BLOCK_WIDTH-1-y)))) { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+x+BLOCK_HEIGHT*2)*640 + initial_x+y+BLOCK_WIDTH*3] = 0x00000000; | |||
} | |||
} | |||
} | |||
break; | |||
default : | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
void erodeBunker(unsigned int* framePointer, int which_bunker, int which_block){ | |||
// int which_block = rand()%10; | |||
short* bunker; | |||
int i, j; | |||
int block_row, block_col; | |||
switch(which_bunker){ // select a bunker that I want to erode | |||
case 0: | |||
bunker = getBunker1(); | |||
break; | |||
case 1: | |||
bunker = getBunker2(); | |||
break; | |||
case 2: | |||
bunker = getBunker3(); | |||
break; | |||
case 3: | |||
bunker = getBunker4(); | |||
break; | |||
default : | |||
break; | |||
} | |||
switch(which_block){ // 'block_row, block_col' are used to calculate to find out the position of framePointer | |||
case 0: | |||
block_row = 0; | |||
block_col = 0; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 1: | |||
block_row = 0; | |||
block_col = 1; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 2: | |||
block_row = 0; | |||
block_col = 2; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 3: | |||
block_row = 0; | |||
block_col = 3; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 4: | |||
block_row = 1; | |||
block_col = 0; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 5: | |||
block_row = 1; | |||
block_col = 1; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 6: | |||
block_row = 1; | |||
block_col = 2; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 7: | |||
block_row = 1; | |||
block_col = 3; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 8: | |||
block_row = 2; | |||
block_col = 0; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
case 9: | |||
block_row = 2; | |||
block_col = 3; | |||
blankBlock(framePointer, which_bunker, which_block, block_row, block_col); | |||
updateBlock(framePointer, which_bunker, which_block, block_row, block_col, bunker); | |||
break; | |||
default : | |||
break; | |||
} | |||
} | |||
// This function runs first to make a block empty, and then draw an eroded block by 'updateBlock()' function | |||
void blankBlock(unsigned int* framePointer, int which_bunker, int which_block, int block_row, int block_col){ | |||
int i, j; | |||
initial_x = x_y[which_bunker]; | |||
for(i = 0; i < BLOCK_HEIGHT; i++){ | |||
for(j = 0; j < BLOCK_WIDTH; j++){ | |||
framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x00000000; | |||
} | |||
} | |||
} | |||
void updateBlock(unsigned int* framePointer, int which_bunker, int which_block, int block_row, int block_col, short* bunker){ | |||
int i, j; | |||
initial_x = x_y[which_bunker]; | |||
int* which_state; | |||
if(bunker[which_block]==0){ // depending on the block selected and bunker status, 'which_state' points to a pre-defined eroded block | |||
bunker[which_block] = 1; | |||
if(which_block == 0){ | |||
which_state = block_left1; | |||
} | |||
else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){ | |||
which_state = block_normal1; | |||
} | |||
else if(which_block == 3){ | |||
which_state = block_right1; | |||
} | |||
else if(which_block == 5){ | |||
which_state = block_center_left1; | |||
} | |||
else if(which_block == 6){ | |||
which_state = block_center_right1; | |||
} | |||
} | |||
else if(bunker[which_block]==1){ | |||
bunker[which_block] = 2; | |||
if(which_block == 0){ | |||
which_state = block_left2; | |||
} | |||
else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){ | |||
which_state = block_normal2; | |||
} | |||
else if(which_block == 3){ | |||
which_state = block_right2; | |||
} | |||
else if(which_block == 5){ | |||
which_state = block_center_left2; | |||
} | |||
else if(which_block == 6){ | |||
which_state = block_center_right2; | |||
} | |||
} | |||
else if(bunker[which_block]==2){ | |||
bunker[which_block] = 3; | |||
if(which_block == 0){ | |||
which_state = block_left3; | |||
} | |||
else if(which_block == 1 || which_block == 2 || which_block == 4 || which_block == 7 || which_block == 8 || which_block == 9){ | |||
which_state = block_normal3; | |||
} | |||
else if(which_block == 3){ | |||
which_state = block_right3; | |||
} | |||
else if(which_block == 5){ | |||
which_state = block_center_left3; | |||
} | |||
else if(which_block == 6){ | |||
which_state = block_center_right3; | |||
} | |||
} | |||
else{ | |||
bunker[which_block] = 4; | |||
which_state = empty; | |||
} | |||
for(i = 0; i < BLOCK_HEIGHT; i++){ | |||
for(j = 0; j < BLOCK_WIDTH; j++){ | |||
if ((which_state[i%16] & (1<<(BLOCK_WIDTH-1-j)))) { | |||
framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x0000FF00; | |||
} else { | |||
framePointer[(initial_y+i+BLOCK_HEIGHT*block_row)*640 + initial_x+j+BLOCK_WIDTH*block_col] = 0x00000000; | |||
} | |||
} | |||
} | |||
} | |||
void selectBlock(unsigned int* framePointer, int bullet){ | |||
int bullet_x; | |||
int bullet_y; | |||
short hit = 0; | |||
short* bunker; | |||
int counter=0; | |||
short dying = 0; | |||
int gameover = 0; | |||
switch(bullet){ | |||
case 1: | |||
bullet_x = getAlien1BulletPositionX()+3; | |||
bullet_y = getAlien1BulletPositionY()+10; | |||
break; | |||
case 2: | |||
bullet_x = getAlien2BulletPositionX()+3; | |||
bullet_y = getAlien2BulletPositionY()+10; | |||
break; | |||
case 3: | |||
bullet_x = getAlien3BulletPositionX()+3; | |||
bullet_y = getAlien3BulletPositionY()+10; | |||
break; | |||
case 4: | |||
bullet_x = getAlien4BulletPositionX()+3; | |||
bullet_y = getAlien4BulletPositionY()+10; | |||
break; | |||
case 5: | |||
bullet_x = getTankBulletPositionX()+3; | |||
bullet_y = getTankBulletPositionY(); | |||
default: | |||
break; | |||
} | |||
if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+64+3){ | |||
bunker = getBunker1(); | |||
if(bullet_y > initial_y && bullet_y < initial_y+16){ | |||
if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+16 && bunker[0] != 4){ | |||
erodeBunker(framePointer, 0, 0); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+16 && bullet_x < BUNKER1_X+32 && bunker[1] != 4){ | |||
erodeBunker(framePointer, 0, 1); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+32 && bullet_x < BUNKER1_X+48 && bunker[2] != 4){ | |||
erodeBunker(framePointer, 0, 2); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+48 && bullet_x < BUNKER1_X+64+3 && bunker[3] != 4){ | |||
erodeBunker(framePointer, 0, 3); | |||
hit = 1; | |||
} | |||
} | |||
if(bullet_y>initial_y+16 && bullet_y<initial_y+32){ | |||
if(bullet_x >= BUNKER1_X-3 && bullet_x < BUNKER1_X+16 && bunker[4] != 4){ | |||
erodeBunker(framePointer, 0, 4); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+16 && bullet_x < BUNKER1_X+32 && bunker[5] != 4){ | |||
erodeBunker(framePointer, 0, 5); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+32 && bullet_x < BUNKER1_X+48 && bunker[6] != 4){ | |||
erodeBunker(framePointer, 0, 6); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+48 && bullet_x < BUNKER1_X+64+3 && bunker[7] != 4){ | |||
erodeBunker(framePointer, 0, 7); | |||
hit = 1; | |||
} | |||
} | |||
if(bullet_y>initial_y+32 && bullet_y<initial_y+48){ | |||
if(bullet_x >= BUNKER1_X-3 && bullet_x<BUNKER1_X+16 && bunker[8] != 4){ | |||
erodeBunker(framePointer, 0, 8); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER1_X+48 && bullet_x<BUNKER1_X+64+3 && bunker[9] != 4){ | |||
erodeBunker(framePointer, 0, 9); | |||
hit = 1; | |||
} | |||
} | |||
} | |||
if(bullet_x > BUNKER2_X-3 && bullet_x < BUNKER2_X+64+3){ | |||
bunker = getBunker2(); | |||
if(bullet_y>initial_y && bullet_y<initial_y+16){ | |||
if(bullet_x >= BUNKER2_X-3 && bullet_x<BUNKER2_X+16 && bunker[0] != 4){ | |||
erodeBunker(framePointer, 1, 0); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+16 && bullet_x<BUNKER2_X+32 && bunker[1] != 4){ | |||
erodeBunker(framePointer, 1, 1); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+32 && bullet_x<BUNKER2_X+48 && bunker[2] != 4){ | |||
erodeBunker(framePointer, 1, 2); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+48 && bullet_x<BUNKER2_X+64+3 && bunker[3] != 4){ | |||
erodeBunker(framePointer, 1, 3); | |||
hit = 1; | |||
} | |||
} | |||
if(bullet_y>initial_y+16 && bullet_y<initial_y+32){ | |||
if(bullet_x >= BUNKER2_X-3 && bullet_x<BUNKER2_X+16 && bunker[4] != 4){ | |||
erodeBunker(framePointer, 1, 4); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+16 && bullet_x<BUNKER2_X+32 && bunker[5] != 4){ | |||
erodeBunker(framePointer, 1, 5); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+32 && bullet_x<BUNKER2_X+48 && bunker[6] != 4){ | |||
erodeBunker(framePointer, 1, 6); | |||
hit = 1; | |||
} | |||
if(bullet_x >= BUNKER2_X+48 && bullet_x<BUNKER2_X+64+3 && bunker[7] != 4){ | |||
erodeBunker(framePointer, 1, 7); | |||
hit = 1; | |||
} | |||
} | |||