#include "score.h" #include "mario.h" #include #include #include #include static int score=0; static int lifes=3; int combo=0; int combo_id=-10; static int pieces=0; static unsigned int time_last_piece=0; unsigned int time_id=0; int time_left=0; int time_spent=0; int finish_level=0; void gameNew() { lifes=3; pieces=0; score=0; combo=0; combo_id=-10; marioSmaller(); mario_immunity=0; levelNew(); time_spent=0; } void levelNew() { finish_level=0; time_left=400; time_id=0; } int scoreGet() { return score; } int coinsGet() { return pieces; } void scoreReset() { score=0; combo=0; combo_id=-10; } void coinAdd() { pieces++; time_last_piece=time_id; scoreAdd(200); } void scoreAdd(int i) { if (i==0) return; if (time_id-combo_id<=12 && combo) { score+=i; combo_id=time_id; combo+=i; } else { combo_id=time_id; combo=i; score+=i; } } void scoreDisplay() { char str[10]; if (time_id-combo_id<=8 && combo) // displays score & combo only when there is a combo { sprintf(str, "%d", score); dtext(0,0,str, C_BLACK, C_WHITE); sprintf(str, "+ %d", combo); dtext(0,6,str, C_BLACK, C_WHITE); } else { combo=0; } if (time_last_piece<=time_id && time_id<=time_last_piece+30) // display pieces only when 1 is taken during 2 seconds { sprintf(str, "c*%d", pieces); dtext(50,0,str, C_BLACK, C_WHITE); } if (mario_dead==0 && finish_level==0) { time_id++; if (0==time_id%8) { time_left--; time_spent++; } } sprintf(str, "%d", time_left); int i=0; while (str[i]) i++; dtext(127-6*i, 1, str, C_BLACK, C_WHITE); extern image_t img_time_over; if (time_left==0) { dimage(0,0, &img_time_over); dupdate(); sleep_ms(3,1000); sleep_ms(3,1000); sleep_ms(3,1000); finish_level=2; } } int getTimeSpent() { return time_spent; } int lifesGet() { return lifes; } void lifesSet(int l) { lifes = l; } void lifesAdd(int l) { lifes += l; }