fb:porticula NoPaste
Bacterium
Uploader: | DonStevone |
Datum/Zeit: | 13.11.2011 13:42:40 |
'Programm(ablauf)
#Define ScreenWidth 1024
#Define ScreenHeight 786
#Define MaxFPS 60
'Bakterien
#Define MaxV 12
#Define StartBakterien 20
#Define MaxBakterien 50000
#Define Zellteilung 600
#Define BakteriumLeben 1300
Type Bakterium
LX as Double
LY as Double
X as Double
Y as Double
Xv as Double
Yv as Double
TeilCounter as Integer
Hunger as Integer
Leben as Integer
Aktiv as Byte
SLeben as Integer
End Type
Type Kultur
Private:
Bakterien as Bakterium PTR
CA as Byte
Public:
Anzahl as UInteger
X as Integer
Y as Integer
Aktiv as Byte
Lebenserwartung as Integer
LCounter as Integer
MaxLebenserwartung as Integer
MaxLeben as Integer
Declare Constructor(BakterienZahl as UInteger, XPos as Integer, YPos as Integer)
Declare Destructor()
Declare Sub NewBakterium(X as Double, Y as Double, NewLeben as Integer)
Declare Sub Control()
Declare Sub GClear()
Declare Sub G()
End Type
Constructor Kultur(BakterienZahl as UInteger, XPos as Integer, YPos as Integer)
Dim a as Integer
Anzahl = BakterienZahl - 1
Aktiv = 1
Bakterien = Allocate(MaxBakterien * Sizeof(Bakterium))
For a = 0 to Anzahl
Bakterien[a].X = XPos
Bakterien[a].Y = YPos
Bakterien[a].Xv = (RND * MaxV) - MaxV / 2
Bakterien[a].Yv = (RND * MaxV) - MaxV / 2
Bakterien[a].TeilCounter = Zellteilung + INT(RND * MaxFPS * 2)
Bakterien[a].Leben = BakteriumLeben
Bakterien[a].SLeben = Bakterien[a].Leben
Bakterien[a].Aktiv = 1
Next a
End Constructor
Destructor Kultur()
DeAllocate(Bakterien)
End Destructor
Sub Kultur.NewBakterium(X as Double, Y as Double, NewLeben as Integer)
Dim a as Integer
Dim Free as Integer
If Anzahl < MaxBakterien then
Anzahl += 1
For a = 0 to MaxBakterien
If Bakterien[a].Aktiv = 0 then Free = a : Exit For
Next a
Bakterien[Free].X = X
Bakterien[Free].Y = Y
Bakterien[Free].Xv = (RND * MaxV) - MaxV / 2
Bakterien[Free].Yv = (RND * MaxV) - MaxV / 2
Bakterien[Free].TeilCounter = Zellteilung + INT(RND * MaxFPS * 2)
Bakterien[Free].Leben = NewLeben + INT((RND * MaxFPS * 4) - MaxFPS * 2)
Bakterien[Free].SLeben = Bakterien[Free].Leben
Bakterien[Free].Aktiv = 1
Endif
End Sub
Sub Kultur.Control()
Dim a as Integer
Lebenserwartung = 0
MaxLebenserwartung = 0
LCounter = 0
If Aktiv = 1 then
For a = 0 to MaxBakterien
If Bakterien[a].Aktiv = 1 then
If Bakterien[a].SLeben > MaxLebenserwartung then MaxLebenserwartung = Bakterien[a].SLeben
Lebenserwartung += Bakterien[a].SLeben
LCounter += 1
Bakterien[a].LX = Bakterien[a].X
Bakterien[a].LY = Bakterien[a].Y
Bakterien[a].X += Bakterien[a].Xv / 20
Bakterien[a].Y += Bakterien[a].Yv / 20
If Bakterien[a].Xv > 0 then Bakterien[a].Xv -= 0.01
If Bakterien[a].Yv > 0 then Bakterien[a].Yv -= 0.01
Bakterien[a].TeilCounter -= 1
Bakterien[a].Leben -= 1
If INT(RND * 10) = 5 then
Bakterien[a].Xv = (RND * MaxV) - MaxV / 2
Bakterien[a].Yv = (RND * MaxV) - MaxV / 2
Endif
If Bakterien[a].Leben <= 0 then Bakterien[a].Aktiv = 0 : CA = 1 : Anzahl -= 1
If Bakterien[a].TeilCounter <= 0 then
NewBakterium(Bakterien[a].X, Bakterien[a].Y, Bakterien[a].SLeben)
Bakterien[a].TeilCounter = Zellteilung + INT(RND * MaxFPS * 2)
Endif
Endif
Next a
Lebenserwartung = Lebenserwartung / LCounter
Endif
End Sub
Sub Kultur.GClear()
Dim a as Integer
If Aktiv = 1 then
For a = 0 to MaxBakterien
If Bakterien[a].Aktiv = 1 Or CA = 1 then
PSet(Bakterien[a].LX, Bakterien[a].LY), &h000000
Endif
Next a
CA = 0
Endif
End Sub
Sub Kultur.G()
Dim a as Integer
If Aktiv = 1 then
For a = 0 to MaxBakterien
If Bakterien[a].Aktiv = 1 then
'Circle(Bakterien[a].X, Bakterien[a].Y), 1, &h000050
PSet(Bakterien[a].X, Bakterien[a].Y), &h0000FF
Endif
Next a
Endif
End Sub
Type TimeControlUDT
Declare Constructor(FPS as Integer)
Declare Sub ControlTime()
Declare Sub SetFPS(FPS as Integer)
Private:
Temp1 as Double
StartTime as Double
DurchlaeufeS as Integer
End Type
Constructor TimeControlUDT(FPS as Integer)
DurchlaeufeS = FPS
End Constructor
Sub TimeControlUDT.ControlTime()
If StartTime > 0 then
Temp1 = INT(1000 - (Timer - StartTime) * DurchlaeufeS)
Temp1 = Temp1 \ DurchlaeufeS
If Temp1 > 0 then Sleep Temp1, 1
Endif
StartTime = Timer
End Sub
Sub TimeControlUDT.SetFPS(FPS as Integer)
DurchlaeufeS = FPS
End Sub
Screenres ScreenWidth, ScreenHeight, 32
Randomize Timer
Dim as TimeControlUDT FPS = TimeControlUDT(MaxFPS)
Dim FPSCheck as UInteger
Dim ST as Double
Dim OTFlag as Byte
Dim as Integer SLebenserwartung
Dim as Kultur PTR K
K = NEW Kultur(10, ScreenWidth / 2, ScreenHeight / 2)
St = Timer
While(NOT Multikey(&h01))
K->Control()
ScreenLock
Line (0, 0)-(ScreenWidth, 40), &h000000, BF
K->GClear()
K->G()
Draw String (10, 10) , "FPS: " & INT(FPSCheck / (Timer - ST))
Draw String (100, 10), "Bakterien: " & K->LCounter
Draw String (300, 10), "Maximale Bakterien: " & MaxBakterien + 1
Draw String (10, 20), "StartLebenserwartung: " & INT(SLebenserwartung / MaxFPS) & "s"
Draw String (300, 20), "Lebenserwartung: " & INT(K->Lebenserwartung / MaxFPS) & "s"
Draw String (10, 30), "Hochste Lebensdauer Start: " & INT(BakteriumLeben / MaxFPS) & "s"
Draw String (300, 30), "zZ Hoechste Lebensdauer: " & INT(K->MaxLebenserwartung / MaxFPS) & "s"
ScreenUnlock
FPS.ControlTime()
FPSCheck += 1
If Timer - St > 10 then St = Timer : FPSCheck = 0
If OTFlag = 0 then
OTFlag = 1
SLebenserwartung = K->Lebenserwartung
Endif
Wend