Here is the solution:
Rem Project: Dark Basic Pro Project
Rem Created: Sunday, February 24, 2013
Rem ***** Main Source File *****
set display mode 1024, 768, 32
#CONSTANT OBJSIZE = 64
tick as dword = timer()
lastTick as dword
type thing
acceleration as float
x as integer
y as float
gem as integer
color as dword
still as integer
neighboor as integer
endtype
dim gems(0) as thing
`Get gem 0 out of the grid
gems(0).x = -64
sync on
`sync rate 60
do
cls
lastTick = tick
tick = timer()
delta# = (tick-lastTick)*.01
if mouseclick() = 1 and flag=0
flag = 1
tx = mousex()/64
ty = mousey()/64
if getGem(tx, ty) = -1 then addGem(tx*64, ty*64)
endif
if mouseclick() = 2 and flag = 0
flag = 1
my = mousey() / 64
selectedGem = getGem(mousex()/64, my)
if selectedGem > -1 then removeGem(selectedGem)
endif
if mouseclick() = 0 then flag = 0
selectedGem = getGem(mousex()/64, mousey()/64)
text 640,0,"SelectedGem: "+str$(selectedGem)
if selectedGem >0
text 640,20,"gems(i).still: "+str$(gems(selectedGem).still)
endif
if selectedGem >0
text 640,40,"gems(selectedGem).y: "+str$(gems(selectedGem).y)
endif
if selectedGem >0
text 640,60,"gems(selectedGem).neighboor: "+str$(gems(selectedGem).neighboor)
endif
rem draw map
ink rgb(64,64,64),0
box 0, 0, 640, 640
ink rgb(48,48,48),0
for x = 1 to 10
line x*64,0,x*64,640
next x
for y = 1 to 10
line 0,y*64,640,y*64
next y
gemCount = array count(gems())
for i = 1 to gemCount
if gems(i).still = 0
inc gems(i).acceleration, 20*delta#
inc gems(i).y, gems(i).acceleration*delta#
endif
for j = 1 to gemCount
if i <> j
x = gems(i).x
y = gems(i).y
x2 = gems(j).x
y2 = gems(j).y
if overlap(x, y, x+64, y+64, x2, y2, x2+64, y2+64) = 1
gems(i).y = y2-64
gems(i).acceleration = 0
gems(i).still = 1
endif
if gems(i).x = gems(j).x and gems(i).y = gems(j).y - 64 and gems(j).still = 1
gems(i).neighboor = getGem(gems(i).x/64, gems(j).y/64)
endif
if gems(i).neighboor = 0
gems(i).still = 0
endif
endif
next j
if gems(i).y+64 >= 640
gems(i).y = 576
gems(i).acceleration = 0
gems(i).still = 1
endif
next i
rem draw gems
ink rgb(0,192,128),0
for i = 0 to gemCount
x = gems(i).x
y = gems(i).y
ink gems(i).color
box x+4, y+4, x+60, y+60
next i
sync
loop
function overlap(x1, y1, x2, y2, x3, y3, x4, y4)
if x1 < x4 and x2 > x3 and y1 < y4 and y2 > y3 then exitfunction 1
endfunction 0
function addGem(x, y)
array insert at bottom gems()
gems().x = x
gems().y = y
gems().color = rgb(rnd(255),rnd(255),rnd(255))
endfunction
function removeGem(i)
array delete element gems(), i
endfunction
function getGem(mapX, mapY)
gemCount = array count(gems())
for i = 0 to gemCount
if gems(i).x / 64 = mapX and int(gems(i).y) / 64 = mapY then exitfunction i
next i
endfunction -1
There is still state for every gem and no more verical shuffle, it was the overlap statement that messed up everything, gems never fully stop from fall and there was the problem, they just seemed like they are not falling but y position keep changing.Plus there is neighboor gem, if there isn't the program can't tell if the gem must fall if you put fast another gem under and it got stuck in mid fall.Now it checks the gem under and if it's 0 at some point when the second gem is away,it continues the fall.Instead of checking for i=0 and j=0 now it checks from i=1 and j=1 because gem 0 is a special and mess up everything it's also positioned out of the grid.You need to think of some workaround if you want to use right mouse click to destroy gem.I tried to make it work with overlap but failed.
Coding is My Kung Fu!
And My Kung Fu is better than Yours!