Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   pygame half-pipe game (http://www.programmingforums.org/showthread.php?t=10910)

al1986 Aug 1st, 2006 3:09 PM

pygame half-pipe game
 
hey,

i'd like to make a simple 2D half-pipe game using pygame. this is what inspired me: http://www.gmaxskateboarding.com/game.asp

however, i'm not sure about the maths involved in coding this kind of game. i'll need to make the skater move along the half-pipe, rotating him accordingly so he appears to stay in an upright position.

i'd appreciate it if anyone could point me in the right direction. i'm aware of the pygame.transform.rotate method, as well as pygame.draw.arc (could maybe use to draw the half-pipe?)

oh, and i tried to read up on bezier curves but it just went over my head!

Sane Aug 1st, 2006 5:08 PM

Start by making a function that will convert a given x position (1 dimension), in to a x, y tuple (2 dimensions) by placing it on a parabolic curve.

The pipe will have the same equation as the parabolic curve, and it will be represented by an image (you're limiting yourself by using functions like pygame.draw.arc).

Then try displaying the skater on the pipe in various locations by using your 1-2 dimension converting function.

Then manipulate the x position in a periodic function after reading up on some physics.

Add user input which will vary the dependants that the physics calculations use.

That would probably be the order in which I would do this. Although other people would do it differently. Everyone has their own way which works for them. Good luck.

al1986 Aug 1st, 2006 5:58 PM

thanks for the help, i'll give what you suggested a try :)

Sane Aug 1st, 2006 6:31 PM

I apolagize, I forgot about one of the most important parts. The rotation.

http://img466.imageshack.us/img466/2674/pipedz0.jpg

The red circle is the skater. The blue lines are the tangents/x axis. The green is the determined angle of rotation.

The tangent is calculated by solving for the immediate slope. I won't bother going over this, because noting your age, you would have already.

Then the angle of rotation is solved with trigonometry, by drawing a triangle with the x axis as shown in the picture (I left out the opposite side to avoid messiness, plus it is not needed).

This may not be the fastest way to calculate it, mind you. Also, it may be a good idea to pre-determine all the values that this function can output, by a set integer interval. That will reduce the redundancy of calculating the angle every time the skater passes each similar point.

Arevos Aug 2nd, 2006 2:51 AM

You could also treat the half-pipe as a mathematical curve. Differentiate the curve to find the tangent, find the perpendicular, and use trigonometry to find the corresponding angle to rotate it by.


All times are GMT -5. The time now is 8:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC