View Single Post
Seren Seren's Avatar

JCF Member

Joined: Feb 2010

Posts: 866

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Aug 19, 2014, 05:30 AM
Seren is offline
Reply With Quote
Most of behavior constants for the majority of objects are hard-coded so you can't technically change only the distance bats detect you from or chase you from without rewriting the whole behavior. However, the position bats return to when they lose interest is their (xOrg, yOrg), so you could keep setting those to player's current position in order to make the bat chase them regardless of whether the range check succeeds. The variable you mention, var[0], stores ID of currently chased player, so you should use
Code:
const jjPLAYER@ player = jjPlayers[obj.var[0]];
obj.xOrg = player.xPos;
obj.yOrg = player.yPos;
or equivalent code. Speed values for bats are also more or less hard-coded but you can just adjust their position manually yourself. We established that xOrg and yOrg will always contain the position the bat is trying to reach so the code can look something like this:
Code:
obj.xPos = obj.xPos + (obj.xOrg > obj.xPos ? 2.f : -2.f);
obj.yPos = obj.yPos + (obj.yOrg > obj.yPos ? 2.f : -2.f);
Both of these pieces of code will naturally best fit in a custom behavior function that also calls the original behavior. However, at least the second one of them only makes sense to call when the bat is actually chasing somebody. You can make sure about that with a state check.
Code:
void bat(jjOBJ@ obj) {
	const jjPLAYER@ player = jjPlayers[obj.var[0]];
	obj.xOrg = player.xPos;
	obj.yOrg = player.yPos;
	obj.behave(BEHAVIOR::BAT);
	if (obj.state == STATE::FLY) {
		obj.xPos = obj.xPos + (obj.xOrg > obj.xPos ? 2.f : -2.f);
		obj.yPos = obj.yPos + (obj.yOrg > obj.yPos ? 2.f : -2.f);
	}
}
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.