Beispiel #1
0
static int l_new( lua_State* L )
{
  rl_sprite_t** self = (rl_sprite_t**)lua_newuserdata( L, sizeof( rl_sprite_t* ) );
  
  *self = rl_sprite_create();
  
  if ( !*self )
  {
    return luaL_error( L, "sprite limit reached" );
  }
  
  ( *self )->layer = 100;
  
  if ( luaL_newmetatable( L, "image" ) != 0 )
  {
    static const luaL_Reg methods[] =
    {
      { "__index",    l_index },
      { "__newindex", l_newindex },
      { "__tostring", l_tostring },
      { "__gc",       l_gc },
      { NULL, NULL }
    };
    
    luaL_setfuncs( L, methods, 0 );
  }

  lua_setmetatable( L, -2 );
  return 1;
}
Beispiel #2
0
bool retro_load_game( const struct retro_game_info* info )
{
  enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
  
  if ( !env_cb( RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt ) )
  {
    log_cb( RETRO_LOG_ERROR, "retroluxury needs RGB565\n" );
    return false;
  }
  
  rl_image_init();
  rl_sprite_init();
  
  if ( rl_backgrnd_create( WIDTH, HEIGHT, RL_BACKGRND_EXACT ) != 0 )
  {
    log_cb( RETRO_LOG_ERROR, "Error creating the framebuffer\n" );
    return false;
  }
  
  rl_backgrnd_clear( RL_COLOR( 64, 64, 64 ) );
  
  if ( rl_imgdata_create( &state.imgdata, res_smile_png, sizeof( res_smile_png ) ) != 0 )
  {
    log_cb( RETRO_LOG_ERROR, "Error loading image smile.png\n" );
error1:
    rl_backgrnd_destroy();
    return false;
  }
  
  if ( rl_image_create( &state.image, &state.imgdata, 0, 0 ) != 0 )
  {
    log_cb( RETRO_LOG_ERROR, "Error creating RLE-image\n" );
error2:
    rl_imgdata_destroy( &state.imgdata );
    goto error1;
  }
  
  for ( unsigned i = 0; i < COUNT; i++ )
  {
    rl_sprite_t* sprite = rl_sprite_create();
    
    if ( sprite == NULL )
    {
      log_cb( RETRO_LOG_ERROR, "Error creating sprite %u of %u\n", i, COUNT );
error3:
      rl_image_destroy( &state.image );
      
      for ( i = 0; i < COUNT; i++ )
      {
        if ( state.smiles[ i ].sprite != NULL )
        {
          rl_sprite_destroy( state.smiles[ i ].sprite );
        }
      }
      
      goto error2;
    }
    
    sprite->x = rand() % ( WIDTH - state.imgdata.width + 1 );
    sprite->y = rand() % ( HEIGHT - state.imgdata.height + 1 );
    sprite->layer = i;
    sprite->image = &state.image;
    
    state.smiles[ i ].sprite = sprite;
    state.smiles[ i ].dx = rand() & 1 ? -1 : 1;
    state.smiles[ i ].dy = rand() & 1 ? -1 : 1;
  }
  
  state.music = rl_sound_play_ogg( res_sketch008_ogg, sizeof( res_sketch008_ogg ), 1, NULL );
  
  if ( state.music == NULL )
  {
    log_cb( RETRO_LOG_ERROR, "Error loading music sketch008.ogg\n" );
    goto error3;
  }
  
  if ( rl_snddata_create( &state.snddata, res_bounce_wav, sizeof( res_bounce_wav ) ) != 0 )
  {
    log_cb( RETRO_LOG_ERROR, "Error loading wave bounce.wav\n" );
error4:
    rl_sound_stop( state.music );
    goto error3;
  }
  
  if ( rl_sound_create( &state.sound, &state.snddata ) != 0 )
  {
    log_cb( RETRO_LOG_ERROR, "Error creating PCM data\n" );
//error5:
    rl_snddata_destroy( &state.snddata );
    goto error4;
  }
  
  return true;
}