#include <d3d8.h>

#include ".\gsmenu.h"
#include ".\GSDone.h"
#include ".\LD.h"



GSDone::GSDone()
{
  m_Player.X = 270;
  m_Player.Y = 190;
  m_Player.SizeFactor = 0.5f;
  m_SecondPlayer = false;

  m_GrowDelay = 0.0f;
}



GSDone::~GSDone()
{
}



void GSDone::Display( IDirect3DDevice8* pDevice )
{
  theApp.m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );

  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
  theApp.m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

  theApp.RenderTextureSection2d( 0, 0, theApp.m_TexSec[LD::TEX_TITLE] );

  theApp.PrintNiceCentered( 320, 350, "CONGRATULATIONS" );
  theApp.PrintNiceCentered( 320, 390, "IT'S MITOSIS TIME!" );

  m_Player.Display();
  if ( m_SecondPlayer )
  {
    m_Player2.Display();
  }
}



void GSDone::UpdateFrame( const float ElapsedTime )
{
  if ( !m_SecondPlayer )
  {
    if ( m_Player.SizeFactor < 5.0f )
    {
      if ( m_GrowDelay < 5.0f )
      {
        m_GrowDelay += ElapsedTime;
      }
      else
      {
        m_Player.SizeFactor += 5.0f * ElapsedTime;
      }
    }
    else if ( !m_SecondPlayer )
    {
      m_SecondPlayer = true;

      m_Player2.X = 240;
      m_Player2.Y = 190;
      m_Player2.SizeFactor = 2.5f;
      m_Player2.Angle = 45.0f;

      m_Player.SizeFactor = 2.5f;
      m_Player.X = 300;
      m_Player.Y = 190;
    }
  }
  m_Player.AnimDelay += ElapsedTime;
  if ( fmodf( m_Player.AnimDelay, 0.5f ) >= 0.25f )
  {
    m_Player.m_Texture = LD::TEX_PLAYER_1;
  }
  else
  {
    m_Player.m_Texture = LD::TEX_PLAYER_2;
  }
  m_Player2.AnimDelay += ElapsedTime;
  if ( fmodf( m_Player2.AnimDelay, 0.5f ) >= 0.25f )
  {
    m_Player2.m_Texture = LD::TEX_PLAYER_1;
  }
  else
  {
    m_Player2.m_Texture = LD::TEX_PLAYER_2;
  }
}



void GSDone::OnMouse( int X, int Y, int Buttons )
{

}



void GSDone::OnChar( int iChar )
{
  if ( ( iChar == 27 )
  ||   ( iChar == ' ' ) )
  {
    theApp.NextState( new CGSMenu() );
  }
}



void GSDone::OnKeyDown( int iChar )
{

}