Skip to content

Instantly share code, notes, and snippets.

@AnastasiaDunbar
Last active April 14, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnastasiaDunbar/9ecb5839277c987a45c0abe38aaf9fdd to your computer and use it in GitHub Desktop.
Save AnastasiaDunbar/9ecb5839277c987a45c0abe38aaf9fdd to your computer and use it in GitHub Desktop.
codecombat.com/play
function MoveList(arr){
for(var i=0;i<arr.length;i++){
switch(arr[i]) {
case "a": me.moveLeft(); break;
case "w": me.moveUp(); break;
case "s": me.moveDown(); break;
case "d": me.moveRight(); break;
default: me.say(arr[i]);
}
}
}
function MoveString(str){
for(var i=0;i<str.length;i++){
switch(str[i]) {
case "a": me.moveLeft(); break;
case "w": me.moveUp(); break;
case "s": me.moveDown(); break;
case "d": me.moveRight(); break;
}
}
}
function MoveChar(char){
switch(char) {
case "a": me.moveLeft(); break;
case "w": me.moveUp(); break;
case "s": me.moveDown(); break;
case "d": me.moveRight(); break;
}
}
this.KillEnemies = function(){
var enemy = this.findNearestEnemy();
while(true){
if (enemy != this.findNearestEnemy()) {
enemy = this.findNearestEnemy();
}
if (enemy === null) {
break;
} else {
this.attack(enemy);
}
}
}
this.RunAwayFrom = function(obj,dist){
var direction=Math.atan2(-(obj.pos.y-this.pos.y),obj.pos.x-this.pos.x);
var velocity={x:Math.cos(direction)*dist,y:-(Math.sin(direction)*dist)};
this.moveXY(this.pos.x-velocity.x,this.pos.y-velocity.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment