fix bug with rolling over output
[fishladder.git] / fishladder.c
index dc2d540a739edcf5dca8713443acb4572e33e3f7..9c573084c3daa3fe9deeaf3d01dc0caece1f201f 100644 (file)
@@ -127,7 +127,7 @@ struct world
        
        u32 w, h;
        
-       struct mesh tile, circle;
+       struct mesh tile, circle, splitter_l, splitter_r;
        
        int selected;
        
@@ -341,6 +341,21 @@ void vg_start(void)
                init_mesh( &world.circle, circle_mesh, vg_list_size( circle_mesh ) );
        }
        
+       // splitters (temp)
+       {
+               float splitter_l[] =
+               {
+                       #include "models/splitter_l.obj.h"
+               };
+               float splitter_r[] =
+               {
+                       #include "models/splitter_r.obj.h"
+               };
+               
+               init_mesh( &world.splitter_l, splitter_l, vg_list_size( splitter_l ) );
+               init_mesh( &world.splitter_r, splitter_r, vg_list_size( splitter_r ) );
+       }
+       
        map_load
        ( 
                "#############;\n"
@@ -360,6 +375,8 @@ void vg_free(void)
 {
        free_mesh( &world.tile );
        free_mesh( &world.circle );
+       free_mesh( &world.splitter_l );
+       free_mesh( &world.splitter_r );
 
        map_free();
 }
@@ -664,7 +681,7 @@ void vg_update(void)
                                        else
                                        {
                                                struct cell *cell_next = pcell( (v2i){ fish->pos[0]+fish->dir[0], fish->pos[1]+fish->dir[1] } );
-                                               if( !(cell_next->state & FLAG_CANAL) )
+                                               if( !(cell_next->state & (FLAG_CANAL|FLAG_OUTPUT)) )
                                                {
                                                        // Try other directions for valid, so down, left, right..
                                                        v2i dirs[] = {{1,0},{-1,0},{0,-1}};
@@ -675,7 +692,7 @@ void vg_update(void)
                                                                if( (dirs[j][0] == -fish->dir[0]) && (dirs[j][1] == -fish->dir[1]) )
                                                                        continue;
                                                        
-                                                               if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & FLAG_CANAL )
+                                                               if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & (FLAG_CANAL|FLAG_OUTPUT) )
                                                                {
                                                                        fish->dir[0] = dirs[j][0];
                                                                        fish->dir[1] = dirs[j][1];
@@ -729,7 +746,19 @@ void vg_render(void)
                        struct cell *cell = pcell((v2i){x,y});
                        int selected = world.selected == y*world.w + x;
                
-                       if( cell->state & FLAG_CANAL && !selected )
+                       if( cell->state & FLAG_SPLIT )
+                       {
+                               glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 0.9f, 0.9f, 0.9f, 1.0f );
+                               glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y, 1.0f );
+                               
+                               struct mesh *splitter = cell->state & FLAG_FLIP_FLOP? &world.splitter_r: &world.splitter_l;
+                               
+                               use_mesh( splitter );
+                               draw_mesh( 0, splitter->elements );
+                               use_mesh( &world.tile );
+                       }
+               
+                       if( (cell->state & FLAG_CANAL) && !selected )
                                continue;
                
                        glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y, 1.0f );