function isWalkable () {
  var able = true
  var heroCornerPt = new Phaser.Point(heroMapPos.x - heroMapSprite.width / 2, heroMapPos.y - heroMapSprite.height / 2)
  var cornerTL = new Phaser.Point()
  cornerTL.x = heroCornerPt.x + (heroSpeed * dX)
  cornerTL.y = heroCornerPt.y + (heroSpeed * dY)

  // Now we have the top left corner point.
  // We need to find all 4 corners based on the map marker graphics width & height.
  // Ideally we should just provide the hero a volume instead of using the graphics width & height
  var cornerTR = new Phaser.Point()
  cornerTR.x = cornerTL.x + heroMapSprite.width
  cornerTR.y = cornerTL.y
  var cornerBR = new Phaser.Point()
  cornerBR.x = cornerTR.x
  cornerBR.y = cornerTL.y + heroMapSprite.height
  var cornerBL = new Phaser.Point()
  cornerBL.x = cornerTL.x
  cornerBL.y = cornerBR.y
  var newTileCorner1
  var newTileCorner2
  var newTileCorner3 = heroMapPos

  // Let us get which 2 corners to check based on current facing, may be 3.
  switch (facing) {
    case 'north':
      newTileCorner1=cornerTL
      newTileCorner2=cornerTR
    break
    case 'south':
      newTileCorner1=cornerBL
      newTileCorner2=cornerBR
    break
    case 'east':
      newTileCorner1=cornerBR
      newTileCorner2=cornerTR
    break
    case 'west':
      newTileCorner1=cornerTL
      newTileCorner2=cornerBL
    break
    case 'northeast':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBR
      newTileCorner3=cornerTL
    break
    case 'southeast':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBR
      newTileCorner3=cornerBL
    break
    case 'northwest':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBL
      newTileCorner3=cornerTL
    break
    case 'southwest':
      newTileCorner1=cornerTL
      newTileCorner2=cornerBR
      newTileCorner3=cornerBL
    break
  }

  // Check if those corners fall inside a wall after moving
  newTileCorner1 = getTileCoordinates(newTileCorner1, tileWidth)
  if (levelData[newTileCorner1.y][newTileCorner1.x] === 1) able = false
  newTileCorner2 = getTileCoordinates(newTileCorner2,tileWidth)
  if (levelData[newTileCorner2.y][newTileCorner2.x] === 1) able = false
  newTileCorner3=getTileCoordinates(newTileCorner3,tileWidth);
  if (levelData[newTileCorner3.y][newTileCorner3.x] === 1) able=false
  return able
}
// It is not advisable to create points in update loop, but for code readability.
It is not advisable to create points in update loop, but for code readability.
It is not advisable to create points in update loop but for code readability .
function isWalkable () {
  var able = true
  var heroCornerPt = new Phaser.Point(heroMapPos.x - heroMapSprite.width / 2, heroMapPos.y - heroMapSprite.height / 2)
  var cornerTL = new Phaser.Point()
  cornerTL.x = heroCornerPt.x + (heroSpeed * dX)
  cornerTL.y = heroCornerPt.y + (heroSpeed * dY)
  var cornerTR = new Phaser.Point()
  cornerTR.x = cornerTL.x + heroMapSprite.width
  cornerTR.y = cornerTL.y
  var cornerBR = new Phaser.Point()
  cornerBR.x = cornerTR.x
  cornerBR.y = cornerTL.y + heroMapSprite.height
  var cornerBL = new Phaser.Point()
  cornerBL.x = cornerTL.x
  cornerBL.y = cornerBR.y
  var newTileCorner1
  var newTileCorner2
  var newTileCorner3 = heroMapPos
  switch (facing) {
    case 'north':
      newTileCorner1=cornerTL
      newTileCorner2=cornerTR
    break
    case 'south':
      newTileCorner1=cornerBL
      newTileCorner2=cornerBR
    break
    case 'east':
      newTileCorner1=cornerBR
      newTileCorner2=cornerTR
    break
    case 'west':
      newTileCorner1=cornerTL
      newTileCorner2=cornerBL
    break
    case 'northeast':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBR
      newTileCorner3=cornerTL
    break
    case 'southeast':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBR
      newTileCorner3=cornerBL
    break
    case 'northwest':
      newTileCorner1=cornerTR
      newTileCorner2=cornerBL
      newTileCorner3=cornerTL
    break
    case 'southwest':
      newTileCorner1=cornerTL
      newTileCorner2=cornerBR
      newTileCorner3=cornerBL
    break
  }
  newTileCorner1 = getTileCoordinates(newTileCorner1, tileWidth)
  if (levelData[newTileCorner1.y][newTileCorner1.x] === 1) able = false
  newTileCorner2 = getTileCoordinates(newTileCorner2,tileWidth)
  if (levelData[newTileCorner2.y][newTileCorner2.x] === 1) able = false
  newTileCorner3=getTileCoordinates(newTileCorner3,tileWidth);
  if (levelData[newTileCorner3.y][newTileCorner3.x] === 1) able=false
  return able
}
function isWalkable ( ) { var able = true var heroCornerPt = new Phaser . Point ( heroMapPos . x - heroMapSprite . width / 2 , heroMapPos . y - heroMapSprite . height / 2 ) var cornerTL = new Phaser . Point ( ) cornerTL . x = heroCornerPt . x + ( heroSpeed * dX ) cornerTL . y = heroCornerPt . y + ( heroSpeed * dY ) var cornerTR = new Phaser . Point ( ) cornerTR . x = cornerTL . x + heroMapSprite . width cornerTR . y = cornerTL . y var cornerBR = new Phaser . Point ( ) cornerBR . x = cornerTR . x cornerBR . y = cornerTL . y + heroMapSprite . height var cornerBL = new Phaser . Point ( ) cornerBL . x = cornerTL . x cornerBL . y = cornerBR . y var newTileCorner1 var newTileCorner2 var newTileCorner3 = heroMapPos switch ( facing ) { case 'north' : newTileCorner1 = cornerTL newTileCorner2 = cornerTR break case 'south' : newTileCorner1 = cornerBL newTileCorner2 = cornerBR break case 'east' : newTileCorner1 = cornerBR newTileCorner2 = cornerTR break case 'west' : newTileCorner1 = cornerTL newTileCorner2 = cornerBL break case 'northeast' : newTileCorner1 = cornerTR newTileCorner2 = cornerBR newTileCorner3 = cornerTL break case 'southeast' : newTileCorner1 = cornerTR newTileCorner2 = cornerBR newTileCorner3 = cornerBL break case 'northwest' : newTileCorner1 = cornerTR newTileCorner2 = cornerBL newTileCorner3 = cornerTL break case 'southwest' : newTileCorner1 = cornerTL newTileCorner2 = cornerBR newTileCorner3 = cornerBL break } newTileCorner1 = getTileCoordinates ( newTileCorner1 , tileWidth ) if ( levelData [ newTileCorner1 . y ] [ newTileCorner1 . x ] === 1 ) able = false newTileCorner2 = getTileCoordinates ( newTileCorner2 , tileWidth ) if ( levelData [ newTileCorner2 . y ] [ newTileCorner2 . x ] === 1 ) able = false newTileCorner3 = getTileCoordinates ( newTileCorner3 , tileWidth ) ; if ( levelData [ newTileCorner3 . y ] [ newTileCorner3 . x ] === 1 ) able = false return able }
It is not advisable to create points in update loop, but for code readability.
It is not advisable to create points in update loop but for code readability .
// Now we have the top left corner point. // We need to find all 4 corners based on the map marker graphics width & height. // Ideally we should just provide the hero a volume instead of using the graphics width & height // Let us get which 2 corners to check based on current facing, may be 3. // Check if those corners fall inside a wall after moving