Esempio n. 1
0
void Game::left_mousebutton(int m_x, int m_y)
{
	if (m_x <= GRIDWIDTH && m_y <= GRIDHEIGHT)
	{ //Mouse within Grid
		Tile* tile = grid->get_tile_from_mouse(m_x, m_y);
		if (optionbox_visible())
		{
			bool done = false;
			iter_op_box = optionbox.begin();

			// if mouse is inside OptionBox
			if ((*iter_op_box)->overlaps(m_x, m_y))
			{
				if (tile_selection != NULL)
					tile = tile_selection;
				for (iter_op_box = optionbox.begin()++; iter_op_box != optionbox.end(); iter_op_box++)
				{
					if ((*iter_op_box)->overlaps(m_x, m_y))
					{
						if (tile != NULL)
							done = optbox_do_selection((*iter_op_box), tile->get_position());
					}

					if (done)
						break;
				}
			}

			else //if mouse is outside the box
			{
				if (tile != NULL && tile->get_tower() == NULL)
				{
					cancel_selection();
					hide_option_box();
				}
				else
				{
					//Select Tower on this position
					cancel_selection();
					option_box_visible = false;
					select(tile);
				}
				/*****/

			}
		} //(ShowOptionBox)

		else //if (!ShowOptionBox)

		{
			if (buildmenu_selection != NULL && tile->get_tower() == NULL )
			{
				//Create new tower
				create_new_tower(buildmenu_selection->get_type(), tile->get_position());
			}
			else if (buildmenu_selection == NULL)
			{
				select(tile);
			}
			else // tower is occupying this tile, cannot build there
			{
				SFX_cant_build->play();
			}
		}
	} //Mouse on grid

	else //Mouse on menu

	{
		if (optionbox_visible())
			hide_option_box();
		//Stuff on menu
		for (iter_ingame_button = ingame_buttons.begin(); iter_ingame_button != ingame_buttons.end(); iter_ingame_button++)
		{
			if ((m_x > (*iter_ingame_button)->get_x()) && (m_x < (*iter_ingame_button)->get_x() + (*iter_ingame_button)->get_width()) && (m_y
					> (*iter_ingame_button)->get_y()) && (m_y < (*iter_ingame_button)->get_y() + (*iter_ingame_button)->get_height()))
			{

				if ((*iter_ingame_button)->get_type() == BUTTON_TOGGLEGRID)
				{
					((*iter_ingame_button))->update();
					grid_visible = !grid_visible;
				}

				if ((*iter_ingame_button)->get_type() == BUTTON_MENU) {
					old_game_state = game_state;
					game_state = INGAMEMENU;
				}

				if (tile_selection != NULL &&
						((*iter_ingame_button)->get_type() > BUTTONS) &&
						buildmenu_selection == NULL
						&& !optionbox_visible())
				{
					switch ((*iter_ingame_button)->get_type())
					{
					case BUTTON_UPGR:
					{
						Tower* t = tile_selection->get_tower();
						if (t != NULL)
							upgrade_tower(t->get_type());
						break;
					}
					case BUTTON_SELL:
					{
						sell(tile_selection);
						break;
					}
					}
				}
			}
		}// Iterator-loop ends

		for (iter_build_obj = build_list.begin(); iter_build_obj != build_list.end(); iter_build_obj++)
		{
			if ((m_x > (*iter_build_obj)->get_x()) && (m_x < (*iter_build_obj)->get_x() + 40) && (m_y > (*iter_build_obj)->get_y()) && (m_y
					< (*iter_build_obj)->get_y() + 40))
			{
				select_from_buildmenu((*iter_build_obj));
			}
		}
	}

}
Esempio n. 2
0
bool Game::optbox_do_selection(int type, GridPosition position)
{
	/**
	 * Selects an option on the optionbox
	 */
	switch (type)
	{
	case BUTTON_BASE:
	{
		if (grid->get_tile(position)->get_tower() == NULL)
		{
			create_new_tower(towers::SIMPLE, position);
			return true;
		}
		break;
	}
	case BUTTON_BOOST:
	{
		if (grid->get_tile(position)->get_tower() == NULL)
		{
			create_new_tower(towers::BOOST, position);
			return true;
		}
		break;
	}
	case BUTTON_BASIC:
	{
		upgrade_tower(towers::BASIC);
		return true;
	}
	case BUTTON_BOMB:
	{
		upgrade_tower(towers::BOMB);
		return true;
	}
	case BUTTON_RANGE:
	{
		upgrade_tower(towers::RANGE);
		return true;
	}
	case BUTTON_SELL:
	{
		sell(tile_selection);
		return true;
	}
	case BUTTON_SPEED:
	{
		upgrade_tower(towers::SPEED);
		return true;
	}
	case BUTTON_UPGRADE:
	{
		Tower* t = grid->get_tile(position)->get_tower();
		if (t != NULL) {
			upgrade_tower(t->get_type());
			return true;
		} else {
			return false;
		}
		break;
	}
	case BUTTON_WALL:
	{
		create_new_tower(towers::WALL, position);
		return true;
	}
	default:
		break;
	} //Switch
	return false;
}