forums

TNT Basic Forums > Game-In-60 Tutorials Q&A
Bad pong code!
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-14-2006 18:40

Posted by:
Gustav

Location:
Lund, Sweden

Click Here to Email Gustav   Find more posts by Gustav

I've found bad code in the pong tutorial.
Check this out:
input=poll input (1) ' get player 1 input
player1y=player1y+input/20
if player1y<0 then player1y=0
if player1y>430 then player1y=430

input=poll input (2) ' get player 2 input
player2y=player2y+input/20
if player2y<0 then player2y=0
if player2y>430 then player2y=430

This is all wrong and inverted!
It should be:

input=poll input (1)
player1y=player1y-input/20 MINUS NOT PLUS
if player1y<0 then player1y=0
if player1y>430 then player1y=430

input=poll input (2)
player2y=player2y-input/20 HERE TOO
if player2y<0 then player2y=0
if player2y>430 then player2y=430

You have to really check that the inputs are called 1 and two, if not change the numbers in the poll input command.

02-11-2006 19:09

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Sorry Gustav...

...but the code was right. You 'add' the result of poll input (not subtract it) and if you look at this extract from the input tutorial you'll see why:

quote:
For a y axis it returns in the range:
-100 = Maximum Up
0 = Middle
100 = Maximum Down


If you subtract 100 (Maximum Down) from the Y value it will decrease, making the image go up.

Danny (nods)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.