Ejemplo n.º 1
0
static void
score_start(ScoreStyleList style, guint x, guint y, guint max)
{
  max_score = max;
  set_button(BUTTON_SCORE, TRUE);
  update_score(0);
}
Ejemplo n.º 2
0
void		step_game(t_context *gamestate, int key)
{
	WINDOW	*window;
	int		condition;

	if (!gamestate->is_running)
	{
		if (key == KEY_RETURN)
			new_game(gamestate);
	}
	else
	{
		if ((condition = get_input(gamestate, key)) != -1)
		{
			update_grid(gamestate);
			update_score(gamestate);
			if (condition == 1)
			{
				window = gamestate->windows[HIGHSCORES];
				mvwaddstr(window, 8, 2, "U R TEH WINRARZ!!");
				wrefresh(window);
				gamestate->is_running = 0;
				free(gamestate->grid);
			}
		}
	}
}
Ejemplo n.º 3
0
static void draw_first()
{
	GrLine(invaders_wid,invaders_gc, 0, screen_info.rows-HEADER_TOPLINE-2-4,
		screen_info.cols-1, screen_info.rows-HEADER_TOPLINE-2-4);
	update_score();
	onetime=0;
}
Ejemplo n.º 4
0
order_result_t trash_water_treatment(void){
  ROME_LOG(&rome_paddock,INFO,"Trashing water in treatment area");
  order_result_t or;
  set_speed(RS_FAST);

  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_PREPARE_TRASH_TREATMENT);
  _wait_meca_ground_clear();

  //store nb balls for scoring purpose
  uint8_t balls_loaded = robot_state.cylinder_nb_bad;

  //push away the cubes in front of treatment area
  //the angle is changed to avoid pushing cubes towards recyling area
  float angle = arfast(TEAM_SIDE_VALUE(ROBOT_SIDE_BACK, ROBOT_SIDE_BALLEATER), TABLE_SIDE_MAIN);

  or = goto_pathfinding_node(PATHFINDING_GRAPH_NODE_MIDDLE_BOT, angle);
  if (or != ORDER_SUCCESS)
    return or;

  //go in position to trash the bad water
  or = goto_xya(KX(-250),250+130, arfast(ROBOT_SIDE_TURBINE,TABLE_SIDE_DOWN));
  if (or != ORDER_SUCCESS)
    return or;
  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_TRASH_TREATMENT);
  _wait_meca_ground_clear();
  update_score(10*balls_loaded);

  or = goto_xya(KX(-250), 400, arfast(ROBOT_SIDE_TURBINE, TABLE_SIDE_DOWN));

  set_speed(RS_NORMAL);
  return or;
}
Ejemplo n.º 5
0
int main(void)
{
    initialize();
    init_matrix(column);
    update_score(0, 0);
	game(); 
    return 0;
}
Ejemplo n.º 6
0
void player_release_layers(PLAYER *player)
{
    char *source, *target;
    int  mask;
    int  capacity = BoardDepth * BoardWidth;
    int  source_count, released_count;
    const static int release_bonus[4] =
    { 100, 300, 600, 1000};


    source_count = BoardHeight;
    released_count = 0;

    source = target = player->board;
    mask = player->released_details;

    while(--source_count >= 0)
    {
        if (mask & 1)
            released_count++;
        else
        {   if (target != source)
                memmove(target, source, capacity);


            target += capacity;
        }

        mask >>= 1, source += capacity;
    }


    source_count = released_count;

    while(--source_count >= 0)
    {   memset(target, '\0', capacity);
        target += capacity;
    }


    player->tile_code = 0;
    memset(player->tile_pos, '\0', sizeof(short)*Dimension);
    memset(player->tile_size, '\0', sizeof(short)*Dimension);

    player->layers += released_count;
    player->released_details = released_count;

    if (released_count)
    {   if(player->type == 0) player->status |= PLST_DELAY;
        draw_board(PT_FOREGROUND, player, 0);
        player->status &= ~PLST_DELAY;
    }

    /*    player->score += released_count * 100; */
    player->score += release_bonus[released_count-1];
    update_score(PT_FOREGROUND, player->score, player->layers);

}
Ejemplo n.º 7
0
int main(int argc, char* argv[]){

    update_time("5:00");

    update_score(1, 9000);

    update_name(3, "Billy");

}
Ejemplo n.º 8
0
void new_game(void) {
	char c = 0;
	cancel_software_timer(foodTimerNum);
	cancel_software_timer(ratsTimerNum);
	empty_display();

	//wait for space
	while(c != ' ' && c != 'l' && c != 'L'){
		if(input_available())
			c = fgetc(stdin);

		if(c == 'M' || c == 'm'){
			toggle_sound();
			display_sound_status();
			c = 0;
		}
	}
	
	init_display();
	
	if(c == 'l' || c == 'L'){
		if(load_state())
			render_board();
		else {
			/* Initialise internal representations. */
			init_board();
			init_score();
		}
	}
	else {
		/* Initialise internal representations. */
		init_board();
		init_score();
	}
	clear_terminal();

	//Place scores
	update_score();

	//place sound status
	display_sound_status();

	show_instruction(PLAYING);

	/* Make food blink 5 times a second. We should call blink_food
	** 10 times a second which is 100ms
	*/
	foodTimerNum = execute_function_periodically(BLINKRATE, blink_food);
	ratsTimerNum = execute_function_periodically(RATSPEED, move_rats);

	/* Debug *
	move_cursor(0, TITLEY-1);
	printf_P(PSTR("new_game %u"), get_score());
	wait_for(1000);
	//*/
}
Ejemplo n.º 9
0
void Reversi::clear_board(){							//sets board to starting state of game
	for(unsigned int i=0; i<8; i++)
		for(unsigned int j=0; j<8; j++)
			board[i][j] = 'o';
	board[3][3] = 'w';
	board[3][4] = 'b';
	board[4][3] = 'b';
	board[4][4] = 'w';
	update_score();									//updates score
}
Ejemplo n.º 10
0
void new_game() {
  set_grid_to_zero();
  srand(time(NULL));
  draw_tetramino();
  new_shape();
  fill_current_shape(current_shape.index + 1);
  update_score();
  gtk_widget_queue_draw(application.window);
  g_timeout_add(500, timeout, NULL);
}
Ejemplo n.º 11
0
static void draw_first()
{
	GrLine(ipobble_wid,ipobble_gc, BRD_MINX, 0, 
			BRD_MINX, BRD_MAXY+ME_RADIUS);
	GrLine(ipobble_wid,ipobble_gc, BRD_MAXX, 0, 
			BRD_MAXX, BRD_MAXY+ME_RADIUS);
	GrLine(ipobble_wid,ipobble_gc, 0, BRD_MAXY+ME_RADIUS,
			BRD_MAXX, BRD_MAXY+ME_RADIUS);
	update_score();
	
}
Ejemplo n.º 12
0
Reversi::Reversi() {
	for(unsigned int i = 0; i < 8; ++i)
		board.push_back({'o','o','o','o','o','o','o','o'});

	board[3][3] = 'w';
	board[3][4] = 'b';
	board[4][3] = 'b';
	board[4][4] = 'w';
	//cout << "Created Board!\n";
	//cout << "Got Moves!\n";
	update_score();
	//cout << "Updated Score!\n";
}
Ejemplo n.º 13
0
// Source: 0xBE4E
void OStats::convert_speed_score(uint16_t speed)
{
    // 0x960 is the last value in this table to be actively used
    static const uint16_t CONVERT[] = 
    {
        0x0,   0x10,  0x20,  0x30,  0x40,  0x50,  0x60,  0x80,  0x110, 0x150,
        0x200, 0x260, 0x330, 0x410, 0x500, 0x600, 0x710, 0x830, 0x960, 0x1100,
        0x1250,
    };

    uint16_t score = CONVERT[(speed >> 4)];
    update_score(score);
}
Ejemplo n.º 14
0
//appear interface
static void appear(Window *window) 
{
  // Get a tm structure and update time
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);
  update_time(tick_time);
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  
  //get data for player name
  PlayerScore * ps = (PlayerScore *)window_get_user_data(window);
  if(ps != NULL)
  {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "appear of stockScore PlayerScore=%p player=%d games=%d points=%d",
          ps, ps->p, ps->score.games, ps->score.points);
    
    if(ps->p == Player1)
    {
      score_p1.games = score_p1.games + ps->score.games; 
      score_p1.points = score_p1.points + ps->score.points;
      if(ps->score.games >= 1){
        score_p2.points = 0;
      }
      if(score_p1.points >= 3){
        score_p1.games = score_p1.games + (score_p1.points / 3);
        score_p1.points = score_p1.points % 3;
        score_p2.points = 0;
      }
    }
    else if(ps->p == Player2)
    {
      score_p2.games = score_p2.games + ps->score.games; 
      score_p2.points = score_p2.points + ps->score.points;
      if(ps->score.games >= 1){
        score_p1.points = 0;
      }
      if(score_p2.points >= 3){
        score_p2.games = score_p2.games + (score_p2.points / 3);
        score_p2.points = score_p2.points % 3;
        score_p1.points = 0;
      }
    }
    APP_LOG(APP_LOG_LEVEL_INFO, "new values Player1 games=%d points=%d Player2 games=%d points=%d",
          score_p1.games, score_p1.points, score_p2.games, score_p2.points);
  }  
  
  update_score();
}
Ejemplo n.º 15
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);
}
Ejemplo n.º 16
0
int main(void)
{
	uint8_t column[nrCol];
	
	initialize();

	init_matrix(column);
	update_score(0, 0);
	
	for(;;)
	{
		//currently, display takes 10ms to execute
		display(column);
	}
	
	return 0;
}
Ejemplo n.º 17
0
void GameScene::update_game(float dt)
{
	if (_state == GameState::PLAYING)
	{
		bool game_over{ false };
		_robin->update(dt);

		_tube_spawn_interval -= dt;
		if (_tube_spawn_interval < 0)
		{
			spawn_tube_pair();
			_tube_spawn_interval = TUBE_SPAWN_INTERVAL;
		}

		if (_robin->getPositionY() < 0)
		{
			game_over = true;
		}
		else
		{
			for (const auto& tube : _tubes)
			{
				if (tube->get_state() == TubeState::ACTIVE)
				{
					if (_robin->get_tube_collision_box().intersectsRect(tube->getBoundingBox()))
					{
						game_over = true;
					}
					else if (tube->get_robin_scored() == false)
					{
						if (tube->getPositionX() < _robin->getPositionX())
						{
							tube->set_robin_scored(true);
							_game_score += tube->get_score();
							update_score();
						}
					}
				}
			}
		}

		if (game_over)
			stop_game();
	}
}
Ejemplo n.º 18
0
static void	new_game(t_context *gamestate)
{
	WINDOW	**windows;

	windows = gamestate->windows;
	if (ft_bitscan(WIN_VALUE) != 1 || WIN_VALUE == 1)
	{
		mvwaddstr(windows[SCORE], CENTER(WINC_Y, 1), 2, "I AIN'T RUNNIN' THAT");
		wrefresh(windows[SCORE]);
		gamestate->is_running = 0;
		return ;
	}
	gamestate->is_running = 1;
	mvwhline(windows[HIGHSCORES], WINA_Y - 2, 1, ' ', WINA_X - 2);
	wrefresh(windows[HIGHSCORES]);
	update_score(gamestate);
	gamestate->grid = new_grid();
	add_number(gamestate);
	add_number(gamestate);
	draw_grid(gamestate);
}
Ejemplo n.º 19
0
/* Return release mask */
void player_process_dropped_tile(PLAYER *player)
{
    int  released_mask;
    int  w, d, h, layer_count;
    int  layer_capacity;
    int  layer_mask;
    char *layer;

    released_mask = 0;
    layer_mask = 1;
    layer_capacity = BoardWidth * BoardDepth;
    layer = player->board;

    player->score += player->bonus;
    update_score(PT_FOREGROUND, player->score, player->layers);

    player->bonus = -1;
    update_bonus(PT_FOREGROUND, -1);

    for (h=0; h<BoardHeight; h++)
    {   layer_count = 0;

        for (d=0; d<BoardDepth; d++)
            for (w=0; w<BoardWidth; w++)
                if (*layer++) layer_count++;

        if (layer_count == layer_capacity)
            released_mask |= layer_mask;
        else if (layer_count == 0)
            break;

        layer_mask <<= 1;
    }

    player->released_details = released_mask;
    if (released_mask)
        player_animate_release(player);

}
Ejemplo n.º 20
0
static void ipobble_create_board(int level)
{
	int i, j, irw;
	brd_ox = BRD_MINX + 1;
	brd_oy = 1;
	me_posx = 20 + BCOLS * BALL_WIDTH / 2;
	me_posy = BRD_MAXY;
	current_angle = 0;
	delta_angle = 2;
	ball_firing = 0;
	irw = (level > 8) ? 8 : level;
	for(i = 0; i < BROWS; i++) {
		for(j = 0; j < BCOLS; j++){
#if 0
			if(board[i * BCOLS + j] != 0)
#endif
			if (i < irw)
				board[i * BCOLS + j] = new_ball(level);
			else
				board[i * BCOLS + j] =- 1;
		}
	}
	level_connection = 3; /* for now let's take 3... */
	new_ball_x = 0;
	new_ball_y = me_posy - 2;
	new_ball_type = new_ball(level);
	current_ball_x = me_posx - BALL_RADIUS + 1;
	current_ball_y = me_posy - ME_RADIUS + BALL_RADIUS - 1;
	current_ball_type = new_ball(level);
	update_score();
	if(level > 6)
		fire_counter_start = 4000;
	else
		fire_counter_start = (10000 - level * 1000) / DELTA_TIME;
	podzilla_bmp_var = 0;
	accel = 0;
	accel_status = 0;
	counter = 0;
}
Ejemplo n.º 21
0
order_result_t throw_water_watertower(void){
  ROME_LOG(&rome_paddock,INFO,"Throwing water in watertower");
  order_result_t or;
  set_speed(RS_FAST);

  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_PREPARE_THROW_WATERTOWER);
  _wait_meca_ground_clear();

  uint8_t balls_loaded = robot_state.cylinder_nb_good;
  or = goto_pathfinding_node(PATHFINDING_GRAPH_NODE_WATER_DISPENSER_NEAR,arfast(ROBOT_SIDE_TURBINE, TABLE_SIDE_MAIN));
  if (or != ORDER_SUCCESS)
    return or;
  or = goto_xya(KX(1100), 1450, compute_throw_angle(1100,1450));
  ROME_SENDWAIT_MECA_SET_THROW_POWER(&rome_meca,1950);
  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_THROW_WATERTOWER);
  _wait_meca_ground_clear();
  update_score(5*balls_loaded);

  set_speed(RS_NORMAL);
  return or;
}
Ejemplo n.º 22
0
void splash_screen(void) {

	/* Clear the terminal screen */
	clear_terminal();
	init_score();
	update_score();

	/* 
	** Display some suitable message to the user that includes your name(s)
	** and student number(s).
	** You may need to use terminalio functions to position the cursor 
	** appropriately - see terminalio.h for details.
	*/
	display_sound_status();

	move_cursor(0,TITLEY);
	printf_P(PSTR("Snake\n\nBy: Justin Mancinelli\n\nID: 42094353"));
	//move_cursor(NAMEX,NAMEY);
	//printf_P(PSTR(""));
	//move_cursor(IDX,IDY);
	//printf_P(PSTR(""));

}
Ejemplo n.º 23
0
void down_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
  if (paused) return;
  update_score(1, 0);
}
Ejemplo n.º 24
0
Archivo: main.c Proyecto: z88dk/z88dk
void
update_sprites(void)
{
   for (sp_iter = sp_used; sp_iter; sp_iter = sp_iter->n)
   {
      if (!sp_iter->alive)
         continue;

      switch(sp_iter->type)
      {
         default:
            break;

         case ST_BULLET:

            sp_iter->x += sp_iter->ix;
            sp_iter->y += sp_iter->iy;

            // out of screen
            if(sp_iter->x < ORIGINX || sp_iter->x > WIDTH
                  || sp_iter->y + 8 < ORIGINY || sp_iter->y > HEIGHT)
            {
               remove_sprite(sp_iter);
               // no drawing required
               break;
            }

            // enemy check
            for (sp_iter2 = sp_used; sp_iter2; sp_iter2 = sp_iter2->n)
               if (sp_iter2->type == ST_ENEMY && sp_iter2->alive
                     && sp_iter->x + 4 < sp_iter2->x + 16
                     && sp_iter2->x < sp_iter->x + 4
                     && sp_iter->y + 4 < sp_iter2->y + 16
                     && sp_iter2->y < sp_iter->y + 4)
               {
                  score += 25;
                  if (score > hi_score)
                     hi_score = score;

                  update_score();

                  // convert into an explosion
                  sp_iter2->sprite = explosion;
                  sp_iter2->frame = 0;
                  sp_iter2->delay = 0;
                  sp_iter2->type = ST_EXPLO;

                  playfx(FX_EXPLO);

                  // remove the bullet
                  remove_sprite(sp_iter);

                  // one less enemy
                  --horde_count;
               }

            // draw only if it didn't hit anything
            if (sp_iter->alive)
               sp1_MoveSprPix(sp_iter->s, &cr, sp_iter->sprite, 8 + sp_iter->x, 8 + sp_iter->y);
            
            break;

         case ST_EBULLET:

            sp_iter->y += sp_iter->iy;

            // out of screen
            if (sp_iter->y > HEIGHT)
            {
               remove_sprite(sp_iter);
               // no drawing required
               break;
            }

            // player check
            if (!invulnerable && sp_iter->x + 4 < sprites[PLAYER].x + 16
                  && sprites[PLAYER].x < sp_iter->x + 4
                  && sp_iter->y + 4 < sprites[PLAYER].y + 16
                  && sprites[PLAYER].y < sp_iter->y + 4)
            {
               // convert into an explosion
               sp_iter->sprite = impact + 2 * 4 * 8;
               sp_iter->frame = 0;
               sp_iter->delay = 0;
               sp_iter->type = ST_HIT;

               playfx(FX_EXPLO);

               if (!invulnerable)
               {
                  // we hit the player, kill him!
                  --lives;
                  update_score();
                  invulnerable = 10;
               }
               
               continue;
            }

            sp1_MoveSprPix(sp_iter->s, &cr, sp_iter->sprite, 8 + sp_iter->x, 8 + sp_iter->y);
            break;

         case ST_ENEMY:

            if (!horde_delay)
            {
               if (!horde_iy)
                  sp_iter->x += horde_ix;
               else
                  sp_iter->y += horde_iy;

               // change frame
               sp_iter->frame = !sp_iter->frame;

               if (sp_iter->sprite == bomber)
               {
                  if (!sp_iter->delay--)
                  {
                     sp_iter->delay = 15 + rand() % 15;
                     add_bullet(ST_EBULLET, sp_iter->x + 4, sp_iter->y + 16);
                  }
               }
            }

            // player check
            if (!invulnerable && sp_iter->x < sprites[PLAYER].x + 16
                  && sprites[PLAYER].x < sp_iter->x + 16
                  && sp_iter->y < sprites[PLAYER].y + 16
                  && sprites[PLAYER].y < sp_iter->y + 16)
            {
               // convert into an explosion
               sp_iter->sprite = explosion;
               sp_iter->frame = 0;
               sp_iter->delay = 0;
               sp_iter->type = ST_EXPLO;

               // one less enemy
               --horde_count;

               playfx(FX_EXPLO);

               if (!invulnerable)
               {
                  // we hit the player, kill him!
                  --lives;
                  update_score();
                  invulnerable = 10;
               }
               
               continue;
            }

            // out of screen?
            if (sp_iter->y > HEIGHT)
            {
               // one less enemy
               --horde_count;

               // repeat the wave
               not_clean = 1;

               remove_sprite(sp_iter);
               // no drawing required
               break;
            }

            sp1_MoveSprPix(sp_iter->s, &cr, sp_iter->sprite + sp_iter->frame * 8 * 12, 8 + sp_iter->x, 8 + sp_iter->y);
            break;

         case ST_EXPLO:
            // first frame must be half frame longer
            if (sp_iter->delay < 2)
               sp_iter->delay++;
            else
            {
               sp_iter->delay = 1;
               sp_iter->frame++;
               if (sp_iter->frame == 3)
               {
                  // we're done!
                  remove_sprite(sp_iter);
                  break;
               }
            }
            
            sp1_MoveSprPix(sp_iter->s, &cr, sp_iter->sprite + sp_iter->frame * 8 * 12 , 8 + sp_iter->x, 8 + sp_iter->y);
            break;

         case ST_HIT:
            // first frame must be half frame longer
            if (sp_iter->delay < 2)
               sp_iter->delay++;
            else
            {
               sp_iter->delay = 0;
               sp_iter->frame++;
               if (sp_iter->frame == 2)
               {
                  // we're done!
                  remove_sprite(sp_iter);
                  break;
               }
            }
            sp1_MoveSprPix(sp_iter->s, &cr, sp_iter->sprite + sp_iter->frame * 4 * 8 , 8 + sp_iter->x, 8 + sp_iter->y);
            break;
      }
   }

   // update the lists
   collect_sprites();
}
Ejemplo n.º 25
0
Archivo: main.c Proyecto: z88dk/z88dk
void
update_script(void)
{
   unsigned char mod;

   // there's a wave already
   if (horde_count)
      return;

   // wait between waves
   if (wave_delay--)
      return;

   // only if the player killed all aliens in the wave
   if (!not_clean)
   {
      ++wave;
      update_score();
      wait();
      sp1_UpdateNow();
   }
   not_clean = 0;

   // don't play the sound for the first wave
   if (wave > 1)
      playfx(FX_SELECT);

   wave_delay = 16;

   horde_move_x = 0;
   horde_inc_x = 1;
   horde_ix = 4;
   horde_iy = 0;
   horde_move_y = 0;
   horde_delay = 0;
   horde_delay_base = 6;
   horde_count = 0;

   mod = wave & 0x7;  // 0-7
   switch(mod)
   {
      case 1:
         for (j = 0; j < 2; ++j)
            for (i = 0; i < 5; ++i)
            {
               add_enemy(24 * i, j * 20, flyer);
               ++horde_count;
            }
         break;
      case 2:
         horde_move_x = HORDE_MOVE + 1;
         horde_inc_x = -1;
         horde_ix = -4;
         for (j = 0; j < 3; ++j)
            for (i = 0; i < 3 - j; ++i)
            {
               add_enemy(236 - 24 * i, j * 20, !i && !j ? bomber : flyer);
               ++horde_count;
               add_enemy(236 - 120 + 24 * i, j * 20, !i && !j ? bomber : flyer);
               ++horde_count;
            }
         break;
      case 3:
         horde_delay_base = 3;
         for (j = 0; j < 3; ++j)
            for (i = 0; i < 5; ++i)
            {
               add_enemy(24 * i, j * 20, !j ? bomber : flyer);
               ++horde_count;
            }
         break;
      case 4:
         horde_delay_base = 3;
         horde_move_x = HORDE_MOVE + 1;
         horde_inc_x = -1;
         horde_ix = -4;
         k = 1;
         for (j = 0; j < 4; ++j)
            for (i = 0; i < 5; ++i)
            {
               if (i & 1)
                  continue;

               if (k)
                  add_enemy(220 - 24 * i, j * 20, bomber);
               else
                  add_enemy(220 - 24 * i, j * 20, flyer);
               k = !k;

               ++horde_count;
            }
         break;
      case 5:
         horde_delay_base = 3;

         for (i = 0; i < 6; ++i)
         {
            add_enemy(- 8 + 24 * i, 0, bomber);
            ++horde_count;
         }

         for (j = 0; j < 2; ++j)
            for (i = 0; i < 4; ++i)
            {
               add_enemy(-8 + 24 + 24 * i, 20 + j * 20, flyer);
               ++horde_count;
            }

            add_enemy(-8 + 24 + 24 + 12, 60, flyer);
            ++horde_count;
         break;
      case 6:
         horde_delay_base = 2;

         for (i = 0; i < 5; ++i)
         {
            add_enemy(24 * i, 0, bomber);
            ++horde_count;
         }
         for (i = 0; i < 4; ++i)
         {
            add_enemy(12 + 24 * i, 20, flyer);
            ++horde_count;
         }
         for (i = 0; i < 5; ++i)
         {
            add_enemy(24 * i, 40, flyer);
            ++horde_count;
         }
         break;
      case 7:
         horde_move_x = HORDE_MOVE + 1;
         horde_inc_x = -1;
         horde_ix = -4;
         horde_delay_base = 2;

         for (i = 0; i < 5; ++i)
         {
            add_enemy(220 - 24 * i, 0, bomber);
            ++horde_count;
         }
         for (i = 0; i < 5; ++i)
         {
            add_enemy(220 - 24 * i, 40, flyer);
            ++horde_count;
         }
         for (i = 0; i < 4; ++i)
         {
            add_enemy(220 - 12 - 24 * i, 80, bomber);
            ++horde_count;
         }
         break;
      // this is 8
      case 0:
         horde_delay_base = 1;

         for (i = 0; i < 3; ++i)
         {
            add_enemy(24 + 24 * i, 0, flyer);
            ++horde_count;
         }
         for (i = 0; i < 5; ++i)
         {
            add_enemy(24 * i, 40, bomber);
            ++horde_count;
         }
         for (i = 0; i < 4; ++i)
         {
            add_enemy(12 + 24 * i, 80, flyer);
            ++horde_count;
         }
         break;
   }

   if (wave > 8)
      horde_delay_base = 0;
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: z88dk/z88dk
void
run_play()
{
   sp1_ClearRectInv(&cr, BRIGHT | INK_WHITE | PAPER_BLACK, 32, SP1_RFLAG_TILE | SP1_RFLAG_COLOUR);
   sp1_UpdateNow();

   sp1_SetPrintPos(&ps0, 0, 0);
   sp1_PrintString(&ps0, ptiles);

   // setup the game
   sprites[PLAYER].x = 15 * 8;
   sprites[PLAYER].y = 20 * 8;
   sprites[PLAYER].frame = 0;
   sprites[PLAYER].delay = 0;
   sprites[PLAYER].sprite = player;
   update_player();

   horde_count = 0;
   wave_delay = 0;
   wave = 0;
   score = 0;
   lives = 3;
   invulnerable = 0;
   update_score();

   while(1)
   {
      // TODO: pause/resume

      if (in_inkey() == 12)
         // exit current game
         break;

      key = (joyfunc)(&joy_k);
      if (key & IN_STICK_LEFT && !(key & IN_STICK_RIGHT))
      {
         if (sprites[PLAYER].x - 4 > ORIGINX)
         {
            sprites[PLAYER].x -= 4;
            sprites[PLAYER].frame = 2;
            sprites[PLAYER].delay = 4;
            update_player();
         }
      }

      if (key & IN_STICK_RIGHT && !(key & IN_STICK_LEFT))
      {
         if (sprites[PLAYER].x + 16 + 8 + 4 < WIDTH)
         {
            sprites[PLAYER].x += 4;
            sprites[PLAYER].frame = 1;
            sprites[PLAYER].delay = 4;
            update_player();
         }
      }

      if (cooldown > 0)
         --cooldown;

      if (key & IN_STICK_FIRE && !cooldown)
      {
         // fire rate
         cooldown = 10;
         add_bullet(ST_BULLET, sprites[PLAYER].x + 4, sprites[PLAYER].y - 2);

         playfx(FX_FIRE);
      }

      // change the frame to normal?
      if (sprites[PLAYER].delay)
      {
         if (!--sprites[PLAYER].delay)
         {
            sprites[PLAYER].frame = 0;
            update_player();
         }
      }

      update_horde();
      update_sprites();
      update_script();

      if (invulnerable > 0)
      {
         // will be 0, but in case of "the unexpected"
         if (lives <= 0)
         {
            // GAME OVER

            // some noise
            playfx(FX_EXPLO);
            playfx(FX_EXPLO);
            playfx(FX_EXPLO);

            // we don't want the player to miss the game over music
            in_wait_nokey();

            sp1_SetPrintPos(&ps0, 11, 8);
            sp1_PrintString(&ps0, "\x14\x46" "G A M E  O V E R");
            sp1_UpdateNow();

            dzx7_standard(song2, TEMPMEM);
            ntropic_play(TEMPMEM, 0);

            for (i = 0; i < 32; ++i)
               wait();

            // leave the game
            break;
         }

         --invulnerable;
         update_player();
      }

      wait();
      intrinsic_halt();   // inline halt without impeding optimizer
      sp1_UpdateNow();
   }

   destroy_type_sprite(ST_ALL);
   collect_sprites();

   // the player sprite is never destroyed, so hide it
   sp1_MoveSprAbs(sprites[PLAYER].s, &cr, NULL, 0, 34, 0, 0);
   sp1_UpdateNow();

   sp1_ClearRectInv(&cr, BRIGHT | INK_BLACK | PAPER_BLACK, 32, SP1_RFLAG_TILE | SP1_RFLAG_COLOUR);
   sp1_UpdateNow();
}
Ejemplo n.º 27
0
/*
 * main -- Main program.
 */
int main(void) {
	uint8_t chars_into_escape_sequence = 0;
	int8_t moveStatus = 0;

	char c;

	/* Initialise our main clock */
	init_timer();

	/* Initialise serial I/O */
	init_serial_stdio(19200, 0);

	/* Make the display_row() function be called every 2ms.
	** (This function returns a timer number, but we ignore 
	** this since we'll never do anything with it.)
	*/
	execute_function_periodically(2, display_row);

	/* Register the time_increment() function to be called every 500ms.
	** This function just sets a variable (timePassedFlag).
	*/
	mainTimerNum = execute_function_periodically(500, time_increment);

	//4209435
	/* setup AVR to handle sounds*/
	init_sound();

	/*
	** Turn on interrupts (needed for timer and serial input/output to work)
	*/
	sei();
	
	/*
	** Display splash screen 
	*/
	splash_screen();
	show_instruction(NEWGAME);
	
	/*
	** Perform necessary initialisations for a new game.
	*/
	new_game();
		
	/*
	** Event loop - wait for a certain amount of time to pass or wait
	** for a character to arrive from standard input. The time_passed_flag
	** is set within the function time_increment() below - which is setup
	** to be called periodically.
	*/
	for(;;) {
		if(timePassedFlag) {
			moveStatus = move_snake();
			timePassedFlag = 0;
		} else if(input_available()) {
			/* Read the input from our terminal and handle it */
			c = fgetc(stdin);			
			if(chars_into_escape_sequence == 0 && c == '\x1b') {
				/*
				** Received ESCAPE character - we're one character into
				** an escape sequence
				*/
				chars_into_escape_sequence = 1;
			} else if(chars_into_escape_sequence == 1 && c == '[') {
				/* 
				** We're now two characters into an escape sequence
				*/
				chars_into_escape_sequence = 2;
			} else if (chars_into_escape_sequence == 2) {
				/* We're two characters into an escape sequence and
				** have received another - see if it is as expected.
				*/
				if (c == 'C') {
					/* Cursor right key pressed - Set next direction to
					** be moved to RIGHT */
					set_snake_dirn(RIGHT);
				}  
				if (c == 'D') {
					/* Cursor left key pressed - Set next direction to
					** be moved to LEFT */
					set_snake_dirn(LEFT);
				}  
				if (c == 'A') {
					/* Cursor up key pressed - Set next direction to
					** be moved to UP */
					set_snake_dirn(UP);
				}  
				if (c == 'B') {
					/* Cursor down key pressed - Set next direction to
					** be moved to DOWN */
					set_snake_dirn(DOWN);
				}

				/* else, unknown escape sequence */

				/* We're no longer part way through an escape sequence */
				chars_into_escape_sequence = 0; 
			} else if(chars_into_escape_sequence != 0) {
				/*
				** We started an escape sequence but didn't get a character
				** we recognised - discard it and assume that we're not
				** in an escape sequence.
				*/
				chars_into_escape_sequence = 0;
			} else if (c == ' ') {
				/* Space character received - move snake immediately */
				moveStatus = move_snake();
			} else {					
				if(c == 'N' || c == 'n'){	
					show_instruction(NEWGAME);				
					new_game();
				} else if(c == 'P' || c == 'p'){
					moveStatus = 0;
					pause_game();
				} else if(c == 'M' || c == 'm'){
					toggle_sound();
					display_sound_status();
				}
			}
		}

		switch(moveStatus){
			case ATE_FOOD:
				if(sound_status())
					play_sound();
				moveStatus = MOVE_OK;
				break;
		}

		if(moveStatus < 0) {
			/* Move failed - game over */
			handle_game_over();
			moveStatus = 0;
			update_score();
		}
	}
}
Ejemplo n.º 28
0
bool Reversi::make_move(string move){
	//check size of move
	//cout << "Making move!\n";
	//cout << "size of move:" <<  sizeof(move) << endl;
	if(move.size() != 2)
		return false;
	//check if user has chosen side
	//cout << "Move sized correctly!\n";
	//cout << "current player:" << current_player << endl;
	if(current_player == 'n')
		return false;

	//split move into correct data types
	//cout << "Player has been set!\n";
	//cout << "Move string: " << move << endl;

	Position current_move;
	if(isalpha(move[0])) {
		current_move.column = get_number_of_letter(move[0]);
		current_move.row = move[1]-'0'-1;
	}
	else{
		current_move.row = get_number_of_letter(move[0]);
		current_move.column = move[1]-'0'-1;
	}
	//cout << "row: " << current_move.row << endl;
	//cout << "column: " << current_move.column << endl;

	// check if valid move
	bool possible_move_check = false;
	for(unsigned int i=0; i< available_moves.size(); i++)
		if(available_moves[i].row == current_move.row && available_moves[i].column == current_move.column)
			possible_move_check = true;

	if(!possible_move_check)
		return false;
	//cout << "Move is valid!\n";

	// save previous state
	// only need to support 10 undos (20 total saved states)
	if(previous_states.size() >= 20)
		previous_states.pop_back();
	
	previous_states.push_front({board, available_moves, white_score, black_score, current_player});
	previous_move = move;

	//check all directions
	//if valid in a direction flip all appropriate tiles
	vector<Position> all_positions;
	vector<Position> temp_positions;
	all_positions.push_back(current_move);
	int x_step = 0;
	int y_step = -1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check above
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	y_step = 1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check below
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	y_step = 0;
	x_step = 1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check right
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	x_step = -1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check left
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	y_step = -1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check top left
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	x_step = 1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check top right
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	y_step = 1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check bottom right
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	x_step = -1;
	temp_positions = get_tiles(current_move, x_step, y_step);		//check bottom left
	for(unsigned int i=0; i<temp_positions.size(); i++)
		all_positions.push_back(temp_positions[i]);
	for(unsigned int i=0; i<all_positions.size(); i++)
		board[all_positions[i].row][all_positions[i].column] = current_player;
	update_score();
	toggle_player();
	available_moves = get_available_moves();

	if(available_moves.size() == 0 && !(is_game_over())) {
		toggle_player();
		available_moves = get_available_moves();
	}
}
Ejemplo n.º 29
0
static void update(Tetris *tetris)
{
    if (tetris->key_quit) {
        Tetris_destroy(tetris);
        exit(0);
    }
    else if (tetris->key_pause) {
        if (tetris->game_state == RUNNING) {
            tetris->game_state = PAUSED;
            Renderer_erase_panel_labels(tetris->renderer);
            Renderer_erase_panel_line_counter(tetris->renderer);
            Renderer_erase_panel_score(tetris->renderer);
            Renderer_erase_panel_level(tetris->renderer);

            Renderer_draw_pause_message(tetris->renderer);
        }
        else if (tetris->game_state == PAUSED) {
            tetris->game_state = RUNNING;
            Renderer_erase_pause_message(tetris->renderer);

            Renderer_draw_panel_labels(tetris->renderer);
            Renderer_draw_panel_line_counter(tetris->renderer,
                                             tetris->lines_completed);
            Renderer_draw_panel_score(tetris->renderer, tetris->score);
            Renderer_draw_panel_level(tetris->renderer, tetris->level);
        }
    }

    if (tetris->game_state != PAUSED) {
        if (collision(COORDINATE_BOTTOM_COLLISION,
                      tetris->current_block,
                      tetris->renderer->buffer)
        ) {
            ++tetris->movement_frame_counter;
            if (tetris->movement_frame_counter == tetris->movement_frame_delay) {
                tetris->movement_frame_counter = 0;

                Renderer_draw_block(tetris->renderer, tetris->current_block);

                int complete_lines = check_complete_lines(tetris);

                next_block(tetris);

                check_game_over(tetris);

                update_score(tetris, complete_lines);
                update_level(tetris);

                Renderer_draw_panel_score(tetris->renderer, tetris->score);
                Renderer_draw_panel_level(tetris->renderer, tetris->level);

                tetris->renderer->buffer->dirty = 1;
            }
        }

        if (!collision(COORDINATE_BOTTOM_COLLISION,
                       tetris->current_block,
                       tetris->renderer->buffer)
        ) {
            ++tetris->gravity_frame_counter;
            if (tetris->gravity_frame_counter == tetris->gravity_frame_delay) {
                tetris->gravity_frame_counter = 0;
                ++tetris->current_block->y;
                tetris->renderer->buffer->dirty = 1;
            }
        }
        if (tetris->key_drop) {
            while (!collision(COORDINATE_BOTTOM_COLLISION,
                              tetris->current_block,
                              tetris->renderer->buffer)
            ) {
                ++tetris->current_block->y;
                tetris->score += 2;
            }
            tetris->renderer->buffer->dirty = 1;
        }
        else if (tetris->key_rotate
                 && rotate_collision(tetris->current_block,
                                     tetris->renderer->buffer) != 1
        ) {
            Block_rotate(tetris->current_block);
            if (tetris->enable_ghost_block == 1) {
                set_ghost_block(tetris);
            }
            tetris->renderer->buffer->dirty = 1;
        }
        else if (tetris->key_ghost_block) {
            if (tetris->enable_ghost_block) {
                tetris->enable_ghost_block = 0;
            }
            else {
                tetris->enable_ghost_block = 1;
                set_ghost_block(tetris);
            }
            tetris->renderer->buffer->dirty = 1;
        }
        else if (tetris->key_left
                 && !collision(COORDINATE_LEFT_COLLISION,
                               tetris->current_block,
                               tetris->renderer->buffer)
        ) {
            --tetris->current_block->x;
            if (tetris->enable_ghost_block == 1) {
                set_ghost_block(tetris);
            }
            tetris->renderer->buffer->dirty = 1;
        }
        else if (tetris->key_right
                 && !collision(COORDINATE_RIGHT_COLLISION,
                               tetris->current_block,
                               tetris->renderer->buffer)
        ) {
            ++tetris->current_block->x;

            if (tetris->enable_ghost_block == 1) {
                set_ghost_block(tetris);
            }

            tetris->renderer->buffer->dirty = 1;
        }
        else if (tetris->key_down
                 && !collision(COORDINATE_BOTTOM_COLLISION,
                               tetris->current_block,
                               tetris->renderer->buffer)
        ) {
            ++tetris->current_block->y;

            if (tetris->enable_ghost_block == 1) {
                set_ghost_block(tetris);
            }

            ++tetris->score;

            Renderer_draw_panel_score(tetris->renderer, tetris->score);

            tetris->renderer->buffer->dirty = 1;
        }
    }
}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
    // An array of 4 players, may need to be a pointer if you want it set dynamically
    player players[NUM_PLAYERS];
    
    // Input buffer and and commands
    //char buffer[BUFFER_LEN] = { 0 };

    // Display the game introduction and initialize the questions
    initialize_game();

    // Prompt for players names
    printf("This is Jeopardy \n");

    // initialize each of the players in the array
    for(int i = 0; i < 4; i++) {
        players[i].score = 0;

        printf("Enter player name: ");
        scanf("%s", (char *) &players[i].name);
    }

    // Perform an infinite loop getting command input from users until game ends
    //while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
    while(!answered_status())
    {
        system("clear");

        char selected_player[MAX_LEN] = "";
        char selected_category[MAX_LEN] = "";
        int selected_val = 0;

        do {
            if(strcmp(selected_player, "") != 0)
                printf("The player %s was not found", selected_player);

            printf("Enter first player's name: ");
            scanf("%s", (char *) &selected_player);
        } while(!player_exists(players, 4, selected_player));

        do {
            if(selected_val != 0)
                printf("Invalid selection");

            printf("Enter category: ");
            getchar();
            fgets((char *) selected_category, MAX_LEN, stdin);
            strtok(selected_category, "\n");

            printf("Enter: ");
            scanf("%d", (int *) &selected_val);
        } while(already_answered(selected_category, selected_val));


        system("clear");
        display_question(selected_category, selected_val);

        char *answer[MAX_LEN] = {0};
        getchar();
        fgets((char *) answer, MAX_LEN, stdin);

        char *tokenize_answer;
        tokenize((char *) answer, &tokenize_answer);

        if(tokenize_answer == NULL)
            printf("Try again");
        else if(valid_answer(selected_category, selected_val, tokenize_answer)) {
            printf("Correct Answer!");
            printf("%s gains %d points \n", selected_player, selected_val);
            update_score(players, 4, selected_player, selected_val);
        } else {
            printf("Wrong Answer!");
            int num = get_question_number(selected_category, selected_val);
            printf("Correct answer was: %s", questions[num].answer);
        }

        track_answered(selected_category, selected_val);

        // Call functansions from the questions and players source files

        // Execute the game until all questions are answered

        // Display the final results and exit
    }

    show_results(players, 4);
    getchar();

    return EXIT_SUCCESS;
}