File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ script = ExtResource("3_urblq")
24
24
position = Vector2 (-174 , 28 )
25
25
gridlayer = NodePath ("../../Tiles/Layer0" )
26
26
27
- [node name ="RealtimeTroll" parent ="TrollSpawner" instance =ExtResource ("2" )]
27
+ [node name ="RealtimeTroll" parent ="TrollSpawner" node_paths = PackedStringArray ( "gridlayer" ) instance =ExtResource ("2" )]
28
28
modulate = Color (1.5 , 1.5 , 1.5 , 1 )
29
29
position = Vector2 (3.81897 , -137.288 )
30
+ gridlayer = NodePath ("../../Tiles/Layer0" )
30
31
31
32
[node name ="CanvasLayer" type ="CanvasLayer" parent ="." ]
32
33
Original file line number Diff line number Diff line change @@ -5,17 +5,31 @@ const FRICTION_FACTOR = 0.89
5
5
const TAN30DEG = tan (deg_to_rad (30 ))
6
6
7
7
8
+ @export var gridlayer : TileMapLayer
9
+
10
+
8
11
func become_active_troll () -> void :
9
12
pass
10
13
11
14
12
15
func _physics_process (_delta : float ) -> void :
16
+ var prev_position := global_position
17
+
13
18
var motion := Vector2 ()
14
- motion .x = Input .get_axis (& "move_left" , & "move_right" )
15
- motion .y = Input .get_axis (& "move_up" , & "move_down" )
19
+ motion .x = Input .get_axis ("move_left" , "move_right" )
20
+ motion .y = Input .get_axis ("move_up" , "move_down" )
16
21
# Make diagonal movement fit for hexagonal tiles.
17
22
motion .y *= TAN30DEG
18
23
velocity += motion .normalized () * MOTION_SPEED
19
24
# Apply friction.
20
25
velocity *= FRICTION_FACTOR
21
26
move_and_slide ()
27
+
28
+
29
+ # Prevent movement off of the grid tiles. Alternatively, you could add a
30
+ # border tile around the outside of your world with physics enabled in the
31
+ # TileMapLayer. That would allow nice sliding along the walls of the world.
32
+ var dest_tile : int = gridlayer .get_world_tile (global_position )
33
+ var has_tile := dest_tile >= 0
34
+ if not has_tile :
35
+ global_position = prev_position
Original file line number Diff line number Diff line change @@ -10,19 +10,21 @@ radius = 16.0
10
10
script = ExtResource ("1" )
11
11
12
12
[node name ="Sprite2D" type ="Sprite2D" parent ="." ]
13
+ position = Vector2 (-3.74084 , -19.5 )
13
14
texture = ExtResource ("2" )
14
15
15
16
[node name ="Shadow" type ="Sprite2D" parent ="." ]
16
17
modulate = Color (0 , 0 , 0 , 0.501961 )
17
18
show_behind_parent = true
18
- position = Vector2 (16.4422 , 4.89438 )
19
+ position = Vector2 (12.7014 , -14.6056 )
19
20
scale = Vector2 (0.794259 , 1.04505 )
20
21
skew = 0.523599
21
22
texture = ExtResource ("2" )
22
23
23
24
[node name ="CollisionShape2D" type ="CollisionShape2D" parent ="." ]
24
- position = Vector2 (3.24216 , 19.453 )
25
+ position = Vector2 (-0.498685 , -0.0470009 )
25
26
shape = SubResource ("1" )
26
27
27
28
[node name ="Camera2D" type ="Camera2D" parent ="." ]
29
+ position = Vector2 (-3.74084 , -19.5 )
28
30
process_callback = 0
You can’t perform that action at this time.
0 commit comments