I'm working on a scorched earth clone, and want to make the ground destructible. I thought the best way to do this would be to use pixmaps and turn pixels alpha when they are destroyed, I made a test program and have found that this method takes a bit more processing time then I'd prefer.
Is there a better way to do it?
Is there a better way to do it?
Strict Const X_RES = 800, Y_RES = 600 Graphics X_RES, Y_RES, 0 SetBlend(ALPHABLEND) Global map:Timage = CreateImage(X_RES, Y_RES) Global pixels:TPixmap = LockImage(map) Global radius = 20 'radius of terrain to destroy around a click For Local i% = 0 To X_RES - 1 For Local j% = Y_RES/2 To Y_RES - 1 WritePixel(pixels,i,j, $ff00ff00) 'blue Next Next UnlockImage(map) Function destroy(x,y) pixels:TPixmap = LockImage(map) For Local i% = x-radius To x+radius For Local j% = y-radius To y+radius Local pixel% = ReadPixel(pixels,i,j) If Hex(pixel) > $00ffffff 'if the pixel is not completely clear pixel = ($00ffffff & pixel) 'changes the alpha bits to 0 and preserves the rest WritePixel(pixels,i,j,pixel) EndIf Next Next UnlockImage(map) EndFunction 'UnlockImage(map) While Not KeyHit(key_escape) If MouseHit(1) Then Local time = MilliSecs() 'For Local i% = 1 To 100 destroy(MouseX(),MouseY()) 'Next Print MilliSecs() - time EndIf SetColor(255,0,0) DrawRect(0,0,X_RES,Y_RES) SetColor(255,255,255) DrawImage(map,0,0) Flip;Cls Wend