KirbyDreamLand/GUI.cpp

348 lines
14 KiB
C++

#include "GUI.hpp"
extern "C"
{
#include <math.h>
}
void Script_GUI::Start()
{
vie = 6;
restart = 4;
score = 0;
timer = 500;
}
void Script_GUI::Update()
{
ML_rectangle(0,57,127,63,1,ML_WHITE,ML_WHITE);
const unsigned char SVie[]={0x77, 0x8f, 0x8f, 0x77, };
const unsigned char Keby[]={0x3e, 0x0, 0x41, 0x11, 0x80, 0x8a, 0xa4, 0x84, 0xa4, 0x8a, 0x41, 0x51, 0xff, 0xc0, };
int position;
if(score >99999) position = 12;
else if(score >9999) position = 16;
else if(score >999) position = 20;
else if(score >99) position = 24;
else if(score >9) position = 28;
else position = 32;
PrintMini(1,58,"Sc:",0);
PrintV(position,58,score);
PrintMini(39,58,"Kirby",0);
if(vie > 0)ML_bmp_or(SVie , 62 , 59 , 5 , 4);
if(vie > 1)ML_bmp_or(SVie , 68 , 59 , 5 , 4);
if(vie > 2)ML_bmp_or(SVie , 74 , 59 , 5 , 4);
if(vie > 3)ML_bmp_or(SVie , 80 , 59 , 5 , 4);
if(vie > 4)ML_bmp_or(SVie , 86 , 59 , 5 , 4);
if(vie > 5)ML_bmp_or(SVie , 92 , 59 , 5 , 4);
if(vie < 1)ML_rectangle(63,60,65,61, 1 , ML_BLACK , ML_BLACK);
if(vie < 2)ML_rectangle(69,60,71,61, 1 , ML_BLACK , ML_BLACK);
if(vie < 3)ML_rectangle(75,60,77,61, 1 , ML_BLACK , ML_BLACK);
if(vie < 4)ML_rectangle(81,60,83,61, 1 , ML_BLACK , ML_BLACK);
if(vie < 5)ML_rectangle(87,60,89,61, 1 , ML_BLACK , ML_BLACK);
if(vie < 6)ML_rectangle(93,60,95,61, 1 , ML_BLACK , ML_BLACK);
ML_rectangle(114,-1,129,7,1,ML_BLACK, ML_WHITE);
ML_pixel(114,7,ML_WHITE);
if(timer / 100)
PrintV(116,1,timer);
else if(timer / 10)
PrintV(120,1,timer);
else
PrintV(124,1,timer);
ML_bmp_or(Keby , 102 , 57 , 16 , 7);
PrintV(122 , 58 , restart);
if(input_press(K_EXIT))GetEngine()->StopGame();
}
void Script_GUI::UpdateEverySecond()
{
timer --;
if(timer < 0)
{
vie = 0;
restart = 0;
Lose();
}
}
void Script_GUI::DelVie(int v)
{
vie -= v;
if(vie <= 0)
{
Lose();
vie = 6;
}
}
int Script_GUI::GetVie()
{
return vie;
}
void Script_GUI::AddScore(int v)
{
if(v > 0)score += v;
}
void Script_GUI::Lose()
{
bool cinematic = true;
Object * Kirby;
for(int i = 0 ; i < GetEngine()->GetCurrentLevel()->GetNbObject() ; i++ )
{
if(!strcmp(GetEngine()->GetCurrentLevel()->GetListeObject()[i]->GetTag(), "Kirby"))Kirby = GetEngine()->GetCurrentLevel()->GetListeObject()[i];
}
int y = Kirby->GetTransform()->GetY();
float force = 4.5;
Kirby->GetRender()->ForceSetIt(11);
ML_clear_vram();
GetEngine()->GetCurrentLevel()->DrawMap();
Kirby->GetTransform()->SetY(y);
GetEngine()->UpdateRelativePosition();
Kirby->GetRender()->DrawObject();
Update();
ML_display_vram();
Sleep(400);
while(cinematic)
{
y += force;
force -= 0.25;
ML_clear_vram();
if(y < -16) cinematic = false;
GetEngine()->GetCurrentLevel()->DrawMap();
Kirby->GetTransform()->SetY(y);
GetEngine()->UpdateRelativePosition();
Kirby->GetRender()->DrawObject();
Update();
ML_display_vram();
Sleep(25);
}
restart --;
if(restart <= 0)
{
TryAgain();
}
switch(Kirby->GetEngine()->GetIdCurrentLevel())
{
default: Kirby->GetTransform()->SetXY(8, 32); break;
case 0: Kirby->GetTransform()->SetXY(8, 32); break;
case 1: Kirby->GetTransform()->SetXY(8 , 16 ); break;
case 2: Kirby->GetTransform()->SetXY(96 , 32); break;
case 3: Kirby->GetTransform()->SetXY(16 , 336 ); break;
case 4: Kirby->GetTransform()->SetXY(112 , 48); break;
}
}
void Script_GUI::TryAgain()
{
bool end = false;
int choix = 0;
float b;
const unsigned char Pointeur[]={0x3, 0x80, 0x1f, 0x4, 0x40, 0x1f, 0x4, 0x40, 0x1f, 0x8, 0x80, 0x1f, 0x30, 0xff, 0xdf, 0x40, 0x0, 0x3f, 0x81, 0xf0, 0x3f, 0x82, 0xf, 0xdf, 0x82, 0x8, 0x1f, 0x82, 0x8, 0x1f, 0x41, 0xf0, 0x1f, 0x42, 0x8, 0x1f, 0x3a, 0x8, 0x1f, 0x1, 0xf0, 0x1f, };
const unsigned char Bulle[]={0x30, 0x3f, 0x48, 0x3f, 0x84, 0x3f, 0x84, 0x3f, 0x48, 0x3f, 0x30, 0x3f, 0x0, 0x3f, 0x1, 0xbf, 0x2, 0x7f, 0x2, 0x7f, 0x1, 0xbf, };
const unsigned char KS1[]={0x3, 0xe0, 0x7f, 0xc, 0x18, 0x7f, 0x10, 0x4, 0x7f, 0x20, 0x2, 0x7f, 0x20, 0x2, 0x7f, 0x40, 0x1, 0x7f, 0x44, 0x61, 0x7f, 0x42, 0x81, 0x7f, 0xc0, 0x3, 0x7f, 0xa1, 0x4, 0xff, 0x91, 0x8, 0xff, 0x88, 0x10, 0xff, 0x85, 0x31, 0x7f, 0x7a, 0xde, 0x7f, };
const unsigned char KS2[]={0x0, 0x0, 0x7f, 0x3, 0xe0, 0x7f, 0xc, 0x18, 0x7f, 0x10, 0x4, 0x7f, 0x20, 0x2, 0x7f, 0x20, 0x2, 0x7f, 0x40, 0x1, 0x7f, 0x44, 0x61, 0x7f, 0x42, 0x83, 0x7f, 0xa0, 0x4, 0xff, 0x91, 0x8, 0xff, 0x88, 0x10, 0xff, 0x8c, 0x31, 0x7f, 0x77, 0xde, 0x7f, };
Sprite S_Kirby_Sleep1(KS1, 17 , 14 );
Sprite S_Kirby_Sleep2(KS2, 17 , 14 );
Sprite S_Kirby_Sleep[]={ S_Kirby_Sleep1 , S_Kirby_Sleep2};
Animation A_Sleep(S_Kirby_Sleep , 2 , 750);
ML_clear_vram();
PrintXY(35,25,"GAME OVER",0);
ML_display_vram();
Sleep(1500);
b = -15;
while(end == false)
{
ML_clear_vram();
input_update();
PrintXY( 20 , 5 , "Kirby's DreamLand" , 0);
PrintXY( 35 , 25 , "Continue" , 0);
PrintXY( 35 , 35 , "End" , 0);
A_Sleep.DrawAnim( 95 , 45 , 0);
if( b > 0) ML_bmp_or( Bulle , 90 - b , 44 - b , 10 ,11 );
b += 0.1; if( b > 10) b = -15;
if(input_any_key())
{
if(input_trigger(K_DOWN))choix ++;
if(input_trigger(K_UP))choix --;
if(choix < 0)choix = 0;
if(choix > 1)choix = 1;
if(input_trigger(K_EXE))end = true;
}
switch(choix)
{
case 0: ML_bmp_or(Pointeur , 8 , 22 , 19 , 14); break;
case 1: ML_bmp_or(Pointeur , 8 , 32 , 19 , 14); break;
}
ML_display_vram();
Sleep(10);
}
if(choix == 0)
{
this->restart = 4;
vie = 6;
timer = 500;
score = score / 2 ;
}
if(choix == 1)
{
GetEngine()->StopGame();
}
}
void Script_GUI::EndStage()
{
int nscore = 0;
const unsigned char stageEnd[]={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xfc, 0x3f, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0xcf, 0xf3, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x73, 0xce, 0xe0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x40, 0x2, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x40, 0x2, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,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; i++)
{
for(int j = 0; j <= mod(restart , pow( 10, 2 - i )) / pow( 10, 1 - i ); j++ )
{
ML_rectangle(11 + i * 5 ,9, 14 + i * 5 ,15,1,ML_WHITE,ML_WHITE);
ML_bmp_or(nombers + j * 6 , 11 + i * 5 , 9 , 4 , 6 );
ML_display_vram();
Sleep(70);
}
}
for(int i = 0 ; i < 3; i++)
{
for(int j = 0; j <= mod(timer , pow( 10, 3 - i )) / pow( 10, 2 - i ); j++ )
{
ML_rectangle(11 + i * 5 ,17, 14 + i * 5 ,22,1,ML_WHITE,ML_WHITE);
ML_bmp_or(nombers + j * 6 , 11 + i * 5 , 17 , 4 , 6 );
ML_display_vram();
Sleep(50);
}
}
for(int i = 0 ; i < 7; i++)
{
for(int j = 0; j <= mod(score , pow( 10, 7 - i )) / pow( 10, 6 - i ); j++ )
{
ML_rectangle(11 + i * 5 ,26, 14 + i * 5 ,31,1,ML_WHITE,ML_WHITE);
ML_bmp_or(nombers + j * 6 , 11 + i * 5 , 26 , 4 , 6 );
ML_display_vram();
Sleep(30);
}
}
nscore = 1000 * restart + 20 * timer + score;
for(int i = 0 ; i < 7; i++)
{
for(int j = 0; j <= mod(nscore , pow( 10, 7 - i )) / pow( 10, 6 - i ); j++ )
{
ML_rectangle(77 + i * 5 ,26, 80 + i * 5 ,32,1,ML_WHITE,ML_WHITE);
ML_bmp_or(nombers + j * 6 , 77 + i * 5 , 26 , 4 , 6 );
ML_display_vram();
Sleep(30);
}
}
PrintV(24,50,nscore);
ML_display_vram();
bool end = false;
while(end == false)
{
input_update();
if(input_trigger(K_EXE))end = true;
Sleep(200);
}
GetEngine()->StopGame();
ML_clear_vram();
}