Commit 281e3bfc authored by Eben Blaisdell's avatar Eben Blaisdell

orientation and 2 actions test

parent b04bd83f
......@@ -425,6 +425,8 @@ var Block = function(game,team,x,y) {
this.x = x;
this.y = y;
this.interp = funce.newInterpreter();
this.orient = getRandomInt(0,3);
console.log(this.orient);
this.actions = 0;
this.interp.block = this;
this.interp.globalScope.vars.main = game.codes[team];
......@@ -435,7 +437,14 @@ Block.dx = function(dir){
Block.dy = function(dir){
return {0:0,1:-1,2:0,3:1}[dir];
}
Block.prototype.transformDir = function(dir){
return (dir + this.orient)%4;
}
Block.prototype.untransformDir = function(dir){
return (dir - this.orient)%4;
}
Block.prototype.isOpen = function(dir){
dir = this.untransformDir(dir);
newx = this.x + Block.dx(dir);
newy = this.y + Block.dy(dir);
if(newx<0 || newy<0 || newx>=this.game.width || newy>=this.game.height) {
......@@ -449,6 +458,7 @@ Block.prototype.move = function(dir){
}
this.actions--;
if(this.isOpen(dir)) {
dir = this.untransformDir(dir);
newx = this.x + Block.dx(dir);
newy = this.y + Block.dy(dir);
this.game.board[this.x][this.y] = null;
......@@ -462,6 +472,7 @@ Block.prototype.attack = function(dir) {
return;
}
this.actions--;
dir = this.untransformDir(dir);
attackx = this.x + Block.dx(dir);
attacky = this.y + Block.dy(dir);
if(attackx>=0 && attacky>=0 && attackx<this.game.width && attacky<this.game.height && this.game.board[attackx][attacky] != null) {
......@@ -471,13 +482,14 @@ Block.prototype.attack = function(dir) {
}
Block.prototype.onTurn =function (){
//console.log("onTurn");
this.actions = 1;
this.actions = 2;
this.flops = 0;
funce.exec("onTurn",[],this.interp);
}
Block.prototype.sendMessage = function(dir){
//console.log("onMessage");
//console.log(dir);
dir = this.untransformDir(dir);
messagex = this.x + Block.dx(dir);
messagey = this.y + Block.dy(dir);
if(messagex>=0 && messagey>=0 && messagex<this.game.width && messagey<this.game.height && this.game.board[messagex][messagey] != null) {
......@@ -487,7 +499,7 @@ Block.prototype.sendMessage = function(dir){
Block.prototype.onMessage = function(dir){
//console.log("onMessage");
//console.log(dir);
funce.exec("onMessage",[dir],this.interp);
funce.exec("onMessage",[this.transformDir(dir)],this.interp);
}
//Main
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment