2 // ===========================================================================================================
4 vg_tex2d tex_tile_data
= { .path
= "textures/tileset.qoi" };
5 vg_tex2d tex_tile_detail
= { .path
= "textures/tile_overlays.qoi" };
7 vg_tex2d tex_tiles_wood
= { .path
= "textures/tile_wood.qoi" };
8 vg_tex2d tex_tiles_min
= { .path
= "textures/tile_minimal.qoi" };
9 vg_tex2d tex_tiles_lab
= { .path
= "textures/tile_lab.qoi" };
11 vg_tex2d tex_ball_noise
= { .path
= "textures/bnoise.qoi" };
12 vg_tex2d tex_monofur
= { .path
= "textures/ascii.qoi", .flags
= VG_TEXTURE_NO_MIP
};
13 vg_tex2d tex_unkown
= { .path
= "textures/unkown.qoi" };
14 vg_tex2d tex_buttons
= { .path
= "textures/buttons.qoi" };
15 vg_tex2d tex_sprites
= { .path
= "textures/autocombine.qoi" };
17 vg_tex2d
*texture_list
[] = {
30 #include "sprites_autocombine.h"
33 // ===========================================================================================================
35 sfx_vol_control audio_volume_sfx
= { .val
= 1.0f
, .name
= "Sound effects" };
36 sfx_vol_control audio_volume_music
= { .val
= 1.0f
, .name
= "Music" };
38 sfx_system audio_system_sfx
=
42 .vol_src
= &audio_volume_sfx
,
46 sfx_set audio_tile_mod
=
58 sfx_set audio_splitter
=
61 sound/splitter_01.ogg\0"
67 sound/rolling_01.ogg\0\
68 sound/rolling_02.ogg\0"
71 sfx_set audio_random
=
74 sound/random_01.ogg\0\
75 sound/random_02.ogg\0\
76 sound/random_03.ogg\0\
77 sound/random_04.ogg\0\
78 sound/random_05.ogg\0\
79 sound/random_06.ogg\0\
80 sound/random_07.ogg\0\
81 sound/random_08.ogg\0"
84 sfx_set audio_clicks
=
107 // One two or three layers of rolling noise
108 sfx_system audio_system_balls_rolling
=
110 .vol
= 0.7f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
111 .name
= "Balls Rolling", .flags
= SFX_FLAG_REPEAT
| SFX_FLAG_PERSISTENT
115 sfx_system audio_system_balls_switching
=
117 .vol
= 0.2f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
118 .name
= "Balls Switching"
121 // Gameplay critical sounds eg. splitter sound rocking
122 sfx_system audio_system_balls_important
=
124 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
125 .name
= "Balls Gameplay"
128 // Suplemental sounds
129 sfx_system audio_system_balls_extra
=
131 .vol
= 0.27f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
132 .name
= "Balls Extra"
135 sfx_system audio_system_ui
=
137 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
141 static void resource_load_main(void)
144 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
147 sfx_set_init( &audio_tile_mod
, NULL
);
148 sfx_set_init( &audio_splitter
, NULL
);
149 sfx_set_init( &audio_rolls
, NULL
);
150 sfx_set_init( &audio_random
, NULL
);
151 sfx_set_init( &audio_clicks
, NULL
);
152 sfx_set_init( &audio_tones
, NULL
);
155 static void resource_free_main(void)
157 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
159 sfx_set_free( &audio_tile_mod
);
160 sfx_set_free( &audio_splitter
);
161 sfx_set_free( &audio_rolls
);
162 sfx_set_free( &audio_random
);
163 sfx_set_free( &audio_clicks
);
164 sfx_set_free( &audio_tones
);
168 // ===========================================================================================================
170 SHADER_DEFINE( shader_tile_colour
,
173 "layout (location=0) in vec2 a_co;"
175 "uniform vec3 uOffset;"
179 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
183 "out vec4 FragColor;"
184 "uniform vec4 uColour;"
188 "FragColor = uColour;"
191 UNIFORMS({ "uPv", "uOffset", "uColour" })
194 SHADER_DEFINE( shader_ball
,
196 "layout (location=0) in vec2 a_co;"
197 "uniform vec3 uOffset;"
200 "out vec4 aTexCoords;"
205 "vec3 worldpos = vec3( (a_co * 0.5 - 0.25) * uOffset.z + uOffset.xy, 1.0 );"
206 "gl_Position = vec4( uPv * worldpos, 1.0 );"
208 // Create texture coords
209 "aTexCoords = vec4( a_co, worldpos.xy );"
213 "out vec4 FragColor;"
215 "uniform sampler2D uTexMain;"
216 "uniform vec3 uColour;"
217 "uniform vec2 uTexOffset;"
219 "in vec4 aTexCoords;"
223 "vec2 center_coords = aTexCoords.xy - 0.5;"
224 "vec2 center_coords_sqr = center_coords*center_coords;"
225 "float circle_factor = smoothstep( 0.07, 0.0625, center_coords_sqr.x+center_coords_sqr.y );"
227 "float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;"
228 "vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;"
229 "vec4 noise_sample = texture( uTexMain, warped_coords );"
231 "float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;"
233 "vec2 shadow_coords = center_coords + vec2(0.02,0.07);"
234 "vec2 shadow_coords_sqr = shadow_coords*shadow_coords;"
235 "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
237 "vec3 marble_comp = uColour*0.9 + (noise_sample.x*0.7+pow(rim_light,3.0)*2.0) * 0.1;"
238 //"vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
239 "vec4 colour_comp = mix( vec4(0.2,0.2,0.2,shadow), vec4(marble_comp,1.0), circle_factor );"
241 "FragColor = colour_comp;"
244 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv", "uTexOffset" })
247 SHADER_DEFINE( shader_tile_main
,
249 "layout (location=0) in vec2 a_co;"
250 "uniform vec4 uOffset;" // Tile x/y, uv x/y
252 "uniform mat2 uSubTransform;"
253 "uniform float uVisibility;"
255 "out vec4 aTexCoords;"
256 "out vec2 aWorldCoords;"
258 "vec2 hash22(vec2 p)"
260 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
261 "p3 += dot(p3, p3.yzx+33.33);"
262 "return fract((p3.xx+p3.yz)*p3.zy);"
267 "vec2 hash_val = hash22(uOffset.xy);"
268 "float scaling_factor = smoothstep( hash_val.x, hash_val.x+1.0, uVisibility );"
271 "vec2 subtransform = uSubTransform * (a_co-0.5) * scaling_factor + 0.5;"
272 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
273 "gl_Position = vec4( uPv * worldpos, 1.0 );"
275 // Create texture coords
276 "vec2 random_offset = floor(hash_val * 4.0) * 0.25;"
277 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
278 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
279 "aWorldCoords = worldpos.xy;"
283 "out vec4 FragColor;"
285 "uniform sampler2D uTexGlyphs;"
286 "uniform sampler2D uTexWood;"
287 "uniform float uGhost;"
288 "uniform float uForeground;"
289 "uniform vec2 uMousePos;"
290 "uniform vec4 uColour;"
291 "uniform vec3 uShadowing;"
293 "in vec4 aTexCoords;"
294 "in vec2 aWorldCoords;"
298 //"vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
299 //"vec3 shadowing_colour = vec3( 0.8, 0.8, 0.8 );"
301 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
302 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
303 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
304 "vec3 wood_comp = mix( wood_secondary.rgb * uShadowing, wood.rgb, clamp( glyph.b*2.0-1.0, 0.0, 1.0 ) );"
306 //"vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
307 "vec3 shadows = mix( uShadowing, vec3(1.0,1.0,1.0), glyph.r );"
309 "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
311 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
312 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
314 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
317 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos",
318 "uColour", "uForeground", "uVisibility", "uShadowing" })
321 SHADER_DEFINE( shader_background
,
323 "layout (location=0) in vec2 a_co;"
325 "uniform vec3 uOffset;"
327 "out vec2 aTexCoords;"
331 "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
332 "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
337 "out vec4 FragColor;"
339 "uniform sampler2D uTexMain;"
340 "uniform sampler2D uSamplerNoise;"
341 "uniform float uVariance;"
342 "uniform float uVisibility;"
344 "in vec2 aTexCoords;"
348 "float ao_accum = 0.0;"
349 "for( int i=0; i<10; ++i )"
351 "vec2 random_noise = (texture( uSamplerNoise, aTexCoords * 20.0 + float(i) * 0.2 ).xy - vec2( 0.5, 0.5 )) * uVariance;"
352 "vec4 background = texture( uTexMain, aTexCoords + random_noise );"
353 "ao_accum += background.r * clamp((1.0 - length( random_noise )), 0.0, 1.0);"
357 "vec4 data_this_tile = texture( uTexMain, aTexCoords );"
359 "ao_accum -= data_this_tile.r;"
360 "ao_accum *= uVisibility;"
362 "vec3 colour_main = mix( vec3( 0.369768, 0.3654, 0.42 ), vec3( 0.275, 0.388, 0.553 ), data_this_tile.g * uVisibility );"
364 "vec2 square_coords = fract( aTexCoords * 64.0 );"
365 "vec2 grid_coords = abs( square_coords - 0.5 );"
366 "float edge_contrast = (1.0-ao_accum*0.2);"
368 "float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );"
369 "float gridline_fadeout = min(max(edge_contrast-1.0, 0.0)*40.0 + data_this_tile.g,10.0);"
371 "FragColor = vec4( colour_main * edge_contrast + gridline * 0.02 * gridline_fadeout, 1.0 );"
374 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise", "uVisibility" })
377 SHADER_DEFINE( shader_wire
,
379 "layout (location=0) in vec2 a_co;"
380 "uniform vec3 uStart;"
383 "uniform float uCurve;"
385 "out vec2 aTexCoords;"
387 "vec3 sample_curve_time( float t )"
389 "vec3 line_coord = mix( uStart, uEnd, t );"
391 "float curve_amt = 1.0-(pow((t*2.0-1.0),2.0));"
392 "return vec3( line_coord.x, line_coord.y - curve_amt*uCurve, line_coord.z );"
398 "vec3 p0 = sample_curve_time( a_co.x );"
399 "vec3 p1 = sample_curve_time( a_co.x + 0.025 );"
401 "vec2 line_tangent = normalize(p1.xy-p0.xy);"
402 "vec2 line_normal = vec2( -line_tangent.y, line_tangent.x );"
404 "vec2 worldfinal = p0.xy + line_normal*a_co.y*p0.z;"
406 "gl_Position = vec4( uPv * vec3(worldfinal, 1.0), 1.0 );"
408 // Create texture coords (todo: include stretch adjusted coords?)
409 "aTexCoords = vec2( a_co.x, a_co.y + 0.5 );"
413 "out vec4 FragColor;"
415 "uniform sampler2D uTexMain;"
416 "uniform vec4 uColour;"
417 "uniform float uTime;"
418 "uniform float uGlow;"
420 "in vec2 aTexCoords;"
425 "float shadow = 1.0 - abs(aTexCoords.y - 0.5) * 2.0;"
426 "float masking = smoothstep( 0.5, 0.8, shadow );"
428 "vec3 colour_comp = mix( vec3(0.0,0.0,0.0), uColour.rgb, masking );"
430 "float flow_thing = fract( aTexCoords.x + uTime );"
431 "vec3 final_comp = colour_comp + flow_thing * uGlow;"
433 "FragColor = vec4( final_comp, max( shadow* 0.2, masking ) * uColour.a );"
436 UNIFORMS({ "uPv", "uColour", "uTexMain", "uStart", "uEnd", "uCurve", "uTime", "uGlow" })
439 SHADER_DEFINE( shader_buttons
,
441 "layout (location=0) in vec2 a_co;"
442 "uniform vec4 uOffset;" // Tile x/y, uv x/y
445 "out vec2 aTexCoords;"
450 "vec3 worldpos = vec3( a_co + uOffset.xy, 1.0 );"
451 "gl_Position = vec4( uPv * worldpos, 1.0 );"
453 // Create texture coords
454 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
455 "aTexCoords = (edge_safe_coords + uOffset.zw) * 0.25;"
459 "out vec4 FragColor;"
461 "uniform sampler2D uTexMain;"
462 "uniform vec4 uColour;" // rgb, light amount
464 "in vec2 aTexCoords;"
468 "vec4 glyph = texture( uTexMain, aTexCoords.xy );"
470 "FragColor = vec4( uColour.rgb * (mix(glyph.r, glyph.g, uColour.a)+0.02)*2.6 + glyph.b * 0.4, glyph.a );"
473 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uColour" })
476 SHADER_DEFINE( shader_sprite
,
479 "layout (location=0) in vec2 a_co;" // quad mesh
485 "out vec2 aTexCoords;"
489 "vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;"
490 "gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );"
491 "aTexCoords = uUv.xy + a_co*uUv.zw;"
495 "uniform sampler2D uTexMain;"
496 "out vec4 FragColor;"
498 "in vec2 aTexCoords;"
502 "vec4 texture_sample = texture( uTexMain, aTexCoords );"
503 "FragColor = texture_sample;"
506 UNIFORMS({ "uPv", "uTexMain", "uUv", "uPos" })
509 void vg_register(void)
511 SHADER_INIT( shader_tile_colour
);
512 SHADER_INIT( shader_tile_main
);
513 SHADER_INIT( shader_ball
);
514 SHADER_INIT( shader_background
);
515 SHADER_INIT( shader_wire
);
516 SHADER_INIT( shader_buttons
);
517 SHADER_INIT( shader_sprite
);
521 0000 0 | 0001 1 | 0010 2 | 0011 3
525 0100 4 | 0101 5 | 0110 6 | 0111 7
529 1000 8 | 1001 9 | 1010 10 | 1011 11
533 1100 12 | 1101 13 | 1110 14 | 1111 15
544 const char *map_name
;
546 const char *description
;
548 const char *achievement
;
550 int _unlock
, _linked
; // When completed, unlock this level
572 struct world_button btn
;
573 struct cmp_level
*unlock
, *linked
;
576 SteamLeaderboard_t steam_leaderboard
;
580 static struct cmp_level cmp_levels_tutorials
[] =
583 0, "cmp_t01", "PRINCIPLE 1", "",
588 1, "cmp_t02", "PRINCIPLE 2", "",
593 2, "cmp_t03", "PRINCIPLE 3", "",
598 12, "cmp_t04", "PRINCIPLE 4", "",
601 .achievement
= "TUTORIALS"
604 15, "cmp_b10", "PRINCIPLE 5", "",
609 17, "cmp_b11", "PRINCIPLE 6", "(Right click)",
614 26, "cmp_p7", "PRINCIPLE 7", "Emitters",
620 static struct cmp_level cmp_levels_basic
[] =
623 6, "cmp_b04", "PATCH", "",
628 3, "cmp_b01", "SUBDIVISION 1", "",
633 4, "cmp_b02", "SUBDIVISION 2", "",
637 5, "cmp_b03", "RESTRUCTURE", "",
641 7, "cmp_b05", "PATTERNS 1", "",
646 8, "cmp_b06", "PATTERNS 2", "",
650 16, "cmp_routing", "ROUTING PROBLEM", "",
654 9, "cmp_b07", "MIGHTY CONSUMER", "",
657 .achievement
= "MIGHTY_CONSUMER"
660 10, "cmp_b08", "SHIFT", "",
664 11, "cmp_b09", "REVERSE", "",
668 18, "cmp_not", "NOT GATE", "",
673 19, "cmp_and", "AND GATE", "",
677 20, "cmp_xor", "QUALIFICATION PROJECT", "",
679 .achievement
= "GRADUATE"
682 27, "cmp_expander", "EXPAND", "",
686 28, "cmp_pattern3", "PATTERNS 3", "",
690 29, "cmp_routing2", "ROUTING PROBLEM 2", "Spaghetti!",
694 30, "cmp_exact5", "EXACTLY 5", ""
698 static struct cmp_level cmp_levels_grad
[] =
701 13, "cmp_i01", "SORT", "",
705 14, "cmp_i02", "THIRDS", "",
709 21, "cmp_grad", "SIMPLE ADDITION", "",
714 22, "cmp_secret", "SECRET CODE", "",
719 static struct cmp_level cmp_levels_computer
[] =
722 23, "cmp_binary", "3 BIT BINARY", "Convert amount to binary",
727 .placement
= k_placement_bottom
,
729 "\t\t\t\t\t\t\t\t\t\t\x83 \x84\n"
730 "\t\t\t\t\t\t\t\t\t\t\x83 \x84 Binary\n"
731 "\t\t\t\t\t\t\t\t\t\t\x83 4 2 1 \x84"
734 .placement
= k_placement_top
,
737 "\t\t\t\t\t\t\t\t\t\t\t Count"
742 24, "cmp_add3b", "3 BIT ADDER", "Binary addition",
747 .placement
= k_placement_top
,
748 //.str ="\t\t\t\t\t\t\t\t\t| NUMBER A | | NUMBER B |\n"
750 "\t\t\t\t\t\t\t\t\t\x8A 4 2 1 \x8B \x8A 4 2 1 \x8B\n"
751 "\t\t\t\t\t\t\t\t\t\x83 \x84 add \x83 \x84\n"
752 "\t\t\t\t\t\t\t\t\t\x83 \x84 \x83 \x84"
755 .placement
= k_placement_bottom
,
758 "\t\t\t\x83 \x84 result a+b\n"
759 "\t\t\t\x83 8 4 2 1 \x84"
764 25, "cmp_plot3x3", "3x3 PLOT", "2 bit x/y",
768 .placement
= k_placement_top
,
770 "\t\t\t\t\t\t\t\t\x8A 2 1 \x8B \x8A 2 1 \x8B\n"
771 "\t\t\t\t\t\t\t\t\x83 \x84 X Y \x83 \x84\n"
772 "\t\t\t\t\t\t\t\t\x83 \x84 \x83 \x84"
778 #define NUM_CAMPAIGN_LEVELS (vg_list_size( cmp_levels_tutorials ) + vg_list_size( cmp_levels_basic ) + vg_list_size( cmp_levels_grad ) + vg_list_size( cmp_levels_computer ) )
780 static struct career_level_pack
782 struct cmp_level
*pack
;
792 .pack
= cmp_levels_tutorials
,
793 .count
= vg_list_size( cmp_levels_tutorials
),
794 .primary_colour
= { 0.204f
, 0.345f
, 0.553f
},
795 .origin
= { -5, -2 },
799 .pack
= cmp_levels_basic
,
800 .count
= vg_list_size( cmp_levels_basic
),
801 .primary_colour
= { 0.304f
, 0.245f
, 0.553f
},
802 .origin
= { -3, -2 },
806 .pack
= cmp_levels_grad
,
807 .count
= vg_list_size( cmp_levels_grad
),
808 .primary_colour
= { 0.553f
, 0.345f
, 0.204f
},
813 .pack
= cmp_levels_computer
,
814 .count
= vg_list_size( cmp_levels_computer
),
815 .primary_colour
= { 0.75f
, 0.23f
, 0.39f
},
821 // Setup pointers and that
822 static void career_local_data_init(void)
824 struct cmp_level
*level_ptrs
[ NUM_CAMPAIGN_LEVELS
];
825 for( int i
= 0; i
< NUM_CAMPAIGN_LEVELS
; i
++ )
826 level_ptrs
[i
] = NULL
;
829 for( int i
= 0; i
< vg_list_size( career_packs
); i
++ )
831 struct career_level_pack
*set
= &career_packs
[i
];
833 for( int j
= 0; j
< set
->count
; j
++ )
835 int id
= set
->pack
[j
].serial_id
;
837 if( level_ptrs
[ id
] )
838 vg_error( "Serial id %u already used!\n", id
);
840 level_ptrs
[ set
->pack
[j
].serial_id
] = &set
->pack
[j
];
845 for( int i
= 0; i
< vg_list_size( career_packs
); i
++ )
847 struct career_level_pack
*set
= &career_packs
[i
];
849 for( int j
= 0; j
< set
->count
; j
++ )
851 struct cmp_level
*lvl
= &set
->pack
[j
];
853 if( lvl
->_unlock
>= NUM_CAMPAIGN_LEVELS
||
854 lvl
->_linked
>= NUM_CAMPAIGN_LEVELS
)
856 vg_error( "_unlock / _linked out of range (%d, %d)\n",
857 lvl
->_unlock
, lvl
->_linked
);
861 lvl
->unlock
= lvl
->_unlock
? level_ptrs
[ lvl
->_unlock
]: NULL
;
862 lvl
->linked
= lvl
->_linked
? level_ptrs
[ lvl
->_linked
]: NULL
;