Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
/**
  * Aufforderung zur Neuzeichnung.
  * @param window     Verweis auf das Fenster, in dem die Figur
  *                   erscheinen soll.
  * @param cellWidth  Breite einer Zelle auf dem Spielfeld in Pixeln.
  * @param cellHeight Hoehe einer Zelle auf dem Spielfeld in Pixeln.
  */
void Pacman::draw(Gosu::Graphics& graphics, int cellWidth, int cellHeight) 
{
	Gosu::Color foo(255, 255, 0);

	//this->spriteset[mouthStatus]->draw(4 + xOffset + this->cellX * cellWidth, 4 + yOffset + this->cellY * cellHeight, 2);

	/*graphics.drawQuad(xOffset + this->cellX * cellWidth, yOffset + this->cellY * cellHeight, foo,
					  xOffset + this->cellX * cellWidth + cellWidth, yOffset + this->cellY * cellHeight, foo,
					  xOffset + this->cellX * cellWidth, yOffset + this->cellY * cellHeight + cellHeight, foo,
					  xOffset + this->cellX * cellWidth + cellWidth, yOffset + this->cellY * cellHeight + cellHeight, foo, 3);*/
	drawArc(graphics, foo, cellWidth, cellHeight, true, Descriptor.circle, (mouthOpenAngle / 2 + getAngleFromDirection() * 90), (360 - mouthOpenAngle));

/*
	QPainter painter(window);
	// Zeichenfarbe setzen
	painter.setPen(QColor(255, 255, 0));
	painter.setBrush(Qt::SolidPattern);
	painter.setRenderHint(QPainter::Antialiasing);
	// Kreissegment zeichnen
	drawArc(painter, cellWidth, cellHeight,
			true, Descriptor.circle, (mouthOpenAngle / 2 + getAngleFromDirection() * 90), 
			(360 - mouthOpenAngle)); */
}