#include #include "video.h" #include // #define sint64 signed long long #define uint32 unsigned int #define sint32 signed int #define uint16 unsigned short #define sint16 signed short #define uint8 unsigned char #define sint8 signed char // const int c_ScreenWidth = 640; const int c_ScreenHeight = 480; // SDL_Surface *screen = NULL; // static inline void plot( int x, int y, int c ) { if ( x < 0 ) return; if ( y < 0 ) return; if ( x >= c_ScreenWidth ) return; if ( y >= c_ScreenHeight ) return; Uint32 *p = (Uint32*)screen->pixels; p += x + y * (screen->pitch >> 2); *p = c; } // bool start_sdl( void ) { // if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) return false; // screen = SDL_SetVideoMode ( c_ScreenWidth, c_ScreenHeight, 32, 0//SDL_FULLSCREEN ); return ( screen != NULL ); } // const float pi = 3.14159265359f; // const int nodeCount = 27; // struct sTentacle { float head; float girth; float friction; float muscleRange; float muscleFrequency; float tv; float theta; float count; float thetaMuscle; // float px; float py; // float x[ nodeCount ]; float y[ nodeCount ]; }; // float random( float range = 1.0f ) { float i = (float)( rand( ) & 0xFFFF ); i /= (float) 0xFFFF; i *= range; return i; } // const int snakeCount = 7; sTentacle snake[snakeCount]; // void generate( sTentacle *t ) { t->count = 0; t->theta = 0; t->tv = 0; t->thetaMuscle = 0; t->head = 2.0f + random( 4 ); t->girth = 8.0f + random( 12 ); t->friction = 0.9f + random( 10 ) / 100.0f; t->muscleRange = 20.0f + random( 50 ); t->muscleFrequency = 0.1f + random( 100 ) / 250.0f; // for ( int i=0; ix[i] = 0; t->y[i] = 0; } // t->px = -64; t->py = c_ScreenHeight/2 + random( 100 ); } // void update( sTentacle *t ) { // t->tv += 0.5f * (random() - random( )); t->theta += t->tv; t->tv *= t->friction; t->x[0] = t->head * cos( pi / 180 * t->theta ); t->y[0] = t->head * sin( pi / 180 * t->theta ); // t->count += t->muscleFrequency; t->thetaMuscle = t->muscleRange * sin( t->count ); // t->x[1] = -t->head * cos( pi / 180 * ( t->theta + t->thetaMuscle ) ); t->y[1] = -t->head * sin( pi / 180 * ( t->theta + t->thetaMuscle ) ); // for ( int i=2; ix[i] - t->x[i-2]; float dy = t->y[i] - t->y[i-2]; // float d = sqrtf( dx*dx + dy*dy ); // t->x[i] = t->x[i-1] + (dx * t->girth) / d; t->y[i] = t->y[i-1] + (dy * t->girth) / d; // setColour( 0xFFFFFF ); drawLine ( t->px + (int)t->x[i ], t->py + (int)t->y[i ], t->px + (int)t->x[i-1], t->py + (int)t->y[i-1] ); } drawCircle( t->px + t->x[0], t->py + t->y[0], 6 ); t->px -= t->x[1]; t->py -= t->y[1]; // if ( t->px > c_ScreenWidth + 200 ) generate( t ); } // bool tick_sdl( void ) { SDL_Event event; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case ( SDL_QUIT ): return false; case ( SDL_KEYDOWN ): if ( event.key.keysym.sym == SDLK_ESCAPE ) return false; if ( event.key.keysym.sym == SDLK_r ) { // for ( int i=0; i 33 ) { time += dt; break; } else { SDL_Delay( 1 ); } } // SDL_Flip( screen ); } // return 0; }