fixed rendering bug where players would be placed in the wrong chunk
This commit is contained in:
parent
281d243827
commit
245c6a44e4
|
@ -1,9 +1,10 @@
|
|||
5 6
|
||||
S.....
|
||||
031E..
|
||||
024...
|
||||
215...
|
||||
......
|
||||
5 5
|
||||
..S..
|
||||
..214
|
||||
...35
|
||||
.E15.
|
||||
.....
|
||||
|
||||
|
||||
$
|
||||
. = NULL
|
||||
|
|
BIN
obj/cars.o
BIN
obj/cars.o
Binary file not shown.
BIN
obj/collisions.o
BIN
obj/collisions.o
Binary file not shown.
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/structure.o
BIN
obj/structure.o
Binary file not shown.
|
@ -32,8 +32,8 @@ car* init_car(int nPl, int nTotPl) {
|
|||
res->nCoins = 0;
|
||||
res->pos = get_position(nPl, nTotPl);
|
||||
res->lastPos = (ptf){.fx = res->pos.fx, .fy = res->pos.fy};
|
||||
res->chx = START_CHX;
|
||||
res->chy = START_CHY;
|
||||
res->chx = START_CHY;
|
||||
res->chy = START_CHX;
|
||||
//res->vel = (ptf){.fx = 0.0, .fy = 0.0};
|
||||
double theta = (2.0*MAX_THETA_SPAWN*nPl/((nTotPl-1==0)?(1):(nTotPl-1)) - 1.0*MAX_THETA_SPAWN);
|
||||
res->vel = (ptf){.fx = (rand()%100-50.0)/100.0*2.0*MAX_SPEED, .fy = (rand()%100-50.0)/100.0*2.0*MAX_SPEED};
|
||||
|
|
|
@ -134,11 +134,11 @@ void bumpOtherCars(int nPl) {
|
|||
double speed_P = norm(players[p].c->vel);
|
||||
double speed_N = norm(players[nPl].c->vel);
|
||||
|
||||
players[p].c->vel.fx = director.fx*RESTITUTION_PLAYER*(speed_P - speed_P/2.0 + speed_N/2.0);
|
||||
players[p].c->vel.fy = director.fy*RESTITUTION_PLAYER*(speed_P - speed_P/2.0 + speed_N/2.0);
|
||||
players[p].c->vel.fx = director.fx*RESTITUTION_PLAYER*(speed_N);
|
||||
players[p].c->vel.fy = director.fy*RESTITUTION_PLAYER*(speed_N);
|
||||
|
||||
players[nPl].c->vel.fx = -director.fx*RESTITUTION_PLAYER*(speed_N + speed_P/2.0 - speed_N/2.0);
|
||||
players[nPl].c->vel.fy = -director.fy*RESTITUTION_PLAYER*(speed_N + speed_P/2.0 - speed_N/2.0);
|
||||
players[nPl].c->vel.fx = -director.fx*RESTITUTION_PLAYER*(speed_P);
|
||||
players[nPl].c->vel.fy = -director.fy*RESTITUTION_PLAYER*(speed_P);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -504,10 +504,10 @@ void renderCircles(SDL_Renderer* renderer, level* lvl, int cx, int cy, int range
|
|||
void renderPlayers(SDL_Renderer* renderer, int cx, int cy, int range, int rsize) {
|
||||
for(int p = 0; p < nPlayers; p++) {
|
||||
if(players[p].c->chx >= cx-range && players[p].c->chx <= cx+range && players[p].c->chy >= cy-range && players[p].c->chy <= cy+range) {
|
||||
int plchx = players[p].c->chx;
|
||||
int plchy = players[p].c->chy;
|
||||
int cox = (WIDTH-rsize)/2+rsize*(plchx-cx) + (int)((players[p].c->pos.fx*1.0)/ROOM_SIZE*rsize);
|
||||
int coy = (HEIGHT-rsize)/2+rsize*(plchy-cy) + (int)((players[p].c->pos.fy*1.0)/ROOM_SIZE*rsize);
|
||||
int cox = (WIDTH-rsize)/2+rsize*(players[p].c->chx-cy) + (int)((players[p].c->pos.fx*1.0)/ROOM_SIZE*rsize);
|
||||
int coy = (HEIGHT-rsize)/2+rsize*(players[p].c->chy-cx) + (int)((players[p].c->pos.fy*1.0)/ROOM_SIZE*rsize);
|
||||
//printf("Abs : (%d %d)\n", players[p].c->chx, players[p].c->chy);
|
||||
//printf("Relative : (%d : %d)\n", players[p].c->chx-cy, players[p].c->chy-cx);
|
||||
SDL_RenderFillCircle(renderer, cox, coy, PLAYER_R, players[p].rgb.red, players[p].rgb.green, players[p].rgb.blue, 255);
|
||||
} else {
|
||||
//
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "rooms.h"
|
||||
#include "cars.h"
|
||||
|
||||
const int N_PLAYERS = 6;
|
||||
const int N_PLAYERS = 4;
|
||||
double elapsed = 0.0;
|
||||
|
||||
bool halt = false;
|
||||
|
@ -77,7 +77,7 @@ int main() {
|
|||
|
||||
while(!halt) {
|
||||
resetRenderer(rend);
|
||||
renderMap(rend, test, 1, 1, 2, 250);
|
||||
renderMap(rend, test, 1, 2, 2, 250);
|
||||
if(elapsed <= 0.7) {
|
||||
placeRectToRenderer(rend, 0, 0, 50, 50, 255, 255, 32, 192);
|
||||
} else if(updateCars(test)) {
|
||||
|
|
|
@ -15,12 +15,12 @@ const double RESTITUTION_WALL = 0.8;
|
|||
const double RESTITUTION_PLAYER = 0.8;
|
||||
|
||||
const int PLAYER_R = 10;
|
||||
const int MAX_THETA_SPAWN = 60; // degrees
|
||||
const int MAX_THETA_SPAWN = 80; // degrees
|
||||
|
||||
const int BARRIERS = 1;
|
||||
const double BARRIER_WIDTH = 0.05;
|
||||
|
||||
const double FRICTION = 0.75;
|
||||
const double DV = 1.0; // m/s
|
||||
const double DV = 1.5; // m/s
|
||||
const double DT = 1.0/100.0;
|
||||
const double EPSILON = 1.0/4096.0;
|
Loading…
Reference in New Issue