supercasiobros/src/score.c

127 lines
1.5 KiB
C

#include "score.h"
#include "mario.h"
#include <gint/display.h>
#include <gint/std/stdio.h>
#include <gint/clock.h>
#include <gint/timer.h>
static int score=0;
int lifes=3;
int combo=0;
int combo_id=-10;
int pieces=0;
int time_id=0;
int time_left=0;
int time_spent=0;
int finish_level=0;
void new_game()
{
lifes=3;
pieces=0;
score=0;
combo=0;
combo_id=-10;
mario_smaller();
new_level();
time_spent=0;
}
void new_level()
{
finish_level=0;
time_left=400;
time_id=0;
}
int get_score()
{
return score;
}
int get_coins()
{
return pieces;
}
void score_reset()
{
score=0;
combo=0;
combo_id=-10;
}
void score_add_coin()
{
pieces++;
}
void score_add(int i)
{
if (i==0)
return;
if (time_id-combo_id<=12 && time_id-combo_id>=0 && combo)
{
score+=i;
combo_id=time_id;
combo+=i;
}
else
{
combo_id=time_id;
combo=i;
score+=i;
}
}
void score_display()
{
char str[10];
sprintf(str, "%d", score);
dtext(0,0,str, C_BLACK, C_WHITE);
if (time_id-combo_id<=8 && time_id-combo_id>=0 && combo)
{
sprintf(str, "+ %d", combo);
dtext(0,6,str, C_BLACK, C_WHITE);
}
else
{
combo=0;
}
sprintf(str, "c*%d", pieces);
dtext(50,0,str, C_BLACK, C_WHITE);
time_id++;
if (time_id%8==0)
{
time_left--;
time_spent++;
}
sprintf(str, "TIME : %d", time_left);
dtext(87-7,0,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=0;
mario_dead=1;
}
}
int get_time_spent()
{
return time_spent;
}