Forked from Untrusted-Game/untrusted-lvl20-solution.js
Created
April 2, 2019 18:55
-
-
Save valepu/77cae200c2e92533ecdd347c83eaa4d9 to your computer and use it in GitHub Desktop.
Solution to level 20 in Untrusted: http://alex.nisnevich.com/untrusted/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************** | |
* bossFight.js * | |
***************** | |
* | |
* NO FARTHER, DR. EVAL!!!! | |
* YOU WILL NOT GET OUT OF HERE ALIVE!!!! | |
* IT'S TIME YOU SEE MY TRUE FORM!!!! | |
* FACE MY ROBOT WRATH!!!!! | |
*/ | |
function startLevel(map) { | |
map.defineObject('boss', { | |
'type': 'dynamic', | |
'symbol': '⊙', | |
'color': 'red', | |
'interval': 200, | |
'onCollision': function (player) { | |
player.killedBy('the boss'); | |
}, | |
'behavior': function (me) { | |
if (!me.direction) { | |
me.direction = 'right'; | |
} | |
if (me.canMove(me.direction)) { | |
me.move(me.direction); | |
} else { | |
me.direction = (me.direction == 'right') ? 'left' : 'right'; | |
} | |
if (Math.random() < 0.3) { | |
map.placeObject(me.getX(), me.getY() + 2, 'bullet'); | |
} | |
}, | |
'onDestroy': function (me) { | |
if (map.countObjects('boss') == 0) { | |
map.placeObject(me.getX(), me.getY(), 'theAlgorithm'); | |
} | |
} | |
}); | |
map.defineObject('bullet', { | |
'type': 'dynamic', | |
'symbol': '.', | |
'color': 'red', | |
'interval': 100, | |
'projectile': true, | |
'behavior': function (me) { | |
me.move('down'); | |
} | |
}); | |
map.placePlayer(0, map.getHeight() - 3); | |
map.placeObject(map.getWidth() - 1, map.getHeight() - 1, 'exit'); | |
// Not so tough now, huh? | |
map.getPlayer().removeItem('phone'); | |
map.placeObject(map.getWidth() - 1, map.getHeight() - 3, 'phone'); | |
map.placeObject(0, map.getHeight() - 4, 'block'); | |
map.placeObject(1, map.getHeight() - 4, 'block'); | |
map.placeObject(2, map.getHeight() - 4, 'block'); | |
map.placeObject(2, map.getHeight() - 3, 'block'); | |
map.placeObject(map.getWidth() - 1, map.getHeight() - 4, 'block'); | |
map.placeObject(map.getWidth() - 2, map.getHeight() - 4, 'block'); | |
map.placeObject(map.getWidth() - 3, map.getHeight() - 4, 'block'); | |
map.placeObject(map.getWidth() - 3, map.getHeight() - 3, 'block'); | |
for (var x = 0; x < map.getWidth(); x++) { | |
map.placeObject(x, 4, 'block'); | |
} | |
map.placeObject(9, 5, 'boss'); | |
map.placeObject(11, 5, 'boss'); | |
map.placeObject(13, 5, 'boss'); | |
map.placeObject(15, 5, 'boss'); | |
map.placeObject(17, 5, 'boss'); | |
map.placeObject(19, 5, 'boss'); | |
map.placeObject(21, 5, 'boss'); | |
map.placeObject(23, 5, 'boss'); | |
map.placeObject(25, 5, 'boss'); | |
map.placeObject(27, 5, 'boss'); | |
map.placeObject(29, 5, 'boss'); | |
map.placeObject(31, 5, 'boss'); | |
map.placeObject(10, 6, 'boss'); | |
map.placeObject(12, 6, 'boss'); | |
map.placeObject(14, 6, 'boss'); | |
map.placeObject(16, 6, 'boss'); | |
map.placeObject(18, 6, 'boss'); | |
map.placeObject(20, 6, 'boss'); | |
map.placeObject(22, 6, 'boss'); | |
map.placeObject(24, 6, 'boss'); | |
map.placeObject(26, 6, 'boss'); | |
map.placeObject(28, 6, 'boss'); | |
map.placeObject(30, 6, 'boss'); | |
map.defineObject('zumba', { | |
'type': 'dynamic', | |
'symbol': '6', | |
'color': 'red', | |
}); | |
map.defineObject('antibullet', { | |
'type': 'dynamic', | |
'symbol': '^ÿ^', | |
'color': 'blue', | |
'interval': 100, | |
'projectile': true, | |
'behavior': function (me) { | |
me.move('up'); | |
} | |
}); | |
map.getPlayer().setPhoneCallback(function() { | |
var player = map.getPlayer(); | |
console.log(player.getY()); | |
map.placeObject(player.getX(), player.getY() - 50, 'bullet'); | |
//map.startTimer(function() {}, 90); | |
}); | |
map.overrideKey('right', () => { | |
var player = map.getPlayer(); | |
player.move("right"); | |
map.placeObject(player.getX(), player.getY() - 10, 'antibullet'); | |
map.placeObject(player.getX() -1, player.getY() - 10, 'antibullet'); | |
map.placeObject(player.getX() +1, player.getY() - 10, 'antibullet'); | |
map.placeObject(player.getX() +2, player.getY() - 10, 'antibullet'); | |
map.placeObject(player.getX() -2, player.getY() - 10, 'antibullet'); | |
map.placeObject(player.getX() + 1, player.getY() - 5, 'zumba'); | |
map.placeObject(player.getX() + 0, player.getY() - 5, 'zumba'); | |
map.placeObject(player.getX() + -1, player.getY() - 5, 'zumba'); | |
map.placeObject(player.getX() + 1, player.getY() - 4, 'zumba'); | |
map.placeObject(player.getX() + 0, player.getY() - 4, 'zumba'); | |
map.placeObject(player.getX() + -1, player.getY() - 4, 'zumba'); | |
}); | |
} | |
function validateLevel(map) { | |
// called at start of level and whenever a callback executes | |
map.validateAtMostXObjects(59, 'block'); | |
map.validateAtMostXObjects(1, 'phone'); | |
if (map.countObjects('theAlgorithm') > 0 && map.countObjects('boss') > 0) { | |
throw "The Algorithm can only be dropped by the boss!"; | |
} | |
// only called at start of level | |
if (map.isStartOfLevel()) { | |
map.validateAtMostXDynamicObjects(23); | |
map.validateNoTimers(); | |
} | |
} | |
function onExit(map) { | |
if (!map.getPlayer().hasItem('theAlgorithm')) { | |
map.writeStatus("You must take back the Algorithm!!"); | |
return false; | |
} else if (!map.getPlayer().hasItem('phone')) { | |
map.writeStatus("We need the phone!"); | |
return false; | |
} else { | |
return true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment