60 lines
1.3 KiB
GDScript
60 lines
1.3 KiB
GDScript
extends TileMap
|
|
|
|
class_name Map
|
|
|
|
enum Direction { North, East, South, West }
|
|
|
|
@export var defaultPlayerStartPosition:Vector2i
|
|
@export var stepIncrement:float = 1.0
|
|
|
|
var player
|
|
|
|
func _ready():
|
|
CommandDispatcher.PLAYER_MOVE.connect(onPlayerMove)
|
|
CommandDispatcher.TOGGLE_TILEMAP_LAYER.connect(onToggleRequest)
|
|
|
|
|
|
@warning_ignore("unused_parameter")
|
|
func spawnPlayerAtPosition(newPosition, facing):
|
|
var spawnposition:Vector2i
|
|
|
|
if (newPosition == null):
|
|
spawnposition = defaultPlayerStartPosition
|
|
else:
|
|
spawnposition = newPosition
|
|
|
|
player.position = Vector2(spawnposition.x * 16, spawnposition.y * 16)
|
|
|
|
|
|
func onPlayerMove(direction):
|
|
var newPos = Vector2(player.position)
|
|
var moveIncrement = tile_set.tile_size.x * stepIncrement
|
|
|
|
match(direction):
|
|
Direction.North:
|
|
newPos.y -= moveIncrement
|
|
Direction.South:
|
|
newPos.y += moveIncrement
|
|
Direction.West:
|
|
newPos.x -= moveIncrement
|
|
Direction.East:
|
|
newPos.x += moveIncrement
|
|
|
|
if (playerCanMoveTo(newPos)):
|
|
player.position = newPos
|
|
player.updateAnimation(direction)
|
|
|
|
|
|
@warning_ignore("unused_parameter")
|
|
func playerCanMoveTo(newPosition) -> bool:
|
|
return false
|
|
|
|
|
|
func onToggleRequest(layerName):
|
|
for layer in range(get_layers_count()):
|
|
if(get_layer_name(layer) == layerName):
|
|
if(is_layer_enabled(layer)):
|
|
set_layer_enabled(layer, false)
|
|
else:
|
|
set_layer_enabled(layer, true)
|