update !
Strict Const Max_TILEMAP_HEIGHT = 1000 Type TScreen Field array_cells : TCell[32 * MAX_TILEMAP_HEIGHT] Field array_tiles : TTile[] Field array_cannons : TCannon[] Field NbTiles Field NbCannons Field ScrollY Field LigneMap Field EllapsedTime Field t Function Init:TScreen () Local s:TScreen = New TScreen ' fill the array with empy values For Local y = 0 To MAX_TILEMAP_HEIGHT - 1 For Local x=0 To 32 - 1 Local i = y * 32 + x s.array_cells[i] = TCell.Create (x,y) Next Next s.NbTiles = 0 s.NbCannons = 0 s.EllapsedTime = MilliSecs() s.ScrollY = 0 s.LigneMap = 0 Return s End Function Method Add_tile (pPosX, pPosY) ' check index if not out of bound Local index = pPosY * 32 + pPosX If index > 32 * MAX_TILEMAP_HEIGHT Then RuntimeError "Bad Index" End If array_cells[Index].Id_tile = NbTiles + 1 NbTiles = NbTiles + 1 array_tiles = array_tiles [..NbTiles+1] array_tiles [NbTiles] = TTile.Create(pPosX, pPosY) End Method Method Add_cannon (pPosX, pPosY) ' check index if not out of bound Local index = pPosY * 32 + pPosX If index > 32 * MAX_TILEMAP_HEIGHT Then RuntimeError "Bad Index" End If array_cells[index].Id_cannon = NbCannons + 1 NbCannons = NbCannons + 1 array_cannons = array_cannons [..NbCannons+1] array_cannons [NbCannons] = TCannon.Create(pPosX, pPosY) End Method Method Compute_logic() If EllapsedTime + 20 < MilliSecs() Then If ScrollY < 31 Then ScrollY = ScrollY + 1 Else ScrollY = 0 If LigneMap < MAX_TILEMAP_HEIGHT Then LigneMap = LigneMap + 1 Else LigneMap = 0 End If End If t = MilliSecs() Local Decal = -32 For Local y= Lignemap+24 To LigneMap Step -1 For Local x=0 To 31 Local Index = y * 32 + x If array_cells[Index].Id_tile <> - 1 Then Local ix ix = array_cells[Index].Id_tile array_tiles [ix].PosY = ScrollY + Decal End If If array_cells[Index].Id_cannon <> - 1 Then Local ix ix = array_cells[Index].Id_cannon array_cannons [ix].PosY = ScrollY + Decal End If Next Decal = Decal + 32 Next t = MilliSecs() - t EllapsedTime = MilliSecs() End If End Method Method Draw() For Local y= Lignemap To LigneMap + 24 Step 1 For Local x=0 To 31 Local Index = y * 32 + x If array_cells[Index].Id_tile <> - 1 Then Local px,py, ix, r,g,b ix = array_cells[Index].Id_tile px = array_tiles [ix].PosX py = array_tiles [ix].PosY r = array_tiles [ix].r g = array_tiles [ix].g b = array_tiles [ix].b SetColor r,g,b DrawRect px,py, 32,32 End If If array_cells[Index].Id_cannon <> - 1 Then Local px,py, angle, ix ix = array_cells[Index].Id_cannon px = array_cannons [ix].PosX py = array_cannons [ix].PosY angle = array_cannons [ix].Angle SetColor 255,0,0 DrawOval px,py, 32,32 SetColor 0,0,255 SetRotation angle SetLineWidth 3 DrawLine px+16,py+16,px+16+20,py+16 SetLineWidth 2 SetRotation 0 End If Next Next SetColor 255,255,255 DrawText "Time=" + String(t),10,10 DrawText "Lignemap=" + String(LigneMap),10,20 End Method End Type Type TCell Field PosX Field PosY Field Id_tile Field Id_Cannon Function Create : TCell (PosX, PosY) Local c:TCell = New TCell c.PosX = PosX c.PosY = PosY c.Id_Tile = -1 c.Id_Cannon = -1 Return c End Function End Type Type TTile Field PosX Field PosY Field r Field g Field b Function Create:TTile (PosX, PosY) Local t:TTile = New TTile t.PosX = PosX * 32 t.PosY = PosY * 32 t.r = Rand (100,255) t.g = Rand (100,255) t.b = Rand (100,255) Return t End Function End Type Type TCannon 'Field Id_cannon : Int Field PosX Field PosY Field angle Function Create:TCannon (PosX, PosY) Local c:TCannon = New TCannon c.PosX = PosX * 32 c.PosY = PosY * 32 c.angle = Rand (0,360) Return c End Function End Type ' main program Graphics 1024 , 768 , 32 , 75 Global Screen : TScreen = TScreen.init() Global MaxTiles = 10000 For Local i=1 To MaxTiles Local x = Rand (0,31) Local y = Rand (0,MAX_TILEMAP_HEIGHT-1) Screen.Add_tile (x,y) x = Rand (0,31) y = Rand (0,MAX_TILEMAP_HEIGHT-1) Screen.Add_cannon (x,y) If KeyDown (KEY_ESCAPE) Then End Cls DrawText "please wait, computing " + String(MaxTiles) + " random tiles And canons positions... i=" + String(i),0,0 Flip Next While Not KeyDown (KEY_ESCAPE) Or MouseHit(1) Screen.Compute_logic() Cls Screen.Draw() Flip Wend