示例#1
0
static void health_handler(HealthEventType event, void *context) {
  // Which type of event occurred?
  switch(event) {
    case HealthEventSignificantUpdate:
      update_health();
      break;
    case HealthEventMovementUpdate:
      update_health();
      break;
    case HealthEventSleepUpdate:
      update_health();
      break;
    default:
      update_health();
      break;
  }
}
示例#2
0
文件: health_sys.c 项目: rcorre/alecs
void health_system_fn(double time) {
  elapsed_time = time;
  list *components = ecs_component_store[ECS_COMPONENT_HEALTH];
  list_node *node = components->head;
  while (node) {
    ecs_component *comp = node->value;
    if (comp->active) {
      update_health(comp);
      node = node->next;
    }
    else {
      node = list_remove(components, node, free);
    }
  }
  list_each(components, (list_lambda)update_health);
}
示例#3
0
int main(void) {
	/* Related object data */
	system_t* system;
	player_t* player1;
	player_t* player2;

	alt_timestamp_start();
	int start_time = alt_timestamp();
	int wind;
	int restart = 0;
	/* initialize all hardware dev */
	system = system_init(VIDEO_PIXEL_BUFFER_DMA_NAME,
			"/dev/video_character_buffer_with_dma_0",
			ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME, PS2_0_NAME);
	if (!alt_up_sd_card_is_Present()) {
		printf("SD card not present\n");
		return -2;
	} else {
		printf("SD card detected.\n");
	}
	if (!alt_up_sd_card_is_FAT16()) {
		printf("SD card is not FAT16.\n");
		return -3;
	} else {
		printf("SD card is FAT 16.\n");
	}
	fireSound = initSoundbank("shotgun.wav");
	explosionSound = initSoundbank("big_bomb.wav");
	printf("Done Initializing\n");
	int end_time = alt_timestamp();
	srand(end_time - start_time);
	clearScreen(system);
	printf("Press enter to start game");
	restartGame(system);
	while (restart == 1) {
	/* initialize required objects */
	player1 = makePlayer(1, "Lomash");
	player2 = makePlayer(2, "TJ");

	/*
	 * Draw the screen for the first time.
	 */
	store_background_data();
	draw_background(system);
	drawPlayers(system);
	draw_ground(system);
	draw_windbox(system);
	draw_player1GUI(system);
	draw_player2GUI(system);
	update_wind(system, wind);
	draw_health(player1, system);
	draw_health(player2, system);
	update_power(player1, system);
	update_power(player2, system);
	usleep(2000000); // sleep to wait for video buffer to load
	while (TRUE) {

	printf(
	 "\n\n\n\n===========================================================\n");
	 printf("Player 1 Health = %d \t\t Player 2 Health = %d\n",
	 player1->health, player2->health);
	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);


//	 Player 1's turn

	 player_1_jump(system);
	 player_1_jump(system);
	 printf("Getting Player 1 Power.\n");
	 getKeyboardInput(1, player1, system); // Power
	 skipOneEnter(system);
	 printf("Getting Player 1 Angle.\n");
	 getKeyboardInput(2, player1, system); // Angle

//	 Player 1 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon1(system);
	 playSound(fireSound, system->audio);
	 switch (animateShooting(system, player1, wind)) { // different value for result
	 case 1: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 case 2: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }
	 printf("Ended animation\n");

//	 Post-animation Calculation
	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }


//	 Player 2's turn


	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);
	 player_2_jump(system);
	 player_2_jump(system);
	 printf("Getting Player 2 Velocity.\n");
	 getKeyboardInput(1, player2, system);
//	 Player 2 Angle-Selection
	 skipOneEnter(system);
	 printf("Getting Player 2 Angle.\n");
	 getKeyboardInput(2, player2, system);

//	 Player 2 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon2(system);
	 playSound(fireSound, system->audio);
//	 Post-animation Calculation
	 switch (animateShooting(system, player2, wind)) { // different value for result
	 case 1: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 case 2: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }

	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }
	};
	/*
	 * Find out who won.
	 */
		if (player1->health <= 0) {
			printf("Player 2 Wins!!! \n");
			draw_P2WIN(system);
		} else if (player2->health <= 0) {
			printf("Player 1 Wins!!!\n");
			draw_P1WIN(system);
		} else {
			printf("we shouldn't be here.\n");
		}
		restart = restartGame(system);
	}
	return 0; // FIN
}
示例#4
0
文件: map.c 项目: long5313828/ythtbbs
int
walk_map(McMap * mcMap)
{
	int i, j, ch, r, walk;
	unsigned short exits;

	i = mcMap->prev_x;
	j = mcMap->prev_y;

	for (walk = 0; map_valid(mcMap);) {
		r = 4;
		myInfo->pos_x = i;
		myInfo->pos_y = j;
		money_show_stat("邪恶荒原");
		move(r++, 0);
		prints
		    ("这里是大富翁城外不远的邪恶荒原, 周围荒草凄凄, 静寂得令人毛骨悚然.");
		if (myInfo->health < 1) {
			showAt(++r, 0, "你没有足够的体力行走了...", YEA);
			continue;
		}
		move(t_lines - 2, 0);
		prints("[h 帮助]这里明显的出口是:");
		exits = mcMap->map[i][j].exit;
		if (exits & NODE_LEFT)
			prints("%s、", "←");
		if (exits & NODE_RIGHT)
			prints("%s、", "→");
		if (exits & NODE_UP)
			prints("%s、", "↑");
		if (exits & NODE_DOWN)
			prints("%s。", "↓");

		print_item(&mcMap->map[i][j], &r);

		ch = igetkey();
		if (ch == KEY_LEFT && (exits & NODE_LEFT)) {
			walk++;
			j--;
		} else if (ch == KEY_RIGHT && (exits & NODE_RIGHT)) {
			walk++;
			j++;
		} else if (ch == KEY_UP && (exits & NODE_UP)) {
			walk++;
			i--;
		} else if (ch == KEY_DOWN && (exits & NODE_DOWN)) {
			walk++;
			i++;
		} else if (ch == 'q' || ch == 'Q') {
			return 0;
		} else if (ch == 'h' || ch == 'H') {
			print_map_help();
		} else if (ch == KEY_TAB) {
			nomoney_show_stat("邪恶荒原");
			move(4, 0);
			print_map(mcMap, 1);
			pressanykey();
		} else if (ch == 'k' || ch == 'K') {
			kill_npc();
		} else if (ch == 'o') {
			open_box();
		} else {
			showAt(t_lines - 1, 0, ">你要做什么?", YEA);
		}
		//更新身体状态
		update_health();
		if (walk % 4 == 1) {
			walk++;
			myInfo->health--;
			limit_cpu();
		}
	}
	return 0;
}
示例#5
0
/**This is a public slot that adds all of the necessary components for game play to the scene.
 * @brief Game::game_begin() adds objects of classes Ash, Pikachu, Snorlax, Muk,
 *        Beedrill, Tile, Score, and Health to the scene and then begins the game.
 */
void Game::game_begin() {
    // play game music
    game_music->play();

    // stop menu music
    menu_music->stop();

    // close the main manu
    main_widget->close();

    //if retrying game again, clear away the game over window
    scene->clearFocus();
    scene->clear();

    // set the level
    if (hard->isChecked()) isHard = true;

    // Create an Ash object player
    player_ash = new Ash;
    // make the player focusable and set it to be the current focus
    player_ash->setFlag(QGraphicsItem::ItemIsFocusable);
    player_ash->setFocus();
    // add the player to the scene
    scene->addItem(player_ash);

    // Create five Pikachu objects
    pikachu1 = new Pikachu;
    if (!isHard) pikachu1->setPos(50,240);
    else pikachu1->setPos(100,70);
    pikachu1->setSound(QUrl("qrc:/sounds/sound/pikachuuu.wav"));
    scene->addItem(pikachu1);

    pikachu2 = new Pikachu;
    if (!isHard) pikachu2->setPos(250,412);
    else pikachu2->setPos(180,412);
    pikachu2->setSound(QUrl("qrc:/sounds/sound/pika.wav"));
    scene->addItem(pikachu2);

    pikachu3 = new Pikachu;
    pikachu3->setPos(543,45);
    pikachu3->setSound(QUrl("qrc:/sounds/sound/pikachu.wav"));
    scene->addItem(pikachu3);

    pikachu4 = new Pikachu;
    if (!isHard) pikachu4->setPos(610,323);
    else pikachu4->setPos(500,350);
    pikachu4->setSound(QUrl("qrc:/sounds/sound/pikapi.wav"));
    scene->addItem(pikachu4);

    pikachu5 = new Pikachu;
    if (!isHard) pikachu5->setPos(1150,410);
    else pikachu5->setPos(1100,410);
    pikachu5->setSound(QUrl("qrc:/sounds/sound/pika.wav"));
    scene->addItem(pikachu5);

    // Create a snorlax
    snorlax = new Snorlax;
    scene->addItem(snorlax);

    // Create a button in hard mode
    if (isHard) {
        Button* button = new Button;
        scene->addItem(button);
    }

    // Create two muk objects
    muk1 = new Muk;
    muk1->setAsh(player_ash);
    muk1->setPos(100,412);
    if(isHard) muk1->start_movement();
    scene->addItem(muk1);

    muk2 = new Muk;
    muk2->setAsh(player_ash);
    muk2->setPos(740,130);
    if (isHard) muk2->start_movement();
    scene->addItem(muk2);

    if (isHard) {
        Muk* muk3 = new Muk;
        muk3->setAsh(player_ash);
        muk3->setPos(480,412);
        muk3->start_movement();
        scene->addItem(muk3);
    }

    // Create two beedril objects
    beedril1 = new Beedril;
    beedril1->setAsh(player_ash);
    beedril1->setPos(480,250);
    beedril1->set_vertical();
    beedril1->start_movement();
    scene->addItem(beedril1);

    beedril2 = new Beedril;
    beedril2->setAsh(player_ash);
    beedril2->setPos(1000,400);
    beedril2->start_movement();
    scene->addItem(beedril2);

    if (isHard) {
        Beedril* beedril3 = new Beedril;
        beedril3->setAsh(player_ash);
        beedril3->setPos(100,115);
        beedril3->start_movement();
        scene->addItem(beedril3);
    }

    // set up a score box
    score1 = new Score;
    score1->setGeometry(1000,0,40,40);
    scene->addWidget(score1);

    score2 = new Score;
    score2->setGeometry(1040,0,40,40);
    scene->addWidget(score2);

    score3 = new Score;
    score3->setGeometry(1080,0,40,40);
    scene->addWidget(score3);

    score4 = new Score;
    score4->setGeometry(1120,0,40,40);
    scene->addWidget(score4);

    score5 = new Score;
    score5->setGeometry(1160,0,40,40);
    scene->addWidget(score5);

    // set up health points
    health1 = new Health;
    health1->setGeometry(0,0,40,40);
    scene->addWidget(health1);

    health2 = new Health;
    health2->setGeometry(40,0,40,40);
    scene->addWidget(health2);

    health3 = new Health;
    health3->setGeometry(80,0,40,40);
    scene->addWidget(health3);

    // set up tiles
    tile1 = new Tile;
    tile1->setPos(0,465);
    scene->addItem(tile1);

    tile2 = new Tile;
    tile2->setPos(tile1->boundingRect().width()*0.2,465);
    scene->addItem(tile2);

    tile3 = new Tile;
    tile3->setPos(tile1->boundingRect().width()*0.4,465);
    scene->addItem(tile3);

    tile4 = new Tile;
    tile4->setPos(tile1->boundingRect().width()*0.6,465);
    scene->addItem(tile4);

    tile5 = new Tile;
    tile5->setPos(tile1->boundingRect().width()*0.8,465);
    scene->addItem(tile5);

    tile6 = new Tile;
    tile6->setPos(tile1->boundingRect().width(),465);
    scene->addItem(tile6);

    tile7 = new Tile;
    tile7->setPos(tile1->boundingRect().width()*1.2,465);
    scene->addItem(tile7);

    tile8 = new Tile;
    tile8->setPos(tile1->boundingRect().width()*1.4,465);
    scene->addItem(tile8);

    tile9 = new Tile;
    tile9->setPos(tile1->boundingRect().width()*1.6,465);
    scene->addItem(tile9);

    tile10 = new Tile;
    tile10->setPos(tile1->boundingRect().width()*1.8,465);
    scene->addItem(tile10);

    tile11 = new Tile;
    tile11->setPos(300,372);
    scene->addItem(tile11);

    tile12 = new Tile;
    tile12->setPos(50,290);
    scene->addItem(tile12);

    tile13 = new Tile;
    tile13->setPos(600,372);
    scene->addItem(tile13);

    tile14 = new Tile;
    tile14->setPos(600+tile1->boundingRect().width()*0.2,372);
    scene->addItem(tile14);

    tile15 = new Tile;
    tile15->setPos(1000,250);
    scene->addItem(tile15);

    tile16 = new Tile;
    tile16->setPos(700,180);
    scene->addItem(tile16);

    tile17 = new Tile;
    tile17->setPos(500,100);
    scene->addItem(tile17);

    //show the scene
    show();

    QTimer* statustimer = new QTimer(this);
    connect(statustimer, SIGNAL(timeout()), this, SLOT(update_score()));
    connect(statustimer,SIGNAL(timeout()),this,SLOT(update_health()));
    statustimer->start(100);
}