- Corregits bugs del moviment

- Ara es mou de 2 en 2 pixels, com el orichinal
This commit is contained in:
2023-11-22 12:44:05 +01:00
parent 930550e039
commit 4ae0000aaf

59
main.c
View File

@@ -26,7 +26,7 @@ SDL_Texture * tex;
Uint8 pixels[200*200];
int player_x = 100;
int player_y = 199;
int player_y = 198;
int mode = MODE_NORMAL;
int lento = 0;
@@ -109,16 +109,16 @@ int main(int argc, char *argv[])
SDL_RenderSetLogicalSize(ren, 320, 240);
for (int i=0; i<200*200; ++i) pixels[i]=0;
for (int i=0; i<200; ++i) pixels[i]=pixels[i+199*200]=pixels[i*200]=pixels[199+i*200]=1;
for (int i=0; i<200; ++i) pixels[i]=pixels[i+198*200]=pixels[i*200]=pixels[198+i*200]=1;
SDL_SetRenderTarget(ren, tex);
set_color(COLOR_BLACK);
SDL_RenderClear(ren);
set_color(COLOR_WHITE);
SDL_RenderDrawLine(ren, 0, 0, 199, 0);
SDL_RenderDrawLine(ren, 0, 0, 0, 199);
SDL_RenderDrawLine(ren, 199, 199, 199, 0);
SDL_RenderDrawLine(ren, 199, 199, 0, 199);
SDL_RenderDrawLine(ren, 0, 0, 198, 0);
SDL_RenderDrawLine(ren, 0, 0, 0, 198);
SDL_RenderDrawLine(ren, 198, 198, 198, 0);
SDL_RenderDrawLine(ren, 198, 198, 0, 198);
SDL_SetRenderTarget(ren, NULL);
int should_exit = 0;
@@ -138,47 +138,50 @@ int main(int argc, char *argv[])
};
}
}
int speed = 15;
if (lento) speed = 30;
int speed = 30;
if (lento) speed = 60;
if (SDL_GetTicks()-t>=speed)
{
if (keys[SDL_SCANCODE_UP] && player_y>0 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x+(player_y-1)*200]==1)) {
if (keys[SDL_SCANCODE_UP] && player_y>0 && ( ((mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE])&&pixels[player_x+(player_y-2)*200]==0) || pixels[player_x+(player_y-2)*200]==1)) {
if (mode==MODE_CREANT)
put_pix();
else if (pixels[player_x+(player_y-1)*200]==0)
else if (pixels[player_x+(player_y-2)*200]==0)
lento=1;
mode = MODE_CREANT; player_y--;
} else if (keys[SDL_SCANCODE_RIGHT] && player_x<199 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x+1+player_y*200]==1)) {
mode = MODE_CREANT; player_y--; put_pix(); player_y--;
} else if (keys[SDL_SCANCODE_RIGHT] && player_x<198 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x+2+player_y*200]==1)) {
if (mode==MODE_CREANT)
put_pix();
else if (pixels[player_x+1+player_y*200]==0)
else if (pixels[player_x+2+player_y*200]==0)
lento=1;
mode = MODE_CREANT; player_x++;
} else if (keys[SDL_SCANCODE_DOWN] && player_y<199 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x+(player_y+1)*200]==1)) {
mode = MODE_CREANT; player_x++; put_pix(); player_x++;
} else if (keys[SDL_SCANCODE_DOWN] && player_y<198 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x+(player_y+2)*200]==1)) {
if (mode==MODE_CREANT)
put_pix();
else if (pixels[player_x+(player_y+1)*200]==0)
else if (pixels[player_x+(player_y+2)*200]==0)
lento=1;
mode = MODE_CREANT; player_y++;
} else if (keys[SDL_SCANCODE_LEFT] && player_x>0 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x-1+player_y*200]==1)) {
mode = MODE_CREANT; player_y++; put_pix(); player_y++;
} else if (keys[SDL_SCANCODE_LEFT] && player_x>0 && ( mode==MODE_CREANT || keys[SDL_SCANCODE_SPACE] || pixels[player_x-2+player_y*200]==1)) {
if (mode==MODE_CREANT)
put_pix();
else if (pixels[player_x-1+player_y*200]==0)
else if (pixels[player_x-2+player_y*200]==0)
lento=1;
mode = MODE_CREANT; player_x--;
mode = MODE_CREANT; player_x--; put_pix(); player_x--;
}
if (mode==MODE_CREANT && !keys[SDL_SCANCODE_SPACE])
if (mode==MODE_CREANT)
{
make_rapid();
lento=0;
if (!keys[SDL_SCANCODE_SPACE])
{
make_rapid();
lento=0;
}
if (pixels[player_x+player_y*200]==1)
{
close_sector();
mode = MODE_NORMAL;
}
}
if (pixels[player_x+player_y*200]==1)
{
close_sector();
mode = MODE_NORMAL;
}
t = SDL_GetTicks();
}
set_color(COLOR_BLACK);