|
The
following sections of code are designed to perform various functions within
the Doops ecosystem. If you have downloaded Gamemaker,
you can open up the source files and make your modifications. These bits of
code can be input as scripts, or code segments. Notice that if you have a
newer version of doops (the file name will begin
with either 2sp or 3sp), then these files are pre-included. You can jump to a certain
snippet, or scroll down to view: Plant respiration Plant parthenogenesis
Predator
movement |
|
|
{ global.plantwaste += 1 * self.health; if (global.plantwaste / 230400 > 0.2) {self.health
-= 0.02}; global.consuwaste -= 1 * health; if (global.consuwaste / 230400 > 0.03 and global.consuwaste > 0.0) {self.reptime -= 25 * (global.consuwaste / 230400)}; if (global.consuwaste <= 0.0) {self.reptime
+= 25 / health}; if (global.consuwaste < 0.0) {global.consuwaste
= 0.0}; } |
This
is what a respiration sequence for a plant could look like (it’s also what I’m currently using). One
drawback is that it assumes that plantwaste is
spread out equally through the entire ecosystem. |
|
{ //this creates
a new descendent plant, passing on the parent's characteristics //first,
decide if there's going to be a mutation. i = random(global.mutations); if (i <= 10.0){will_mute
= true}; //p_type = self.type; p_genome = self.genome; p_reptime = self.reptime; p_health = self.health; p_nutval = self.nutval; p_midage = self.midage; p_maxage = self.maxage; if (will_mute = false) //if mutations
are not to occur, child is identical to parent { //d_type = p_type; d_genome = p_genome; d_reptime = p_reptime; d_health =
1.0; d_nutval = p_nutval * (p_health * 2); //except for
the nutval, which depends on the parent's health d_midage = p_midage; d_maxage = p_maxage; } //end if false if (will_mute = true and random(global.mutations * 5) <= 10.0) { p = round(random(3) + 1); if (p = 1) {d_genome = 'plantA'}; if (p = 2) {d_genome = 'plantB'}; if (p = 3) {d_genome = 'plantC'}; if (p = 4) {d_genome = 'plantD'}; file_open_read(d_genome+'.gen'); file_readln(); d_reptime = file_read_real(); file_readln(); d_nutval = file_read_real(); file_readln(); d_midage = file_read_real(); file_readln(); d_maxage = file_read_real(); file_close(); d_health =
1.0; } //end if true
and highly unlikely occurrance takes place if (will_mute = true) //if mutations
are to occur, mutate just one attribute { i = random(5); if (i
< 1) {d_reptime = p_reptime
+ (random(50) - 25)}; if (i
> 1 and i < 2) {d_nutval = p_nutval + (random(50) - 25)}; if (i
> 2 and i < 3) {d_midage = p_midage + (random(50) - 25)}; if (i
> 3 and i < 4) {d_maxage = p_maxage + (random(50) - 25)}; if (i
> 4 and i < 5) {d_reptime = p_reptime + (random(50) - 25)}; d_health =
1.0; //the child's health is a constant--no crack babies d_genome = string(d_midage + d_maxage + d_reptime); //the genome is just a numeric
identifier. descendents of one genome will //have the same identifier,
unless they mutate (notice that the midage, maxage, //and reptime
variables will be the same for every creature of the same genome //at start, since the only
thing that can affect them is health, which is the same //for each newborn. } //end if true //then create
the instance //ALL EVENTS
AFTER instance_create //THE CHILD. YOU !!!CANNOT!!! PLACE SUBS IN THE CREATE EVENT FOR THE
CHILD. des1 = instance_create(random(20) - 9 + x, random(20) - 9 + y, grass_evo); des1.genome = d_genome; des1.reptime =
d_reptime; des1.health = d_health; des1.nutval = d_nutval; des1.midage = d_midage; des1.maxage = d_maxage; //there is a
small inherent chance that the plant will create two offspring i = ceil(random(5)) if (i < 2) { des2 = instance_create(random(40) - 18 + x, random(40) - 18 + y, grass_evo); des2.genome = d_genome; des2.reptime = d_reptime; des2.health = d_health; des2.nutval = d_nutval; des2.midage = d_midage; des2.maxage = d_maxage; } //if the plant
is near the equator (within 45 pixels +/- of Y=240) //then it
produces an extra descendent if (y < 285 and
y > 195) { des3 = instance_create(random(40) - 18 + x, random(40) - 18 + y, grass_evo); des3.genome = d_genome; des3.reptime = d_reptime; des3.health = d_health; des3.nutval = d_nutval; des3.midage = d_midage; des3.maxage = d_maxage; } }//end script |
This
next one is much more complicated (and I’ve left it commented for your
benefit). This
controls the sequence in which a new plant is created. First it reads the phenotypical information from the parent plant into
temporary variables. Then
it “rolls dice” to see if there will be a random genetic mutation. If the
“dice” come to a certain value, then it performs one modification, if not,
another, and so on. Later,
when creating the new plant, it writes the temporary variables into the
descendent, and then “rolls dice” again to see if a second child will be born
simultaneously (strictly speaking, this is closer to budding than simple unicellular
mitosis). In
this version, if the parent is located within the equatorial region, it is
assumed to have a reproductive advantage, and thus creates a second or third
child automatically. |
|
{ //Depending on
what TYPE the predator is, it will go after //a certain
prey. if (type >=
3.75) { mX = predator_evo.x; mY = predator_evo.y; move_towards_point(mX, mY, 6 * health); } //end if if (type <
3.75) { mininsname = instance_nearest(x, y, consumer_evo_seed); mX = mininsname.x; mY = mininsname.y; move_towards_point(mX, mY, 5.2 * health); } // end if //the next
segment accounts for when there is nothing to eat if (type <
3.75 and global.consupop <= 0) { mX = random(472) + 4; mY = random(472) + 4; move_towards_point(mX, mY, 4 * health); } //end if //check to
make sure coordinates aren't 0,0 (to eliminate crowding syndrome) if (mX = 0 and mY = 0) { mX = random(472) + 4; mY = random(472) + 4; move_towards_point(mX, mY, 4 * health); } //end if } //end code
segment |
Again,
this is a complicated script that I’ve left commented. This
section of code determines where a predatory creature will move, and how
quickly. It
first determines if the predator is cannibalistic or not, then determines
which prey creature is closest. Notice
that there are also extensive checks to make sure that even if there are no
other instances onscreen, it will still have a place to move to. These bits
of foresight are easily overlooked, and could easily, easily cause you
problems with your own code. Remember that no matter what you intend, the
code will do exactly as it’s told, and
only what it’s told. If you want to make sure your program accounts for
all possibilities, you have to make sure you think them all through, and
prepare for them. |