Compare commits
27 Commits
702dbd4f9a
...
fix/insecu
| Author | SHA1 | Date | |
|---|---|---|---|
| 763893c5d9 | |||
| c44ace5804 | |||
| ec63ce6701 | |||
| 767d821534 | |||
| 59b6728ce8 | |||
| 4e3e17ced4 | |||
| bb23f2e3a1 | |||
| ec4bc9bb82 | |||
| 4a2d199904 | |||
| 58bf89f2f2 | |||
| 4bef8f37b4 | |||
| 096b0eb096 | |||
| 89e0c483ad | |||
| 7d0e134a56 | |||
| 198f639289 | |||
| f71d140af3 | |||
| 651ac7703f | |||
| 587fd210a2 | |||
| 79e9d0e2ad | |||
| 81ebbd9eec | |||
| 90e3d5aec0 | |||
| 68856fb8c5 | |||
| 7605f0ca8c | |||
| 6d64c6426f | |||
| 93ae351959 | |||
|
|
c57ac68a04 | ||
|
|
5793af4896 |
28
.gitea/workflows/ci.yaml
Normal file
28
.gitea/workflows/ci.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
build-essential \
|
||||||
|
libsdl2-dev \
|
||||||
|
libsdl2-image-dev \
|
||||||
|
libsdl2-mixer-dev \
|
||||||
|
pkg-config
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
run: |
|
||||||
|
git config --global http.https://git.kimchi.sslVerify false
|
||||||
|
git clone --depth 1 https://${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASSWORD }}@git.kimchi/tas/major_tom.git .
|
||||||
|
|
||||||
|
- name: Build (native Linux)
|
||||||
|
run: make
|
||||||
56
.gitea/workflows/deploy.yaml
Normal file
56
.gitea/workflows/deploy.yaml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
name: Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.kimchi
|
||||||
|
IMAGE: git.kimchi/tas/major_tom
|
||||||
|
NAMESPACE: jnr-web
|
||||||
|
DEPLOYMENT: jnr-web
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
run: |
|
||||||
|
git config --global http.https://git.kimchi.sslVerify false
|
||||||
|
git clone --depth 1 https://${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASSWORD }}@git.kimchi/tas/major_tom.git .
|
||||||
|
|
||||||
|
- name: Build and push container image
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
IMAGE_TAG="${{ env.IMAGE }}:sha-${GITHUB_SHA::8}"
|
||||||
|
IMAGE_LATEST="${{ env.IMAGE }}:latest"
|
||||||
|
|
||||||
|
buildah bud --tls-verify=false -f Containerfile -t "$IMAGE_TAG" -t "$IMAGE_LATEST" .
|
||||||
|
|
||||||
|
CREDS="${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_PASSWORD }}"
|
||||||
|
|
||||||
|
echo "=== debug: Www-Authenticate header ==="
|
||||||
|
curl -sk -I https://git.kimchi/v2/ | grep -i www-authenticate || true
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== buildah push tag ==="
|
||||||
|
buildah push --tls-verify=false --creds "$CREDS" "$IMAGE_TAG"
|
||||||
|
|
||||||
|
echo "=== buildah push latest ==="
|
||||||
|
buildah push --tls-verify=false --creds "$CREDS" "$IMAGE_LATEST"
|
||||||
|
|
||||||
|
echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Deploy to k3s
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
|
kubectl set image deployment/${{ env.DEPLOYMENT }} \
|
||||||
|
${{ env.DEPLOYMENT }}="${{ env.IMAGE_TAG }}" \
|
||||||
|
-n ${{ env.NAMESPACE }}
|
||||||
|
|
||||||
|
kubectl rollout status deployment/${{ env.DEPLOYMENT }} \
|
||||||
|
-n ${{ env.NAMESPACE }} --timeout=60s
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
# JNR Web — static file server for the Emscripten build
|
# JNR Web — multi-stage build: compile WASM then serve static files
|
||||||
#
|
|
||||||
# Prerequisites:
|
|
||||||
# make web (produces dist-web/)
|
|
||||||
#
|
#
|
||||||
# Build:
|
# Build:
|
||||||
# podman build -t jnr-web .
|
# podman build -t jnr-web .
|
||||||
@@ -15,9 +12,21 @@
|
|||||||
# podman save jnr-web | sudo k3s ctr images import -
|
# podman save jnr-web | sudo k3s ctr images import -
|
||||||
# sudo k3s kubectl apply -f k8s/
|
# sudo k3s kubectl apply -f k8s/
|
||||||
|
|
||||||
|
# ── Stage 1: Build WASM artifacts ──
|
||||||
|
FROM docker.io/emscripten/emsdk:3.1.51 AS builder
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY Makefile ./
|
||||||
|
COPY include/ include/
|
||||||
|
COPY src/ src/
|
||||||
|
COPY assets/ assets/
|
||||||
|
COPY web/ web/
|
||||||
|
RUN make web
|
||||||
|
|
||||||
|
# ── Stage 2: Serve static files ──
|
||||||
FROM docker.io/joseluisq/static-web-server:2
|
FROM docker.io/joseluisq/static-web-server:2
|
||||||
|
|
||||||
COPY dist-web/ /public/
|
COPY --from=builder /src/dist-web/ /public/
|
||||||
|
|
||||||
# Disable the default cache-control headers which cache .js for 1 year.
|
# Disable the default cache-control headers which cache .js for 1 year.
|
||||||
# The .js and .wasm files must always be fetched together (EM_ASM address
|
# The .js and .wasm files must always be fetched together (EM_ASM address
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ adding a new def. See `src/game/projectile.h` for the full definition.
|
|||||||
## Levels
|
## Levels
|
||||||
|
|
||||||
### Format (.lvl)
|
### Format (.lvl)
|
||||||
Current directives: `TILESET`, `SIZE`, `SPAWN`, `GRAVITY`, `WIND`, `BG_COLOR`, `MUSIC`, `PARALLAX_FAR`, `PARALLAX_NEAR`, `TILEDEF`, `ENTITY`, `EXIT`, `LAYER`
|
Current directives: `TILESET`, `SIZE`, `SPAWN`, `GRAVITY`, `WIND`, `BG_COLOR`, `MUSIC`, `PARALLAX_FAR`, `PARALLAX_NEAR`, `TRANSITION_IN`, `TRANSITION_OUT`, `TILEDEF`, `ENTITY`, `EXIT`, `LAYER`
|
||||||
|
|
||||||
**Needed additions:**
|
**Needed additions:**
|
||||||
- `STORM`, `DRAG` — Remaining atmosphere settings
|
- `STORM`, `DRAG` — Remaining atmosphere settings
|
||||||
|
|||||||
30
TODO.md
30
TODO.md
@@ -160,11 +160,25 @@ The spacecraft fly-in animation should only play on surface levels (moon01,
|
|||||||
mars01, etc.). Interior/base levels (mars02, mars03, generated mars_base,
|
mars01, etc.). Interior/base levels (mars02, mars03, generated mars_base,
|
||||||
generated station) should skip it — the player is already indoors.
|
generated station) should skip it — the player is already indoors.
|
||||||
|
|
||||||
## New level transition styles: elevator and teleporter
|
## ~~New level transition styles: elevator and teleporter~~ ✓
|
||||||
Two new transition animations to complement the spacecraft fly-in:
|
Implemented: `src/game/transition.h` / `transition.c` module with two-phase
|
||||||
- **Elevator** — Doors slide shut, brief pause (screen shake / rumble),
|
transition state machine (outro on old level → level swap → intro on new level).
|
||||||
doors slide open onto the new level. Good for base/station interior
|
|
||||||
transitions (mars02 → mars_base, between generated station levels).
|
- **Elevator** — Two horizontal doors slide inward from top/bottom (0.6 s),
|
||||||
- **Teleporter** — Energy charge-up effect around the player, flash/warp
|
hold closed with screen-shake rumble (0.3 s), then slide apart on the new
|
||||||
distortion, player materialises in the new level. Good for cross-planet
|
level (0.6 s). Smooth ease-in-out motion, dark gray industrial color,
|
||||||
jumps or generated-to-handcrafted transitions.
|
bright seam at the meeting edge. Used for base/station interior transitions.
|
||||||
|
- **Teleporter** — Scanline dissolve: 3 px-tall horizontal bands sweep
|
||||||
|
across the screen in alternating directions with staggered top-to-bottom
|
||||||
|
timing (0.5 s), then white flash (0.15 s). Intro reverses the sweep
|
||||||
|
bottom-to-top (0.5 s). Uses `teleport.wav` sound effect.
|
||||||
|
|
||||||
|
New `MODE_TRANSITION` game state in `main.c` pauses gameplay during the
|
||||||
|
animation. Level-load dispatch extracted into `dispatch_level_load()` helper,
|
||||||
|
called both from instant transitions and from the transition state machine.
|
||||||
|
|
||||||
|
New `.lvl` directives `TRANSITION_IN` and `TRANSITION_OUT` with values
|
||||||
|
`none`, `spacecraft`, `elevator`, `teleporter`. Parsed in `tilemap.c`,
|
||||||
|
saved by editor and level generator dump. All three procedural generators
|
||||||
|
(generic, station, mars_base) set `TRANS_ELEVATOR` for interior themes.
|
||||||
|
Handcrafted levels updated: mars02, mars03, level01, level02.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ SPAWN 3 18
|
|||||||
GRAVITY 400
|
GRAVITY 400
|
||||||
BG_COLOR 15 15 30
|
BG_COLOR 15 15 30
|
||||||
MUSIC assets/sounds/algardalgar.ogg
|
MUSIC assets/sounds/algardalgar.ogg
|
||||||
|
TRANSITION_OUT elevator
|
||||||
|
|
||||||
# Spacecraft landing intro (arriving from moon)
|
# Spacecraft landing intro (arriving from moon)
|
||||||
ENTITY spacecraft 1 14
|
ENTITY spacecraft 1 14
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ SPAWN 3 18
|
|||||||
GRAVITY 600
|
GRAVITY 600
|
||||||
BG_COLOR 10 10 25
|
BG_COLOR 10 10 25
|
||||||
MUSIC assets/sounds/algardalgar.ogg
|
MUSIC assets/sounds/algardalgar.ogg
|
||||||
|
TRANSITION_IN elevator
|
||||||
|
TRANSITION_OUT elevator
|
||||||
|
|
||||||
# Enemies
|
# Enemies
|
||||||
ENTITY grunt 12 18
|
ENTITY grunt 12 18
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ SIZE 40 46
|
|||||||
SPAWN 3 7
|
SPAWN 3 7
|
||||||
GRAVITY 700
|
GRAVITY 700
|
||||||
BG_COLOR 20 10 6
|
BG_COLOR 20 10 6
|
||||||
PARALLAX_STYLE 5
|
PARALLAX_STYLE 2
|
||||||
MUSIC assets/sounds/kaffe_og_kage.ogg
|
MUSIC assets/sounds/kaffe_og_kage.ogg
|
||||||
|
TRANSITION_OUT elevator
|
||||||
|
|
||||||
ENTITY spacecraft 1 3
|
ENTITY spacecraft 1 3
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ GRAVITY 700
|
|||||||
BG_COLOR 15 8 5
|
BG_COLOR 15 8 5
|
||||||
PARALLAX_STYLE 3
|
PARALLAX_STYLE 3
|
||||||
MUSIC assets/sounds/kaffe_og_kage.ogg
|
MUSIC assets/sounds/kaffe_og_kage.ogg
|
||||||
|
TRANSITION_IN elevator
|
||||||
|
TRANSITION_OUT elevator
|
||||||
|
|
||||||
# Gun pickup right at spawn — the player needs it
|
# Gun pickup right at spawn — the player needs it
|
||||||
ENTITY powerup_gun 5 18
|
ENTITY powerup_gun 5 18
|
||||||
|
|||||||
@@ -28,6 +28,14 @@
|
|||||||
/* ── Level transitions ─────────────────────────────── */
|
/* ── Level transitions ─────────────────────────────── */
|
||||||
#define MAX_EXIT_ZONES 16 /* max exit zones per level */
|
#define MAX_EXIT_ZONES 16 /* max exit zones per level */
|
||||||
|
|
||||||
|
typedef enum TransitionStyle {
|
||||||
|
TRANS_NONE, /* instant cut (default) */
|
||||||
|
TRANS_SPACECRAFT, /* handled by spacecraft entity */
|
||||||
|
TRANS_ELEVATOR, /* doors close, rumble, doors open */
|
||||||
|
TRANS_TELEPORTER, /* scanline dissolve, flash, materialize */
|
||||||
|
TRANS_STYLE_COUNT
|
||||||
|
} TransitionStyle;
|
||||||
|
|
||||||
/* ── Rendering ──────────────────────────────────────── */
|
/* ── Rendering ──────────────────────────────────────── */
|
||||||
#define MAX_SPRITES 2048 /* max queued sprites per frame */
|
#define MAX_SPRITES 2048 /* max queued sprites per frame */
|
||||||
|
|
||||||
|
|||||||
@@ -556,38 +556,69 @@ void particle_emit_atmosphere_dust(Vec2 cam_pos, Vec2 vp) {
|
|||||||
* Two sub-layers for depth: large slow "far" motes and small quick
|
* Two sub-layers for depth: large slow "far" motes and small quick
|
||||||
* "near" specks. Wind carries them; gravity_scale controls how much
|
* "near" specks. Wind carries them; gravity_scale controls how much
|
||||||
* environmental forces (wind + gravity) affect each particle.
|
* environmental forces (wind + gravity) affect each particle.
|
||||||
* Particles spawn along the upwind viewport edge and drift inward;
|
* When wind is strong, particles spawn along the upwind viewport edge
|
||||||
* occasional interior spawns prevent a visible edge seam. */
|
* and drift inward. When wind is calm, particles spawn across the
|
||||||
float wind = physics_get_wind();
|
* full viewport to avoid clustering on one side. */
|
||||||
float margin = 32.0f;
|
float wind = physics_get_wind();
|
||||||
float dir = (wind >= 0.0f) ? 1.0f : -1.0f; /* velocity sign */
|
float margin = 32.0f;
|
||||||
|
float abs_wind = (wind >= 0.0f) ? wind : -wind;
|
||||||
|
int has_wind = abs_wind > 5.0f; /* threshold for edge-spawning */
|
||||||
|
|
||||||
/* Upwind edge X for the two edge-spawned layers */
|
if (has_wind) {
|
||||||
float edge_far = (wind >= 0.0f) ? cam_pos.x - margin
|
float dir = (wind >= 0.0f) ? 1.0f : -1.0f;
|
||||||
: cam_pos.x + vp.x + margin;
|
|
||||||
float edge_near = (wind >= 0.0f) ? cam_pos.x - margin * 0.5f
|
|
||||||
: cam_pos.x + vp.x + margin * 0.5f;
|
|
||||||
|
|
||||||
/* Far dust motes — large, slow, translucent (1/frame) */
|
/* Upwind edge X for the two edge-spawned layers */
|
||||||
spawn_dust_mote(
|
float edge_far = (wind >= 0.0f) ? cam_pos.x - margin
|
||||||
vec2(edge_far, cam_pos.y + randf() * vp.y),
|
: cam_pos.x + vp.x + margin;
|
||||||
vec2(dir * randf_range(8.0f, 25.0f), randf_range(-6.0f, 6.0f)),
|
float edge_near = (wind >= 0.0f) ? cam_pos.x - margin * 0.5f
|
||||||
4.0f, 7.0f, 1.5f, 3.0f, 0.3f, 0.08f,
|
: cam_pos.x + vp.x + margin * 0.5f;
|
||||||
180, 140, 100, 25);
|
|
||||||
|
|
||||||
/* Near dust specks — small, quicker, brighter (1/frame) */
|
/* Far dust motes — large, slow, translucent (1/frame) */
|
||||||
spawn_dust_mote(
|
spawn_dust_mote(
|
||||||
vec2(edge_near, cam_pos.y + randf() * vp.y),
|
vec2(edge_far, cam_pos.y + randf() * vp.y),
|
||||||
vec2(dir * randf_range(15.0f, 40.0f), randf_range(-10.0f, 10.0f)),
|
vec2(dir * randf_range(8.0f, 25.0f), randf_range(-6.0f, 6.0f)),
|
||||||
2.5f, 5.0f, 0.8f, 1.5f, 0.2f, 0.12f,
|
4.0f, 7.0f, 1.5f, 3.0f, 0.3f, 0.08f,
|
||||||
200, 160, 120, 20);
|
180, 140, 100, 25);
|
||||||
|
|
||||||
/* Occasional interior spawn — prevents edge seam on calm wind */
|
/* Near dust specks — small, quicker, brighter (1/frame) */
|
||||||
if (rand() % 3 == 0) {
|
spawn_dust_mote(
|
||||||
|
vec2(edge_near, cam_pos.y + randf() * vp.y),
|
||||||
|
vec2(dir * randf_range(15.0f, 40.0f), randf_range(-10.0f, 10.0f)),
|
||||||
|
2.5f, 5.0f, 0.8f, 1.5f, 0.2f, 0.12f,
|
||||||
|
200, 160, 120, 20);
|
||||||
|
|
||||||
|
/* Occasional interior spawn — prevents edge seam */
|
||||||
|
if (rand() % 3 == 0) {
|
||||||
|
spawn_dust_mote(
|
||||||
|
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
||||||
|
vec2(randf_range(-5.0f, 5.0f), randf_range(-8.0f, 3.0f)),
|
||||||
|
3.0f, 6.0f, 1.0f, 2.5f, 0.4f, 0.06f,
|
||||||
|
160, 130, 95, 25);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Calm wind — spawn across the full viewport to distribute evenly */
|
||||||
|
|
||||||
|
/* Far dust motes — large, slow, translucent (1/frame) */
|
||||||
spawn_dust_mote(
|
spawn_dust_mote(
|
||||||
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
||||||
vec2(randf_range(-5.0f, 5.0f), randf_range(-8.0f, 3.0f)),
|
vec2(randf_range(-10.0f, 10.0f), randf_range(-6.0f, 6.0f)),
|
||||||
3.0f, 6.0f, 1.0f, 2.5f, 0.4f, 0.06f,
|
4.0f, 7.0f, 1.5f, 3.0f, 0.3f, 0.08f,
|
||||||
160, 130, 95, 25);
|
180, 140, 100, 25);
|
||||||
|
|
||||||
|
/* Near dust specks — small, quicker, brighter (1/frame) */
|
||||||
|
spawn_dust_mote(
|
||||||
|
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
||||||
|
vec2(randf_range(-15.0f, 15.0f), randf_range(-10.0f, 10.0f)),
|
||||||
|
2.5f, 5.0f, 0.8f, 1.5f, 0.2f, 0.12f,
|
||||||
|
200, 160, 120, 20);
|
||||||
|
|
||||||
|
/* Extra interior mote for density parity with windy path */
|
||||||
|
if (rand() % 3 == 0) {
|
||||||
|
spawn_dust_mote(
|
||||||
|
vec2(cam_pos.x + randf() * vp.x, cam_pos.y + randf() * vp.y),
|
||||||
|
vec2(randf_range(-5.0f, 5.0f), randf_range(-8.0f, 3.0f)),
|
||||||
|
3.0f, 6.0f, 1.0f, 2.5f, 0.4f, 0.06f,
|
||||||
|
160, 130, 95, 25);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* ── Transition style name → enum mapping ── */
|
||||||
|
static TransitionStyle parse_transition_style(const char *name) {
|
||||||
|
if (strcmp(name, "spacecraft") == 0) return TRANS_SPACECRAFT;
|
||||||
|
if (strcmp(name, "elevator") == 0) return TRANS_ELEVATOR;
|
||||||
|
if (strcmp(name, "teleporter") == 0) return TRANS_TELEPORTER;
|
||||||
|
return TRANS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read a full line from f into a dynamically growing buffer.
|
/* Read a full line from f into a dynamically growing buffer.
|
||||||
* *buf and *cap track the heap buffer; the caller must free *buf.
|
* *buf and *cap track the heap buffer; the caller must free *buf.
|
||||||
* Returns the line length, or -1 on EOF/error. */
|
* Returns the line length, or -1 on EOF/error. */
|
||||||
@@ -120,6 +128,16 @@ bool tilemap_load(Tilemap *map, const char *path, SDL_Renderer *renderer) {
|
|||||||
}
|
}
|
||||||
} else if (strncmp(line, "PLAYER_UNARMED", 14) == 0) {
|
} else if (strncmp(line, "PLAYER_UNARMED", 14) == 0) {
|
||||||
map->player_unarmed = true;
|
map->player_unarmed = true;
|
||||||
|
} else if (strncmp(line, "TRANSITION_IN ", 14) == 0) {
|
||||||
|
char tname[32] = {0};
|
||||||
|
if (sscanf(line + 14, "%31s", tname) == 1) {
|
||||||
|
map->transition_in = parse_transition_style(tname);
|
||||||
|
}
|
||||||
|
} else if (strncmp(line, "TRANSITION_OUT ", 15) == 0) {
|
||||||
|
char tname[32] = {0};
|
||||||
|
if (sscanf(line + 15, "%31s", tname) == 1) {
|
||||||
|
map->transition_out = parse_transition_style(tname);
|
||||||
|
}
|
||||||
} else if (strncmp(line, "EXIT ", 5) == 0) {
|
} else if (strncmp(line, "EXIT ", 5) == 0) {
|
||||||
if (map->exit_zone_count < MAX_EXIT_ZONES) {
|
if (map->exit_zone_count < MAX_EXIT_ZONES) {
|
||||||
ExitZone *ez = &map->exit_zones[map->exit_zone_count];
|
ExitZone *ez = &map->exit_zones[map->exit_zone_count];
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ typedef struct Tilemap {
|
|||||||
char parallax_near_path[ASSET_PATH_MAX]; /* near bg image path */
|
char parallax_near_path[ASSET_PATH_MAX]; /* near bg image path */
|
||||||
int parallax_style; /* procedural bg style (0=default) */
|
int parallax_style; /* procedural bg style (0=default) */
|
||||||
bool player_unarmed; /* if true, player starts without gun */
|
bool player_unarmed; /* if true, player starts without gun */
|
||||||
|
TransitionStyle transition_in; /* transition animation for level entry */
|
||||||
|
TransitionStyle transition_out; /* transition animation for level exit */
|
||||||
EntitySpawn entity_spawns[MAX_ENTITY_SPAWNS];
|
EntitySpawn entity_spawns[MAX_ENTITY_SPAWNS];
|
||||||
int entity_spawn_count;
|
int entity_spawn_count;
|
||||||
ExitZone exit_zones[MAX_EXIT_ZONES];
|
ExitZone exit_zones[MAX_EXIT_ZONES];
|
||||||
|
|||||||
@@ -9,9 +9,20 @@
|
|||||||
/* Initialize client_id in localStorage and store the analytics
|
/* Initialize client_id in localStorage and store the analytics
|
||||||
* API URL + key. Called once at startup. */
|
* API URL + key. Called once at startup. */
|
||||||
EM_JS(void, js_analytics_init, (), {
|
EM_JS(void, js_analytics_init, (), {
|
||||||
/* Generate or retrieve a persistent client UUID */
|
/* Generate or retrieve a persistent client UUID.
|
||||||
|
* crypto.randomUUID() requires a secure context (HTTPS) and is
|
||||||
|
* absent in older browsers, so fall back to a manual v4 UUID. */
|
||||||
if (!localStorage.getItem('jnr_client_id')) {
|
if (!localStorage.getItem('jnr_client_id')) {
|
||||||
localStorage.setItem('jnr_client_id', crypto.randomUUID());
|
var uuid;
|
||||||
|
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||||
|
uuid = crypto.randomUUID();
|
||||||
|
} else {
|
||||||
|
uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||||
|
var r = Math.random() * 16 | 0;
|
||||||
|
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
localStorage.setItem('jnr_client_id', uuid);
|
||||||
}
|
}
|
||||||
/* Store config on the Module for later use by other EM_JS calls.
|
/* Store config on the Module for later use by other EM_JS calls.
|
||||||
* ANALYTICS_URL and ANALYTICS_KEY are replaced at build time via
|
* ANALYTICS_URL and ANALYTICS_KEY are replaced at build time via
|
||||||
@@ -21,15 +32,20 @@ EM_JS(void, js_analytics_init, (), {
|
|||||||
Module._analyticsStartPending = null; /* Promise while start is in-flight */
|
Module._analyticsStartPending = null; /* Promise while start is in-flight */
|
||||||
Module._analyticsLastStats = null; /* stashed for beforeunload fallback */
|
Module._analyticsLastStats = null; /* stashed for beforeunload fallback */
|
||||||
|
|
||||||
/* Runtime config: check for data attributes on the canvas container
|
/* Runtime config: URL from data attribute, key decoded at runtime.
|
||||||
* first, then fall back to compiled-in defaults. */
|
* The key is XOR-encoded across two byte arrays so it never appears
|
||||||
|
* as a plain string in the WASM binary, emitted JS, or HTML. */
|
||||||
var container = document.getElementById('canvas-container');
|
var container = document.getElementById('canvas-container');
|
||||||
Module._analyticsUrl = (container && container.dataset.analyticsUrl)
|
Module._analyticsUrl = (container && container.dataset.analyticsUrl)
|
||||||
? container.dataset.analyticsUrl
|
? container.dataset.analyticsUrl
|
||||||
: (typeof ANALYTICS_URL !== 'undefined' ? ANALYTICS_URL : '');
|
: (typeof ANALYTICS_URL !== 'undefined' ? ANALYTICS_URL : '');
|
||||||
Module._analyticsKey = (container && container.dataset.analyticsKey)
|
var _a = [53,75,96,19,114,122,112,34,28,62,24,5,57,34,126,14,
|
||||||
? container.dataset.analyticsKey
|
112,73,105,121,122,79,50,0,77,33,82,58,61,19,44,0];
|
||||||
: (typeof ANALYTICS_KEY !== 'undefined' ? ANALYTICS_KEY : '');
|
var _b = [82,15,4,95,36,32,29,18,95,14,87,95,115,70,12,76,
|
||||||
|
55,5,4,12,28,30,65,78,4,72,26,92,84,90,70,54];
|
||||||
|
var _k = '';
|
||||||
|
for (var i = 0; i < _a.length; i++) _k += String.fromCharCode(_a[i] ^ _b[i]);
|
||||||
|
Module._analyticsKey = _k;
|
||||||
|
|
||||||
if (!Module._analyticsUrl) {
|
if (!Module._analyticsUrl) {
|
||||||
console.log('[analytics] No analytics URL configured — analytics disabled');
|
console.log('[analytics] No analytics URL configured — analytics disabled');
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "game/editor.h"
|
#include "game/editor.h"
|
||||||
#include "game/entity_registry.h"
|
#include "game/entity_registry.h"
|
||||||
|
#include "game/transition.h"
|
||||||
#include "engine/core.h"
|
#include "engine/core.h"
|
||||||
#include "engine/input.h"
|
#include "engine/input.h"
|
||||||
#include "engine/renderer.h"
|
#include "engine/renderer.h"
|
||||||
@@ -359,6 +360,16 @@ static bool save_tilemap(const Tilemap *map, const char *path) {
|
|||||||
if (map->player_unarmed)
|
if (map->player_unarmed)
|
||||||
fprintf(f, "PLAYER_UNARMED\n");
|
fprintf(f, "PLAYER_UNARMED\n");
|
||||||
|
|
||||||
|
/* Transition styles */
|
||||||
|
if (map->transition_in != TRANS_NONE) {
|
||||||
|
fprintf(f, "TRANSITION_IN %s\n",
|
||||||
|
transition_style_name(map->transition_in));
|
||||||
|
}
|
||||||
|
if (map->transition_out != TRANS_NONE) {
|
||||||
|
fprintf(f, "TRANSITION_OUT %s\n",
|
||||||
|
transition_style_name(map->transition_out));
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
|
|
||||||
/* Entity spawns */
|
/* Entity spawns */
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "engine/input.h"
|
#include "engine/input.h"
|
||||||
#include "engine/camera.h"
|
#include "engine/camera.h"
|
||||||
#include "engine/assets.h"
|
#include "engine/assets.h"
|
||||||
|
#include "engine/font.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -779,6 +780,20 @@ void level_render(Level *level, float interpolation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw score in top-right corner */
|
||||||
|
{
|
||||||
|
GameStats *stats = stats_get_active();
|
||||||
|
if (stats) {
|
||||||
|
stats_update_score(stats);
|
||||||
|
char score_buf[16];
|
||||||
|
snprintf(score_buf, sizeof(score_buf), "%d", stats->score);
|
||||||
|
int text_w = font_text_width(score_buf);
|
||||||
|
font_draw_text(g_engine.renderer, score_buf,
|
||||||
|
SCREEN_WIDTH - text_w - 8, 8,
|
||||||
|
(SDL_Color){255, 220, 80, 255});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Flush the renderer */
|
/* Flush the renderer */
|
||||||
renderer_flush(cam);
|
renderer_flush(cam);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "game/levelgen.h"
|
#include "game/levelgen.h"
|
||||||
|
#include "game/transition.h"
|
||||||
#include "engine/parallax.h"
|
#include "engine/parallax.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -1317,6 +1318,14 @@ bool levelgen_generate(Tilemap *map, const LevelGenConfig *config) {
|
|||||||
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/algardalgar.ogg");
|
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/algardalgar.ogg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Transition style — interior themes use elevator, surface uses none
|
||||||
|
* (spacecraft entity handles surface transitions). */
|
||||||
|
if (primary_theme == THEME_PLANET_BASE || primary_theme == THEME_MARS_BASE
|
||||||
|
|| primary_theme == THEME_SPACE_STATION) {
|
||||||
|
map->transition_in = TRANS_ELEVATOR;
|
||||||
|
map->transition_out = TRANS_ELEVATOR;
|
||||||
|
}
|
||||||
|
|
||||||
/* Tileset */
|
/* Tileset */
|
||||||
/* NOTE: tileset texture will be loaded by level_load_generated */
|
/* NOTE: tileset texture will be loaded by level_load_generated */
|
||||||
|
|
||||||
@@ -1826,6 +1835,10 @@ bool levelgen_generate_station(Tilemap *map, const LevelGenConfig *config) {
|
|||||||
/* Music */
|
/* Music */
|
||||||
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/algardalgar.ogg");
|
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/algardalgar.ogg");
|
||||||
|
|
||||||
|
/* Interior levels use elevator transitions. */
|
||||||
|
map->transition_in = TRANS_ELEVATOR;
|
||||||
|
map->transition_out = TRANS_ELEVATOR;
|
||||||
|
|
||||||
printf("levelgen_station: generated %dx%d level (%d segments, seed=%u, gravity=%.0f)\n",
|
printf("levelgen_station: generated %dx%d level (%d segments, seed=%u, gravity=%.0f)\n",
|
||||||
map->width, map->height, num_segs, s_rng_state, map->gravity);
|
map->width, map->height, num_segs, s_rng_state, map->gravity);
|
||||||
printf(" segments:");
|
printf(" segments:");
|
||||||
@@ -2485,6 +2498,10 @@ bool levelgen_generate_mars_base(Tilemap *map, const LevelGenConfig *config) {
|
|||||||
/* Music */
|
/* Music */
|
||||||
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/kaffe_og_kage.ogg");
|
snprintf(map->music_path, sizeof(map->music_path), "assets/sounds/kaffe_og_kage.ogg");
|
||||||
|
|
||||||
|
/* Interior levels use elevator transitions. */
|
||||||
|
map->transition_in = TRANS_ELEVATOR;
|
||||||
|
map->transition_out = TRANS_ELEVATOR;
|
||||||
|
|
||||||
printf("levelgen_mars_base: generated %dx%d level (%d segments, seed=%u)\n",
|
printf("levelgen_mars_base: generated %dx%d level (%d segments, seed=%u)\n",
|
||||||
map->width, map->height, num_segs, s_rng_state);
|
map->width, map->height, num_segs, s_rng_state);
|
||||||
printf(" segments:");
|
printf(" segments:");
|
||||||
@@ -2541,6 +2558,16 @@ bool levelgen_dump_lvl(const Tilemap *map, const char *path) {
|
|||||||
fprintf(f, "PLAYER_UNARMED\n");
|
fprintf(f, "PLAYER_UNARMED\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Transition styles */
|
||||||
|
if (map->transition_in != TRANS_NONE) {
|
||||||
|
fprintf(f, "TRANSITION_IN %s\n",
|
||||||
|
transition_style_name(map->transition_in));
|
||||||
|
}
|
||||||
|
if (map->transition_out != TRANS_NONE) {
|
||||||
|
fprintf(f, "TRANSITION_OUT %s\n",
|
||||||
|
transition_style_name(map->transition_out));
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
|
|
||||||
/* Entity spawns */
|
/* Entity spawns */
|
||||||
|
|||||||
@@ -300,6 +300,33 @@ void player_update(Entity *self, float dt, const Tilemap *map) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Double-tap down for free downward jetpack ── */
|
||||||
|
if (!body->on_ground && input_pressed(ACTION_DOWN)) {
|
||||||
|
if (pd->down_tap_timer > 0) {
|
||||||
|
/* Second tap — trigger free downward dash */
|
||||||
|
pd->down_tap_timer = 0;
|
||||||
|
pd->dash_timer = PLAYER_DASH_DURATION;
|
||||||
|
pd->dash_dir = vec2(0.0f, 1.0f);
|
||||||
|
|
||||||
|
/* Brief invincibility during dash */
|
||||||
|
pd->inv_timer = PLAYER_DASH_DURATION;
|
||||||
|
self->flags |= ENTITY_INVINCIBLE;
|
||||||
|
|
||||||
|
/* Jetpack burst downward */
|
||||||
|
Vec2 exhaust_pos = vec2(
|
||||||
|
body->pos.x + body->size.x * 0.5f,
|
||||||
|
body->pos.y + body->size.y * 0.5f
|
||||||
|
);
|
||||||
|
particle_emit_jetpack_burst(exhaust_pos, pd->dash_dir);
|
||||||
|
audio_play_sound(s_sfx_dash, 96);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pd->down_tap_timer = 0.3f; /* window for second tap */
|
||||||
|
}
|
||||||
|
if (pd->down_tap_timer > 0) {
|
||||||
|
pd->down_tap_timer -= dt;
|
||||||
|
}
|
||||||
|
|
||||||
if (input_pressed(ACTION_DASH) && pd->dash_charges > 0) {
|
if (input_pressed(ACTION_DASH) && pd->dash_charges > 0) {
|
||||||
pd->dash_charges--;
|
pd->dash_charges--;
|
||||||
stats_record_dash();
|
stats_record_dash();
|
||||||
@@ -478,6 +505,7 @@ void player_update(Entity *self, float dt, const Tilemap *map) {
|
|||||||
|
|
||||||
/* ── Landing detection ───────────────────── */
|
/* ── Landing detection ───────────────────── */
|
||||||
if (body->on_ground && !pd->was_on_ground) {
|
if (body->on_ground && !pd->was_on_ground) {
|
||||||
|
pd->down_tap_timer = 0; /* reset double-tap on landing */
|
||||||
/* Just landed — emit dust at feet */
|
/* Just landed — emit dust at feet */
|
||||||
Vec2 feet = vec2(
|
Vec2 feet = vec2(
|
||||||
body->pos.x + body->size.x * 0.5f,
|
body->pos.x + body->size.x * 0.5f,
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ typedef struct PlayerData {
|
|||||||
AimDir aim_dir; /* current aim direction */
|
AimDir aim_dir; /* current aim direction */
|
||||||
bool looking_up; /* holding up without moving */
|
bool looking_up; /* holding up without moving */
|
||||||
float look_up_timer; /* how long up has been held */
|
float look_up_timer; /* how long up has been held */
|
||||||
|
/* Down-arrow double-tap (free downward jetpack) */
|
||||||
|
float down_tap_timer; /* time since last mid-air down press */
|
||||||
/* Death / Respawn */
|
/* Death / Respawn */
|
||||||
float respawn_timer; /* countdown after death anim finishes */
|
float respawn_timer; /* countdown after death anim finishes */
|
||||||
Vec2 spawn_point; /* where to respawn */
|
Vec2 spawn_point; /* where to respawn */
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ void stats_reset(GameStats *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stats_update_score(GameStats *s) {
|
void stats_update_score(GameStats *s) {
|
||||||
int score = s->levels_completed * 100
|
int score = s->enemies_killed * 100
|
||||||
+ s->enemies_killed * 10
|
+ s->levels_completed * 500
|
||||||
- s->deaths * 25
|
- s->deaths * 200
|
||||||
+ s->pickups_collected * 5;
|
- (int)s->time_elapsed;
|
||||||
s->score = score > 0 ? score : 0;
|
s->score = score > 0 ? score : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
351
src/game/transition.c
Normal file
351
src/game/transition.c
Normal file
@@ -0,0 +1,351 @@
|
|||||||
|
#include "game/transition.h"
|
||||||
|
#include "engine/core.h"
|
||||||
|
#include "engine/audio.h"
|
||||||
|
#include "engine/particle.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Constants
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
/* ── Elevator timing ── */
|
||||||
|
#define ELEVATOR_CLOSE_DURATION 0.6f /* doors slide shut */
|
||||||
|
#define ELEVATOR_HOLD_DURATION 0.3f /* closed with rumble */
|
||||||
|
#define ELEVATOR_OPEN_DURATION 0.6f /* doors slide open */
|
||||||
|
|
||||||
|
#define ELEVATOR_OUT_DURATION (ELEVATOR_CLOSE_DURATION + ELEVATOR_HOLD_DURATION)
|
||||||
|
#define ELEVATOR_IN_DURATION (ELEVATOR_HOLD_DURATION + ELEVATOR_OPEN_DURATION)
|
||||||
|
|
||||||
|
/* ── Teleporter timing ── */
|
||||||
|
#define TELEPORT_DISSOLVE_DURATION 0.5f /* scanline sweep out */
|
||||||
|
#define TELEPORT_FLASH_DURATION 0.15f /* white flash */
|
||||||
|
#define TELEPORT_MATERIALIZE_DURATION 0.5f /* scanline sweep in */
|
||||||
|
|
||||||
|
#define TELEPORT_OUT_DURATION (TELEPORT_DISSOLVE_DURATION + TELEPORT_FLASH_DURATION)
|
||||||
|
#define TELEPORT_IN_DURATION (TELEPORT_FLASH_DURATION + TELEPORT_MATERIALIZE_DURATION)
|
||||||
|
|
||||||
|
/* ── Scanline dissolve parameters ── */
|
||||||
|
#define SCANLINE_HEIGHT 3 /* pixel height per band */
|
||||||
|
#define SCANLINE_STAGGER 0.3f /* time spread between first/last band */
|
||||||
|
|
||||||
|
/* ── Elevator colors ── */
|
||||||
|
#define ELEV_R 40
|
||||||
|
#define ELEV_G 42
|
||||||
|
#define ELEV_B 48
|
||||||
|
|
||||||
|
/* ── Sound effects ── */
|
||||||
|
static Sound s_sfx_teleport;
|
||||||
|
static bool s_sfx_loaded = false;
|
||||||
|
|
||||||
|
static void ensure_sfx(void) {
|
||||||
|
if (s_sfx_loaded) return;
|
||||||
|
s_sfx_teleport = audio_load_sound("assets/sounds/teleport.wav");
|
||||||
|
s_sfx_loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Outro duration for a given style
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
static float outro_duration(TransitionStyle style) {
|
||||||
|
switch (style) {
|
||||||
|
case TRANS_ELEVATOR: return ELEVATOR_OUT_DURATION;
|
||||||
|
case TRANS_TELEPORTER: return TELEPORT_OUT_DURATION;
|
||||||
|
default: return 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static float intro_duration(TransitionStyle style) {
|
||||||
|
switch (style) {
|
||||||
|
case TRANS_ELEVATOR: return ELEVATOR_IN_DURATION;
|
||||||
|
case TRANS_TELEPORTER: return TELEPORT_IN_DURATION;
|
||||||
|
default: return 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Public API
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
void transition_start_out(TransitionState *ts, TransitionStyle out_style) {
|
||||||
|
ensure_sfx();
|
||||||
|
ts->out_style = out_style;
|
||||||
|
ts->in_style = TRANS_NONE;
|
||||||
|
ts->phase = TRANS_PHASE_OUT;
|
||||||
|
ts->timer = 0.0f;
|
||||||
|
ts->phase_dur = outro_duration(out_style);
|
||||||
|
ts->sound_played = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void transition_set_in_style(TransitionState *ts, TransitionStyle in_style) {
|
||||||
|
ts->in_style = in_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
void transition_update(TransitionState *ts, float dt, Camera *cam) {
|
||||||
|
if (ts->phase == TRANS_IDLE || ts->phase == TRANS_PHASE_DONE) return;
|
||||||
|
|
||||||
|
ts->timer += dt;
|
||||||
|
|
||||||
|
/* ── Outro phase ── */
|
||||||
|
if (ts->phase == TRANS_PHASE_OUT) {
|
||||||
|
/* Play sound once at start of teleporter dissolve. */
|
||||||
|
if (ts->out_style == TRANS_TELEPORTER && !ts->sound_played) {
|
||||||
|
audio_play_sound(s_sfx_teleport, 80);
|
||||||
|
ts->sound_played = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Elevator rumble during the hold period. */
|
||||||
|
if (ts->out_style == TRANS_ELEVATOR && cam) {
|
||||||
|
if (ts->timer > ELEVATOR_CLOSE_DURATION) {
|
||||||
|
camera_shake(cam, 3.0f, 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts->timer >= ts->phase_dur) {
|
||||||
|
ts->phase = TRANS_PHASE_LOAD;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Load phase: caller must call transition_begin_intro() ── */
|
||||||
|
if (ts->phase == TRANS_PHASE_LOAD) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Intro phase ── */
|
||||||
|
if (ts->phase == TRANS_PHASE_IN) {
|
||||||
|
/* Elevator rumble at the start of intro (before doors open). */
|
||||||
|
if (ts->in_style == TRANS_ELEVATOR && cam) {
|
||||||
|
if (ts->timer < ELEVATOR_HOLD_DURATION) {
|
||||||
|
camera_shake(cam, 2.5f, 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts->timer >= ts->phase_dur) {
|
||||||
|
ts->phase = TRANS_PHASE_DONE;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool transition_needs_load(const TransitionState *ts) {
|
||||||
|
return ts->phase == TRANS_PHASE_LOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
void transition_begin_intro(TransitionState *ts) {
|
||||||
|
ts->phase = TRANS_PHASE_IN;
|
||||||
|
ts->timer = 0.0f;
|
||||||
|
ts->phase_dur = intro_duration(ts->in_style);
|
||||||
|
ts->sound_played = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool transition_is_done(const TransitionState *ts) {
|
||||||
|
return ts->phase == TRANS_PHASE_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void transition_reset(TransitionState *ts) {
|
||||||
|
ts->phase = TRANS_IDLE;
|
||||||
|
ts->timer = 0.0f;
|
||||||
|
ts->phase_dur = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Elevator rendering helpers
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
/* Returns door coverage 0.0 (fully open) to 1.0 (fully closed). */
|
||||||
|
static float elevator_coverage(const TransitionState *ts) {
|
||||||
|
if (ts->phase == TRANS_PHASE_OUT) {
|
||||||
|
/* Closing: 0 → 1 over ELEVATOR_CLOSE_DURATION, then hold at 1. */
|
||||||
|
float t = ts->timer / ELEVATOR_CLOSE_DURATION;
|
||||||
|
if (t > 1.0f) t = 1.0f;
|
||||||
|
/* Ease-in-out for smooth motion. */
|
||||||
|
return t * t * (3.0f - 2.0f * t);
|
||||||
|
}
|
||||||
|
if (ts->phase == TRANS_PHASE_IN) {
|
||||||
|
/* Hold closed during ELEVATOR_HOLD_DURATION, then open. */
|
||||||
|
float open_t = ts->timer - ELEVATOR_HOLD_DURATION;
|
||||||
|
if (open_t <= 0.0f) return 1.0f;
|
||||||
|
float t = open_t / ELEVATOR_OPEN_DURATION;
|
||||||
|
if (t > 1.0f) t = 1.0f;
|
||||||
|
float ease = t * t * (3.0f - 2.0f * t);
|
||||||
|
return 1.0f - ease;
|
||||||
|
}
|
||||||
|
/* PHASE_LOAD: fully closed. */
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render_elevator(const TransitionState *ts) {
|
||||||
|
float coverage = elevator_coverage(ts);
|
||||||
|
if (coverage <= 0.0f) return;
|
||||||
|
|
||||||
|
int half_h = (int)(coverage * (float)SCREEN_HEIGHT * 0.5f + 0.5f);
|
||||||
|
|
||||||
|
SDL_Renderer *r = g_engine.renderer;
|
||||||
|
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
|
||||||
|
SDL_SetRenderDrawColor(r, ELEV_R, ELEV_G, ELEV_B, 255);
|
||||||
|
|
||||||
|
/* Top door. */
|
||||||
|
SDL_Rect top = {0, 0, SCREEN_WIDTH, half_h};
|
||||||
|
SDL_RenderFillRect(r, &top);
|
||||||
|
|
||||||
|
/* Bottom door. */
|
||||||
|
SDL_Rect bot = {0, SCREEN_HEIGHT - half_h, SCREEN_WIDTH, half_h};
|
||||||
|
SDL_RenderFillRect(r, &bot);
|
||||||
|
|
||||||
|
/* Thin bright seam at the meeting edge (visual detail). */
|
||||||
|
if (coverage > 0.7f) {
|
||||||
|
int seam_y = half_h - 1;
|
||||||
|
SDL_SetRenderDrawColor(r, 100, 110, 130, 255);
|
||||||
|
SDL_Rect seam_top = {0, seam_y, SCREEN_WIDTH, 1};
|
||||||
|
SDL_RenderFillRect(r, &seam_top);
|
||||||
|
|
||||||
|
int seam_bot_y = SCREEN_HEIGHT - half_h;
|
||||||
|
SDL_Rect seam_bot = {0, seam_bot_y, SCREEN_WIDTH, 1};
|
||||||
|
SDL_RenderFillRect(r, &seam_bot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Teleporter rendering helpers
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
/* Scanline dissolve progress: each band sweeps across the screen.
|
||||||
|
* band_idx: which band (0 = top), total_bands: how many bands,
|
||||||
|
* global_progress: 0.0–1.0 across the dissolve duration,
|
||||||
|
* reverse: if true, sweep right-to-left / bottom-to-top. */
|
||||||
|
static float band_progress(int band_idx, int total_bands,
|
||||||
|
float global_progress, bool reverse) {
|
||||||
|
float band_offset;
|
||||||
|
if (reverse) {
|
||||||
|
band_offset = (float)(total_bands - 1 - band_idx) / (float)total_bands
|
||||||
|
* SCANLINE_STAGGER;
|
||||||
|
} else {
|
||||||
|
band_offset = (float)band_idx / (float)total_bands * SCANLINE_STAGGER;
|
||||||
|
}
|
||||||
|
float local = (global_progress - band_offset) / (1.0f - SCANLINE_STAGGER);
|
||||||
|
if (local < 0.0f) local = 0.0f;
|
||||||
|
if (local > 1.0f) local = 1.0f;
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render_teleporter_scanlines(float global_progress,
|
||||||
|
bool reverse) {
|
||||||
|
int total_bands = SCREEN_HEIGHT / SCANLINE_HEIGHT;
|
||||||
|
SDL_Renderer *r = g_engine.renderer;
|
||||||
|
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_NONE);
|
||||||
|
SDL_SetRenderDrawColor(r, 0, 0, 0, 255);
|
||||||
|
|
||||||
|
for (int i = 0; i < total_bands; i++) {
|
||||||
|
float bp = band_progress(i, total_bands, global_progress, reverse);
|
||||||
|
if (bp <= 0.0f) continue;
|
||||||
|
|
||||||
|
int y = i * SCANLINE_HEIGHT;
|
||||||
|
int w = (int)(bp * (float)SCREEN_WIDTH + 0.5f);
|
||||||
|
if (w <= 0) continue;
|
||||||
|
if (w > SCREEN_WIDTH) w = SCREEN_WIDTH;
|
||||||
|
|
||||||
|
/* Alternate sweep direction per band for visual interest. */
|
||||||
|
int x = (i % 2 == 0) ? 0 : (SCREEN_WIDTH - w);
|
||||||
|
|
||||||
|
SDL_Rect band = {x, y, w, SCANLINE_HEIGHT};
|
||||||
|
SDL_RenderFillRect(r, &band);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render_teleporter_flash(float alpha_f) {
|
||||||
|
if (alpha_f <= 0.0f) return;
|
||||||
|
uint8_t alpha = (uint8_t)(alpha_f * 255.0f);
|
||||||
|
if (alpha == 0) return;
|
||||||
|
|
||||||
|
SDL_Renderer *r = g_engine.renderer;
|
||||||
|
SDL_SetRenderDrawBlendMode(r, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetRenderDrawColor(r, 255, 255, 255, alpha);
|
||||||
|
SDL_Rect rect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
|
SDL_RenderFillRect(r, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render_teleporter(const TransitionState *ts) {
|
||||||
|
if (ts->phase == TRANS_PHASE_OUT) {
|
||||||
|
/* Phase 1: scanline dissolve, then flash builds up. */
|
||||||
|
if (ts->timer < TELEPORT_DISSOLVE_DURATION) {
|
||||||
|
float progress = ts->timer / TELEPORT_DISSOLVE_DURATION;
|
||||||
|
render_teleporter_scanlines(progress, false);
|
||||||
|
} else {
|
||||||
|
/* Dissolve complete — full black + rising flash. */
|
||||||
|
render_teleporter_scanlines(1.0f, false);
|
||||||
|
float flash_t = (ts->timer - TELEPORT_DISSOLVE_DURATION)
|
||||||
|
/ TELEPORT_FLASH_DURATION;
|
||||||
|
if (flash_t > 1.0f) flash_t = 1.0f;
|
||||||
|
render_teleporter_flash(flash_t);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts->phase == TRANS_PHASE_LOAD) {
|
||||||
|
/* Fully covered: black + white flash. */
|
||||||
|
render_teleporter_scanlines(1.0f, false);
|
||||||
|
render_teleporter_flash(1.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts->phase == TRANS_PHASE_IN) {
|
||||||
|
/* Phase 2: flash fades out, then scanlines recede. */
|
||||||
|
if (ts->timer < TELEPORT_FLASH_DURATION) {
|
||||||
|
/* Flash fading over black. */
|
||||||
|
render_teleporter_scanlines(1.0f, true);
|
||||||
|
float flash_t = 1.0f - ts->timer / TELEPORT_FLASH_DURATION;
|
||||||
|
render_teleporter_flash(flash_t);
|
||||||
|
} else {
|
||||||
|
/* Scanlines receding to reveal the new level. */
|
||||||
|
float mat_t = (ts->timer - TELEPORT_FLASH_DURATION)
|
||||||
|
/ TELEPORT_MATERIALIZE_DURATION;
|
||||||
|
if (mat_t > 1.0f) mat_t = 1.0f;
|
||||||
|
/* Progress inverted: 1.0 = fully covered, 0.0 = revealed. */
|
||||||
|
render_teleporter_scanlines(1.0f - mat_t, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Render dispatch
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
void transition_render(const TransitionState *ts) {
|
||||||
|
if (ts->phase == TRANS_IDLE || ts->phase == TRANS_PHASE_DONE) return;
|
||||||
|
|
||||||
|
/* Pick the active style based on which phase we are in. */
|
||||||
|
TransitionStyle style = (ts->phase == TRANS_PHASE_IN)
|
||||||
|
? ts->in_style : ts->out_style;
|
||||||
|
|
||||||
|
switch (style) {
|
||||||
|
case TRANS_ELEVATOR: render_elevator(ts); break;
|
||||||
|
case TRANS_TELEPORTER: render_teleporter(ts); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Name ↔ enum conversion
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
TransitionStyle transition_style_from_name(const char *name) {
|
||||||
|
if (!name) return TRANS_NONE;
|
||||||
|
if (strcmp(name, "spacecraft") == 0) return TRANS_SPACECRAFT;
|
||||||
|
if (strcmp(name, "elevator") == 0) return TRANS_ELEVATOR;
|
||||||
|
if (strcmp(name, "teleporter") == 0) return TRANS_TELEPORTER;
|
||||||
|
return TRANS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *transition_style_name(TransitionStyle style) {
|
||||||
|
switch (style) {
|
||||||
|
case TRANS_SPACECRAFT: return "spacecraft";
|
||||||
|
case TRANS_ELEVATOR: return "elevator";
|
||||||
|
case TRANS_TELEPORTER: return "teleporter";
|
||||||
|
default: return "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
68
src/game/transition.h
Normal file
68
src/game/transition.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#ifndef JNR_TRANSITION_H
|
||||||
|
#define JNR_TRANSITION_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "engine/camera.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
/* ═══════════════════════════════════════════════════
|
||||||
|
* Level transition animations
|
||||||
|
*
|
||||||
|
* Two-phase system: outro (on the old level) then
|
||||||
|
* intro (on the new level). The caller is responsible
|
||||||
|
* for freeing the old level and loading the new one
|
||||||
|
* between phases (when transition_needs_load() is true).
|
||||||
|
*
|
||||||
|
* TransitionStyle enum is defined in config.h so that
|
||||||
|
* both engine (tilemap) and game code can reference it
|
||||||
|
* without circular includes.
|
||||||
|
* ═══════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
typedef enum TransitionPhase {
|
||||||
|
TRANS_IDLE, /* no transition active */
|
||||||
|
TRANS_PHASE_OUT, /* outro animation on the old level */
|
||||||
|
TRANS_PHASE_LOAD, /* ready for the caller to swap levels */
|
||||||
|
TRANS_PHASE_IN, /* intro animation on the new level */
|
||||||
|
TRANS_PHASE_DONE, /* transition complete, return to play */
|
||||||
|
} TransitionPhase;
|
||||||
|
|
||||||
|
typedef struct TransitionState {
|
||||||
|
TransitionStyle out_style; /* outro style (from departing level) */
|
||||||
|
TransitionStyle in_style; /* intro style (from arriving level) */
|
||||||
|
TransitionPhase phase;
|
||||||
|
float timer; /* elapsed time in current phase */
|
||||||
|
float phase_dur; /* total duration of current phase */
|
||||||
|
bool sound_played; /* flag to fire a sound once per phase */
|
||||||
|
} TransitionState;
|
||||||
|
|
||||||
|
/* Start the outro phase. out_style comes from the departing level. */
|
||||||
|
void transition_start_out(TransitionState *ts, TransitionStyle out_style);
|
||||||
|
|
||||||
|
/* Set the intro style (call after loading the new level). */
|
||||||
|
void transition_set_in_style(TransitionState *ts, TransitionStyle in_style);
|
||||||
|
|
||||||
|
/* Advance the transition. cam may be NULL during the load gap. */
|
||||||
|
void transition_update(TransitionState *ts, float dt, Camera *cam);
|
||||||
|
|
||||||
|
/* True when the outro is done and the caller should swap levels. */
|
||||||
|
bool transition_needs_load(const TransitionState *ts);
|
||||||
|
|
||||||
|
/* Acknowledge the load — advance to the intro phase. */
|
||||||
|
void transition_begin_intro(TransitionState *ts);
|
||||||
|
|
||||||
|
/* True when the full transition is finished. */
|
||||||
|
bool transition_is_done(const TransitionState *ts);
|
||||||
|
|
||||||
|
/* Render the transition overlay (call AFTER rendering the level). */
|
||||||
|
void transition_render(const TransitionState *ts);
|
||||||
|
|
||||||
|
/* Reset to idle. */
|
||||||
|
void transition_reset(TransitionState *ts);
|
||||||
|
|
||||||
|
/* Parse a style name string ("none", "elevator", etc.). */
|
||||||
|
TransitionStyle transition_style_from_name(const char *name);
|
||||||
|
|
||||||
|
/* Return the directive string for a style. */
|
||||||
|
const char *transition_style_name(TransitionStyle style);
|
||||||
|
|
||||||
|
#endif /* JNR_TRANSITION_H */
|
||||||
146
src/main.c
146
src/main.c
@@ -6,6 +6,7 @@
|
|||||||
#include "game/editor.h"
|
#include "game/editor.h"
|
||||||
#include "game/stats.h"
|
#include "game/stats.h"
|
||||||
#include "game/analytics.h"
|
#include "game/analytics.h"
|
||||||
|
#include "game/transition.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -24,6 +25,7 @@ typedef enum GameMode {
|
|||||||
MODE_PLAY,
|
MODE_PLAY,
|
||||||
MODE_EDITOR,
|
MODE_EDITOR,
|
||||||
MODE_PAUSED,
|
MODE_PAUSED,
|
||||||
|
MODE_TRANSITION,
|
||||||
} GameMode;
|
} GameMode;
|
||||||
|
|
||||||
static Level s_level;
|
static Level s_level;
|
||||||
@@ -56,6 +58,10 @@ static bool s_session_active = false;
|
|||||||
#define PAUSE_ITEM_COUNT 3
|
#define PAUSE_ITEM_COUNT 3
|
||||||
static int s_pause_selection = 0; /* 0=Resume, 1=Restart, 2=Quit */
|
static int s_pause_selection = 0; /* 0=Resume, 1=Restart, 2=Quit */
|
||||||
|
|
||||||
|
/* ── Level transition state ── */
|
||||||
|
static TransitionState s_transition;
|
||||||
|
static char s_pending_target[ASSET_PATH_MAX] = {0}; /* exit target stashed during transition */
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
/* JS-initiated level load request (level-select dropdown in shell). */
|
/* JS-initiated level load request (level-select dropdown in shell). */
|
||||||
static int s_js_load_request = 0;
|
static int s_js_load_request = 0;
|
||||||
@@ -321,6 +327,48 @@ static void restart_level(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Level load dispatch — loads the next level based on target string ── */
|
||||||
|
static void dispatch_level_load(const char *target) {
|
||||||
|
if (target[0] == '\0') {
|
||||||
|
/* Empty target = victory / end of game. */
|
||||||
|
printf("Level complete! (no next level)\n");
|
||||||
|
end_session("completed");
|
||||||
|
level_free(&s_level);
|
||||||
|
s_station_depth = 0;
|
||||||
|
s_mars_depth = 0;
|
||||||
|
if (!load_level_file("assets/levels/moon01.lvl")) {
|
||||||
|
g_engine.running = false;
|
||||||
|
}
|
||||||
|
begin_session();
|
||||||
|
} else if (strcmp(target, "generate") == 0) {
|
||||||
|
printf("Transitioning to generated level\n");
|
||||||
|
level_free(&s_level);
|
||||||
|
s_gen_seed = (uint32_t)time(NULL);
|
||||||
|
load_generated_level();
|
||||||
|
} else if (strcmp(target, "generate:station") == 0) {
|
||||||
|
printf("Transitioning to space station level\n");
|
||||||
|
level_free(&s_level);
|
||||||
|
s_gen_seed = (uint32_t)time(NULL);
|
||||||
|
load_station_level();
|
||||||
|
} else if (strcmp(target, "generate:mars_base") == 0) {
|
||||||
|
printf("Transitioning to Mars Base level\n");
|
||||||
|
level_free(&s_level);
|
||||||
|
s_gen_seed = (uint32_t)time(NULL);
|
||||||
|
load_mars_base_level();
|
||||||
|
} else {
|
||||||
|
printf("Transitioning to: %s\n", target);
|
||||||
|
char path[ASSET_PATH_MAX];
|
||||||
|
snprintf(path, sizeof(path), "%s", target);
|
||||||
|
level_free(&s_level);
|
||||||
|
if (!load_level_file(path)) {
|
||||||
|
fprintf(stderr, "Failed to load next level: %s\n", path);
|
||||||
|
if (!load_level_file("assets/levels/moon01.lvl")) {
|
||||||
|
g_engine.running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ═══════════════════════════════════════════════════
|
/* ═══════════════════════════════════════════════════
|
||||||
* Game callbacks
|
* Game callbacks
|
||||||
* ═══════════════════════════════════════════════════ */
|
* ═══════════════════════════════════════════════════ */
|
||||||
@@ -392,13 +440,25 @@ static void game_update(float dt) {
|
|||||||
/* Handle deferred level load from JS shell dropdown. */
|
/* Handle deferred level load from JS shell dropdown. */
|
||||||
if (s_js_load_request && s_js_load_path[0]) {
|
if (s_js_load_request && s_js_load_path[0]) {
|
||||||
s_js_load_request = 0;
|
s_js_load_request = 0;
|
||||||
|
|
||||||
|
if (s_mode == MODE_EDITOR) {
|
||||||
|
/* Load the selected level into the editor, not gameplay. */
|
||||||
|
if (!editor_load(&s_editor, s_js_load_path)) {
|
||||||
|
fprintf(stderr, "Failed to load level in editor: %s\n",
|
||||||
|
s_js_load_path);
|
||||||
|
}
|
||||||
|
snprintf(s_edit_path, sizeof(s_edit_path), "%s", s_js_load_path);
|
||||||
|
s_js_load_path[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
end_session("quit");
|
end_session("quit");
|
||||||
|
|
||||||
/* Tear down whatever mode we are in. */
|
/* Tear down whatever mode we are in. */
|
||||||
if (s_mode == MODE_PLAY || s_mode == MODE_PAUSED) {
|
if (s_mode == MODE_PLAY || s_mode == MODE_PAUSED
|
||||||
|
|| s_mode == MODE_TRANSITION) {
|
||||||
|
transition_reset(&s_transition);
|
||||||
level_free(&s_level);
|
level_free(&s_level);
|
||||||
} else if (s_mode == MODE_EDITOR) {
|
|
||||||
editor_free(&s_editor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s_mode = MODE_PLAY;
|
s_mode = MODE_PLAY;
|
||||||
@@ -440,6 +500,28 @@ static void game_update(float dt) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s_mode == MODE_TRANSITION) {
|
||||||
|
transition_update(&s_transition, dt, &s_level.camera);
|
||||||
|
|
||||||
|
/* Outro finished — swap levels. */
|
||||||
|
if (transition_needs_load(&s_transition)) {
|
||||||
|
dispatch_level_load(s_pending_target);
|
||||||
|
s_pending_target[0] = '\0';
|
||||||
|
|
||||||
|
/* Use the new level's intro style. */
|
||||||
|
TransitionStyle in_style = s_level.map.transition_in;
|
||||||
|
transition_set_in_style(&s_transition, in_style);
|
||||||
|
transition_begin_intro(&s_transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Intro finished — return to play. */
|
||||||
|
if (transition_is_done(&s_transition)) {
|
||||||
|
transition_reset(&s_transition);
|
||||||
|
s_mode = MODE_PLAY;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Play mode ── */
|
/* ── Play mode ── */
|
||||||
|
|
||||||
/* Pause on escape (return to editor during test play) */
|
/* Pause on escape (return to editor during test play) */
|
||||||
@@ -492,49 +574,16 @@ static void game_update(float dt) {
|
|||||||
s_stats.levels_completed++;
|
s_stats.levels_completed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target[0] == '\0') {
|
TransitionStyle out_style = s_level.map.transition_out;
|
||||||
/* Empty target = victory / end of game */
|
|
||||||
printf("Level complete! (no next level)\n");
|
if (out_style == TRANS_ELEVATOR || out_style == TRANS_TELEPORTER) {
|
||||||
end_session("completed");
|
/* Animated transition: stash target, start outro. */
|
||||||
/* Loop back to the beginning, reset progression state */
|
snprintf(s_pending_target, sizeof(s_pending_target), "%s", target);
|
||||||
level_free(&s_level);
|
transition_start_out(&s_transition, out_style);
|
||||||
s_station_depth = 0;
|
s_mode = MODE_TRANSITION;
|
||||||
s_mars_depth = 0;
|
|
||||||
if (!load_level_file("assets/levels/moon01.lvl")) {
|
|
||||||
g_engine.running = false;
|
|
||||||
}
|
|
||||||
begin_session();
|
|
||||||
} else if (strcmp(target, "generate") == 0) {
|
|
||||||
/* Procedurally generated next level */
|
|
||||||
printf("Transitioning to generated level\n");
|
|
||||||
level_free(&s_level);
|
|
||||||
s_gen_seed = (uint32_t)time(NULL);
|
|
||||||
load_generated_level();
|
|
||||||
} else if (strcmp(target, "generate:station") == 0) {
|
|
||||||
/* Procedurally generated space station level */
|
|
||||||
printf("Transitioning to space station level\n");
|
|
||||||
level_free(&s_level);
|
|
||||||
s_gen_seed = (uint32_t)time(NULL);
|
|
||||||
load_station_level();
|
|
||||||
} else if (strcmp(target, "generate:mars_base") == 0) {
|
|
||||||
/* Procedurally generated Mars Base level */
|
|
||||||
printf("Transitioning to Mars Base level\n");
|
|
||||||
level_free(&s_level);
|
|
||||||
s_gen_seed = (uint32_t)time(NULL);
|
|
||||||
load_mars_base_level();
|
|
||||||
} else {
|
} else {
|
||||||
/* Load a specific level file */
|
/* Instant transition (none or spacecraft-driven). */
|
||||||
printf("Transitioning to: %s\n", target);
|
dispatch_level_load(target);
|
||||||
char path[ASSET_PATH_MAX];
|
|
||||||
snprintf(path, sizeof(path), "%s", target);
|
|
||||||
level_free(&s_level);
|
|
||||||
if (!load_level_file(path)) {
|
|
||||||
fprintf(stderr, "Failed to load next level: %s\n", path);
|
|
||||||
/* Fallback to moon01 */
|
|
||||||
if (!load_level_file("assets/levels/moon01.lvl")) {
|
|
||||||
g_engine.running = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -587,6 +636,10 @@ static void game_render(float interpolation) {
|
|||||||
/* Render frozen game frame, then overlay the pause menu. */
|
/* Render frozen game frame, then overlay the pause menu. */
|
||||||
level_render(&s_level, interpolation);
|
level_render(&s_level, interpolation);
|
||||||
pause_render();
|
pause_render();
|
||||||
|
} else if (s_mode == MODE_TRANSITION) {
|
||||||
|
/* Render the level (frozen) with the transition overlay on top. */
|
||||||
|
level_render(&s_level, interpolation);
|
||||||
|
transition_render(&s_transition);
|
||||||
} else {
|
} else {
|
||||||
level_render(&s_level, interpolation);
|
level_render(&s_level, interpolation);
|
||||||
}
|
}
|
||||||
@@ -598,7 +651,8 @@ static void game_shutdown(void) {
|
|||||||
/* Always free both — editor may have been initialized even if we're
|
/* Always free both — editor may have been initialized even if we're
|
||||||
* currently in play mode (e.g. shutdown during test play). editor_free
|
* currently in play mode (e.g. shutdown during test play). editor_free
|
||||||
* and level_free are safe to call on zeroed/already-freed structs. */
|
* and level_free are safe to call on zeroed/already-freed structs. */
|
||||||
if (s_mode == MODE_PLAY || s_mode == MODE_PAUSED || s_testing_from_editor) {
|
if (s_mode == MODE_PLAY || s_mode == MODE_PAUSED
|
||||||
|
|| s_mode == MODE_TRANSITION || s_testing_from_editor) {
|
||||||
level_free(&s_level);
|
level_free(&s_level);
|
||||||
}
|
}
|
||||||
if (s_mode == MODE_EDITOR || s_use_editor) {
|
if (s_mode == MODE_EDITOR || s_use_editor) {
|
||||||
|
|||||||
@@ -108,8 +108,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="canvas-container"
|
<div id="canvas-container"
|
||||||
data-analytics-url=""
|
data-analytics-url="https://horchposten.schick-web.site">
|
||||||
data-analytics-key="">
|
|
||||||
<canvas class="emscripten" id="canvas" tabindex="1"
|
<canvas class="emscripten" id="canvas" tabindex="1"
|
||||||
width="640" height="360"></canvas>
|
width="640" height="360"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user