cmp_plot3x3
[fishladder.git] / fishladder.c
index e671208e560f6c6558f04c061d84ee72ab7bf3b2..08406bc8acd2a19ca65de60b58247b0fa9286087 100644 (file)
@@ -14,10 +14,9 @@ enum world_button_mode
 struct world_button
 {
        v2i position;
-       v3f colour;
 
-       float light_target, light;
-       int state, click_grab;
+       float light_target, light, extra_light;
+       int state;
 
        enum world_button_mode mode;
 };
@@ -62,7 +61,14 @@ enum e_world_button
        k_world_button_none = -1,
        k_world_button_sim = 0,
        k_world_button_pause = 1,
-       k_world_button_speedy = 2
+       k_world_button_speedy = 2,
+       k_world_button_settings = 3
+};
+
+enum e_game_state
+{
+       k_game_state_main,
+       k_game_state_settings
 };
 
 #define FLAG_CANAL             0x1
@@ -185,33 +191,22 @@ struct
 }
 text_buffers;
 
-struct world_static
+static struct world
 {
-       struct world_button buttons[4];
-}
-world_static =
-{
-       .buttons = {
-               {
-                       .colour = { 0.204f, 0.345f, 0.553f },
-                       .mode = k_world_button_mode_toggle
-               },
-               {
-                       .colour = { 0.204f, 0.345f, 0.553f },
-                       .mode = k_world_button_mode_toggle
-               },
-               {
-                       .colour = { 0.553f, 0.345f, 0.204f },
-                       .mode = k_world_button_mode_toggle
-               },
-               {
-                       // TODO: Settings button and menu
-               }
+       // Things that are 'static', aka, initialized once
+       struct
+       {
+               struct world_button buttons[4];
+               float zoom;
+               enum e_game_state state;
+
+               struct cmp_level *lvl_to_load;
+               float lvl_load_time;
+
+               float world_transition;
        }
-};
+       st;
 
-struct world
-{
 #pragma pack(push,1)
        struct cell
        {
@@ -224,7 +219,6 @@ struct world
 #pragma pack(pop)
        
        int initialzed;
-       
        int sim_run, max_runs;
 
        int sim_frame, sim_target;
@@ -285,7 +279,6 @@ struct world
        int num_fishes;
        
        char map_name[64];
-       //struct career_level *ptr_career_level;
        struct cmp_level *pCmpLevel;
        
        u32 score;
@@ -295,6 +288,16 @@ struct world
        u16 id_drag_from;
        v2f drag_from_co;
        v2f drag_to_co;
+}
+world = 
+{
+       .st = 
+       {
+               .buttons = { { .mode = k_world_button_mode_toggle },
+                       { .mode = k_world_button_mode_toggle },
+                       { .mode = k_world_button_mode_toggle },
+                       { .mode = k_world_button_mode_toggle } }
+       }
 };
 
 // Forward declerations
@@ -380,8 +383,6 @@ m3x3f m_projection;
 m3x3f m_view;
 m3x3f m_mdl;
 
-struct world world;
-
 // UTILITY
 // ===========================================================================================================
 
@@ -928,7 +929,14 @@ static int map_load( const char *str, const char *name )
                        {
                                u8 *px = &info_buffer[((x*64)+y)*4];
                                
-                               px[0] = 0xFF-0x3F + hash21i( (v2i){x,y}, 0x3F );
+                               // Fade out edges of world so that there isnt an obvious line
+                               int dist_x = 16 - VG_MIN( VG_MIN( x, 16 ), 16-VG_MAX( x-16-world.w, 0 ) );
+                               int dist_y = 16 - VG_MIN( VG_MIN( y, 16 ), 16-VG_MAX( y-16-world.h, 0 ) );
+                               int dist = VG_MAX( dist_x, dist_y ) * 16;
+
+                               int value = VG_MAX( 0, 0xFF-0x3F + hash21i( (v2i){x,y}, 0x3F ) - dist );
+                               
+                               px[0] = value;
                                px[1] = 0;
                                px[2] = 0;
                                px[3] = 0;
@@ -940,13 +948,21 @@ static int map_load( const char *str, const char *name )
                for( int i = 0; i < vg_list_size( career_packs ); i ++ )
                {
                        struct career_level_pack *grid = &career_packs[ i ];
-                       
+               
+                       int j = 0;
+
                        for( int y = 0; y < grid->dims[1]; y ++ )
                        {
                                for( int x = 0; x < grid->dims[0]; x ++ )
                                {
                                        u8 *px = &info_buffer[((y+16+grid->origin[1])*64+16+x+grid->origin[0])*4];
                                        px[0] = 0x10;
+
+                                       if( j < grid->count )
+                                       {
+                                               struct cmp_level *lvl = &grid->pack[ j ++ ];
+                                               v2i_add( grid->origin, (v2i){x,y}, lvl->btn.position );
+                                       }
                                }
                        }
                }
@@ -962,6 +978,10 @@ static int map_load( const char *str, const char *name )
                        v2i turtle;
                        v2i turtle_dir;
                        int original_y;
+
+                       // Only make breakouts for terminals on the edge
+                       if( !(term->pos[1] == 1 || term->pos[1] == world.h-2) )
+                               continue;
                        
                        turtle[0] = 16+term->pos[0];
                        turtle[1] = 16+term->pos[1];
@@ -1057,9 +1077,9 @@ static int map_load( const char *str, const char *name )
        world.initialzed = 1;
 
        // Setup world button locations
-       for( int i = 0; i < vg_list_size( world_static.buttons ); i ++ )
+       for( int i = 0; i < vg_list_size( world.st.buttons ); i ++ )
        {
-               struct world_button *btn = &world_static.buttons[i];
+               struct world_button *btn = &world.st.buttons[i];
                btn->position[0] = world.w -1;
                btn->position[1] = world.h -i -2;
        }
@@ -1318,7 +1338,7 @@ static void career_load(void)
 // ===========================================================================================================
 static int is_simulation_running(void)
 {
-       return world_static.buttons[ k_world_button_sim ].state;
+       return world.st.buttons[ k_world_button_sim ].state;
 }
 
 static void clear_animation_flags(void)
@@ -1329,8 +1349,8 @@ static void clear_animation_flags(void)
 
 static void simulation_stop(void)
 {
-       world_static.buttons[ k_world_button_sim ].state = 0;
-       world_static.buttons[ k_world_button_pause ].state = 0;
+       world.st.buttons[ k_world_button_sim ].state = 0;
+       world.st.buttons[ k_world_button_pause ].state = 0;
        
        world.num_fishes = 0;
        world.sim_frame = 0;
@@ -1356,7 +1376,7 @@ static void simulation_start(void)
        world.sim_frame = 0;
        world.sim_run = 0;
        
-       world.sim_delta_speed = world_static.buttons[ k_world_button_speedy ].state? 10.0f: 2.5f;
+       world.sim_delta_speed = world.st.buttons[ k_world_button_speedy ].state? 10.0f: 2.5f;
        world.sim_delta_ref = vg_time;
        world.sim_internal_ref = 0.0f;
        world.sim_internal_time = 0.0f;
@@ -1464,8 +1484,29 @@ static int cell_interactive( v2i co )
        return 1;
 }
 
-void vg_update(void)
+static void vg_update(void)
 {
+       // Async events
+       if( world.st.lvl_to_load )
+       {
+               world.st.world_transition = (world.st.lvl_load_time-vg_time) * 4.0f;
+
+               if( vg_time > world.st.lvl_load_time )
+               {       
+                       if( console_changelevel( 1, &world.st.lvl_to_load->map_name ) )
+                       {
+                               world.pCmpLevel = world.st.lvl_to_load;
+                               gen_level_text( world.pCmpLevel );
+                       }
+
+                       world.st.lvl_to_load = NULL;
+               }
+       }
+       else
+       {
+               world.st.world_transition = vg_minf( 1.0f, (vg_time-world.st.lvl_load_time) * 4.0f );
+       }
+
        // Camera
        // ========================================================================================================
        
@@ -1475,17 +1516,28 @@ void vg_update(void)
        
        static float size_current = 2.0f;
        static v3f origin_current = { 0.0f, 0.0f, 0.0f };
+       static v2f drag_offset = { 0.0f, 0.0f };
+       static v2f view_point = { 0.0f, 0.0f };
+       v2f result_view;
+
+       size = ( r2 < r1? (float)(world.w+5) * 0.5f: ((float)(world.h+5) * 0.5f) / r1 ) + 0.5f;
        
-       size = ( r2 < r1? (float)(world.w+5) * 0.5f: ((float)(world.h+5) * 0.5f) / r1 ) + 0.5f; 
-       
-       v3f origin;
+       v2f origin;
+       v2f vt_target;
+
        origin[0] = floorf( -0.5f * ((float)world.w-4.5f) );
        origin[1] = floorf( -0.5f * world.h );
-       origin[2] = 0.0f;
        
+       // Create and clamp result view
+       v2_add( view_point, drag_offset, result_view );
+       result_view[0] = vg_clampf( result_view[0], -world.st.zoom, world.st.zoom );
+       result_view[1] = vg_clampf( result_view[1], -world.st.zoom*r1, world.st.zoom*r1 );
+       
+       v2_add( origin, result_view, vt_target );
+
        // Lerp towards target
-       size_current = vg_lerpf( size_current, size, vg_time_delta * 6.0f );
-       v2_lerp( origin_current, origin, vg_time_delta * 6.0f, origin_current ); 
+       size_current = vg_lerpf( size_current, size - world.st.zoom, vg_time_delta * 6.0f );
+       v2_lerp( origin_current, vt_target, vg_time_delta * 6.0f, origin_current ); 
        
        m3x3_projection( m_projection, -size_current, size_current, -size_current*r1, size_current*r1 );
        m3x3_identity( m_view );
@@ -1500,6 +1552,50 @@ void vg_update(void)
        world.tile_x = floorf( world.tile_pos[0] );
        world.tile_y = floorf( world.tile_pos[1] );
 
+       // Camera dragging
+       {
+               static v2f drag_origin; // x/y pixel
+
+               if( vg_get_button_down( "tertiary" ) )
+                       v2_copy( vg_mouse, drag_origin );
+               else if( vg_get_button( "tertiary" ) )
+               {
+                       // get offset
+                       v2_sub( vg_mouse, drag_origin, drag_offset );
+                       v2_div( drag_offset, (v2f){ vg_window_x, vg_window_y }, drag_offset );
+                       v2_mul( drag_offset, (v2f){ size_current*2.0f, -size_current*r1*2.0f }, drag_offset );
+               }
+               else
+               {
+                       v2_copy( result_view, view_point );
+                       v2_copy( (v2f){0.0f,0.0f}, drag_offset );
+               }
+       }
+
+       // Zooming
+       {
+               v2f mview_local;
+               v2f mview_new;
+               v2f mview_cur;
+               v2f mview_delta;
+               float rsize;
+
+               rsize = size-world.st.zoom;
+
+               v2_div( vg_mouse, (v2f){ vg_window_x*0.5f, vg_window_y*0.5f }, mview_local );
+               v2_add( (v2f){ -rsize, -rsize*r1 }, (v2f){ mview_local[0]*rsize, (2.0f-mview_local[1])*rsize*r1 }, mview_cur );
+
+               world.st.zoom = vg_clampf( world.st.zoom + vg_mouse_wheel[1], 0.0f, size - 4.0f );
+
+               // Recalculate new position
+               rsize = size-world.st.zoom;
+               v2_add( (v2f){ -rsize, -rsize*r1 }, (v2f){ mview_local[0]*rsize, (2.0f-mview_local[1])*rsize*r1 }, mview_new );
+
+               // Apply offset
+               v2_sub( mview_new, mview_cur, mview_delta );
+               v2_add( mview_delta, view_point, view_point );
+       }
+       
        // Tilemap
        // ========================================================================================================
        if( !is_simulation_running() && !gui_want_mouse() )
@@ -1634,7 +1730,7 @@ void vg_update(void)
        {       
                float old_time = world.sim_internal_time;
        
-               if( !world_static.buttons[ k_world_button_pause ].state )
+               if( !world.st.buttons[ k_world_button_pause ].state )
                        world.sim_internal_time = world.sim_internal_ref + (vg_time-world.sim_delta_ref) * world.sim_delta_speed;
                else
                        world.sim_internal_time = vg_lerpf( world.sim_internal_time, world.sim_internal_ref + world.pause_offset_target, vg_time_delta*15.0f );
@@ -1880,7 +1976,7 @@ void vg_update(void)
                                        {
                                                fj = &world.fishes[j];
                                                
-                                               if( (fj->state == k_fish_state_alive) )
+                                               if( fj->state == k_fish_state_alive )
                                                {
                                                        v2i fi_prev;
                                                        v2i fj_prev;
@@ -2005,7 +2101,7 @@ void vg_update(void)
                                                world.sim_delta_ref = vg_time;
                                                world.sim_internal_ref = 0.0f;
                                                
-                                               if( world_static.buttons[ k_world_button_pause ].state )
+                                               if( world.st.buttons[ k_world_button_pause ].state )
                                                        world.pause_offset_target = 0.5f;
                                                else
                                                        world.pause_offset_target = 0.0f;
@@ -2206,10 +2302,22 @@ static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f cons
        }
 }
 
-static int world_button_exec( struct world_button *btn, v2f texture, enum world_button_status *status )
+static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, enum world_button_status *status )
 {
+       static v2i click_grab = { -9999, -9999 };
+
+       // Reset click_grab
+       if( !btn )
+       {
+               click_grab[0] = -9999;
+               click_grab[1] = -9999;
+               return 0;
+       }
+
+       v2i click_tile = { world.tile_x, world.tile_y };
+
        int triggered = 0;
-       int is_hovering = v2i_eq( (v2i){ world.tile_x, world.tile_y }, btn->position );
+       int is_hovering = v2i_eq( click_tile, btn->position );
 
        // Set up light targets before logic runs
        if( btn->state )
@@ -2224,10 +2332,8 @@ static int world_button_exec( struct world_button *btn, v2f texture, enum world_
        if( is_hovering )
        {
                if( vg_get_button_down( "primary" ) && is_hovering )
-               {
-                       btn->click_grab = 1;
-               }
-               else if( btn->click_grab && vg_get_button_up( "primary" ) )
+                       v2i_copy( click_tile, click_grab );
+               else if( v2i_eq( click_grab, click_tile ) && vg_get_button_up( "primary" ) )
                {
                        // Click event
                        *status = btn->state? k_world_button_on_disable: k_world_button_on_enable;
@@ -2239,15 +2345,13 @@ static int world_button_exec( struct world_button *btn, v2f texture, enum world_
                        triggered = 1;
                }
        }
-       if( vg_get_button_up( "primary" ) )
-               btn->click_grab = 0;
 
        // Drawing stage
        v4f final_colour;
        
-       btn->light = vg_lerpf( btn->light, btn->light_target, vg_time_delta*26.0f );
+       btn->light = vg_lerpf( btn->light, btn->light_target + btn->extra_light, vg_time_delta*26.0f );
 
-       v3_copy( btn->colour, final_colour );
+       v3_copy( colour, final_colour );
        final_colour[3] = btn->light;
 
        glUniform4f( SHADER_UNIFORM( shader_buttons, "uOffset" ),
@@ -2262,235 +2366,55 @@ static int world_button_exec( struct world_button *btn, v2f texture, enum world_
        return triggered;
 }
 
-/*
-static void wbutton_run( enum e_world_button btn_name, v2f btn_tex )
-{
-       static v3f button_colours[] = {
-               {0.204f, 0.345f, 0.553f},
-               {0.204f, 0.345f, 0.553f},
-               {0.553f, 0.345f, 0.204f},
-               {1.0f, 0.0f, 0.0f}
-       };
-
-       struct cell_button *btn = &world.buttons[btn_name];
-       
-       // Interaction
-       int tex_offset = 0;
-       
-       int is_hovering = (world.tile_x == world.w-1 && world.tile_y == world.h-btn_name-2)?1:0;        
-       if( vg_get_button_up( "primary" ) && is_hovering )
-       {
-               // Click event
-               if( btn_name == k_world_button_sim )
-               {
-                       if( world.buttons[ k_world_button_pause ].pressed )
-                       {
-                               if( !btn->pressed )
-                               {
-                                       btn->pressed = 1;
-                                       simulation_start();
-                                       
-                                       world.pause_offset_target = 0.5f;
-                               }
-                               else
-                                       world.pause_offset_target += 1.0f;
-                       }
-                       else
-                       {
-                               btn->pressed ^= 0x1;
-                               
-                               if( btn->pressed )
-                                       simulation_start();
-                               else
-                                       simulation_stop();
-                       }
-               }
-               else if( btn_name == k_world_button_pause )
-               {
-                       btn->pressed ^= 0x1;
-               
-                       world.sim_internal_ref = world.sim_internal_time;
-                       world.sim_delta_ref = vg_time;
-                       
-                       if( btn->pressed )
-                       {
-                               float time_frac = world.sim_internal_time-floorf(world.sim_internal_time);
-                               world.pause_offset_target = 0.5f - time_frac;
-                       }
-                       else
-                               world.pause_offset_target = 0.0f;
-               }
-               else if( btn_name == k_world_button_speedy )
-               {
-                       btn->pressed ^= 0x1;
-                       
-                       world.sim_delta_speed = btn->pressed? 10.0f: 2.5f;
-                       world.sim_delta_ref = vg_time;
-                       world.sim_internal_ref = world.sim_internal_time;
-               }
-               else
-               {
-                       btn->pressed ^= 0x1;
-               }
-               
-               sfx_set_play( &audio_clicks, &audio_system_ui, btn->pressed?1:0 );
-       }
-       
-       // Drawing
-       if( btn->pressed ) 
-       {
-               if( is_hovering )
-               {
-                       btn->light_target = 0.9f;
-               }
-               else
-               {
-                       if( btn_name == k_world_button_sim && world.buttons[ k_world_button_pause ].pressed )
-                               btn->light_target = fabsf(sinf( vg_time * 2.0f )) * 0.3f + 0.3f;
-                       else
-                               btn->light_target = 0.8f;
-               }
-       }
-       else 
-       {
-               btn->light_target = is_hovering? 0.2f: 0.0f;
-       }
-
-       if( vg_get_button( "primary" ) && is_hovering )
-               btn->light_target = 1.0f;
-       
-       btn->light = vg_lerpf( btn->light, btn->light_target, vg_time_delta*26.0f );
-       
-       // Draw
-       if( btn_name == k_world_button_sim && world.buttons[ k_world_button_sim ].pressed )
-       {
-               if( world.buttons[ k_world_button_pause ].pressed )
-                       tex_offset = 3;
-               else
-                       tex_offset = 2;
-       }
-       
-       v4f final_colour;
-       v3_copy( button_colours[ btn_name ], final_colour );
-       final_colour[3] = btn->light;
-       
-       glUniform4f( SHADER_UNIFORM( shader_buttons, "uOffset" ), 
-               world.w-1, 
-               world.h-btn_name-2, 
-               (float)(btn_tex[0]+tex_offset), 
-               btn_tex[1]
-       );
-       glUniform4fv( SHADER_UNIFORM( shader_buttons, "uColour" ), 1, final_colour );
-       
-       draw_mesh( 0, 2 );
-}
-
-static void wbutton_draw( v2i pos, v2f tex, v4f colour )
-{
-       glUniform4f( SHADER_UNIFORM( shader_buttons, "uOffset" ), 
-               pos[0], 
-               pos[1], 
-               tex[0], 
-               tex[1] 
-       );
-       glUniform4fv( SHADER_UNIFORM( shader_buttons, "uColour" ), 1, colour );
-       draw_mesh( 0, 2 );
-}
-*/
-
 static void level_selection_buttons(void)
 {
        v3f tutorial_colour = { 0.204f, 0.345f, 0.553f };
        v3f locked_colour = { 0.2f, 0.2f, 0.2f };
-       
-       v4f final_colour = { 0.0f, 0.0f, 0.0f, 0.2f };
-       v2i button_pos;
-       static struct cmp_level *select_from = NULL;
+
        struct cmp_level *switch_level_to = NULL;
-       
-       if( vg_get_button_down( "primary" ) )
-               select_from = NULL;
-       
+
        for( int i = 0; i < vg_list_size( career_packs ); i ++ )
        {
                struct career_level_pack *grid = &career_packs[i];
                
-               int j = 0;
-               
-               for( int x = 0; x < grid->dims[0]; x ++ )
+               for( int j = 0; j < grid->count; j ++ )
                {
-                       for( int y = 0; y < grid->dims[1]; y ++ )
-                       {
-                               if( j < grid->count )
-                               {
-                                       struct cmp_level *lvl = &grid->pack[ j ];
-                                       
-                                       // Determine colour
-                                       if( lvl->unlocked )
-                                       {
-                                               if( lvl->is_tutorial )
-                                                       v3_copy( tutorial_colour, final_colour );
-                                               else
-                                                       v3_copy( grid->primary_colour, final_colour );
-                                                       
-                                               if( lvl->completed_score )
-                                                       final_colour[3] = 0.8f;
-                                               else
-                                                       final_colour[3] = 0.2f;
-                                       }
-                                       else 
-                                       {
-                                               v3_copy( locked_colour, final_colour );
-                                               final_colour[3] = 0.2f;
-                                       }
-                                       
-                                       v2i_add( grid->origin, (v2i){ x,y }, button_pos );
-                                       int is_hovering = v2i_eq( (v2i){world.tile_x, world.tile_y}, button_pos );
-                               
-                                       if( is_hovering )
-                                       {
-                                               final_colour[3] += 0.1f;
-                                               
-                                               // Up click
-                                               if( vg_get_button_up( "primary" ) )
-                                                       if( select_from == lvl && lvl->unlocked )
-                                                       {
-                                                               switch_level_to = lvl;
-                                                               sfx_set_play( &audio_clicks, &audio_system_ui, 1 );
-                                                       }
-                                               
-                                               // Start click
-                                               if( vg_get_button_down( "primary" ) )
-                                                       select_from = lvl;
-                                               
-                                               if( vg_get_button( "primary" ) )
-                                                       final_colour[3] += 0.2f;
-                                       }
-                                       
-                                       if( world.pCmpLevel == lvl )
-                                       {
-                                               final_colour[3] += 0.15f + fabsf(sinf( vg_time * 2.0f )) * 0.05f;
-                                               
-                                               if( lvl->completed_score )
-                                                       final_colour[3] += 0.1f;
-                                       }
-                                       
-                                       //wbutton_draw( (v2i){ grid->origin[0] + x, grid->origin[1] + y }, tex_coord, final_colour );
-                               }
-                               else break;
+                       struct cmp_level *lvl = &grid->pack[ j ];
                                
-                               j ++;
+                       if( world.pCmpLevel == lvl )
+                               lvl->btn.extra_light = 0.35f + fabsf(sinf( vg_time * 2.0f )) * 0.05f;   
+                       else lvl->btn.extra_light = 0.2f;
+                       
+                       if( lvl->completed_score )
+                               lvl->btn.extra_light += 0.8f;
+                       
+                       enum world_button_status status;
+                       if( world_button_exec( 
+                               &lvl->btn, 
+                               (v2f){0.0f,0.0f}, 
+                               lvl->unlocked? (lvl->is_tutorial? tutorial_colour: grid->primary_colour): locked_colour,
+                               &status 
+                       ))
+                       {
+                               if( status == k_world_button_on_enable && lvl->unlocked )
+                                       switch_level_to = lvl;
                        }
                }
        }
        
        if( switch_level_to )
        {
+               world.st.lvl_to_load = switch_level_to;
+               world.st.lvl_load_time = vg_time + 0.25f;
+               world.st.world_transition = 1.0f;
+
+               /*
                if( console_changelevel( 1, &switch_level_to->map_name ) )
                {
                        world.pCmpLevel = switch_level_to;
                        gen_level_text( world.pCmpLevel );
                }
+               */
        }
 }
 
@@ -2531,7 +2455,7 @@ void vg_render(void)
        glActiveTexture( GL_TEXTURE1 );
        glBindTexture( GL_TEXTURE_2D, world.random_samples );
        glUniform1i( SHADER_UNIFORM( shader_background, "uSamplerNoise" ), 1 );
-       glUniform1f( SHADER_UNIFORM( shader_background, "uVisibility" ), 1.0f ); // (sinf( vg_time ) + 1.0f) * 0.5f );
+       glUniform1f( SHADER_UNIFORM( shader_background, "uVisibility" ), 1.0f ); //world.st.world_transition );
 
        draw_mesh( 0, 2 );
        
@@ -2546,7 +2470,7 @@ void vg_render(void)
        glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
        glUniform1f( SHADER_UNIFORM( shader_tile_main, "uGhost" ), 0.0f );
        glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 0.0f );
-       glUniform1f( SHADER_UNIFORM( shader_tile_main, "uVisibility" ), 2.0f ); // sinf( vg_time ) + 1.0f );
+       glUniform1f( SHADER_UNIFORM( shader_tile_main, "uVisibility" ), world.st.world_transition * 2.0f );
        
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -2569,7 +2493,7 @@ void vg_render(void)
        vg_tex2d_bind( &tex_ball_noise, 0 );
        glUniform1i( SHADER_UNIFORM( shader_ball, "uTexMain" ), 0 );
        
-       if( world_static.buttons[ k_world_button_sim ].state )
+       if( world.st.buttons[ k_world_button_sim ].state )
        {
                for( int i = 0; i < world.num_fishes; i ++ )
                {
@@ -2697,12 +2621,15 @@ void vg_render(void)
        glUniform1i( SHADER_UNIFORM( shader_buttons, "uTexMain" ), 0 );
        
        enum world_button_status stat;
-       int world_paused = world_static.buttons[k_world_button_pause].state;
-       int world_running = world_static.buttons[k_world_button_sim].state;
+       int world_paused = world.st.buttons[k_world_button_pause].state;
+       int world_running = world.st.buttons[k_world_button_sim].state;
 
        float sim_icon_x = world_paused? 3.0f: (world_running? 2.0f: 0.0f);
 
-       if( world_button_exec( &world_static.buttons[k_world_button_sim], (v2f){ sim_icon_x, 3.0f }, &stat ))
+       v3f btn_dark_blue = { 0.204f, 0.345f, 0.553f };
+       v3f btn_orange = { 0.553f, 0.345f, 0.204f };
+
+       if( world_button_exec( &world.st.buttons[k_world_button_sim], (v2f){ sim_icon_x, 3.0f }, btn_dark_blue, &stat ))
        {
                if( stat == k_world_button_on_enable )
                {
@@ -2717,7 +2644,7 @@ void vg_render(void)
                        {
                                // Trigger single step
                                world.pause_offset_target += 1.0f;
-                               world_static.buttons[k_world_button_sim].state = 1;
+                               world.st.buttons[k_world_button_sim].state = 1;
                        }
                        else
                        {
@@ -2726,7 +2653,7 @@ void vg_render(void)
                }
        }
        
-       if( world_button_exec( &world_static.buttons[k_world_button_pause], (v2f){ 1.0f, 3.0f }, &stat ))
+       if( world_button_exec( &world.st.buttons[k_world_button_pause], (v2f){ 1.0f, 3.0f }, btn_dark_blue, &stat ))
        {
                world.sim_internal_ref = world.sim_internal_time;
                world.sim_delta_ref = vg_time;
@@ -2740,7 +2667,7 @@ void vg_render(void)
                        world.pause_offset_target = 0.0f;
        }
 
-       if( world_button_exec( &world_static.buttons[k_world_button_speedy], (v2f){ 0.0f, 2.0f }, &stat ))
+       if( world_button_exec( &world.st.buttons[k_world_button_speedy], (v2f){ 0.0f, 2.0f }, btn_orange, &stat ))
        {
                world.sim_delta_speed = stat == k_world_button_on_enable? 10.0f: 2.5f;
                
@@ -2751,8 +2678,16 @@ void vg_render(void)
                }
        }
 
+       if( world_button_exec( &world.st.buttons[k_world_button_settings], (v2f){ 1.0f, 2.0f }, btn_orange, &stat ))
+       {
+               world.st.state = stat == k_world_button_on_enable? k_game_state_settings: k_game_state_main;    
+       }
+
        level_selection_buttons();
        
+       if( vg_get_button_up( "primary" ) )
+               world_button_exec( NULL, NULL, NULL, NULL );
+
        // TEXT ELEMENTS
        // ========================================================================================================
        SHADER_USE( shader_sdf );
@@ -3224,8 +3159,10 @@ static int console_changelevel( int argc, char const *argv[] )
        {
                // Save current level
                console_save_map( 0, NULL );
+               
                if( console_load_map( argc, argv ) )
                {                               
+                       world.st.zoom = 0.0f;
                        simulation_stop();
                        return 1;
                }
@@ -3393,7 +3330,7 @@ void vg_start(void)
        }
        
        resource_load_main();
-       
+
        // Create text buffers
        {
                // Work out the counts for each 'segment'