//--------------------------------------------------------------------------------------
// Copyright (C) 2008 http://shift.delblanco.es
//--------------------------------------------------------------------------------------
// SHIFT Videogame is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
//--------------------------------------------------------------------------------------
// PlayerLocal.cpp
//--------------------------------------------------------------------------------------
#include "dxstdafx.h"
#include "DXUT.h"

#include "PlayerLocal.h"

//--------------------------------------------------------------------------------------
// Variables Globales
//--------------------------------------------------------------------------------------
extern float			g_TimeGame;        // Tiempo de juego (Game.cpp)

//--------------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------------
CPlayerLocal::CPlayerLocal()
{

}

//--------------------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------------------
CPlayerLocal::~CPlayerLocal()
{
    // Liberamos estructuras internas

}

//--------------------------------------------------------------------------------------
// Inicializa el jugador local
//--------------------------------------------------------------------------------------
bool CPlayerLocal::initialize(LPCWSTR dName, LPCWSTR dPathVehicle, C3DObject *dParent, int dType)
{
    // Función de la clase padre
    if(!CPlayer::initialize(dName, dPathVehicle, dParent))
        return false;

	// Tomamos el tipo de jugador
	m_iType = dType;

	// Situamos el coche dependiendo del tipo de jugador
	switch(m_iType)
	{
	case PLAYERLOCAL_1:
		m_pVehicle->setPosition(D3DXVECTOR3(0.0f, 0.0f, 3.5f));
		break;
	case PLAYERLOCAL_2:
		m_pVehicle->setPosition(D3DXVECTOR3(0.0f, 0.0f, -3.5f));
		break;
	}

    return true;
}

//--------------------------------------------------------------------------------------
// Actualiza el jugador local
//--------------------------------------------------------------------------------------
void CPlayerLocal::update()
{
    // Salimos si no se ha inicializado
    if(!m_bInit) return;

    // Adecuamos los parámetros del coche en función del estado del teclado
	if (g_TimeGame > 0.0f)
	{
		switch(m_iType)
		{
		case PLAYERLOCAL_1:
			m_bUp        = GetAsyncKeyState(VK_UP);
			m_bDown      = GetAsyncKeyState(VK_DOWN);
			m_bRight     = GetAsyncKeyState(VK_RIGHT);
			m_bLeft      = GetAsyncKeyState(VK_LEFT);
			m_bHandBrake = GetAsyncKeyState(VK_SPACE);
			m_bMine      = GetAsyncKeyState(VK_RSHIFT);
			m_bRocket    = GetAsyncKeyState(VK_RCONTROL);
			break;
		case PLAYERLOCAL_2:
			m_bUp        = GetAsyncKeyState(0x57); // W
			m_bDown      = GetAsyncKeyState(0x53); // S
			m_bRight     = GetAsyncKeyState(0x44); // D
			m_bLeft      = GetAsyncKeyState(0x41); // A
			m_bHandBrake = GetAsyncKeyState(VK_CAPITAL);
			m_bMine      = GetAsyncKeyState(VK_LSHIFT);
			m_bRocket    = GetAsyncKeyState(VK_LCONTROL);
			break;
		}
	}

    // Llamamos a la función del padre
    CPlayer::update();
}
