Hey everyone
Why do i get this error: you can only increment variables.
runing this program?
it runs fine for a while, but then that error sows up
And can some one sow me some examples on how to animate a sprite?
or maby link me to some tuts on the subject? i tryed searching the forums but dident find anything on it. hmmm
and i would also be thank full for some suggestions on how to make better ball/bat conditions
here is the code, media included in download
remstart
-------------------------------------------------------------------
program name:Sprite Break Out test
-------------------------------------------------------------------
written by:Mika J Olaussen << Coder#0.5 >>
date:01-22-06
-------------------------------------------------------------------
comments:first game using 2d sprites
-------------------------------------------------------------------
remend
REM Initialze program
sync on: sync rate 60: set display mode 800,600,16: set window on: randomize timer()
REM load images
load image "sprites\bat1.bmp",1
load image "sprites\sball.bmp",2
load image "sprites\redBrik.bmp",3
REM Global variables
DIM x(1)
DIM ballx(10)
DIM bally(10)
DIM bspeedx(10)
DIM bspeedy(10)
DIM ballspeed(10)
DIM newbx(10)
DIM newby(10)
DIM bwidth(10)
DIM bheight(10)
DIM ballx(10)
DIM bally(10)
DIM bh(10)
DIM bw(10)
REM bat variables
bat=1
speed= 10
newx= 300
newy= 550
REM ball variables
balls= 1 +9 :rem +x (x= number of bals
serve= 1
REM initialze ballz
for num= 2 to balls
ballx(num)= newx
bally(num)= 500
bspeedx(num)= rnd(9)+1
bspeedy(num)= rnd(9)+1
newbx(num)= ballx(num) + bspeedx(num)
newby(num)= bally(num) + bspeedy(num)
next num
REM brik variables
rem make sprites
gosub make_sprites
REM In Game Loop
DO
cls
`""""""""""""""""""""""""""""""""""""
REM move bat
gosub Move_bat
REM move ball(s)
gosub Move_ball
REM serve loop
if serve=1 then gosub serve_loop
`____________________________________
sync
LOOP
REM Functions And Subroutines
REM #########################
REM plase briks routine
REM make sprites routine
make_sprites:
sprite 1,newx,newym1,1
for b= 2 to balls
sprite b,newx,newy+10,2
next b
return
REM serve loop
serve_loop:
for b= 2 to balls:if serve=1 then sprite b,batx,baty-50,2:if spacekey()=1 then serve=0
if serve=0 then newbx(b)= batx
next b:return
REM routine for moving bat, bat conditions etc.
Move_bat:
REM move bat (bat size= 148)
rem store sprite x and y positions in batx and baty
baty=sprite y(1):batx=sprite x(1)
if leftkey()=1 then x(bat)= x(bat)-speed
if rightkey()=1 then x(bat)= x(bat)+speed
rem bat collision with screen border (800*600)
if x(bat)> 800-148 then x(bat)= 800-148
if x(bat)< 0 then x(bat)= 0
batx= x(bat)
baty= newy
REM draw bat at new position
sprite 1,batx,baty,1
RETURN
REM routine for moving balls, ball conditions and "physics" etc.
Move_ball:
for ball= 2 to balls
REM move ball
newbx(ball)= newbx(ball)+bspeedx(ball)
newby(ball)= newby(ball)+bspeedy(ball)
REM store height and width in bh() and bw()
bh(ball)= sprite height(ball)
bw(ball)= sprite width(ball)
REM store ball x and y in ballx() and bally()
ballx(ball)= sprite x(ball)
bally(ball)= sprite y(ball)
REM ball collison with screen border (800*600)
if newby(ball)<= 0+bh(ball) then bspeedy(ball)= bspeedy(ball)+5
if newbx(ball)<= 0+bw(ball) then bspeedx(ball)= +2
if newbx(ball)>= 800 then bspeedx(ball)= -2
REM ball collision with player bat
rem store bat left position in lbatx
lbatx= sprite x(1)
rem store bat right position in rbatx
rbatx= sprite x(1)+148
rem bounce ball of bat if ball is between lbatx and rbatx
if ballx(ball)> lbatx and ballx(ball)+10< lbatx+50 and bally(ball)> baty-20 and bally(ball)< 600
bspeedy(ball)= bspeedy(ball)-5
bspeedx(ball)= bspeedx(ball)-5
hitbat= 1
endif
if ballx(ball)> lbatx+50 and ballx(ball)+10< lbatx+100 and bally(ball)> baty-20 and bally(ball)< 600
bspeedy(ball)= bspeedy(ball)-5
bspeedx(ball)= 0
hitbat=1
endif
if ballx(ball)> lbat+100 and ballx(ball)+10< rbatx and bally(ball)> baty-20 and bally(ball)< 600
bspeedy(ball)= bspeedy(ball)-5
bspeedx(ball)= bspeedx(ball)+3
hitbat=1
endif
if hitbat=1 and leftkey()=1
xl=xl+1
bspeedy(ball)= bspeedy(ball)-5
bspeedx(ball)= bspeedx(ball)-3
endif
if hitbat=1 and rightkey()=1
xr=xr+1
bspeedy(ball)= bspeedy(ball)-5
bspeedx(ball)= bspeedx(ball)+3
if x> 10 then dec x,1
endif
hitbat= 0
xl=0
xr=0
REM make sure ball(s) dosent get to fast
if bspeedy(ball)>10 then bspeedy(ball)= 10
if bspeedy(ball)<-10 then bspeedy(ball)= -10
if bspeedx(ball)>10 then bspeedx(ball= 10
if bspeedx(ball)<-10 then inc bspeedx(ball)= -10
REM draw ball(s) at new position
sprite ball,newbx(ball),newby(ball),2
REM some text info
text 10,10,"left bat: "+str$(lbatx)
text 10,30,"right bat: "+str$(rbatx)
text 10,60,"ballx: "+str$(ballx(ball))
text 10,80,"bally: "+str$(bally(ball))
text 10,100,"baty: "+str$(baty)
text 10,140,"offx: "+str$(offx)
text 10,160,"offy: "+str$(offy)
next ball
return
well goodnight from denmark
hope some one can help me out a bit.
Not that much a noob, but still a noob