Löschen und "Shufflen" nicht so ruckelt.
Code: Alles auswählen
InitSprite()
InitKeyboard()
InitMouse()
Global bb.l, bh.l, w.l, h.l, breite.l, array.l
bb = 800
bh = 600
breite.l = 3
w = bb / breite - 1
h = bh / breite - 1
array = 0
Dim f(w, h, 1)
If Not OpenWindow(0, 0, 0, bb, bh, "Test") : End : EndIf
If Not OpenWindowedScreen(WindowID(0), 0, 0, bb, bh, 0, 0, 0) : End : EndIf
If #PB_Compiler_OS = #PB_OS_Linux
HideWindow(0, 1)
EndIf
;- bild
If CreateSprite(1, bb, bh, 0)
StartDrawing(SpriteOutput(1))
Box(0, 0, bb, bh, $FFFFFF)
StopDrawing()
EndIf
If CreateSprite(0, breite, breite, 0)
StartDrawing(SpriteOutput(0))
Box(0, 0, breite, breite, 0)
StopDrawing()
EndIf
If CreateSprite(2, breite, breite, 0)
StartDrawing(SpriteOutput(2))
Box(0, 0, breite, breite, $FFFFFF)
StopDrawing()
EndIf
#maus = 3
If CreateSprite(#maus, 11, 16)
StartDrawing(SpriteOutput(#maus))
FrontColor(RGB(20, 0, 0))
BackColor(RGB(0, 0, 0))
LineXY(0, 0, 0, 15)
LineXY(1, 15, 5, 11)
LineXY(5, 11, 11, 11)
LineXY(11, 11, 0, 0)
FillArea(2, 5, RGB(20, 0, 0), RGB(20, 0, 0))
TransparentSpriteColor(#maus, RGB(0, 0, 0))
StopDrawing()
EndIf
Structure change
x.l
y.l
new.l
EndStructure
NewList change.change()
Macro changefield(xp, yp, newp)
If AddElement(change())
change()\x = xp
change()\y = yp
change()\new = newp
f(change()\x, change()\y, array) = newp
EndIf
EndMacro
ClearList(change())
Repeat
ClearScreen(RGB(255, 255, 255))
ExamineKeyboard()
ExamineMouse()
UseBuffer(1)
ForEach change()
With change()
If \new
DisplaySprite(0, \x * breite, \y * breite)
Else
DisplaySprite(2, \x * breite, \y * breite)
EndIf
EndWith
Next
ClearList(change())
For y = 0 To h
ym = y - 1
yp = y + 1
If ym < 0 : ym = h : EndIf
If yp > h : yp = 0 : EndIf
For x = 0 To w
xm = x - 1
xp = x + 1
If xm < 0 : xm = w : EndIf
If xp > w : xp = 0 : EndIf
If g
livingaround = f(xm, ym, array)
livingaround + f( x, ym, array)
livingaround + f(xp, ym, array)
livingaround + f(xm, y, array)
livingaround + f(xp, y, array)
livingaround + f(xm, yp, array)
livingaround + f( x, yp, array)
livingaround + f(xp, yp, array)
exist = f(x, y, array)
If livingaround = 3 Or (livingaround = 2 And exist)
f(x, y, array ! 1) = 1
If Not exist
DisplaySprite(0, x * breite, y * breite)
EndIf
Else
f(x, y, array ! 1) = 0
If exist
DisplaySprite(2, x * breite, y * breite)
EndIf
EndIf
EndIf
Next
Next
If g
array ! 1
EndIf
UseBuffer(#PB_Default)
DisplaySprite(1, 0, 0)
DisplayTransparentSprite(#maus, MouseX(), MouseY())
If KeyboardReleased(#PB_Key_R) ;RUN
g ! 1
EndIf
If MouseButton(1)
changefield(MouseX() / breite, MouseY()/breite, 1)
EndIf
If MouseButton(2)
changefield(MouseX() / breite, MouseY()/breite, 0)
EndIf
If KeyboardPushed(#PB_Key_S) ;SHUFFLE
For i = 0 To w * h / 100
changefield(Random(w), Random(h), 1)
Next
EndIf
FlipBuffers(0)
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow