Ejemplo n.º 1
0
void Agent::updateAudio(boost::shared_ptr<AudioSource> s) {
	assert(s);
	MetaRoom *room = world.map.metaRoomAt(x, y);
	if (!room) {
		// TODO: think about inrange when positioning outside-metaroom agents
		s->setPos(x + getWidth() / 2, y + getHeight() / 2, zorder);
		return;
	}

	float xc = x;

	bool inrange = false;
	if (inrange_at(room, x, y, getWidth(), getHeight())) {
		xc = x;
		inrange = true;
	} else if (room->wraparound()) {
		if (inrange_at(room, x - room->width(), y, getWidth(), getHeight())) {
			xc = x - room->width();
			inrange = true;
		} else if (inrange_at(room, x + room->width(), y, getWidth(), getHeight())) {
			xc = x + room->width();
			inrange = true;
		}
	}
	s->setMute(!inrange);
	if (inrange)
		s->setPos(xc + getWidth() / 2, y + getHeight() / 2, zorder);
	// TODO: setVelocity?
}
Ejemplo n.º 2
0
void Agent::moveTo(float _x, float _y, bool force) {
	// Move ourselves to the specified location.
	wasmoved = true;

	// if we're being carried and aren't being forced to move (prbly by our carrier), forget it
	if (carriedby && !force) return;
	
	// TODO: what if we move while being carried? doomy explosions ensue, that's what!
	float xoffset = _x - x;
	float yoffset = _y - y;		

	x = _x; y = _y;

	// handle wraparound
	// TODO: this is perhaps non-ideal
	if (engine.version < 3 && xoffset != 0.0f) {
		// TODO: it'd be nice to handle multiple metarooms
		MetaRoom *m = world.map.getFallbackMetaroom();
		assert(m);

		if (x < m->x()) {
			x += m->width();
		} else if (x > m->x() + m->width()) {
			x -= m->width();
		}
	}

	for (std::vector<AgentRef>::iterator i = floated.begin(); i != floated.end(); i++) {
		assert(*i);
		(*i)->moveTo((*i)->x + xoffset, (*i)->y + yoffset);
	}

	adjustCarried(xoffset, yoffset);
}
Ejemplo n.º 3
0
MetaRoom *Map::metaRoomAt(unsigned int _x, unsigned int _y) {
	for (std::vector<MetaRoom *>::iterator i = metarooms.begin(); i != metarooms.end(); i++) {
		MetaRoom *r = *i;
		if ((_x >= r->x()) && (_y >= r->y()))
			if ((_x <= (r->x() + r->width())) && (_y <= (r->y() + r->height())))
				return r;
	}
	return 0;
}