I am trying to make a tron style game and I need a help finding the previous position of a rectangle(my player) and drawing over it another reactangle(the light trail).The code i wrote dose something like that but dose not work how i want it to. Te player starts at 400,400(x,y) and the previous x and y variables are initiated with 400.
int main()
{
InitWindow(800, 800, "Tron");
SetTargetFPS(10);
int direction=0;
while (!WindowShouldClose())
{
ClearBackground(BLACK);
BeginDrawing();
DrawRectangle(player1x, player1y, 18, 18, RED);
EndDrawing();
DrawRectangle(prevx, prevy, 18, 18, RED);
if (IsKeyPressed(KEY_D))
{
direction = 1;
}
else if (IsKeyPressed(KEY_A))
{
direction = 2;
}
else if (IsKeyPressed(KEY_W))
{
direction = 3;
}
else if (IsKeyPressed(KEY_S))
{
direction = 4;
}
if (direction == 1)
{
player1x = player1x + 20;
prevx = player1x - 20;
}
else if (direction == 2)
{
prevx = player1x + 20;
player1x = player1x - 20;
}
else if (direction == 3)
{
prevy = player1y + 20;
player1y = player1y - 20;
}
else if (direction == 4)
{
prevy = player1y - 20;
player1y = player1y + 20;
}
}
CloseWindow();
return 0;
}