2020-01-07 21:31:34 +01:00
|
|
|
#include <levelchanger.h>
|
|
|
|
|
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <gint/timer.h>
|
2020-01-08 15:43:58 +01:00
|
|
|
#include <gint/clock.h>
|
2020-01-15 20:42:51 +01:00
|
|
|
#include <gint/std/stdio.h>
|
2020-01-07 21:31:34 +01:00
|
|
|
|
|
|
|
#include <keyboard.h>
|
|
|
|
#include <mario.h>
|
|
|
|
#include <world.h>
|
2020-01-08 15:43:58 +01:00
|
|
|
#include <score.h>
|
|
|
|
#include <level.h>
|
|
|
|
#include <save.h>
|
2020-01-11 15:19:53 +01:00
|
|
|
#include <config.h>
|
2020-01-25 21:06:34 +01:00
|
|
|
#include <framerate.h>
|
2020-01-29 18:24:33 +01:00
|
|
|
#include <camera.h>
|
2020-01-30 21:09:18 +01:00
|
|
|
#include <bonus.h>
|
2020-01-13 20:26:04 +01:00
|
|
|
|
2020-02-15 19:35:49 +01:00
|
|
|
int PlayLevel(int, int); // déclaration de la fonction codée plus bas
|
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
static void LevelChanger(int world)
|
2020-01-13 20:26:04 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
MKB_clear(); // clear keyboard
|
2020-02-15 14:40:01 +01:00
|
|
|
unsigned int choice=0;
|
2020-01-13 20:26:04 +01:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2020-02-15 19:35:49 +01:00
|
|
|
extern image_t img_levelchanger;
|
|
|
|
dimage(0,0,&img_levelchanger); // Draw menu
|
|
|
|
drect(19+8*choice, 7, 25+8*choice, 13, C_INVERT); // Invert color of selected level
|
2020-01-13 20:26:04 +01:00
|
|
|
|
2020-01-15 20:42:51 +01:00
|
|
|
char str[8];
|
|
|
|
if (choice != 8)
|
2020-02-15 14:40:01 +01:00
|
|
|
{
|
2020-01-15 20:42:51 +01:00
|
|
|
sprintf(str, "%d", choice+1);
|
2020-02-15 19:35:49 +01:00
|
|
|
dtext(45,19, str, C_BLACK, C_WHITE); // Maybe later replace it by level names
|
2020-01-15 20:42:51 +01:00
|
|
|
}
|
2020-02-15 19:35:49 +01:00
|
|
|
else dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
|
2020-01-15 20:42:51 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (saveGetTime(world,choice))
|
2020-01-15 20:42:51 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
sprintf(str, "%d", saveGetTime(world,choice));
|
2020-01-15 20:42:51 +01:00
|
|
|
int i=0;
|
|
|
|
while (str[i])
|
2020-02-15 14:40:01 +01:00
|
|
|
i++;
|
2020-01-15 20:42:51 +01:00
|
|
|
dtext(99-6*i, 53, str, C_BLACK, C_WHITE);
|
|
|
|
}
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (saveGetScore(world,choice))
|
2020-02-15 14:40:01 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
sprintf(str, "%d", saveGetScore(world,choice));
|
2020-02-15 14:40:01 +01:00
|
|
|
int i=0;
|
|
|
|
while (str[i])
|
2020-01-19 20:17:14 +01:00
|
|
|
i++;
|
2020-02-15 14:40:01 +01:00
|
|
|
dtext(99-6*i, 45, str, C_BLACK, C_WHITE);
|
|
|
|
}
|
2020-01-19 20:17:14 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (saveGetCoins(world,choice))
|
2020-02-15 14:40:01 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
sprintf(str, "%d", saveGetCoins(world,choice));
|
2020-02-15 14:40:01 +01:00
|
|
|
int i=0;
|
|
|
|
while (str[i])
|
2020-01-25 11:54:39 +01:00
|
|
|
i++;
|
2020-02-15 14:40:01 +01:00
|
|
|
dtext(90-6*i, 37, str, C_BLACK, C_WHITE);
|
|
|
|
}
|
2020-01-25 11:54:39 +01:00
|
|
|
|
2020-01-13 20:26:04 +01:00
|
|
|
dupdate();
|
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
|
2020-02-16 20:43:35 +01:00
|
|
|
switch (MKB_getkey())
|
2020-01-13 20:26:04 +01:00
|
|
|
{
|
2020-02-15 14:40:01 +01:00
|
|
|
case KEY_LEFT:
|
|
|
|
if (choice) /* >0 */ choice--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if (choice!=8) /* <8 */ choice++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_EXE:
|
|
|
|
// fall through
|
|
|
|
case KEY_SHIFT:
|
2020-01-13 20:26:04 +01:00
|
|
|
if (choice==8)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
gameNew();
|
2020-02-15 19:35:49 +01:00
|
|
|
|
2020-01-14 21:31:13 +01:00
|
|
|
for (int i=0; i<7; i+=0)
|
|
|
|
{
|
2020-01-25 20:35:34 +01:00
|
|
|
extern image_t img_new_level;
|
|
|
|
dimage(0,0,&img_new_level);
|
|
|
|
char lvl[4];
|
2020-02-16 20:43:35 +01:00
|
|
|
getLevelID(world, i, lvl);
|
2020-01-25 20:35:34 +01:00
|
|
|
|
|
|
|
dtext(53,28, lvl, C_WHITE, C_BLACK);
|
2020-02-16 20:43:35 +01:00
|
|
|
sprintf(lvl, "%d", lifesGet());
|
2020-01-25 20:35:34 +01:00
|
|
|
dtext(65,54, lvl, C_WHITE, C_BLACK);
|
|
|
|
dupdate();
|
|
|
|
sleep_ms(3,2000);
|
|
|
|
|
2020-02-15 19:35:49 +01:00
|
|
|
int a=PlayLevel(world, i);
|
2020-02-16 20:43:35 +01:00
|
|
|
if (a==0) lifesAdd(-1);
|
2020-02-15 14:40:01 +01:00
|
|
|
if (a==1) i++;
|
|
|
|
if (a==-1) break;
|
2020-02-16 20:43:35 +01:00
|
|
|
if (lifesGet()==0)
|
2020-01-14 21:31:13 +01:00
|
|
|
{
|
|
|
|
extern image_t img_game_over;
|
|
|
|
dimage(0,0,&img_game_over);
|
|
|
|
dupdate();
|
|
|
|
sleep_ms(3,2000);
|
|
|
|
// TODO: Highscore management
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 20:43:35 +01:00
|
|
|
saveSetScore(world, choice, scoreGet());
|
2020-01-13 20:26:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-25 20:35:34 +01:00
|
|
|
extern image_t img_new_level;
|
|
|
|
dimage(0,0,&img_new_level);
|
|
|
|
char lvl[4];
|
2020-02-16 20:43:35 +01:00
|
|
|
getLevelID(world, choice, lvl);
|
2020-01-25 20:35:34 +01:00
|
|
|
|
|
|
|
dtext(53,28, lvl, C_WHITE, C_BLACK);
|
2020-02-16 20:43:35 +01:00
|
|
|
sprintf(lvl, "%d", lifesGet());
|
2020-01-25 20:35:34 +01:00
|
|
|
dtext(65,54, lvl, C_WHITE, C_BLACK);
|
|
|
|
dupdate();
|
|
|
|
sleep_ms(3,2000);
|
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
playagain:
|
2020-02-16 20:43:35 +01:00
|
|
|
gameNew();
|
2020-02-15 19:35:49 +01:00
|
|
|
switch (PlayLevel(world, choice))
|
2020-01-19 19:59:13 +01:00
|
|
|
{
|
2020-02-15 14:40:01 +01:00
|
|
|
case 1: // if level completed
|
2020-02-16 20:43:35 +01:00
|
|
|
saveSetTime(world, choice, getTimeSpent());
|
|
|
|
saveSetScore(world, choice, scoreGet());
|
|
|
|
saveSetCoins(world, choice, coinsGet());
|
2020-02-15 14:40:01 +01:00
|
|
|
break; // go back to menu
|
|
|
|
|
|
|
|
case 0: // save score anyways
|
2020-02-16 20:43:35 +01:00
|
|
|
saveSetScore(world, choice, scoreGet());
|
|
|
|
saveSetCoins(world, choice, coinsGet());
|
2020-02-15 14:40:01 +01:00
|
|
|
goto playagain;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
2020-02-16 20:43:35 +01:00
|
|
|
saveSetScore(world, choice, scoreGet());
|
|
|
|
saveSetCoins(world, choice, coinsGet());
|
2020-02-15 14:40:01 +01:00
|
|
|
break; // do not play again
|
2020-01-19 19:59:13 +01:00
|
|
|
}
|
2020-01-13 20:26:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
case KEY_EXIT:
|
|
|
|
// fall through
|
|
|
|
case KEY_MENU:
|
|
|
|
return;
|
|
|
|
}
|
2020-01-13 20:26:04 +01:00
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
}
|
2020-01-13 20:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-07 21:31:34 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void launchUI() // Main Menu
|
2020-01-07 21:31:34 +01:00
|
|
|
{
|
|
|
|
extern image_t img_mainmenu;
|
2020-01-13 20:26:04 +01:00
|
|
|
|
2020-01-08 15:43:58 +01:00
|
|
|
const int xt=17,yt=9;
|
2020-02-15 13:41:50 +01:00
|
|
|
unsigned int choice_x=0, choice_y=0;
|
2020-01-07 21:31:34 +01:00
|
|
|
while (1)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
MKB_clear();
|
2020-01-07 21:31:34 +01:00
|
|
|
dimage(0,0,&img_mainmenu);
|
2020-02-15 14:40:01 +01:00
|
|
|
|
2020-02-15 13:41:50 +01:00
|
|
|
// Draw world images, but only unlocked ones
|
2020-01-08 15:43:58 +01:00
|
|
|
//Show unlocked worlds
|
2020-02-15 14:40:01 +01:00
|
|
|
|
2020-01-08 15:43:58 +01:00
|
|
|
extern image_t img_w1, img_w2, img_w3, img_w4, img_w5;
|
2020-02-16 20:43:35 +01:00
|
|
|
switch (saveGetProgressStatus())
|
2020-01-08 15:43:58 +01:00
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
dimage(xt, yt+24, &img_w5);
|
2020-01-29 14:34:47 +01:00
|
|
|
// fall through
|
2020-01-08 15:43:58 +01:00
|
|
|
case 3:
|
|
|
|
dimage(xt+72, yt, &img_w4);
|
2020-01-29 14:34:47 +01:00
|
|
|
// fall through
|
2020-01-08 15:43:58 +01:00
|
|
|
case 2:
|
|
|
|
dimage(xt+48, yt, &img_w3);
|
2020-01-29 14:34:47 +01:00
|
|
|
// fall through
|
2020-01-08 15:43:58 +01:00
|
|
|
case 1:
|
|
|
|
dimage(xt+24, yt, &img_w2);
|
2020-01-29 14:34:47 +01:00
|
|
|
// fall through
|
2020-01-08 15:43:58 +01:00
|
|
|
case 0:
|
|
|
|
dimage(xt, yt, &img_w1);
|
|
|
|
}
|
|
|
|
|
2020-02-15 13:41:50 +01:00
|
|
|
// invert color of selected world
|
2020-01-08 15:43:58 +01:00
|
|
|
drect(xt+24*choice_x,yt+24*choice_y, xt+24*choice_x+20,yt+24*choice_y+20, C_INVERT);
|
|
|
|
|
2020-01-07 21:31:34 +01:00
|
|
|
dupdate();
|
2020-01-08 16:16:05 +01:00
|
|
|
|
2020-02-15 13:41:50 +01:00
|
|
|
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
|
2020-02-16 20:43:35 +01:00
|
|
|
switch (MKB_getkey())
|
2020-01-08 16:16:05 +01:00
|
|
|
{
|
2020-02-15 13:41:50 +01:00
|
|
|
case KEY_UP:
|
|
|
|
if (choice_y) // >0
|
2020-02-15 14:40:01 +01:00
|
|
|
choice_y--;
|
2020-02-15 13:41:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_LEFT:
|
|
|
|
if (choice_x) // >0
|
2020-02-15 14:40:01 +01:00
|
|
|
choice_x--;
|
2020-02-15 13:41:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (KEY_DOWN):
|
|
|
|
if (!choice_y) // ==0
|
2020-02-15 14:40:01 +01:00
|
|
|
choice_y++;
|
2020-02-15 13:41:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case (KEY_RIGHT):
|
|
|
|
if (choice_x!=3) // <3
|
2020-02-15 14:40:01 +01:00
|
|
|
choice_x++;
|
2020-02-15 13:41:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_EXE:
|
|
|
|
// fall through
|
|
|
|
case KEY_SHIFT:
|
|
|
|
switch (4*choice_y+choice_x)
|
2020-01-11 15:19:53 +01:00
|
|
|
{
|
2020-02-15 13:41:50 +01:00
|
|
|
case 5: // No idea yet !
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2020-01-11 15:19:53 +01:00
|
|
|
configmenu();
|
2020-02-15 13:41:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
return;
|
2020-01-13 20:26:04 +01:00
|
|
|
|
2020-02-15 13:41:50 +01:00
|
|
|
default:
|
2020-02-16 20:43:35 +01:00
|
|
|
if (4*choice_y+choice_x<=saveGetProgressStatus())
|
2020-02-15 14:40:01 +01:00
|
|
|
LevelChanger(4*choice_y+choice_x);
|
2020-01-11 15:19:53 +01:00
|
|
|
}
|
2020-01-07 21:31:34 +01:00
|
|
|
break;
|
2020-02-15 13:41:50 +01:00
|
|
|
|
|
|
|
case KEY_EXIT:
|
|
|
|
// fall through
|
|
|
|
case KEY_MENU:
|
|
|
|
return;
|
|
|
|
}
|
2020-01-07 21:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:35:49 +01:00
|
|
|
int PlayLevel(int w, int l)
|
2020-01-07 21:31:34 +01:00
|
|
|
{
|
2020-02-17 17:53:37 +01:00
|
|
|
time_id=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
initRefreshTimer();
|
2020-01-08 15:43:58 +01:00
|
|
|
|
|
|
|
//int finish_status=0; // FAil
|
2020-01-11 15:19:53 +01:00
|
|
|
finish_level=0; mario_dead=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
setLevel(w, l);
|
2020-01-30 21:09:18 +01:00
|
|
|
if (map_current==0)
|
2020-01-25 20:35:34 +01:00
|
|
|
{
|
|
|
|
timer_stop(0);
|
|
|
|
return -1;
|
|
|
|
}
|
2020-02-16 20:43:35 +01:00
|
|
|
cameraAdjust();
|
|
|
|
bonusSet(0, 0, 0);
|
2020-01-14 21:31:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-07 21:31:34 +01:00
|
|
|
while(global_quit==0)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
waitNextFrame();
|
2020-02-15 14:40:01 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
//marioMove();
|
2020-01-07 21:31:34 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
worldMove();
|
2020-01-25 21:06:34 +01:00
|
|
|
dclear(C_WHITE);
|
2020-02-16 20:43:35 +01:00
|
|
|
worldDraw(mario.p.x,mario.p.y);
|
|
|
|
scoreDisplay();
|
2020-01-07 21:31:34 +01:00
|
|
|
|
2020-01-25 21:06:34 +01:00
|
|
|
dupdate();
|
|
|
|
if (mario_dead)
|
|
|
|
{
|
|
|
|
mario_immunity=0;
|
|
|
|
int i=6;
|
|
|
|
while(mario.p.y>=0)
|
2020-01-07 21:31:34 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
waitNextFrame();
|
2020-01-25 21:06:34 +01:00
|
|
|
mario.p.y+=i;
|
|
|
|
dclear(C_WHITE);
|
2020-02-16 20:43:35 +01:00
|
|
|
worldDraw(mario.p.x,mario.p.y);
|
|
|
|
marioDraw();
|
|
|
|
scoreDisplay();
|
2020-01-14 21:31:13 +01:00
|
|
|
|
2020-01-25 21:06:34 +01:00
|
|
|
dupdate();
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
sleep_ms(3,1000);
|
2020-01-14 21:31:13 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
quitRefreshTimer();
|
2020-01-14 21:31:13 +01:00
|
|
|
|
2020-01-25 21:06:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (finish_level)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
quitRefreshTimer();
|
2020-02-15 14:40:01 +01:00
|
|
|
// TODO ajouter temps au score etc
|
2020-02-17 17:53:37 +01:00
|
|
|
if (finish_level==1) sleep_ms(3,3000); // win
|
2020-01-25 21:06:34 +01:00
|
|
|
return finish_level;
|
2020-01-07 21:31:34 +01:00
|
|
|
}
|
2020-01-25 21:06:34 +01:00
|
|
|
|
2020-01-07 21:31:34 +01:00
|
|
|
}
|
2020-01-15 20:42:51 +01:00
|
|
|
return 0;
|
2020-01-14 21:31:13 +01:00
|
|
|
|
2020-02-15 14:40:01 +01:00
|
|
|
}
|