Beispiel #1
0
void Label::render()
{
	if (m_visible)
	{
		Vector2 pos = getAbsolutePosition();
		String text = String(m_text.c_str());
	
		if (!m_pushed)
			Renderer::Instance().SetColor(m_r, m_g, m_b, 255);
		else
			Renderer::Instance().SetColor((uint8)WrapValue (m_r - 50,255), (uint8)WrapValue (m_g - 50,255), (uint8)WrapValue (m_b - 50,255), 255);
	
		m_font->Render(text,pos.x, pos.y);
		Renderer::Instance().SetColor(255, 255, 255, 255);
	}
}
Beispiel #2
0
void Sprite::Update(double elapsed, const Map* map) {
			
	// Informacion inicial de colision
	colSprite = NULL;
	collided = false;

	// TAREA: Actualizar animacion	
	currentFrame+=elapsed * animFPS;
		
	if (currentFrame > lastFrame)
		currentFrame = firstFrame;
	
	// TAREA: Actualizar rotacion animada
	if (rotating)
	{		
		angle+=elapsed * rotatingSpeed;
		angle= WrapValue(angle,360);

		anglesToRotate-=abs(elapsed * rotatingSpeed);

		if (anglesToRotate <= 0)
			rotating = false;					
	}

	// TAREA: Actualizar movimiento animado
	if (moving)
	{
		x+= elapsed * movingSpeedX;
		y+= elapsed * movingSpeedY;

		if ((movingSpeedX > 0 && x >= toX) || (movingSpeedX < 0 && x <= toX))
			x = toX;

		if ((movingSpeedY > 0 && y >= toY) || (movingSpeedY < 0 && y <= toY))
			y = toY;

		if (x == toX && y == toY)
			moving = false;					
	}

	//ESCALADO	
	if (scaling)
	{
		scalex+= elapsed * scalingSpeedX;
		scaley+= elapsed * scalingSpeedY;

		if ((scalingSpeedX > 0 && scalex >= toScaleX) || (scalingSpeedX < 0 && scalex <= toScaleX))
			scalex = toScaleX;

		if ((scalingSpeedY > 0 && scaley >= toScaleY) || (scalingSpeedY < 0 && scaley <= toScaleY))
			scaley = toScaleY;

		if (scalex == toScaleX && scaley == toScaleY)
			scaling = false;		
	}

	// Informacion final de colision
	UpdateCollisionBox();
}
Beispiel #3
0
void Sprite::RotateTo(int32 angle, double speed) {
	
	toAngle = WrapValue(angle,360);	
			
	//giramos en sentido horario
	if ( WrapValue(toAngle - this->angle,360) > WrapValue(this->angle - toAngle,360))
	{	rotatingSpeed = speed * -1;		
		anglesToRotate = WrapValue(this->angle - toAngle,360);
	}
	else //giramos en sentido antihorario
	{	rotatingSpeed = speed;
		anglesToRotate = WrapValue(toAngle - this->angle,360);
	}

	rotating = true;

}
Beispiel #4
0
double Angle(double x1, double y1, double x2, double y2) {
    // TAREA: Implementar funcion
    double x = x2 - x1;
    double y = -(y2 - y1);
    double angle = 0;

    angle = WrapValue( DegATan2(y, x), 360);

    return angle;
}
Beispiel #5
0
double Bone::RotationForFrame(int32 f) const {
    const Frame* frame = NULL, * prevFrame = NULL, * nextFrame = NULL;
	GetFrame(f, &frame, &prevFrame, &nextFrame);

	if ( frame != NULL )
		return frame->GetRotation();
	else if ( prevFrame != NULL  &&  nextFrame != NULL )
		return WrapValue(Interpolate(f, prevFrame->GetId(), nextFrame->GetId(), prevFrame->GetRotation(), nextFrame->GetRotation()), 360);
	else
		return 0;
}
Beispiel #6
0
void Sprite::RotateTo(int32 angle, double speed) {
	double wrapAngle = WrapValue(angle, 360); 
	if (wrapAngle == WrapValue(this->angle, 360) || speed == 0)
		this->rotating = false; 
	else {
		this->rotating = true;
		this->toAngle = wrapAngle; 

		uint16 wrapAngle = (uint16)WrapValue(this->angle, 360);
		double ccw = WrapValue(this->toAngle - wrapAngle, 360);
		double cw = WrapValue(wrapAngle - this->toAngle, 360);

		if (min(ccw, cw) == ccw) {
			this->degreesToRotate = ccw; 
			this->rotatingSpeed = fabs(speed); 
		}
		else {
			this->degreesToRotate = cw;
			this->rotatingSpeed = -fabs(speed);
		}
	}
}
Beispiel #7
0
double Angle(double x1, double y1, double x2, double y2) {
	return WrapValue(DegATan2(y1-y2, x2-x1), 360);
}
Beispiel #8
0
int main(int argc, char* argv[]) 
{
	Screen &screen = Screen::Instance();
	const Renderer &render = Renderer::Instance();

	screen.Open(800, 600, false);

	//inicamos el motor de sonido
	AudioEngine::Instance().Init();

	//cargamos recursos
	AudioBuffer* wav = ResourceManager::Instance().LoadAudioBuffer("data/music.wav");
	AudioSource source = AudioSource(wav);
	Font* fuente = ResourceManager::Instance().LoadFont("data/arial16_2.png");
				
	float x,y,pitch;
	x = screen.GetWidth() / 2;
	y = screen.GetHeight() / 2;
	pitch = 1;
	source.SetGain(2);

	//sitamos el listener en el centro de la pantalla
	Listener::Instance().SetPosition(x, y, 0);	
		
	while (screen.IsOpened()  &&  !screen.KeyPressed(GLFW_KEY_ESC)) 
	{		
		render.Clear();

		//actualizamos la posicion del source y su pitch
		source.SetPosition(x, y, 0);
		source.SetPitch(pitch);

		if (!source.IsPlaying())
			source.Play();
		
		if (screen.KeyPressed(GLFW_KEY_LEFT))
			x-=50 * screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_RIGHT))
			x+=50 * screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_UP))
			pitch+= screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_DOWN))
			pitch-= screen.ElapsedTime();
		else if (screen.KeyPressed(GLFW_KEY_SPACE))
		{
			x = screen.GetWidth() / 2;
			pitch = 1;
		}

		x = WrapValue(x, screen.GetWidth());		

		//pintamos texto informativo y posicion de la fuente
		render.SetColor(255,125,0,255);
		render.DrawEllipse(x,y,10,10);

		render.SetColor(255,255,255,255);
		render.DrawText(fuente, String("cursor izquierda : desplazar fuente a la izquierda"),10,10);
		render.DrawText(fuente, String("cursor derecha : desplazar fuente a la derecha"),10,30);
		render.DrawText(fuente, String("cursor arriba : aumentar pitch"),10,50);
		render.DrawText(fuente, String("cursor abajo : disminuir pitch"),10,70);
		render.DrawText(fuente, String("espacio : resetear pitch y posicion"),10,90);
		render.DrawText(fuente, String("pitch: ") + String::FromFloat(pitch),10,110);
		render.DrawText(fuente, String("(Listener)"),(screen.GetWidth() / 2) - fuente->GetTextWidth(String("(Listener)")) / 2,  screen.GetHeight() / 2 + 20);

        screen.Refresh();
	}

	//paramos el source
	source.Stop();

	//paramos motor audio y liberamos recursos
	AudioEngine::Instance().Finish();
	ResourceManager::Instance().FreeResources();
		
	return 0;
}
Beispiel #9
0
void Sprite::Render() const {

	Renderer::Instance().SetBlendMode(this->blendMode);
	Renderer::Instance().SetColor(GetRed(), GetGreen(), GetBlue(), GetAlpha());
	Renderer::Instance().DrawImage(this->image,x,y,(uint32)currentFrame,(double)(image->GetWidth() * scalex), (double)(image->GetHeight() * scaley), WrapValue(angle,360));
}