Advertisement
snake5

sgs-sdl - random loading screen prototype

Apr 1st, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. include "sgsxgmath";
  3.  
  4. global initialWidth = 1024;
  5. global initialHeight = 576;
  6.  
  7.  
  8. function initialize()
  9. {
  10.     global Window = SS_CreateWindow( "Fancy visualization [1]", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, initialWidth, initialHeight, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGLMAYBE );
  11.     Window.initRenderer( SS_RENDERER_DONTCARE, SS_RENDERER_DONTCARE, SS_RENDERER_VSYNC );
  12.    
  13.     global Font = SS_CreateFont( "familiar-pro-bold.otf", 32 );
  14.     global FontBig = SS_CreateFont( "familiar-pro-bold.otf", 64 );
  15.     global TxSpinner = SS_CreateTexture( "spinner.png", "mipmaps" );
  16.    
  17.     SS_InitDrawFunctions();
  18.    
  19.     global lasttime = ftime();
  20.     global T = 0;
  21.    
  22.     global particle_count = 100;
  23.     global particle_positions = floatarray_buffer( particle_count * 2 );
  24.     global particle_time_offsets = floatarray_buffer( particle_count );
  25.     particle_positions.randbox( vec2( 0, 0 ), vec2( 1024, 576 ) );
  26.     particle_time_offsets.randbox( 0.0, 32.0 );
  27. }
  28.  
  29. function update()
  30. {
  31.     global lasttime;
  32.     var curtime = ftime();
  33.     var delta = curtime - lasttime;
  34.     lasttime = curtime;
  35.     if( delta > 1.0/15.0 )
  36.         delta = 1.0/15.0;
  37.    
  38.     W = Window.width;
  39.     H = Window.height;
  40.    
  41.     SS_Clear( color(0.1,0.1,0.1) );
  42.     SS_SetCameraUI( 0, W, 0, H );
  43.    
  44.     global T;
  45.     T += delta;
  46.    
  47.     SS_DrawColor2VRect( 0, 0, W, H, 0.2, 0.2, 0.2, 1, 0.05, 0.05, 0.05, 1 );
  48.    
  49.     spdT = T * 1;
  50.     mpc0 = ( sin( spdT * 3 ) + sin( spdT * 5 ) + sin( spdT * 7 ) > 1.3 ) * 2.0;
  51.     mpc1 = ( sin( spdT * 2 ) + sin( spdT * 4 ) + sin( spdT * 5 ) > 1.3 ) * 2.0;
  52.     mpc2 = ( sin( spdT * 1 ) + sin( spdT * 3 ) + sin( spdT * 6 ) > 1.3 ) * 1.4;
  53.     SS_SetCamera2D( 1024/2 + mpc0 - mpc2, 576/2 + mpc1 - mpc2, 300-T*2, 1024/576, 0 );
  54.     for( i = 0; i < particle_count; ++i )
  55.     {
  56.         px = particle_positions[ i * 2 + 0 ];
  57.         py = particle_positions[ i * 2 + 1 ];
  58.         pq = sin( T + particle_time_offsets[ i ] ) * 0.5 + 0.5;
  59.         pq *= pq;
  60.         SS_DrawTextLine( "+", FontBig, px, py, color(1,1,1,0.25*pq) );
  61.     }
  62.     SS_SetCameraUI( 0, W, 0, H );
  63.    
  64.     textlen = T * 37 % 100 - 5;
  65.     if( textlen < 0 ) textlen = 0;
  66.     text = string_part( "Loading...", 0, textlen );
  67.     SS_DrawTextLine( text, Font, W - 192, H - 64, color(0.9,0.91,0.92,0.5) );
  68.     SS_Draw({ preset = "box", texture = TxSpinner, position = vec2(48,H-48), scale = vec2(48,48), angle = T * 2 });
  69.    
  70.     SS_Present();
  71. }
  72.  
  73. function on_event( e )
  74. {
  75.     if( e.type == SDL_QUIT )
  76.         global sys_exit = true;
  77. }
  78.  
  79. function cleanup()
  80. {
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement