Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 1st, 2006, 3:09 PM   #1
al1986
Newbie
 
Join Date: Feb 2005
Posts: 24
Rep Power: 0 al1986 is on a distinguished road
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!
al1986 is offline   Reply With Quote
Old Aug 1st, 2006, 5:08 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
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.
Sane is offline   Reply With Quote
Old Aug 1st, 2006, 5:58 PM   #3
al1986
Newbie
 
Join Date: Feb 2005
Posts: 24
Rep Power: 0 al1986 is on a distinguished road
thanks for the help, i'll give what you suggested a try
al1986 is offline   Reply With Quote
Old Aug 1st, 2006, 6:31 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
I apolagize, I forgot about one of the most important parts. The rotation.



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.
Sane is offline   Reply With Quote
Old Aug 2nd, 2006, 2:51 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to setup an anti-cheat system for a game friend and I are creating Dr.Backtick` C++ 14 Feb 15th, 2006 11:12 PM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 7:25 PM
a simple 2d game, faster in pygame or pyopengl? cypherkronis Python 1 Jun 30th, 2005 7:57 PM
Programmers Needed! Online Game troy_eisert C++ 2 Jan 29th, 2005 12:51 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:18 PM.

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