Skip to content

Commit 49a01d6

Browse files
committed
Update grid based movement demo
1 parent ff10a80 commit 49a01d6

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

2d/grid_based_movement/grid/grid.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends TileMap
22

3-
enum CellType { EMPTY = -1, ACTOR, OBSTACLE, OBJECT}
3+
enum CellType { EMPTY = -1, ACTOR, OBSTACLE, OBJECT }
44

55
func _ready():
66
for child in get_children():

2d/grid_based_movement/pawns/Actor.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,3 @@ position = Vector2( 1.43051e-06, -1.90735e-06 )
8282
texture = ExtResource( 2 )
8383
centered = false
8484
offset = Vector2( -32, -32 )
85-

2d/grid_based_movement/pawns/actor.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
extends "pawn.gd"
22

3-
onready var Grid = get_parent()
3+
onready var grid = get_parent()
44

55
func _ready():
6-
update_look_direction(Vector2(1, 0))
6+
update_look_direction(Vector2.RIGHT)
77

88

99
func _process(_delta):
@@ -12,7 +12,7 @@ func _process(_delta):
1212
return
1313
update_look_direction(input_direction)
1414

15-
var target_position = Grid.request_move(self, input_direction)
15+
var target_position = grid.request_move(self, input_direction)
1616
if target_position:
1717
move_to(target_position)
1818
else:
@@ -21,8 +21,8 @@ func _process(_delta):
2121

2222
func get_input_direction():
2323
return Vector2(
24-
int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")),
25-
int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
24+
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
25+
Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
2626
)
2727

2828

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extends Node2D
22

33
enum CellType { ACTOR, OBSTACLE, OBJECT }
4+
#warning-ignore:unused_class_variable
45
export(CellType) var type = CellType.ACTOR

2d/grid_based_movement/project.godot

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,41 @@ window/size/height=720
2626
window/stretch/mode="2d"
2727
window/stretch/aspect="expand"
2828

29+
[input]
30+
31+
move_right={
32+
"deadzone": 0.5,
33+
"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)
34+
, 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)
35+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
36+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
37+
]
38+
}
39+
move_left={
40+
"deadzone": 0.5,
41+
"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)
42+
, 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)
43+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
44+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
45+
]
46+
}
47+
move_down={
48+
"deadzone": 0.5,
49+
"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)
50+
, 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)
51+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
52+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
53+
]
54+
}
55+
move_up={
56+
"deadzone": 0.5,
57+
"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)
58+
, 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)
59+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
60+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
61+
]
62+
}
63+
2964
[rendering]
3065

3166
environment/default_environment="res://default_env.tres"

2d/grid_based_movement/tilesets/grid/GridTiles.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ texture = ExtResource( 2 )
1717
[node name="Object" type="Sprite" parent="."]
1818
position = Vector2( 160, 32 )
1919
texture = ExtResource( 3 )
20-

2d/grid_based_movement/tilesets/grid_lines/GridLinesTiles.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
[node name="Grass" type="Sprite" parent="."]
88
position = Vector2( 32, 32 )
99
texture = ExtResource( 1 )
10-

0 commit comments

Comments
 (0)