#include #include #include #include #include #include #include #include #include #include #include #include static void levelchanger(int w) { int play_level(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); 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) { play_level(0); // Todo : add score lifes etc... } else { mario_smaller(); mario_immunity=0; play_level(choice); } } 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 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(l); if (w_current==0) return 0; reset_camera(); 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) { timer_stop(0); return 0; } if (finish_level) { timer_stop(0); return 1; } } else sleep_ms(3,1); } }