295 lines
4.8 KiB
C
295 lines
4.8 KiB
C
#include <levelchanger.h>
|
|
|
|
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/timer.h>
|
|
#include <gint/clock.h>
|
|
#include <gint/std/stdio.h>
|
|
|
|
#include <keyboard.h>
|
|
#include <mario.h>
|
|
#include <world.h>
|
|
#include <score.h>
|
|
#include <level.h>
|
|
#include <save.h>
|
|
#include <config.h>
|
|
|
|
|
|
static void levelchanger(int w)
|
|
{
|
|
int play_level(int w, int l);
|
|
|
|
extern image_t img_levelchanger;
|
|
|
|
int choice=0;
|
|
|
|
// x y, first button coordinates and size
|
|
const int xt = 19, yt = 7, wt = 6, ht = 6;
|
|
|
|
while (1)
|
|
{
|
|
keyboard_clear();
|
|
dimage(0,0,&img_levelchanger);
|
|
|
|
drect(xt+(2+wt)*choice, yt, xt+(wt+2)*choice+wt,yt+ht, C_INVERT);
|
|
|
|
char str[8];
|
|
if (choice != 8)
|
|
{
|
|
sprintf(str, "%d", choice+1);
|
|
dtext(45,19, str, C_BLACK, C_WHITE);
|
|
}
|
|
else
|
|
{
|
|
dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
|
|
}
|
|
|
|
if (get_best_time(w,choice))
|
|
{
|
|
sprintf(str, "%d", get_best_time(w,choice));
|
|
int i=0;
|
|
while (str[i])
|
|
i++;
|
|
dtext(99-6*i, 53, str, C_BLACK, C_WHITE);
|
|
}
|
|
|
|
sprintf(str, "%d", get_highscore(w,choice));
|
|
int i=0;
|
|
while (str[i])
|
|
i++;
|
|
dtext(99-6*i, 45, str, C_BLACK, C_WHITE);
|
|
|
|
dupdate();
|
|
|
|
|
|
|
|
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
|
|
int key=getkey_custom();
|
|
|
|
if (key==KEY_LEFT && choice>0)
|
|
choice--;
|
|
|
|
if (key==KEY_RIGHT && choice<8)
|
|
choice++;
|
|
|
|
if (key==KEY_EXE || key==KEY_SHIFT)
|
|
{
|
|
if (choice==8)
|
|
{
|
|
new_game();
|
|
mario_smaller();
|
|
mario_immunity=0;
|
|
for (int i=0; i<7; i+=0)
|
|
{
|
|
int a=play_level(w, i);
|
|
if (a==0)
|
|
lifes--;
|
|
if (a==1)
|
|
i++;
|
|
if (a==-1)
|
|
break;
|
|
if (lifes==0)
|
|
{
|
|
extern image_t img_game_over;
|
|
dimage(0,0,&img_game_over);
|
|
dupdate();
|
|
sleep_ms(3,2000);
|
|
// TODO: Highscore management
|
|
break;
|
|
}
|
|
}
|
|
set_highscore(w, choice, get_score());
|
|
}
|
|
else
|
|
{
|
|
new_game();
|
|
mario_smaller();
|
|
mario_immunity=0;
|
|
int s=play_level(w, choice);
|
|
if (s==1)
|
|
{
|
|
set_best_time(w, choice, get_time_spent());
|
|
}
|
|
set_highscore(w, choice, get_score());
|
|
}
|
|
|
|
}
|
|
|
|
if (key==KEY_EXIT || key==KEY_MENU)
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void launch_ui()
|
|
{
|
|
keyboard_clear();
|
|
extern image_t img_mainmenu;
|
|
|
|
const int xt=17,yt=9;
|
|
int choice_x=0, choice_y=0;
|
|
while (1)
|
|
{
|
|
keyboard_clear();
|
|
dimage(0,0,&img_mainmenu);
|
|
|
|
//Show unlocked worlds
|
|
|
|
extern image_t img_w1, img_w2, img_w3, img_w4, img_w5;
|
|
switch (get_progress_status())
|
|
{
|
|
case 4:
|
|
dimage(xt, yt+24, &img_w5);
|
|
|
|
case 3:
|
|
dimage(xt+72, yt, &img_w4);
|
|
|
|
case 2:
|
|
dimage(xt+48, yt, &img_w3);
|
|
|
|
case 1:
|
|
dimage(xt+24, yt, &img_w2);
|
|
|
|
case 0:
|
|
dimage(xt, yt, &img_w1);
|
|
}
|
|
|
|
drect(xt+24*choice_x,yt+24*choice_y, xt+24*choice_x+20,yt+24*choice_y+20, C_INVERT);
|
|
|
|
dupdate();
|
|
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
|
|
int key=getkey_custom();
|
|
if (key==KEY_UP && choice_y>0)
|
|
choice_y--;
|
|
if (key==KEY_LEFT && choice_x>0)
|
|
choice_x--;
|
|
if (key==KEY_DOWN && choice_y<1)
|
|
choice_y++;
|
|
if (key==KEY_RIGHT && choice_x<3)
|
|
choice_x++;
|
|
|
|
if (key==KEY_EXE || key==KEY_SHIFT)
|
|
{
|
|
// Determine mode
|
|
if (choice_x==3 && choice_y==1)
|
|
break;
|
|
if (choice_x==2 && choice_y==1)
|
|
{
|
|
configmenu();
|
|
}
|
|
if (choice_y*choice_x==0)
|
|
{
|
|
int world_chosen=0;
|
|
if (choice_y==1)
|
|
world_chosen=4;
|
|
else
|
|
world_chosen=choice_x;
|
|
if (world_chosen<=get_progress_status())
|
|
levelchanger(world_chosen);
|
|
|
|
}
|
|
}
|
|
|
|
if (key==KEY_EXIT || key==KEY_MENU)
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
int frame_id;
|
|
int callback(volatile void *arg)
|
|
{
|
|
volatile int *has_ticked = arg;
|
|
*has_ticked = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int play_level(int w, int l)
|
|
{
|
|
volatile int has_ticked = 1;
|
|
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
|
|
timer_start(0);
|
|
|
|
//int finish_status=0; // FAil
|
|
finish_level=0; mario_dead=0;
|
|
set_level(w, l);
|
|
if (w_current==0)
|
|
return 0;
|
|
reset_camera();
|
|
|
|
extern image_t img_new_level;
|
|
dimage(0,0,&img_new_level);
|
|
char lvl[4];
|
|
get_lvl_id(w, l, lvl);
|
|
|
|
dtext(53,28, lvl, C_WHITE, C_BLACK);
|
|
sprintf(lvl, "%d", lifes);
|
|
dtext(65,54, lvl, C_WHITE, C_BLACK);
|
|
dupdate();
|
|
sleep_ms(3,2000);
|
|
|
|
|
|
while(global_quit==0)
|
|
{
|
|
if (has_ticked)
|
|
{
|
|
has_ticked=0;
|
|
frame_id++;
|
|
//mario_move();
|
|
|
|
world_move();
|
|
dclear(C_WHITE);
|
|
world_draw(mario.p.x,mario.p.y);
|
|
score_display();
|
|
|
|
dupdate();
|
|
if (mario_dead)
|
|
{
|
|
mario_immunity=0;
|
|
int i=6;
|
|
while(mario.p.y>=0)
|
|
{
|
|
if (has_ticked)
|
|
{
|
|
has_ticked=0;
|
|
mario.p.y+=i;
|
|
dclear(C_WHITE);
|
|
world_draw(mario.p.x,mario.p.y);
|
|
mario_draw();
|
|
score_display();
|
|
|
|
dupdate();
|
|
i--;
|
|
}
|
|
else
|
|
sleep_ms(3,1);
|
|
}
|
|
sleep_ms(3,1000);
|
|
|
|
timer_stop(0);
|
|
|
|
return 0;
|
|
}
|
|
if (finish_level)
|
|
{
|
|
timer_stop(0);
|
|
// TODO ajouter temps au score etc
|
|
sleep_ms(3,3000);
|
|
return finish_level;
|
|
}
|
|
|
|
}
|
|
else
|
|
sleep_ms(3,1);
|
|
}
|
|
return 0;
|
|
|
|
} |