Skip to content

Commit

Permalink
add collisionlayers to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathaneeckhout committed Oct 31, 2023
1 parent 3161ea2 commit 84cf581
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions scenes/enemies/MoldedDruvar/MoldedDruvar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ var movement_multiplier := 1.0


func _init():
super()
enemy_class = "MoldedDruvar"
1 change: 1 addition & 0 deletions scenes/enemies/Sheep/Sheep.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ var movement_multiplier := 1.0


func _init():
super()
enemy_class = "Sheep"
19 changes: 18 additions & 1 deletion scenes/enemies/Sheep/Sheep.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[gd_scene load_steps=21 format=3 uid="uid://dfq5lb87meq6q"]
[gd_scene load_steps=25 format=3 uid="uid://dfq5lb87meq6q"]

[ext_resource type="Script" path="res://scenes/enemies/Sheep/Sheep.gd" id="1_6p7b5"]
[ext_resource type="Texture2D" uid="uid://dvpbmkvp7ppqm" path="res://assets/images/enemies/sheep/sheep.png" id="2_57cp7"]
[ext_resource type="PackedScene" uid="uid://kb8mhtyak1ki" path="res://scripts/components/watchersynchronizercomponent/WatcherSynchronizerComponent.tscn" id="2_nxh3l"]
[ext_resource type="PackedScene" uid="uid://8t6nwakq6im5" path="res://scenes/templates/JInterface/JInterface.tscn" id="3_jxmll"]
[ext_resource type="PackedScene" uid="uid://c5tliladmodux" path="res://scripts/components/positionsynchronizercomponent/PositionSynchronizerComponent.tscn" id="3_umoon"]
[ext_resource type="PackedScene" uid="uid://bkd384iloxu7f" path="res://scripts/components/actionsynchronizercomponent/ActionSynchronizerComponent.tscn" id="4_dsad5"]
[ext_resource type="PackedScene" uid="uid://c8cji8g03ayyx" path="res://scripts/components/statssynchronizercomponent/StatsSynchronizerComponent.tscn" id="5_ho1ox"]
[ext_resource type="Script" path="res://addons/beehave/nodes/beehave_tree.gd" id="5_yme22"]
[ext_resource type="Script" path="res://addons/beehave/nodes/composites/sequence.gd" id="7_bkydl"]
[ext_resource type="Script" path="res://addons/beehave/nodes/composites/selector_reactive.gd" id="7_hnfbx"]
Expand Down Expand Up @@ -197,6 +201,19 @@ motion_mode = 1
wall_min_slide_angle = 0.0
script = ExtResource("1_6p7b5")

[node name="WatcherSynchronizerComponent" parent="." instance=ExtResource("2_nxh3l")]

[node name="PositionSynchronizerComponent" parent="." node_paths=PackedStringArray("watcher_synchronizer") instance=ExtResource("3_umoon")]
watcher_synchronizer = NodePath("../WatcherSynchronizerComponent")

[node name="ActionSynchronizerComponent" parent="." node_paths=PackedStringArray("watcher_synchronizer") instance=ExtResource("4_dsad5")]
watcher_synchronizer = NodePath("../WatcherSynchronizerComponent")

[node name="StatsSynchronizerComponent" parent="." node_paths=PackedStringArray("watcher_synchronizer") instance=ExtResource("5_ho1ox")]
watcher_synchronizer = NodePath("../WatcherSynchronizerComponent")
hp_max = 20
movement_speed = 50.0

[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.1, 0.1)
texture = ExtResource("2_57cp7")
Expand Down
1 change: 1 addition & 0 deletions scenes/enemies/TreeTrunkGuy/TreeTrunkGuy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ var movement_multiplier := 1.0


func _init():
super()
enemy_class = "TreeTrunkGuy"
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func _on_got_hurt(from: String, _hp: int, _damage: int):
reset_timer.start()
if target == null:
start_combat = true
target = get_node("/root/Root/World/JEntities/JPlayers/" + from)
target = J.world.players.get_node(from)


func _reset(actor: Node):
Expand Down
1 change: 1 addition & 0 deletions scenes/npcs/milklady/Milklady.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extends NPC


func _init():
super()
npc_class = "MilkLady"


Expand Down
6 changes: 6 additions & 0 deletions scenes/npcs/milklady/Milklady.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -512,31 +512,37 @@ texture = ExtResource("2_yblp5")

[node name="MilkladyRightArm" type="Sprite2D" parent="Sprites"]
position = Vector2(-60, -410)
scale = Vector2(1, 1)
texture = ExtResource("7_f60ad")
offset = Vector2(137, -61.5)

[node name="MilkladyBody" type="Sprite2D" parent="Sprites"]
position = Vector2(30, -200)
scale = Vector2(1, 1)
texture = ExtResource("3_cyqqs")
offset = Vector2(47.0001, -271.5)

[node name="MilkladyHead" type="Sprite2D" parent="Sprites"]
position = Vector2(0, -430)
scale = Vector2(1, 1)
texture = ExtResource("4_0w10x")
offset = Vector2(77.0001, -41.5)

[node name="MilkladyRightFoot" type="Sprite2D" parent="Sprites"]
position = Vector2(-30, -20)
scale = Vector2(1, 1)
texture = ExtResource("8_xp8pl")
offset = Vector2(107, -451.5)

[node name="MilkladyLeftFoot" type="Sprite2D" parent="Sprites"]
position = Vector2(220, -20)
scale = Vector2(1, 1)
texture = ExtResource("6_ba0nm")
offset = Vector2(-133, -451.5)

[node name="MilkladyLeftArm" type="Sprite2D" parent="Sprites"]
position = Vector2(170, -390)
scale = Vector2(1, 1)
texture = ExtResource("5_1mf1y")
offset = Vector2(-92.9999, -101.5)

Expand Down
10 changes: 10 additions & 0 deletions scenes/player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ var network_view_synchronizer: NetworkViewSynchronizerComponent = $NetworkViewSy
"LeftHand": $Sprites/LeftHand.texture
}

func _init():
collision_layer = J.PHYSICS_LAYER_PLAYERS

if J.is_server():
# The player cannot walk past NPCs and enemies. But other players cannot block their path.
collision_mask = J.PHYSICS_LAYER_WORLD + J.PHYSICS_LAYER_ENEMIES + J.PHYSICS_LAYER_NPCS
else:
# Don't handle collision on client side
collision_mask = 0


func _ready():
# Server and Client's common code
Expand Down
11 changes: 11 additions & 0 deletions scripts/classes/Enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ class_name Enemy

var entity_type: J.ENTITY_TYPE = J.ENTITY_TYPE.ENEMY
var enemy_class: String = ""


func _init():
collision_layer = J.PHYSICS_LAYER_ENEMIES

if J.is_server():
# Enemies can be blocked by NPCs and players.
collision_mask = J.PHYSICS_LAYER_WORLD + J.PHYSICS_LAYER_PLAYERS + J.PHYSICS_LAYER_NPCS
else:
# Don't handle collision on client side
collision_mask = 0
11 changes: 11 additions & 0 deletions scripts/classes/NPC.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ class_name NPC

var entity_type: J.ENTITY_TYPE = J.ENTITY_TYPE.NPC
var npc_class: String = ""


func _init():
collision_layer = J.PHYSICS_LAYER_NPCS

if J.is_server():
# NPCs cannot be stopped by any entity.
collision_mask = J.PHYSICS_LAYER_WORLD
else:
# Don't handle collision on client side
collision_mask = 0
2 changes: 1 addition & 1 deletion scripts/classes/World.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func _ready():
add_child(synced_entities)

players = Node2D.new()
players.name = "JPlayers"
players.name = "Players"
players.y_sort_enabled = true
synced_entities.add_child(players)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ var server_buffer: Array[Dictionary] = []
func _ready():
target_node = get_parent()

if target_node.get("peer_id") == null:
J.logger.error("target_node does not have the peer_id variable")
return

# Physics only needed on client side
if J.is_server():
set_physics_process(false)
Expand Down Expand Up @@ -112,6 +108,10 @@ func sync_respawn():


func sync_experience(from: String, current_exp: int, amount: int):
if target_node.get("peer_id") == null:
J.logger.error("target_node does not have the peer_id variable")
return

var timestamp: float = Time.get_unix_time_from_system()

# Experience is only synced towards the player
Expand Down

0 comments on commit 84cf581

Please sign in to comment.