#include "player.h"
void player::Init()
{
m_pSpriteShot = new sprite;
m_pSpriteShot->Load("Data/schuss.bmp");
m_pSpriteShot->SetColorKey(255, 255, 255);
m_pSpritePlayer = new sprite;
m_pSpritePlayer->Load("Data/lülülü.bmp");
m_pSpritePlayer->SetColorKey(255, 255, 255);
m_pSpriteKiste = new sprite;
m_pSpriteKiste->Load("Data/non.bmp");
m_pSpriteKiste->SetColorKey(255, 0, 255);
SpawnAsteroids();
cout << "\nInit Player ging\n";
Yposi = 500;
anzahlschuesse = 0;
jumping = false;
jumplock = true;
shotlock = false;
}
void player::processmoving ()
{
if (g_pVerwaltung->KeyDown (SDLK_RIGHT))
{
Xposi += 200.0f * g_pTimer->GetElapsed ();
}
if (g_pVerwaltung->KeyDown (SDLK_LEFT))
{
Xposi -= 200.0f * g_pTimer->GetElapsed ();
}
if(g_pVerwaltung->KeyDown (SDLK_DOWN) && g_pVerwaltung->KeyDown (SDLK_RIGHT))
{
Xposi += 400.0f *g_pTimer->GetElapsed ();
}
if(g_pVerwaltung->KeyDown (SDLK_DOWN) && g_pVerwaltung->KeyDown (SDLK_LEFT))
{
Xposi -= 400.0f *g_pTimer->GetElapsed ();
}
if(jumplock == true)
{
if(g_pVerwaltung->KeyDown (SDLK_SPACE))
{
Gravitation = 9.81f;
Vertikal = 1.0f;
h = 50.0f;
jumping = true;
jumplock = false;
}
}
Yposi += 9.81f;
if (Yposi >= 500)
Yposi = 500;
}
void player::Render()
{
m_pSpritePlayer->SetPosi(Xposi, Yposi);
m_pSpritePlayer->Render();
cout<< "Render ging";
list<shot>::iterator it = m_Shotlist.begin();
while (it != m_Shotlist.end ())
{
it->update();
if (it->IsAlive())
{
it->Render();
it++;
}
else
{
it = m_Shotlist.erase (it);
anzahlschuesse--;
}
}
}
void player::jump()
{
if (jumping == true)
{
h -= Vertikal + Gravitation * g_pTimer->GetElapsed();
Yposi -= h + Gravitation * g_pTimer->GetElapsed();
Xposi ++;
if ( h <= -40)
{
//Yposi = 500;
jumping = false;
jumplock = true;
}
}
}
void player::proccessshoting()
{
if(anzahlschuesse < 3)
{
if(g_pVerwaltung->KeyDown(SDLK_DOWN) && shotlock == false)
{
shot shoot;
shoot.Init(m_pSpriteShot , Xposi + 120 , Yposi + 41);
m_Shotlist.push_back(shoot);
anzahlschuesse++;
shotlock = true;
}
if (g_pVerwaltung->KeyDown(SDLK_DOWN) == false)
shotlock = false;
}
}
void player::SpawnAsteroids ()
{
KistenundAnderes Kiste;
int XPos = 500; //rand()%736;
Kiste.Init (m_pSpriteKiste, static_cast<float>(XPos), 400.0f);
m_KistenList.push_back (Kiste);
}
void player::CheckCollisions ()
{
list<KistenundAnderes>::iterator ItKiste = m_KistenList.begin ();
SDL_Rect Kiste;
SDL_Rect Player;
Kiste = m_pSpriteKiste->GetRect();
Player = m_pSpritePlayer->GetRect ();
if (Player.x > Kiste.x - Player.w/2 && Player.y - Player.h > Kiste.y - Kiste.h && Player.x < Kiste.x + Player.w - 10) //&& RectShot.y > RectAsteroid.h)
{
Xposi = Kiste.x - Player.w/2;
cout << "Check Collision";
}
if (Player.x < Kiste.x + Kiste.w && Player.y - Player.h > Kiste.y - Kiste.h && Player.x > Kiste.x + Player.w) //&& RectShot.y > RectAsteroid.h)
{
Xposi = Kiste.x + Kiste.w;
cout << "Check Collision";
}
if (Player.x > Kiste.x - Player.w/2 && Player.y - Player.h < Kiste.y - Kiste.h && Player.x < Kiste.x + Player.w - 10 && Player.y > Kiste.y - Kiste.h - 10) //&& RectShot.y > RectAsteroid.h)
{
Yposi = Kiste.y - Kiste.h/2 - 10 ;
cout << "Check Collision";
}
}
void player::RenderKiste()
{
list<KistenundAnderes>::iterator ItKiste = m_KistenList.begin ();
while (ItKiste != m_KistenList.end () )
{
ItKiste->Render();
ItKiste++;
}
}