Esempio n. 1
0
void switchTile(Move_t move)
{
	REG_DISPCTL = MODE3 | BG2_ENABLE;

	// get blank tiles current co-ordinates 
	int x_blank = game_grid[0].x_cord;
	int y_blank = game_grid[0].y_cord;

	// calcualte co-ordinates for the tile that you need to switch with the blank tile
	int x_tile = 0;
	int y_tile = 0;
	int tile_to_move = 0;

	if (move == UP)
	{
		x_tile = x_blank;
		y_tile = y_blank - 1;
		// draw black tiles over the 2 tiles you need to move


	} else if (move == DOWN)
	{
		x_tile = x_blank;
		y_tile = y_blank + 1;
	} else if (move == RIGHT)
	{
		x_tile = x_blank + 1;
		y_tile = y_blank;
	} else //(move == LEFT)
	{
		x_tile = x_blank - 1;
		y_tile = y_blank;
	}

	tile_to_move = game_state[x_tile][y_tile];

	// draw black tiles over the 2 tiles you need to move
	WaitForVblank();
	drawRect3(y_cords[y_tile], x_cords[x_tile], TILE1_WIDTH, TILE1_HEIGHT, BLACK);
	drawRect3(y_cords[y_blank], x_cords[x_blank], TILE1_WIDTH, TILE1_HEIGHT, BLACK);

	// draw the two tiles 
	WaitForVblank();
	drawImage3(y_cords[y_tile], x_cords[x_tile], TILE1_WIDTH, TILE1_HEIGHT, game_grid[0].image_data);
	drawImage3(y_cords[y_blank], x_cords[x_blank], TILE1_WIDTH, TILE1_HEIGHT, game_grid[tile_to_move].image_data);		

	// update game_grid
	game_grid[tile_to_move].x_cord = x_blank;
	game_grid[tile_to_move].y_cord = y_blank;

	game_grid[0].x_cord = x_tile;
	game_grid[0].y_cord = y_tile;

	// update game_state
	game_state[x_blank][y_blank] = tile_to_move;
	game_state[x_tile][y_tile] = 9;

}
Esempio n. 2
0
/*
* draws the initial layour of the game
*/
void startGame() {
	state = NORMAL;

	u16 bgcolor = BLACK;
	DMA[3].src = &bgcolor;
	DMA[3].dst = videoBuffer;
	DMA[3].cnt = 38400 | DMA_ON | DMA_SOURCE_FIXED;

	for (int i = 0; i < NUM_RECS; i++) {
		drawRect3(topWall[i].yPos, topWall[i].xPos, topWall[i].width, topWall[i].height, topWall[i].color);
		drawRect3(bottomWall[i].yPos, bottomWall[i].xPos, bottomWall[i].width, bottomWall[i].height, bottomWall[i].color);
	}

}
Esempio n. 3
0
void runInstructions(){
	buttonsIns = BUTTONS;
	if(BUTTON_PRESSED_INS(BUTTON_SELECT)){
		setupSplash();
		stateFunction = runSplash;
	}else if(BUTTON_PRESSED_INS(BUTTON_START)){
		waitForVblank();
		nbr = (nbr +1) %6;
		switch(nbr){
		case 0: drawImage3(ins1Bitmap,0,0,160,240);
		drawString3(140,20,"To return press SELECT", WHITE);
		drawString3(150,20,"To continue press START", WHITE);
		break;
		case 1: drawImage3(ins2Bitmap,0,0,160,240); break;
		case 2: drawImage3(ins3Bitmap,0,0,160,240); break;
		case 3: drawImage3(ins4Bitmap,0,0,160,240); break;
		case 4: drawImage3(ins5Bitmap,0,0,160,240); break;
		case 5: drawRect3(0,0,160,240, BLACK); drawString3(40,20,"To PAUSE at any time press SELECT",WHITE);
		drawString3(50,20,"To return from PAUSE press START",WHITE);
		drawString3(60,20,"To turn cheat ON/OFF press R",WHITE);
		break;
		}
	}
	oldButtonsIns = buttonsIns;
}
Esempio n. 4
0
void zone_gl::drawMisc(unsigned long flags)
{
  if (render)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glLineWidth(2);
   
    if (flags & ZONE_VIEWMODE_VIEWSECTIONS)
    {
      for (int lp = 0; lp < sectionCount; lp++)
        sections[lp]->drawFrom(location, 8);
    }

    //draw a wireframe rectangle that shows zone boundaries
    if (flags & ZONE_VIEWMODE_VIEWBOUNDS)
      drawRect3(bounds, 8);
    
    if (flags & ZONE_VIEWMODE_VIEWCOLLISIONS) 
      drawCollisions();
    
    //drawQuery();
      
    glLineWidth(1);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }
}
Esempio n. 5
0
//Brings mario back to home when wall is it
void home() {
	drawRect3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, CYAN);
	currentPlayer.x = SCREEN_HEIGHT - MARIO_HEIGHT - BOTTOM_BUFFER - 5;
	currentPlayer.y = SCREEN_WIDTH/2 - 20;
	drawImage3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, mario);
	playerSpeed=1;
}
Esempio n. 6
0
//Draws a filled triangle
void drawTriangle3(int r, int c, int side, u16 color) {
	int width = 1, i = 0, j = 0;
	while (width <= side) {
		drawRect3(i+r, j+c, width, 1, color);
		width += 2;
		i++;
		j--;
	}
}
Esempio n. 7
0
//Updates score, lives, speed on bottom of screen
void updateValues() {
	drawRect3(SCREEN_HEIGHT - BOTTOM_BUFFER, 0 , SCREEN_WIDTH, BOTTOM_BUFFER, BLACK);
	sprintf(scoreString, "Score: %d", currentScore);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, 5, scoreString, GREEN);
	sprintf(livesString, "Lives: %d", lives);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, SCREEN_WIDTH - 60, livesString, GREEN);
	sprintf(speedString, "Speed: %d", playerSpeed);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, SCREEN_WIDTH/3 + 20, speedString, GREEN);
}
Esempio n. 8
0
//Initializes score strings, entities
void startGame() {
	state = NORMAL;
	currentPlayer.x = SCREEN_HEIGHT - MARIO_HEIGHT - BOTTOM_BUFFER - 5;
	currentPlayer.y = SCREEN_WIDTH/2 - 20;
	drawRect3(0, 0, 240, 160, CYAN);
	drawRect3(SCREEN_HEIGHT - BOTTOM_BUFFER, 0 , SCREEN_WIDTH, BOTTOM_BUFFER, BLACK);
	drawImage3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, mario);
	sprintf(scoreString, "Score: %d", currentScore);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, 5, scoreString, GREEN);
	sprintf(livesString, "Lives: %d", lives);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, SCREEN_WIDTH - 60, livesString, GREEN);
	sprintf(speedString, "Speed: %d", playerSpeed);
	drawString(SCREEN_HEIGHT - BOTTOM_BUFFER + BOTTOM_BUFFER/5, SCREEN_WIDTH/3 + 20, speedString, GREEN);
	srand(frame);
	frame = 0;
	initSpawned();
	spawnCoin();
	spawnMushroom();
}
Esempio n. 9
0
//Moves items down screen
void moveItemsDown() {
	for(int i=0; i<=10; i++) {
		ITEM* a = &spawned[i];
		if(a->x == SCREEN_HEIGHT - BOTTOM_BUFFER - COIN_HEIGHT) {
			a->alive=0;
			draw();
			a->x = 0;
			a->y = rand() % SCREEN_WIDTH + 1;
		}
		if(a->alive){			
			if(!a->type) {
				drawRect3(a->x, a->y, BOMB_WIDTH, BOMB_HEIGHT, CYAN);
				a->x++;		
			} else {
				drawRect3(a->x, a->y, COIN_WIDTH, COIN_HEIGHT, CYAN);
				a->x++;
			}
		}
	}
	draw();
}
Esempio n. 10
0
//Draws bombs, coins, mushrooms
void draw() {
	for(int i=0; i<=10; i++) {
		ITEM* a = &spawned[i];
		if(!a->alive) {
			if(!a->type) {
				drawRect3(a->x, a->y, BOMB_WIDTH, BOMB_HEIGHT, CYAN);
			}else if(a->type) {
				drawRect3(a->x, a->y, COIN_WIDTH, COIN_HEIGHT, CYAN);
			} else {
				drawRect3(a->x, a->y, MUSHROOM_WIDTH, MUSHROOM_HEIGHT, CYAN);
			}			
		} else {
			if(!a->type) {
				drawImage3(a->x, a->y, BOMB_WIDTH, BOMB_HEIGHT, bomb);
			}else if(a->type==1) {
				drawImage3(a->x, a->y, COIN_WIDTH, COIN_HEIGHT, coin);
			} else {
				drawImage3(a->x, a->y, MUSHROOM_WIDTH, MUSHROOM_HEIGHT, mushroom);
			}	
		}
	}
	drawImage3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, mario);
	drawImage3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, mario);
}
Esempio n. 11
0
//Clears entities on screen and shows end screen
void endGame() {
	state = GAMEOVER;
	for(int i=0; i<=10; i++) {
		ITEM* a = &spawned[i];
		a->x=SCREEN_WIDTH*2;
		a->y=SCREEN_HEIGHT*2;
		a->alive = 0;
	}
	currentPlayer.x = SCREEN_WIDTH*2;
	currentPlayer.y = SCREEN_HEIGHT*2;
	draw();
	drawRect3(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, BLACK);
	drawImage3(0, 0, GAME_OVER_WIDTH, GAME_OVER_HEIGHT, game_over);
	sprintf(scoreString, "Final Score: %d", currentScore);
	drawString(SCREEN_HEIGHT/2 - 15, SCREEN_WIDTH/2 - 45, scoreString, WHITE);
	sprintf(playAgain, "Press 'select' to play again");
	drawString(SCREEN_HEIGHT/2, SCREEN_WIDTH/2 - 85, playAgain, WHITE);
}
Esempio n. 12
0
void instructions() {
    REG_DISPCTL = MODE3 | BG2_ENABLE;
    fillScreen3(COLOR(0,31,31)); 

    drawRect3(0, 0,0,240,160);

    drawString(1, 1, "NERD HERDER!", COLOR(31,31,31));
    drawString(21, 1, "As head TA you control the destiny of", COLOR(31,31,31));
    drawString(31, 1, "scores of students. It takes dedication,", COLOR(31,31,31));
    drawString(41, 1, "strength, and the ability to intimidate.", COLOR(31,31,31));
    drawString(51, 1, "In this game you separate the wheat", COLOR(31,31,31));
    drawString(61, 1, "from the chaff. Intimidate the nerds to", COLOR(31,31,31));
    drawString(71, 1, "their dorm so they'll do their homework.", COLOR(31,31,31));
    drawString(81, 1, "Send the flunkies to the M-Train so they", COLOR(31,31,31));
    drawString(91, 1, "won't bother the rest of us. Also there", COLOR(31,31,31));
    drawString(101, 1, "might be power ups?", COLOR(31,31,31));
    drawString(121, 1, "Press A to return", COLOR(31,31,31));

    while (state == INSTRUCTIONS) {
        key_poll();
        if (key_hit(BUTTON_A))
            state = SPLASH;
    }
}
Esempio n. 13
0
//Moves mario left
void moveLeft() {
	drawRect3(currentPlayer.x, currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, CYAN);
	currentPlayer.y = currentPlayer.y - playerSpeed;
	drawImage3(currentPlayer.x , currentPlayer.y, MARIO_WIDTH, MARIO_HEIGHT, mario);
}
Esempio n. 14
0
int main()
{


    /* Set display control register to Mode 3 and BG2 */
    REG_DISPCTL = MODE3 | BG2_ENABLE;

    //Sets game up
    reset();

    while(FOREVER)
    {
        // Check for paddle movement & collision
        paddle[0].pcol = paddleInputAndCollision(paddle[0].pcol);

        //Ball Movement and Collisions
        ballMovementAndCollision(theBalls, theBricks, paddle[0].pcol, paddle[0].prow, i, k);

        waitForVblank();

        // Erase, Draw New Paddle, and change Paddle position values
        drawRect3(paddle[0].poldrow, paddle[0].poldcol, PHEIGHT, PWIDTH, BLACK);
        drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, paddle[0].color);
        paddle[0].poldrow = paddle[0].prow;
        paddle[0].poldcol = paddle[0].pcol;

        //Loop through each Ball Struct
        for(i=0; i<NUM; i++)
        {
            // Erase old ball & poaddle
            drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls
                      [i].size, BLACK);

            //Checks to see if ball is currently visible and draws it if it is
            if(theBalls[i].visible == 1)
            {
                // Draw new ball & paddle
                drawRect3(theBalls[i].row, theBalls[i].col, theBalls[i].size, theBalls[i].size,
                          theBalls[i].color);
                // Transfer values
                theBalls[i].oldrow = theBalls[i].row;
                theBalls[i].oldcol = theBalls[i].col;
            }
        }

        //Checks to see if all balls have hit the bottom
        for(i = 0; i < NUM; i++)
            ballCount += !theBalls[i].visible;
        if(ballCount == NUM) //Lose if all balls hit the bottom
        {
            //Erases screen elements
            drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, BLACK);
            for(i = 0; i < NUM; i++)
            {
                drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls
                          [i].size, BLACK);
                theBalls[i].visible = 0;
            }
            loseScreen(); //lose screen
            reset(); //reset game
        }

        else //Win if all bricks are hit
        {
            ballCount = 0;
            for(k = 0; k < NUMBRICKS; k++) //Calculates number of bricks hit
            {
                brickCount += !theBricks[k].visible;
            }
            if(brickCount == NUMBRICKS) //Checks to see if all bricks are hit
            {
                //Erase Screen Elements
                drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, BLACK);
                for(i = 0; i < NUM; i++)
                {
                    drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls
                              [i].size, BLACK);
                    theBalls[i].visible = 0;
                }
                winScreen(); //win screen
                reset(); //reset game
            }
            else
                brickCount = 0;
        }

    }
    return 0;
}
Esempio n. 15
0
//calls all the updates and then checks for user button presses and draws everything to the screen.
void runGame() {

	if(state == GAMEOVER) {
		return;
	}

	oldGary = gary;

	updateGary();


	oldMidWall[0] = middleWall[0];
	oldMidWall[1] = middleWall[1];
	oldMidWall[2] = middleWall[2];
	updateMiddle();

	for (int i = 0; i < 3; i++) {
		drawRect3(oldMidWall[i].yPos, oldMidWall[i].xPos, oldMidWall[i].width, oldMidWall[i].height, BLACK);
		drawRect3(middleWall[i].yPos, middleWall[i].xPos, middleWall[i].width, middleWall[i].height, middleWall[i].color);
	}

	for (int i = 0; i < NUM_RECS; i++)
	{
		oldTopWall[i] = topWall[i];
		oldBottomWall[i] = bottomWall[i];
	}

	updateBarriers();

	

	for (int i = 0; i < NUM_RECS; i++) {
		drawRect3(oldBottomWall[i].yPos, bottomWall[i].xPos, bottomWall[i].width, bottomWall[i].height, BLACK);
	}

	for (int i = 0; i < NUM_RECS; i++) {
		drawRect3(bottomWall[i].yPos, bottomWall[i].xPos, bottomWall[i].width, bottomWall[i].height, bottomWall[i].color);
	}



	for (int i = 0; i < NUM_RECS; i++) {
		
		drawRect3(oldTopWall[i].yPos, topWall[i].xPos, topWall[i].width, topWall[i].height, BLACK);

	}

	for (int i = 0; i < NUM_RECS; i++) {
		
		drawRect3(topWall[i].yPos, topWall[i].xPos, topWall[i].width, topWall[i].height, topWall[i].color);
		
	}


	distance += 1;
	sprintf(buffer, "Distance: %d", distance);
	drawString(150, 5, buffer, WHITE);
	drawRect3(0,0,240,20,RED);
	
	drawRect3(oldGary.xPos, oldGary.yPos, 15, 21, BLACK);
	animator(gary.xPos, gary.yPos);
	if(isHit())
		endGame();
	

}
Esempio n. 16
0
void clearGameState()
{
	REG_DISPCTL = MODE3 | BG2_ENABLE;

	drawRect3(0,0, 20, 120, BLACK);
}