mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-07 00:10:09 +01:00
1. Renamed `CELL_TYPES` enums to `CellType` 2. Fixed references, old: `turn_combat_system/actors/Actor.gd`, new: `turn_combat/combatants/Combatant.gd` 3. Fixed references, old: `turn_combat_system/actors/health/Health.tscn`, new: `turn_combat/combatants/health/Health.tscn` 4. Fixed bug in `grid_movement/pawns/Actor.gd` extending lowercase `pawn.gd`; changed to `Pawn.gd` 5. Renamed lowercase `grid_movement/pawns/actor.gd` to capital `Actor.gd` for consistency 6. Fixed some unused local variables warnings Other changes are from engine, after opening and saving all scenes.
45 lines
1.2 KiB
GDScript
45 lines
1.2 KiB
GDScript
extends 'Pawn.gd'
|
|
|
|
onready var Grid = get_parent()
|
|
var lost = false
|
|
|
|
func _ready():
|
|
update_look_direction(Vector2(1, 0))
|
|
|
|
func _process(delta):
|
|
var input_direction = get_input_direction()
|
|
if not input_direction:
|
|
return
|
|
update_look_direction(input_direction)
|
|
|
|
var target_position = Grid.request_move(self, input_direction)
|
|
if target_position:
|
|
move_to(target_position)
|
|
$Tween.start()
|
|
else:
|
|
bump()
|
|
|
|
func get_input_direction():
|
|
return Vector2(
|
|
int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")),
|
|
int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
|
|
)
|
|
|
|
func update_look_direction(direction):
|
|
$Pivot/Sprite.rotation = direction.angle()
|
|
|
|
func move_to(target_position):
|
|
set_process(false)
|
|
$AnimationPlayer.play("walk")
|
|
var move_direction = (position - target_position).normalized()
|
|
$Tween.interpolate_property($Pivot, "position", move_direction * 32, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
|
$Pivot/Sprite.position = position - target_position
|
|
position = target_position
|
|
|
|
yield($AnimationPlayer, "animation_finished")
|
|
|
|
set_process(true)
|
|
|
|
func bump():
|
|
$AnimationPlayer.play("bump")
|