2 // ===========================================================================================================
4 vg_tex2d tex_tile_data
= { .path
= "textures/tileset.qoi" };
5 vg_tex2d tex_tile_detail
= { .path
= "textures/tile_overlays.qoi" };
6 vg_tex2d tex_wood
= { .path
= "textures/wood.qoi" };
7 vg_tex2d tex_background
= { .path
= "textures/background.qoi" };
8 vg_tex2d tex_ball_noise
= { .path
= "textures/bnoise.qoi" };
9 vg_tex2d tex_monofur
= { .path
= "textures/ascii.qoi", .flags
= VG_TEXTURE_NO_MIP
};
10 vg_tex2d tex_unkown
= { .path
= "textures/unkown.qoi" };
12 vg_tex2d
*texture_list
[] = { &tex_tile_detail
, &tex_tile_data
, &tex_wood
, &tex_background
, &tex_ball_noise
, &tex_monofur
, &tex_unkown
};
15 // ===========================================================================================================
17 sfx_vol_control audio_volume_sfx
= { .val
= 1.0f
, .name
= "Sound effects" };
18 sfx_vol_control audio_volume_music
= { .val
= 1.0f
, .name
= "Music" };
20 sfx_system audio_system_sfx
=
24 .vol_src
= &audio_volume_sfx
,
28 sfx_set audio_tile_mod
=
40 sfx_set audio_splitter
=
43 sound/splitter_01.ogg\0"
49 sound/rolling_01.ogg\0\
50 sound/rolling_02.ogg\0"
53 sfx_set audio_random
=
56 sound/random_01.ogg\0\
57 sound/random_02.ogg\0\
58 sound/random_03.ogg\0\
59 sound/random_04.ogg\0\
60 sound/random_05.ogg\0\
61 sound/random_06.ogg\0\
62 sound/random_07.ogg\0\
63 sound/random_08.ogg\0"
66 // One two or three layers of rolling noise
67 sfx_system audio_system_balls_rolling
=
69 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
70 .name
= "Balls Rolling", .flags
= SFX_FLAG_REPEAT
74 sfx_system audio_system_balls_switching
=
76 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
77 .name
= "Balls Switching"
80 // Gameplay critical sounds eg. splitter sound rocking
81 sfx_system audio_system_balls_important
=
83 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
84 .name
= "Balls Gameplay"
88 sfx_system audio_system_balls_extra
=
90 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
94 ui_colourset ui_fl_colours
= {
100 ui_colourset ui_fl_colours_inactive
= {
106 static void resource_load_main(void)
109 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
111 ui_override_font( tex_monofur
.name
, 7 );
113 ui_global_ctx
.colours_main
= &ui_fl_colours
;
117 sfx_set_init( &audio_tile_mod
, NULL
);
118 sfx_set_init( &audio_splitter
, NULL
);
119 sfx_set_init( &audio_rolls
, NULL
);
120 sfx_set_init( &audio_random
, NULL
);
123 static void resource_free_main(void)
125 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
127 sfx_set_free( &audio_tile_mod
);
128 sfx_set_free( &audio_splitter
);
129 sfx_set_free( &audio_rolls
);
130 sfx_set_free( &audio_random
);
134 // ===========================================================================================================
136 SHADER_DEFINE( shader_tile_colour
,
139 "layout (location=0) in vec2 a_co;"
141 "uniform vec3 uOffset;"
145 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
149 "out vec4 FragColor;"
150 "uniform vec4 uColour;"
154 "FragColor = uColour;"
157 UNIFORMS({ "uPv", "uOffset", "uColour" })
160 SHADER_DEFINE( shader_ball
,
162 "layout (location=0) in vec2 a_co;"
163 "uniform vec2 uOffset;"
166 "out vec4 aTexCoords;"
171 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
172 "gl_Position = vec4( uPv * worldpos, 1.0 );"
174 // Create texture coords
175 "aTexCoords = vec4( a_co, worldpos.xy );"
179 "out vec4 FragColor;"
181 "uniform sampler2D uTexMain;"
182 "uniform vec3 uColour;"
183 "uniform vec2 uTexOffset;"
185 "in vec4 aTexCoords;"
189 "vec2 center_coords = aTexCoords.xy - 0.5;"
190 "vec2 center_coords_sqr = center_coords*center_coords;"
191 "float circle_factor = smoothstep( 0.07, 0.0625, center_coords_sqr.x+center_coords_sqr.y );"
193 "float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;"
194 "vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;"
195 "vec4 noise_sample = texture( uTexMain, warped_coords );"
197 "float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;"
199 "vec2 shadow_coords = center_coords + vec2(0.02,0.07);"
200 "vec2 shadow_coords_sqr = shadow_coords*shadow_coords;"
201 "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
203 "vec3 marble_comp = uColour*0.9 + (noise_sample.x*0.7+pow(rim_light,3.0)*2.0) * 0.1;"
204 "vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
206 "FragColor = colour_comp;"
209 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv", "uTexOffset" })
212 SHADER_DEFINE( shader_tile_main
,
214 "layout (location=0) in vec2 a_co;"
215 "uniform vec4 uOffset;" // Tile x/y, uv x/y
217 "uniform mat2 uSubTransform;"
219 "out vec4 aTexCoords;"
220 "out vec2 aWorldCoords;"
222 "vec2 hash22(vec2 p)"
224 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
225 "p3 += dot(p3, p3.yzx+33.33);"
226 "return fract((p3.xx+p3.yz)*p3.zy);"
232 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
233 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
234 "gl_Position = vec4( uPv * worldpos, 1.0 );"
236 // Create texture coords
237 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
238 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
239 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
240 "aWorldCoords = worldpos.xy;"
244 "out vec4 FragColor;"
246 "uniform sampler2D uTexGlyphs;"
247 "uniform sampler2D uTexWood;"
248 "uniform float uGhost;"
249 "uniform float uForeground;"
250 "uniform vec2 uMousePos;"
251 "uniform vec4 uColour;"
253 "in vec4 aTexCoords;"
254 "in vec2 aWorldCoords;"
258 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
259 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
260 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
261 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
262 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
264 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
266 "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
268 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
269 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
271 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
274 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour", "uForeground" })
277 SHADER_DEFINE( shader_background
,
279 "layout (location=0) in vec2 a_co;"
281 "uniform vec3 uOffset;"
283 "out vec2 aTexCoords;"
287 "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
288 "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
293 "out vec4 FragColor;"
295 "uniform sampler2D uTexMain;"
296 "uniform sampler2D uSamplerNoise;"
297 "uniform float uVariance;"
299 "in vec2 aTexCoords;"
303 "float ao_accum = 0.0;"
304 "for( int i=0; i<10; ++i )"
306 "vec2 random_noise = (texture( uSamplerNoise, aTexCoords * 20.0 + float(i) * 0.2 ).xy - vec2( 0.5, 0.5 )) * uVariance;"
307 "vec4 background = texture( uTexMain, aTexCoords + random_noise );"
308 "ao_accum += background.r * clamp((1.0 - length( random_noise )), 0.0, 1.0);"
312 "vec4 data_this_tile = texture( uTexMain, aTexCoords );"
314 "ao_accum -= data_this_tile.r;"
316 "vec3 colour_main = mix( vec3( 0.369768, 0.3654, 0.42 ),vec3( 0.275, 0.388, 0.553 ), data_this_tile.g );"
318 "vec2 square_coords = fract( aTexCoords * 64.0 );"
319 "vec2 grid_coords = abs( square_coords - 0.5 );"
320 "float edge_contrast = (1.0-ao_accum*0.2);"
322 "float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );"
323 "float gridline_fadeout = min(max(edge_contrast-1.0, 0.0)*40.0 + data_this_tile.g,10.0);"
325 "FragColor = vec4( colour_main * edge_contrast + gridline * 0.02 * gridline_fadeout, 1.0 );"
328 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise" })
331 SHADER_DEFINE( shader_wire
,
333 "layout (location=0) in vec2 a_co;"
334 "uniform vec3 uStart;"
337 "uniform float uCurve;"
339 "out vec2 aTexCoords;"
341 "vec3 sample_curve_time( float t )"
343 "vec3 line_coord = mix( uStart, uEnd, t );"
345 "float curve_amt = 1.0-(pow((t*2.0-1.0),2.0));"
346 "return vec3( line_coord.x, line_coord.y - curve_amt*uCurve, line_coord.z );"
352 "vec3 p0 = sample_curve_time( a_co.x );"
353 "vec3 p1 = sample_curve_time( a_co.x + 0.025 );"
355 "vec2 line_tangent = normalize(p1.xy-p0.xy);"
356 "vec2 line_normal = vec2( -line_tangent.y, line_tangent.x );"
358 "vec2 worldfinal = p0.xy + line_normal*a_co.y*p0.z;"
360 "gl_Position = vec4( uPv * vec3(worldfinal, 1.0), 1.0 );"
362 // Create texture coords (todo: include stretch adjusted coords?)
363 "aTexCoords = vec2( a_co.x, a_co.y + 0.5 );"
367 "out vec4 FragColor;"
369 "uniform sampler2D uTexMain;"
370 "uniform vec4 uColour;"
372 "in vec2 aTexCoords;"
376 "FragColor = uColour;"
379 UNIFORMS({ "uPv", "uColour", "uTexMain", "uStart", "uEnd", "uCurve" })
383 void vg_register(void)
385 SHADER_INIT( shader_tile_colour
);
386 SHADER_INIT( shader_tile_main
);
387 SHADER_INIT( shader_ball
);
388 SHADER_INIT( shader_background
);
389 SHADER_INIT( shader_wire
);
393 0000 0 | 0001 1 | 0010 2 | 0011 3
397 0100 4 | 0101 5 | 0110 6 | 0111 7
401 1000 8 | 1001 9 | 1010 10 | 1011 11
405 1100 12 | 1101 13 | 1110 14 | 1111 15
411 float const MESH_NUMBER_0
[] = {
412 #include "fonts/numbers/n0.h"
415 float const MESH_NUMBER_1
[] = {
416 #include "fonts/numbers/n1.h"
419 float const MESH_NUMBER_2
[] = {
420 #include "fonts/numbers/n2.h"
423 float const MESH_NUMBER_3
[] = {
424 #include "fonts/numbers/n3.h"
427 float const MESH_NUMBER_4
[] = {
428 #include "fonts/numbers/n4.h"
431 float const MESH_NUMBER_5
[] = {
432 #include "fonts/numbers/n5.h"
435 float const MESH_NUMBER_6
[] = {
436 #include "fonts/numbers/n6.h"
439 float const MESH_NUMBER_7
[] = {
440 #include "fonts/numbers/n7.h"
443 float const MESH_NUMBER_8
[] = {
444 #include "fonts/numbers/n8.h"
447 float const MESH_NUMBER_9
[] = {
448 #include "fonts/numbers/n9.h"
451 float const MESH_NUMBERS_BUFFER
[] =
453 #include "fonts/numbers/n0.h"
454 #include "fonts/numbers/n1.h"
455 #include "fonts/numbers/n2.h"
456 #include "fonts/numbers/n3.h"
457 #include "fonts/numbers/n4.h"
458 #include "fonts/numbers/n5.h"
459 #include "fonts/numbers/n6.h"
460 #include "fonts/numbers/n7.h"
461 #include "fonts/numbers/n8.h"
462 #include "fonts/numbers/n9.h"
465 #define MESH_NUMBER_DIVISOR 6
467 u32
const MESH_NUMBERS_OFFSETS
[][2] =
471 vg_list_size( MESH_NUMBER_0
) / MESH_NUMBER_DIVISOR
474 vg_list_size( MESH_NUMBER_0
) / MESH_NUMBER_DIVISOR
,
475 vg_list_size( MESH_NUMBER_1
) / MESH_NUMBER_DIVISOR
479 vg_list_size( MESH_NUMBER_0
) +
480 vg_list_size( MESH_NUMBER_1
)
481 ) / MESH_NUMBER_DIVISOR
,
482 vg_list_size( MESH_NUMBER_2
) / MESH_NUMBER_DIVISOR
486 vg_list_size( MESH_NUMBER_0
) +
487 vg_list_size( MESH_NUMBER_1
) +
488 vg_list_size( MESH_NUMBER_2
)
489 ) / MESH_NUMBER_DIVISOR
,
490 vg_list_size( MESH_NUMBER_3
) / MESH_NUMBER_DIVISOR
494 vg_list_size( MESH_NUMBER_0
) +
495 vg_list_size( MESH_NUMBER_1
) +
496 vg_list_size( MESH_NUMBER_2
) +
497 vg_list_size( MESH_NUMBER_3
)
498 ) / MESH_NUMBER_DIVISOR
,
499 vg_list_size( MESH_NUMBER_4
) / MESH_NUMBER_DIVISOR
503 vg_list_size( MESH_NUMBER_0
) +
504 vg_list_size( MESH_NUMBER_1
) +
505 vg_list_size( MESH_NUMBER_2
) +
506 vg_list_size( MESH_NUMBER_3
) +
507 vg_list_size( MESH_NUMBER_4
)
508 ) / MESH_NUMBER_DIVISOR
,
509 vg_list_size( MESH_NUMBER_5
) / MESH_NUMBER_DIVISOR
513 vg_list_size( MESH_NUMBER_0
) +
514 vg_list_size( MESH_NUMBER_1
) +
515 vg_list_size( MESH_NUMBER_2
) +
516 vg_list_size( MESH_NUMBER_3
) +
517 vg_list_size( MESH_NUMBER_4
) +
518 vg_list_size( MESH_NUMBER_5
)
519 ) / MESH_NUMBER_DIVISOR
,
520 vg_list_size( MESH_NUMBER_6
) / MESH_NUMBER_DIVISOR
524 vg_list_size( MESH_NUMBER_0
) +
525 vg_list_size( MESH_NUMBER_1
) +
526 vg_list_size( MESH_NUMBER_2
) +
527 vg_list_size( MESH_NUMBER_3
) +
528 vg_list_size( MESH_NUMBER_4
) +
529 vg_list_size( MESH_NUMBER_5
) +
530 vg_list_size( MESH_NUMBER_6
)
531 ) / MESH_NUMBER_DIVISOR
,
532 vg_list_size( MESH_NUMBER_7
) / MESH_NUMBER_DIVISOR
536 vg_list_size( MESH_NUMBER_0
) +
537 vg_list_size( MESH_NUMBER_1
) +
538 vg_list_size( MESH_NUMBER_2
) +
539 vg_list_size( MESH_NUMBER_3
) +
540 vg_list_size( MESH_NUMBER_4
) +
541 vg_list_size( MESH_NUMBER_5
) +
542 vg_list_size( MESH_NUMBER_6
) +
543 vg_list_size( MESH_NUMBER_7
)
544 ) / MESH_NUMBER_DIVISOR
,
545 vg_list_size( MESH_NUMBER_8
) / MESH_NUMBER_DIVISOR
549 vg_list_size( MESH_NUMBER_0
) +
550 vg_list_size( MESH_NUMBER_1
) +
551 vg_list_size( MESH_NUMBER_2
) +
552 vg_list_size( MESH_NUMBER_3
) +
553 vg_list_size( MESH_NUMBER_4
) +
554 vg_list_size( MESH_NUMBER_5
) +
555 vg_list_size( MESH_NUMBER_6
) +
556 vg_list_size( MESH_NUMBER_7
) +
557 vg_list_size( MESH_NUMBER_8
)
558 ) / MESH_NUMBER_DIVISOR
,
559 vg_list_size( MESH_NUMBER_9
) / MESH_NUMBER_DIVISOR
565 const char *map_name
;
567 const char *description
;
572 int _unlock
, _linked
; // When completed, unlock this level
573 struct cmp_level
*unlock
, *linked
;
578 SteamLeaderboard_t steam_leaderboard
;
581 static struct cmp_level cmp_levels_tutorials
[] =
585 .title
= "PRINCIPLE 1",
586 .map_name
= "cmp_t01",
587 .description
= "Utilize basic transport methods",
594 .title
= "PRINCIPLE 2",
595 .map_name
= "cmp_t02",
596 .description
= "Utilize the twisty turny(TM) piece to split\n"
597 "the marble stream into two",
604 .title
= "PRINCIPLE 3",
605 .map_name
= "cmp_t03",
606 .description
= "Merge transport into one",
613 .title
= "PRINCIPLE 4",
614 .map_name
= "cmp_t04",
615 .description
= "Some stages require multiple runs to succeed\n"
623 static struct cmp_level cmp_levels_basic
[] =
627 .title
= "SUBDIVISION 1",
628 .map_name
= "cmp_b01",
629 .description
= "Simple maths, branching required.",
636 .title
= "SUBDIVISION 2",
637 .map_name
= "cmp_b02",
638 .description
= "Simple maths, except more.",
645 .title
= "RESTRUCTURE",
646 .map_name
= "cmp_b03",
647 .description
= "Not so simple swap",
653 .title
= "SERIALIZE",
654 .map_name
= "cmp_b04",
655 .description
= "Merge and sort",
661 .title
= "PATTERNS 1",
662 .map_name
= "cmp_b05",
663 .description
= "Replicate",
669 .title
= "PATTERNS 2",
670 .map_name
= "cmp_b06",
671 .description
= "Replicate MORE",
677 .title
= "MIGHTY CONSUMER",
678 .map_name
= "cmp_b07",
679 .description
= "Build a greedy system",
686 .title
= "ENCRYPTED 1",
687 .map_name
= "cmp_b08",
688 .description
= "Some configurations may not be valid",
695 .map_name
= "cmp_b09",
696 .description
= "Reverse the incoming order. Always length 4",
702 .title
= "PRINCIPLE 5",
703 .map_name
= "cmp_b10",
705 "The competent engineers among you may have already\n"
706 "spotted and utilized these parts of the system\n"
708 "We forgot to include the relevant principle tasks as\n"
709 "of your training package, you will now be tasked to\n"
716 .title
= "ROUTING PROBLEM",
717 .map_name
= "cmp_routing",
719 "Things can get a little chaotic on tight boards, do your\n"
720 "best to utilize principle 5 to get the job done\n",
726 .title
= "PRINCIPLE 6",
727 .map_name
= "cmp_b11",
729 "While hovering over a simple tile peice, right click and\n"
730 "drag to start creating a wire. These can be connected to\n"
731 "the left, or right recieving pins of a Twisty Turny(TM).\n"
733 "Once connected, the Twisty Turny(TM) will no longer\n"
734 "'flip flop' as marbles run through them, but instead be\n"
735 "et to left or right rotating only. As indicated by the\n"
736 "status arrow beneath them\n"
738 "When the left or right slot is triggered, the Twisty\n"
739 "Turny(TM) will switch modes according to that input.\n"
741 "Trigger wires apply instantaneously, however if both the\n"
742 "left and right inputs are recieved at the same time,\n"
743 "this results in no operation being performed, and no\n"
744 "state changes take place in the Twisty Turny(TM)\n",
751 .map_name
= "cmp_not",
753 "Test your knowledge of triggers, build an 'NOT GATE'\n"
754 "emulated by marble logic.",
762 .map_name
= "cmp_and",
764 "A slightly more complicated gate, but shouldn't be\n"
765 "too difficult for your skillset.",
771 .title
= "QUALIFICATION PROJECT",
772 .map_name
= "cmp_grad",
774 "There's no instructions here, resolve and complete this\n"
775 "task to qualify yourself as an official marble engineer",
780 static struct cmp_level cmp_levels_grad
[] =
785 .map_name
= "cmp_i01",
787 "Device a scheme to filter and sort the inputs. If you\n"
788 "believe you lack the tools required to solve this one,\n"
789 "take a harder look at the inputs.",
796 .map_name
= "cmp_i02",
798 "Split the inputs up into a third of their values\n"
800 "Is this possible? -HG",
807 .map_name
= "cmp_xor",
809 "Significantly more complicated than an AND or NOT gate,\n"
815 .title
= "SECRET CODE",
816 .map_name
= "cmp_secret",
818 "Only one input should send an unlock signal marble to\n"
824 #define NUM_CAMPAIGN_LEVELS (vg_list_size( cmp_levels_tutorials ) + vg_list_size( cmp_levels_basic ) + vg_list_size( cmp_levels_grad ))
834 static struct serializable_set
836 struct cmp_level
*pack
;
839 career_serializable
[] =
842 .pack
= cmp_levels_tutorials
,
843 .count
= vg_list_size( cmp_levels_tutorials
)
846 .pack
= cmp_levels_basic
,
847 .count
= vg_list_size( cmp_levels_basic
)
850 .pack
= cmp_levels_grad
,
851 .count
= vg_list_size( cmp_levels_grad
)
855 // Setup pointers and that
856 static void career_local_data_init(void)
858 struct cmp_level
*level_ptrs
[ NUM_CAMPAIGN_LEVELS
];
861 for( int i
= 0; i
< vg_list_size( career_serializable
); i
++ )
863 struct serializable_set
*set
= &career_serializable
[i
];
865 for( int j
= 0; j
< set
->count
; j
++ )
866 level_ptrs
[ set
->pack
[j
].serial_id
] = &set
->pack
[j
];
870 for( int i
= 0; i
< vg_list_size( career_serializable
); i
++ )
872 struct serializable_set
*set
= &career_serializable
[i
];
874 for( int j
= 0; j
< set
->count
; j
++ )
876 struct cmp_level
*lvl
= &set
->pack
[j
];
877 lvl
->unlock
= lvl
->_unlock
? level_ptrs
[ lvl
->_unlock
]: NULL
;
878 lvl
->linked
= lvl
->_linked
? level_ptrs
[ lvl
->_linked
]: NULL
;