#include <math.h> #include <GL/glut.h> #include "globals.h" #include "dna.h" #include "brain.h" #include "thing.h" #include "animal.h" #include "lizard.h" Lizard::Lizard( DNA* dna ) :Animal( dna ) { } Lizard::~Lizard(void) { } void Lizard::Render() { glBegin( GL_POLYGON ); //Head SetHue( diet * 5.0 / 6.0 ); glVertex2f( x + A_R * cos( angle + 1.0 ), y + A_R * sin( angle + 1.0 ) ); glVertex2f( x + A_R * cos( angle - 1.0 ), y + A_R * sin( angle - 1.0 ) ); //Tail if ( settings.shade ) { if ( fighting && mating ) SetColor( Cyan ); //birth else if ( fighting ) SetColor( Magenta ); //overcrowding else if ( mating ) SetColor( Yellow ); //just married else SetColor( color ); } glVertex2f( x - A_R * cos( angle ), y - A_R * sin( angle ) ); glEnd(); if ( tagged && settings.wake ) { glBegin( GL_LINES ); glColor3f( 1, 1, 1 ); glVertex2f( x-A_R*1.5*cos(angle) + A_R*0.5, y-A_R*1.5*sin(angle) ); if ( settings.shade ) glColor3f( 0, 0, 0 ); glVertex2f( x-A_R*2.0*step*cos(angle)-A_R*1.5*cos(angle) + A_R*0.5, y-A_R*2.0*step*sin(angle)-A_R*1.5*sin(angle) ); glColor3f( 1, 1, 1 ); glVertex2f( x-A_R*1.5*cos(angle) - A_R*0.5, y-A_R*1.5*sin(angle) ); if ( settings.shade ) glColor3f( 0, 0, 0 ); glVertex2f( x-A_R*2.0*step*cos(angle)-A_R*1.5*cos(angle) - A_R*0.5, y-A_R*2.0*step*sin(angle)-A_R*1.5*sin(angle) ); glColor3f( 1, 1, 1 ); glVertex2f( x-A_R*1.5*cos(angle), y-A_R*1.5*sin(angle) + A_R*0.5 ); if ( settings.shade ) glColor3f( 0, 0, 0 ); glVertex2f( x-A_R*2.0*step*cos(angle)-A_R*1.5*cos(angle), y-A_R*2.0*step*sin(angle)-A_R*1.5*sin(angle) + A_R*0.5 ); glColor3f( 1, 1, 1 ); glVertex2f( x-A_R*1.5*cos(angle), y-A_R*1.5*sin(angle) - A_R*0.5 ); if ( settings.shade ) glColor3f( 0, 0, 0 ); glVertex2f( x-A_R*2.0*step*cos(angle)-A_R*1.5*cos(angle), y-A_R*2.0*step*sin(angle)-A_R*1.5*sin(angle) - A_R*0.5 ); glEnd(); } } void Lizard::See( float d2, Color c, float d, float a ) { float f = 1.0 - ( d2 - A_R * A_R ) / ( A_V * A_V - A_R * A_R ); float da = a - angle; if ( cos( da ) <= 0 ) return; //behind you int i; //Send input to appropriate neuron. // input[0] = plant // input[2] = same // input[4] = prey // input[6] = predator float dd = d - diet; if ( c == P_C ) i = 0; else if ( dd < -0.16 ) { i = 4; f *= -dd; } else if ( dd > 0.16 ) { i = 6; f *= dd; } else i = 2; if ( sin( da ) <= sin( A_A ) && sin( da ) >= sin( -A_L ) )//left { brain.input[i].axon += f; } if ( sin( da ) < sin( A_L ) && sin( da ) > sin( -A_A ) )//right { brain.input[i+1].axon += f; } } void Lizard::Step() { // Things get kind of sludgy in this ruleset, so decrease the amount // of energy needed to move, and increase the amount needed just to live Animal::Step(); float p = step < 0 ? A_B : 1.0; energy += step * A_M * A_S * p * 0.25; energy -= 3 * A_Z ; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 28901 | marc_tooley | "" | ||
#2 | 4902 | marc |
Working Genesaver under NetBSD.. . Fixed all default-level compiler warnings such as: .. Missing newline at end of files; .. Eliminating NULLs in non-pointer comparisons; .. Fixing all case inconsistencies; .. Added appropriate includes for math-functions under NetBSD; .. Added missing extern World *world pointers; .. #ifdef'd redefinition of NULL .. Deleted :) unnecessary sln/vcproj/scc clutter (shh don't tell Sam) . Submitting advanced long-ish term creature DNA as a cheat for the impatient. (Move Genes.txt out of the way to see them evolve right from the start.) . Added Jamfile for building an in-place executable called 'gene' . Added a build.sh script for users who don't have access to Jam. . Made it into standard resizeable window operation (no fullsc) . Removed winmain.cpp because we don't need it for UNIX! :) |
||
#1 | 4899 | marc |
branch from Stafford's genesaver Intent is to get it working under NetBSD, my (current) favourite OS. |
||
//guest/sam_stafford/genesaver/src/Lizard.cpp | |||||
#1 | 3052 | Sam Stafford |
Add Genesaver to the Public Depot. It's not in any way Perforce-related, but it does share a bit of code with Jamgraph, and it feels strange to have an open-source project that's not in the PD. |