ok, first thing. instead of:
for a = 1 to 154
load object "media\gem.dbo", a
next a
try:
load object "media\gem.dbo",1
for a = 2 to 154
clone object a,1
next a
saves you (and our already-overworked hard drives) 153 loads
next, you shouldn't ever need to create more gem objects than can be visible at any one time. period. more on this later...
re: a reference system for this, an array is perfect here; you've already got tank(x,y) going so you're on the right track. take a look at this little "gem swapper" i wrote especially for you (and me, since i think it's the easiest way i could explain it).
pay attention to the
_checkgems: routine at the very end where the array coordinates are derived from the object x & z values.
Rem Project: gem swapper by virtual nomad
Rem Created: 1/18/2010 9:43:40 PM
sw = desktop width() : sh = desktop height()
set display mode sw, sh, 32, 1
autocam off : randomize timer()
sync on : sync rate 0
rem define colors
red = rgb(255,0,0)
green = rgb(0,255,0)
blue = rgb(0,0,255)
rem define grid
xsize = 10
ysize = 10
size# = 50.0
dim board(xsize,ysize)
dim temp(1,1)
gosub _initialize:
position camera 275.0,500.0,275.0
point camera 275.0,0.0,275.0
do
mx = mousex() : my = mousey()
if mouseclick() = 1 and lastpick + 100 < timer()
if pickgem1 = 0
pickgem1 = pick object (mx, my, 1,100)
else
pickgem2 = pick object (mx, my, 1,100)
if pickgem2 = pickgem1 or pickgem2 = 0
rem deselect gems
pickgem1 = 0
pickgem2 = 0
else
if pickgem1 > 0 and pickgem2 > 0
gosub _checkgems:
endif
endif
endif
lastpick = timer()
endif
if mouseclick() = 2 and lastshuffle + 100 < timer()
gosub _initialize:
endif
set cursor 0,0
print "LMB = Pick Gem"
print "RMB = Shuffle Gems"
print
print "gem1: ",pickgem1
print "gem2: ",pickgem2
center text sw/2,10,"Gem Swapper by Virtual Nomad"
if messagetimer + 3000 > timer()
center text sw/2,30,message$
endif
sync
loop
_initialize:
rem make cubes & initialize board array
gemsize# = 40.0
thisgem = 0
for x = 1 to xsize
for y = 1 to ysize
thisgem = thisgem + 1
if object exist(thisgem) = 0
make object cube thisgem, gemsize#
endif
thiscolor = rnd(2) + 1
if thiscolor = 1
board(x,y) = red
color object thisgem, red
else
if thiscolor = 2
board(x,y) = green
color object thisgem, green
else
board(x,y) = blue
color object thisgem, blue
endif
endif
position object thisgem, (x*size#), 0.0, (y*size#)
next y
next x
message$ = "New Game!"
messagetimer = timer()
lastshuffle = timer()
return `end initialize
_checkgems:
rem get array indices
x1 = object position x(pickgem1)/size#
y1 = object position z(pickgem1)/size#
x2 = object position x(pickgem2)/size#
y2 = object position z(pickgem2)/size#
index1$ = str$(x1)+","+str$(y1)
index2$ = str$(x2)+","+str$(y2)
message$ = index1$ + " <-> " + index2$
messagetimer = timer()
rem swap gem colors using colors stored in array
temp = board(x1,y1)
board(x1,y1) = board(x2,y2)
board(x2,y2) = temp
color object pickgem1, board(x1,y1)
color object pickgem2, board(x2,y2)
pickgem1 = 0
pickgem2 = 0
return
ok, back:
to finish on the reference system, i'm using the board() array to hold colors. you can add whatever you want here, of course. ie, texture numbers or other object settings with minimal difficulty. when objects occupy those grid-spaces, you can reference the array and apply whatever settings are held there to the new object.
also, note, my objects never move. they simple re-color themselves giving the illusion that they've swapped places. again, not sure how your game is gonna play out but judging from the movegems() function in your code (and
your other thread), you intend to literally swap x/y/z positions. as you can see, if you set the objects with the new settings based on the array, you won't have to. alas, if you
still want to re-position the objects, the "swap colors" part in the gem swapper can be modified to suit your needs. changing the existing code in your movegems() function:
position object gem1, gem2x, gem2y, gem2z
position object gem2, gem1x, gem1y, gem1z
to
tempx = gem1x : tempy = gem1y : tempz = gem1z
position object gem1, gem2x, gem2y, gem2z
position object gem2, tempx, tempy, tempz
...should work (but, you should get used to using floats instead of integers for 3d stuff).
as for the notion of creating "several hundred thousand" objects, forget it
again, you shouldn't need more than can be visible at any one time. assuming your game will be "removing" matching gems from the board and then introducing new gems at some point, why not re-use those objects, placing them wherever you want and re-"skinning" them as "new" gems, or moving them off the screen and hiding them until they're needed again? keep track of unused gem objects by using an array like FreeGems() that you would fill with hidden/"removed" object numbers and draw from as needed. ie, if a gem is remove from play, move and hide it from vision and add its object number to FreeGems(). say 3 seconds later you want a new gem to "spawn", pull one from FreeGems(), show it, place and set it up however you want.
anyway, enough from me. i hope this helps
Virtual Nomad @ California, USA
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit