Add the sun and extra stars in the background

main
Cameron Murphy Reikes 2 years ago
parent 3dd6f1a5ba
commit 16f3dfa443

@ -1005,6 +1005,10 @@ void process(GameState* gs, float dt)
p = new_entity(gs);
create_player(gs, p);
player->entity = get_id(gs, p);
cpVect pos = v2_to_cp(V2sub(entity_pos(p), SUN_POS));
cpFloat r = cpvlength(pos);
cpFloat v = cpfsqrt(SUN_GRAVITY_STRENGTH/ r) / r;
cpBodySetVelocity(p->body, cpvmult(cpvperp(pos), v));
}
assert(p->is_player);
@ -1149,12 +1153,26 @@ void process(GameState* gs, float dt)
p->spice_taken_away = clamp01(p->spice_taken_away);
}
// process grids
// process entities
for (size_t i = 0; i < gs->cur_next_entity; i++) {
Entity* e = &gs->entities[i];
if (!e->exists)
continue;
if (e->body != NULL)
{
cpVect p = cpvsub(cpBodyGetPosition(e->body),v2_to_cp(SUN_POS));
cpFloat sqdist = cpvlengthsq(p);
if (sqdist < (SUN_RADIUS * SUN_RADIUS))
{
entity_destroy(gs, e);
continue;
}
cpVect g = cpvmult(p, -SUN_GRAVITY_STRENGTH / (sqdist * cpfsqrt(sqdist)));
cpBodyUpdateVelocity(e->body, g, 1.0f, dt);
}
if (e->is_box)
{
if (e->damage >= 1.0f)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

@ -51,6 +51,8 @@ static sg_image image_thrusterburn;
static sg_image image_player;
static sg_image image_cockpit_used;
static sg_image image_stars;
static sg_image image_stars2;
static sg_image image_sun;
static int cur_editing_boxtype = -1;
static int cur_editing_rotation = 0;
@ -157,6 +159,8 @@ init(void)
image_player = load_image("loaded/player.png");
image_cockpit_used = load_image("loaded/cockpit_used.png");
image_stars = load_image("loaded/stars.png");
image_stars2 = load_image("loaded/stars2.png");
image_sun = load_image("loaded/sun.png");
}
// socket initialization
@ -597,7 +601,7 @@ frame(void)
#if 1 // space background
transform_scope
{
V2 scaled_camera_pos = V2scale(camera_pos, 0.1f); // this is how strong/weak the parallax is
V2 scaled_camera_pos = V2scale(camera_pos, 0.05f); // 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);
@ -608,6 +612,19 @@ frame(void)
//sgp_draw_textured_rect(0, 0, stars_width, stars_height);
sgp_reset_image(0);
}
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_stars2);
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
#if 1 // parallaxed dots
@ -750,6 +767,12 @@ frame(void)
set_color(GOLD);
sgp_draw_filled_rect(gs.goldpos.x, gs.goldpos.y, 0.1f, 0.1f);
// the SUN
set_color(WHITE);
sgp_set_image(0, image_sun);
draw_texture_centered(SUN_POS, SUN_RADIUS*2.0f);
sgp_reset_image(0);
sgp_set_color(1.0f, 1.0f, 1.0f, 1.0f);
dbg_drawall();
} // world space transform end

@ -22,7 +22,7 @@ void server(void* data)
Log("Allocated %zu bytes for entities\n", entities_size);
// one box policy
if (true)
if (false)
{
Entity* grid = new_entity(&gs);
grid_create(&gs, grid);

@ -13,8 +13,11 @@
#define BOX_MASS 1.0f
#define THRUSTER_FORCE 4.0f
#define THRUSTER_ENERGY_USED_PER_SECOND 0.05f
#define VISION_RADIUS 8.0f
#define VISION_RADIUS 16.0f
#define MAX_BYTES_SIZE 2048 * 2 // maximum size of gamestate buffer
#define SUN_RADIUS 10.0f
#define SUN_POS ((V2){50.0f,0.0f})
#define SUN_GRAVITY_STRENGTH (5.0e3f)
#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)

Loading…
Cancel
Save