mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 06:09:46 +03:00
Fix pawn direction code, add EMPTY constant to grid
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
[ext_resource path="res://pawns/sprites/character_grey.png" type="Texture" id=6]
|
||||
[ext_resource path="res://pawns/sprites/star.png" type="Texture" id=7]
|
||||
|
||||
[node name="Game" type="Node" index="0"]
|
||||
[node name="Game" type="Node"]
|
||||
|
||||
[node name="Grass" type="TileMap" parent="." index="0"]
|
||||
[node name="GridLines" type="TileMap" parent="." index="0"]
|
||||
|
||||
modulate = Color( 1, 1, 1, 0.271059 )
|
||||
z_index = -1
|
||||
@@ -95,81 +95,5 @@ type = 2
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object2" type="Node2D" parent="Grid" index="3"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 800, 416 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object2" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object3" type="Node2D" parent="Grid" index="4"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 800, 288 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object3" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object4" type="Node2D" parent="Grid" index="5"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 672, 288 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object4" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object5" type="Node2D" parent="Grid" index="6"]
|
||||
|
||||
position = Vector2( 672, 544 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object5" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object6" type="Node2D" parent="Grid" index="7"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 352, 480 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object6" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object7" type="Node2D" parent="Grid" index="8"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 352, 352 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object7" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
[node name="Object8" type="Node2D" parent="Grid" index="9"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 480, 544 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object8" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
|
||||
[editable path="Grid/Actor"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends TileMap
|
||||
|
||||
enum CELL_TYPES { ACTOR, OBSTACLE, OBJECT }
|
||||
enum CELL_TYPES { EMPTY = -1, ACTOR, OBSTACLE, OBJECT}
|
||||
|
||||
func _ready():
|
||||
for child in get_children():
|
||||
@@ -19,7 +19,7 @@ func request_move(pawn, direction):
|
||||
|
||||
var cell_target_type = get_cellv(cell_target)
|
||||
match cell_target_type:
|
||||
-1:
|
||||
EMPTY:
|
||||
return update_pawn_position(pawn, cell_start, cell_target)
|
||||
OBJECT:
|
||||
var object_pawn = get_cell_pawn(cell_target)
|
||||
@@ -32,5 +32,5 @@ func request_move(pawn, direction):
|
||||
|
||||
func update_pawn_position(pawn, cell_start, cell_target):
|
||||
set_cellv(cell_target, pawn.type)
|
||||
set_cellv(cell_start, -1)
|
||||
set_cellv(cell_start, EMPTY)
|
||||
return map_to_world(cell_target) + cell_size / 2
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[ext_resource path="res://pawns/actor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://pawns/sprites/character.png" type="Texture" id=2]
|
||||
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
|
||||
resource_name = "bump"
|
||||
@@ -103,6 +102,7 @@ _sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Pivot" index="0"]
|
||||
|
||||
position = Vector2( 1.43051e-06, -1.90735e-06 )
|
||||
texture = ExtResource( 2 )
|
||||
centered = false
|
||||
offset = Vector2( -32, -32 )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extends 'pawn.gd'
|
||||
extends "pawn.gd"
|
||||
|
||||
onready var Grid = get_parent()
|
||||
|
||||
@@ -15,7 +15,6 @@ func _process(delta):
|
||||
var target_position = Grid.request_move(self, input_direction)
|
||||
if target_position:
|
||||
move_to(target_position)
|
||||
$Tween.start()
|
||||
else:
|
||||
bump()
|
||||
|
||||
@@ -34,11 +33,16 @@ func update_look_direction(direction):
|
||||
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
|
||||
|
||||
# Move the node to the target cell instantly,
|
||||
# and animate the sprite moving from the start to the target cell
|
||||
var move_direction = (target_position - position).normalized()
|
||||
$Tween.interpolate_property($Pivot, "position", - move_direction * 32, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
position = target_position
|
||||
|
||||
|
||||
$Tween.start()
|
||||
|
||||
# Stop the function execution until the animation finished
|
||||
yield($AnimationPlayer, "animation_finished")
|
||||
|
||||
set_process(true)
|
||||
|
||||
Reference in New Issue
Block a user