Parallax stars and developer helpers

main
Cameron Murphy Reikes 2 years ago
parent 75734752e3
commit b11767a284

@ -1008,10 +1008,9 @@ void process(GameState* gs, float dt)
}
assert(p->is_player);
if (INFINITE_RESOURCES)
{
#ifdef INFINITE_RESOURCES
p->spice_taken_away = 0.0f;
}
#endif
// update gold win condition
if (V2length(V2sub(cp_to_v2(cpBodyGetPosition(p->body)), gs->goldpos)) < GOLD_COLLECT_RADIUS)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -48,6 +48,7 @@ static sg_image image_itemframe_selected;
static sg_image image_thrusterburn;
static sg_image image_player;
static sg_image image_cockpit_used;
static sg_image image_stars;
static int cur_editing_boxtype = -1;
static int cur_editing_rotation = 0;
@ -153,6 +154,7 @@ init(void)
image_itemframe_selected = load_image("loaded/itemframe_selected.png");
image_player = load_image("loaded/player.png");
image_cockpit_used = load_image("loaded/cockpit_used.png");
image_stars = load_image("loaded/stars.png");
}
// socket initialization
@ -548,7 +550,7 @@ frame(void)
sgp_set_blend_mode(SGP_BLENDMODE_BLEND);
// Draw background color
set_color(colhexcode(0x020509));
set_color(colhexcode(0x000000));
// sgp_set_color(0.1f, 0.1f, 0.1f, 1.0f);
sgp_clear();
@ -559,9 +561,59 @@ frame(void)
sgp_translate(width / 2, height / 2);
sgp_scale_at(zoom, -zoom, 0.0f, 0.0f);
// parllax layers, just the zooming, but not 100% of the camera panning
#if 1 // space background
transform_scope
{
V2 scaled_camera_pos = V2scale(camera_pos, 0.1f); // this is how strong/weak the parallax is
sgp_translate(-scaled_camera_pos.x, -scaled_camera_pos.y);
set_color(WHITE);
sgp_set_image(0, image_stars);
float stars_height_over_width = (float)sg_query_image_info(image_stars).height / (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);
//sgp_draw_textured_rect(0, 0, stars_width, stars_height);
sgp_reset_image(0);
}
#endif
// camera go to player
sgp_translate(-camera_pos.x, -camera_pos.y);
#if 0 // radius of viewership, dots which contextualize stuff
{
set_color(WHITE);
for (float r = 1.0f; r <= VISION_RADIUS; r += 1.0f)
{
for (float theta = 0.0f; theta < 2.0f * PI; theta += 0.1f)
{
V2 pos = V2scale((V2){ cosf(theta), sinf(theta) }, r);
sgp_draw_point(pos.x, pos.y);
}
}
}
#endif
#if 1 // test grid of dots
{
sgp_set_color(1.0f, 1.0f, 1.0f, 1.0f);
const int num = 100;
for (int x = -num; x < num; x++) {
for (int y = -num; y < num; y++) {
float gap = 0.5f;
V2 star = (V2){ (float)x * gap, (float)y * gap };
if (fabsf(star.x - camera_pos.x) > VISION_RADIUS)
continue;
if (fabsf(star.y - camera_pos.y) > VISION_RADIUS)
continue;
star.x += hash11(star.x*100.0f + star.y*67.0f);
star.y += hash11(star.y*93.0f + star.x*53.0f);
sgp_draw_point(star.x, star.y);
}
}
}
#endif
// hand reached limit circle
if (myentity() != NULL) {
static float hand_reach_alpha = 1.0f;
@ -570,18 +622,9 @@ frame(void)
draw_circle(entity_pos(myentity()), MAX_HAND_REACH);
}
// stars
sgp_set_color(1.0f, 1.0f, 1.0f, 1.0f);
const int num = 30;
for (int x = -num; x < num; x++) {
for (int y = -num; y < num; y++) {
sgp_draw_point((float)x * 0.1f, (float)y * 0.1f);
}
}
float halfbox = BOX_SIZE / 2.0f;
// mouse
// mouse frozen, debugging tool
if (mouse_frozen) {
sgp_set_color(1.0f, 0.0f, 0.0f, 0.5f);
sgp_draw_filled_rect(world_mouse_pos.x, world_mouse_pos.y, 0.1f, 0.1f);
@ -668,13 +711,14 @@ frame(void)
draw_color_rect_centered(box_pos(b), BOX_SIZE);
}
}
// draw the velocity
sgp_set_color(1.0f, 0.0f, 0.0f, 1.0f);
V2 vel = grid_vel(g);
V2 to = V2add(grid_com(g), vel);
sgp_draw_line(grid_com(g).x, grid_com(g).y, to.x, to.y);
}
if (e->is_player && get_entity(&gs, e->currently_piloting_seat) == NULL) {
transform_scope
{
sgp_rotate_at(entity_rotation(e), entity_pos(e).x, entity_pos(e).y);

@ -226,6 +226,9 @@ void server(void* data)
size_t len = 0;
into_bytes(&to_send, bytes_buffer, &len, MAX_BYTES_SIZE);
#ifdef LOG_GAMESTATE_SIZE
Log("Size of gamestate packet: %zu\n", len);
#endif
ENetPacket* gamestate_packet = enet_packet_create((void*)bytes_buffer, len, ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
enet_peer_send(&server->peers[i], 0, gamestate_packet);
}

@ -13,6 +13,7 @@
#define BOX_MASS 1.0f
#define THRUSTER_FORCE 4.0f
#define THRUSTER_ENERGY_USED_PER_SECOND 0.05f
#define VISION_RADIUS 8.0f
#define TIMESTEP (1.0f / 60.0f) // not required to simulate at this, but this defines what tick the game is on
#define TIME_BETWEEN_INPUT_PACKETS (1.0f / 20.0f)
@ -377,6 +378,49 @@ static float lerp(float a, float b, float f)
return a * (1.0f - f) + (b * f);
}
static V2 V2floor(V2 p)
{
return (V2) { floorf(p.x), floorf(p.y) };
}
static V2 V2fract(V2 p)
{
return (V2) { fract(p.x), fract(p.y) };
}
/*
float noise(V2 p)
{
V2 id = V2floor(p);
V2 f = V2fract(p);
V2 u = V2dot(f, f) * (3.0f - 2.0f * f);
return mix(mix(random(id + V2(0.0, 0.0)),
random(id + V2(1.0, 0.0)), u.x),
mix(random(id + V2(0.0, 1.0)),
random(id + V2(1.0, 1.0)), u.x),
u.y);
}
float fbm(V2 p)
{
float f = 0.0;
float gat = 0.0;
for (float octave = 0.; octave < 5.; ++octave)
{
float la = pow(2.0, octave);
float ga = pow(0.5, octave + 1.);
f += ga * noise(la * p);
gat += ga;
}
f = f / gat;
return f;
}
*/
static V2 V2lerp(V2 a, V2 b, float factor)
{
V2 to_return = { 0 };

Loading…
Cancel
Save