Example #1
0
void display_playinfo(SDL_Surface *virtualscreen, int player, plane &p, int y,
                      shape images[319], int mission, int targetscore,
                      SDLfont &whitefont, SDLfont &greenfont, gamedata &g){

  // Display player
  SDL_Rect rect;

  if(g.players == 1){
	  rect.x = 0;
	  rect.y = y;
	  rect.w = 16;
	  rect.h = 16;
	  SDL_FillRect(virtualscreen,&rect,16);
	  images[p.image+13].blit(virtualscreen,0,y);
  }
  else{
/*
	  rect.x = 0;
	  rect.y = y - 5;
	  rect.w = 16;
	  rect.h = 16;
	  SDL_FillRect(virtualscreen,&rect,16);
	  images[p.image+13].blit(virtualscreen,0,y - 5);
*/
  }
  char playerstring[] = "Player x";
  playerstring[7] = '0' + player;
  whitefont.write(virtualscreen, 24, y, playerstring);
  // Display score
  display_score(virtualscreen, p, 112, y, mission, targetscore, whitefont, greenfont);
  if(g.players == 1){
	  // Display shots
	  images[114].blit(virtualscreen,246 - 24,y+6);
	  char shotstring[] = "xx";
	  shotstring[0] = '0' + (p.ammo / 10);
	  shotstring[1] = '0' + (p.ammo % 10);
	  whitefont.write(virtualscreen, 256 - 24, y + 4, shotstring);
	  // Display bombs
	  images[119].blit(virtualscreen,285 - 24,y+5);
	  char bombstring[] = "xx";
	  bombstring[0] = '0' + (p.bombs / 10);
	  bombstring[1] = '0' + (p.bombs % 10);
	  whitefont.write(virtualscreen, 296 - 24, y + 4, bombstring);
  }
  else{
	  // Display shots
	  images[114].blit(virtualscreen,246 - 24,y + 2);
	  char shotstring[] = "xx";
	  shotstring[0] = '0' + (p.ammo / 10);
	  shotstring[1] = '0' + (p.ammo % 10);
	  whitefont.write(virtualscreen, 256 - 24, y, shotstring);
	  // Display bombs
	  images[119].blit(virtualscreen,285 - 24,y + 1);
	  char bombstring[] = "xx";
	  bombstring[0] = '0' + (p.bombs / 10);
	  bombstring[1] = '0' + (p.bombs % 10);
	  whitefont.write(virtualscreen, 296 - 24, y, bombstring);
  }

}
Example #2
0
int main(void) {
  uint8_t p1Score = 0;
  uint8_t p2Score = 0;

  Button p1Button = new_button(P1BUTTON);
  Button p2Button = new_button(P2BUTTON);

  DDRB |= (1 << BUTTONLED);
  DDRB |= (1 << WINLED); // temp

  PORTB |= (1 << P1BUTTON) | (1 << P2BUTTON);
  PORTB &= ~(1 << WINLED); // temp

  CLKPR=_BV(CLKPCE);
  CLKPR=0;

  TCCR1 |= (1 << CS10) | (1 << CS11);// | (1 << CS12 ) || (0 << CS13);
  TCNT1 = 0;

  while (1) {
    // Poll buttons for scoring
    switch (button_tick(p1Button)) {
      case SinglePress:
        p1Score++;
        break;
      default:
        break;
    }

    switch (button_tick(p2Button)) {
      case SinglePress:
        p2Score++;
        break;
      default:
        break;
    }


    // Update score display
    display_score(p1Score, p2Score);


    // Check for a game win scenario
    if ((p1Score >= 11 || p2Score >= 11) && abs(p1Score - p2Score) >= 2) {
      // Game is over
      PORTB |= (1 << WINLED); // temp
    }


    // _delay_ms(10);
  }
  return (0);
}
Example #3
0
void
ask_user (piece_info_t *obj)
{
	char c;

    for (;;) {
	display_loc_u (obj->loc); /* display piece to move */
	describe_obj (obj); /* describe object to be moved */
	display_score (); /* show current score */
	display_loc_u (obj->loc); /* reposition cursor */

	c = get_chx (); /* get command from user (no echo) */
	switch (c) {
	case 'Q': user_dir (obj, NORTHWEST); return;
	case 'W': user_dir (obj, NORTH); return;
	case 'E': user_dir (obj, NORTHEAST); return;
	case 'D': user_dir (obj, EAST); return;
	case 'C': user_dir (obj, SOUTHEAST); return;
	case 'X': user_dir (obj, SOUTH); return;
	case 'Z': user_dir (obj, SOUTHWEST); return;
	case 'A': user_dir (obj, WEST); return;

	case 'J': edit (obj->loc); reset_func (obj); return;
	case 'V': user_set_city_func (obj); reset_func (obj); return;

	case ' ': user_skip (obj); return;
	case 'F': user_fill (obj); return;
	case 'I': user_set_dir (obj); return;
	case 'R': user_random (obj); return;
	case 'S': user_sentry (obj); return;
	case 'L': user_land (obj); return;
	case 'G': user_explore (obj); return;
	case 'T': user_transport (obj); return;
	case 'U': user_repair (obj); return;
	case 'Y': user_armyattack (obj); return;

	case 'B': user_build (obj); break;
	case '?': help (help_user, user_lines);; break;
	case 'K': user_wake (obj); break;
	case 'O': user_cancel_auto (); break;
	case '\014':
	case 'P': redraw (); break;
	case '=': describe_obj (obj); break;

	default: alert();
	}
    }
}
Example #4
0
// --------- Do not submit the following functions --------- // 
void simple_timer() {
	Game game;
	setup_score(&game);
	
	while (!game.over) {
		if (update_score(&game)) {
			clear_screen();
			display_score(&game);
			show_screen();
		}
		
		timer_pause(100);
	}
	
	timer_pause(1500);
}
Example #5
0
void play( void )
{
	ende=0;
	display_field();
	new_stone();
	display_stone();
	while (!ende)
	{
		move_stone();
		display_stone();
		fall_stone();
		clear_line();
		display_score();
		check_ende();
		delay(zeit);
	}
}
Example #6
0
void waiting_for_other_player(DECK card[], int cardNumberOnScreen, PLAYER usr [],int myPlayerNumber){
        int i;
        char game_table[50]="grafik/casino_betlight_off.bmp";
        SDL_Surface* table_lightsOff_img = NULL;  //Loaded converted table image
        table_lightsOff_img=loadSurface(game_table);
        SDL_BlitSurface(table_lightsOff_img, NULL, screen, NULL);
        SDL_FreeSurface(table_lightsOff_img);
        for(i=0;i<3;i++) {
            display_score(usr,i); // display user and dealer score
        }
        for(i=0;i<cardNumberOnScreen+1;i++) {
            card[i].card_img = SDL_LoadBMP(card[i].path);
            SDL_BlitScaled(card[i].card_img, NULL, screen, &card[i].CardPos);
            SDL_FreeSurface(card[i].card_img);
        }
        display_bet_holding(usr,card,myPlayerNumber,cardNumberOnScreen);
}
Example #7
0
void loose2(){
	effect_reset();
	int j;
	for(j=0;j<snakelen*5+50; j++){
		if(j%5==0 && j<snakelen*5){
			effect_create(EFFECT_TYPE_STROBE , snake[j/5], -63-32*(sin(j/5)+1),0,-32*(sin(j/5+3.14159)+1), 2, j, 30); 
			effect_create(EFFECT_TYPE_FADEIN , snake[j/5], -63-32*(sin(j/5)+1),0,-32*(sin(j/5+3.14159)+1), 2, j, 30); 
			effect_create(EFFECT_TYPE_DELAY , snake[j/5], -63-32*(sin(j/5)+1),0,-32*(sin(j/5+3.14159)+1), 2, j+30, snakelen*5+50); 
		}
		snake_draw();
		effect_draw(j);
		blit();
		update();
		//usleep(10000);
	}
	calc_score();
	display_score();
	welcome();
}
Example #8
0
/**
* Main game cycle, handles user interaction and checks if game is over
*/
void Game::play() {

	// run indefinitely
	while (1) {
		auto b1 = new Board();
		auto b2 = new Board();
		srand(time(NULL)); //random seed set as current time

		int game_over = 0;
		int winner;

		while (!game_over) {
			display_help();
			display_score(b1, b2);

			// if any board needs a piece, add it
			if (b1->needs_piece) {
				int next = rand() % 7;
				Piece new_piece(next);
				if (b1->is_collision(new_piece)) {
					game_over = 1;
					winner = 2;
				}
				b1->set_curr_piece(new_piece);
			}

			if (b2->needs_piece) {
				int next = rand() % 7;
				Piece new_piece(next);
				if (b2->is_collision(new_piece)) {
					game_over = 1;
					winner = 1;
				}
				b2->set_curr_piece(new_piece);
			}

			Piece current1 = b1->get_curr_piece(), potential1;
			Piece current2 = b2->get_curr_piece(), potential2;
			char move;

			// draw boards
			b1->draw(b2);

			move = wait_for_char(WAIT_TIME); // wait for input

			// quit immediatly
			if (move == 'q') {
				winner = 1;
				break;
			}

			if (move == 'w') {
				current1.move(UP);
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}
			else if (move == 's') {
				current1.move(DOWN);
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}
			else if (move == 'a') {
				current1.rotate();
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}

			else if (move == 'i') {
				current2.move(UP);
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}
			else if (move == 'k') {
				current2.move(DOWN);
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}
			else if (move == 'l') {
				current2.rotate();
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}

			// check if current piece of the boards has completely fallen
			potential1 = current1;
			potential2 = current2;


			potential1.move(RIGHT);
			if (!b1->is_collision(potential1))
				b1->set_curr_piece(potential1);
			else {
				b1->add_piece(current1);
				b1->needs_piece = true;
			}

			potential2.move(RIGHT);
			if (!b2->is_collision(potential2))
				b2->set_curr_piece(potential2);
			else {
				b2->add_piece(current2);
				b2->needs_piece = true;
			}

			int adjust1 = b1->delete_needed_lines();
			int adjust2 = b2->delete_needed_lines();

			// for each deleted line adjust the base of the boards accordingly 
			for (int i = 0; i < adjust1; i++)
			{
				b1->adjust_middle(DOWN);
				b2->adjust_middle(UP);
			}

			for (int i = 0; i < adjust2; i++)
			{
				b2->adjust_middle(DOWN);
				b1->adjust_middle(UP);
			}
		}

		// ask for input, if input is 'y' start another game
		cout << "\nPlayer " << winner << " WINS!\n\n";
		cout << "Play again? (Y or N)\n";
		char resume = getch();
		if (resume == 'n')
			break;

	}
}
Example #9
0
void drawall(gamedata &g){

  int ypos;
  int ypos2;

  // Set screenheight
  int screenheight = 0;
  if (g.players == 1){
    screenheight = limit(GAME_HEIGHT,GAME_HEIGHT,240); //464);
  }else{
    screenheight = limit(GAME_HEIGHT,GAME_HEIGHT,120);
  }

  if(!g.scoreBarPos) // top
  {
	ypos = 0;
	ypos2 = 8;
  }
  else // bottom
  {
	ypos = screenheight - 16;
	ypos2 = screenheight - 8;
  }

  // Player 1
//  int x1 = limit(int(g.player1->x)-308, 0, GAME_WIDTH-320);
  int x1 = limit(int(g.player1->x)-160, 0, GAME_WIDTH-320);
  int y1 = limit(int(g.player1->y)-54, 0, GAME_HEIGHT-screenheight);
  SDL_Rect srcrect;
    srcrect.x = x1;
    srcrect.y = y1;
    srcrect.w = 320;
    srcrect.h = screenheight;
  SDL_BlitSurface(g.gamescreen, &srcrect, g.virtualscreen, NULL);
  SDL_Rect cliprect;
    cliprect.x = 0;
    cliprect.y = 0;
    cliprect.w = 320;
    cliprect.h = screenheight;
  SDL_SetClipRect(g.virtualscreen, &cliprect);
  drawblits(g,x1,y1);
  SDL_SetClipRect(g.virtualscreen, NULL);

  if (g.players == 1){
  if(GameState == STATE_GAME)
//	  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight - 16, g.images, g.mission,
//                   g.targetscore, g.whitefont, g.greenfont, g);
	  display_playinfo(g.virtualscreen, 1, *g.player1, ypos, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
  }else{
  if(GameState == STATE_GAME)
	  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight - 8, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
  }

/*
  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
*/

  // Player 2
  if (g.players == 2){
    int x2 = limit(int(g.player2->x)-160, 0, GAME_WIDTH-320);
    int y2 = limit(int(g.player2->y)-54, 0, GAME_HEIGHT-screenheight);//-208); //224);
    SDL_Rect srcrect;
      srcrect.x = x2;
      srcrect.y = y2;
      srcrect.w = 320;
      srcrect.h = screenheight;
    SDL_Rect desrect;
      desrect.x = 0;
      desrect.y = 120;
      desrect.w = 320;
      desrect.h = screenheight;
    SDL_BlitSurface(g.gamescreen, &srcrect, g.virtualscreen, &desrect);
    SDL_Rect cliprect;
      cliprect.x = 0;
      cliprect.y = 120;
      cliprect.w = 320;
      cliprect.h = screenheight;
    SDL_SetClipRect(g.virtualscreen, &cliprect);
    drawblits(g,x2,y2-120);
    SDL_SetClipRect(g.virtualscreen, NULL);

    if(GameState == STATE_GAME)
  	  display_playinfo(g.virtualscreen, 2, *g.player2, 240 - 8, g.images, g.mission,
                     g.targetscore, g.whitefont, g.greenfont, g);
/*
    display_playinfo(g.virtualscreen, 2, *g.player2, 464, g.images, g.mission,
                     g.targetscore, g.whitefont, g.greenfont, g);
*/
  }

  if(GameState == STATE_INTRO || GameState == STATE_MENU)
  {
	if(CurrentMenu == MenuMainIntro)
		menuDraw(CurrentMenu, 140, 100, g);
	else if(CurrentMenu == MenuMain)
		menuDraw(CurrentMenu, 120, 100, g);
	else if(CurrentMenu == MenuOptions)
		menuDraw(CurrentMenu, 110, 100,g);
	else if(CurrentMenu == MenuGameOptions)
		menuDraw(CurrentMenu, 20, 80, g);
	else
		menuDraw(CurrentMenu, 140, 100, g);
  }
  else if(GameState == STATE_MENU_PLANE_SELECT)
  {
	menuPlanesDraw(20, 10, g);
  }
  else if(GameState == STATE_MENU_PLAYER_CONTROL_SELECT)
  {
	menuSelectPlayerDraw(g);
  }

  // Best AI Score
  if (g.planes > g.players){
    plane bestp;
    bool found = false;
    g.p.reset();
    while (g.p.next()){
      if ((g.p().control == 0) && (g.p().side > 0)){
        if (!found){
          bestp = g.p();
          found = true;
        }else{
          if ((g.mission == 0) || (g.mission == 1)){
            if (g.p().score > bestp.score){
              bestp = g.p();
            }
          }else{
            if (g.p().targetscore < bestp.targetscore){
              bestp = g.p();
            }          
          }
        }
      }
    }
    // Display AI
    if(GameState == STATE_GAME){
	    SDL_Rect rect;
	    char compstring[] = "Plane x";
	    compstring[6] = '0' + bestp.side;

	    if (g.players == 1){
	        rect.x = 304;
	        rect.y = ypos;
	        rect.w = 16;
	        rect.h = 16;
	        SDL_FillRect(g.virtualscreen,&rect,16);
	        g.images[bestp.image+13].blit(g.virtualscreen,304,ypos);
		g.whitefont.write(g.virtualscreen, 24, ypos2, compstring);
	    }
	    else{
		// TODO: display the best player score
	    }
	    // Display score
	    if (g.players == 1){
	    display_score(g.virtualscreen, bestp, 112, ypos2, g.mission, g.targetscore,
		          g.whitefont, g.greenfont);
	    }else{
	    display_score(g.virtualscreen, bestp, 112, screenheight-8, g.mission, g.targetscore,
		          g.whitefont, g.greenfont);
	    }
    }

  }

  // Update screen display
  SDL_Rect rect;
    rect.x = 0;
    rect.y = 0;
    rect.w = 320;
    rect.h = 240;
  SDL_BlitSurface(g.virtualscreen, &rect, g.physicalscreen, NULL);

  //SDL_Flip(g.physicalscreen);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_LockSurface(ScreenSurface);
		SDL_Surface *p = SDL_ConvertSurface(g.physicalscreen, ScreenSurface->format, 0);
		SDL_SoftStretch(p, NULL, ScreenSurface, NULL);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_UnlockSurface(ScreenSurface);
		SDL_Flip(ScreenSurface);
		SDL_FreeSurface(p);
  //SDL_UpdateRect(g.physicalscreen, 0, 0, 0, 0);

  g.sound.update();

}
Example #10
0
int main(int argc, char *argv[])
{
    WINDOW *my_win, *score;
    WINDOW **car;
    game newGame, tmpGame;
    MEVENT event;

    int ch = 0, choosenCar = -1, soluce_move = 0;
    char message[1024];
    bool quit = false;
    bool show_solution = false;
    gameStruct *resultSolv = NULL;
    //INIT
    setup();
    //END INIT
    //Wait for good size
    wait_for_size(MINH, MINW);
    //Instruction
    show_instruction(MINH, MINW);
    while (!quit) {
        quit = false;
        show_solution = false;
        soluce_move = 0;
        strcpy(message, "Playing");
        //Select game
        newGame = select_game();
        //Check for level file
        if (handle_level(&tmpGame)) {
            delete_game(newGame);
            newGame = tmpGame;
            MAXCOL = game_width(newGame);
            MAXROW = game_height(newGame);
            MINH = MAXROW * SIZE + 2;
            MINW = MAXCOL * SIZE;
        }
        car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame));
        //First draw
        draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        //Loop while the game is not finished
        while (!game_over(newGame)) {
            //Print on bottom of grid
            mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :");
            ch = getch();
            if (ch == 's' && !show_solution) {
                show_solution = true;
                strcpy(message, "Solution");
                resultSolv = solv(newGame, gameOverRh,true);
                if(!resultSolv){
                    strcpy(message, "No solution");
                    show_solution=false;
                }
            }
            if (show_solution) {
                newGame = play_solution(newGame, resultSolv, soluce_move++);
            } else {
                if (KEY_MOUSE == ch) {
                    /* Mouse event. */
                    if (OK == getmouse(&event)) {
                        choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame));
                    }
                } else {
                    if (ch == 'q') {
                        quit = true;
                        break;
                    }
                    play_input(newGame, ch, &choosenCar);
                }
            }
            wait_for_size(MINH, MINW);
            erase_game(newGame, my_win, car, score);
            draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        }
        if (!quit) {
            display_score(newGame);
        }
        for (int i = 0; i < game_nb_pieces(newGame); i++) {
            destroy_win(car[i]);
        }
        destroy_win(my_win);
        destroy_win(score);
        free(car);
        delete_game(newGame);
        if (resultSolv != NULL) {
            delete_game(resultSolv->current);
            free(resultSolv->move);
            free(resultSolv);
            resultSolv = NULL;
        }
    }
    endwin(); /* End curses mode		  */
    return 0;
}
Example #11
0
bool loadMedia(DECK card[], int cardNumberOnScreen, PLAYER usr [],int myPlayerNumber){
    //Loading success flag
    bool success = true;
    int i=0;
    // ------------------------------ LOAD BUTTONS AND GAMEBOARD ---------------------------------
    if (running==true){
        char game_table[50]="grafik/casino_betlight_off.bmp", hit_button[50]="grafik/hit_button.bmp",stand_button[50]="grafik/stand_button.bmp";
        SDL_Surface* table_lightsOff_img = NULL;        //Loaded converted table image
        SDL_Surface* hit_img = NULL;          //Loaded converted hit button image
        SDL_Surface* stand_img = NULL;        //Loaded converted stand button image
        table_lightsOff_img=loadSurface(game_table);
        hit_img=loadSurface(hit_button);
        stand_img=loadSurface(stand_button);
        SDL_Rect    hit_Rect;
        SDL_Rect    stand_Rect;
        hit_Rect.x=490;
        hit_Rect.y=530;
        hit_Rect.w=98;
        hit_Rect.h=49;
        stand_Rect.x=610;
        stand_Rect.y=530;
        stand_Rect.w=98;
        stand_Rect.h=49;
        SDL_BlitSurface(table_lightsOff_img, NULL, screen, NULL);
        SDL_BlitScaled(hit_img, NULL, screen, &hit_Rect);       // hit button
        SDL_BlitScaled(stand_img, NULL, screen, &stand_Rect);   // stand button
        SDL_FreeSurface(hit_img); // Frigör bild för hit-knapp bordet.
        SDL_FreeSurface(stand_img); // Frigör bild för stand-knapp bordet.
        SDL_FreeSurface(table_lightsOff_img);
        }
    if (running==false){
        char bet_table[50]="grafik/casino_betlight_on.bmp",bet_button[50]="grafik/bet_button.bmp";
        SDL_Surface* table_lightsOn_img = NULL;        //Loaded converted table image
        SDL_Surface* bet_img= NULL;
        table_lightsOn_img=loadSurface(bet_table);
        bet_img=loadSurface(bet_button);
        SDL_Rect    bet_Rect;
        bet_Rect.x=550;
        bet_Rect.y=530;
        bet_Rect.w=98;
        bet_Rect.h=49;
        SDL_BlitSurface(table_lightsOn_img, NULL, screen, NULL);
        SDL_BlitSurface(bet_img, NULL, screen, &bet_Rect);
        SDL_FreeSurface(table_lightsOn_img);
        SDL_FreeSurface(bet_img);
    }
    // ----------------------------------------------------------------------------------------------
    if (running==true){
        for(i=0;i<3;i++) {
            display_score(usr,i); // display user and dealer score
        }
    }
    for(i=0;i<cardNumberOnScreen+1;i++) {
        card[i].card_img = SDL_LoadBMP(card[i].path);
        SDL_BlitScaled(card[i].card_img, NULL, screen, &card[i].CardPos);
        SDL_FreeSurface(card[i].card_img);
    }

    SDL_UpdateWindowSurface(window);
    display_bet_holding(usr,card,myPlayerNumber,cardNumberOnScreen);
    return success;
}