Ejemplo n.º 1
0
void load(
	Animation_Set *anim_set,
	std::string info_filename,
	std::string path_to_files,
	std::map< std::pair<std::string, int>, std::vector<Bone> > &bones)
{
	XMLData *xml = new XMLData(info_filename);
	std::list<XMLData *>::iterator it;
	std::list<XMLData *> nodes = xml->get_nodes();

	std::string sub_bak = anim_set->get_sub_animation_name();

	for (it = nodes.begin(); it != nodes.end(); it++) {
		XMLData *sub = *it;
		XMLData *tmp;
		std::string name = sub->get_name();
		tmp = sub->find("frames");
		std::string framesS;
		if (tmp)
			framesS = tmp->get_value();
		else
			framesS = "1";
		int nframes = atoi(framesS.c_str());
		for (int i = 0; i < nframes; i++) {
			anim_set->set_sub_animation(name, true);
			anim_set->get_current_animation()->set_frame(i);
			int w = anim_set->get_current_animation()->get_current_frame()->get_width();
			int h = anim_set->get_current_animation()->get_current_frame()->get_height();
			std::string filename = path_to_files + "/" + name + "/" + General::itos(i+1) + ".xml";
			std::vector<Bone> bones2;
			load(bones2, w, h, filename);
			std::pair<std::string, int> p;
			p.first = name;
			p.second = i;
			bones[p] = bones2;
		}
	}

	anim_set->set_sub_animation(sub_bak);

	delete xml;
}
bool Whack_a_Skunk_Loop::init(void)
{
	engine->clear_touches();

	if (inited) {
		return true;
	}
	Loop::init();

	regular_skunk = new Animation_Set();
	regular_skunk->load("mini_games/whack_a_skunk/skunk");
	silver_skunk = new Animation_Set();
	silver_skunk->load("mini_games/whack_a_skunk/silver_skunk");
	gold_skunk = new Animation_Set();
	gold_skunk->load("mini_games/whack_a_skunk/gold_skunk");
	fake_skunk = new Animation_Set();
	fake_skunk->load("mini_games/whack_a_skunk/mallard");
	skunk_size.w = regular_skunk->get_current_animation()->get_current_frame()->get_bitmap()->get_width();
	skunk_size.h = regular_skunk->get_current_animation()->get_current_frame()->get_bitmap()->get_height();

	bg_bitmap = Wrap::load_bitmap("mini_games/whack_a_skunk/board.png");

	hand = new Animation_Set();
	hand->load("mini_games/whack_a_skunk/hands");
	hand_size.w = hand->get_current_animation()->get_current_frame()->get_bitmap()->get_width();
	hand_size.h = hand->get_current_animation()->get_current_frame()->get_bitmap()->get_height();

	font_w = 15;
	font_h = 19;
	font = new Animation_Set();
	font->load("mini_games/whack_a_skunk/font");

	XMLData *xml = new XMLData("mini_games/whack_a_skunk/board.xml");

	for (int i = 0; i < 9; i++) {
		char buf[2];
		buf[0] = '0'+i;
		buf[1] = 0;
		XMLData *node = xml->find(std::string(buf));
		XMLData *x_node = node->find("x");
		XMLData *y_node = node->find("y");
		Skunk_Hole h;
		h.x = atoi(x_node->get_value().c_str());
		h.y = atoi(y_node->get_value().c_str());
		h.status = NIL;
		h.miss_count = -1;
		holes.push_back(h);
	}

	delete xml;

	bg_w = al_get_bitmap_width(bg_bitmap->bitmap);
	bg_h = al_get_bitmap_height(bg_bitmap->bitmap);

	top_offset.x = (cfg.screen_w-bg_w)/2;
	top_offset.y = cfg.screen_h-bg_h;

	next_diff = max_next - min_next;
	next_count = 0;

	misses = 0;
	hits = 0;

	star_bmp = Wrap::load_bitmap("mini_games/whack_a_skunk/star.png");
	pow_bmp = Wrap::load_bitmap("mini_games/whack_a_skunk/pow.png");
	kratch_bmp = Wrap::load_bitmap("mini_games/whack_a_skunk/kratch.png");
	mask_front = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-front.png");
	mask_middle = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-middle.png");
	mask_back = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-back.png");
	highlight_front = Wrap::load_bitmap("mini_games/whack_a_skunk/highlight-front.png");
	highlight_middle = Wrap::load_bitmap("mini_games/whack_a_skunk/highlight-middle.png");
	highlight_back = Wrap::load_bitmap("mini_games/whack_a_skunk/highlight-back.png");
	mask_fronthighlight = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-fronthighlight.png");
	mask_middlehighlight = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-middlehighlight.png");
	mask_backhighlight = Wrap::load_bitmap("mini_games/whack_a_skunk/mask-backhighlight.png");

	start_time = al_current_time();

	// Load SFX
	hit_sample = Sound::load("mini_games/whack_a_skunk/sfx/bash.ogg");
	miss_sample = Sound::load("mini_games/whack_a_skunk/sfx/bash_no_skunk.ogg");
	taunt_sample = Sound::load_set("mini_games/whack_a_skunk/sfx/taunt", "ogg");

	return true;
}