pt2game/game.cpp

76 lines
2.3 KiB
C++

#include <assert.h>
#include <stdio.h>
#include "engine.h"
#define BGWIDTH 1280
#define BGHEIGHT 800
extern const char _binary_sprite_lobby_raw_start[];
extern const char _binary_sprite_managers_office_raw_start[];
extern const char _binary_sprite_stickman_raw_start[];
extern struct navmesh navmesh_lobby;
#define OBJID_BACKGROUND 1
#define OBJID_DOOR_TO_MANAGERS_OFFICE_FROM_LOBBY 2
#define OBJID_DOOR_TO_LOBBY_FROM_MANAGERS_OFFICE 3
// #define OBJID_PLAYER 4
// #define SCRIPTID_PLAYER_WALK 5
#define OBJID_PLAYER_WALK_TO_DOOR_SCRIPT 6
void scene_setup(int scene) {
switch(scene) {
case SCENE_LOBBY:
scene_add_object(OBJID_BACKGROUND, 0, 0, BGWIDTH, BGHEIGHT, _binary_sprite_lobby_raw_start);
scene_add_object(OBJID_DOOR_TO_MANAGERS_OFFICE_FROM_LOBBY, 273, 313, 76, 128, nullptr);
scene_add_object(OBJID_PLAYER, 424, 575, 51, 111, _binary_sprite_stickman_raw_start);
scene_set_navmesh(&navmesh_lobby);
break;
case SCENE_MANAGERS_OFFICE:
scene_add_object(OBJID_BACKGROUND, 0, 0, BGWIDTH, BGHEIGHT, _binary_sprite_managers_office_raw_start);
scene_add_object(OBJID_DOOR_TO_LOBBY_FROM_MANAGERS_OFFICE, 273, 313, 76, 128, nullptr);
scene_add_object(OBJID_PLAYER, 424, 575, 51, 111, _binary_sprite_stickman_raw_start);
break;
}
}
static void transition_scene_on_walk_finish(struct script *scr, int wakeupMode, int arg1, int arg2, int arg3, int arg4) {
scr->id = 0;
printf("walk finish transition %d %d\n", wakeupMode, scr->vars[0]);
if(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT)
transition_scene(scr->vars[0]);
else
assert(wakeupMode == SCRIPT_WAKEUP_OTHER_SCRIPT_INTERRUPTED);
}
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;
}
void onclick(int curscene, int objid) {
switch(curscene) {
case SCENE_LOBBY:
switch(objid) {
case OBJID_DOOR_TO_MANAGERS_OFFICE_FROM_LOBBY:
start_player_walk_to_point_then_transition_scene(312, 441, SCENE_MANAGERS_OFFICE);
return;
}
break;
case SCENE_MANAGERS_OFFICE:
switch(objid) {
case OBJID_DOOR_TO_LOBBY_FROM_MANAGERS_OFFICE:
transition_scene(SCENE_LOBBY);
return;
}
break;
}
}