Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / my first 2d pong - (help)

Author
Message
Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 9th Dec 2006 01:11
Hey guys,
Okay so iv been designing a 2d pong (my first real game, I havent been following a tutorial because i basically have a grip on the commands and such except i have a problem getting the paddles to move!
Iv just run a test.
To see the issue hit "1 player" then hit the up key and youll see what happens, it just jets up the screen.
If anyone can think of a way to slow it down thatd be awesome.

Heres my current code:



PS. I thank Xenocythe for the menu

Opposites are different, not wrong
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 9th Dec 2006 02:30
This code is your problem:


"and" is a boolean operation, so you're confusing the compiler. The solution is to break up each command onto a separate line.



CHESS ENCOUNTER
Demo
WIP
Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 9th Dec 2006 05:38
YAY!
Thank you so much!!

Opposites are different, not wrong
Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 9th Dec 2006 06:35 Edited at: 9th Dec 2006 06:36
Okay i have made some progress on the program.
But I have yet another issue.

For some reason the ball isnt coliding with the top or bottum of the table it just goes right through!

This is the code



Thanks in advance,
-inverted

Opposites are different, not wrong
Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 10th Dec 2006 00:30
Anybody?

Opposites are different, not wrong
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Dec 2006 03:53 Edited at: 10th Dec 2006 03:54
Variables which have the # symbol on the end like your ballx# are floating point variables and hold values like 3.142 and 12.66.

Screen positions using the X and Y co-ordinates can only be whole numbers so you should use integer variables - like Ballx.

The use of newxvalue is overkill for moving a ball in 2D - all you need to do is simply add a value to both the X and Y screen position and then check to see if the Y value is less than 0 or greater than the screen height. (You can adjust these values depending on the size of the ball).

You are trying to add fractions of a pixel to the ball's position when the smallest element of the screen is a full pixel.

Just rewrite it using integers and get rid of the newxvalue function - which is more useful when used with 3D.

TDK_Man

Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 10th Dec 2006 04:00
Instead of using the ball angle and newxvalue and newyvalue functions, I would make a separate variable for the x velocity and for the y velocity.



CHESS ENCOUNTER
Demo
WIP
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Dec 2006 04:33
Which is what I said!

But he still needs to get rid of those float variables...



TDK_Man

Inverted
18
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 10th Dec 2006 06:54
Wow thanks guys!
I appriciate your help so much!

Opposites are different, not wrong

Login to post a reply

Server time is: 2024-11-27 01:46:33
Your offset time is: 2024-11-27 01:46:33