here is a sprite example JSG
read each part for an idea how to set this up.
this example is using arrays to manage things.
you could use typed arrays as well for a more effecient way to manage multiple objects.
rem --------------------------------------------------------------------
rem Sprite and 3D example
rem using arrays instead of typed arrays for compatability DBC/DBP
rem indi
rem april 6 2007
rem --------------------------------------------------------------------
REM BASIC GAME SETUP
sync rate 60 : sync on : randomize timer()
set text font "verdana" : set text size 24 :ink rgb(255,255,255),1
REM MAKE BGD CUBE
make object cube 1,25
position object 1,0,0,0
REM PRECALC SINEWAVE into an array : Usage is tSin#(var)
Dim tSin#(360) : For i = 0 To 360 : tSin#(i) = Sin(i) : Next i
REM PLAYER ARRAYS FOR X AND Y
dim plr1x(1) : dim plr1y(1)
REM PLAYER START LOCATION
plr1_start_pos_x = 10 : plr1_start_pos_y = 10
REM FILL PLAYER ARRAYS WITH DATA
plr1x(1) = plr1_start_pos_x : plr1y(1) = plr1_start_pos_y
REM CREATE AN ARRAY TO STORE THE OLD LOCATION WHEN COLLISION OCCURS
dim oldplr1x(1) : dim oldplr1y(1)
REM FILL OLD PLAYER LOCATION ARRAYS WITH DATA
oldplr1x(1) = plr1_start_pos_x : oldplr1y(1) = plr1_start_pos_y
REM CREATE A PLAYER LIVES ARRAY AND FILL IT
dim plr1lives(1) : plr1lives(1) = 5
REM CREATE AN ENEMY ARRAY
dim enemyx(6) : dim enemyy(6)
REM TEMP PLAYER COLOUR
cls
ink rgb(rnd(255),rnd(255),rnd(255)),1 : box 0,0,16,16
get image 1,0,0,16,16
cls
REM TEMP ENEMY COLOURS
for i = 2 to 6
ink rgb(rnd(255),rnd(255),rnd(255)),1 : box 0,0,16,16
get image i,0,0,16,16
next i
cls
REM PLACE ENEMIES FROM ARRAY DATA
for i = 2 to 6
enemyx(i) = i * 50
enemyy(i) = i * 50
sprite i,enemyx(i),enemyy(i),i
next i
REM PRE MAIN
position camera 0,50,-50
point camera 0,0,0
REM MAIN LOOP START
disable escapekey : while escapekey()=0
r = wrapvalue(r+1)
rotate object 1,r,r,r
REM CONTROL PLAYER
if upkey()=1 then plr1y(1) = plr1y(1)-3
if downkey()=1 then plr1y(1) = plr1y(1)+3
if leftkey()=1 then plr1x(1) = plr1x(1)-3
if rightkey()=1 then plr1x(1) = plr1x(1)+3
REM UPDATE PLAYERS POSITION
sprite 1,plr1x(1),plr1y(1),1
REM UPDATE MOVING ENEMY Number 6
h = h + 1
h = wrapvalue(h)
v = v + 4
v = wrapvalue(v)
enemyx(6) = int(tSin#(h)*-145) + 320
enemyy(6) = int(tSin#(v)*-145) + 240
sprite 6,enemyx(6),enemyy(6),6
REM CHECK PLAYERS COLLISION FOR ALL ENEMYS
REM CHANGE LIVES AND END GAME IF LIVES = 0
if sprite hit(1,0)>0
if sprite collision(1,0)>0
plr1x(1) = oldplr1x(1)
plr1y(1) = oldplr1y(1)
plr1lives(1) = plr1lives(1) - 1
if plr1lives(1) = 0
cls
REM GAME OVER
end
endif
text 100,10," plr1 lives :" + STR$(plr1lives(1))
sprite 1,plr1x(1),plr1y(1),1
endif
endif
REM UPDATE THE SCREEN EACH LOOP WITH TEXT
text 1,1,"Fps:" + STR$(screen fps())
text 1,30,"Lives :" + STR$(plr1lives(1))
REM END MAIN LOOP
sync : endwhile
REM END
end