Hi,

i'm trying to write a car game and i have decided to start by the movement
part. I calculate the X and Y components of the car and update his position
by increasing the current one with the two new components. The two
components depend of the orientation of the car, managed by the right and
left arrow :


speedx = math.sin(self.angle * (math.pi/180)) * SPEED
> speedy = math.cos(self.angle * (math.pi/180)) * SPEED * -1
>

Where SPEED is a constant and self.angle a int representing the orientation.
I don't know if this is the best way because, the car speed depends of his
orientation. Increasing the self.angle value will increase the components,
this is not suitable for a car game i think.

I have another problem with the car movement. Each time the orientation
change, i would like to rotate the car in the right direction. I thought to
do something like that :

a_rad = math.asin(speedx/SPEED)
> a_deg = math.degrees(a_rad)

self.sprite = pygame.transform.rotate(self.original, a_deg * -1)
> self.rect = self.sprite.get_rect(center = self.rect.center)
>

It does not work properly, this way, my car can't rotate over 90° because of
the speedx values.

Here is my code :

http://pastebin.com/VJgQRtYq

and the sprite i use for the car is joined.

Thanks for reading me.

<<attachment: car.png>>

Reply via email to