Skip to content

Commit

Permalink
Merge pull request #113 from nezvers/player_spawn_and_rooms
Browse files Browse the repository at this point in the history
remove last dependencies on Mover2D
  • Loading branch information
nezvers authored Oct 30, 2024
2 parents 2d7e2c2 + f9581e3 commit e3554fc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions addons/top_down/scenes/actors/actor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ libraries = {
"": SubResource("AnimationLibrary_tbujk")
}

[node name="MoverTopDown2D" type="Node2D" parent="." node_paths=PackedStringArray("character", "resource_node")]
[node name="MoverTopDown2D" type="Node" parent="." node_paths=PackedStringArray("character", "resource_node")]
script = ExtResource("5_3rf64")
character = NodePath("..")
axis_multiplier_resource = ExtResource("14_7u4bv")
Expand All @@ -275,9 +275,9 @@ resource_node = NodePath("../ResourceNode")
script = ExtResource("14_gnke1")
resource_node = NodePath("../ResourceNode")

[node name="SpriteFlip" type="Node" parent="." node_paths=PackedStringArray("mover_2d", "flip_node")]
[node name="SpriteFlip" type="Node" parent="." node_paths=PackedStringArray("resource_node", "flip_node")]
script = ExtResource("8_7uvby")
mover_2d = NodePath("../MoverTopDown2D")
resource_node = NodePath("../ResourceNode")
flip_node = NodePath("../Body")

[node name="CharacterStates" type="Node" parent="." node_paths=PackedStringArray("resource_node", "animation_player")]
Expand Down
1 change: 1 addition & 0 deletions addons/top_down/scenes/actors/ai/enemy_ai.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enabled = false
collision_mask = 9

[node name="TileNavigationGetter" type="Line2D" parent="."]
visible = false
width = 1.0
script = ExtResource("2_kpufw")
astargrid_resource = ExtResource("3_54ctl")
Expand Down
5 changes: 3 additions & 2 deletions addons/top_down/scenes/actors/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ dead_vfx_scene = ExtResource("8_s8ofx")
[node name="ItemDrop" parent="." index="12"]
asset_list = SubResource("Resource_ahfgc")

[node name="PlayerInput" type="Node" parent="." index="13" node_paths=PackedStringArray("mover")]
[node name="PlayerInput" type="Node" parent="." index="13" node_paths=PackedStringArray("position_node", "resource_node")]
script = ExtResource("4_uihqc")
mover = NodePath("../MoverTopDown2D")
position_node = NodePath("..")
aim_offset = Vector2(0, 8)
resource_node = NodePath("../ResourceNode")

[node name="WeaponManager" type="Node2D" parent="." index="14" node_paths=PackedStringArray("resource_node")]
script = ExtResource("9_hpc12")
Expand Down
2 changes: 1 addition & 1 deletion addons/top_down/scripts/actor/MoverTopDown2D.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class_name MoverTopDown2D
extends Node2D
extends Node

## Way to disable functionality at _ready
@export var enabled:bool = true
Expand Down
18 changes: 11 additions & 7 deletions addons/top_down/scripts/actor/PlayerInput.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ class_name PlayerInput
extends Node

@export var enabled:bool = true
@export var mover:MoverTopDown2D
## Used for getting mouse local position
@export var position_node:Node2D
## Offset aim to the body to shoot at shadow collider (feet position)
@export var aim_offset:Vector2
@export var resource_node:ResourceNode

var input_resource:InputResource

func set_enabled(value:bool)->void:
enabled = value
set_physics_process(enabled)

func _ready()->void:
input_resource = resource_node.get_resource("input")
# Read input before mover
process_physics_priority -= 1
set_enabled(enabled)
Expand All @@ -21,18 +25,18 @@ func _physics_process(_delta:float)->void:
var axis:Vector2 = Vector2(Input.get_axis("move_left", "move_right"), Input.get_axis("move_up", "move_down"))
if axis.length() > 1.0:
axis = axis.normalized()
mover.input_resource.set_axis(axis)
input_resource.set_axis(axis)

# Aiming
var aim_direction:Vector2 = mover.get_local_mouse_position() + aim_offset
mover.input_resource.set_aim_direction(aim_direction.normalized())
var aim_direction:Vector2 = position_node.get_local_mouse_position() + aim_offset
input_resource.set_aim_direction(aim_direction.normalized())

# Shooting
mover.input_resource.set_action(Input.is_action_pressed("shoot"))
input_resource.set_action(Input.is_action_pressed("shoot"))

var weapon_switch_dir:int = int(Input.is_action_just_released("weapon_up")) - int(Input.is_action_just_released("weapon_down"))
if weapon_switch_dir != 0:
mover.input_resource.set_switch_weapon(weapon_switch_dir)
input_resource.set_switch_weapon(weapon_switch_dir)

# Dashing
mover.input_resource.set_action_2(Input.is_action_pressed("dash"))
input_resource.set_action_2(Input.is_action_pressed("dash"))
10 changes: 7 additions & 3 deletions addons/top_down/scripts/actor/SpriteFlip.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class_name SpriteFlip
extends Node

@export var mover_2d:MoverTopDown2D
@export var resource_node:ResourceNode
## Node that is used for flipping visuals horizontally
@export var flip_node:Node2D

Expand All @@ -11,14 +11,18 @@ enum FlipType {WALK_DIR, AIM_DIR}

## 1 = Right, -1 = Left
var dir:int = 1
var input_resource:InputResource

func _ready()->void:
input_resource = resource_node.get_resource("input")

func _process(_delta:float)->void:
var new_dir:int
match flip_type:
FlipType.WALK_DIR:
new_dir = sign(mover_2d.input_resource.axis.x)
new_dir = sign(input_resource.axis.x)
FlipType.AIM_DIR:
new_dir = sign(mover_2d.input_resource.aim_direction.x)
new_dir = sign(input_resource.aim_direction.x)

if new_dir == 0:
return
Expand Down

0 comments on commit e3554fc

Please sign in to comment.