Browse Source

"working" version (also cpc26 version)

Way too much >_<
master
Alice 8 months ago
parent
commit
f9e28acea4
21 changed files with 1075 additions and 4 deletions
  1. BIN
      assets-fx/icon-fx.png
  2. BIN
      assets-fx/img/ally.png
  3. BIN
      assets-fx/img/cloud.png
  4. BIN
      assets-fx/img/cloud_big.png
  5. BIN
      assets-fx/img/cursor.png
  6. BIN
      assets-fx/img/foe.png
  7. BIN
      assets-fx/img/foe_big.png
  8. BIN
      assets-fx/img/forest.png
  9. BIN
      assets-fx/img/forest_big.png
  10. BIN
      assets-fx/img/mountain.png
  11. BIN
      assets-fx/img/mountain_big.png
  12. BIN
      assets-fx/img/path.png
  13. BIN
      assets-fx/img/path_big.png
  14. BIN
      assets-fx/img/tanya.png
  15. BIN
      assets-fx/img/title.png
  16. BIN
      cpc26.g1a
  17. +15
    -0
      include/engine.h
  18. +93
    -0
      include/level.h
  19. +89
    -0
      include/test.h
  20. +870
    -0
      src/engine.c
  21. +8
    -4
      src/main.c

BIN
assets-fx/icon-fx.png View File

Before After
Width: 30  |  Height: 19  |  Size: 7.3 KiB Width: 30  |  Height: 19  |  Size: 6.8 KiB

BIN
assets-fx/img/ally.png View File

Before After
Width: 7  |  Height: 7  |  Size: 584 B

BIN
assets-fx/img/cloud.png View File

Before After
Width: 7  |  Height: 7  |  Size: 583 B

BIN
assets-fx/img/cloud_big.png View File

Before After
Width: 30  |  Height: 30  |  Size: 683 B

BIN
assets-fx/img/cursor.png View File

Before After
Width: 9  |  Height: 9  |  Size: 619 B

BIN
assets-fx/img/foe.png View File

Before After
Width: 7  |  Height: 7  |  Size: 587 B

BIN
assets-fx/img/foe_big.png View File

Before After
Width: 30  |  Height: 30  |  Size: 608 B

BIN
assets-fx/img/forest.png View File

Before After
Width: 7  |  Height: 7  |  Size: 581 B

BIN
assets-fx/img/forest_big.png View File

Before After
Width: 30  |  Height: 30  |  Size: 630 B

BIN
assets-fx/img/mountain.png View File

Before After
Width: 7  |  Height: 7  |  Size: 585 B

BIN
assets-fx/img/mountain_big.png View File

Before After
Width: 30  |  Height: 30  |  Size: 546 B

BIN
assets-fx/img/path.png View File

Before After
Width: 7  |  Height: 7  |  Size: 580 B

BIN
assets-fx/img/path_big.png View File

Before After
Width: 30  |  Height: 30  |  Size: 553 B

BIN
assets-fx/img/tanya.png View File

Before After
Width: 30  |  Height: 30  |  Size: 610 B

BIN
assets-fx/img/title.png View File

Before After
Width: 128  |  Height: 64  |  Size: 1.2 KiB

BIN
cpc26.g1a View File


+ 15
- 0
include/engine.h View File

@@ -0,0 +1,15 @@
#ifndef _ENGINE_H_
#define _ENGINE_H_

void start_engine(Level * level);
void init_engine(Level * level, Engine * engine);
void textbox(char * str);
void expo(Slide * slide, int nb_slide);
void move(Engine * engine);
void sprint(Engine * engine);
void atk(Engine * engine);
void atk2(Engine * engine);
void display(Engine * engine);
void player(Engine * engine);
void ia(Engine * engine);
#endif // _ENGINE_H_

+ 93
- 0
include/level.h View File

@@ -0,0 +1,93 @@
#ifndef _LEVEL_H_
#define _LEVEL_H_

#include <gint/display.h>
#include <stdbool.h>

typedef struct {
enum {Ally, Foe, Zero} side;
char * name;
char * rank;
image_t * picture;
int x;
int y;
int HP;
int MP;
int ATK;
int DEF;
}Entity;

typedef enum {
Forest,
Mountain,
Path,
Cloud,
}Tile_type;

typedef struct {
Tile_type type;
Entity * entity;
}Tile;

typedef struct {
int width;
int height;
Tile * tile;
}Map;

typedef struct {
enum {Text, Art} type;
union {
const char * text;
image_t * art;
};
}Slide;

typedef struct Engine{
Map * map;
int nb_event;
int event_pos;
struct Event{
int turn;
void (*ev_func)(struct Engine *);
char * dialog;
}*event_list;
int nb_entity;
Entity * entity_list;
int nb_ally;
int nb_foe;
int turn;
int x_cursor;
int y_cursor;
int x_view;
int y_view;
bool victory;
bool defeat;
}Engine;

typedef struct {
int turn;
void (*ev_func)(struct Engine *);
char * dialog;
}Event;

typedef struct {
int nb_pro, nb_event, nb_epi;
Slide * prologue;
Event * event_list;
Slide * epilogue;
}Script;

typedef struct {
char * name;
image_t * art;
char * description;
Map * map;
int nb_entity;
Entity * entity_list;
Script * script;
}Level;


#endif // _LEVEL_H_


+ 89
- 0
include/test.h View File

@@ -0,0 +1,89 @@
#include <gint/display.h>
#include "level.h"

extern image_t img_tanya;
extern image_t img_foe_big;

Entity missing_no={Zero, "Zero", "Missing No", NULL,0,0,0,0,0,0};
Entity entity_list_lvl1[] = {{Ally,"Tanya", "2nd lieutenant", &img_tanya, 6,27,100,30,100,5},
{Zero,"Enemie", "", &img_foe_big, 1,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 10,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 3,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 5,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 6,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 7,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 8,0,100,100,10,5},
{Zero,"Enemie", "", &img_foe_big, 9,0,100,100,10,5}};
Tile tiles_lvl1[]={
{Mountain, &missing_no},{Mountain, &entity_list_lvl1[1]},{Mountain, &missing_no},{Mountain, &entity_list_lvl1[3]},{Path, &missing_no},{Mountain, &entity_list_lvl1[4]},{Mountain, &entity_list_lvl1[5]},{Mountain, &entity_list_lvl1[6]},{Mountain, &entity_list_lvl1[7]},{Mountain, &entity_list_lvl1[8]},{Mountain, &entity_list_lvl1[2]},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},
{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},
{Forest, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Path, &missing_no},{Mountain, &missing_no},{Forest, &entity_list_lvl1[0]},{Mountain, &missing_no},{Forest, &missing_no},{Mountain, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Forest, &missing_no},{Forest, &missing_no}};
Map map_lvl1 = { 14, 28, tiles_lvl1};

Slide pro_list_lvl1[] = {
{Text, .text="Il etait une fois un salarie japonais chef du departement des ressources humaines au coeur froid, renvoyant sans pitie pour son propre interet et celui de ses employeurs"},
{Text, .text="Du moins cela aurait ete si un ex employe ne l'avait pousse sous le metro. Il se retrouvat alors face a Dieu."},
{Text, .text="Ce dernier en colere face a son manque de foi et son impertinance le maudit a vivre une vie a l'opose de la precedante."},
{Text, .text="Ainsi fut-il reincarne en orpheline dans un pays en guerre et ou la technologie n'etait pas autant devellopee."},
{Text, .text="Il se decidat alors de survivre et réussir une nouvelle fois pour detruire et se venger de cette entite qu'il nomera X refusant de l'appeler Dieu."},
{Text, .text="Cependant a ses 9 ans, par miracle ou par malediction l'on trouva sa capacite magique expetionel et on l'enrola de force parmis les mages volant."},
{Text, .text="Et c'est ainsi que qu'il fut deploye dans le nord avec pour mission de reconaitre la position des troupes enemies pour le compte de l'artilerie."}
};
void trouble(Engine * engine)
{
for(int i=1; i<engine->nb_entity;i++)
{
engine->entity_list[i].side=Foe;
}
}
void victory(Engine * engine)
{
engine->victory=true;
}
Event event_list_lvl1[] = {{0,NULL,"Tanya: tachons de briller afin d'obtenir rapidement une promotion à l'arriere..."},
{0,NULL,"Tanya: Controle, ici pixy1, rien à signaler, je continue mon inspection."},
{0,NULL,"Controle: Pixy1, ici controle, Bien recu"},
{8,&trouble,"Enemies: Nous devons suprimez les unités de reconnaissance enemies"},
{9,NULL,"Tanya: Controle, je detecte 8 signature au loin, demande de replis"},
{9,NULL,"Controle: negatif, nous envoyons renforts, seront sur place dans 20 tours"},
{9,NULL,"Tanya: m'envoyer à ma mort ainsi, est-ce un tour de X..."},
{179,&victory,"Tanya: Les renforts sont bientot la, quittons le combats sous les feux des projecteurs"},
{179,NULL,"Enemies: un sort d'auto-destruction, retraite avant que les renfort enemis arrivent"},
{179,NULL,"BOOOOOOUUUUUUM"},
};

Slide epi_list_lvl1[] = {
{Text, .text="Pour ses exploit heroique, le second lieutenant Tanya Von Degurechhaff recu la plus haute distinction militaire, la médaille d'assault au ailes d'argent"},
{Text, .text="Devenant ainsi la plus jeunes personne vivante à la recevoir, obtenant egalement ainsi son surnom: Argent"},
{Text, .text="Et maintenant si vous voulez la suite, aller lire l'oeuvre original, ou harcelez Alice pour qu'elle coninue son jeux ;)"},
};
Script script_lvl1 = {7,10,3, pro_list_lvl1,event_list_lvl1,epi_list_lvl1};

Level lvl1 = {"lvl1", NULL, "description", &map_lvl1, 9,entity_list_lvl1, &script_lvl1};


+ 870
- 0
src/engine.c View File

@@ -0,0 +1,870 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/string.h>
#include "level.h"
#include "engine.h"
extern Entity missing_no;
void start_engine(Level * level)
{
Engine game;
dclear(C_WHITE);
init_engine(level, &game);
expo(level->script->prologue, level->script->nb_pro);
display(&game);
while(!game.defeat && !game.victory)
{
while(game.event_pos<game.nb_event && game.event_list[game.event_pos].turn == game.turn)
{
game.x_cursor=game.entity_list[game.turn%game.nb_entity].x;
game.y_cursor=game.entity_list[game.turn%game.nb_entity].y;
game.x_view = game.x_cursor;
game.y_view = game.y_cursor;
if(game.x_view<3) game.x_view=3;
if(game.y_view<3) game.y_view=3;
if(game.x_view>game.map->width-4) game.x_view=game.map->width-4;
if(game.y_view>game.map->height-4) game.y_view=game.map->height-4;

display(&game);
if(game.event_list[game.event_pos].ev_func!=NULL)
{
(*game.event_list[game.event_pos].ev_func)(&game);
}
textbox(game.event_list[game.event_pos].dialog);
while(getkey().key!=KEY_EXE);
drect(57,30,127,63,C_WHITE);
game.event_pos++;
}
if(game.entity_list[game.turn%game.nb_entity].HP != 0 && game.entity_list[game.turn%game.nb_entity].MP!=0)
{
game.x_cursor=game.entity_list[game.turn%game.nb_entity].x;
game.y_cursor=game.entity_list[game.turn%game.nb_entity].y;
game.x_view = game.x_cursor;
game.y_view = game.y_cursor;
if(game.x_view<3) game.x_view=3;
if(game.y_view<3) game.y_view=3;
if(game.x_view>game.map->width-4) game.x_view=game.map->width-4;
if(game.y_view>game.map->height-4) game.y_view=game.map->height-4;
switch(game.entity_list[game.turn%game.nb_entity].side)
{
case Ally:
display(&game);
player(&game);
break;
case Foe:
display(&game);
ia(&game);
display(&game);
break;
default:
game.turn++;
break;
}
}else{game.turn++;}
}
if(game.victory)
{
expo(level->script->epilogue, level->script->nb_epi);
}
else
{
dclear(C_WHITE);
dtext(35,25,"Game Over", C_BLACK, C_WHITE);
dupdate();
getkey();
}
}

void textbox(char * str)
{
int len = strlen(str);
int lines = (len/11)+1;
char buff[12];
memset(buff,0,12);
drect(57,30,127,63,C_WHITE);
for(int i = 0; i<lines; i++)
{
dprint(58,30+8*(i%4),C_BLACK, C_WHITE,"%s",strncpy(buff,str+(11*sizeof(char)*i),11));
if(i%4==3)
{
dupdate();
while(getkey().key!=KEY_EXE);
drect(57,30,127,63,C_WHITE);
}
}
dupdate();
}

void expo(Slide * slide, int nb_slide)
{
int len;
char buff[22];
for(int i = 0; i<nb_slide; i++)
{
dclear(C_WHITE);
switch(slide[i].type)
{
case Text:
len = strlen(slide[i].text);
memset(buff,0,22);
for(int j = 0; j<((len/21)+1);j++)
{
dprint(0,8*j,C_BLACK,C_WHITE,"%s",strncpy(buff,slide[i].text+(sizeof(char)*21*j),21));
}
break;
case Art:
dimage(0,0,slide[i].art);
break;
}
dupdate();
while(getkey().key!=KEY_EXE);
}
}
void init_engine(Level * level, Engine * engine)
{
engine->map = level->map;
engine->nb_event = level->script->nb_event;
engine->event_list = level->script->event_list;
engine->nb_entity = level->nb_entity;
engine->entity_list = level->entity_list;
engine->nb_ally = 0;
engine->nb_foe = 0;
for (int i = 0; i < engine->nb_entity; i++)
{
switch(engine->entity_list[i].side)
{
case Ally:
engine->nb_ally++;
break;
case Foe:
engine->nb_foe++;
break;
default:break;
}
}
engine->turn = 0;
engine->event_pos=0;
engine->x_view = 3;
engine->y_view = 3;
engine->x_cursor = 3;
engine->y_cursor = 3;
engine->victory = false;
engine->defeat = false;
}
void move (Engine * engine)
{
Entity * player = &engine->entity_list[engine->turn%engine->nb_entity];
switch(getkey().key)
{
case KEY_UP:
case KEY_8:
if(player->y>0)
{
if(engine->map->tile[((player->y - 1)*engine->map->width+player->x)].entity->side == Zero)
{
engine->map->tile[(player->y - 1)*engine->map->width+player->x].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->y--;
player->MP--;
engine->turn++;
}
}
break;
case KEY_DOWN:
case KEY_2:
if(player->y<engine->map->height-1)
{
if(engine->map->tile[((player->y + 1)*engine->map->width+player->x)].entity->side == Zero)
{
engine->map->tile[(player->y + 1)*engine->map->width+player->x].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->y++;
player->MP--;
engine->turn++;
}
}
break;
case KEY_LEFT:
case KEY_4:
if(player->x>0)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x - 1)].entity->side == Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x-1].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->x--;
player->MP--;
engine->turn++;
}
}
break;
case KEY_RIGHT:
case KEY_6:
if(player->x<engine->map->width-1)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x + 1)].entity->side == Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x + 1].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->x++;
player->MP--;
engine->turn++;
}
}
break;
case KEY_5:
player->MP--;
engine->turn++;
break;
default:
break;
}
}

void sprint(Engine * engine)
{
Entity * player = &engine->entity_list[engine->turn%engine->nb_entity];
switch(getkey().key)
{
case KEY_UP:
case KEY_8:
if(player->y>1)
{
if(engine->map->tile[((player->y - 2)*engine->map->width+player->x)].entity->side == Zero)
{
engine->map->tile[(player->y - 2)*engine->map->width+player->x].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->y-=2;
player->MP-=2;
engine->turn++;
}
}
break;
case KEY_DOWN:
case KEY_2:
if(player->y<engine->map->height-2)
{
if(engine->map->tile[((player->y + 2)*engine->map->width+player->x)].entity->side == Zero)
{
engine->map->tile[(player->y + 2)*engine->map->width+player->x].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->y+=2;
player->MP-=2;
engine->turn++;
}
}
break;
case KEY_LEFT:
case KEY_4:
if(player->x>1)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x - 2)].entity->side == Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x-2].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->x-=2;
player->MP-=2;
engine->turn++;
}
}
break;
case KEY_RIGHT:
case KEY_6:
if(player->x<engine->map->width-2)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x + 2)].entity->side == Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x + 2].entity = player;
engine->map->tile[(player->y)*engine->map->width+player->x].entity = &missing_no;
player->x+=2;
player->MP-=2;
engine->turn++;
}
}
break;
case KEY_5:
player->MP--;
engine->turn++;
break;
default:
break;
}
}

void atk (Engine * engine)
{
Entity * player = &engine->entity_list[engine->turn%engine->nb_entity];
switch(getkey().key)
{
case KEY_UP:
case KEY_8:
if(player->y>0)
{
if(engine->map->tile[((player->y - 1)*engine->map->width+player->x)].entity->side != Zero)
{
engine->map->tile[(player->y - 1)*engine->map->width+player->x].entity->HP -= player->ATK;
if(engine->map->tile[(player->y - 1)*engine->map->width+player->x].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y - 1)*engine->map->width+player->x].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_DOWN:
case KEY_2:
if(player->y<engine->map->height-1)
{
if(engine->map->tile[((player->y + 1)*engine->map->width+player->x)].entity->side != Zero)
{
engine->map->tile[(player->y + 1)*engine->map->width+player->x].entity->HP = player->ATK;
if(engine->map->tile[(player->y + 1)*engine->map->width+player->x].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y + 1)*engine->map->width+player->x].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_LEFT:
case KEY_4:
if(player->x>0)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x - 1)].entity->side != Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x-1].entity->HP -= player->ATK;
if(engine->map->tile[(player->y)*engine->map->width+player->x-1].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y)*engine->map->width+player->x-1].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_RIGHT:
case KEY_6:
if(player->x<engine->map->width-1)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x + 1)].entity->side != Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x + 1].entity->HP -= player->ATK;
if(engine->map->tile[(player->y)*engine->map->width+player->x+1].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y)*engine->map->width+player->x+1].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
default:
break;
}
engine->victory = (engine->nb_foe==0);
}

void atk2(Engine * engine)
{
Entity * player = &engine->entity_list[engine->turn%engine->nb_entity];
switch(getkey().key)
{
case KEY_UP:
case KEY_8:
if(player->y>1)
{
if(engine->map->tile[((player->y - 2)*engine->map->width+player->x)].entity->side != Zero)
{
engine->map->tile[(player->y - 2)*engine->map->width+player->x].entity->HP -= player->ATK;
if(engine->map->tile[(player->y - 2)*engine->map->width+player->x].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y - 1)*engine->map->width+player->x].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_DOWN:
case KEY_2:
if(player->y<engine->map->height-2)
{
if(engine->map->tile[((player->y + 2)*engine->map->width+player->x)].entity->side != Zero)
{
engine->map->tile[(player->y + 2)*engine->map->width+player->x].entity->HP = player->ATK;
if(engine->map->tile[(player->y + 2)*engine->map->width+player->x].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y + 2)*engine->map->width+player->x].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_LEFT:
case KEY_4:
if(player->x>1)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x - 2)].entity->side != Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x-2].entity->HP -= player->ATK;
if(engine->map->tile[(player->y)*engine->map->width+player->x-2].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y)*engine->map->width+player->x-2].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
case KEY_RIGHT:
case KEY_6:
if(player->x<engine->map->width-2)
{
if(engine->map->tile[((player->y)*engine->map->width+player->x + 2)].entity->side != Zero)
{
engine->map->tile[(player->y)*engine->map->width+player->x + 2].entity->HP -= player->ATK;
if(engine->map->tile[(player->y)*engine->map->width+player->x+2].entity->HP<=0)
{
engine->nb_foe--;
engine->map->tile[(player->y)*engine->map->width+player->x+2].entity = &missing_no;
}
player->MP--;
engine->turn++;
}
}
break;
default:
break;
}
engine->victory = (engine->nb_foe==0);
}

void display(Engine * engine)
{
extern image_t img_grid;
extern image_t img_forest;
extern image_t img_mountain;
extern image_t img_path;
extern image_t img_cloud;
extern image_t img_forest_big;
extern image_t img_mountain_big;
extern image_t img_path_big;
extern image_t img_cloud_big;
extern image_t img_foe;
extern image_t img_ally;
extern image_t img_cursor;
dclear(C_WHITE);
dimage(0,0,&img_grid);
for(int i = 0; i < 7; i++)
{
for( int j = 0; j < 7 ; j++)
{
switch(engine->map->tile[(engine->x_view)-3+j+(engine->map->width)*(engine->y_view-3+i)].type)
{
case Forest:
dimage(j*8+1,i*8+1,&img_forest);
break;
case Mountain:
dimage(j*8+1,i*8+1,&img_mountain);
break;
case Path:
dimage(j*8+1,i*8+1,&img_path);
break;
case Cloud:
dimage(j*8+1,i*8+1,&img_cloud);
break;
}
}
}
for(int i = 0; i < engine->nb_entity; i++)
{
if((engine->entity_list[i].x - engine->x_view)>=-3 && (engine->entity_list[i].y - engine->y_view)>=-3 &&
(engine->entity_list[i].x - engine->x_view)<=3 && (engine->entity_list[i].y - engine->y_view)<=3)
{
switch(engine->entity_list[i].side)
{
case Ally:
dimage((engine->entity_list[i].x - engine->x_view + 3)*8+1,(engine->entity_list[i].y - engine->y_view + 3)*8+1, &img_ally);
break;
case Foe:
dimage((engine->entity_list[i].x - engine->x_view + 3)*8+1,(engine->entity_list[i].y - engine->y_view + 3)*8+1, &img_foe);
break;
default:break;
}
}
}
if(engine->map->tile[engine->x_cursor+(engine->map->width)*(engine->y_cursor)].entity->side==Zero)
{
switch(engine->map->tile[engine->x_cursor+(engine->map->width)*(engine->y_cursor)].type)
{
case Forest:
dimage(58,0,&img_forest_big);
dtext(58,30,"Forest",C_BLACK,C_WHITE);
break;
case Mountain:
dimage(58,0,&img_mountain_big);
dtext(58,30,"Mountain",C_BLACK,C_WHITE);
break;
case Path:
dimage(58,0,&img_path_big);
dtext(58,30,"Path",C_BLACK,C_WHITE);
break;
case Cloud:
dimage(58,0,&img_cloud_big);
dtext(58,30,"Cloud",C_BLACK,C_WHITE);
break;
}
}else{
Entity * focus =engine->map->tile[engine->x_cursor+(engine->map->width)*(engine->y_cursor)].entity;
if(focus->side!=Zero)
{
dimage(58,0,focus->picture);
dprint(90,0,C_BLACK,C_WHITE,"%s",focus->name);
dprint(90,9,C_BLACK,C_WHITE,"HP:%d",focus->HP);
dprint(90,19,C_BLACK,C_WHITE,"MP:%d",focus->MP);
}
}
if((engine->x_cursor - engine->x_view)>=-3 && (engine->y_cursor - engine->y_view)>=-3 &&
(engine->x_cursor - engine->x_view)<=3 && (engine->y_cursor - engine->y_view)<=3)
dimage((engine->x_cursor - engine->x_view + 3)*8,(engine->y_cursor - engine->y_view + 3)*8, &img_cursor);
dupdate();

}


void player(Engine * engine)
{
const int old_turn=engine->turn;
while(old_turn==engine->turn)
{
switch(getkey().key)
{
case KEY_UP:
if(engine->y_cursor>0)engine->y_cursor--;
break;
case KEY_DOWN:
if(engine->y_cursor<engine->map->height-1)engine->y_cursor++;
break;
case KEY_LEFT:
if(engine->x_cursor>0)engine->x_cursor--;
break;
case KEY_RIGHT:
if(engine->x_cursor<engine->map->width-1)engine->x_cursor++;
break;
case KEY_8:
if(engine->y_view>3)engine->y_view--;
break;
case KEY_2:
if(engine->y_view<engine->map->height-4)engine->y_view++;
break;
case KEY_4:
if(engine->x_view>3)engine->x_view--;
break;
case KEY_6:
if(engine->x_view<engine->map->width-4)engine->x_view++;
break;
case KEY_5:
engine->x_view = engine->x_cursor;
engine->y_view = engine->y_cursor;
if(engine->x_view<3) engine->x_view=3;
if(engine->y_view<3) engine->y_view=3;
if(engine->x_view>engine->map->width-4) engine->x_view=engine->map->width-4;
if(engine->y_view>engine->map->height-4) engine->y_view=engine->map->height-4;
break;
case KEY_EXIT:
engine->defeat= true;
engine->turn++;
break;
case KEY_F1:
move(engine);
break;
case KEY_F2:
sprint(engine);
break;
case KEY_F3:
atk(engine);
break;
case KEY_F4:
atk2(engine);
break;
default:
break;
}
display(engine);
}
if(engine->entity_list[old_turn%engine->nb_entity].MP<=0)
{
engine->nb_ally--;
engine->map->tile[engine->entity_list[old_turn%engine->nb_entity].x+(engine->map->width)*engine->entity_list[old_turn%engine->nb_entity].y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
}

void ia(Engine * engine)
{
Entity * foe = &engine->entity_list[engine->turn%engine->nb_entity];
if(foe->x>0 && engine->map->tile[foe->x-1+foe->y*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x-1+foe->y*engine->map->width].entity;
dtext(0,0,"0",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP--;
engine->turn++;
} else if(foe->y>0 && engine->map->tile[foe->x+(foe->y-1)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+(foe->y-1)*engine->map->width].entity;
dtext(0,0,"1",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP--;
engine->turn++;
} else if(foe->x<engine->map->width-1 && engine->map->tile[foe->x+1+(foe->y)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+1+(foe->y)*engine->map->width].entity;
dtext(0,0,"2",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP--;
engine->turn++;
} else if(foe->y<engine->map->height-1 && engine->map->tile[foe->x+(foe->y+1)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+(foe->y+1)*engine->map->width].entity;
dtext(0,0,"3",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP--;
engine->turn++;
}else if(foe->x>1 && engine->map->tile[foe->x-2+foe->y*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x-2+foe->y*engine->map->width].entity;
dtext(0,0,"4",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP-=2;
engine->turn++;
} else if(foe->y>1 && engine->map->tile[foe->x+(foe->y-2)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+(foe->y-2)*engine->map->width].entity;
dtext(0,0,"5",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP-=2;
engine->turn++;
} else if(foe->x<engine->map->width-2 && engine->map->tile[foe->x+2+(foe->y)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+2+(foe->y)*engine->map->width].entity;
dtext(0,0,"6",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP-=2;
engine->turn++;
} else if(foe->y<engine->map->height-2 && engine->map->tile[foe->x+(foe->y+2)*engine->map->width].entity->side == Ally)
{
Entity * target = engine->map->tile[foe->x+(foe->y+2)*engine->map->width].entity;
dtext(0,0,"7",C_BLACK,C_WHITE);
dupdate();
getkey();
target->HP-=foe->ATK;
if(target->HP<=0)
{
engine->nb_ally--;
engine->map->tile[target->x+(engine->map->width)*target->y].entity = &missing_no;
engine->defeat = (engine->nb_ally == 0);
}
foe->MP-=2;
engine->turn++;
}else{ int target_id=0;
dtext(0,0,"8",C_BLACK,C_WHITE);
dupdate();
getkey();
while(engine->entity_list[target_id].HP == 0 ||engine->entity_list[target_id].MP==0)
{
target_id++;
}
Entity * target = &engine->entity_list[target_id];
int dx = target->x - foe->x;
int dy = target->y - foe->y;
if (dy > 2)
{
dtext(0,0,"9",C_BLACK,C_WHITE);
dupdate();
getkey();
if(engine->map->tile[foe->x+engine->map->width*(foe->y+2)].entity->side==Zero)
{
foe->MP-=2;
engine->map->tile[foe->x+engine->map->width*(foe->y+2)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y+=2;
}else if(engine->map->tile[foe->x+engine->map->width*(foe->y+1)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+engine->map->width*(foe->y+1)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y+=1;
}else{
foe->MP--;
}
}else if (dy < -2)
{
if(engine->map->tile[foe->x+engine->map->width*(foe->y-2)].entity->side==Zero)
{
foe->MP-=2;
engine->map->tile[foe->x+engine->map->width*(foe->y-2)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y-=2;
}else if(engine->map->tile[foe->x+engine->map->width*(foe->y-1)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+engine->map->width*(foe->y-1)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y-=1;
}else{
foe->MP--;
}
}else if (dx > 2)
{
if(engine->map->tile[foe->x+2+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP-=2;
engine->map->tile[foe->x+2+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x+=2;
}else if(engine->map->tile[foe->x+1+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+1+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x+=1;
}else{
foe->MP--;
}
}else if (dx < -2)
{
if(engine->map->tile[foe->x-2+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP-=2;
engine->map->tile[foe->x-2+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x-=2;
}else if(engine->map->tile[foe->x-1+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x-1+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x-=1;
}else{
foe->MP--;
}
}else if (dy == 1)
{
if(engine->map->tile[foe->x+engine->map->width*(foe->y+1)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+engine->map->width*(foe->y+1)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y+=1;
}else{
foe->MP--;
}
}else if (dy == -1)
{
if(engine->map->tile[foe->x+engine->map->width*(foe->y-1)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+engine->map->width*(foe->y-1)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->y-=1;
}else{
foe->MP--;
}
}else if (dx == 1)
{
if(engine->map->tile[foe->x+1+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x+1+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x+=1;
}else{
foe->MP--;
}
}else if (dx == -1)
{
if(engine->map->tile[foe->x-1+engine->map->width*(foe->y)].entity->side==Zero)
{
foe->MP--;
engine->map->tile[foe->x-1+engine->map->width*(foe->y)].entity = foe;
engine->map->tile[foe->x+engine->map->width*(foe->y)].entity = &missing_no;
foe->x-=1;
}else{
foe->MP--;
}
}
engine->turn++;
}
if (foe->MP<=0)
{
engine->nb_foe--;
engine->map->tile[foe->x+(engine->map->width)*foe->y].entity = &missing_no;
engine->victory = (engine->nb_foe == 0);
}
}

+ 8
- 4
src/main.c View File

@@ -1,13 +1,17 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "level.h"
#include "engine.h"
#include "test.h"

int main(void)
{
extern image_t img_grid;
extern image_t img_title;
dclear(C_WHITE);
dimage(0, 0, &img_grid);
dimage(0,0,&img_title);
dupdate();
while(getkey().key!=KEY_EXE);
start_engine(&lvl1);

getkey();
return 1;
return 0;
}

Loading…
Cancel
Save