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 / Help With My Pong Game

Author
Message
Meltabomb
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location:
Posted: 5th Mar 2005 02:32
I need help with scoring/wining the game.

I want the game to say something like player1 wins or player 2 wins or something like that when the score gets to 20.

then i need to b able to choose if i want to cont playing, like press space for yes, esc for no.

and is there a way for the game to wait like 3 sec to respawn the ball?

or at least make the paddles respawn in line with the ball?

here is my code so far
Meltabomb
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location:
Posted: 5th Mar 2005 06:25
Rem Hide Mouse And Set Sync Rate to 40
hide mouse:sync rate 40
rem Make Paddles, Ball And Floor
make object box 1,1,1,3:color object 1,rgb(255,0,0)
make object box 2,1,1,3:color object 2,rgb(0,255,0)
make object sphere 3,1:color object 3,rgb(0,0,50)
make object box 4,10,0.1,10:position object 4,0,-0.55,0
load image "jeans01.bmp",1
load image "iron01.bmp",2

texture object 4,1
texture object 3,2
rem set ball angle to 90 degrees
balla#=90
rem Start the main loop
sync on:do
rem Scoring
if ballx#>6 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=270
if ballx#<-6 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=90
set cursor 300,50:print player1score#
set cursor 320,50:print "-"
set cursor 340,50:print player2score#
rem Ball Movement
ballx#=newxvalue(ballx#,balla#,0.4):ballz#=newzvalue(ballz#,balla#,0.3)
rem Player 1 paddle movement
IF upkey()=1 and player1pos#<3.5 then player1pos#=player1pos#+0.3
IF downkey()=1 and player1pos#>-3.5 then player1pos#=player1pos#-0.3
if upkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#+8
if downkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#-8
rem player 2 paddle movement
IF keystate(17)=1 and player2pos#<3.5 then player2pos#=player2pos#+0.3
IF keystate(31)=1 and player2pos#>-3.5 then player2pos#=player2pos#-0.3
if keystate(17)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#+8
if keystate(31)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#-8
rem Ball Bouncing
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#
balla#=wrapvalue(balla#)
rem Position Objects
position object 1,5,0,player1pos#:position object 2,-5,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
position camera 0,10,-10:point camera 0,0,0
sync:loop
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Mar 2005 06:29 Edited at: 5th Mar 2005 06:29
Use the code tags to add code - the source button doesn't work.

The solutions to your problems would go along the lines of:




Meltabomb
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location:
Posted: 5th Mar 2005 07:18
i think it will work but i not sure where 2 put that code, everywhere i try it i get a ton of lag
Meltabomb
19
Years of Service
User Offline
Joined: 1st Mar 2005
Location:
Posted: 5th Mar 2005 07:28
also the screen just flashes the text over and over each time the lag stops. here is what i changed the code 2.


btw, how do you use code tags to ad ur code?

if player1_score=20
text 0,0,"You Win"
gosub restart
endif
restart:
text 0,20,"Play again?"
sync
wait key
score=0
position object 1,5,0,player1pos#:position object 2,-5,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
return

Login to post a reply

Server time is: 2024-09-23 13:28:09
Your offset time is: 2024-09-23 13:28:09