move, score, timer and coins improvement
2
Makefile
|
@ -29,7 +29,7 @@ G1AF := -i "$(ICON_FX)" -n "$(NAME_G1A)" --internal="$(INTERNAL)"
|
|||
G3AF := -n basic:"$(NAME_G3A)" -i uns:"$(ICON_CG_UNS)" -i sel:"$(ICON_CG_SEL)"
|
||||
|
||||
ifeq "$(TOOLCHAIN_FX)" ""
|
||||
TOOLCHAIN_FX := sh-elf
|
||||
TOOLCHAIN_FX := sh3eb-elf
|
||||
endif
|
||||
|
||||
ifeq "$(TOOLCHAIN_CG)" ""
|
||||
|
|
BIN
SuperCbr.g1a
Before Width: | Height: | Size: 132 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 585 B |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 712 B After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 716 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 786 B |
920
build-fx/map
|
@ -1,5 +1,5 @@
|
|||
build-fx/src/level.c.o: src/level.c src/level.h src/world.h src/mario.h \
|
||||
src/box.h
|
||||
src/box.h src/score.h
|
||||
|
||||
src/level.h:
|
||||
|
||||
|
@ -8,3 +8,5 @@ src/world.h:
|
|||
src/mario.h:
|
||||
|
||||
src/box.h:
|
||||
|
||||
src/score.h:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
build-fx/src/main.c.o: src/main.c src/world.h src/mario.h src/box.h \
|
||||
src/level.h
|
||||
src/level.h src/score.h
|
||||
|
||||
src/world.h:
|
||||
|
||||
|
@ -8,3 +8,5 @@ src/mario.h:
|
|||
src/box.h:
|
||||
|
||||
src/level.h:
|
||||
|
||||
src/score.h:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
build-fx/src/mario.c.o: src/mario.c src/mario.h src/box.h src/tile.h \
|
||||
src/world.h src/keyboard.h
|
||||
src/world.h src/keyboard.h src/score.h
|
||||
|
||||
src/mario.h:
|
||||
|
||||
|
@ -10,3 +10,5 @@ src/tile.h:
|
|||
src/world.h:
|
||||
|
||||
src/keyboard.h:
|
||||
|
||||
src/score.h:
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
build-fx/src/score.c.o: src/score.c src/score.h src/mario.h src/box.h
|
||||
|
||||
src/score.h:
|
||||
|
||||
src/mario.h:
|
||||
|
||||
src/box.h:
|
|
@ -82,3 +82,4 @@ LDFLAGS_CG += -Wl,-Map=build-cg/map
|
|||
# font name "hexa.png", you might write:
|
||||
#
|
||||
# FONT.hexa.png = charset:print grid:size:3x5 grid.padding:1
|
||||
FONT.mario.png = charset:print grid.size:5x5 grid.padding:1 proportional:true
|
|
@ -13,6 +13,7 @@ typedef struct
|
|||
int vy;
|
||||
|
||||
int gravity;
|
||||
//int is_mario;
|
||||
} box_t;
|
||||
|
||||
int box_move(box_t * b);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <gint/keyboard.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/timer.h>
|
||||
#include <gint/clock.h>
|
||||
|
||||
mkey_t keys[6]={0};
|
||||
|
||||
|
@ -41,6 +42,7 @@ int menu_pause() // 1 exit, 0 continue
|
|||
dimage(x,y,&img_menu_pause);
|
||||
dimage(x+2, y+2+7*choice, &img_select_arrow);
|
||||
dupdate();
|
||||
sleep_ms(3,1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +51,8 @@ void update_keyboard()
|
|||
key_event_t e;
|
||||
e=pollevent();
|
||||
int menu=0;
|
||||
for (int i=0; i<6; i++)
|
||||
if (keys[i]==2) keys[i]=1;
|
||||
while(e.type!=KEYEV_NONE)
|
||||
{
|
||||
mkey_t k = MK_NONE;
|
||||
|
@ -78,7 +82,7 @@ void update_keyboard()
|
|||
{
|
||||
if (e.type==KEYEV_DOWN)
|
||||
{
|
||||
keys[k]=1;
|
||||
keys[k]=2;
|
||||
}
|
||||
if (e.type==KEYEV_UP)
|
||||
{
|
||||
|
|
111
src/level.c
|
@ -1,41 +1,100 @@
|
|||
#include "level.h"
|
||||
#include "world.h"
|
||||
#include "mario.h"
|
||||
#include "score.h"
|
||||
#include <gint/display.h>
|
||||
#include <gint/std/stdlib.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/timer.h>
|
||||
#include <gint/std/string.h>
|
||||
|
||||
world_t level_0[]=
|
||||
void malloc_error()
|
||||
{
|
||||
{EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {GIFT,0,0,0}, {COIN,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}
|
||||
};
|
||||
extern image_t img_lvl0;
|
||||
#define LVL_0_X 12
|
||||
#define LVL_0_Y 8
|
||||
#define LVL_0_MARIOX 11
|
||||
#define LVL_0_MARIOY 16
|
||||
extern image_t img_ram;
|
||||
timer_stop(0);
|
||||
dimage(0,0,&img_ram);
|
||||
dupdate();
|
||||
while (1)
|
||||
getkey();
|
||||
}
|
||||
|
||||
|
||||
void init_level(world_t * lvl)
|
||||
{
|
||||
mario.p.vx=0;
|
||||
mario.p.vy=0;
|
||||
if (w_current)
|
||||
{
|
||||
free(w_current);
|
||||
}
|
||||
int size=sizeof(int)*w_current_y*w_current_x;
|
||||
w_current=malloc(size);
|
||||
if (w_current==0)
|
||||
malloc_error();
|
||||
|
||||
memcpy(w_current, lvl, size);
|
||||
}
|
||||
|
||||
void set_level(int n)
|
||||
{
|
||||
new_level();
|
||||
world_t * lvl=0;
|
||||
if (n==0)
|
||||
{
|
||||
w_current=&level_0;
|
||||
world_t level_0[]=
|
||||
{
|
||||
{EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {GIFT,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,0,0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {COIN,0,0,0},
|
||||
{EARTH,1,1,0}, {EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
||||
{EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0}, {EARTH,0,1,0},
|
||||
};
|
||||
lvl=&level_0;
|
||||
extern image_t img_lvl0;
|
||||
w_fond=&img_lvl0;
|
||||
w_current_x=LVL_0_X;
|
||||
w_current_y=LVL_0_Y;
|
||||
w_current_x=25;
|
||||
w_current_y=8;
|
||||
mario_x_max=0;
|
||||
mario.p.x=LVL_0_MARIOX;
|
||||
mario.p.y=LVL_0_MARIOY;
|
||||
mario.p.x=25;
|
||||
mario.p.y=16;
|
||||
init_level(lvl);
|
||||
}
|
||||
}
|
||||
|
||||
void get_lvl_id(int n, char * str)
|
||||
{
|
||||
str[3]='\0';
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
str[0]='1';
|
||||
str[1]='-';
|
||||
str[2]='1';
|
||||
return;
|
||||
case 1:
|
||||
str[0]='1';
|
||||
str[1]='-';
|
||||
str[2]='2';
|
||||
return;
|
||||
}
|
||||
mario.p.vx=0;
|
||||
mario.p.vy=0;
|
||||
}
|
|
@ -2,5 +2,6 @@
|
|||
#define LEVEL_H
|
||||
|
||||
void set_level(int n);
|
||||
void get_lvl_id(int n, char * str);
|
||||
|
||||
#endif
|
31
src/main.c
|
@ -5,6 +5,7 @@
|
|||
#include "world.h"
|
||||
#include "mario.h"
|
||||
#include "level.h"
|
||||
#include "score.h"
|
||||
|
||||
#include <gint/exc.h>
|
||||
#include <gint/keyboard.h>
|
||||
|
@ -29,6 +30,8 @@ int callback(volatile void *arg)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
extern font_t font_mario;
|
||||
dfont(&font_mario);
|
||||
gint_panic_set(system_error);
|
||||
volatile int has_ticked = 1;
|
||||
|
||||
|
@ -45,15 +48,37 @@ int main(void)
|
|||
dclear(C_WHITE);
|
||||
|
||||
world_draw(mario.p.x,mario.p.y);
|
||||
|
||||
score_display();
|
||||
//ennemies_draw();
|
||||
|
||||
//ingame_draw();
|
||||
dupdate();
|
||||
if (mario_dead)
|
||||
if (mario_dead==1)
|
||||
{
|
||||
set_level(current_level);
|
||||
mario_dead=0;
|
||||
end_level=0;
|
||||
}
|
||||
if (end_level==0)
|
||||
{
|
||||
lifes--;
|
||||
set_level(current_level);
|
||||
extern image_t img_new_level;
|
||||
dimage(0,0,&img_new_level);
|
||||
char lvl[4];
|
||||
get_lvl_id(current_level, lvl);
|
||||
dtext(57,28, lvl, C_WHITE, C_BLACK);
|
||||
sprintf(lvl, "%d", lifes);
|
||||
dtext(65,54, lvl, C_WHITE, C_BLACK);
|
||||
dupdate();
|
||||
sleep_ms(3,1000);
|
||||
sleep_ms(3,1000);
|
||||
sleep_ms(3,1000);
|
||||
dclear(C_BLACK);
|
||||
}
|
||||
if (end_level>=1)
|
||||
{
|
||||
current_level+=end_level;
|
||||
set_level(current_level);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
204
src/mario.c
|
@ -5,98 +5,162 @@
|
|||
#include <gint/keyboard.h>
|
||||
#include "keyboard.h"
|
||||
#include "box.h"
|
||||
#include "score.h"
|
||||
|
||||
static int sgn(int x)
|
||||
{
|
||||
if (x>0)
|
||||
return 1;
|
||||
else if (x<0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern image_t img_mariosmall;
|
||||
int numero_frame=0;
|
||||
int id_frame=0;
|
||||
tileset_t mario_small={&img_mariosmall, 8,8, 1};
|
||||
|
||||
pnj mario=
|
||||
{
|
||||
{26,17,8,8,0,0,1},
|
||||
M_SMALL,
|
||||
M_RIGHT1, M_WALK,
|
||||
0
|
||||
{26,17,8,8,0,0,1},
|
||||
M_SMALL,
|
||||
M_RIGHT1, M_WALK,
|
||||
0
|
||||
};
|
||||
int mario_x_max=0;
|
||||
int mario_time_accel=0;
|
||||
int mario_dead=0;
|
||||
int mario_coins=0;
|
||||
int last_vx_sign=1;
|
||||
int last_bonus=0;
|
||||
|
||||
void mario_draw()
|
||||
{
|
||||
if (mario.size==M_SMALL)
|
||||
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, mario.type1, mario.type2);
|
||||
if (mario.size==M_SMALL)
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=3)
|
||||
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
|
||||
else if (mario.p.vx*sgn(mario.p.vx)>=1)
|
||||
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
|
||||
else
|
||||
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int test_sol_le_plus_proche(int x, int y)
|
||||
{
|
||||
int distance=0;
|
||||
int t=0;
|
||||
while (t==0)
|
||||
{
|
||||
int type_sol = world_get_ctg(x, y-1);
|
||||
if (type_sol==CTG_SOIL)
|
||||
t=1;
|
||||
if (type_sol==CTG_DEATH)
|
||||
return distance+1;
|
||||
type_sol = world_get_ctg(x+7, y-1);
|
||||
if (type_sol==CTG_SOIL)
|
||||
t=1;
|
||||
if (type_sol==CTG_DEATH)
|
||||
return distance+1;
|
||||
y--;
|
||||
distance++;
|
||||
}
|
||||
return distance;
|
||||
int distance=0;
|
||||
int t=0;
|
||||
while (t==0)
|
||||
{
|
||||
int type_sol = world_get_ctg(x, y-1);
|
||||
if (type_sol==CTG_SOIL)
|
||||
t=1;
|
||||
if (type_sol==CTG_DEATH)
|
||||
return distance+1;
|
||||
type_sol = world_get_ctg(x+7, y-1);
|
||||
if (type_sol==CTG_SOIL)
|
||||
t=1;
|
||||
if (type_sol==CTG_DEATH)
|
||||
return distance+1;
|
||||
y--;
|
||||
distance++;
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
static int sgn(int x)
|
||||
{
|
||||
if (x>0)
|
||||
return 1;
|
||||
else if (x<0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int global_quit=0;
|
||||
void mario_move()
|
||||
{
|
||||
update_keyboard();
|
||||
int jump = keys[MK_JUMP1] || keys[MK_JUMP2];
|
||||
if (jump)
|
||||
box_jump(&mario.p, 7);
|
||||
int vx=keys[MK_RIGHT] - keys[MK_LEFT];
|
||||
if (vx)
|
||||
{
|
||||
if (sgn(vx)==sgn(mario.p.vx) || vx==0)
|
||||
mario_time_accel++;
|
||||
mario_time_accel%=4;
|
||||
if (mario_time_accel==0)
|
||||
{
|
||||
if (keys[MK_RUN])
|
||||
{
|
||||
if(mario.p.vx*sgn(mario.p.vx)<=4)
|
||||
mario.p.vx+=vx;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mario.p.vx*sgn(mario.p.vx)<=2)
|
||||
mario.p.vx+=vx;
|
||||
}
|
||||
}
|
||||
if (mario.p.x+mario.p.vx<world_get_real_x0(mario.p.x))
|
||||
mario.p.vx=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mario.p.vx-=sgn(mario.p.vx);
|
||||
mario_time_accel=0;
|
||||
}
|
||||
box_move(&mario.p); // <-> + gravity
|
||||
if (mario.p.x>mario_x_max)
|
||||
mario_x_max=mario.p.x;
|
||||
if (mario.p.y<0)
|
||||
mario_dead=1;
|
||||
id_frame++;
|
||||
update_keyboard();
|
||||
int jump = keys[MK_JUMP1] || keys[MK_JUMP2];
|
||||
if (keys[MK_JUMP1]==2 || keys[MK_JUMP2]==2)
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=3)
|
||||
box_jump(&mario.p, 8);
|
||||
else
|
||||
box_jump(&mario.p, 7);
|
||||
}
|
||||
else if (mario.p.vy>0 && jump==0)
|
||||
mario.p.vy=0;
|
||||
|
||||
int vx=sgn(keys[MK_RIGHT] - keys[MK_LEFT]);
|
||||
|
||||
int c1=world_get_ctg(mario.p.x, mario.p.y-1/*+mario.p.h*/);
|
||||
int c2=world_get_ctg(mario.p.x+mario.p.w-1, mario.p.y-1/*+mario.p.h*/);
|
||||
|
||||
if (vx)
|
||||
{
|
||||
if (vx==sgn(mario.p.vx) || vx==0)
|
||||
mario_time_accel++;
|
||||
else if (vx==-sgn(mario.p.vx))
|
||||
mario_time_accel=0;
|
||||
|
||||
mario_time_accel%=4;
|
||||
if (mario_time_accel==0)
|
||||
{
|
||||
if (keys[MK_RUN] && (c1==CTG_SOIL || c2==CTG_SOIL))
|
||||
{
|
||||
if(mario.p.vx*sgn(mario.p.vx)<=4)
|
||||
mario.p.vx+=vx;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mario.p.vx*vx<2)
|
||||
mario.p.vx+=vx;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mario.p.vx)
|
||||
{
|
||||
mario_time_accel++;
|
||||
mario_time_accel%=4;
|
||||
if (mario_time_accel==0)
|
||||
mario.p.vx-=sgn(mario.p.vx);
|
||||
}
|
||||
else
|
||||
mario_time_accel=0;
|
||||
}
|
||||
|
||||
if (vx>0 && (c1==CTG_SOIL || c2==CTG_SOIL))
|
||||
last_vx_sign=1;
|
||||
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL))
|
||||
last_vx_sign=0;
|
||||
|
||||
if (mario.p.x+mario.p.vx<world_get_real_x0(mario.p.x))
|
||||
mario.p.vx=0;
|
||||
|
||||
|
||||
|
||||
|
||||
box_move(&mario.p); // <-> + gravity
|
||||
if (mario.p.x>mario_x_max)
|
||||
mario_x_max=mario.p.x;
|
||||
if (mario.p.y<0)
|
||||
mario_dead=1;
|
||||
if (mario.p.vx==0)
|
||||
mario_time_accel=0;
|
||||
|
||||
// coins
|
||||
world_t* c;
|
||||
c=world_get(mario.p.x, mario.p.y);
|
||||
if (c->type==COIN && c->p1==0)
|
||||
{score_add_coin();c->p1=1;}
|
||||
c=world_get(mario.p.x+mario.p.w-1, mario.p.y);
|
||||
if (c->type==COIN && c->p1==0)
|
||||
{score_add_coin();c->p1=1;}
|
||||
c=world_get(mario.p.x, mario.p.y+mario.p.h-1);
|
||||
if (c->type==COIN && c->p1==0)
|
||||
{score_add_coin();c->p1=1;}
|
||||
c=world_get(mario.p.x+mario.p.w-1, mario.p.y+mario.p.h-1);
|
||||
if (c->type==COIN && c->p1==0)
|
||||
{score_add_coin();c->p1=1;}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -38,4 +38,5 @@ extern int global_quit;
|
|||
extern int numero_frame;
|
||||
extern int mario_x_max;
|
||||
extern int mario_dead;
|
||||
extern int id_frame;
|
||||
#endif
|
|
@ -0,0 +1,95 @@
|
|||
#include "score.h"
|
||||
#include "mario.h"
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <gint/std/stdio.h>
|
||||
#include <gint/clock.h>
|
||||
#include <gint/timer.h>
|
||||
|
||||
int score=0;
|
||||
int lifes=5;
|
||||
|
||||
int combo=0;
|
||||
int combo_id=-10;
|
||||
|
||||
int pieces=0;
|
||||
|
||||
int time_id=0;
|
||||
int time_left=0;
|
||||
|
||||
int end_level=-1;
|
||||
|
||||
void new_game()
|
||||
{
|
||||
|
||||
lifes=5;
|
||||
pieces=0;
|
||||
score=0;
|
||||
combo=0;
|
||||
combo_id=-10;
|
||||
new_level();
|
||||
}
|
||||
|
||||
void new_level()
|
||||
{
|
||||
end_level=-1;
|
||||
time_left=300;
|
||||
time_id=0;
|
||||
}
|
||||
|
||||
void score_add_coin()
|
||||
{
|
||||
pieces++;
|
||||
score_add(10);
|
||||
}
|
||||
|
||||
void score_add(int i)
|
||||
{
|
||||
if (i==0)
|
||||
return;
|
||||
if (time_id-combo_id<=12 && time_id-combo_id>=0 && combo)
|
||||
{
|
||||
i*=2;
|
||||
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);
|
||||
}
|
||||
sprintf(str, "c*%d", pieces);
|
||||
dtext(50,0,str, C_BLACK, C_WHITE);
|
||||
|
||||
time_id++;
|
||||
if (time_id%10==0)
|
||||
time_left--;
|
||||
|
||||
sprintf(str, "TIME : %d", time_left);
|
||||
dtext(87,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);
|
||||
end_level=0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef SCORE
|
||||
#define SCORE
|
||||
|
||||
extern int score;
|
||||
extern int lifes;
|
||||
extern int end_level; // si ==-1, continue, si 0==retry, si ==1 ou + next
|
||||
|
||||
void score_add(int);
|
||||
void score_display();
|
||||
void score_add_coin();
|
||||
void new_level();
|
||||
|
||||
#endif
|