[oden][game] Multiple screens, logging, pre/post, bluescreen
Better blue screens and also logging and whatnot
This commit is contained in:
parent
95d626c15f
commit
93d4e3eb91
8 changed files with 1201 additions and 244 deletions
|
|
@ -2,7 +2,8 @@ import { load_texture } from "./assets";
|
|||
import { btn, Button } from "./input";
|
||||
import { Vec2, new_v2, vadd, vsub, vnorm, vmul } from "./vector";
|
||||
import { color, stroke, circle, spr, use_texture, Texture } from "./graphics";
|
||||
import { has_collision, Level } from "./level";
|
||||
import { has_collision, Level, World } from "./level";
|
||||
import { log } from "./log";
|
||||
|
||||
export interface ActorProps {
|
||||
id: string;
|
||||
|
|
@ -50,7 +51,15 @@ export class Actor {
|
|||
this.props = props;
|
||||
}
|
||||
|
||||
update() {}
|
||||
pre_update(_world: World) {}
|
||||
|
||||
post_update(_world: World) {}
|
||||
|
||||
update(world: World) {
|
||||
this.pre_update(world);
|
||||
this.update_physics(world.current_level);
|
||||
this.post_update(world);
|
||||
}
|
||||
|
||||
// IDEAS: Make gameplay logic at 30fps and render updates at 60fps? Does
|
||||
// this mean we do some "update" in render?
|
||||
|
|
@ -159,7 +168,7 @@ export class Robo extends Actor {
|
|||
});
|
||||
}
|
||||
|
||||
update() {
|
||||
pre_update() {
|
||||
// Acceleration from input
|
||||
let a = new_v2(0);
|
||||
if (btn(Button.Up)) {
|
||||
|
|
@ -178,6 +187,50 @@ export class Robo extends Actor {
|
|||
this.props.velocity = vadd(this.props.velocity, vmul(a, 0.07));
|
||||
}
|
||||
|
||||
post_update(world: World) {
|
||||
const level = world.current_level;
|
||||
const props = this.props;
|
||||
const w = level.cw - 1;
|
||||
const h = level.ch - 1;
|
||||
|
||||
log("robo position", "cx", props.cx, "cy", props.cy, "w", w, "h", h);
|
||||
let next_level = null;
|
||||
if (props.cx > w || (props.cx == w && props.xr > 0.8)) {
|
||||
const iid = level.neighbors.e;
|
||||
next_level = iid && world.level_map.get(iid);
|
||||
if (next_level) {
|
||||
props.cx = 0;
|
||||
props.xr = 0.2;
|
||||
}
|
||||
} else if (props.cy > h || (props.cy == h && props.yr > 0.8)) {
|
||||
const iid = level.neighbors.s;
|
||||
next_level = iid && world.level_map.get(iid);
|
||||
if (next_level) {
|
||||
props.cy = 0;
|
||||
props.yr = 0.2;
|
||||
}
|
||||
} else if (props.cx < 0 || (props.cx == 0 && props.xr < 0.2)) {
|
||||
const iid = level.neighbors.w;
|
||||
next_level = iid && world.level_map.get(iid);
|
||||
if (next_level) {
|
||||
props.cx = next_level.cw - 1;
|
||||
props.xr = 0.8;
|
||||
}
|
||||
} else if (props.cy < 0 || (props.cy == 0 && props.yr < 0.2)) {
|
||||
const iid = level.neighbors.n;
|
||||
next_level = iid && world.level_map.get(iid);
|
||||
if (next_level) {
|
||||
props.cy = next_level.ch - 1;
|
||||
props.yr = 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
if (next_level) {
|
||||
log("vwoop", next_level.iid);
|
||||
world.current_level = next_level; // Yikes.
|
||||
}
|
||||
}
|
||||
|
||||
draw(clock: number) {
|
||||
if (this.bot_sprite != undefined) {
|
||||
use_texture(this.bot_sprite);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue