Fix star and galaxy rendering

main
Cameron Murphy Reikes 2 years ago
parent 144a2a532f
commit 72e36e9b3d

Binary file not shown.

@ -1224,17 +1224,38 @@ static void ui(bool draw, float dt, float width, float height)
static void draw_dots(V2 camera_pos, float gap)
{
sgp_set_color(1.0f, 1.0f, 1.0f, 1.0f);
const int num = 100;
for (int x = -num; x < num; x++)
// const int num = 100;
// initial_x * gap = camera_pos.x - VISION_RADIUS
// initial_x = (camera_pos.x - VISION_RADIUS) / gap
// int initial_x = (int)floorf((camera_pos.x - VISION_RADIUS) / gap);
// int final_x = (int)floorf((camera_pos.x + VISION_RADIUS) / gap);
// -VISION_RADIUS < x * gap - camera_pos.x < VISION_RADIUS
// -VISION_RADIUS + camera_pos.x < x * gap < VISION_RADIUS + camera_pos.x
// (-VISION_RADIUS + camera_pos.x)/gap < x < (VISION_RADIUS + camera_pos.x)/gap
int initial_x = (int)floorf((-VISION_RADIUS*2 + camera_pos.x)/gap);
int final_x = (int)ceilf((VISION_RADIUS*2 + camera_pos.x)/gap);
int initial_y = (int)floorf((-VISION_RADIUS*2 + camera_pos.y)/gap);
int final_y = (int)ceilf((VISION_RADIUS*2 + camera_pos.y)/gap);
// initial_x = -num;
// final_x = num;
for (int x = initial_x; x < final_x; x++)
{
for (int y = -num; y < num; y++)
for (int y = initial_y; y < final_y; y++)
{
V2 star = (V2){(float)x * gap, (float)y * gap};
star.x += hash11(star.x * 100.0f + star.y * 67.0f) * gap;
star.y += hash11(star.y * 93.0f + star.x * 53.0f) * gap;
if (V2lengthsqr(V2sub(star, camera_pos)) > VISION_RADIUS * VISION_RADIUS)
continue;
star.x += hash11(star.x * 100.0f + star.y * 67.0f) * gap;
star.y += hash11(star.y * 93.0f + star.x * 53.0f) * gap;
sgp_draw_point(star.x, star.y);
}
}
@ -1624,7 +1645,7 @@ static void frame(void)
transform_scope
{
V2 scaled_camera_pos = V2scale(
camera_pos, 0.05f); // this is how strong/weak the parallax is
camera_pos, 0.0005f); // 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);
@ -1641,7 +1662,7 @@ static void frame(void)
transform_scope
{
V2 scaled_camera_pos = V2scale(
camera_pos, 0.1f); // this is how strong/weak the parallax is
camera_pos, 0.005f); // 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_stars2);
@ -2080,7 +2101,7 @@ void event(const sapp_event *e)
break;
case SAPP_EVENTTYPE_MOUSE_SCROLL:
zoom_target *= 1.0f + (e->scroll_y / 4.0f) * 0.1f;
zoom_target = clamp(zoom_target, 0.5f, 900.0f);
zoom_target = clamp(zoom_target, ZOOM_MIN, ZOOM_MAX);
break;
case SAPP_EVENTTYPE_MOUSE_DOWN:
mousedown[e->mouse_button] = true;

@ -3,6 +3,8 @@
#include "ipsettings.h"
#define MAX_BOX_TYPES 64
#define ZOOM_MIN 0.25f
#define ZOOM_MAX 1500.0f
#define MAX_PLAYERS 16
#define MAX_SUNS 8
#define MAX_ENTITIES 1024 * 25
@ -46,7 +48,7 @@
#define MAX_CLIENT_TO_SERVER 1024 * 10 // maximum size of serialized inputs and mic data
#define GRAVITY_CONSTANT 0.1f
#define GRAVITY_SMALLEST 0.01f // used to determine when gravity is clamped to 0.0f
#define INSTANT_DEATH_DISTANCE_FROM_CENTER 2000.0f
#define INSTANT_DEATH_DISTANCE_FROM_CENTER 4000.0f
#define SOLAR_ENERGY_PER_SECOND 0.09f
#define DAMAGE_TO_PLAYER_PER_BLOCK 0.1f
#define BATTERY_CAPACITY 1.5f

Loading…
Cancel
Save