@ -7,6 +7,8 @@
# include <enet/enet.h>
# include <process.h> // starting server thread
# define TOOLBAR_SLOTS 9
# pragma warning(disable : 33010) // this warning is so broken, doesn't
// understand assert()
# include "sokol_app.h"
@ -31,8 +33,10 @@
# include "miniaudio.h"
// shaders
# include "goodpixel.gen.h"
# include "hueshift.gen.h"
static sg_pipeline pip ;
static sg_pipeline hueshift_pipeline ;
static sg_pipeline goodpixel_pipeline ;
static struct GameState gs = { 0 } ;
static int my_player_index = - 1 ;
@ -47,6 +51,7 @@ typedef struct KeyPressed
static KeyPressed keypressed [ MAX_KEYDOWN ] = { 0 } ;
static V2 mouse_pos = { 0 } ;
static bool fullscreened = false ;
static bool picking_new_boxtype = false ;
static bool build_pressed = false ;
static bool interact_pressed = false ;
@ -102,9 +107,22 @@ static sg_image image_flag_taken;
static sg_image image_squad_invite ;
static sg_image image_check ;
static sg_image image_no ;
static int cur_editing_boxtype = - 1 ;
static int cur_editing_rotation = 0 ;
static sg_image image_solarpanel_charging ;
static sg_image image_scanner_head ;
static sg_image image_itemswitch ;
static sg_image image_cloaking_panel ;
static enum BoxType toolbar [ TOOLBAR_SLOTS ] = {
BoxHullpiece ,
BoxThruster ,
BoxBattery ,
BoxCockpit ,
BoxMedbay ,
BoxSolarPanel ,
BoxScanner ,
} ;
static int cur_toolbar_slot = 0 ;
static int cur_editing_rotation = Right ;
// audio
static bool muted = false ;
@ -130,7 +148,6 @@ static struct BoxInfo
enum BoxType type ;
const char * image_path ;
sg_image image ;
bool needs_tobe_unlocked ;
} boxes [ ] = {
// if added to here will show up in toolbar, is placeable
{
@ -160,7 +177,19 @@ static struct BoxInfo
{
. type = BoxExplosive ,
. image_path = " loaded/explosive.png " ,
. needs_tobe_unlocked = true ,
} ,
{
. type = BoxScanner ,
. image_path = " loaded/scanner_base.png " ,
} ,
{
. type = BoxGyroscope ,
. image_path = " loaded/gyroscope.png " ,
} ,
{
. type = BoxCloaking ,
. image_path = " loaded/cloaking_device.png " ,
} ,
} ;
# define ENTITIES_ITER(cur) \
@ -168,7 +197,8 @@ static struct BoxInfo
cur + + ) \
if ( cur - > exists )
# define ARRLEN(arr) (sizeof(arr) / sizeof(*arr))
// suppress compiler warning about ^^ above used in floating point context
# define ARRLENF(arr) ((float)sizeof(arr) / sizeof(*arr))
static struct SquadMeta
{
enum Squad squad ;
@ -208,6 +238,13 @@ struct SquadMeta squad_meta(enum Squad squad)
return ( struct SquadMeta ) { 0 } ;
}
static enum BoxType currently_building ( )
{
assert ( cur_toolbar_slot > = 0 ) ;
assert ( cur_toolbar_slot < TOOLBAR_SLOTS ) ;
return toolbar [ cur_toolbar_slot ] ;
}
struct BoxInfo boxinfo ( enum BoxType type )
{
for ( int i = 0 ; i < ARRLEN ( boxes ) ; i + + )
@ -239,8 +276,9 @@ static sg_image load_image(const char *path)
& ( sg_image_desc ) { . width = x ,
. height = y ,
. pixel_format = SG_PIXELFORMAT_RGBA8 ,
. min_filter = SG_FILTER_NEAREST ,
. mag_filter = SG_FILTER_NEAREST ,
. min_filter = SG_FILTER_LINEAR ,
. mag_filter = SG_FILTER_LINEAR ,
. wrap_u = SG_WRAP_CLAMP_TO_EDGE ,
. data . subimage [ 0 ] [ 0 ] = {
. ptr = image_data ,
. size = ( size_t ) ( x * y * desired_channels ) ,
@ -439,14 +477,30 @@ static void init(void)
// shaders
{
// initialize shader
{
{
sgp_pipeline_desc pip_desc = {
. shader = * hueshift_program_shader_desc ( sg_query_backend ( ) ) ,
. blend_mode = SGP_BLENDMODE_BLEND ,
} ;
pip = sgp_make_pipeline ( & pip_desc ) ;
if ( sg_query_pipeline_state ( pip) ! = SG_RESOURCESTATE_VALID )
hueshift_ pipeline = sgp_make_pipeline ( & pip_desc ) ;
if ( sg_query_pipeline_state ( hueshift_ pipeline ) ! = SG_RESOURCESTATE_VALID )
{
fprintf ( stderr , " failed to make custom pipeline \n " ) ;
fprintf ( stderr , " failed to make hueshift pipeline \n " ) ;
exit ( - 1 ) ;
}
}
{
sgp_pipeline_desc pip_desc = {
. shader = * goodpixel_program_shader_desc ( sg_query_backend ( ) ) ,
. blend_mode = SGP_BLENDMODE_BLEND ,
} ;
goodpixel_pipeline = sgp_make_pipeline ( & pip_desc ) ;
if ( sg_query_pipeline_state ( goodpixel_pipeline ) ! = SG_RESOURCESTATE_VALID )
{
fprintf ( stderr , " failed to make goodpixel pipeline \n " ) ;
exit ( - 1 ) ;
}
}
@ -476,6 +530,10 @@ static void init(void)
image_squad_invite = load_image ( " loaded/squad_invite.png " ) ;
image_check = load_image ( " loaded/check.png " ) ;
image_no = load_image ( " loaded/no.png " ) ;
image_solarpanel_charging = load_image ( " loaded/solarpanel_charging.png " ) ;
image_scanner_head = load_image ( " loaded/scanner_head.png " ) ;
image_itemswitch = load_image ( " loaded/itemswitch.png " ) ;
image_cloaking_panel = load_image ( " loaded/cloaking_panel.png " ) ;
}
// socket initialization
@ -526,23 +584,30 @@ static void init(void)
}
}
}
}
}
# define transform_scope DeferLoop(sgp_push_transform(), sgp_pop_transform())
static void set_pipeline_and_pull_color ( sg_pipeline pip )
{
sgp_set_pipeline ( pip ) ;
sgp_set_uniform ( & sgp_query_state ( ) - > color , sizeof ( sgp_query_state ( ) - > color ) ) ;
}
# define pipeline_scope(pipeline) DeferLoop(set_pipeline_and_pull_color(pipeline), sgp_reset_pipeline())
static void draw_color_rect_centered ( V2 center , float size )
{
float halfbox = size / 2.0f ;
sgp_draw_filled_rect ( center . x - halfbox , center . y - halfbox , size , size ) ;
}
static void draw_texture_rectangle_centered ( V2 center , V2 width_height )
{
V2 halfsize = V2scale ( width_height , 0.5f ) ;
sgp_draw_textured_rect ( center . x - halfsize . x , center . y - halfsize . y ,
width_height . x , width_height . y ) ;
sgp_draw_textured_rect ( center . x - halfsize . x , center . y - halfsize . y , width_height . x , width_height . y ) ;
}
static void draw_texture_centered ( V2 center , float size )
{
draw_texture_rectangle_centered ( center , ( V2 ) { size , size } ) ;
@ -569,19 +634,21 @@ static void draw_circle(V2 point, float radius)
bool can_build ( int i )
{
bool allow_building = true ;
if ( boxinfo ( ( enum BoxType ) i ) . needs_tobe_unlocked )
{
enum BoxType box_type = ( enum BoxType ) i ;
allow_building = false ;
if ( myplayer ( ) ! = NULL )
allow_building = myplayer ( ) - > unlocked_bombs ;
}
allow_building = box_unlocked ( myplayer ( ) , box_type ) ;
return allow_building ;
}
void attempt_to_build ( int i )
static void setup_hueshift ( enum Squad squad )
{
if ( can_build ( i ) )
cur_editing_boxtype = i ;
struct SquadMeta meta = squad_meta ( squad ) ;
hueshift_uniforms_t uniform = {
. is_colorless = meta . is_colorless ,
. target_hue = meta . hue ,
} ;
sgp_set_uniform ( & uniform , sizeof ( hueshift_uniforms_t ) ) ;
}
static V2 screen_to_world ( float width , float height , V2 screen )
@ -616,6 +683,108 @@ static void ui(bool draw, float dt, float width, float height)
if ( draw )
sgp_push_transform ( ) ;
// draw pick new box type menu
static float pick_opacity = 0.0f ;
{
if ( keypressed [ SAPP_KEYCODE_ESCAPE ] . pressed )
picking_new_boxtype = false ;
AABB pick_modal = ( AABB ) {
. x = width * 0.25f ,
. y = height * 0.25f ,
. width = width * 0.5f ,
. height = height * 0.5f ,
} ;
pick_opacity = lerp ( pick_opacity , picking_new_boxtype ? 1.0f : 0.0f , dt * 7.0f ) ;
if ( picking_new_boxtype )
{
if ( build_pressed )
{
if ( has_point ( pick_modal , mouse_pos ) )
{
}
else
{
build_pressed = false ;
picking_new_boxtype = false ;
}
}
}
static float item_scaling [ ARRLEN ( boxes ) ] = { 1.0f } ;
{
float alpha = pick_opacity * 0.8f ;
if ( draw )
{
sgp_set_color ( 0.4f , 0.4f , 0.4f , alpha ) ;
sgp_draw_filled_rect ( pick_modal . x , pick_modal . y , pick_modal . width , pick_modal . height ) ;
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f * pick_opacity ) ;
}
int boxes_per_row = ( int ) floorf ( pick_modal . width / 128.0f ) ;
boxes_per_row = boxes_per_row < 4 ? 4 : boxes_per_row ;
float cell_width = pick_modal . width / ( float ) boxes_per_row ;
float cell_height = cell_width ;
float padding = 0.2f * cell_width ;
int cur_row = 0 ;
int cur_column = 0 ;
for ( int i = 0 ; i < ARRLEN ( boxes ) ; i + + )
{
if ( cur_column > = boxes_per_row )
{
cur_column = 0 ;
cur_row + + ;
}
float item_width = cell_width - padding * 2.0f ;
float item_height = cell_height - padding * 2.0f ;
item_width * = item_scaling [ i ] ;
item_height * = item_scaling [ i ] ;
float cell_y = pick_modal . y + ( float ) cur_row * cell_height ;
float cell_x = pick_modal . x + ( float ) cur_column * cell_width ;
float item_x = cell_x + ( cell_width - item_width ) / 2.0f ;
float item_y = cell_y + ( cell_height - item_height ) / 2.0f ;
bool item_being_hovered = has_point ( ( AABB ) {
. x = item_x ,
. y = item_y ,
. width = item_width ,
. height = item_height ,
} ,
mouse_pos ) ;
item_scaling [ i ] = lerp ( item_scaling [ i ] , item_being_hovered ? 1.3f : 1.0f , dt * 4.0f ) ;
struct BoxInfo info = boxes [ i ] ;
if ( item_being_hovered & & build_pressed & & picking_new_boxtype )
{
toolbar [ cur_toolbar_slot ] = info . type ;
picking_new_boxtype = false ;
build_pressed = false ;
}
if ( draw )
{
if ( can_build ( info . type ) )
{
sgp_set_image ( 0 , info . image ) ;
}
else
{
sgp_set_image ( 0 , image_mystery ) ;
}
transform_scope
{
sgp_scale_at ( 1.0f , - 1.0f , item_x + item_width / 2.0f , item_y + item_height / 2.0f ) ;
pipeline_scope ( goodpixel_pipeline )
sgp_draw_textured_rect ( item_x , item_y , item_width , item_height ) ;
sgp_reset_image ( 0 ) ;
}
}
cur_column + + ;
}
}
}
// draw squad invite
static float invite_y = - 200.0f ;
static enum Squad draw_as_squad = SquadNone ;
@ -643,9 +812,15 @@ static void ui(bool draw, float dt, float width, float height)
no_size = lerp ( no_size , no_hovered ? 75.0f : 50.0f , dt * 9.0f ) ;
if ( invited & & build_pressed & & yes_hovered )
{
accept_invite = true ;
build_pressed = false ;
}
if ( invited & & build_pressed & & no_hovered )
{
reject_invite = true ;
build_pressed = false ;
}
if ( draw )
{
@ -656,19 +831,15 @@ static void ui(bool draw, float dt, float width, float height)
transform_scope
{
sgp_set_pipeline ( pip ) ;
struct SquadMeta meta = squad_meta ( draw_as_squad ) ;
hueshift_uniforms_t uniform = { 0 } ;
uniform . is_colorless = meta . is_colorless ;
uniform . target_hue = meta . hue ;
sgp_set_uniform ( & uniform , sizeof ( hueshift_uniforms_t ) ) ;
pipeline_scope ( hueshift_pipeline )
{
setup_hueshift ( draw_as_squad ) ;
sgp_scale_at ( 1.0f , - 1.0f , x ,
invite_y ) ; // images upside down by default :(
sgp_set_image ( 0 , image_squad_invite ) ;
draw_texture_centered ( ( V2 ) { x , invite_y } , size ) ;
sgp_reset_image ( 0 ) ;
sgp_reset_pipeline ( ) ;
}
}
// yes
@ -677,7 +848,10 @@ static void ui(bool draw, float dt, float width, float height)
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
sgp_scale_at ( 1.0f , - 1.0f , yes_x , buttons_y ) ;
sgp_set_image ( 0 , image_check ) ;
pipeline_scope ( goodpixel_pipeline )
{
draw_texture_centered ( ( V2 ) { yes_x , buttons_y } , yes_size ) ;
}
sgp_reset_image ( 0 ) ;
}
@ -687,7 +861,10 @@ static void ui(bool draw, float dt, float width, float height)
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
sgp_scale_at ( 1.0f , - 1.0f , no_x , buttons_y ) ;
sgp_set_image ( 0 , image_no ) ;
pipeline_scope ( goodpixel_pipeline )
{
draw_texture_centered ( ( V2 ) { no_x , buttons_y } , no_size ) ;
}
sgp_reset_image ( 0 ) ;
}
}
@ -725,19 +902,16 @@ static void ui(bool draw, float dt, float width, float height)
size ) ;
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
}
sgp_set_pipeline ( pip ) ;
struct SquadMeta meta = squad_meta ( myplayer ( ) - > squad ) ;
hueshift_uniforms_t uniform = { 0 } ;
uniform . is_colorless = meta . is_colorless ;
uniform . target_hue = meta . hue ;
sgp_set_uniform ( & uniform , sizeof ( hueshift_uniforms_t ) ) ;
pipeline_scope ( hueshift_pipeline )
{
setup_hueshift ( myplayer ( ) - > squad ) ;
sgp_scale_at ( 1.0f , - 1.0f , pos . x ,
pos . y ) ; // images upside down by default :(
sgp_set_image ( 0 , image_squad_invite ) ;
draw_texture_centered ( pos , size ) ;
sgp_reset_image ( 0 ) ;
sgp_reset_pipeline ( ) ;
}
}
}
}
@ -852,12 +1026,9 @@ static void ui(bool draw, float dt, float width, float height)
sgp_set_image ( 0 , image_flag_taken ) ;
}
sgp_set_pipeline ( pip ) ;
struct SquadMeta meta = squad_meta ( this_squad ) ;
hueshift_uniforms_t uniform = { 0 } ;
uniform . is_colorless = meta . is_colorless ;
uniform . target_hue = meta . hue ;
sgp_set_uniform ( & uniform , sizeof ( hueshift_uniforms_t ) ) ;
pipeline_scope ( hueshift_pipeline )
{
setup_hueshift ( this_squad ) ;
sgp_rotate_at ( flag_rot [ i ] , flag_pos [ i ] . x , flag_pos [ i ] . y ) ;
sgp_scale_at ( 1.0f , - 1.0f , flag_pos [ i ] . x ,
@ -865,7 +1036,7 @@ static void ui(bool draw, float dt, float width, float height)
draw_texture_centered ( flag_pos [ i ] , size ) ;
sgp_reset_image ( 0 ) ;
sgp_reset_pipeline ( ) ;
}
}
}
}
@ -934,7 +1105,7 @@ static void ui(bool draw, float dt, float width, float height)
( float ) sg_query_image_info ( image_itemframe ) . width * 2.0f ;
float itemframe_height =
( float ) sg_query_image_info ( image_itemframe ) . height * 2.0f ;
float total_width = itemframe_width * ARRLEN ( boxes ) ;
float total_width = itemframe_width * ( float ) TOOLBAR_SLOTS ;
float item_width = itemframe_width * 0.75f ;
float item_height = itemframe_height * 0.75f ;
float item_offset_x = ( itemframe_width - item_width ) / 2.0f ;
@ -942,8 +1113,9 @@ static void ui(bool draw, float dt, float width, float height)
float x = width / 2.0f - total_width / 2.0f ;
float y = height - itemframe_height * 1.5f ;
for ( int i = 0 ; i < ARRLEN ( boxes ) ; i + + )
for ( int i = 0 ; i < TOOLBAR_SLOTS ; i + + )
{
// mouse over the item frame box
if ( has_point (
( AABB ) {
. x = x ,
@ -955,14 +1127,38 @@ static void ui(bool draw, float dt, float width, float height)
build_pressed )
{
// "handle" mouse pressed
attempt_to_build ( i ) ;
cur_toolbar_slot = i ;
build_pressed = false ;
}
// mouse over the item switch button
bool switch_hovered = false ;
if ( has_point (
( AABB ) {
. x = x ,
. y = y - 20.0f ,
. width = itemframe_width ,
. height = itemframe_height * 0.2f ,
} ,
mouse_pos ) )
{
switch_hovered = true ;
}
if ( switch_hovered & & build_pressed )
{
picking_new_boxtype = true ;
build_pressed = false ;
}
if ( draw )
{
sgp_set_color ( 1.0f , 1.0f , 1.0f , cur_opacity ) ;
if ( cur_editing_boxtype = = i )
bool is_current = cur_toolbar_slot = = i ;
static float switch_scaling = 1.0f ;
switch_scaling = lerp ( switch_scaling , switch_hovered ? 1.8f : 1.2f , dt * 3.0f ) ;
if ( is_current )
{
sgp_set_image ( 0 , image_itemframe_selected ) ;
}
@ -970,27 +1166,42 @@ static void ui(bool draw, float dt, float width, float height)
{
sgp_set_image ( 0 , image_itemframe ) ;
}
pipeline_scope ( goodpixel_pipeline )
sgp_draw_textured_rect ( x , y , itemframe_width , itemframe_height ) ;
struct BoxInfo info = boxinfo ( ( enum BoxType ) i ) ;
if ( can_build ( i ) )
{
sgp_set_image ( 0 , info . image ) ;
}
else
{
sgp_set_image ( 0 , image_mystery ) ;
}
sgp_reset_image ( 0 ) ;
transform_scope
{
float item_x = x + item_offset_x ;
float item_y = y + item_offset_y ;
sgp_scale_at ( 1.0f , - 1.0f , item_x + item_width / 2.0f ,
item_y + item_height / 2.0f ) ;
// sgp_scale(1.0f, -1.0f);
pipeline_scope ( goodpixel_pipeline )
{
if ( toolbar [ i ] ! = BoxInvalid )
{
struct BoxInfo info = boxinfo ( toolbar [ i ] ) ;
if ( can_build ( info . type ) )
sgp_set_image ( 0 , info . image ) ;
else
sgp_set_image ( 0 , image_mystery ) ;
sgp_draw_textured_rect ( item_x , item_y , item_width , item_height ) ;
sgp_reset_image ( 0 ) ;
}
if ( is_current )
{
sgp_set_image ( 0 , image_itemswitch ) ;
float switch_item_width = item_width * switch_scaling ;
float switch_item_height = item_height * switch_scaling ;
item_x - = ( switch_item_width - item_width ) / 2.0f ;
item_y - = ( switch_item_height - item_height ) / 2.0f ;
sgp_draw_textured_rect ( item_x , item_y + 20.0f , switch_item_width , switch_item_height ) ;
sgp_reset_image ( 0 ) ;
}
}
}
}
x + = itemframe_width ;
}
}
@ -1076,6 +1287,11 @@ static void frame(void)
{
switch ( event . type )
{
case ENET_EVENT_TYPE_NONE :
{
Log ( " Wtf none event type? \n " ) ;
break ;
}
case ENET_EVENT_TYPE_CONNECT :
{
Log ( " New client from host %x \n " , event . peer - > address . host ) ;
@ -1084,7 +1300,7 @@ static void frame(void)
case ENET_EVENT_TYPE_RECEIVE :
{
char * decompressed = malloc (
unsigned char * decompressed = malloc (
sizeof * decompressed * MAX_SERVER_TO_CLIENT ) ; // @Robust no malloc
size_t decompressed_max_len = MAX_SERVER_TO_CLIENT ;
assert ( LZO1X_MEM_DECOMPRESS = = 0 ) ;
@ -1246,6 +1462,7 @@ static void frame(void)
if ( V2length ( input ) > 0.0 )
input = V2normalize ( input ) ;
cur_input_frame . movement = input ;
cur_input_frame . rotation = ( float ) keydown [ SAPP_KEYCODE_E ] - ( float ) keydown [ SAPP_KEYCODE_Q ] ;
if ( interact_pressed )
cur_input_frame . seat_action = interact_pressed ;
@ -1273,20 +1490,16 @@ static void frame(void)
reject_invite = false ;
}
if ( build_pressed & & cur_editing_boxtype ! = - 1 )
if ( build_pressed & & currently_building ( ) ! = BoxInvalid )
{
cur_input_frame . dobuild = build_pressed ;
cur_input_frame . build_type = cur_editing_boxtype ;
cur_input_frame . build_type = currently_building ( ) ;
cur_input_frame . build_rotation = cur_editing_rotation ;
}
// "commit" the input. each input must be on a successive tick.
if ( tick ( & gs ) > last_input_committed_tick )
{
if ( cur_input_frame . take_over_squad ! = - 1 )
{
Log ( " Sending take over squad at tick %zu \n " , tick ( & gs ) ) ;
}
cur_input_frame . tick = tick ( & gs ) ;
last_input_committed_tick = tick ( & gs ) ;
@ -1326,12 +1539,12 @@ static void frame(void)
. mic_data = & packets_to_send ,
. input_data = & input_queue ,
} ;
char serialized [ MAX_CLIENT_TO_SERVER ] = { 0 } ;
unsigned char serialized [ MAX_CLIENT_TO_SERVER ] = { 0 } ;
size_t out_len = 0 ;
if ( client_to_server_serialize ( & gs , & to_send , serialized , & out_len ,
MAX_CLIENT_TO_SERVER ) )
{
char compressed [ MAX_CLIENT_TO_SERVER ] = { 0 } ;
unsigned char compressed [ MAX_CLIENT_TO_SERVER ] = { 0 } ;
char lzo_working_mem [ LZO1X_1_MEM_COMPRESS ] = { 0 } ;
size_t compressed_len = 0 ;
@ -1358,8 +1571,8 @@ static void frame(void)
global_hand_pos =
get_global_hand_pos ( world_mouse_pos , & hand_at_arms_length ) ;
Entity * placing_grid = closest_to_point_in_radius(
& gs , global_hand_pos , BUILD_BOX_SNAP_DIST_TO_SHIP );
Entity * placing_grid = box_grid( closest_box _to_point_in_radius(
& gs , global_hand_pos , BUILD_BOX_SNAP_DIST_TO_SHIP , NULL ) );
if ( placing_grid = = NULL )
{
build_preview = ( struct BuildPreviewInfo ) {
@ -1410,8 +1623,8 @@ static void frame(void)
( float ) sg_query_image_info ( image_stars ) . width ;
const float stars_width = 35.0f ;
float stars_height = stars_width * stars_height_over_width ;
sgp_draw_textured_rect( - stars_width / 2.0f , - stars_height / 2.0f ,
stars_width , stars_height ) ;
pipeline_scope( goodpixel_pipeline )
sgp_draw_textured_rect ( - stars_width / 2.0f , - stars_height / 2.0f , stars_width , stars_height ) ;
// sgp_draw_textured_rect(0, 0, stars_width, stars_height);
sgp_reset_image ( 0 ) ;
}
@ -1427,8 +1640,8 @@ static void frame(void)
( float ) sg_query_image_info ( image_stars ) . width ;
const float stars_width = 35.0f ;
float stars_height = stars_width * stars_height_over_width ;
sgp_draw_textured_rect( - stars_width / 2.0f , - stars_height / 2.0f ,
stars_width , stars_height ) ;
pipeline_scope( goodpixel_pipeline )
sgp_draw_textured_rect ( - stars_width / 2.0f , - stars_height / 2.0f , stars_width , stars_height ) ;
// sgp_draw_textured_rect(0, 0, stars_width, stars_height);
sgp_reset_image ( 0 ) ;
}
@ -1483,17 +1696,18 @@ static void frame(void)
}
// building preview
if ( cur_editing_boxtype ! = - 1 )
if ( currently_building ( ) ! = BoxInvalid & & can_build ( currently_building ( ) ) )
{
sgp_set_color ( 0.5f , 0.5f , 0.5f ,
( sinf ( ( float ) time * 9.0f ) + 1.0f ) / 3.0f + 0.2f ) ;
transform_scope
{
sgp_set_image ( 0 , boxinfo ( cur_editing_boxtype ) . image ) ;
sgp_set_image ( 0 , boxinfo ( currently_building ( ) ) . image ) ;
sgp_rotate_at ( build_preview . grid_rotation +
rotangle ( cur_editing_rotation ) ,
global_hand_pos . x , global_hand_pos . y ) ;
pipeline_scope ( goodpixel_pipeline )
draw_texture_centered ( global_hand_pos , BOX_SIZE ) ;
// drawbox(hand_pos, build_preview.grid_rotation, 0.0f,
// cur_editing_boxtype, cur_editing_rotation);
@ -1511,11 +1725,6 @@ static void frame(void)
Entity * g = e ;
BOXES_ITER ( & gs , b , g )
{
if ( b - > is_explosion_unlock )
{
set_color ( colhexcode ( 0xfcba03 ) ) ;
draw_circle ( entity_pos ( b ) , GOLD_UNLOCK_RADIUS ) ;
}
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
if ( b - > box_type = = BoxBattery )
{
@ -1539,7 +1748,10 @@ static void frame(void)
sgp_set_image ( 0 , image_thrusterburn ) ;
float scaling = 0.95f + lerp ( 0.0f , 0.3f , b - > thrust ) ;
sgp_scale_at ( scaling , 1.0f , entity_pos ( b ) . x , entity_pos ( b ) . y ) ;
pipeline_scope ( goodpixel_pipeline )
{
draw_texture_centered ( entity_pos ( b ) , BOX_SIZE ) ;
}
sgp_reset_image ( 0 ) ;
}
}
@ -1554,24 +1766,93 @@ static void frame(void)
if ( get_entity ( & gs , b - > player_who_is_inside_of_me ) ! = NULL )
img = image_medbay_used ;
}
if ( b - > box_type = = BoxSolarPanel )
{
sgp_set_image ( 0 , image_solarpanel_charging ) ;
sgp_set_color ( 1.0f , 1.0f , 1.0f , b - > sun_amount ) ;
pipeline_scope ( goodpixel_pipeline )
draw_texture_centered ( entity_pos ( b ) , BOX_SIZE ) ;
sgp_reset_image ( 0 ) ;
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f - b - > sun_amount ) ;
/* Color to_set = colhexcode(0xeb9834);
to_set . a = b - > sun_amount * 0.5f ;
set_color ( to_set ) ;
draw_color_rect_centered ( entity_pos ( b ) , BOX_SIZE ) ;
*/
}
sgp_set_image ( 0 , img ) ;
if ( b - > indestructible )
{
sgp_set_color ( 0.2f , 0.2f , 0.2f , 1.0f ) ;
}
else if ( b - > is_platonic )
{
set_color ( GOLD ) ;
}
// all of these box types show team colors so are drawn with the hue shifting shader
// used with the player
if ( b - > box_type = = BoxCloaking )
{
pipeline_scope ( hueshift_pipeline )
{
setup_hueshift ( b - > owning_squad ) ;
draw_texture_centered ( entity_pos ( b ) , BOX_SIZE ) ;
}
}
else
{
pipeline_scope ( goodpixel_pipeline )
draw_texture_centered ( entity_pos ( b ) , BOX_SIZE ) ;
}
sgp_reset_image ( 0 ) ;
if ( b - > box_type = = BoxSolarPanel )
if ( b - > box_type = = BoxS canner )
{
Color to_set = colhexcode ( 0xeb9834 ) ;
to_set . a = b - > sun_amount * 0.5f ;
set_color ( to_set ) ;
draw_color_rect_centered ( entity_pos ( b ) , BOX_SIZE ) ;
sgp_set_image ( 0 , image_scanner_head ) ;
transform_scope
{
pipeline_scope ( goodpixel_pipeline )
{
sgp_rotate_at ( b - > scanner_head_rotate , entity_pos ( b ) . x , entity_pos ( b ) . y ) ;
draw_texture_centered ( entity_pos ( b ) , BOX_SIZE ) ;
}
}
sgp_reset_image ( 0 ) ;
set_color ( WHITE ) ;
}
if ( b - > box_type = = BoxScanner )
{
set_color ( BLUE ) ;
draw_circle ( entity_pos ( b ) , SCANNER_RADIUS ) ;
set_color ( WHITE ) ;
}
sgp_set_color ( 0.5f , 0.1f , 0.1f , b - > damage ) ;
draw_color_rect_centered ( entity_pos ( b ) , BOX_SIZE ) ;
if ( b - > box_type = = BoxCloaking )
{
sgp_set_color ( 1.0f , 1.0f , 1.0f , b - > cloaking_power ) ;
sgp_set_image ( 0 , image_cloaking_panel ) ;
pipeline_scope ( goodpixel_pipeline )
draw_texture_centered ( entity_pos ( b ) , CLOAKING_PANEL_SIZE ) ;
sgp_reset_image ( 0 ) ;
}
}
// outside of the transform scope
if ( b - > box_type = = BoxScanner )
{
if ( b - > platonic_detection_strength > 0.0 )
{
set_color ( colhexcode ( 0xf2d75c ) ) ;
V2 to = V2add ( entity_pos ( b ) , V2scale ( b - > platonic_nearest_direction , b - > platonic_detection_strength ) ) ;
dbg_rect ( to ) ;
dbg_rect ( entity_pos ( b ) ) ;
sgp_draw_line ( entity_pos ( b ) . x , entity_pos ( b ) . y , to . x , to . y ) ;
}
}
}
}
@ -1585,17 +1866,14 @@ static void frame(void)
sgp_rotate_at ( entity_rotation ( e ) , entity_pos ( e ) . x , entity_pos ( e ) . y ) ;
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
sgp_set_pipeline ( pip ) ;
struct SquadMeta meta = squad_meta ( e - > presenting_squad ) ;
hueshift_uniforms_t uniform = { 0 } ;
uniform . is_colorless = meta . is_colorless ;
uniform . target_hue = meta . hue ;
sgp_set_uniform ( & uniform , sizeof ( hueshift_uniforms_t ) ) ;
pipeline_scope ( hueshift_pipeline )
{
setup_hueshift ( e - > presenting_squad ) ;
sgp_set_image ( 0 , image_player ) ;
draw_texture_rectangle_centered (
entity_pos ( e ) , V2scale ( PLAYER_SIZE , player_scaling ) ) ;
sgp_reset_image ( 0 ) ;
sgp_reset_pipeline ( ) ;
}
}
}
if ( e - > is_explosion )
@ -1621,9 +1899,14 @@ static void frame(void)
draw_texture_centered ( ( V2 ) { 0 } , SUN_RADIUS * 2.0f ) ;
sgp_reset_image ( 0 ) ;
// can draw at 0,0 because everything relative to sun now!
// sun DEATH RADIUS
set_color ( RED ) ;
draw_circle ( ( V2 ) { 0 } , INSTANT_DEATH_DISTANCE_FROM_SUN ) ;
set_color ( BLUE ) ;
draw_circle ( ( V2 ) { 0 } , SUN_NO_MORE_ELECTRICITY_OR_GRAVITY ) ;
}
sgp_set_color ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
@ -1654,7 +1937,7 @@ static void frame(void)
void cleanup ( void )
{
sg_destroy_pipeline ( pip) ;
sg_destroy_pipeline ( hueshift_ pipeline ) ;
ma_mutex_lock ( & server_info . info_mutex ) ;
server_info . should_quit = true ;
@ -1706,10 +1989,18 @@ void event(const sapp_event *e)
fullscreened = false ;
}
int key_num = e - > key_code - SAPP_KEYCODE_0 ;
int target_box = key_num - 1 ;
if ( target_box < BoxLast & & target_box > = 0 )
int target_slot = key_num - 1 ;
if ( target_slot < = TOOLBAR_SLOTS & & target_slot > = 0 )
{
if ( target_slot = = cur_toolbar_slot )
{
attempt_to_build ( target_box ) ;
picking_new_boxtype = ! picking_new_boxtype ;
}
else
{
picking_new_boxtype = false ;
}
cur_toolbar_slot = target_slot ;
}
if ( ! mouse_frozen )
@ -1759,6 +2050,9 @@ void event(const sapp_event *e)
Log ( " Funval %f \n " , funval ) ;
}
break ;
default :
{
}
}
}