#include <SDL.h>
-#include "broadcast.h"
-#include "ebisp/interpreter.h"
#include "game/level/level_editor/point_layer.h"
#include "goals.h"
#include "math/pi.h"
#include "system/str.h"
#define GOAL_RADIUS 10.0f
-#define GOAL_MAX_ID_SIZE 36
static int goals_is_goal_hidden(const Goals *goals, size_t i);
struct Goals {
Lt *lt;
char **ids;
- Point *positions;
+ Vec2f *positions;
Color *colors;
Cue_state *cue_states;
bool *visible;
size_t count;
- Rect player_hitbox;
float angle;
};
RETURN_LT(lt, NULL);
}
for (size_t i = 0; i < goals->count; ++i) {
- goals->ids[i] = PUSH_LT(lt, nth_calloc(1, sizeof(char) * GOAL_MAX_ID_SIZE), free);
+ goals->ids[i] = PUSH_LT(lt, nth_calloc(1, sizeof(char) * ENTITY_MAX_ID_SIZE), free);
if (goals->ids[i] == NULL) {
RETURN_LT(lt, NULL);
}
}
- goals->positions = PUSH_LT(lt, nth_calloc(1, sizeof(Point) * goals->count), free);
+ goals->positions = PUSH_LT(lt, nth_calloc(1, sizeof(Vec2f) * goals->count), free);
if (goals->positions == NULL) {
RETURN_LT(lt, NULL);
}
for (size_t i = 0; i < goals->count; ++i) {
if (sscanf(
line_stream_next(line_stream),
- "%" STRINGIFY(GOAL_MAX_ID_SIZE) "s%f%f%6s",
+ "%" STRINGIFY(ENTITY_MAX_ID_SIZE) "s%f%f%6s",
goals->ids[i],
&goals->positions[i].x,
&goals->positions[i].y,
RETURN_LT(lt, NULL);
}
for (size_t i = 0; i < goals->count; ++i) {
- goals->ids[i] = PUSH_LT(lt, nth_calloc(1, sizeof(char) * GOAL_MAX_ID_SIZE), free);
+ goals->ids[i] = PUSH_LT(lt, nth_calloc(1, sizeof(char) * ENTITY_MAX_ID_SIZE), free);
if (goals->ids[i] == NULL) {
RETURN_LT(lt, NULL);
}
}
- goals->positions = PUSH_LT(lt, nth_calloc(1, sizeof(Point) * goals->count), free);
+ goals->positions = PUSH_LT(lt, nth_calloc(1, sizeof(Vec2f) * goals->count), free);
if (goals->positions == NULL) {
RETURN_LT(lt, NULL);
}
RETURN_LT(lt, NULL);
}
- const Point *positions = point_layer_positions(point_layer);
+ const Vec2f *positions = point_layer_positions(point_layer);
const Color *colors = point_layer_colors(point_layer);
const char *ids = point_layer_ids(point_layer);
static int goals_render_core(const Goals *goals,
size_t goal_index,
- Camera *camera)
+ const Camera *camera)
{
trace_assert(goals);
trace_assert(camera);
- const Point position = vec_sum(
+ const Vec2f position = vec_sum(
goals->positions[goal_index],
vec(0.0f, sinf(goals->angle) * 10.0f));
}
int goals_render(const Goals *goals,
- Camera *camera)
+ const Camera *camera)
{
trace_assert(goals);
trace_assert(camera);
goals->angle = fmodf(goals->angle + 2.0f * delta_time, 2.0f * PI);
}
-void goals_hide_from_player(Goals *goals,
- Rect player_hitbox)
-{
- goals->player_hitbox = player_hitbox;
-
-}
-
int goals_sound(Goals *goals,
Sound_samples *sound_samples)
{
}
}
-static struct EvalResult
-goals_action(Goals *goals, size_t index, Gc *gc, struct Scope *scope, struct Expr path)
-{
- trace_assert(goals);
- trace_assert(gc);
- trace_assert(scope);
-
- const char *target = NULL;
- struct EvalResult res = match_list(gc, "q*", path, &target, NULL);
- if (res.is_error) {
- return res;
- }
-
- if (strcmp(target, "show") == 0) {
- goals->visible[index] = true;
- return eval_success(NIL(gc));
- } else if (strcmp(target, "hide") == 0) {
- goals->visible[index] = false;
- return eval_success(NIL(gc));
- }
+/* Private Functions */
- return unknown_target(gc, goals->ids[index], target);
+static int goals_is_goal_hidden(const Goals *goals, size_t i)
+{
+ return !goals->visible[i];
}
-struct EvalResult
-goals_send(Goals *goals, Gc *gc, struct Scope *scope, struct Expr path)
+void goals_hide(Goals *goals, char goal_id[ENTITY_MAX_ID_SIZE])
{
trace_assert(goals);
- trace_assert(gc);
- trace_assert(scope);
-
- const char *target = NULL;
- struct Expr rest = void_expr();
- struct EvalResult res = match_list(gc, "s*", path, &target, &rest);
- if (res.is_error) {
- return res;
- }
+ trace_assert(goal_id);
for (size_t i = 0; i < goals->count; ++i) {
- if (strcmp(target, goals->ids[i]) == 0) {
- return goals_action(goals, i, gc, scope, rest);
+ if (strncmp(goal_id, goals->ids[i], ENTITY_MAX_ID_SIZE) == 0) {
+ goals->visible[i] = false;
}
}
-
- return unknown_target(gc, "goals", target);
}
-/* Private Functions */
-
-static int goals_is_goal_hidden(const Goals *goals, size_t i)
+void goals_show(Goals *goals, char goal_id[ENTITY_MAX_ID_SIZE])
{
- return !goals->visible[i];
+ trace_assert(goals);
+ trace_assert(goal_id);
+ for (size_t i = 0; i < goals->count; ++i) {
+ if (strncmp(goal_id, goals->ids[i], ENTITY_MAX_ID_SIZE) == 0) {
+ goals->visible[i] = true;
+ }
+ }
}