Activity

Aalisha

Hello!
First I decided to rewrite the code and this time use classes. I created the class Car with methods for the controls, collisions, etc. In the main file, I just create 2 cars, car1 and car2 and can now easily adjust code order.
Then I tried fixing the collision bug. Since I rewrote the program, the bug kind of got fixed on its own. A similar bug still exists and I don’t know why, but I’ll either search for it tomorrow or ignore it as it is a rare case of when you collide diagonally and do “cross the wall”.
Another collision problem is, that the cars can sometimes go inside each other (a bit). It is due to me checking for the distance between a point and a line. It would be solved, if I check for collision between 2 lines. I’ll try that tomorrow.

0
Aalisha

Hi!
Today I changed the polygon values, so now the cars should be rectangles.
Then I tried adding the collision detection. It accurately measures the shortest distance between the necessary points/lines. The collision detection partially works, since you can turn even if you are colliding. I tried adjusting the values and changing the code to include it, but then the collision detection didn’t work at all. I will try fixing it tomorrow.

0
Aalisha

Hello!
Now I added a polygon (almost rectangle) instead of the circle for the car. On Car1 (red) the green circle marks the turning axis. Finding the coordinates for the car’s corners took longer, as it involved sin() and cos() and I haven’t used them much till now.
I also adjusted the car controls a bit, like now there’s a speed limit (positive and negative). The turn degrees is proportional to the car speed, so now the car can’t rotate when it isn’t moving.
Since Car1 is done for now, I added Car2.

Problems:
Since the turning axis is towards the back, the front of the car can still leave the boundaries. I will fix it when adding collision detection. That would also solve the problem of the cars colliding each other.

Attachment
0
Aalisha

Hello!
Today I created the PyGame window and added Car1. The green circle shows the direction the car is pointing in (since the car is currently a circle).
With the left and right arrow, you can change the angle. sin() and cos() are used to move the car with a specific speed and a given angle.
When the up or down arrow is pressed, the speed increases or decreases (you can also go backwards). If neither is pressed, the car slows down, till it eventually stops.

0