2023-12-11 16:59:59 -06:00
|
|
|
"use math";
|
2023-05-24 20:45:50 -05:00
|
|
|
var files = {};
|
|
|
|
function load(file) {
|
2023-09-18 10:45:51 -05:00
|
|
|
var modtime = cmd(0, file);
|
2023-05-24 20:45:50 -05:00
|
|
|
files[file] = modtime;
|
2023-09-18 12:35:40 -05:00
|
|
|
}
|
2023-05-24 20:45:50 -05:00
|
|
|
|
2023-09-18 10:45:51 -05:00
|
|
|
load("scripts/base.js");
|
2023-09-07 16:46:35 -05:00
|
|
|
load("scripts/std.js");
|
2023-09-05 17:09:25 -05:00
|
|
|
|
2023-05-29 10:47:30 -05:00
|
|
|
function run(file)
|
|
|
|
{
|
2023-06-08 17:27:37 -05:00
|
|
|
var modtime = cmd(119, file);
|
2023-05-29 10:47:30 -05:00
|
|
|
if (modtime === 0) {
|
|
|
|
Log.stack();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
files[file] = modtime;
|
2023-06-08 17:27:37 -05:00
|
|
|
return cmd(117, file);
|
2023-05-29 10:47:30 -05:00
|
|
|
}
|
|
|
|
|
2023-11-02 17:25:00 -05:00
|
|
|
function run_env(file, env)
|
|
|
|
{
|
|
|
|
var script = IO.slurp(file);
|
|
|
|
return function(){return eval(script);}.call(env);
|
|
|
|
}
|
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
load("scripts/diff.js");
|
2023-09-05 17:09:25 -05:00
|
|
|
Log.level = 1;
|
2023-05-24 20:45:50 -05:00
|
|
|
|
2023-11-29 12:40:13 -06:00
|
|
|
load("scripts/color.js");
|
2023-09-22 09:44:58 -05:00
|
|
|
|
2023-06-01 15:58:56 -05:00
|
|
|
function bb2wh(bb) {
|
|
|
|
return [bb.r-bb.l, bb.t-bb.b];
|
|
|
|
};
|
|
|
|
|
2023-11-08 01:39:10 -06:00
|
|
|
var Device = {
|
|
|
|
pc: [1920,1080],
|
|
|
|
macbook_m2: [2560,1664, 13.6],
|
|
|
|
ds_top: [400,240, 3.53],
|
|
|
|
ds_bottom: [320,240, 3.02],
|
|
|
|
playdate: [400,240,2.7],
|
|
|
|
switch: [1280,720, 6.2],
|
|
|
|
switch_lite: [1280,720,5.5],
|
|
|
|
switch_oled: [1280,720,7],
|
|
|
|
dsi: [256,192,3.268],
|
|
|
|
ds: [256,192, 3],
|
|
|
|
dsixl: [256,192,4.2],
|
|
|
|
ipad_air_m2: [2360,1640, 11.97],
|
|
|
|
iphone_se: [1334, 750, 4.7],
|
|
|
|
iphone_12_pro: [2532,1170,6.06],
|
|
|
|
iphone_15: [2556,1179,6.1],
|
|
|
|
gba: [240,160,2.9],
|
|
|
|
gameboy: [160,144,2.48],
|
|
|
|
gbc: [160,144,2.28],
|
|
|
|
steamdeck: [1280,800,7],
|
|
|
|
vita: [960,544,5],
|
|
|
|
psp: [480,272,4.3],
|
|
|
|
imac_m3: [4480,2520,23.5],
|
|
|
|
macbook_pro_m3: [3024,1964, 14.2],
|
|
|
|
ps1: [320,240,5],
|
|
|
|
ps2: [640,480],
|
|
|
|
snes: [256,224],
|
|
|
|
gamecube: [640,480],
|
|
|
|
n64: [320,240],
|
|
|
|
c64: [320,200],
|
|
|
|
macintosh: [512,342,9],
|
|
|
|
gamegear: [160,144,3.2],
|
|
|
|
};
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
load("scripts/gui.js");
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-11-16 09:27:04 -06:00
|
|
|
var timer = {
|
|
|
|
update(dt) {
|
|
|
|
this.remain -= dt;
|
|
|
|
if (this.remain <= 0)
|
|
|
|
this.fire();
|
|
|
|
},
|
|
|
|
|
|
|
|
kill() {
|
|
|
|
Register.unregister_obj(this);
|
|
|
|
},
|
2023-11-29 17:31:41 -06:00
|
|
|
|
|
|
|
delay(fn, secs) {
|
2023-11-16 09:27:04 -06:00
|
|
|
var t = Object.create(this);
|
|
|
|
t.time = secs;
|
|
|
|
t.remain = secs;
|
2023-11-29 17:31:41 -06:00
|
|
|
t.fire = function() { fn(); t.kill(); };
|
2023-11-16 09:27:04 -06:00
|
|
|
Register.update.register(t.update, t);
|
2023-11-29 17:31:41 -06:00
|
|
|
return function() { t.kill(); };
|
2023-11-16 09:27:04 -06:00
|
|
|
},
|
|
|
|
};
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-11-29 12:40:13 -06:00
|
|
|
load("scripts/animation.js");
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
var Render = {
|
2023-12-18 06:45:27 -06:00
|
|
|
normal() { cmd(67);},
|
|
|
|
wireframe() { cmd(68); },
|
|
|
|
|
|
|
|
pass() {
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-11-02 17:25:00 -05:00
|
|
|
Render.doc = {
|
|
|
|
doc: "Functions for rendering modes.",
|
|
|
|
normal: "Final render with all lighting.",
|
|
|
|
wireframe: "Show only wireframes of models."
|
|
|
|
};
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
load("scripts/physics.js");
|
|
|
|
load("scripts/input.js");
|
2023-09-08 01:26:48 -05:00
|
|
|
load("scripts/sound.js");
|
2023-11-27 17:04:04 -06:00
|
|
|
load("scripts/ai.js");
|
2023-04-25 14:59:26 -05:00
|
|
|
|
2023-10-23 08:08:11 -05:00
|
|
|
function screen2world(screenpos) {
|
|
|
|
if (Game.camera)
|
|
|
|
return Game.camera.view2world(screenpos);
|
|
|
|
return screenpos;
|
|
|
|
}
|
2023-09-07 16:46:35 -05:00
|
|
|
function world2screen(worldpos) { return Game.camera.world2view(worldpos); }
|
2023-04-25 16:59:12 -05:00
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
var Register = {
|
2023-09-02 06:53:52 -05:00
|
|
|
kbm_input(mode, btn, state, ...args) {
|
2023-09-12 17:19:46 -05:00
|
|
|
if (state === 'released') {
|
2023-12-18 06:45:27 -06:00
|
|
|
btn = btn.split('-').last();
|
2023-09-12 17:19:46 -05:00
|
|
|
}
|
|
|
|
|
2023-09-02 06:53:52 -05:00
|
|
|
switch(mode) {
|
|
|
|
case "emacs":
|
|
|
|
Player.players[0].raw_input(btn, state, ...args);
|
|
|
|
break;
|
2023-09-12 17:19:46 -05:00
|
|
|
|
|
|
|
case "mouse":
|
|
|
|
Player.players[0].mouse_input(btn, state, ...args);
|
|
|
|
break;
|
2023-09-14 12:49:29 -05:00
|
|
|
|
|
|
|
case "char":
|
|
|
|
Player.players[0].char_input(btn);
|
|
|
|
break;
|
2023-09-02 06:53:52 -05:00
|
|
|
};
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
|
|
|
|
2023-04-25 16:59:12 -05:00
|
|
|
gamepad_playermap: [],
|
|
|
|
gamepad_input(pad, btn, state, ...args) {
|
|
|
|
var player = this.gamepad_playermap[pad];
|
|
|
|
if (!player) return;
|
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
var statestr = Input.state2str(state);
|
2023-04-25 16:59:12 -05:00
|
|
|
|
|
|
|
var rawfn = `gamepad_${btn}_${statestr}`;
|
|
|
|
player.input(rawfn, ...args);
|
|
|
|
|
|
|
|
Action.actions.forEach(x => {
|
|
|
|
if (x.inputs.includes(btn))
|
|
|
|
player.input(`action_${x.name}_${statestr}`, ...args);
|
|
|
|
});
|
|
|
|
},
|
2023-08-28 17:00:53 -05:00
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
unregister_obj(obj) {
|
2023-08-28 17:00:53 -05:00
|
|
|
Register.registries.forEach(function(x) {
|
2023-09-06 17:48:08 -05:00
|
|
|
x.unregister_obj(obj);
|
2023-08-28 17:00:53 -05:00
|
|
|
});
|
2023-08-29 09:41:40 -05:00
|
|
|
Player.uncontrol(obj);
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
2023-05-24 20:45:50 -05:00
|
|
|
|
2023-05-27 10:13:20 -05:00
|
|
|
endofloop(fn) {
|
|
|
|
if (!this.inloop)
|
|
|
|
fn();
|
|
|
|
else {
|
|
|
|
this.loopcbs.push(fn);
|
|
|
|
}
|
|
|
|
},
|
2023-04-25 16:59:12 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
clear() {
|
|
|
|
Register.registries.forEach(function(n) {
|
|
|
|
n.entries = [];
|
|
|
|
});
|
|
|
|
},
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
registries: [],
|
2023-06-05 17:19:43 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
add_cb(idx, name) {
|
|
|
|
var entries = [];
|
|
|
|
var n = {};
|
|
|
|
n.register = function(fn, obj) {
|
2023-09-06 17:48:08 -05:00
|
|
|
if (!obj) {
|
2023-09-07 16:46:35 -05:00
|
|
|
Log.error("Refusing to register a function without a destroying object.");
|
2023-09-06 17:48:08 -05:00
|
|
|
return;
|
|
|
|
}
|
2023-09-07 16:46:35 -05:00
|
|
|
entries.push({
|
|
|
|
fn: fn,
|
|
|
|
obj: obj
|
|
|
|
});
|
2023-08-28 17:00:53 -05:00
|
|
|
}
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
n.unregister = function(fn) {
|
2023-10-31 12:38:23 -05:00
|
|
|
entries = entries.filter(function(e) { return e.fn !== fn; });
|
2023-09-06 17:48:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
n.unregister_obj = function(obj) {
|
2023-09-07 16:46:35 -05:00
|
|
|
entries = entries.filter(function(e) { return e.obj !== obj; });
|
2023-08-28 17:00:53 -05:00
|
|
|
}
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-29 17:11:36 -05:00
|
|
|
n.broadcast = function(...args) {
|
2023-09-07 16:46:35 -05:00
|
|
|
entries.forEach(x => x.fn.call(x.obj, ...args));
|
2023-08-28 17:00:53 -05:00
|
|
|
}
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
n.clear = function() {
|
|
|
|
entries = [];
|
|
|
|
}
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
register(idx, n.broadcast, n);
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
Register[name] = n;
|
|
|
|
Register.registries.push(n);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
},
|
2023-04-22 16:44:26 -05:00
|
|
|
};
|
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
Register.add_cb(0, "update").doc = "Called once per frame.";
|
2023-11-29 17:31:41 -06:00
|
|
|
Register.add_cb(11, "appupdate");
|
2023-08-28 17:00:53 -05:00
|
|
|
Register.add_cb(1, "physupdate");
|
|
|
|
Register.add_cb(2, "gui");
|
|
|
|
Register.add_cb(6, "debug");
|
|
|
|
register(7, Register.kbm_input, Register);
|
|
|
|
Register.add_cb(8, "gamepad_input");
|
|
|
|
Register.add_cb(10, "draw");
|
2023-05-24 20:45:50 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
register(9, Log.stack, this);
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
Register.gamepad_playermap[0] = Player.players[0];
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
var Signal = {
|
|
|
|
obj_begin(fn, obj, go) {
|
|
|
|
register_collide(0, fn, obj, go.body);
|
|
|
|
},
|
|
|
|
|
|
|
|
obj_separate(fn, obj, go) {
|
|
|
|
register_collide(3,fn,obj,go.body);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-11-22 03:51:43 -06:00
|
|
|
var Event = {
|
|
|
|
events: {},
|
|
|
|
|
|
|
|
observe(name, obj, fn) {
|
|
|
|
this.events[name] ??= [];
|
|
|
|
this.events[name].push([obj, fn]);
|
|
|
|
},
|
|
|
|
|
|
|
|
unobserve(name, obj) {
|
|
|
|
this.events[name] = this.events[name].filter(x => x[0] !== obj);
|
|
|
|
},
|
|
|
|
|
2023-12-20 17:20:29 -06:00
|
|
|
rm_obj(obj) {
|
|
|
|
Object.keys(this.events).forEach(name => Event.unobserve(name,obj));
|
|
|
|
},
|
|
|
|
|
2023-11-22 03:51:43 -06:00
|
|
|
notify(name) {
|
|
|
|
if (!this.events[name]) return;
|
|
|
|
this.events[name].forEach(function(x) {
|
|
|
|
x[1].call(x[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-12-20 17:20:29 -06:00
|
|
|
Event.observe('quit', undefined, function() { Primum.kill(); });
|
|
|
|
|
2023-06-06 15:49:55 -05:00
|
|
|
var Window = {
|
2023-10-16 09:40:43 -05:00
|
|
|
fullscreen(f) { cmd(145, f); },
|
2023-09-04 09:48:44 -05:00
|
|
|
set width(w) { cmd(125, w); },
|
|
|
|
set height(h) { cmd(126, h); },
|
|
|
|
get width() { return cmd(48); },
|
|
|
|
get height() { return cmd(49); },
|
2023-09-06 12:17:16 -05:00
|
|
|
get dimensions() { return [this.width, this.height]; },
|
2023-09-13 01:08:32 -05:00
|
|
|
set name(str) { cmd(134, str); },
|
2023-10-04 08:18:09 -05:00
|
|
|
boundingbox() {
|
|
|
|
return {
|
|
|
|
t: Window.height,
|
|
|
|
b: 0,
|
|
|
|
r: Window.width,
|
|
|
|
l: 0
|
|
|
|
};
|
|
|
|
},
|
2023-06-06 15:49:55 -05:00
|
|
|
};
|
|
|
|
|
2023-08-28 17:00:53 -05:00
|
|
|
Window.icon = function(path) { cmd(90, path); };
|
|
|
|
Window.icon.doc = "Set the icon of the window using the PNG image at path.";
|
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
function reloadfiles() {
|
|
|
|
Object.keys(files).forEach(function (x) { load(x); });
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
load("scripts/debug.js");
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-05-29 10:47:30 -05:00
|
|
|
/*
|
2023-04-22 16:44:26 -05:00
|
|
|
function Color(from) {
|
|
|
|
var color = Object.create(Array);
|
|
|
|
Object.defineProperty(color, 'r', setelem(0));
|
|
|
|
Object.defineProperty(color, 'g', setelem(1));
|
|
|
|
Object.defineProperty(color, 'b', setelem(2));
|
|
|
|
Object.defineProperty(color, 'a', setelem(3));
|
|
|
|
|
|
|
|
color.a = color.g = color.b = color.a = 1;
|
|
|
|
Object.assign(color, from);
|
|
|
|
|
|
|
|
return color;
|
|
|
|
};
|
2023-05-29 10:47:30 -05:00
|
|
|
*/
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-10-29 16:39:45 -05:00
|
|
|
var Spline = {};
|
2023-12-12 08:46:27 -06:00
|
|
|
Spline.sample_angle = function(type, points, angle) {
|
2023-12-13 19:53:09 -06:00
|
|
|
return spline_cmd(0, type, points[0].length, points, angle);
|
2023-10-29 16:39:45 -05:00
|
|
|
}
|
2023-12-13 19:53:09 -06:00
|
|
|
|
2023-12-20 17:20:29 -06:00
|
|
|
Spline.bezier_loop = function(cp)
|
|
|
|
{
|
|
|
|
cp.push(Vector.reflect_point(cp.at(-2),cp.at(-1)));
|
|
|
|
cp.push(Vector.reflect_point(cp[1],cp[0]));
|
|
|
|
cp.push(cp[0].slice());
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
2023-12-21 10:49:44 -06:00
|
|
|
Spline.bezier_node_count = function(cp)
|
|
|
|
{
|
|
|
|
if (cp.length === 4) return 2;
|
|
|
|
return 2 + (cp.length-4)/3;
|
|
|
|
}
|
|
|
|
|
2023-12-18 17:12:05 -06:00
|
|
|
Spline.is_bezier = function(t) { return t === Spline.type.bezier; }
|
|
|
|
Spline.is_catmull = function(t) { return t === Spline.type.catmull; }
|
|
|
|
|
2023-12-18 06:45:27 -06:00
|
|
|
Spline.bezier2catmull = function(b)
|
|
|
|
{
|
|
|
|
var c = [];
|
|
|
|
for (var i = 0; i < b.length; i += 3)
|
|
|
|
c.push(b[i]);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.catmull2bezier = function(c)
|
|
|
|
{
|
|
|
|
var b = [];
|
|
|
|
for (var i = 1; i < c.length-2; i++) {
|
|
|
|
b.push(c[i].slice());
|
|
|
|
b.push(c[i+1].sub(c[i-1]).scale(0.25).add(c[i]));
|
|
|
|
b.push(c[i].sub(c[i+2]).scale(0.25).add(c[i+1]));
|
|
|
|
}
|
|
|
|
b.push(c[c.length-2]);
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.catmull_loop = function(cp)
|
|
|
|
{
|
|
|
|
cp = cp.slice();
|
|
|
|
cp.unshift(cp.last());
|
|
|
|
cp.push(cp[1]);
|
|
|
|
cp.push(cp[2]);
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.catmull_caps = function(cp)
|
|
|
|
{
|
|
|
|
cp = cp.slice();
|
|
|
|
cp.unshift(cp[0].sub(cp[1]).add(cp[0]));
|
|
|
|
cp.push(cp.last().sub(cp.at(-2).add(cp.last())));
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.catmull2bezier.doc = "Given a set of control points C for a camtull-rom type curve, return a set of cubic bezier points to give the same curve."
|
|
|
|
|
2023-10-29 16:39:45 -05:00
|
|
|
Spline.type = {
|
2023-12-12 08:46:27 -06:00
|
|
|
catmull: 0,
|
2023-12-13 19:53:09 -06:00
|
|
|
bezier: 1,
|
2023-12-12 08:46:27 -06:00
|
|
|
bspline: 2,
|
|
|
|
cubichermite: 3
|
2023-10-29 16:39:45 -05:00
|
|
|
};
|
|
|
|
|
2023-12-18 06:45:27 -06:00
|
|
|
Spline.bezier_tan_partner = function(points, i)
|
|
|
|
{
|
|
|
|
if (i%3 === 0) return undefined;
|
|
|
|
var partner_i = (i%3) === 2 ? i-1 : i+1;
|
|
|
|
return points[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.bezier_cp_mirror = function(points, i)
|
|
|
|
{
|
|
|
|
if (i%3 === 0) return undefined;
|
|
|
|
var partner_i = (i%3) === 2 ? i+2 : i-2;
|
|
|
|
var node_i = (i%3) === 2 ? i+1 : i-1;
|
|
|
|
if (partner_i >= points.length || node_i >= points.length) return;
|
|
|
|
points[partner_i] = points[node_i].sub(points[i]).add(points[node_i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Spline.bezier_point_handles = function(points, i)
|
|
|
|
{
|
|
|
|
if (!Spline.bezier_is_node(points,i)) return [];
|
|
|
|
var a = i-1;
|
|
|
|
var b = i+1;
|
|
|
|
var c = []
|
|
|
|
if (a > 0)
|
|
|
|
c.push(a);
|
|
|
|
|
|
|
|
if (b < points.length)
|
|
|
|
c.push(b);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2023-12-19 15:34:36 -06:00
|
|
|
Spline.bezier_nodes = function(points)
|
|
|
|
{
|
|
|
|
var c = [];
|
|
|
|
for (var i = 0; i < points.length; i+=3)
|
|
|
|
c.push(points[i].slice());
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2023-12-18 06:45:27 -06:00
|
|
|
Spline.bezier_is_node = function(points, i) { return i%3 === 0; }
|
|
|
|
Spline.bezier_is_handle = function(points, i) { return !Spline.bezier_is_node(points,i); }
|
|
|
|
|
2023-04-22 16:44:26 -05:00
|
|
|
load("scripts/components.js");
|
|
|
|
|
|
|
|
var Game = {
|
2023-10-23 08:08:11 -05:00
|
|
|
init() {
|
|
|
|
if (!Game.edit) {
|
|
|
|
load("config.js");
|
|
|
|
load("game.js");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
load("scripts/editor.js");
|
|
|
|
load("editorconfig.js");
|
|
|
|
editor.enter_editor();
|
|
|
|
}
|
|
|
|
},
|
2023-11-08 01:39:10 -06:00
|
|
|
|
|
|
|
native: Device.pc,
|
|
|
|
|
2023-09-13 01:08:32 -05:00
|
|
|
edit: true,
|
2023-10-11 17:22:41 -05:00
|
|
|
|
2023-12-20 17:20:29 -06:00
|
|
|
object_count() {
|
|
|
|
return cmd(214);
|
|
|
|
},
|
|
|
|
|
2023-11-29 12:40:13 -06:00
|
|
|
all_objects(fn) {
|
|
|
|
/* Wind down from Primum */
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Returns a list of objects by name */
|
|
|
|
find(name) {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Return a list of objects derived from a specific prototype */
|
|
|
|
find_proto(proto) {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/* List of all objects spawned that have a specific tag */
|
2023-12-20 17:20:29 -06:00
|
|
|
find_tag(tag){
|
2023-04-22 16:44:26 -05:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2023-12-18 17:12:05 -06:00
|
|
|
quit() { sys_cmd(0); },
|
|
|
|
pause() { sys_cmd(3); },
|
|
|
|
stop() { Game.pause(); },
|
|
|
|
step() { sys_cmd(4);},
|
2023-09-19 12:35:12 -05:00
|
|
|
editor_mode(m) { sys_cmd(10, m); },
|
2023-08-16 20:17:18 -05:00
|
|
|
playing() { return sys_cmd(5); },
|
|
|
|
paused() { return sys_cmd(6); },
|
2023-12-18 17:12:05 -06:00
|
|
|
stepping() { return cmd(79); },
|
|
|
|
play() { sys_cmd(1); },
|
2023-12-04 13:38:37 -06:00
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
wait_fns: [],
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
wait_exec(fn) {
|
|
|
|
if (!phys_stepping())
|
|
|
|
fn();
|
2023-04-22 16:44:26 -05:00
|
|
|
else
|
2023-09-07 16:46:35 -05:00
|
|
|
this.wait_fns.push(fn);
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
exec() {
|
|
|
|
this.wait_fns.forEach(function(x) { x(); });
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
this.wait_fns = [];
|
2023-04-22 16:44:26 -05:00
|
|
|
},
|
2023-09-07 16:46:35 -05:00
|
|
|
};
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-10-23 08:08:11 -05:00
|
|
|
Game.doc = {};
|
|
|
|
Game.doc.object = "Returns the entity belonging to a given id.";
|
|
|
|
Game.doc.quit = "Immediately quit the game.";
|
|
|
|
Game.doc.pause = "Pause game simulation.";
|
|
|
|
Game.doc.stop = "Stop game simulation. This does the same thing as 'pause', and if the game is a debug build, starts its editor.";
|
|
|
|
Game.doc.play = "Resume or start game simulation.";
|
|
|
|
Game.doc.editor_mode = "Set to true for the game to only update on input; otherwise the game updates every frame.";
|
|
|
|
Game.doc.dt = "Current frame dt.";
|
2023-10-31 12:38:23 -05:00
|
|
|
Game.doc.view_camera = "Set the camera for the current view.";
|
|
|
|
Game.doc.camera = "Current camera.";
|
2023-10-23 08:08:11 -05:00
|
|
|
|
|
|
|
Window.doc = {};
|
|
|
|
Window.doc.width = "Width of the game window.";
|
|
|
|
Window.doc.height = "Height of the game window.";
|
|
|
|
Window.doc.dimensions = "Window width and height packaged in an array [width,height]";
|
|
|
|
Window.doc.name = "Name in the title bar of the window.";
|
|
|
|
Window.doc.boundingbox = "Boundingbox of the window, with top and right being its height and width.";
|
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
Register.update.register(Game.exec, Game);
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-09-08 12:35:06 -05:00
|
|
|
load("scripts/entity.js");
|
2023-05-27 07:01:17 -05:00
|
|
|
|
2023-10-23 08:08:11 -05:00
|
|
|
function world_start() {
|
2023-11-29 17:31:41 -06:00
|
|
|
globalThis.Primum = Object.create(gameobject);
|
|
|
|
Primum.objects = {};
|
2023-12-18 17:12:05 -06:00
|
|
|
Primum.check_dirty = function() {};
|
|
|
|
Primum.namestr = function(){};
|
2023-11-29 17:31:41 -06:00
|
|
|
Primum._ed = {
|
|
|
|
selectable:false,
|
|
|
|
dirty:false,
|
|
|
|
};
|
|
|
|
Primum.toString = function() { return "Primum"; };
|
|
|
|
Primum.ur = undefined;
|
2023-12-21 17:21:01 -06:00
|
|
|
Primum.kill = function() { this.clear(); };
|
2023-10-23 08:08:11 -05:00
|
|
|
}
|
2023-09-08 12:35:06 -05:00
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
load("scripts/physics.js");
|
2023-04-22 16:44:26 -05:00
|
|
|
|
2023-09-07 16:46:35 -05:00
|
|
|
Game.view_camera = function(cam)
|
2023-08-23 17:18:34 -05:00
|
|
|
{
|
2023-09-07 16:46:35 -05:00
|
|
|
Game.camera = cam;
|
|
|
|
cmd(61, Game.camera.body);
|
2023-11-08 01:39:10 -06:00
|
|
|
// cam.zoom = cam.zoom;
|
2023-08-23 17:18:34 -05:00
|
|
|
}
|
|
|
|
|
2023-09-13 01:08:32 -05:00
|
|
|
Window.name = "Primum Machinam (V0.1)";
|
2023-09-12 17:19:46 -05:00
|
|
|
Window.width = 1280;
|
|
|
|
Window.height = 720;
|
2023-10-29 16:39:45 -05:00
|
|
|
|
2023-11-02 17:25:00 -05:00
|
|
|
var Asset = {};
|
|
|
|
Asset.doc = {
|
|
|
|
doc: "Functions to manage the loading and unloading of assets, like sounds and images."
|
|
|
|
};
|