Not a flame - just a few tips to help you on your way...
Your code could be made a fair bit easier to read - so others can follow it better. For example:
if ballx > 10
if ballx < 780
ballx=ballx+speedx
bally=bally+speedy
endif
endif
is easier to follow if you use:
if ballx > 10 And ballx < 780
Inc ballx,speedx
Inc bally,speedy
endif
CLS rgb(0,0,0)
can be changed to:
CLS 0
because the RGB() function involves a calculation which in this case isn't needed.
Indent!
Indent all your code if you intend to post on the forums. It takes time for people to study your code and find out where you can improve things. Making your code easier to follow improves the chances of getting a response.
Subroutines and functions when not indented tend to blend into the code and makes it look more complicated than it actually is. This may put people off helping.
I pasted your code into my IDE and told it to auto-indent it. Take a look at the difference it makes...
REM Project: Pong
REM Created: 23/12/2006 19:04:16
REM
REM ***** Main Source File *****
REM
sync on
sync rate 60
hide mouse
set display mode 800,600,16
cls rgb(255,255,255)
rem set up my game
gosub setupgame
rem make player and enemy
gosub makeplayers
do
gosub collisions
gosub moveplayers
gosub makeplayground
sync
loop
makeplayers:
rem make player1 and enemy
set current bitmap 1
rem make screen black with yellow ink
cls rgb(0,0,0)
ink rgb(255,255,0),0
rem yellow box player
box 2,2,spritewidth,spriteheight
rem nab player
get image 1,0,0,spritewidth+2,spriteheight+2
rem make screen black whith green ink
cls rgb(0,0,0)
ink rgb(0,255,0),0
rem enemy box
box 2,2,enemywidth,enemyheight
rem nab the enemy
get image 2,0,0,enemywidth+2,enemyheight+2
rem make ball
cls rgb(255,255,255)
ink rgb(0,0,0),0
rem ball
circle ballwidth,ballheight,5
rem nab it
get image 3,5.5,5.5,ballwidth+6.5,ballheight+6.5
rem hide
set current bitmap 0
return
moveplayers:
rem make player1 sprite
sprite 1,spriteposx,spriteposy,1
Set Sprite 1,1,0
rem make enemy sprite
sprite 2,enemyposx,enemyposy,2
set sprite 2,1,0
rem make ball sprite
sprite 3,ballx,bally,3
set sprite 3,1,0
rem move player1
if upkey()=1 then spriteposy=spriteposy-10 : enemyposy=enemyposy+10
if downkey()=1 then spriteposy=spriteposy+10 : enemyposy=enemyposy-10
return
collisions:
rem only move if somone hasnt scored
if ballx > 10
if ballx < 780
ballx=ballx+speedx
bally=bally+speedy
endif
endif
rem collision off bats
if sprite exist(1)=1
if sprite collision(3,1)=1
speedx=rnd(speedx)+7
endif
endif
if sprite exist(2)
if sprite collision(3,2)=1
speedx=rnd(speedx)-7
endif
endif
rem collision faster if moving
if sprite exist(1)=1
if sprite collision(3,1)=1
if upkey()=1 or downkey()=1
rotate sprite 3,sprite angle(3)+rnd(45)
endif
endif
endif
if sprite exist(2)=1
if sprite collision(3,2)=1
if downkey()=1 or upkey()=1
rotate sprite 3,sprite angle(3)+rnd(45)
endif
endif
endif
rem not allowed to move past bottom
if spriteposy > 489
spriteposy = 489
endif
rem not allowed to move past top
if spriteposy < 40
spriteposy = 40
endif
rem same for enemy bottom
if enemyposy > 489
enemyposy = 489
endif
rem same for enemy top
if enemyposy < 40
enemyposy = 40
endif
rem same for ball
if bally+speedy < 40 then speedy=speedy+7
if bally+speedy > 560 then speedy=speedy-7
return
makeplayground:
line 0,560,800,560
line 0,40,800,40
return
setupgame:
rem create hidden bitmap to draw to
Create Bitmap 1,320,200
rem setup variables
spritewidth=15
spriteheight=70
spriteposx=40
spriteposy=300-35
enemyposx=750
enemyposy=300-35
enemywidth=15
enemyheight=70
ballx=400
bally=300
ballwidth=10
ballheight=10
speedx=-7
speedy=-1
return
Collision:
Rather than check for every specific sprite collision, try just checking only the ball with 0 as the second sprite number. For example, if the ball is sprite 1 then the command:
BallHit = Sprite Collision(1,0)
...will return the number of any other sprite the ball collides with. You therefore only have to do one collision check and decide what to do next based on the sprite number returned.
Set Current Bitmap:
This is only required if the current bitmap is not the one you want to write to.
If you use Create Bitmap 1,320,200 then that command
automatically sets the current bitmap to 1, You therefore only need to use
Set Current Bitmap 0 when you want to switch from bitmap 1 (the hidden screen) to bitmap 0 (the screen the user sees).
At which point you should use
Delete Bitmap 1 if you aren't going to use it again.
Note: If you delete a bitmap, it doesn't delete any images you have previously grabbed from it.
TDK_Man