示例#1
0
bool circle_rectangle_test(Pos circle_xy, int circle_rad, BBox rect) {
	Pos rad_duped = Pos(circle_rad, circle_rad);
	if (rect.contains(circle_xy + rad_duped) || rect.contains(circle_xy - rad_duped)) {
		return true;
	}
	return circle_line_test(circle_xy, circle_rad, Pos(rect.x1, rect.y1), Pos(rect.x2, rect.y1)) ||
		circle_line_test(circle_xy, circle_rad, Pos(rect.x1, rect.y1), Pos(rect.x1, rect.y2)) ||
		circle_line_test(circle_xy, circle_rad, Pos(rect.x1, rect.y2), Pos(rect.x2, rect.y2)) ||
		circle_line_test(circle_xy, circle_rad, Pos(rect.x2, rect.y1), Pos(rect.x2, rect.y2));
}
示例#2
0
void KdTree::searchInternal(KdNode* node,const BBox& bb,int d,List<VecItem*>& items){
	if( node ){
		Vec pn = node->item->getPosition();
		if( (d==0 && bb.getMinX()<pn.getX()) || bb.getMinY()<pn.getY() ){
			searchInternal(node->left,bb,(d+1)%m_k,items);
		}
		if( bb.contains(pn) ){
			items.append( node->item );
		}
		if( (d==0 && pn.getX()<=bb.getMaxX()) || pn.getY()<=bb.getMaxY() ){
			searchInternal(node->right,bb,(d+1)%m_k,items);
		}
	}
}
示例#3
0
static int get_itemslotn(Inventory& inv, const BBox& bbox, int mx, int my) {
	if (!bbox.contains(mx, my)) {
		return -1;
	}

	int posx = (mx - bbox.x1) / TILE_SIZE;
	int posy = (my - bbox.y1) / TILE_SIZE;
	int slot = 5 * posy + posx;

	if (slot < 0 || slot >= inv.max_size())
		return -1;

	return slot;
}
示例#4
0
static void draw_option(GameState* gs, const BBox& bbox, bool option_set,
		sprite_id sprite, const char* text) {
	Colour bbox_col = option_set ? COL_WHITE : COL_FILLED_OUTLINE;
	if (bbox.contains(gs->mouse_pos())) {
		bbox_col = COL_GOLD;
	}

	gl_draw_sprite(sprite, bbox.x1, bbox.y1,
			COL_WHITE.with_alpha(option_set ? 255 : 100));
	/* Draw item name */
	gl_printf_bounded(gs->primary_font(), option_set ? COL_WHITE : COL_MID_GRAY,
			bbox.x1 + TILE_SIZE * 1.25, bbox.y1 + TILE_SIZE / 2,
			bbox.width() - TILE_SIZE, true, "%s", text);
	gl_draw_rectangle_outline(bbox, bbox_col);
}
示例#5
0
void IOController::trigger_events(const BBox& playing_area) {

	// Loop over all possible keys to find active key states
	for (int i = SDLK_FIRST + 1; i < SDLK_LAST; i++) {
		IOEventTrigger::trigger_t notrigger = IOEventTrigger::NONE;
		if (iostate.key_press_states[i]) {
			// Trigger key press events
			__trigger_events(notrigger, SDLKey(i), iostate.keymod, false);
		} else if (iostate.key_down_states[i]) {
			// Trigger key hold events
			__trigger_events(notrigger, SDLKey(i), iostate.keymod, true);
		}
	}

	if (playing_area.contains(mouse_x(), mouse_y())) {
		if (mouse_left_click() || mouse_left_down()) {
			__trigger_events(IOEventTrigger::MOUSE_LEFT_CLICK, SDLKey(0),
					iostate.keymod, !mouse_left_click());
		}
		if (mouse_right_click() || mouse_right_down()) {
			__trigger_events(IOEventTrigger::MOUSE_RIGHT_CLICK, SDLKey(0),
					iostate.keymod, !mouse_left_click());
		}
	}

	if (iostate.mouse_middleclick || iostate.mouse_middledown) {
		__trigger_events(IOEventTrigger::MOUSE_MIDDLE_CLICK, SDLKey(0),
				iostate.keymod, !iostate.mouse_middleclick);
	}
	if (mouse_upwheel()) {
		__trigger_events(IOEventTrigger::MOUSE_WHEEL_UP, SDLKey(0),
				iostate.keymod, false);
	}
	if (mouse_downwheel()) {
		__trigger_events(IOEventTrigger::MOUSE_WHEEL_DOWN, SDLKey(0),
				iostate.keymod, false);
	}
	if (mouse_downwheel()) {
		__trigger_events(IOEventTrigger::MOUSE_WHEEL_DOWN, SDLKey(0),
				iostate.keymod, false);
	}
}