[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] a bit #ot: design for a game board supporting user facing different directions?



Hi all,
I apologize that this might be off topic, but I am hoping someone can
offer advice. I am writing an audio game, for which I cannot
(unfortunately) use Python. However, I am running into a very
perplexing problem while trying to figure out how to design the
interaction between movable objects, such as the player or a vehicle,
and the map. Here is part of my design so far:

Map: made of Squares, a map is nothing more than a grid. The user
moves around the grid with the arrow keys. If facing north (0
degrees), the up arrow takes the user one step forward. Starting at
(0, 0) and stepping forward facing north, the user will be at (0, 1).

User: subclassing Object, this is an Object that can move and turn in
place. Movement forward is defined as 1 meter, so each step is 1 meter
long. Taking two steps facing north on a map with 1-meter Squares, the
user is at (0, 2).

Square: Maps are made of these. Each square has an (x, y) position, a
terrain type, and so on. A square is defined with a certain size,
defaulting to 1 meter on a side.

Here is my problem. What happens if the user turns to 45 degrees and
takes a step? He moves 1 meter, of course, but his position is then a
pair of floats. Floats aren't a problem since I can just trunkate them
to find which grid Square on the map he is in, but how will the math
work? 45 degrees is easy with the above settings, since it is just
sqrt(1~2+1~2), then add that to both x and y. What about 30 degrees,
or 5, or 250? Is there a trig function or something to find this, or
am I going about this whole thing the wrong way? Any advice would be
great! Thanks in advance.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap