Example #1
0
void playGame()
{
    lives = MAX_LIVES;
    score = 0;
    startLevel();
    resetLevel();
    int resetPressed = FALSE;
    // game loop
	while (lives > 0) 
	{
        //test select button release
        if (KEY_DOWN_NOW(BUTTON_SELECT))
        {
            resetPressed = TRUE;
        }
        if (resetPressed && !KEY_DOWN_NOW(BUTTON_SELECT))
        {
            titleScreen();
        }
		waitForVBlank();
        erase();
        updateVars();
        checkOutsideScreen();
        generateObjs();
        draw();
	}
    gameOverScreen();
}
Example #2
0
int main() 
{ 
  setupBoard();
  titleScreen();
  mainRunLoop();
  gameOverScreen();
}
Example #3
0
int main(void) {
	titleScreen();
	initBoard();
	drawBoard();
	VDP_fillTileMapRectInc(VDP_PLAN_A, TILE_ATTR_FULL(PAL3, PRIORITY_LOW, FALSE, FALSE, TILE_USERINDEX + 20), 32, 0, 5, 3);
	while(1) {
		VDP_waitVSync();
	}
	return 0;
}
Example #4
0
int main( void )
{
    while( 1 )
    {
        if( state == TITLE )
            titleScreen();
        if( state == GAME_LOOP )
            gameLoop();
        if( state == GAME_OVER )
            gameOver();
        if( state == WIN )
            game_win();
    }

    return 0;
}
Example #5
0
void gameOverScreen()
{
    drawImage3(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH, (const u16*) img_game_over);
    sprintf(strBuffer, "Score: %d", score);
    drawStringCentered(SCREEN_HEIGHT / 2 + 14, SCREEN_WIDTH / 2, strBuffer, WHITE);
    int keysPressed = 0;
    //game over screen loop
	while (1)
    {
        //test button release for all buttons
        for (int i = 0; i < 10; i++)
        {
            if (KEY_DOWN_NOW(1 << i))
            {
                keysPressed |= (1 << i);
            }
            if ((keysPressed & (1 << i)) && !KEY_DOWN_NOW(1 << i))
            {
                titleScreen();
            }
        }
    }
}
Example #6
0
int main(void)
{
    int i;
	int diceRoll = 0;
	int diceRoll2 = 0;
	int bet = 0;
	int payOut = 0;
	int count = 0;

	u16 myPalette[] = {BLACK, WHITE, RED, GREEN, BLUE}; //Make Colors

	for(i=0; i<16384/2; i++) //Stores Text Tiles
	{
	 CHARBLOCKBASE[1].tileimg[i] = fontdata_8x8[i*2] | (fontdata_8x8[i*2+1]<<8);
	}

	for(i=0; i<1600/2; i++) //Stores Dice Tiles
	{
	 CHARBLOCKBASE[0].tileimg[i] = dice_8x8[i*2] | (dice_8x8[i*2+1]<<8);
	}

	for(i=0; i<5; i++) //Stores Palette Colors
	{
	 PALETTE[i] = myPalette[i];
	}

    REG_DISPCTL = MODE0 | BG0_ENABLE | BG1_ENABLE;
    REG_BG0HOFS = 0;
    REG_BG0VOFS = 0;

    REG_BG0CNT = BG_SIZE0 | SBB(30) | COLOR256 | CBB(0);  //Layer for Dice
    REG_BG1CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(1);  //Layer for Text

    STATE gameState = TITLE; //Sets Initial Game State

    while(1)
    {
    	switch(gameState)
    	{
    	case TITLE:
    		titleScreen();
    		while(KEY_DOWN_NOW(BUTTON_START)){};
			while(!KEY_DOWN_NOW(BUTTON_START))
			{
				count++; //Time Count for Seeding
			}
			srand(count);//Random Seed
    		gameState = CHOOSELINE;
    		clearTextScreen();
    		waitForVblank();
    		break;
    	case CHOOSELINE:
    		chooseLineScreen();
    		//Checks for Bet Type
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}
    		if(KEY_DOWN_NOW(BUTTON_A))
			{
				gameState = PASSLINEBET;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				gameState = DONTPASSLINEBET;
			}
    		while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}
			clearTextScreen();
    		waitForVblank();
    		break;
    	case PASSLINEBET:
    		passLineScreen();
    		//Checks for Bet Amount
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}

			if(KEY_DOWN_NOW(BUTTON_A))
			{
				bet = 5;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				bet = 25;
			}

    		while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}

    		//Rolls Dice and Computes Results
    		putText(12,0,"Bet Accepted");
    		waitForVblank();
    		putText(14,0, "Rolling");
    		waitForVblank();
    		diceRoll = rollDice(18,2,50);
    		waitForVblank();
    		if(diceRoll == 7 || diceRoll == 11)
    		{
    			gameState = WIN;
    		}
    		else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12)
    		{
    			gameState = LOSE;
    		}
    		else
    		{
    			putText(16,0,"Press Start to Roll Again");
    			waitForVblank();
    			while(!KEY_DOWN_NOW(BUTTON_START))
				{
				}
    			diceRoll2 = rollDice(18,9,50);
    			waitForVblank();
    			if(diceRoll == diceRoll2)
    			{
    				gameState = WIN;
    			}
    			else if(diceRoll == 7)
    			{
    				gameState = LOSE;
    			}
    			else
    			{
    				gameState = LOSE;
    			}
    		}
    		putText(12,16,"Press Start");
    		putText(14,16,"to See Result");
    		waitForVblank();
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
    		clearTextScreen();
    		clearMainScreen();
    		waitForVblank();
    		break;
    	case DONTPASSLINEBET:
    		dontPassLineScreen();
    		//Checks for Bet Amount
    		while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){}

			if(KEY_DOWN_NOW(BUTTON_A))
			{
				bet = 5;
			}

			if(KEY_DOWN_NOW(BUTTON_B))
			{
				bet = 25;
			}

			while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){}

			//Rolls Dice and Computes Results
			putText(12,0,"Bet Accepted");
			waitForVblank();
			putText(14,0, "Rolling");
			waitForVblank();
			diceRoll = rollDice(18,2,50);
			waitForVblank();
			if(diceRoll == 7 || diceRoll == 11)
			{
				gameState = LOSE;
			}
			else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12)
			{
				gameState = WIN;
			}
			else
			{
				putText(16,0,"Press Start to Roll Again");
				waitForVblank();
				while(!KEY_DOWN_NOW(BUTTON_START))
				{
				}
				diceRoll2 = rollDice(18,9,50);
				waitForVblank();
				if(diceRoll == diceRoll2)
				{
					gameState = LOSE;
				}
				else if(diceRoll == 7)
				{
					gameState = WIN;
				}
				else
				{
					gameState = WIN;
				}
			}
			putText(12,16,"Press Start");
			putText(14,16,"to See Result");
			waitForVblank();
			while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			clearTextScreen();
			clearMainScreen();
			waitForVblank();
    		break;
    	case WIN:
    		payOut = 2*bet;
    		winScreen(payOut);
    		while(KEY_DOWN_NOW(BUTTON_START)){}
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			gameState = TITLE;
			clearTextScreen();
			waitForVblank();
    		break;
    	case LOSE:
    		loseScreen();
    		while(KEY_DOWN_NOW(BUTTON_START)){}
    		while(!KEY_DOWN_NOW(BUTTON_START))
			{
			}
			gameState = TITLE;
			clearTextScreen();
			waitForVblank();
    		break;
    	}
    }

   return 0;
}
Example #7
0
int main()
{
  memcpy(board2,board,sizeof(int)*rows*columns);
  int height=800,width=800;				//height and width of screen
  gfx_open(width,height,"Pacman");
  gfx_clear_color(0,0,0);
  gfx_clear();
 
  int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board
  int xtopleft=width/2-boardWidth/2;			//x coord of top left corner of board
  int ytopleft=height/2-boardHeight*9/16; 		//y coord of top left corner of board
  char movement;  
  int i,lives=3;//start with 3 lives
  int win=0;
  int active=0;	//this changes depending on number of dots left
  int initialDots=dotsNumber();
  int remainingDots=dotsNumber();
  int score=0;
  int loop[4]={0,0,0,0};
  int frightenLoop[4]={0};
  int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue
  Location pacman;
  Location ghosts[4];// enumerated to blinky, pinky, inky, clyde;
/*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */
  int state[4]={scatter,scatter,scatter,scatter};

while(1){ 
 titleScreen(height,width,ghosts,&pacman,state);
 score=0;
 lives=3;
 win=0;
 for(i=0;i<=3;i++) loop[i]=0;	//reset the game
 resetBoard();
 gfx_wait();
/* This is the gameplay loop, will repeat every time a life is lost */
 while(lives>0){
  gfx_clear();
/* Initialize pacman's location */
  pacman.x=pacman.prevX=7;
  pacman.y=pacman.prevY=12;
  pacman.orientation=right;
/* Initialize ghost's locations */
  for(i=blinky;i<=clyde;i++){state[i]=scatter;}
  
  ghosts[blinky].x=7; 
  ghosts[blinky].prevX=8;
  ghosts[blinky].y=ghosts[blinky].prevY=6;
  ghosts[blinky].orientation=left;

  ghosts[pinky].x=7;
  ghosts[pinky].prevX=7;
  ghosts[pinky].y=7;
  ghosts[pinky].prevY=8;
  ghosts[pinky].orientation=up;
  
  ghosts[inky].x=ghosts[inky].prevX=6;
  ghosts[inky].y=7;
  ghosts[inky].prevY=8;
  ghosts[inky].orientation=right;

  ghosts[clyde].x=ghosts[clyde].prevX=8;
  ghosts[clyde].y=7;
  ghosts[clyde].prevY=8;
  ghosts[clyde].orientation=left; 
 
/* These two statements draw pacman and the board to begin the program */
  drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score);
  drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0);
  for(i=blinky;i<=clyde;i++){
    drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]);
  }

/* This loop is the gameplay after all initialization */
  while(1){
    /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//}
    
  /* This block updates pacman position, checks for death
   * then updates ghosts' positions, then checks for death again */
    movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop);
    if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){	//pacman's death?
	for(i=0;i<=3;i++) loop[i]=0;	//reset the game
	lives--;			//decrease the lives
	printf("LIVES: %i\n",lives);
	break;
    }
    targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state);
    if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){	//pacman's death?
	for(i=0;i<=3;i++) loop[i]=0;	//reset the game
	lives--;			//decrease the lives
	printf("LIVES: %i\n",lives);
	break;
    }
    ghostState(loop,state,frightenLoop);
    active=activeGhosts(ghosts,loop);

/* The next function animates the motion of all of the objects (pacman and ghosts */
    animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]);

/* The case to exit the loop is winning, when there are no dots left */
    if(dotsNumber()==0){	//The player got all the dots, they won the game
	win=1;
	break;
    }
  }
  if(lives<=0){ 
	gfx_clear();
	printf("\n\nGAME OVER\n\n");	
  	drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score);
	if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen
	else break;}
  else if(win){ printf("\n\nWINNER!\n\n");	
	drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score);
	if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game 
	else break;}
  }
 }
}
Example #8
0
int main()
{
	REG_DISPCTL = MODE3 | BG2_ENABLE;
	int scene = 0;
	int frameCounter = 0;
	int timer = 0;
	int winCondition = 0;
	int pressed = 0;
	int pressedLF = 0;
	int next = 0;
	//int timeBuffer[41];
	//int d = 0;
	//int count = 0;
	MOVOBJ ballon = {80, 60, 0, 0, 10, RED};

	while(1) // game loop
	{
		waitForVblank();
		frameCounter++;
		pressedLF = 0;
		if (KEY_DOWN_NOW(BUTTON_SELECT)) {
			fillScreen(BLACK);
			scene = 0;
			ballon.size = 10;
		}

		if (scene == 0) {
			titleScreen();
			drawString(145, 50, "Press <ENTER> to Start", RED);
			if (KEY_DOWN_NOW(BUTTON_START)) {
				scene = 1;
				timer = 1;
				fillScreen(BLACK);
			}
		}
		if (scene == 1) {
			drawRect(ballon.row, ballon.col, ballon.size, ballon.size, RED);
			drawString(130,80, "Press A!!!", RED);
			drawString(20, 50, "Blow up the balloon!", RED);

			if (timer % 3 == 0) {
				if (winCondition == 0) {
					scene = 500;
					fillScreen(BLACK);
					gameOver();
					timer = 1;
					winCondition = 0;
				}
			}
			if (KEY_DOWN_NOW(BUTTON_A) && pressedLF == 0) {
				ballon.size = ballon.size + 1;
				pressedLF = 1;
			}
			if (ballon.size == 50) {
				winCondition = 0;
				scene = 700;
				fillScreen(BLACK);
				scene = 2;
			}
		}

		if (scene == 2) {
			drawString(10, 80, "Eat the cake!", WHITE);
			if (timer == 2) {
				//drawCake();
			}
			next = playLevel2();
			if (timer % 4 == 0) {
				if (winCondition == 0) {
					scene = 500;
					drawRect(0,0,240, 160, BLACK);
					gameOver();
					timer = 1;
				}
			}
			if (next == 1) {
				scene = 700;
				fillScreen(BLACK);
				winScreen();
			}
		}
		if (scene == 500) {
			//gameOver();
			drawString(145, 50, "Better Luck Next Time!", RED);
			pressed = 0;
		}
		if (scene == 700) {
			drawString(30, 50, "Fine! You beat me...", RED);
			pressed = 0;
		}
		if (frameCounter % 160 == 0) {
			timer++;
		}
	}
}
Example #9
0
int game() {
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_TIMER *timer = NULL;

	bool exit = false;

	if (!al_init()) {
		fprintf(stderr, "Allegro could not be initialized.");
		return -1;
	}

	if (!al_install_keyboard()) {
		fprintf(stderr, "Keyboard could not be initialized.");
		return -1;
	}

	if (!al_install_audio()){
		fprintf(stderr, "Audio could not be initialized.");
		return -1;
	}

	if (!al_reserve_samples(1)){
		fprintf(stderr, "Samples could not be reserved.");
		return -1;
	}
	if (!al_init_acodec_addon()) {
		fprintf(stderr, "Audio codecs could not be initialized.");
		return -1;
	}

	al_init_primitives_addon();
	al_init_image_addon();

	al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
	al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);

	display = al_create_display(SCREEN_W, SCREEN_H);
	if (!display) {
		fprintf(stderr, "Display could not be created.");
		return -1;
	}

	timer = al_create_timer(1.0 / FPS);
	if (!timer) {
		fprintf(stderr, "Timer could not be created.");
		return -1;
	}

	al_set_target_bitmap(al_get_backbuffer(display));

	eventQueue = al_create_event_queue();
	if (!eventQueue) {
		fprintf(stderr, "Event queue could not be created.");
		return -1;
	}

	yaySound = al_load_sample("yay.wav");
	naySound = al_load_sample("nay.wav");
	hitSound = al_load_sample("hit.wav");


	al_register_event_source(eventQueue, al_get_display_event_source(display));
	al_register_event_source(eventQueue, al_get_timer_event_source(timer));
	al_register_event_source(eventQueue, al_get_keyboard_event_source());

	al_clear_to_color(al_map_rgb(10, 10, 10));

	al_flip_display();

	al_start_timer(timer);

	// Open menu.
	titleScreen();

	al_destroy_timer(timer);
	al_destroy_display(display);
	al_destroy_event_queue(eventQueue);

	return 0;
}
Example #10
0
void Game::titleScreen()
{
    Object titleScreen(10,5);
    Object pStart(15, 18);
    titleScreen.Frame(1);
    int i                = 0;
    int pressStartEffect = 0;

    if (HEARTBEAT_THEME) pressStartEffect = 3;
    else pressStartEffect = 50;

    int done = false;

    while (titleScreen.Frame() < 57 && !done) // draw zoom animation of title
    {
        ticks = GetTickCount();
        console.clear();
        titleScreen.draw(title);
        titleScreen.Frame(titleScreen.Frame()+1);
        titleScreen.x(titleScreen.x()+1);

        if (GetKeyState(VK_RETURN) & 0x80) done = true;

        if (1000/FPS > GetTickCount()-ticks)
        {
            Sleep(1000/FPS-(GetTickCount()-ticks));
        }
    }

    done = false;
    console.clear();
    if (!HEARTBEAT_THEME) Sleep(200);

    titleScreen.x(10);
    titleScreen.y(5);
    titleScreen.Frame(0);

    while (!done)
    {
        ticks = GetTickCount();

        if (HEARTBEAT_THEME) heartBeat();

        if (i == 0)
        {
            titleScreen.draw(title);
            pStart.draw(pressStart);
        }
        if (i == pressStartEffect/2)
        {
            console.clear();
            titleScreen.draw(title);
        }

        if (i < pressStartEffect) i++;
        else i = 0;

        if (GetKeyState(VK_RETURN) & 0x80) done = true;

        if (1000/FPS > GetTickCount()-ticks)
        {
            Sleep(1000/FPS-(GetTickCount()-ticks));
        }
    }
}