tron

le jeu des motos dans tron - retour accueil

git clone git://bebou.netlib.re/tron

Log | Files | Refs | README |

commit a5b539e2d868ae8cdd377505942b7818213b4d1b
parent 6438d4e7d66d94ad49fe6c775d0bd7dd232146c1
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Thu, 19 Jun 2025 21:40:53 +0200

On évite de mourir trop tôt

Les voitures peuvent encore spawner très proches mais soit

Diffstat:
Mtron.c | 25++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/tron.c b/tron.c @@ -2,7 +2,7 @@ #include "termbox2.h" #include <time.h> -#define TAIL 20 +#define TAIL 50 enum direction { UP, RIGHT, DOWN, LEFT }; @@ -82,13 +82,6 @@ int main(int argc, char **argv) { coord incs[4] = { up, right, down, left }; srand(time(NULL)); - struct car c1; - c1.path=malloc(sizeof(coord)*300); c1.direction=DOWN; - c1.color=TB_MAGENTA; - struct car c2; - c2.path=malloc(sizeof(coord)*300); c2.direction=UP; - c2.color=TB_CYAN; - int dead_car; tb_init(); @@ -100,8 +93,18 @@ int main(int argc, char **argv) { struct arena arena; arena.width=width-1; arena.height=height-3; - c1.position.x=rd(5,width-5); c1.position.y=rd(5,height-5); - c2.position.x=rd(5,width-5); c2.position.y=rd(5,height-5); + struct car c1; + c1.path=malloc(sizeof(coord)*300); + c1.color=TB_MAGENTA; + struct car c2; + c2.path=malloc(sizeof(coord)*300); + c2.color=TB_CYAN; + + c1.position.x=rd(10,width-10); c1.position.y=rd(10,height-10); + c2.position.x=rd(10,width-10); c2.position.y=rd(10,height-10); + + if(c1.position.x<width/2) c1.direction=RIGHT; else c1.direction=LEFT; + if(c2.position.x<width/2) c2.direction=RIGHT; else c2.direction=LEFT; struct car cars[2]; cars[0]=c1; cars[1]=c2; @@ -118,7 +121,7 @@ int main(int argc, char **argv) { tb_clear(); display(cars,ticknb,TAIL,arena); tb_present(); - tb_peek_event(&ev, 1000); + tb_peek_event(&ev, 100); switch(ev.ch) { case 122: /*z*/ if(cars[1].direction!=DOWN) cars[1].direction=UP;