added slow tiles$

This commit is contained in:
Alexandre 2025-06-06 13:55:47 +02:00
parent 741f63e2af
commit 17983b20b3
15 changed files with 140 additions and 103 deletions

View File

@ -5,7 +5,7 @@ LFLAGS = -lSDL2 -lSDL2_image -lm
all: bin/back
replay: bin/back
bin/back levels/test.txt REP bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
testL: bin/back
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6

View File

@ -1 +1 @@
270 100
348 100

View File

@ -1,68 +1,4 @@
-4.520035 -153.010954
21.769531 -238.471209
-19.987625 -241.204125
-19.500799 -168.039659
14.728318 -231.892620
-1.146169 -211.802657
160.346794 -12.942202
14.734663 -229.843788
183.187726 -20.067243
191.008872 -6.736352
170.348954 0.561499
14.343889 -247.122293
20.500323 190.947536
203.536940 20.430462
-16.283639 158.826220
238.344449 12.606080
177.328188 4.682923
186.150359 3.312978
156.149007 -14.652285
-0.279201 226.257003
155.454736 7.969019
-15.445195 -203.505108
154.883574 -19.965314
2.886820 249.026500
193.744106 9.469789
224.583212 11.928862
158.436164 -17.376616
-16.274097 -246.655139
201.930360 18.198730
211.031319 13.971414
167.641503 2.279956
240.821867 -1.488584
15.075325 169.095356
-7.630298 196.102117
-16.364244 182.033073
235.854636 -0.618213
-3.898845 151.466209
11.772678 255.408435
14.850871 172.844069
-18.121169 196.343427
-159.980078 -16.452435
-1.103776 223.906609
-164.136493 2.665638
-188.419881 11.708277
-168.416232 3.726386
-246.001750 26.159777
-162.864443 -16.413678
-185.432804 -17.595811
10.500652 172.253365
-246.953352 -25.972959
2.389557 169.349638
11.802635 177.146925
-150.628957 1.655484
-21.620570 212.484655
-174.943953 17.815758
10.246061 250.882924
-159.806539 11.576918
-230.847475 -27.358011
-156.905847 -16.074234
-232.901653 13.792754
-13.141665 -171.881205
17.978969 -168.541785
10.998418 -163.890031
-226.053584 27.174607
19.537432 -182.302590
0.707694 -182.975442
-25.737269 -245.385320
-22.985682 -253.425572
145.823546 -38.881425
-193.127137 113.697483
-225.276144 -32.532029
152.154832 -39.888911

View File

@ -5,7 +5,7 @@ name, elo
./bots/dumb4 1466
./bots/dumb5 540
./bots/dumb6 562
./bots/follow1 616
./bots/follow2 702
./bots/follow3 641
./bots/follow4 617
./bots/follow1 657
./bots/follow2 726
./bots/follow3 652
./bots/follow4 671

View File

@ -1,9 +1,9 @@
5 9
31114.314
S...035.0
31714.314
S...035.6
.E..25..0
.0..31115
.2115....
.6..37115
.2175....
$
. = NULL

View File

@ -1,16 +1,16 @@
4
0 (1 2) (77.50 55.88)
1 (1 2) (54.26 37.50)
2 (1 2) (33.12 59.00)
3 (1 3) (74.02 24.62)
0 (0 1) (79.84 55.26)
1 (0 1) (63.60 77.08)
2 (0 1) (36.40 77.08)
3 (0 1) (20.16 55.26)
3
5 9
31114.314
S...035.0
31714.314
S...035.6
.E..25..0
.0..31115
.2115....
.6..37115
.2175....
100 200 5 0.90 0.80 0.20 0.00

View File

@ -91,6 +91,8 @@ int return_directions(road r) {
case END: return 15;
case STR_V: return 5;
case STR_H: return 10;
case STR_VB: return 5;
case STR_HB: return 10;
case TURN_NE: return 3;
case TURN_SE: return 6;
case TURN_SW: return 12;

View File

@ -138,6 +138,27 @@ void move_on_STR_V(int nPl) {
}
}
double absf(double x) {return (x<0.0)?(-x):(x);}
void move_on_STR_VB(int nPl) {
car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT;
c->pos.fy += c->vel.fy*DT;
if(c->pos.fx-PLAYER_R <= ROOM_SIZE*DIST_EDGE && c->vel.fx < 0.0) { // left wall
c->vel.fx *= -1.0;
c->pos.fx += 2.0*c->vel.fx*DT;
c->vel.fx *= RESTITUTION_WALL;
}
if(c->pos.fx+PLAYER_R >= ROOM_SIZE*(1.0-DIST_EDGE) && c->vel.fx > 0.0) { // right wall
c->vel.fx *= -1.0;
c->pos.fx += 2.0*c->vel.fx*DT;
c->vel.fx *= RESTITUTION_WALL;
}
if(absf(c->pos.fx - 0.5*ROOM_SIZE) < ROOM_SIZE*STR2_W/2.0) { // middle area
apply_friction(nPl);
apply_friction(nPl);
}
}
void move_on_STR_H(int nPl) {
car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT;
@ -154,6 +175,26 @@ void move_on_STR_H(int nPl) {
}
}
void move_on_STR_HB(int nPl) {
car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT;
c->pos.fy += c->vel.fy*DT;
if(c->pos.fy-PLAYER_R <= ROOM_SIZE*DIST_EDGE && c->vel.fy < 0.0) { // top wall
c->vel.fy *= -1.0;
c->pos.fy += 2.0*c->vel.fy*DT;
c->vel.fy *= RESTITUTION_WALL;
}
if(c->pos.fy+PLAYER_R >= ROOM_SIZE*(1.0-DIST_EDGE) && c->vel.fy > 0.0) { // bottom wall
c->vel.fy *= -1.0;
c->pos.fy += 2.0*c->vel.fy*DT;
c->vel.fy *= RESTITUTION_WALL;
}
if(absf(c->pos.fy - 0.5*ROOM_SIZE) < ROOM_SIZE*STR2_W/2.0) { // middle area
apply_friction(nPl);
apply_friction(nPl);
}
}
void move_on_TURN(int nPl, int cenX, int cenY) {
car* c = players[nPl].c;
ptf prev = (ptf){.fx = c->pos.fx, .fy = c->pos.fy};
@ -331,6 +372,26 @@ bool updateCar(level* lvl, int nPl) {
apply_friction(nPl);
updateChunk(lvl, nPl);
return true;
case STR_VB:
addEnviroSpeed(nPl);
move_on_STR_VB(nPl);
removeEnviroSpeed(nPl);
bumpOtherCars(nPl);
apply_friction(nPl);
updateChunk(lvl, nPl);
return true;
case STR_HB:
addEnviroSpeed(nPl);
move_on_STR_HB(nPl);
removeEnviroSpeed(nPl);
bumpOtherCars(nPl);
apply_friction(nPl);
updateChunk(lvl, nPl);
return true;
case TURN_NE:
addEnviroSpeed(nPl);

View File

@ -4,4 +4,6 @@
bool updateCars(level* lvl);
void updateWins(int* ranks);
void apply_friction(int nPl);
#endif

View File

@ -365,12 +365,18 @@ void drawQuarterCircleToRenderer(SDL_Renderer * renderer, int32_t centreX, int32
++y;
error += ty;
ty += 2;
++y;
error += ty;
ty += 2;
}
if(error > 0) {
--x;
tx += 2;
error += (tx - diameter);
--x;
tx += 2;
error += (tx - diameter);
}
}
}
@ -423,16 +429,36 @@ void renderStraights(SDL_Renderer* renderer, level* lvl, int cx, int cy, int ran
64, 64, 64, 255);
break;
case TURN_NE:
case STR_VB:
placeRectToRenderer(renderer, (WIDTH-rsize)/2+rsize*y, (HEIGHT-rsize)/2+rsize*x, rsize, rsize, 0, 0, 0, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y+(int)(DIST_EDGE*rsize),
(HEIGHT-rsize)/2+rsize*x,
rsize-(int)(2*DIST_EDGE*rsize),
rsize,
64, 64, 64, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y+(int)((1.0-STR2_W)/2.0*rsize),
(HEIGHT-rsize)/2+rsize*x,
(int)(STR2_W*rsize),
rsize,
64, 0, 0, 255);
break;
case TURN_SE:
break;
case TURN_SW:
break;
case TURN_NW:
case STR_HB:
placeRectToRenderer(renderer, (WIDTH-rsize)/2+rsize*y, (HEIGHT-rsize)/2+rsize*x, rsize, rsize, 0, 0, 0, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y,
(HEIGHT-rsize)/2+rsize*x+(int)(DIST_EDGE*rsize),
rsize,
rsize-(int)(2*DIST_EDGE*rsize),
64, 64, 64, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y,
(HEIGHT-rsize)/2+rsize*x+(int)((1.0-STR2_W)/2.0*rsize),
rsize,
(int)(STR2_W*rsize),
64, 0, 0, 255);
break;
default:

View File

@ -134,12 +134,12 @@ void parse_all_players(level* lvl, char** execs) {
int main(int argc, char** argv) {
if(argc < 2) {
fprintf(stderr, "usage : ./back <level_path> <P1 executable> <P2 executable> ...\n");
fprintf(stderr, "usage : ./back ?<-R> <level_path> <P1 executable> <P2 executable> ...\n");
exit(1);
}
int offsetP = 0;
if(argv[2][0] == 'R' && argv[2][1] == 'E' && argv[2][2] == 'P' && argv[2][3] == '\0') {
if(argv[1+offsetP][0] == '-' && argv[1+offsetP][1] == 'R' && argv[1+offsetP][2] == '\0') {
// replay mode
noise = false;
printf("---------------------------\n");
@ -192,7 +192,7 @@ int main(int argc, char** argv) {
init_music();
// ---------------------------- //
//stage_file("levels/stage.txt");
level* stage = parse_level(argv[1]);
level* stage = parse_level(argv[1+offsetP]);
init_all(N_PLAYERS);
printf("\n");
path* pth = getPath(stage);
@ -304,5 +304,5 @@ TODO :
+ add hazards
KNOWN ISSUES :
- car can sometimes clip into walls (rare, seems turn-related)
- /
*/

View File

@ -47,6 +47,8 @@ int read_int(FILE* ptr) {
3 = BottomRight (SE)
4 = BottomLeft (SW)
5 = TopLeft (NW)
6 = Vertical2
7 = Horizontal2
S = Start
E = End
*/
@ -70,6 +72,10 @@ road get_type(char c) {
return TURN_SW;
case '5':
return TURN_NW;
case '6':
return STR_VB;
case '7':
return STR_HB;
default:
fprintf(stderr, "unrecognized character '%c' encountered in parsing", c);

View File

@ -33,6 +33,8 @@ const double DELTA_THETA = 7.0; // degrees
const double WIND_X = 0.0;
const double WIND_Y = 0.0;
const double STR2_W = 0.2;
double B = 0.0; // 0.6 works fine
// ------------------------------------------------------------------------------------------ //

View File

@ -43,7 +43,7 @@ typedef struct color_t {
} color;
// one chunk
typedef enum road_t {NONE, START, END, STR_V, STR_H, TURN_NE, TURN_SE, TURN_SW, TURN_NW} road;
typedef enum road_t {NONE, START, END, STR_V, STR_H, TURN_NE, TURN_SE, TURN_SW, TURN_NW, STR_VB, STR_HB} road;
typedef struct level_t {
int lines;
@ -87,6 +87,8 @@ extern const int HEIGHT;
extern const int ROOM_SIZE;
extern const int MAX_SPEED;
extern const double STR2_W;
extern int START_CHX;
extern int START_CHY;
extern int FINISH_CHX;

View File

@ -5,7 +5,7 @@ name, elo
./bots/dumb4 1466
./bots/dumb5 540
./bots/dumb6 562
./bots/follow1 616
./bots/follow2 702
./bots/follow3 641
./bots/follow4 617
./bots/follow1 657
./bots/follow2 726
./bots/follow3 652
./bots/follow4 671