2025-02-18 15:26:16 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2025-02-17 19:11:44 +00:00
|
|
|
#include "engine.h"
|
2025-02-18 22:11:20 +00:00
|
|
|
#include "objids.h"
|
2025-02-17 19:11:44 +00:00
|
|
|
|
|
|
|
#define BGWIDTH 1280
|
|
|
|
#define BGHEIGHT 800
|
|
|
|
|
|
|
|
extern const char _binary_sprite_lobby_raw_start[];
|
|
|
|
extern const char _binary_sprite_managers_office_raw_start[];
|
2025-02-18 20:04:43 +00:00
|
|
|
extern const char _binary_sprite_managers_office_safe_raw_start[];
|
2025-02-18 16:53:24 +00:00
|
|
|
extern const char _binary_sprite_basement_raw_start[];
|
2025-02-17 19:11:44 +00:00
|
|
|
|
2025-02-18 01:04:17 +00:00
|
|
|
extern const char _binary_sprite_stickman_raw_start[];
|
|
|
|
|
|
|
|
extern struct navmesh navmesh_lobby;
|
2025-02-18 16:53:24 +00:00
|
|
|
extern struct navmesh navmesh_managers_office;
|
|
|
|
extern struct navmesh navmesh_basement;
|
2025-02-18 22:11:20 +00:00
|
|
|
extern struct level_predef_data predef_basement, predef_lobby, predef_managers_office;
|
2025-02-18 01:04:17 +00:00
|
|
|
|
2025-02-18 22:11:20 +00:00
|
|
|
static void create_player(int x, int y) {
|
|
|
|
const int WIDTH=51, HEIGHT=111;
|
|
|
|
scene_add_object(OBJID_PLAYER, x-WIDTH/2, y-HEIGHT, WIDTH, HEIGHT, _binary_sprite_stickman_raw_start);
|
|
|
|
}
|
2025-02-17 19:11:44 +00:00
|
|
|
|
2025-02-18 16:53:24 +00:00
|
|
|
void scene_setup(int scene, int fromscene) {
|
2025-02-17 19:11:44 +00:00
|
|
|
switch(scene) {
|
|
|
|
case SCENE_LOBBY:
|
|
|
|
scene_add_object(OBJID_BACKGROUND, 0, 0, BGWIDTH, BGHEIGHT, _binary_sprite_lobby_raw_start);
|
2025-02-18 22:11:20 +00:00
|
|
|
scene_load_predef(&predef_lobby);
|
2025-02-18 16:53:24 +00:00
|
|
|
switch(fromscene) {
|
|
|
|
case SCENE_MANAGERS_OFFICE:
|
2025-02-19 00:55:56 +00:00
|
|
|
create_player(256, 445);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(424, 675);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2025-02-18 21:03:37 +00:00
|
|
|
top_scene.navmesh = &navmesh_lobby;
|
2025-02-19 00:55:56 +00:00
|
|
|
push_scene_textbox("Welcome\n\nto\n\ntestgame");
|
2025-02-17 19:11:44 +00:00
|
|
|
break;
|
|
|
|
case SCENE_MANAGERS_OFFICE:
|
|
|
|
scene_add_object(OBJID_BACKGROUND, 0, 0, BGWIDTH, BGHEIGHT, _binary_sprite_managers_office_raw_start);
|
2025-02-18 22:11:20 +00:00
|
|
|
scene_load_predef(&predef_managers_office);
|
2025-02-18 16:53:24 +00:00
|
|
|
switch(fromscene) {
|
|
|
|
case SCENE_LOBBY:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(804, 708);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
case SCENE_BASEMENT:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(408, 559);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(424, 675);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2025-02-18 21:03:37 +00:00
|
|
|
top_scene.navmesh = &navmesh_managers_office;
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
2025-02-18 20:04:43 +00:00
|
|
|
case SCENE_MANAGERS_OFFICE_SAFE:
|
2025-02-18 21:03:37 +00:00
|
|
|
scene_add_object(OBJID_BACKGROUND, 248, 0, 787, BGHEIGHT, _binary_sprite_managers_office_safe_raw_start);
|
2025-02-18 20:04:43 +00:00
|
|
|
scene_add_object(OBJID_CLOSE_MODAL, 0, 0, 248, 800, nullptr);
|
|
|
|
scene_add_object(OBJID_CLOSE_MODAL, 1035, 0, 1280-1035, 800, nullptr);
|
|
|
|
break;
|
2025-02-18 16:53:24 +00:00
|
|
|
case SCENE_BASEMENT:
|
|
|
|
scene_add_object(OBJID_BACKGROUND, 0, 0, BGWIDTH, BGHEIGHT, _binary_sprite_basement_raw_start);
|
2025-02-18 22:11:20 +00:00
|
|
|
scene_load_predef(&predef_basement);
|
2025-02-18 16:53:24 +00:00
|
|
|
switch(fromscene) {
|
|
|
|
case SCENE_MANAGERS_OFFICE:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(435, 404);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2025-02-18 22:11:20 +00:00
|
|
|
create_player(424, 675);
|
2025-02-18 16:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2025-02-18 21:03:37 +00:00
|
|
|
top_scene.navmesh = &navmesh_basement;
|
2025-02-17 19:11:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-18 15:26:16 +00:00
|
|
|
static void transition_scene_on_walk_finish(struct script *scr, int wakeupMode, int arg1, int arg2, int arg3, int arg4) {
|
|
|
|
scr->id = 0;
|
2025-02-18 21:03:37 +00:00
|
|
|
if(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT) {
|
|
|
|
if(scr->vars[0] == SCENE_MANAGERS_OFFICE_SAFE) {
|
|
|
|
push_scene(scr->vars[0]);
|
|
|
|
} else {
|
|
|
|
replace_scene(scr->vars[0]);
|
|
|
|
}
|
|
|
|
}
|
2025-02-18 15:26:16 +00:00
|
|
|
else
|
|
|
|
assert(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT_INTERRUPTED);
|
|
|
|
}
|
|
|
|
|
2025-02-18 16:22:39 +00:00
|
|
|
static void start_player_walk_to_point_then_transition_scene(int x, int y, int scene) {
|
|
|
|
start_player_walk_to_point(x, y);
|
|
|
|
|
|
|
|
struct script *scr = scene_add_script(OBJID_PLAYER_WALK_TO_DOOR_SCRIPT, true);
|
|
|
|
scr->wakeupMode = SCRIPT_WAKEUP_OTHER_SCRIPT;
|
|
|
|
scr->wakeupArg1 = OBJID_PLAYER_WALK_SCRIPT;
|
|
|
|
scr->wakeupFn = transition_scene_on_walk_finish;
|
|
|
|
scr->vars[0] = scene;
|
|
|
|
}
|
|
|
|
|
2025-02-19 00:55:56 +00:00
|
|
|
static void do_popcorn_on_walk_finish(struct script *scr, int wakeupMode, int arg1, int arg2, int arg3, int arg4) {
|
|
|
|
scr->id = 0;
|
|
|
|
if(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT) {
|
|
|
|
push_scene_textbox("You got popcorn.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT_INTERRUPTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_player_walk_to_point_then_do_popcorn(int x, int y) {
|
|
|
|
start_player_walk_to_point(x, y);
|
|
|
|
|
|
|
|
struct script *scr = scene_add_script(OBJID_PLAYER_WALK_TO_DOOR_SCRIPT, true);
|
|
|
|
scr->wakeupMode = SCRIPT_WAKEUP_OTHER_SCRIPT;
|
|
|
|
scr->wakeupArg1 = OBJID_PLAYER_WALK_SCRIPT;
|
|
|
|
scr->wakeupFn = do_popcorn_on_walk_finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onclick(int curscene, struct object *obj) {
|
|
|
|
if(obj->id == OBJID_CLOSE_MODAL) {
|
|
|
|
pop_scene();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-02-17 19:11:44 +00:00
|
|
|
switch(curscene) {
|
|
|
|
case SCENE_LOBBY:
|
2025-02-19 00:55:56 +00:00
|
|
|
switch(obj->id) {
|
2025-02-17 19:11:44 +00:00
|
|
|
case OBJID_DOOR_TO_MANAGERS_OFFICE_FROM_LOBBY:
|
2025-02-18 16:22:39 +00:00
|
|
|
start_player_walk_to_point_then_transition_scene(312, 441, SCENE_MANAGERS_OFFICE);
|
2025-02-17 19:11:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCENE_MANAGERS_OFFICE:
|
2025-02-19 00:55:56 +00:00
|
|
|
switch(obj->id) {
|
2025-02-17 19:11:44 +00:00
|
|
|
case OBJID_DOOR_TO_LOBBY_FROM_MANAGERS_OFFICE:
|
2025-02-18 16:53:24 +00:00
|
|
|
start_player_walk_to_point_then_transition_scene(815, 713, SCENE_LOBBY);
|
|
|
|
return;
|
|
|
|
case OBJID_MANAGERS_OFFICE_SAFE:
|
2025-02-18 20:04:43 +00:00
|
|
|
start_player_walk_to_point_then_transition_scene(895, 497, SCENE_MANAGERS_OFFICE_SAFE);
|
2025-02-18 16:53:24 +00:00
|
|
|
return;
|
|
|
|
case OBJID_MANAGERS_OFFICE_TRAPDOOR:
|
|
|
|
start_player_walk_to_point_then_transition_scene(408, 559, SCENE_BASEMENT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCENE_BASEMENT:
|
2025-02-19 00:55:56 +00:00
|
|
|
switch(obj->id) {
|
2025-02-18 16:53:24 +00:00
|
|
|
case OBJID_BASEMENT_LADDER:
|
|
|
|
start_player_walk_to_point_then_transition_scene(438, 402, SCENE_MANAGERS_OFFICE);
|
2025-02-17 19:11:44 +00:00
|
|
|
return;
|
2025-02-19 00:55:56 +00:00
|
|
|
case OBJID_POPCORN_BARREL:
|
|
|
|
start_player_walk_to_point_then_do_popcorn(obj->x + obj->width/2, obj->y + obj->height);
|
2025-02-18 20:04:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2025-02-17 19:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-18 01:04:17 +00:00
|
|
|
|