Nimbin[12]?Games / Entropie / entropie/src/world/bigtree.c

Entropie git · main

Entropie festival game; first steps

sdl c game entropie cmake · first commit 2026-10-10 · last commit 2026-11-02 (18 hours ago) · synced 10 hours ago

C 88.5% Markdown 9.1% GLSL 2.3%
git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gz
entropie/src/world/bigtree.c 2.2 KB · 52 lines raw
#include "world/bigtree.h"
#include "world/site.h"

#include <math.h>

Object *BigTree_tree(const World *world) {
    for (int i = 0; i < world->count; i++) {
        Object *o = world->objects[i];
        if (o->type == OBJ_TREE && o->variant == 2 && !o->broken) return o;
    }
    return NULL;
}

static Vec3 base(const World *world) {
    Vec3 t = Site_bigTree();
    t.y = world->has_terrain ? Terrain_height(&world->terrain, t.x, t.z) : 0.0f;
    return t;
}

static Vec3 onGround(const World *world, Vec3 p, float up) {
    p.y = (world->has_terrain ? Terrain_height(&world->terrain, p.x, p.z) : 0.0f) + up;
    return p;
}

Vec3 BigTree_attach(const World *world) {
    Vec3 t = base(world);
    return vec3_add(t, vec3_add(vec3(0.0f, world->bigtree.rope_h, 0.0f), vec3_scale(Site_bigTreeSafe(), 0.45f)));
}

Vec3 BigTree_ropeEnd(const World *world) {
    return onGround(world, vec3_add(base(world), vec3_scale(Site_bigTreeSafe(), BT_ROPE_OUT)), 1.0f);
}

Vec3 BigTree_pullerSpot(const World *world, int k) {
    Vec3 safe = Site_bigTreeSafe(), side = vec3(-safe.z, 0.0f, safe.x);
    return onGround(world, vec3_add(base(world), vec3_add(vec3_scale(safe, BT_ROPE_OUT + 0.4f - BT_PULL_GAP * (float)k),
                                                         vec3_scale(side, (k % 2 ? 0.35f : -0.35f)))), 0.0f);
}

Vec3 BigTree_ropeAt(const World *world, Vec3 near) {
    Vec3 a = BigTree_attach(world), b = BigTree_ropeEnd(world), ab = vec3_sub(b, a);
    float t = clampf(vec3_dot(vec3_sub(near, a), ab) / fmaxf(vec3_dot(ab, ab), 1e-4f), 0.0f, 1.0f);
    return vec3_add(a, vec3_scale(ab, t)); /* (pulled tight: straight) */
}

Vec3 BigTree_notchSpot(const World *world) { return onGround(world, vec3_add(base(world), vec3_scale(Site_bigTreeSafe(), 1.15f)), 0.0f); }
Vec3 BigTree_backSpot(const World *world) { return onGround(world, vec3_sub(base(world), vec3_scale(Site_bigTreeSafe(), 1.15f)), 0.0f); }

Vec3 BigTree_escapeSpot(const World *world, float sign) { /* (back and off to the side: the way out every feller plans) */
    Vec3 safe = Site_bigTreeSafe(), side = vec3(-safe.z, 0.0f, safe.x);
    return onGround(world, vec3_add(base(world), vec3_add(vec3_scale(side, 7.0f * sign), vec3_scale(safe, -1.0f))), 0.0f);
}