Exemplo n.º 1
0
int main() {
    REG_DISPCNT = BG2_EN | MODE_4;
    int state = SPLASH;


    //CURSOR STUFF
    user.row              = 80;
    user.col              = 120;
    user.oldRow           = user.row;
    user.oldCol           = user.col;
    user.oldoldRow        = user.row;
    user.oldoldCol        = user.col;
    user.pixelState       = deadYes;
    user.oldPixelState    = deadNo;
    user.oldoldPixelState = deadNo;

    while(1) {
        switch(state) {
        case SPLASH:
            FlipPage();
            setPalette(titleScreen_palette);
            drawImage4(0,0,240,160,titleScreen);
            FlipPage();
            PALETTE[0] = deadNo;
            drawRect4(0,0,160,240,0);
            while(!KEY_DOWN_NOW(BUTTON_START));
            while(KEY_DOWN_NOW(BUTTON_START));
            FlipPage();
            PALETTE[0] = deadNo;
            drawRect4(0,0,160,240,0);
            state = EDIT;
            break;

        case EDIT:
            editableBy(user);
            state = SIMULATE;
            break;

        case SIMULATE:
            simulating();
            state = EDIT;
            break;
        }
    }
    return 0;
}
Exemplo n.º 2
0
int main()
{
	REG_DISPCTL = MODE4 | BG2_ENABLE | BUFFER1FLAG;
	loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);

	int state = BEGIN;
	while(1)
	{
		switch(state)
		{
			case BEGIN:
				// loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);
				drawImage4(0, 0, 240, 160, (u16*)screen);
				waitForVblank();
				FlipPage();
				while(!KEY_DOWN_NOW(BUTTON_START));
				state = GAME;
				break;
			case GAME:
				state = play();
				break;
			case WIN:
				loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);
				drawImage4(0, 0, 240, 160, (u16*)win);
				drawString4(5, 8, "Press Select", PALETTE[0]);
				waitForVblank();
				FlipPage();
					while(!KEY_DOWN_NOW(BUTTON_SELECT));
				state = BEGIN;
				break;
			case LOSE:
				// loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);
				drawImage4(0, 0, 240, 160, (u16*)die);
				waitForVblank();
				FlipPage();
				while(!KEY_DOWN_NOW(BUTTON_SELECT));
				state = BEGIN;
				break;
			default:
				break;
		}
	}
	return 0;
}
/********************************************************
Name: ColorFill
Function: Fill the frame with a color
Parameter:R: the value of RED.   Range:RED 0~255
          G: the value of GREEN. Range:RED 0~255
          B: the value of BLUE.  Range:RED 0~255
********************************************************/
void ColorduinoObject::ColorFill(unsigned char R,unsigned char G,unsigned char B)
{
  PixelRGB *p = GetPixel(0,0);
  for (unsigned char y=0;y<ColorduinoScreenWidth;y++) {
    for(unsigned char x=0;x<ColorduinoScreenHeight;x++) {
      p->r = R;
      p->g = G;
      p->b = B;
      p++;
    }
  }
  
  FlipPage();
}
Exemplo n.º 4
0
void drawBoard(){
	
	if(toReset){
		int i;
		mode=NORMAL;
		playing=0;
		for (i=0;i<2;i++){
			PALETTE[i]=LifeGame_palette[i];
		}
		drawImage4(0,0,240,160,LifeGame);	
		FlipPage();
		while(!(KEY_DOWN_NOW(BUTTON_START))){
		}
		FlipPage();
		u16 colors[]={BLACK,LTGREY,RED,GREEN,BLUE,WHITE,DKGREY,YELLOW};
		int numcolors = sizeof(colors)/sizeof(colors[0]);
		for (i=0;i<numcolors;i++){
			PALETTE[i]=colors[i];
		}
		clear();//Clear array to start game

		mouse->r=UpperLeftRow-1;
		mouse->c=UpperLeftCol-2;
		toReset=0;
	}
	else{
	drawRect4(0,0,240,160,LTGREYINDEX);
	drawImage4(140,58,20,12,clearButton);
	drawImage4(140,80,20,12,One);
	drawImage4(140,110,20,12,Two);
	drawImage4(140,145,20,12,next);
	if(playing)drawImage4(140,30,12,12,pause);
	else drawImage4(140,30,12,12,play);
	if (mode==NORMAL){
		drawImage4(2,5,50,12,normalModeButton);
		drawImage4(140,177,50,12,nextModeButton);
	}
	else{
		drawImage4(2,5,50,12,nextModeButton);
		drawImage4(140,177,50,12,normalModeButton);
		}
		drawMouse(mouse->r,mouse->c,5,5,BLUEINDEX);
	
		int i;
		int j;
		if (mode==NORMAL){
			for (i=0;i<MAXR;i++){
				for (j=0;j<MAXC;j++){
					if (a[i][j])drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,GREENINDEX); 
					else drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,BLACKINDEX);
				}
			}
		}
		else{ 
			int n;
			int m;
			for(n=0;n<MAXR;n++){
				for(m=0;m<MAXC;m++){
					oldA[n][m]=prevA[n][m];
				}
			}
			nextArray();
			
			for (i=0;i<MAXR;i++){
				for (j=0;j<MAXC;j++){
					if (a[i][j]==prevA[i][j]){
						if(a[i][j])
							drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,GREENINDEX);

						else drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,BLACKINDEX); 
					}
					else{
						if(a[i][j])drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,YELLOWINDEX);
						else drawRect4(i*4+UpperLeftRow,j*4+UpperLeftCol,3,3,REDINDEX);
					}
				}
			}
			
			for(n=0;n<MAXR;n++){
				for(m=0;m<MAXC;m++){
					a[n][m]=prevA[n][m];
				}
			}
			for(n=0;n<MAXR;n++){
				for(m=0;m<MAXC;m++){
					prevA[n][m]=oldA[n][m];
				}
			}
				
			
		}
	}
	FlipPage();
	waitForVblank();
	
}
Exemplo n.º 5
0
int main(void) {
	

	int r = 5; //player positions
	int c = 4;
	int r2 = 80; //first ball positions
	int c2 = 120;
	int human_speed = 2; //guess what this is?
	int width = 2; //dont bother, this is the frame width
	int human_size = 10; //duh
	int size = 10; //size of computer
	int dr = 3; //speed of player
	int dc = 3; //should = dr
	int agression; //not being used right now
	int inRange = 0; //a random count variable
	int human_health = 100; //human starting health
	int comp_health = 100; //computer starting health
	int newgame = 1; //another count var
	int loopCount = 0; 
	int numAttacks = 0; //number of times human attacks
	int justAttacked; //count var for computer attacks
	int result; //count var
	int death_radius = 4; //this is how many pixels the radius around the computer is that you have to be in to attack/be attacked
	int next_var1 = 0;
	int retreat = 0;
	int retreat_length = 100; //how long it is after going in to retreat mode that you win
	int next_var2 = 0;
	int junkVar = 0;

	//prebuild the binary search tree
	//make the data in each node be a pointer to a function, then the output of that function
	//decides which node is next

	
NaryNode *root = NULL;
root = createNaryNode(createIntData(0), 0); //make the root node (check health)
  appendChild(root, createNaryNode(createIntData(1), 0)); //make the first child (if health is ok)
  appendChild(root, createNaryNode(createIntData(2), 0)); //make the second child (if health is bad)
  appendChild(root->child[0], createNaryNode(createIntData(3), 0)); //treat the first child as the root and add another child
  appendChild(root->child[1], createNaryNode(createIntData(4), 0)); //treat the first child as the root and add another child
  appendChild(root->child[1]->child[4], createNaryNode(createIntData(5), 0)); //add another child on right parent

int *tree1;
int *tree2;
int *tree3;
tree1 = (int*)(root->child[1]);
(int*)(root->child[1]) = 4;
(int*)(root->child[0]) = 2;
(int*)(root->child[1]->child[4]) = 1;

//tree1 = root->child[1];

  /*
		[root]
		/	\
	[child1] ----------child 2]
	/	   \           \      \
 [child3]  [child4]	   [child5] [child6] 
  /			/	   \
[child7]   [child8] [child9]
			|			|
		  [child9]	   [child10]
  
  
  */
  

Junk first;
first.margin = 40; //the margin for death for the computer
first.comp_health_rate = 1; //how fast the you kill the computer
first.human_health_rate = 2; //how fast the computer kills you



	while(keepGoing()) {
		

		waitForVBlank(ON);
		switch (gameState) {
			case START:
				//start mode 4
				initializeGBA(MODE_4);
				FlipPage(ON);
				paintBackground(PressEnterBitmap);
				FlipPage(OFF);
				
				
				//in to mode 3
				GBASetup();
				initializeGBA(MODE_3);
				drawBackground(6);
				while(!keyHit(BUTTON_START)){
				
					while(keyHit(BUTTON_START)){
						break;}
				}
					
				//reset all the count vars and such
					newgame = 1;
					numAttacks = 0;
					loopCount = 0;
					justAttacked = 0;
					human_health = 100; //human starting health
					comp_health = 100; //computer starting health
					next_var1 = 0;
					next_var2 = 0;
					r = 5; //player positions
					c = 4;
					r2 = 80; //first ball positions
					c2 = 120;
					gameState = PLAY;
					retreat = 0;
				
				break;
			case PLAY:

				//start mode 3
				FlipPage(OFF);
				GBASetup();

				waitForVBlank(ON);
				loopCount++;
				drawRectDMA(0, 0, 160, 240, COLOR(0,0,0)); //the black background
				
				//nary tree usage
				tree3 = (int*)(root->child[1]);
				if(tree3){
					junkVar++;
				}


				if(comp_health < first.margin){
					gameState = WIN;
				}
				
				//frame
				drawRectDMA(1, 1, 240, 1, COLOR(0,0,31)); //left bar
				drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar
				drawRectDMA(1, 1, 240, 1, COLOR(0,0,31));//bottom bar
				drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar
				

				//draw health bars
				if(human_health == 100){
				drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human starting health
				drawRectDMA(5, 6, 1, 1, COLOR(0,0,31));
				drawRectDMA(5, 8, 1, 1, COLOR(0,0,31));
				}

				if(comp_health == 100){
				drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer starting health
				drawRectDMA(5, 232, 1, 1, COLOR(31,0,0));
				drawRectDMA(5, 234, 1, 1, COLOR(31,0,0));
				//newgame = 0;
				}
				
				if((human_health < 100) && (human_health > 66)){
				drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 2/3
				drawRectDMA(5, 6, 1, 1, COLOR(0,0,31));
				drawRectDMA(5, 8, 1, 1, COLOR(0,0,0));
				}

				if((human_health < 66) && (human_health >33)){
				drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 1/3
				drawRectDMA(5, 6, 1, 1, COLOR(0,0,0));
				drawRectDMA(5, 8, 1, 1, COLOR(0,0,0));
				}

				if((human_health < 33) && (human_health >0)){
				drawRectDMA(5, 4, 1, 1, COLOR(0,0,0)); //human health 0/3
				drawRectDMA(5, 6, 1, 1, COLOR(0,0,0));
				drawRectDMA(5, 8, 1, 1, COLOR(0,0,0));
				}

				
				if((comp_health < 100) && (comp_health > 66)){
				drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 2/3
				drawRectDMA(5, 232, 1, 1, COLOR(31,0,0));
				drawRectDMA(5, 234, 1, 1, COLOR(0,0,0));
				}

				if((comp_health < 66) && (comp_health > 33)){
				drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 1/3
				drawRectDMA(5, 232, 1, 1, COLOR(0,0,0));
				drawRectDMA(5, 234, 1, 1, COLOR(0,0,0));
				}

				if((comp_health < 33) && (comp_health > 0)){
				drawRectDMA(5, 230, 1, 1, COLOR(0,0,0)); //computer health 0/3
				drawRectDMA(5, 232, 1, 1, COLOR(0,0,0));
				drawRectDMA(5, 234, 1, 1, COLOR(0,0,0));
				}

				waitForVBlank(ON);

			
			
				//player control
				//controls the boundries and the speed
				drawRectDMA( r, c, width, width, COLOR(0,0,0));
				
				if(keyHit(BUTTON_UP)) {
					r = r - human_speed;
					if(r <= 1) r = 2;
				}
				if(keyHit(BUTTON_DOWN)) {
					r = r + human_speed;
					if(r >= 159+human_size) r = 159;
				}
				if(keyHit(BUTTON_LEFT)) {
					c = c - human_speed;
					if(c <= 1) c = 2;
				}
				if(keyHit(BUTTON_RIGHT)) {
					c = c + human_speed;
					if(c >= 239+human_size) c = 239;
				}
			
						
				//start ball code (makes ball move)
				drawRectDMA( r2, c2, size, size, COLOR(0,0,0) );
				drawRectDMA( r2, c2, size, size, COLOR(0,0,31) );
				
				//collision detection
				//walls (make ball bounce)
			
				//computer bouncing
				
			if((r2+size) > 156) dr = -dr; //top
			if((c2+size) > 236) dc = -dc; //bottom and right
			if((c2+size) < 15) dc = -dc; //left
			if(((r2) <= 3) || ((r2) >= 158)) dr = -dr; //top and bottom
			

				
				//draw player square
				
				drawRectDMA( r, c, human_size, human_size, COLOR(0,0,0));
				
	
				drawRectDMA( r, c, human_size, human_size, COLOR(0,0,31) ); //the actual square

						
				//draw bouncing ball
				drawRectDMA( r2, c2, size, size, COLOR(31,0,0));
				

				//right wall
				drawRectDMA( 1, 238, 72 , width - 1, COLOR(0,0,31) ); 
				drawRectDMA( 87, 238, 73,  width - 1, COLOR(0,0,31) ); 
				
				//keep player in boundries
				if(r < 2) {
					r = 2;
				}
				if(r+size > (159)) {
					r = (148);
				}
				if((c+size > 239)) {
					c = 228;
				}

				if((c < 2)) {
					c = 2;
				}

				//keep computer in boundries
				//the computer boundry is smaller so he doesn't get stuck in corners
				if(r2 < 10) {
					r2 = 10;
				}
				if(r2+size >= (149)) {
					r2 = (138);
				}
				
				if((c2 < 10)) {
					c2 = 10;
				}
				
				if((c2+size > 229)) {
					c2 = 218;
				}


				//BEGIN AI
				

				//if the health is low	
				if((retreatCheck(comp_health,(first.margin)))){
					//retreat
					(int*)(root->child[1]) = 1;
	
				if(r < r2){
					r2 = r2 + 1;
				}

				if(r > r2){
					r2 = r2 - 1;
				}

				if(c < c2){
					c2 = c2 + 1;
				}

				if(c > c2){
					c2 = c2 - 1;
				}
				if(keyHit(BUTTON_A)){
			retreat = retreat + 1;
				}
			}


			//nary tree usage
			tree2 = (int*)(root->child[1]);
				if(tree2){
					junkVar++;
				}



				if(attackCheck(comp_health)){ //if health is ok
					//attack
						(int*)(root->child[0]) = 1;

					if(r < r2){
						r2 = r2 - 1;
					}

					if(r > r2){
						r2 = r2 + 1;
					}

					if(c < c2){
						c2 = c2 - 1;
					}

					if(c > c2){
						c2 = c2 + 1;
					}
				
				
					//see how aggressive the human is being
					agression = numAttacks/inRange;
					//see if the human is within striking distance
						if(inRadius(c2, death_radius, c, human_size, r2, r, size)){ //this function took forever to write

						inRange++;
						result = randGen();
						if(result){
						human_health = human_health - (first.human_health_rate);
						justAttacked++;
						}
					
						//If I ever get around to implementing this, this will allow the computer to retreat
						//when the human gets too aggressive

						/*
						if(agression > .15){
				

				//retreat
					if(r < r2){
						r2 = r2 + 1;
					}

					if(r > r2){
						r2 = r2 - 1;
					}

					if(c < c2){
						c2 = c2 + 1;
					}

					if(c > c2){
						c2 = c2 = 1;
					}

				}
				
			
*/
		
				//set up the health
				//computer (computer loses health under these conditions
					
				if(keyHit(BUTTON_A)){
						comp_health = (comp_health - (first.comp_health_rate));
						numAttacks++;
						
					}
				
			}
				}

				
				if(inRadius(c2, death_radius, c, human_size, r2, r, size)){
						if(retreat >= retreat_length){
					gameState = WIN;
				break;}
						if(human_health < 33){
							gameState = DIE;
							next_var2 = 1;
							break;
						}
				}
				
				break;

			case WIN: //if they make it past level 5, display a win screen and reset some variables
					drawBackground(7);
					if(junkVar){
						newgame = 1;
					}
				retreat = 0;
				if(keyHit(BUTTON_START)) {
					gameState = CREDITS; //next stop is the credits
				
				}
				while(keyHit(BUTTON_START)) {
					while(!keyHit(BUTTON_START)) {
						
					break; }
				next_var1 = 1;}
				
			
			break;

		case CREDITS: //display the Pony Shrapnel logo
				
			if(next_var1 == 1){
				
					drawBackground(8);
					
				
				if(keyHit(BUTTON_START)) {
					gameState = START; //next stop is the start screen
				
				}
				while(keyHit(BUTTON_START)) {
					while(!keyHit(BUTTON_START)) {
					break; }
				}
				}

			

		

		
			case DIE: //if they die, then display a death screen, reset some variables, and go back to the start screen
				
				if(next_var2){
				drawBackground(1);
					if(junkVar){
						newgame = 0;
					}
				
				if(keyHit(BUTTON_START)) {
					gameState = CREDITS2; //next stop is the credits2
				
				}
				while(keyHit(BUTTON_START)) {
					while(!keyHit(BUTTON_START)) {
						
					break; }
				}
				human_health = 100;}
				
			break;


		case CREDITS2: //display the Pony Shrapnel logo
				
			while(next_var2){
				
					drawBackground(8);
					
				
				if(keyHit(BUTTON_START)) {
					gameState = START; //next stop is the start screen
					next_var2 = 0;
				}
				while(keyHit(BUTTON_START)) {
					while(!keyHit(BUTTON_START)) {
					break; }
				}
				break;}

			



				//end switch statements


		
		}

	}
	return 0;
}
Exemplo n.º 6
0
int play()
{
	int score = 0;
	int speed = 1;
	int life = 1;
	int timer = 10;
	int pT = 0;
	char lifes[15];
	char scores[15];

	BIRD bird;
	bird.r = 70;
	bird.c = BIRD_C;

	// loadPalette(pics_palette, PICS_PALETTE_SIZE, 0);
	drawImage4(0, 0, 240, 160, (u16*)background);
	FlipPage();
	drawImage4(0, 0, 240, 160, (u16*)background);

	PIPE pp[4];
	for(int i = 0; i < 4; i++)
	{
		pp[i].r = 10;
		pp[i].c = 219 - i*60;
		pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1);
		pp[i].on = 0;

		if(i == 0)
		{
			pp[i].on = 1;
		}
	}

	int frame = 0;
	while(1)
	{
		if(KEY_DOWN_NOW(BUTTON_SELECT))
		{
			return 0;
		}

		if(KEY_DOWN_NOW(BUTTON_A))
		{
			speed = -5;
		}

		if(timer == 0)
		{
			bird.r += speed;
			speed++;
			timer = 3;
		}
		timer--;
		if(pT == 0)
		{
			pp[0].on = 1;
		}
		else
		{
			pT--;
		}
		if(bird.r < 10)
		{
			bird.r = 10;
		}
		if(bird.r > 149)
		{			
			life--;
			if (life < 0) 
			{
				return LOSE;
			}
			bird.r = 70;
			speed = 1;
			timer = 2;
		}

		for(int i = 1; i < 4; i++)
		{
			if(pp[0].c < 220 - i*60 && !pp[i].on)
			{
				pp[i].c = 219;
				pp[i].on = 1;
			}
		}

		for(int i = 0; i < 4; i++)
		{
			if(pp[i].on)
			{
				pp[i].c -= 1;
				if(bird.c == (pp[i].c + PIPE_W / 2) && pp[i].on)
				{
					score++;
					if(score == 5)
					{
						return WIN;
					}
				}
				if(pp[i].c < 0)
				{
					pp[i].c = 219;
					pp[i].hole = 25 + rand() / (RAND_MAX / (145 - HOLE_L - 25 + 1) + 1);
					pT = 20;
					pp[i].on = 0;
				}
				//collision
				if(bird.c + 14 > pp[i].c && bird.c < pp[i].c + 20 && ((bird.r < pp[i].hole) | (bird.r + 10 > pp[i].hole + HOLE_L)) && pp[i].on)
				{
					life--;
					if (life < 0)
					{
						return LOSE;		
					}
					bird.r = pp[i].hole + 2;
					speed = 1;
					timer = 2;
				}
			}
		}

		drawImage4(0, 0, 240, 160, (u16*)background);
		delay(3);


		//draw pipe
		for(int i = 0; i < 4; i++)
		{
			if(pp[i].on)
			{
				drawPipe(pp[i].r, pp[i].c, pp[i].hole, (u16*)pipes);
			}
		}

		//draw bird
		if(frame % 9 == 0)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0);
		}
		else if(frame % 9 == 1)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1);
		}
		else if(frame % 9 == 2)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2);
		}
		else if(frame % 9 == 3)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3);
		}
		else if(frame % 9 == 4)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4);
		}
		else if(frame % 9 == 5)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5);
		}
		else if(frame % 9 == 6)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6);
		}
		else if(frame % 9 == 7)
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7);
		}
		else
		{
			drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy8);
		}
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy0);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy1);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy2);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy3);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy4);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy5);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy6);
			// drawImage4(bird.r, bird.c, BIRD_W, BIRD_H, (u16*)flappy7);
		sprintf(lifes, "Life: %d", life);
		drawString4(0, 10, lifes, PALETTE[0]);
		sprintf(scores, "Score: %d", score);
		drawString4(0, 170, scores, PALETTE[0]);
		waitForVblank();
		frame++;
		FlipPage();
	}
	return 1;
}