#include "..\C-Engine\CHeader.hpp" #include "control.hpp" char *str_remplace ( char *s, unsigned int x, const char *ct) { char *new_s = NULL; if (s != NULL && ct != NULL && x >= 0) { size_t size = strlen (s); new_s = (char*)malloc (sizeof (*new_s) * (size + strlen (ct))); if (new_s != NULL) { memcpy (new_s, s, x); memcpy (&new_s[x], ct, strlen (ct)); memcpy (&new_s[x + strlen (ct)], &s[x + 1], size - 1 - x + 1); } } else return s; return new_s; } void Control::Initialisation(Script_GUI * v) { SGUI = v ; } void Control::Start() { direction = 0; directionuser = 0; objectif = 0; for( int i = 0; i < GetEngine()->GetMap()->nbtiles_largeur_monde; i++) { for( int j = 0 ; j < GetEngine()->GetMap()->nbtiles_hauteur_monde; j++) { switch(GetEngine()->GetMap()->map[j][i] - '0') { case 15: case 16: objectif ++; break; default: break; } } } } void Control::Update() { GetObject()->GetRender()->SetIt(0); switch(input_dir4()) { case 2: directionuser = 3; break; case 4: directionuser = 4; break; case 6: directionuser = 2; break; case 8: directionuser = 1; break; } if(!GetObject()->GetRigibody()->CollisionDecor( GetX() + (directionuser == 2) - (directionuser == 4) , GetY() + (directionuser == 1) - (directionuser == 3) ))direction = directionuser; switch(direction) { case 1: Move(0,1); GetObject()->GetRender()->SetDirection(90);GetObject()->GetRender()->ReverseRender(false); break; case 2: Move(1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(false);break; case 3: Move(0,-1); GetObject()->GetRender()->SetDirection(270); GetObject()->GetRender()->ReverseRender(false);break; case 4: Move(-1,0); GetObject()->GetRender()->SetDirection(0); GetObject()->GetRender()->ReverseRender(true);break; } int x , y; x = GetX()/3 + 2; y = 91 - GetY()/3 - 3; switch(GetEngine()->GetMap()->map[y][x] - '0') { case 15 : GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); SGUI->AddScore(200); objectif--; break; case 16: GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x+1 , "0"); GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x , "0"); GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x+1 , "0"); SGUI->AddScore(500); SGUI->SetVulnerability(8); objectif--; break; case 17: GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x-1 , "0"); GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x , "0"); GetEngine()->GetMap()->map[y+1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y+1], x-1 , "0"); SGUI->AddScore(500); SGUI->SetVulnerability(8); objectif--; break; case 18: GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x+1 , "0"); GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x , "0"); GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x+1 , "0"); SGUI->AddScore(500); SGUI->SetVulnerability(8); objectif--; break; case 19: GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x , "0"); GetEngine()->GetMap()->map[y] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y], x-1 , "0"); GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x , "0"); GetEngine()->GetMap()->map[y-1] = (unsigned char*)str_remplace((char*)GetEngine()->GetMap()->map[y-1], x-1 , "0"); SGUI->AddScore(500); SGUI->SetVulnerability(8); objectif--; break; default: break; } if(objectif <= 0) { ML_clear_vram(); PrintXY(30,28,"You Win",0); ML_display_vram(); Sleep(1500); GetEngine()->StopGame(); } Object * Ennemi = GetObject()->CollisionTagO("Ghost"); if(Ennemi != NULL) { if(SGUI->GetVulnerability() <= 0)Die(); else Ennemi->GetTransforms()->SetXY(116,131); } if(GetObject()->CollisionTag("TP1")) { GetObject()->GetTransforms()->SetXY(229,138); direction = 4; } if(GetObject()->CollisionTag("TP2")) { GetObject()->GetTransforms()->SetXY(2,138); direction = 2; } if(input_trigger(K_EXIT))GetEngine()->StopGame(); GetEngine()->MiddleScreen(GetX() + 18 , GetY() + 8 ,false); } void Control::Die() { bool cinematic = true; GetObject()->GetRender()->SetIt(1); while(cinematic == true) { ML_clear_vram(); GetEngine()->GetMap()->AfficherMap(); GetObject()->GetRender()->DrawObject(); ML_display_vram(); if(GetObject()->GetRender()->GetisEnd())cinematic = false; Sleep(100); } ML_clear_vram(); GetEngine()->GetMap()->AfficherMap(); ML_display_vram(); Sleep(250); GetObject()->GetRender()->SetIt(0); GetObject()->GetTransforms()->SetXY(116, 57); SGUI->DelVie(1); }