No error displayed when trying to use a file like this: #39
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
'this' refers to nothing; it silently fails
var player = {
block:true,
tag:"player",
player:true
}
var tween = use('tween')
var clay = use('clay')
var audio = use('sound')
var controller = use('controller')
var search = use('actor')
var math = use('math')
this.mixin("grid_e")
this.sprite = this.spawn("sprite", {path:"alcina"})
this.sprite.play('idle')
var keys = 0;
var haveorb = false;
this.walkspeed = 3;
this.speed = acciodbg.player_speed;
this._speed_ed = {
min: 0.01,
max: 0.3,
};
this.mixin("tweenmover.js");
var move_c;
this.premove = function (c) {
move_c = this.coord;
if (keys == 0) return;
var door = grid.find(c, "door");
if (!door) return;
door = door[0];
grid.rm(door.coord, door);
audio.play("door_open");
door.kill();
keys--;
};
var thunktime = 0.025;
var canthunk = true;
this.postcantmove = function (dir) {
if (!canthunk) return;
canthunk = false;
gamestate.add_mover();
audio.play("cantmove");
var ogpos = this.pos.slice();
tween.tween(
this.pos,
this.pos.add(dir.scale(5)),
thunktime,
v => (this.pos = v),
_ => {
tween.tween(
this.pos,
ogpos,
thunktime,
v => (this.pos = v),
_ => gamestate.rm_mover(),
);
grid.pick(this.coord.add(dir)).forEach(x => x.thunked?.());
},
);
this.delay(_ => (canthunk = true), 0.5);
};
this.postmove = function () {
var key = grid.find(this.coord, "key");
if (key) {
key = key[0];
this.collectkey(key);
}
var movesounded = false;
grid.pick(this.coord).forEach(x => {
if (x.step_sound) {
audio.play(x.step_sound);
return;
}
});
if (!movesounded) audio.play("grass");
};
this.collectkey = function (key) {
keys++;
audio.play("key_pickup");
grid.kl(key.coord, key);
};
var hud_style = {font:'smalle.16', color:Color.black};
this.hud = function hud() {
if (!gamestate.curlevel) return;
var cmds = clay.draw([640,360], _ => {
clay.vstack({behave:clay.behave.top, contain:clay.contain.flex, margin:{t:10,l:5}}, _ => {
clay.text(gamestate.curlevel.name, { background_image:'banner_medieval', padding:{b:20,t:10,r:10,l:10}, font: 'blackcastle.24'});
});
clay.spacer();
clay.vstack({behave:clay.behave.top, margin:10, background_image:'panel_brown', padding:[30,10], slice:20}, _ => {
clay.hstack({}, _ => {
clay.image('key', {size:[16,16]});
clay.text(
x${keys}, hud_style);});
clay.hstack({}, _ => {
clay.image('key', {size:[16,16]});
clay.text(
${gamestate.on_portals}/${gamestate.total_portals}, hud_style);});
clay.text('[r] restart', hud_style);
clay.text('[z] undo', hud_style);
});
});
clay.draw_commands(cmds);
};
var thralled = _ => {
if (gamestate.movement) return;
audio.play("whistle");
var pulled = false;
var fools = search.objects_with_tag("thrall");
fools = fools.filter(f => grid.los(this.coord, f.coord));
fools = fools.sort((a, b) => math.length(a.coord.sub(this.coord)) > math.length(b.coord.sub(this.coord)));
var cached = {};
for (var fool of fools) {
var dd = JSON.stringify(grid.linedir(this.coord, fool.coord));
if (cached[dd]) continue;
}
this.accio();
};
this.accio = function() {
var pulled = false;
var fools = search.objects_with_tag("fool");
fools = fools.filter(f => grid.los(this.coord, f.coord));
fools = fools.sort((a, b) => math.length(a.coord.sub(this.coord)) > math.length(b.coord.sub(this.coord)));
for (var fool of fools) {
var oldc = fool.coord;
grid.moveto(fool, this.coord);
if (!oldc.equal(fool.coord) && fool.move_sound) audio.cry(fool.move_sound);
pulled = true;
}
for (var stone of search.objects_with_tag("stone")) {
if (!grid.los(this.coord, stone.coord)) continue;
var dir = grid.linedir(stone.coord, this.coord);
grid.moveto(stone, stone.coord.add(dir));
pulled = true;
}
for (var twostep of search.objects_with_tag("twostep")) {
if (!grid.los(this.coord, twostep.coord)) continue;
var dir = grid.linedir(twostep.coord, this.coord);
dir = dir.scale(2);
grid.moveto(twostep, twostep.coord.add(dir));
}
};
var stop_move;
this.start_slide = _ => {
if (stop_move) {
stop_move();
stop_move = null;
} else {
this.sprite.anim_speed = this.walkspeed;
this.sprite.play("move");
}
gamestate.step();
};
this.stop_slide = _ => {
stop_move = this.delay(_ => {
this.sprite.anim_speed = 1;
this.sprite.play("idle");
stop_move = null;
}, 0.1);
this.accio();
};
var move = (dir) => {
if (gamestate.movement) return;
grid.moveto(this, this.coord.add(dir));
};
this.inputs = {};
this.inputs.w = function () {
move([0, 1]);
};
this.inputs.w.down = true;
this.inputs.a = function () {
move([-1, 0]);
};
this.inputs.a.down = true;
this.inputs.s = function () {
move([0, -1]);
};
this.inputs.s.down = true;
this.inputs.d = function () {
move([1, 0]);
};
this.inputs.d.down = true;
this.imgui = function () {
/* if (debug.cheat)
debug.cheat = imgui.window("Cheat menu", _ => {
imgui.button("win", gamestate.dowin);
imgui.button("restart", gamestate.reset);
imgui.button("map", gamestate.start_map);
acciodbg.player_speed = imgui.slider("speed", acciodbg.player_speed, 0.01, 0.3);
this.speed = acciodbg.player_speed;
});
if (debug.meta)
debug.meta = imgui.window("Meta", _ => {
gamestate.save_imgui();
});*/
};
this.inputs.tab = function () {
// if (!prosperon.debug) return;
gamestate.reset();
controller.player[0].control(gamestate.content.spawn("cursor"));
};
this.inputs.shift = function () {};
this.inputs.escape = function () {
gamestate.content.spawn("levelpause");
};
this.inputs.space = thralled;
this.inputs.r = function () {
if (gamestate.movement) return;
if (acciodbg.animations) {
this.spawn("fog");
this.delay(_ => gamestate.reset(), 2);
gamestate.add_mover();
} else gamestate.reset();
};
this.inputs.z = function () {
if (gamestate.movement) return;
gamestate.undo();
};
this.inputs.p = function () {
this.spawn("fadeout");
};
controller.player[0].control(this)
log.console("HERE!")
return function() { return {} }