2020-02-14 18:53:59 +01:00
|
|
|
#include "../../include/SLK/SLK.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int type;
|
|
|
|
int frame;
|
2020-04-11 17:03:26 +02:00
|
|
|
int flip;
|
2020-02-14 18:53:59 +01:00
|
|
|
}Dino;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Dino *dinos;
|
|
|
|
int used;
|
|
|
|
int space;
|
|
|
|
}Dino_army;
|
|
|
|
|
|
|
|
Dino_army world;
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_Sprite *dino_sprites[4][24];
|
2020-02-14 18:53:59 +01:00
|
|
|
int frame = 0;
|
|
|
|
char time_stat[48];
|
|
|
|
|
|
|
|
void add_dino();
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_setup(320,240,"SLK Engine",1,1);
|
2020-02-14 18:53:59 +01:00
|
|
|
SLK_set_FPS(30);
|
|
|
|
SLK_show_cursor(1);
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_set_clear_color(1);
|
2020-02-14 18:53:59 +01:00
|
|
|
SLK_clear_screen();
|
|
|
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_load_palette("../assets/performance.pal");
|
|
|
|
SLK_Sprite *tileset = SLK_load_sprite("../assets/dino_sprites_doux.slk");
|
2020-02-14 18:53:59 +01:00
|
|
|
for(int x = 0;x<24;x++)
|
|
|
|
{
|
2020-04-11 17:03:26 +02:00
|
|
|
dino_sprites[0][x] = SLK_create_sprite(24,24);
|
|
|
|
SLK_copy_partial_sprite(dino_sprites[0][x],tileset,0,0,x*24,0,24,24);
|
2020-02-14 18:53:59 +01:00
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_destroy_sprite(tileset);
|
2020-02-14 18:53:59 +01:00
|
|
|
|
2020-04-11 17:03:26 +02:00
|
|
|
tileset = SLK_load_sprite("../assets/dino_sprites_mort.slk");
|
2020-02-14 18:53:59 +01:00
|
|
|
for(int x = 0;x<24;x++)
|
|
|
|
{
|
2020-04-11 17:03:26 +02:00
|
|
|
dino_sprites[1][x] = SLK_create_sprite(24,24);
|
|
|
|
SLK_copy_partial_sprite(dino_sprites[1][x],tileset,0,0,x*24,0,24,24);
|
2020-02-14 18:53:59 +01:00
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_destroy_sprite(tileset);
|
2020-02-14 18:53:59 +01:00
|
|
|
|
2020-04-11 17:03:26 +02:00
|
|
|
tileset = SLK_load_sprite("../assets/dino_sprites_tard.slk");
|
2020-02-14 18:53:59 +01:00
|
|
|
for(int x = 0;x<24;x++)
|
|
|
|
{
|
2020-04-11 17:03:26 +02:00
|
|
|
dino_sprites[2][x] = SLK_create_sprite(24,24);
|
|
|
|
SLK_copy_partial_sprite(dino_sprites[2][x],tileset,0,0,x*24,0,24,24);
|
2020-02-14 18:53:59 +01:00
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_destroy_sprite(tileset);
|
2020-02-14 18:53:59 +01:00
|
|
|
|
2020-04-11 17:03:26 +02:00
|
|
|
tileset = SLK_load_sprite("../assets/dino_sprites_vita.slk");
|
2020-02-14 18:53:59 +01:00
|
|
|
for(int x = 0;x<24;x++)
|
|
|
|
{
|
2020-04-11 17:03:26 +02:00
|
|
|
dino_sprites[3][x] = SLK_create_sprite(24,24);
|
|
|
|
SLK_copy_partial_sprite(dino_sprites[3][x],tileset,0,0,x*24,0,24,24);
|
2020-02-14 18:53:59 +01:00
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
SLK_destroy_sprite(tileset);
|
2020-02-14 18:53:59 +01:00
|
|
|
|
|
|
|
world.space = 100;
|
|
|
|
world.used = 0;
|
|
|
|
world.dinos = malloc(sizeof(Dino)*world.space);
|
2020-04-11 17:03:26 +02:00
|
|
|
double time = 0;
|
|
|
|
|
|
|
|
while(world.used<1000)
|
|
|
|
add_dino();
|
|
|
|
|
2020-02-14 18:53:59 +01:00
|
|
|
while(SLK_running())
|
|
|
|
{
|
|
|
|
SLK_update();
|
|
|
|
SLK_clear_screen();
|
|
|
|
frame++;
|
2020-04-11 17:03:26 +02:00
|
|
|
int next_frame = frame%4==0;
|
2020-02-14 18:53:59 +01:00
|
|
|
|
|
|
|
clock_t start = clock();
|
|
|
|
for(int i = 0;i<world.used;i++)
|
|
|
|
{
|
|
|
|
if(next_frame)
|
|
|
|
{
|
|
|
|
world.dinos[i].frame++;
|
|
|
|
if(world.dinos[i].frame>3)
|
|
|
|
world.dinos[i].frame = 0;
|
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
|
|
|
|
SLK_draw_sprite(dino_sprites[world.dinos[i].type][world.dinos[i].frame],world.dinos[i].x,world.dinos[i].y);
|
2020-02-14 18:53:59 +01:00
|
|
|
}
|
2020-04-11 17:03:26 +02:00
|
|
|
time+=((double)(clock()-start)/CLOCKS_PER_SEC);
|
|
|
|
if(next_frame)
|
|
|
|
sprintf(time_stat,"%04lf %04d",time/((double)frame)/*/world.used*10.0f*/,world.used);
|
2020-02-14 18:53:59 +01:00
|
|
|
|
2020-04-11 17:03:26 +02:00
|
|
|
if(SLK_key_down(SLK_KEY_SPACE))
|
2020-02-14 18:53:59 +01:00
|
|
|
add_dino();
|
2020-04-11 17:03:26 +02:00
|
|
|
|
|
|
|
SLK_fill_rectangle(0,0,104,8,SLK_create_paxel(2,SLK_OPAQUE));
|
|
|
|
SLK_draw_string(0,0,1,time_stat,SLK_create_paxel(3,SLK_OPAQUE));
|
2020-02-14 18:53:59 +01:00
|
|
|
|
|
|
|
SLK_update_screen();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_dino()
|
|
|
|
{
|
|
|
|
world.dinos[world.used].frame = rand()%4;
|
2020-04-11 17:03:26 +02:00
|
|
|
world.dinos[world.used].x = rand()%320-12;
|
|
|
|
world.dinos[world.used].y = rand()%240-12;
|
2020-02-14 18:53:59 +01:00
|
|
|
world.dinos[world.used].type = rand()%4;
|
2020-04-11 17:03:26 +02:00
|
|
|
world.dinos[world.used].flip = rand()%2;
|
2020-02-14 18:53:59 +01:00
|
|
|
|
|
|
|
world.used++;
|
|
|
|
|
|
|
|
if(world.used>=world.space)
|
|
|
|
{
|
|
|
|
world.space+=100;
|
|
|
|
world.dinos = realloc(world.dinos,sizeof(Dino)*world.space);
|
|
|
|
}
|
|
|
|
}
|