Ejemplo n.º 1
0
void ComponentSpinAround::update(float milliseconds) {
	facingAngle = angle_clamp(facingAngle += rotationSpeed*milliseconds);
	bounce = angle_clamp(bounce += bounceSpeed*milliseconds);
	
	broadcastOrientation();
	broadcastPosition();
}
Ejemplo n.º 2
0
void ComponentSpinAround::update(float milliseconds)
{
	facingAngle = angle_clamp(facingAngle += rotationSpeed*milliseconds);
	bounce = angle_clamp(bounce += bounceSpeed*milliseconds);

	mat3 orientation = mat3::fromRotateZ(facingAngle);
	orientation = orientation * mat3::fromRotateX((float)(M_PI / 2.0));
	getParentBlackBoard().relayMessage(MessageRequestSetOrientation(orientation));

	vec3 offset = vec3(0.0f, 0.0f, cosf(bounce))*bounceHeight;
	vec3 pos = initialPosition + offset;
	getParentBlackBoard().relayMessage(MessageRequestPositionBeSet(pos));
}
Ejemplo n.º 3
0
bool ComponentBrainShooter::canDetectPlayer(const Actor &player)
{
	ComponentPhysics* component =
		dynamic_cast<ComponentPhysics*>(player.getComponent("Physics"));

	if(!component) return false;

	vec3 playerPosition3D = component->getPosition();
	vec2 playerPosition = vec2(playerPosition3D.x, playerPosition3D.y);
	vec3 ourPosition3D = getPosition3D();
	vec2 ourPosition = getPosition2D();
	
	float distance = getDistance(playerPosition, ourPosition);
	
	if(distance < maxSightDistance)
	{
		float radian_fov = fov * float(M_PI / 180.0);
		float facingAngle = getAngleFromDirection(getCurrentFacing());
		float minFOV = angle_clamp(facingAngle - radian_fov);
		float maxFOV = angle_clamp(facingAngle + radian_fov);
	
		float angleToTarget = getAngle(playerPosition, ourPosition);
	
#if 0
		if(isAngleWithinFOV(angleToTarget, minFOV, maxFOV))
		{
			// Do a fine-detail check against physics geometry (e.g. walls)
			return rayCast(player,
			               ourPosition3D,
						   playerPosition3D - ourPosition3D,
						   maxSightDistance);
		}
#else
		// Do a fine-detail check against physics geometry (e.g. walls)
		return rayCast(player,
			           ourPosition3D,
		               playerPosition3D - ourPosition3D,
		               maxSightDistance);
#endif
	}

	return false;
}
Ejemplo n.º 4
0
void ComponentBrainShooter::drawFOV() const
{
	float radius = maxSightDistance;
	float radian_fov = fov * float(M_PI / 180.0);
	float facingAngle = getAngleFromDirection(getCurrentFacing());
	float minFOV = angle_clamp(facingAngle - radian_fov);
	float maxFOV = angle_clamp(facingAngle + radian_fov);

	vec2 p = getPosition2D();
	vec2 a = vec2(cosf(minFOV), sinf(minFOV))*(radius+0.25f);
	vec2 b = vec2(cosf(maxFOV), sinf(maxFOV))*(radius+0.25f);
	vec2 c = vec2(cosf(facingAngle), sinf(facingAngle))*(radius+0.25f);

	glLineWidth(1.0f);

	glBegin(GL_LINES);
		glColor4fv(yellow);
		glVertex3f(p.x, p.y, 0.5f);
		glVertex3f(p.x + a.x, p.y + a.y, 0.5f);

		glColor4fv(yellow);
		glVertex3f(p.x, p.y, 0.5f);
		glVertex3f(p.x + b.x, p.y + b.y, 0.5f);

		glColor4fv(green);
		glVertex3f(p.x, p.y, 0.5f);
		glVertex3f(p.x + c.x, p.y + c.y, 0.5f);
	glEnd();

	glColor4fv(state==StateChase ? red : yellow);
	glBegin(GL_LINE_LOOP);
	for(size_t j=0; j<16; ++j)
	{
		const float angle = (float)j / 8.0f * float(M_PI * 2.0);
		glVertex3f(radius * cosf(angle) + p.x,
		           radius * sinf(angle) + p.y,
		           0.5f);
	}
	glEnd();
}
Ejemplo n.º 5
0
Action ComponentBrainKamikaze::getNextAction_wander(float milliseconds)
{
	if(canDetectAnyPlayer())
	{
		nextState = StateChase;
	}

	if((wanderTimer -= milliseconds) <= 0.0f)
	{
		wanderTimer = FRAND_RANGE(500.0f, 2000.0f);

		float d = ((float)M_PI / 2.0f) * FRAND_RANGE(-1.0f, 1.0f);
		wanderAngle = getAngleFromDirection(getCurrentFacing()) + d;
		wanderAngle = angle_clamp(wanderAngle);
	}

	return getActionFromAngle(wanderAngle);
}
Ejemplo n.º 6
0
void ComponentMovement::turn( float dAngle ) {
	if (!dead || getDeathBehavior()==Ghost) {
		facingAngle = angle_clamp(facingAngle + dAngle);
	}
}
Ejemplo n.º 7
0
void RenderMethod_Grass_CG::tick( float timeStep ) {
	float dAngle = (timeStep / 1000.0f) * (float)(M_PI / 9.0f);
	angle = angle_clamp(angle + dAngle);
}