le jeu des motos dans tron - retour accueil
git clone git://bebou.netlib.re/tron
Log | Files | Refs | README |
commit bd985f60a1468e73acf0cba6d30d72b314644e5e parent 91292c5853a98595a690ba9e5f240f545ec8c677 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 19 Jun 2025 18:42:02 +0200 zqsd pour contrôler la deuxième voiture Diffstat:
M | tron.c | | | 33 | +++++++++++++++------------------ |
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/tron.c b/tron.c @@ -19,12 +19,11 @@ struct car { void display(struct car *cars, int ticks, int tail) { for (int i=0;i<2;i++) { tb_printf(cars[i].position.x,cars[i].position.y,0,0,"$"); - for (int j=ticks-tail;j<ticks+1;j++) { + for (int j=ticks-tail;j<ticks+1;j++) if(cars[i].path[j].x!=cars[i].path[j-1].x) tb_printf(cars[i].path[j].x,cars[i].path[j].y,0,0,"▒"); else tb_printf(cars[i].path[j].x,cars[i].path[j].y,0,0,"▒"); - } tb_printf(0,i,0,0,"car %d - x: %d, y: %d, direction %d",i,cars[i].position.x,cars[i].position.y,cars[i].direction); } } @@ -82,13 +81,19 @@ int main(int argc, char **argv) { tb_clear(); display(cars,ticknb,TAIL); tb_present(); - tb_peek_event(&ev, 1000); + tb_peek_event(&ev, 50); switch(ev.ch) { - case 97: /*a*/ + case 122: /*z*/ + if(cars[1].direction!=DOWN) cars[1].direction=UP; break; - case 98: /*b*/ + case 100: /*d*/ + if(cars[1].direction!=LEFT) cars[1].direction=RIGHT; break; - default: + case 115: /*s*/ + if(cars[1].direction!=UP) cars[1].direction=DOWN; + break; + case 113: /*q*/ + if(cars[1].direction!=RIGHT) cars[1].direction=LEFT; break; } switch(ev.key) { @@ -96,24 +101,16 @@ int main(int argc, char **argv) { tb_shutdown(); return 0; case 65517: /*up*/ - if(cars[0].direction!=DOWN) { - cars[0].direction=UP; - } + if(cars[0].direction!=DOWN) cars[0].direction=UP; break; case 65514: /*right*/ - if(cars[0].direction!=LEFT) { - cars[0].direction=RIGHT; - } + if(cars[0].direction!=LEFT) cars[0].direction=RIGHT; break; case 65516: /*down*/ - if(cars[0].direction!=UP) { - cars[0].direction=DOWN; - } + if(cars[0].direction!=UP) cars[0].direction=DOWN; break; case 65515: /*left*/ - if(cars[0].direction!=RIGHT) { - cars[0].direction=LEFT; - } + if(cars[0].direction!=RIGHT) cars[0].direction=LEFT; break; default: break;