Code : Tout sélectionner
InitKeyboard()
InitSprite()
Structure uni
X.l
y.l
EndStructure
Global Dim unite.uni (999)
unite(1)\x = 304
unite(1)\y = 304
OpenScreen(640,480,16,"")
Procedure evenement1(nbx.l)
cx = 16 : cy = 16
For tt=1 To nbx
If unite(quan)\x % 32 > 0
a = Round((unite(quan)\x+cx)/32,0)
If a*32 <= unite(quan)\x+cx And (a*32)+32 >= unite(quan)\x+cx
posx = a
ElseIf (a-1)*32 <= unite(quan)\x+cx And (a-1)*32+32 >= unite(quan)\x+cx
posx = a-1
ElseIf (a+1)*32 <= unite(quan)\x+cx And (a+1)*32+32 >= unite(quan)\x+cx
posx = a+1
EndIf
ElseIf unite(quan)\x % 32 = 0
posx = (unite(quan)\x) /32
EndIf
If unite(quan)\y % 32 > 0
b = Round((unite(quan)\y+cy)/32,0)
If b*32 <= unite(quan)\y+cy And (b*32)+32 >= unite(quan)\y+cy
posy = b
ElseIf (b-1)*32 <= unite(quan)\y+cy And (b-1)*32+32 >= unite(quan)\y+cy
posy = b-1
ElseIf (b+1)*32 <= unite(quan)\y+cy And (b+1)*32+32 >= unite(quan)\y+cy
posy = b+1
EndIf
ElseIf unite(quan)\y % 32 =0
posy = (unite(quan)\y) /32
EndIf
Next tt
EndProcedure
Procedure evenement2(nbx.l)
cx = 16 : cy = 16
coef.l
position.l
reX.l
reY.l
For tt=1 To nbx
For u = 1 To 2
If u = 1
position = unite(quan)\x
coef = cx
ElseIf u = 2
position = unite(quan)\y
coef = cy
EndIf
If position % 32 > 0
a = Round((position+coef)/32,0)
If a*32 <= position+coef And (a*32)+32 >= position+coef
posx = a
ElseIf (a-1)*32 <= position+coef And (a-1)*32+32 >= position+coef
posx = a-1
ElseIf (a+1)*32 <= position+coef And (a+1)*32+32 >= position+coef
posx = a+1
EndIf
ElseIf position % 32 = 0
If u = 1 : rex = (position /32) : EndIf
If u = 2 : rey = (position /32) : EndIf
EndIf
Next u
Next tt
EndProcedure
Repeat
timer1.f = ElapsedMilliseconds()
evenement1(1000000)
timer2.f = ElapsedMilliseconds() - timer1
Debug timer2
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

C'est ahurissant, le temps d'execution que prend un for ... next (surtout pour faire 1 à 2 !!!)
J'ai peut-etre mal programmé, mais apparement c'est très lent un for... next (quelque soit le nombre).