End of lesson 31
This commit is contained in:
@@ -2,18 +2,20 @@ extends Map2d
|
||||
|
||||
class_name WorldMap
|
||||
|
||||
func playerCanMoveTo(position:Vector2) -> bool:
|
||||
var tilesize = tile_set.tile_size.x
|
||||
func playerCanMoveTo(newPosition:Vector2) -> bool:
|
||||
var cast_cell_1
|
||||
var cast_cell_2
|
||||
|
||||
player.updateRaycasts(position)
|
||||
player.updateRaycasts(newPosition)
|
||||
|
||||
cast_cell_1 = local_to_map(position + player.collisionRay_1.position)
|
||||
cast_cell_2 = local_to_map(position + player.collisionRay_2.position)
|
||||
cast_cell_1 = local_to_map(newPosition + player.collisionRay_1.position)
|
||||
cast_cell_2 = local_to_map(newPosition + player.collisionRay_2.position)
|
||||
|
||||
if (getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_1.x, cast_cell_1.y) != "Water" and
|
||||
getTerrainDataForTile(0, TerrainDataTypes.TerrainType, cast_cell_2.x, cast_cell_2.y) != "Water"):
|
||||
|
||||
if (player.wouldCollideAt(newPosition)):
|
||||
return false
|
||||
return true
|
||||
else:
|
||||
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
||||
|
||||
@@ -3,3 +3,11 @@ extends Mob
|
||||
class_name Player
|
||||
|
||||
@export var camera:Camera2D
|
||||
|
||||
|
||||
func wouldCollideAt(destination):
|
||||
if (super.wouldCollideAt(destination)):
|
||||
#CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
@@ -2,6 +2,8 @@ extends Node2D
|
||||
|
||||
class_name Mob
|
||||
|
||||
@export var health:int = 100
|
||||
|
||||
@export var animator:AnimatedSprite2D
|
||||
|
||||
@export var collisionRay_1:RayCast2D
|
||||
@@ -77,6 +79,4 @@ func wouldCollideAt(destination):
|
||||
updateRaycasts(destination)
|
||||
|
||||
if collisionRay_1.is_colliding() || collisionRay_2.is_colliding():
|
||||
CommandDispatcher.DISPLAY_MESSAGE.emit("Your path is blocked.")
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user