Update grid based movement demo

This commit is contained in:
Aaron Franke
2020-02-02 21:43:09 -05:00
parent ff10a807d0
commit 49a01d6f87
7 changed files with 42 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
extends TileMap
enum CellType { EMPTY = -1, ACTOR, OBSTACLE, OBJECT}
enum CellType { EMPTY = -1, ACTOR, OBSTACLE, OBJECT }
func _ready():
for child in get_children():

View File

@@ -82,4 +82,3 @@ position = Vector2( 1.43051e-06, -1.90735e-06 )
texture = ExtResource( 2 )
centered = false
offset = Vector2( -32, -32 )

View File

@@ -1,9 +1,9 @@
extends "pawn.gd"
onready var Grid = get_parent()
onready var grid = get_parent()
func _ready():
update_look_direction(Vector2(1, 0))
update_look_direction(Vector2.RIGHT)
func _process(_delta):
@@ -12,7 +12,7 @@ func _process(_delta):
return
update_look_direction(input_direction)
var target_position = Grid.request_move(self, input_direction)
var target_position = grid.request_move(self, input_direction)
if target_position:
move_to(target_position)
else:
@@ -21,8 +21,8 @@ func _process(_delta):
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"))
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
)

View File

@@ -1,4 +1,5 @@
extends Node2D
enum CellType { ACTOR, OBSTACLE, OBJECT }
#warning-ignore:unused_class_variable
export(CellType) var type = CellType.ACTOR

View File

@@ -26,6 +26,41 @@ window/size/height=720
window/stretch/mode="2d"
window/stretch/aspect="expand"
[input]
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
[rendering]
environment/default_environment="res://default_env.tres"

View File

@@ -17,4 +17,3 @@ texture = ExtResource( 2 )
[node name="Object" type="Sprite" parent="."]
position = Vector2( 160, 32 )
texture = ExtResource( 3 )

View File

@@ -7,4 +7,3 @@
[node name="Grass" type="Sprite" parent="."]
position = Vector2( 32, 32 )
texture = ExtResource( 1 )