Skip to content

Instantly share code, notes, and snippets.

@Untrusted-Game
Created January 24, 2021 02:45
Show Gist options
  • Save Untrusted-Game/16e92b46e14c259e548175451e2b2b44 to your computer and use it in GitHub Desktop.
Save Untrusted-Game/16e92b46e14c259e548175451e2b2b44 to your computer and use it in GitHub Desktop.
Solution to level 9 in Untrusted: http://alex.nisnevich.com/untrusted/
/**********************
* fordingTheRiver.js *
**********************
*
* And there's the river. Fortunately, I was prepared for this.
* See the raft on the other side?
*
* Everything is going according to plan.
*/
function startLevel(map) {
var raftDirection = 'down';
map.placePlayer(map.getWidth()-1, map.getHeight()-1);
var player = map.getPlayer();
map.defineObject('raft', {
'type': 'dynamic',
'symbol': '▓',
'color': '#420',
'transport': true, // (prevents player from drowning in water)
'behavior': function (me) {
me.move(raftDirection);
}
});
map.defineObject('water', {
'symbol': '░',
'color': '#44f',
'onCollision': function (player) {
player.killedBy('drowning in deep dark water');
}
});
for (var x = 0; x < map.getWidth(); x++) {
for (var y = 5; y < 15; y++) {
map.placeObject(x, y, 'water');
}
}
map.placeObject(20, 5, 'raft');
map.placeObject(0, 2, 'exit');
map.placeObject(0, 1, 'block');
map.placeObject(1, 1, 'block');
map.placeObject(0, 3, 'block');
map.placeObject(1, 3, 'block');
var player = map.getPlayer()
player.setPhoneCallback(function(){
var player = map.getPlayer()
if (player.atLocation(20, 14)) {
raftDirection = 'up'
}
if (player.atLocation(20, 5)) {
raftDirection = 'down'
}
});
/*
The conditionals were not strictly necessary, but it doesn't hurt
to check where I am before doing stuff.
Twisted Code (sometimes called macks2008 or macks2010) was here
*/
}
function validateLevel(map) {
map.validateExactlyXManyObjects(1, 'exit');
map.validateExactlyXManyObjects(1, 'raft');
}
@Twisted-Code
Copy link

Not much to this level either. Just make your function phone reverse the raft direction (either anywhere, as some might do, or only if you are on it on the shore)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment