Posted: 7th Oct 2009 09:04
I having troubles adding a background to my pong demo. Everything was working until I added the image and the paste image 1, 0, 0 and sync commands in the game loop.
Rem ***** Included Source File *****
REM September 06, 2009
Rem ***** Main Source File *****
rem make some variables
ballx as integer = 320
bally as integer = 240
speedx as integer = -2
speedy as integer = 1
px1 as integer = 600
pyl 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 60
backdrop on
color backdrop 1
hide mouse
load image "background.png", 1
rem the game runs in as loop
do
paste image 1, 0, 0
sync
cls
rem chec shift/ctrl keys to move the left paddle
if shiftkey()
dec py2, 3.5
if py2 < 30 then py2 = 30
endif
if controlkey()
inc py2, 3.5
if py2 > 410 then py2 = 410
endif
rem check up/down to move the right paddle
if upkey()
dec py1, 3.5
if py1 < 30 then py1 = 30
endif
if downkey()
inc py1, 3.5
if py1 > 410 then py1 = 410
endif
rem move the ball
inc ballx, speedx
inc bally, speedy
rem bounce ball off the top/bottom of the screen
if bally < 0 or bally > 470 then speedy = speedy* -1.5
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 700
endif
rem see if left 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 700
endif
rem draw the ball
circle ballx, bally, 10
rem draw the paddles
box px1, py1, px1+16, py1+64, RGB(255,0,0), RGB(255,0,0), RGB(255,0,0), RGB(255,0,0)
box px2, py2, px2+16, py2+64, RGB(0,75,192), RGB(0,75,192), RGB(0,75,192), RGB(0,75,192)
rem collision detection
if point(ballx+5,bally+5) > 0
speedx = speedx* -1
endif
rem print the score
text 10, 10, "Player 1 SCORE: " + str$(score1)
text 498, 10, "Player 2 SCORE: " + str$(score2)
rem draw the screen
sync
loop