Wrap all entities and shapes
This commit is contained in:
44
game.c
44
game.c
@@ -28,14 +28,14 @@
|
||||
#define ASTEROID_R_JITTER 0.02
|
||||
#define ASTEROID_MIN_DIST 0.8
|
||||
|
||||
#define REPLACE_MIN 2
|
||||
#define REPLACE_MAX 4
|
||||
#define REPLACE_MIN 3
|
||||
#define REPLACE_MAX 5
|
||||
#define REPLACE_RANGE (REPLACE_MAX - REPLACE_MIN)
|
||||
#define REPLACE_R_COEFF 0.5
|
||||
#define REPLACE_R_JITTER 0.02
|
||||
#define REPLACE_A_JITTER 0.4
|
||||
#define REPLACE_V_JITTER 0.001
|
||||
#define REPLACE_RADIAL_V_COEFF 0.005
|
||||
#define REPLACE_RADIAL_V_COEFF 0.006
|
||||
#define REPLACE_OMG_JITTER 0.01
|
||||
|
||||
#define LIN_PWR 0.0001
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
#define SHOT_VEL 0.04
|
||||
#define SHOT_COLLIDE_R 0.005
|
||||
#define SHOT_MASS 0.005
|
||||
#define SHOT_MASS 0.01
|
||||
|
||||
#define MAX_SHAPES 256U
|
||||
#define MAX_ENTITIES 128U
|
||||
@@ -67,7 +67,6 @@ typedef struct {
|
||||
unsigned shape_count;
|
||||
float radius;
|
||||
collision_tag_t tag;
|
||||
bool wrap;
|
||||
bool dead;
|
||||
} entity_t;
|
||||
|
||||
@@ -76,7 +75,7 @@ typedef struct {
|
||||
int entity;
|
||||
unsigned vert_count;
|
||||
vec2_t verts[MAX_VERTS];
|
||||
uint8_t flags;
|
||||
bool connect;
|
||||
} shape_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -162,13 +161,12 @@ static entity_t *gen_asteroid(float r_mean, unsigned *id_out)
|
||||
{
|
||||
unsigned id;
|
||||
entity_t *e = add_entity(&id);
|
||||
e->wrap = true;
|
||||
e->radius = r_mean;
|
||||
e->tag = COLLISION_ASTEROID;
|
||||
|
||||
shape_t *s = add_shape(id, nullptr);
|
||||
s->visible = true;
|
||||
s->flags = WRAP | CONNECT;
|
||||
s->connect = true;
|
||||
|
||||
const unsigned n
|
||||
= ASTEROID_MIN_VERTS + rng_uint32() % ASTEROID_VERT_RANGE;
|
||||
@@ -407,19 +405,18 @@ void game_init(float _aspect)
|
||||
entity_count = shape_count = 0;
|
||||
|
||||
entity_t *ship = add_entity(&ship_entity_id);
|
||||
ship->wrap = true;
|
||||
ship->radius = SHIP_COLLIDE_R;
|
||||
ship->tag = COLLISION_SHIP;
|
||||
|
||||
shape_t *ship_shape = add_shape(ship_entity_id, &ship_shape_id);
|
||||
ship_shape->visible = true;
|
||||
ship_shape->flags = WRAP | CONNECT;
|
||||
ship_shape->connect = true;
|
||||
ship_shape->vert_count = NELEMS(ship_verts);
|
||||
memcpy(ship_shape->verts, ship_verts, sizeof(ship_verts));
|
||||
|
||||
shape_t *fire = add_shape(ship_entity_id, &fire_shape_id);
|
||||
fire->visible = true;
|
||||
fire->flags = WRAP | CONNECT;
|
||||
fire->connect = true;
|
||||
fire->vert_count = NELEMS(fire_verts);
|
||||
memcpy(fire->verts, fire_verts, sizeof(fire_verts));
|
||||
|
||||
@@ -440,21 +437,14 @@ void game_update()
|
||||
e->dir = mat2_mul_mat2(mat2_rotation(e->omg), e->dir);
|
||||
e->pos = vec2_add(e->pos, e->vel);
|
||||
|
||||
if (e->wrap) {
|
||||
if (e->pos.y > 1)
|
||||
e->pos.y -= 2;
|
||||
else if (e->pos.y <= -1)
|
||||
e->pos.y += 2;
|
||||
if (e->pos.x >= aspect)
|
||||
e->pos.x -= 2 * aspect;
|
||||
else if (e->pos.x < -aspect)
|
||||
e->pos.x += 2 * aspect;
|
||||
} else if (
|
||||
e->pos.y > 1 || e->pos.y <= -1 || e->pos.x >= aspect
|
||||
|| e->pos.x < -aspect) {
|
||||
remove_entity(i--);
|
||||
continue;
|
||||
}
|
||||
if (e->pos.y > 1)
|
||||
e->pos.y -= 2;
|
||||
else if (e->pos.y <= -1)
|
||||
e->pos.y += 2;
|
||||
if (e->pos.x >= aspect)
|
||||
e->pos.x -= 2 * aspect;
|
||||
else if (e->pos.x < -aspect)
|
||||
e->pos.x += 2 * aspect;
|
||||
|
||||
transforms[i]
|
||||
= mat3_mul_mat3(mat3_translation(e->pos), mat2_extend(e->dir));
|
||||
@@ -476,6 +466,6 @@ void game_draw()
|
||||
const mat3_t transform = transforms[shapes[i].entity];
|
||||
renderer_draw(
|
||||
shapes[i].verts, shapes[i].vert_count, transform,
|
||||
shapes[i].flags);
|
||||
shapes[i].connect);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user