well, mine is still a simulation, and not a game,
but it's really interesting (at least to me) how the life-forms evolve over time.
you can even get a graph of the first 1600 seconds of a run by hitting shift.
i borrowed a lot from the ideas here, and came up with something i'm happy with.
Rapidrory , i tried yours, and it's a neat idea. i got them all on one side, but nothing happened. must have been the wrong side.
you should continue with it. fading fences would be a good idea.
Rem Project: Dark Basic Pro Project
Rem Created: Wednesday, May 04, 2011
Rem ***** Main Source File *****
set display mode 800,600,32
sync on
sync rate 0
sync
randomize timer()
set window position 50,50
set text font "lucida console"
if file exist("bug debug.txt") then delete file "bug debug.txt"
open to write 1,"bug debug.txt"
type life_form
x as float
y as float
spd
age
nut b
size
span
reproAGE
reproNUT
reproLIT
AGG
FEAR
PRED
metab
stealth
armor
agility
poison
fangs
pounce
ID
img
L$ as string
chewing
TX
TY
i2
FoodPref
Eff
aninum
anidir
endtype
` eff is metabolic efficiency.
Type Food
kind
x
y
time
amount
Endtype
TYPE INFORMATION
alive
biodiversity
AvgSize
supply
stealth
armor
agility
poison
fangs
pounce
ENDTYPE
dim c(24,24)
dim d(25,25)
dim col(9) as dword
dim i(801) as INFORMATION
col(0)=rgb(255,255,255)
Global TotalID
Global Mutation
Global Elap
Global NumMutations
Global Predations
Global Supply
Global AvgSize
Global HiMetab
Global HiEff
Global Starvations
Global BioDiversity
` Global Favorite
Global alive
Global aliveguy
starthere:
Create_Background()
TotalID=1
Mutation=8+rnd(7)
Elap=0
NumMutations=0
Predations=0
Supply=10
AvgSize=75
Starvations=0
HIBD=0
seconds=0
HiEff=0
HiMetab=0
INITIALIZE_BASE_CELLS()
Create_Drops()
Dim LF(201) as life_form
dim fo(12) as Food
Dim Pa(201,5)
` this is PARENTS. the last 5 parents of this organism.
` 3 generations is not all that much seperation...
` so, make a 'first cell' , and then the game begins.
` - food drops at random locations, and the bacteria moves toward it.
` - it eats , breeds , or dies as needed.
` clear out old stuff:
for t=1 to 201
if sprite exist(t) then delete sprite t
kill_cell(t)
if image exist(t)
delete image t
endif
for u=0 to 5
Pa(c,u)=0
next u
next t
Create_First_Cell()
for t=1 to 10
fo(t).x=rnd(600)+50
fo(t).y=rnd(500)+50
fo(t).kind=1
sprite 300+t,fo(t).x,fo(t).y,905
fo(t).amount=24
next t
cel=0
t1=timer()
do
cls
` lock pixels
paste image 1334,0,0
` "elap" is how many milliseconds have passed since the last loop.
` it is used to determine how much EFFECT everything has this loop
elap=timer()-t1
t1=timer()
if mouseclick() then elap=0
` elap=1
IF CONTROLKEY()
HIDE ALL SPRITES
ELSE
SHOW ALL SPRITES
ENDIF
` LFs only take action if the SPACEKEY is NOT pressed, and the mouse is also not clicked
IF SPACEKEY()=0 and mouseclick()=0
` ### AI BEGIN
inc cel
if cel>100
cel=1
One_Hundred_Cycles()
endif
if sprite exist(cel)
` ### AI BEGIN
` find NEAREST FOOD
` find other cells , and determine their threat level or tastiness.
dis=9999
fx=0
fy=0
for t=1 to 10
if sprite exist(t+300)
i=sprite image(t+300)-904
d=d2d(lf(cel).x,lf(cel).y,fo(t).x,fo(t).y)
` make non-favorite food be less desirable:
if i<>lf(cel).FoodPref then d=d*2
if d<dis
dis=d
fx=fo(t).x+rnd(10)-5
fy=fo(t).y+rnd(10)-5
endif
endif
next t
` by now, we have an FX,FY.
` but if the cell is VERY HUNGRY, it might actively hunt its kin.
IF LF(CEL).NUT<1
for t=1 to 100
if t<>cel
if sprite exist(t)
d=d2d(lf(cel).x,lf(cel).y,lf(t).x,lf(t).y)*3
if d<dis
a=combat_score(cel,t)
b=combat_score(t,cel)
if a>b
` the hungry cell will try to eat this cell!
fx=lf(t).x+rnd(6)-3
fy=lf(t).y+rnd(6)-3
dis=d
endif
endif
endif
endif
next t
ENDIF
` this sets target for FOOD:
if fx>0 and fy>0
lf(cel).tx=fx
lf(cel).ty=fy
` rotate sprite cel,atanfull(lf(cel).x-lf(cel).tx,lf(cel).y-lf(cel).ty)-180
ELSE
` FOR SOME REASON, WE DID NOT FIND A TARGET FOR THIS LF TO GO TO.
endif
` ### AI END
endif
` ### AI END
Control_Life_Forms()
inc counter,elap
if counter>100 : ` (50+supply*10)
Spawn_Food()
dec counter,100 : ` (50+supply*10)
endif
ENDIF
ink col(0),0
if alive>0
inc seconds,elap
else
center text 400,300,"PRESS ENTER TO RESET"
if returnkey() then goto starthere
endif
save_information(int(seconds/2000))
if BioDiversity>HIBD
HIBD=BioDiversity
endif
` supply=3+abs(sin(seconds)*8)
`text 0,0,"Elap : "+str$(elap)
text 0,0,"Seconds : "+str$(seconds/1000.0,1)
text 0,15,"FPS : "+str$(screen fps())
text 0,30,"Births : "+str$(TotalID)
text 0,50,"Mutation Rate : "+str$(Mutation)+"%"
text 0,65,"Mutations : "+str$(NumMutations)
text 0,80,"Starvations: "+str$(Starvations)
text 0,95,"Predations : "+str$(Predations)
text 0,115,"BioDiversity: "+str$(BioDiversity)
text 0,130,"HIBioDiv: "+str$(HIBD)
text 0,145,"# Alive: "+str$(alive)
text 0,535,"food supply:"+str$(supply)
text 0,550,"AvgSize:"+str$(AvgSize)
text 0,565,"HiMetab:"+str$(Himetab)
text 0,580,"HiEff:"+str$(HiEff)
` MostAlive
IF MOUSECLICK()
SPRITE 999,MOUSEX(),MOUSEY(),905
SCALE SPRITE 999,5
Q=sprite collision(999,0)
if Q>100 then Q=0
ENDIF
if Q>0
if sprite exist(Q)=0
Q=0
endif
endif
if Q>0 and lf(Q).age>0
` circle lf(Q).x+12,lf(Q).y+12,15
circle lf(Q).x+11,lf(Q).y+11,12
center text 739,0,"SPD : "+str$(lf(Q).spd)
center text 739,15,"AGE : "+str$(lf(Q).AGE)
center text 739,30,"NUT : "+str$(lf(Q).NUT)
center text 739,45,"SIZE : "+str$(lf(Q).SIZE)
center text 739,60,"metab : "+str$(lf(Q).metab)
center text 739,75,"efficiency : "+str$(lf(Q).eff)
center text 739,100,"REPROAGE : "+str$(lf(Q).REPROAGE)
center text 739,120,"REPRONUT : "+str$(lf(Q).REPRONUT)
center text 739,140,"SPAN : "+str$(lf(Q).SPAN)
center text 739,155,"+PRED : "+str$(lf(Q).pred)
center text 739,180,"POISON : "+str$(lf(Q).POISON)
center text 739,200,"FANGS : "+str$(lf(Q).FANGS)
center text 739,220,"POUNCE : "+str$(lf(Q).POUNCE)
center text 739,260,"STEALTH : "+str$(lf(Q).STEALTH)
center text 739,280,"ARMOR : "+str$(lf(Q).ARMOR)
center text 739,300,"AGILITY : "+str$(lf(Q).AGILITY)
center text 739,340,"ID : "+str$(lf(Q).ID)
center text 739,360,"img : "+str$(lf(Q).img) : `paste image lf(Q).img,740,360
center text 739,400,"tx : "+str$(lf(Q).tx)
center text 739,415,"ty : "+str$(lf(Q).ty)
`center text 739,," : "+str$(lf(Q).)
`center text 739,," : "+str$(lf(Q).)
`center text 739,," : "+str$(lf(Q).)
if sprite exist(Q)=0 then Q=0
endif
sync
if shiftkey()
Draw_Information()
t1=timer()
endif
for t=1 to 100
if sprite exist(t)
`z=(LF(t).ID+int(seconds/12.3)) mod 23
if lf(t).aninum>230 then lf(t).anidir=-1
if lf(t).aninum<5 then lf(t).anidir=1
lf(t).aninum=lf(t).aninum+(elap)*lf(t).anidir
` z=((LF(t).ID+lf(t).aninum)/7)
z=((lf(t).aninum)/7)
z=z+LF(t).size+1
scale sprite t,z
` offset sprite t,sprite width(t)/2,sprite height(t)/2
endif
next t
loop
end
Function One_Hundred_Cycles()
BioDiversity=0
` for avgsize calc, n is how many cells are alive, z is the added-up size
n=0
z=0
` DELETE UNUSED IMAGES:
for t=1 to 100
lf(t).i2=0
next t
alive=0
aliveguy=0
for t=1 to 100
if lf(t).age>0
if lf(t).img>0
lf(lf(t).img).i2=1
inc n
inc z,lf(t).size
inc alive
aliveguy=t
endif
endif
next t
for t=1 to 100
if image exist(t)
if lf(t).i2<1
delete image t
else
inc BioDiversity
endif
endif
next t
` POSSIBLY ADJUST THE FOOD SUPPLY:
if rnd(11)=0
if supply<5
inc supply
else
if supply>11
dec supply
else
sgn=(rnd(1)*2)-1
supply=supply+sgn
endif
endif
endif
if n>0
avgsize=z/n
else
avgsize=0
endif
Endfunction
Function Spawn_Food()
f=0
numfood=0
` determine how many food we HAVE, and if there are any food sprites available to use.
for u=1 to 10
v=300+u
if sprite exist(v)
inc numfood
else
f=v
endif
next u
if numfood<supply and f>0
` we need a new food, AND there is a sprite available.
n=f-300
fo(n).x=rnd(700)+50
fo(n).y=rnd(500)+50
fo(n).kind=905+rnd(2)
sprite f,fo(n).x,fo(n).y,fo(n).kind
fo(n).amount=25
scale sprite f,125
endif
Endfunction
Function Combat_Score(a,b)
` this function will calculate a COMBAT SCORE for
` LF(A) vs. LF(B).
` when we have a possible combat, we'll call this twice.
` once for a vs. b, once for b vs. a
` whichever is higher will win (but no combat for a tie)
if a>0 and b>0 and a<101 and b<101
` a size difference of 50 will give a combat bonus.
x=0
if ((LF(a).size-LF(b).size))>50 then inc x
if LF(a).poison>lf(b).stealth then inc x , (LF(a).poison-lf(b).stealth)
if LF(a).fangs>lf(b).armor then inc x , (LF(a).fangs-lf(b).armor)
if LF(a).pounce>lf(b).agility then inc x , (LF(a).pounce-lf(b).agility)
` THIS SAYS, ` poison is better than fangs,
` fangs are better that pounce, and pounce is better than poison.
` none is all better, and the bonus is small,
` but it might make some interesting differences:
if LF(a).poison>LF(b).fangs then inc x
if LF(a).fangs>LF(b).pounce then inc x
if LF(a).pounce>LF(b).poison then inc x
` changed 5/9 , 1001am
endif
Endfunction x
Function Control_Life_Forms()
` everything moves towards its target. if it arrives at its target,
` the target is set to 0,0
for t=1 to 100
if sprite exist(t)
` allow to spawn , or move if can't spawn.
` also, increase age, decrease nutrition, and kill if necessary.
if lf(t).age>lf(t).span
` THIS ONE DIES OF OLD AGE (or starvation)
kill_cell(t)
if sprite exist(t) then delete sprite t
inc Starvations
else
` did NOT die yet. so control it.
` AGE. age double for starving. also "process nutrition".
inc lf(t).age,elap
if lf(t).nut<1
inc lf(t).age,((elap*lf(t).metab)/75) : ` this is STARVATION
else
dec lf(t).nut,((elap*lf(t).metab)/100)
endif
if (lf(t).age>=lf(t).reproAGE) AND (lf(t).nut>lf(t).reproNUT)
` this one can SPAWN RIGHT NOW. do it!
` if t=1
` text 0,120,"I AM READY TO SPAWN!"
` endif
Cell_Spawns(t)
else
` can't spawn.
` therefore, it probably MOVES.
` we'll just try some PREDATION right here!
` Predations
` FOR PREDS=1 TO 3
` FOR PREDS=1 TO 5
v=sprite collision(t,0)
if v>0 and v<101
if lf(t).img<>lf(v).img : ` try not to eat your own kind!
a=combat_score(t,v)
b=combat_score(v,t)
if a>b
` T EATS V !
delete sprite v
kill_cell(v)
inc Predations
inc lf(t).nut,lf(t).pred
endif
endif
endif
` NEXT PREDS
` if he has reached his destination, select a random target
if d2d(lf(t).x,lf(t).y,lf(t).tx,lf(t).ty)<2
lf(t).tx=rnd(600)+50
lf(t).ty=rnd(500)+50
endif
if lf(t).tx>0 and lf(t).ty>0 and lf(t).size>0
x#=lf(t).x
y#=lf(t).y
` speed is currently affected by size:
` spd = (lf(t).spd + lf(t).size)/2
spd = (lf(t).spd*100)/lf(t).size
IF LF(T).NUT<7500
` A NEW THING: any cell that is SATIATED, doesn't bother to MOVE.
` (might not favor the fittest though...
` it actually favors the HUNGRY...)
` MOVEMENT
if x#<lf(t).tx
x#=x#+(elap/999.9)*spd
`x#=x#+(elap/999.9)*lf(t).spd
endif
if y#<lf(t).ty
y#=y#+(elap/999.9)*spd
`y#=y#+(elap/999.9)*lf(t).spd
endif
if x#>lf(t).tx
x#=x#-(elap/999.9)*spd
`x#=x#-(elap/999.9)*lf(t).spd
endif
if y#>lf(t).ty
y#=y#-(elap/999.9)*spd
`y#=y#-(elap/999.9)*lf(t).spd
endif
ENDIF
sprite t,x#,y#,sprite image(t)
` offset sprite t,sprite width(t)/2,sprite height(t)/2
lf(t).x=x#
lf(t).y=y#
` check for EATING:
for u=1 to 10
v=u+300
if sprite exist(v)
if sprite collision(v,t)
i=sprite image(v)-904
if lf(t).FoodPref=i
inc lf(t).nut,250 : ` 4500
else
inc lf(t).nut,100 : ` 2000
endif
`delete sprite v
dec fo(u).amount
if fo(u).amount>0
z=fo(u).amount*4+25
if z<50 then z=50
scale sprite v,z
` scale sprite v,fo(u).amount*4+25
else
delete sprite v
endif
endif
endif
next u
endif
endif : ` can't spawn.
endif : ` hasn't died.
endif
next t
Endfunction
Function Create_Cell_Image()
` 0's are "OFF"
` 1's are "always on"
` 2's are "50% chance" to become '1', or be turned OFF
` then , any totally isolated cell is DELETED. (0) (orthoganal or diagonal)
` then , the entire thing is "SKINNED" (3)
` (any 0 surrounded by a 1 (or 2) is turned into a 3)
` then between 5 and 25 '1's' are turned into 4s (organs)
` 1's, 3's, and 4's are each their own colors.
` there should be no 2's , and 3 colors.
` we now re-initialize base cells for every mutation!:
INITIALIZE_BASE_CELLS()
for x=1 to 24
for y=1 to 24
d(x,y)=c(x,y)
next y
next x
` 0's and 1's are already taken care of.
chance=rnd(2)+3 : ` 16% - 25% chance
` do 2's
for x=1 to 24
for y=1 to 24
if d(x,y)=2
if rnd(chance)=0
d(x,y)=1
else
d(x,y)=0
endif
endif
next y
next x
` now REMOVE ISOLATED CELLS
for x=1 to 24
for y=1 to 24
if d(x,y)=1
` check for neighbors:
n=0
for t=x-1 to x+1
for u=y-1 to y+1
if t<>x or u<>y : ` you are not your own neighbor!
if d(t,u)=1
inc n
endif
endif
next u
next t
if n=0
d(x,y)=0
endif
endif
next y
next x
` now make SKIN:
for x=1 to 24
for y=1 to 24
` select an empty cell
if d(x,y)=0
for t=x-1 to x+1
for u=y-1 to y+1
if t=x or u=y : ` if it's got a cardinal neighbor
if d(t,u)=1
d(x,y)=3 : ` make it skin!
endif
endif
next u
next t
endif
next y
next x
` now make ORGANS:
org=(rnd(20)+5)*(rnd(1)+1)
for t=1 to org
` at this point, any 1 can become a 4
repeat
x=rnd(23)+1
y=rnd(23)+1
until d(x,y)=1
d(x,y)=4
next t
CREATE BITMAP 1,24,24
SET CURRENT BITMAP 1
CLS
repeat
a=50+rnd(185)
b=50+rnd(185)
c=50+rnd(185)
until abs(a-b)>30 or abs(b-c)>30
col(1)=rgb(a,b,c)
col(3)=rgb(c,a,b)
col(4)=rgb(b,c,a)
`cls
for x=1 to 24
for y=1 to 24
if d(x,y)>0
ink col(d(x,y)),0
box x*18,y*18,x*18+18,y*18+18
dot x,y
endif
next y
next x
One_Hundred_Cycles()
I=0
repeat
inc i
until image exist(i)=0
if rnd(1)=0
if rnd(1)=0
flip bitmap 1
else
mirror bitmap 1
endif
endif
get image i,0,0,24,24,1
DELETE BITMAP 1
set current bitmap 0
Endfunction I
Function INITIALIZE_BASE_CELLS()
x=rnd(3)
select x
case 0
restore Base_Cells_1
endcase
case 1
restore Base_Cells_2
endcase
case 2
restore Base_Cells_3
endcase
case 3
restore Base_Cells_4
endcase
endselect
for y=1 to 24
for x=1 to 24
read c(x,y)
next x
next y
Base_Cells_1:
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 : ` 1
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 : ` 2
data 0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0 : ` 3
data 0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0 : ` 4
data 0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0 : ` 5
data 0,0,0,2,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,2,2,0,0,0 : ` 6
data 0,0,0,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2,2,0,0,0 : ` 7
data 0,0,2,2,2,2,2,2,1,1,1,1,1,1,1,1,2,2,2,2,2,2,0,0 : ` 8
data 0,0,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,0,0 : ` 9
data 0,0,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,0,0 : ` 10
data 0,0,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,0,0 : 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1,2,0,0,0,0,0,0,0,0 : ` 12
data 0,0,0,0,0,0,0,0,2,1,1,1,1,1,1,2,0,0,0,0,0,0,0,0 : ` 13
data 0,0,2,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2,2,2,0,0 : ` 14
data 0,0,2,1,1,1,2,2,2,1,1,1,1,1,1,2,2,2,1,1,1,2,0,0 : ` 15
data 0,0,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,0,0 : ` 16
data 0,0,0,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,0,0,0 : ` 17
data 0,0,0,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,0,0,0 : ` 18
data 0,0,0,2,2,2,2,1,1,1,2,2,2,2,1,1,1,2,2,2,2,0,0,0 : ` 19
data 0,0,0,2,2,2,2,2,1,1,1,1,1,1,1,1,2,2,2,2,2,0,0,0 : ` 20
data 0,0,0,0,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2,0,0,0,0 : ` 21
data 0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0 : ` 22
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 : ` 23
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 : ` 24
Endfunction
Function D2D(x,y,a,b)
d#=sqrt( (x-a)*(x-a) + (y-b)*(y-b) )
Endfunction d#
Function Kill_Cell(c)
LF(c).x=0
LF(c).y=0
LF(c).spd=0
LF(c).age=0
LF(c).nut=0
LF(c).size=0
LF(c).span=0
LF(c).reproAGE=0
LF(c).reproNUT=0
LF(c).reproLIT=0
LF(c).AGG=0
LF(c).FEAR=0
LF(c).PRED=0
LF(c).metab=0
LF(c).stealth=0
LF(c).armor=0
LF(c).agility=0
LF(c).poison=0
LF(c).fangs=0
LF(c).pounce=0
LF(c).ID=0
LF(c).img=0
LF(c).L$=""
LF(c).chewing=0
LF(c).TX=0
LF(c).TY=0
LF(c).Eff=0
Endfunction
Function Create_First_Cell()
` no randomness in the first cell, besides position.
` span & age are measured in MILLISECONDS,
` so the starting SPAN is 20 seconds,
` and the breeding age is 6 seconds.
` NUT is also measured in milliseconds. (so it has 2 seconds of nutrition)
C=1
I=Create_Cell_Image()
LF(c).x=rnd(600)+50
LF(c).y=rnd(500)+50
LF(c).spd=100
LF(c).age=1
LF(c).nut=500
LF(c).size=75
LF(c).span=9000
LF(c).reproAGE=3000
LF(c).reproNUT=1700 : ` just changed from 1300, 5/9 , 959am
LF(c).reproLIT=2
LF(c).AGG=0
LF(c).FEAR=0
LF(c).PRED=500
LF(c).metab=100
LF(c).stealth=0
LF(c).armor=0
LF(c).agility=0
LF(c).poison=0
LF(c).fangs=0
LF(c).pounce=0
LF(c).ID=1
LF(c).img=I
LF(c).L$=""
LF(c).chewing=0
LF(c).TX=0
LF(c).TY=0
LF(c).Eff=100
LF(c).aninum=0
LF(c).anidir=1
for t=0 to 5
Pa(c,t)=0
next t
sprite 1,LF(c).x,lf(c).y,i
scale sprite 1,75
Endfunction
Function Cell_Spawns(c)
` basically, cell # c is taken as the parent,
` and has a LITTER of 2-n new cells.
` the NEW CELLS are (nearly) identical to its PARENT,
` UNLESS IT MUTATES. in that case , it mutates according to the mutate function.
` NEED TO INCLUDE *PARENTS* HERE.
`for t=1 to LF(c).reproLIT
for t=1 to 2
num=0
repeat
inc num
until LF(num).age=0 or num>100
if num<101
inc TotalID
Mut=0
I=LF(c).img
` the more diverse the population already is, the LESS chance of mutations.
if rnd(99)<(Mutation-(BioDiversity/2))
I=Create_Cell_Image()
Mut=1
endif
LF(num).x=LF(c).x+rnd(50)-25
LF(num).y=LF(c).y+rnd(50)-25
LF(num).spd=LF(c).spd+rnd(7)-3
LF(num).age=1
LF(num).nut=500
LF(num).aninum=0
LF(num).anidir=1
if avgsize<450
LF(num).size=LF(c).size+rnd(7)-3
else
LF(num).size=LF(c).size-rnd(5)
endif
LF(num).span=LF(c).span+rnd(9)-3
LF(num).reproAGE=LF(c).reproAGE-rnd(7)+3
LF(num).reproNUT=LF(c).reproNUT-rnd(7)+3
LF(num).reproLIT=LF(c).reproLIT
LF(num).AGG=LF(c).AGG
LF(num).FEAR=LF(c).FEAR
LF(num).PRED=LF(c).PRED
LF(num).metab=LF(c).metab
LF(num).stealth=LF(c).stealth
LF(num).armor=LF(c).armor
LF(num).agility=LF(c).agility
LF(num).poison=LF(c).poison
LF(num).fangs=LF(c).fangs
LF(num).pounce=LF(c).pounce
LF(num).ID=TotalID
LF(num).img=I
`LF(num).L$=""=LF(c).l$
LF(num).chewing=0
LF(num).TX=rnd(600)+50
LF(num).TY=rnd(500)+50
LF(num).Eff=LF(c).Eff+rnd(4)-2
LF(num).FoodPref=rnd(2)+1
if mut=1
Mutate_Cell(num)
endif
IF LF(num).spd>499 THEN LF(num).spd=300+RND(100)
IF LF(num).size>499 THEN LF(num).size=300+RND(100)
IF LF(num).span>30000 THEN LF(num).span=30000-RND(2000)
IF LF(num).reproAGE<1000 THEN LF(num).reproAGE=1000+RND(50)
IF LF(num).reproNUT<800 THEN LF(num).reproNUT=800+RND(50)
IF LF(num).PRED>2500 THEN LF(num).PRED=2500-RND(100)
` IF LF(num).Eff>300 THEN LF(num).Eff=200+RND(100)
` a further limitation to speed is based on size:
if LF(num).spd>LF(num).size*3 then LF(num).spd=(LF(num).size*2)+rnd(LF(num).size)
IF LF(num).Eff>( (LF(num).spd+LF(num).size)/1.55 )
LF(num).Eff = ( (LF(num).spd+LF(num).size)/1.55 ) + rnd(20)-10
ENDIF
` write string 1,"the cell i spawned has image # "+str$(LF(num).img)
sprite num,LF(num).x,lf(num).y,LF(num).img
` rotate sprite num,(360/num)
scale sprite num,LF(num).size+1
` FIGURE METABOLISM NOW.
m=LF(num).spd + (LF(num).size/75)
m=m+(LF(num).stealth+LF(num).armor+LF(num).agility) : `*3
m=m+(LF(num).poison+LF(num).fangs+LF(num).pounce) : ` *5
` m=100
` this adjusts metabolism for EFFICIENCY
m=(m*100)/lf(num).Eff
lf(num).metab=m
if lf(num).metab>HiMetab then HiMetab=lf(num).metab
if lf(num).eff> HiEff then HiEff=lf(num).eff
endif
next t
Kill_Cell(c)
delete sprite c
Endfunction
Function Mutate_Cell(c)
Inc NumMutations
` this counts how many CELLS mutate, not necesssarily how many mutations
` occur (some cells do 2 mutations at a go)
` for now, ALL CHANGES ARE POSITIVE.
changes = 1 +( rnd(1)*rnd(1) )
` there are 14 things that can change during a mutation.
Done6=0
for t=1 to changes
repeat
x=rnd(13)
until Done6=0 or x<>6
mult=(rnd(1)*rnd(1))+1
` mult=1
select x
case 0
` speed and size are now capable of going DOWN to balance metabolism
if lf(c).spd<300 or rnd(2)=0
inc LF(c).spd,(rnd(9)+9)*mult
else
if lf(c).spd>200
dec LF(c).spd,((rnd(30)+30))
endif
endif
endcase
case 1
`if ( avgsize<300 or rnd(1)=0 ) and (supply>5 or rnd(1)=0)
if (rnd(avgsize)<300 or rnd(2)=0) and (supply>5 or rnd(1)=0)
inc LF(c).size,(rnd(10)+10)
else
if lf(c).size>125
dec LF(c).size,((rnd(30)+30))
endif
endif
endcase
case 2
inc LF(c).span,(rnd(100)+100)*mult
endcase
case 3
if LF(c).reproAGE>1000
dec LF(c).reproAGE,(50+rnd(50))*mult
endif
endcase
case 4
if LF(c).reproNUT>800
dec LF(c).reproNUT,(50+rnd(50))*mult
endif
endcase
case 5
` better metabolic efficiency
inc LF(c).Eff,10+rnd(10)
endcase
case 6
` halves your size when avg size is too big.
if AvgSize>300
if LF(c).size>150
LF(c).size=LF(c).size/2
dec t
Done6=1
` this gives them an extra advantage for losing so much size
endif
endif
endcase
case 7
inc LF(c).PRED,(99+rnd(99))*mult
endcase
case 8
`if rnd(LF(c).stealth)<2 then inc LF(c).stealth,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).stealth,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
case 9
`if rnd(LF(c).armor)<2 then inc LF(c).armor,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).armor,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
case 10
`if rnd(LF(c).agility)<2 then inc LF(c).agility,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).agility,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
case 11
`if rnd(LF(c).poison)<2 then inc LF(c).poison,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).poison,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
case 12
`if rnd(LF(c).fangs)<2 then inc LF(c).fangs,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).fangs,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
case 13
`if rnd(LF(c).pounce)<2 then inc LF(c).pounce,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
inc LF(c).pounce,1+(rnd(1)*rnd(1)*rnd(1)*rnd(1))
endcase
endselect
next t
Endfunction
Function Create_Drops()
col(5)=Rgb(0,128,0)
col(6)=Rgb(255,0,66)
col(7)=Rgb(128,0,192)
for t=5 to 7
CREATE BITMAP 1,24,24
SET CURRENT BITMAP 1
CLS
ink col(t),0
for u=t-4 to t+2
circle 12,12,u
next u
I=t+900 : ` 905,906,907
get image i,0,0,24,24,1
DELETE BITMAP 1
set current bitmap 0
next t
Endfunction
Function save_information(x)
if x<801
i(x).alive=alive
i(x).biodiversity=biodiversity
i(x).AvgSize=AvgSize
i(x).supply=supply
` i(x).stealth
` i(x).armor
` i(x).agility
` i(x).poison
` i(x).fangs
` i(x).pounce
endif
Endfunction
Function Draw_Information()
cls
hide all sprites
` line 0,100,800,100
text 0,102,"Alive"
` line 0,200,800,200
text 0,202,"Biodiversity"
` line 0,300,800,300
text 0,302,"Food Supply"
` line 0,500,800,500
text 0,552,"average size"
for t=1 to 800
line t-1,100-i(t-1).alive*2,t,100-i(t).alive*2
line t-1,200-i(t-1).biodiversity*4,t,200-i(t).biodiversity*4
line t-1,300-i(t-1).supply*4,t,300-i(t).supply*4
line t-1,550-(i(t-1).avgsize)/2,t,550-(i(t).avgsize)/2
next t
for t=1 to 7
line t*100,0,t*100,600
next t
sync
wait key
show all sprites
Endfunction
Function Create_Background()
create bitmap 1,800,600
set current bitmap 1
Recolorize(1)
box 0,0,800,600,col(1),col(3),col(4),col(3)
for t=1 to 15
x=rnd(900)-100
y=rnd(700)-100
w=rnd(150)+25
h=rnd(150)+25
` box x,y,x+w,y+h,col(1),col(3),col(4),col(3)
Recolorize(1)
box x,y,x+w,y+h,col(1),col(3),col(1),col(3)
next t
get image 1334,0,0,800,600,1
delete bitmap 1
set current bitmap 0
Endfunction
Function Recolorize(z)
repeat
a=50+rnd(185)
b=50+rnd(185)
c=50+rnd(185)
until abs(a-b)>30 or abs(b-c)>30
if z=1
a=a/3
b=b/3
c=c/3
endif
col(1)=rgb(a,b,c)
col(3)=rgb(c,a,b)
col(4)=rgb(b,c,a)
Endfunction