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 / Pong paddle not working when i compile.

Author
Message
michael_one
13
Years of Service
User Offline
Joined: 24th Dec 2010
Location:
Posted: 6th Mar 2012 01:37
rem Simple Pong game

rem Make some variables
ballx as integer = 320
bally as integer = 240
speedx as integer = -2
speedy as integer = 1
px1 as integer = 600
py1 as integer = 240
px2 as integer = 20
py2 as integer = 240
score1 as integer = 0
score2 as integer = 0

rem Slow down the game.
sync on
sync rate 40

rem The game runs in a loop.
do
cls

rem check shift/ctrl keys to move the left paddle
if shiftkey()
dec py2,2
if py2<0 then py2 = 0
endif

if controlkey()
inc py2,2
if py2 > 470 then py2 = 470
endif

rem Check up/down keys to move the right paddle
if upkey()
dec py1, 2
if py1<0 then py1 =0
endif

if downkey()
inc py1, 2
if py1 > 470 then py1 = 670
endif

rem Move the ball
inc ballx, speedx
inc bally, speedy

rem Bounce the ball off top/bottom of the screen
if bally < 0 or bally > 470 then speedy = speedy *-1

rem See if left player missed the ball
rem If so, player 2 scores, reset the ball
if ballx < 0
inc score2, 1
ballx = 320
bally = 240
speedx = 2
sleep 500
endif

rem See if right player missed the ball
rem If so, player 1 scores, reset the ball
if ballx > 630
inc score1, 1
ballx = 320
bally = 240
speedx = -2
sleep 500
endif

rem Draw the ball
circle ballx, bally, 10

rem Draw the paddles
box px1, py1, py1+10, py1+10
box px2, py2, py2+16, py2+64

rem Lets see if the ball has hit a paddle
if point(ballx+5, bally+5) >0
speedx = speedx *-1
endif

rem Print the scores
text 0, 0, "SCORE" + str$(score1)
text 550, 0, "SCORE" + str$(score2)

rem Draw the screen
sync

loop
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 6th Mar 2012 06:03 Edited at: 6th Mar 2012 06:12
point is a "picky" command as results may vary. see HERE for the similar issue, with solution a few posts down.

btw, use code tags when posting that amount of code. ie:

[code ] <-- minus the space
...
enter code here
...
[/code ] <-- minus the space

produces:


Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 6th Mar 2012 06:40
Your request is not very specific. I'm not sure if you having trouble with it actually running or if the code has errors in it. It compiled fine for me, and looking through, there were some things wrong.

I would figure out other ways to check for a collision other than using the POINT command - it is terribly slow.

In drawing the first paddle, you had this 'box px1, py1, py1+10, py1+10', which should have been 'box px1,py1,px1+10,py1+10' However, this produces a paddle that is much smaller than the other one, which seems odd.

Anyway, I re-did the code so it at least works, and I sized the paddles the same. Here you go:



Please notice that I indented your code for you, to make it more readable. I would suggest you do this on all of your code. Also, as you get further along, you might want to consider using sprites for the ball and paddles.

So many games to code.......so little time.

Login to post a reply

Server time is: 2024-11-23 20:42:03
Your offset time is: 2024-11-23 20:42:03