Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this code is written by Aidan Dodds 7/may/2013
- // do not reuse this code in anything commercial without my permission
- //
- int invaderSeed = 0;
- //
- char invader[] =
- {
- 0, 1, 1, 1, 0,
- 1, 0, 1, 0, 1,
- 1, 0, 1, 0, 1,
- 1, 1, 1, 1, 1,
- 1, 0, 1, 0, 1,
- };
- //
- uint32 g_noise = 0xDEADBABE;
- //
- static
- inline int myRand( void )
- {
- const uint32 taps = 0x80306031;
- sint32 l = g_noise;
- if (l & 0x1) l = (1 << 31) | ((l ^ taps) >> 1);
- else l = (l >> 1);
- g_noise = l;
- return l;
- }
- //
- void generateInvader( void )
- {
- //
- invaderSeed = g_noise;
- //
- for ( int i=0; i<5*5; i++ )
- invader[i] = 0;
- //
- for ( int y=0; y<5; y++ )
- {
- for ( int x=0; x<5; x++ )
- {
- if ( x < 3 )
- {
- // left side randomness
- invader[ x + y*5 ] = myRand( ) & 0x1;
- }
- else
- {
- // right side symmetry
- invader[ x + y*5 ] = invader[ (4-x) + y*5 ];
- }
- }
- }
- }
- //
- void drawInvader( int x, int y )
- {
- //
- draw_set_colour( invaderSeed );
- //
- for ( int i=0; i<5*5; i++ )
- {
- if ( invader[i] != 0 )
- {
- int tx = x + i % 5;
- int ty = y + i / 5;
- // plot a pixel
- draw_plot( tx, ty );
- }
- }
- }
- //
- void make_all_invaders( void )
- {
- draw_clear_screen( );
- //
- int x = 16;
- int y = 16;
- //
- while ( true )
- {
- generateInvader( );
- drawInvader( x, y );
- //
- if ( x + 7 > target->w - 16 )
- {
- x = 16;
- y += 7;
- //
- if ( y + 7 > target->h - 16 )
- break;
- }
- else
- //
- x += 7;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement