Skip to content

Commit

Permalink
Movement array set up
Browse files Browse the repository at this point in the history
  • Loading branch information
vmckeown committed Mar 28, 2024
1 parent 3c12b0b commit dde9acb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
51 changes: 48 additions & 3 deletions vince_mckeown/Tactics/js/player/warrior.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function warriorClass() {
this.maxHealth = 4;
this.trapCoolDownTimer = 0;
this.trapCoolDownCounter = 0;
this.movementArray = [67,87,88];
this.movementArray = [67];

this.warriorPic = document.createElement("img");

Expand Down Expand Up @@ -67,7 +67,52 @@ function warriorClass() {

this.movement = function() {

var nextX = this.x;
var currentIndex = this.movementArray[0];

if(this.keyHeld_North){
currentIndex = indexN(currentIndex);
if(this.movementArray.length > 1 && this.movementArray[1] == currentIndex){
this.movementArray.shift();
} else {
this.movementArray.unshift(currentIndex);
}
this.keyHeld_North = false;
}
if(this.keyHeld_South){
currentIndex = indexS(currentIndex);
if(this.movementArray.length > 1 && this.movementArray[1] == currentIndex){
this.movementArray.shift();
} else {
this.movementArray.unshift(currentIndex);
}
this.keyHeld_South = false;
}
if(this.keyHeld_West){
currentIndex = indexW(currentIndex);
if(this.movementArray.length > 1 && this.movementArray[1] == currentIndex){
this.movementArray.shift();
} else {
this.movementArray.unshift(currentIndex);
}
this.keyHeld_West = false;
}
if(this.keyHeld_East){
currentIndex = indexE(currentIndex);
if(this.movementArray.length > 1 && this.movementArray[1] == currentIndex){
this.movementArray.shift();
} else {
this.movementArray.unshift(currentIndex);
}
this.keyHeld_East = false;
}

if(this.movementArray.length > 7){
this.movementArray.shift();
}



/*var nextX = this.x;
var nextY = this.y;
var collisionX = nextX;
var collisionY = nextY;
Expand Down Expand Up @@ -126,7 +171,7 @@ function warriorClass() {
break;
} // END OF SWITCH CASE
this.trapCoolDown();

*/
} // END OF THIS.MOVEMENT


Expand Down
21 changes: 19 additions & 2 deletions vince_mckeown/Tactics/js/world/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ function drawTracks(){
canvasContext.drawImage(tileIndicatorPic, isoDrawX - ISO_GRID_W/2, isoDrawY - ISO_TILE_GROUND_Y);
if(showTileNumber){
var textColor;
if(playerOne.movementArray.includes(tileIndex)){
if(playerOne.movementArray[0]==tileIndex){
textColor = "white";
} else if(playerOne.movementArray.includes(tileIndex)){
textColor = "cyan";
}else {
textColor = "orange"
Expand Down Expand Up @@ -171,4 +173,19 @@ function getTileIndexAtPixelCoord(pixelX,pixelY){
function roomTileToIndex(tileCol, tileRow) {
return(tileCol + ROOM_COLS*tileRow);
}


function indexN (fromIndex){
return fromIndex - ROOM_COLS;
}

function indexS (fromIndex){
return fromIndex + ROOM_COLS;
}

function indexW(fromIndex){
return fromIndex - 1;
}

function indexE(fromIndex){
return fromIndex + 1;
}

0 comments on commit dde9acb

Please sign in to comment.