Skip to content

Commit

Permalink
Added basic cut the tree objective
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanNgo committed Oct 5, 2024
1 parent cc41527 commit df728a8
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 109 deletions.
4 changes: 3 additions & 1 deletion source/characters/archer/archer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ hframes = 7
vframes = 2

[node name="ArcherSeparatedSprites" type="Node2D" parent="Sprites"]
visible = false

[node name="ArcherBodySprites" type="Sprite2D" parent="Sprites/ArcherSeparatedSprites"]
rotation = -0.00152653
Expand All @@ -249,7 +250,8 @@ script = ExtResource("5_omhwb")
_sprites = Array[Resource]([ExtResource("3_cyl8l"), ExtResource("10_7r3y7")])

[node name="Hitboxes" type="Node2D" parent="." node_paths=PackedStringArray("hitboxes")]
position = Vector2(-0.0488489, -32)
position = Vector2(-0.048849, -32)
scale = Vector2(1, 1)
script = ExtResource("7_ltp0r")
hitboxes = [NodePath("BodyHitbox")]

Expand Down
2 changes: 1 addition & 1 deletion source/characters/player_body/player_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ extends Area2D
signal player_area_hit(attacker_player_id: int)


func hit(attacker_player_id: int) -> void:
func hit(attacker_player_id: int, _is_projectile: bool) -> void:
player_area_hit.emit(attacker_player_id)
4 changes: 2 additions & 2 deletions source/levels/level_arena/level_arena.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ func _ready() -> void:
MultiplayerLobby.player_connected.connect(_on_player_connected)


func _on_other_player_areas_hit_from_player(attacker_player_id: int, player_areas: Array[Area2D]) -> void:
func _on_other_player_areas_hit_from_player(attacker_player_id: int, player_areas: Array[Area2D], is_projectile: bool) -> void:
for player_area in player_areas:
player_area.hit(attacker_player_id)
player_area.hit(attacker_player_id, is_projectile)


func create_player(peer_id: int):
Expand Down
2 changes: 1 addition & 1 deletion source/levels/level_arena/level_arena.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://source/levels/level_arena/level_arena.gd" id="1_7s657"]
[ext_resource type="PackedScene" uid="uid://th5a5353c0q0" path="res://source/player/player.tscn" id="2_ugal2"]
[ext_resource type="PackedScene" uid="uid://cokb2q5ky857y" path="res://source/levels/level_arena/map/map.tscn" id="3_xp6ot"]
[ext_resource type="PackedScene" uid="uid://crgkfpyuuyip" path="res://source/objective_items/tree.tscn" id="4_l7sth"]
[ext_resource type="PackedScene" uid="uid://crgkfpyuuyip" path="res://source/objective_items/tree/tree.tscn" id="4_l7sth"]

[node name="LevelArena" type="Node2D" node_paths=PackedStringArray("_players", "_player_spawn_points")]
y_sort_enabled = true
Expand Down
7 changes: 7 additions & 0 deletions source/objective_items/objective_area.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Area2D

signal objective_area_hit(attacker_player_id: int, is_projectile: bool)


func hit(attacker_player_id: int, is_projectile: bool) -> void:
objective_area_hit.emit(attacker_player_id, is_projectile)
8 changes: 0 additions & 8 deletions source/objective_items/tree.gd

This file was deleted.

89 changes: 0 additions & 89 deletions source/objective_items/tree.tscn

This file was deleted.

54 changes: 54 additions & 0 deletions source/objective_items/tree/tree.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
extends Node2D


@export var _animation_player: AnimationPlayer
@export var _tree_area: Area2D

@export var health := 100

var is_hit: = false


func _ready() -> void:
print(is_multiplayer_authority())
if not is_multiplayer_authority():
return

_animation_player.animation_finished.connect(_on_animation_finished)
_tree_area.objective_area_hit.connect(_on_objective_area_hit)


func _process(_delta: float) -> void:
if not is_multiplayer_authority():
return

if not is_hit:
_animation_player.play("idle")
elif health <= 0:
_animation_player.play("cut")
else:
_animation_player.play("hit")


func hit():
if health > 0:
is_hit = true
health -= 1


func _on_animation_finished(animation_name: String):
if animation_name == "hit":
is_hit = false
_animation_player.play("idle")


func _on_objective_area_hit(attacker_player_id: int, is_projectile: bool):
var attacker: Node2D = PlayerRegistry.get_player(attacker_player_id)

if attacker.current_player_body != attacker.get_player_body(attacker.characters.WARRIOR):
return

if is_projectile:
return

hit()
140 changes: 140 additions & 0 deletions source/objective_items/tree/tree.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
[gd_scene load_steps=12 format=3 uid="uid://crgkfpyuuyip"]

[ext_resource type="Script" path="res://source/objective_items/tree/tree.gd" id="1_2ix33"]
[ext_resource type="Texture2D" uid="uid://4e2k6yydqv61" path="res://assets/Resources/Trees/Tree.png" id="1_htgnl"]
[ext_resource type="Script" path="res://source/objective_items/objective_area.gd" id="3_ecupt"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_tflww"]
size = Vector2(32, 16)

[sub_resource type="Animation" id="Animation_yc620"]
resource_name = "idle"
length = 0.40001
step = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TreeSprites:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3]
}

[sub_resource type="Animation" id="Animation_74xt2"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TreeSprites:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("TreeSprites:frame_coords")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [Vector2i(0, 1)]
}

[sub_resource type="Animation" id="Animation_ncvla"]
resource_name = "hit"
length = 0.20001
step = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TreeSprites:frame_coords")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [Vector2i(0, 1), Vector2i(1, 1)]
}

[sub_resource type="Animation" id="Animation_5kjuk"]
resource_name = "cut"
step = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("TreeSprites:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [8]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_2ofb1"]
_data = {
"RESET": SubResource("Animation_74xt2"),
"cut": SubResource("Animation_5kjuk"),
"hit": SubResource("Animation_ncvla"),
"idle": SubResource("Animation_yc620")
}

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_34dmq"]
radius = 16.0
height = 48.0

[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_w87bk"]
properties/0/path = NodePath("AnimationPlayer:active")
properties/0/spawn = true
properties/0/replication_mode = 1
properties/1/path = NodePath("AnimationPlayer:current_animation")
properties/1/spawn = true
properties/1/replication_mode = 1

[node name="Tree" type="Node2D" node_paths=PackedStringArray("_animation_player", "_tree_area")]
y_sort_enabled = true
script = ExtResource("1_2ix33")
_animation_player = NodePath("AnimationPlayer")
_tree_area = NodePath("ObjectiveArea")

[node name="NavigationBody" type="StaticBody2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="NavigationBody"]
shape = SubResource("RectangleShape2D_tflww")

[node name="TreeSprites" type="Sprite2D" parent="."]
texture = ExtResource("1_htgnl")
offset = Vector2(0, -72)
hframes = 4
vframes = 3
frame = 4

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_2ofb1")
}

[node name="ObjectiveArea" type="Area2D" parent="."]
collision_layer = 6
collision_mask = 0
script = ExtResource("3_ecupt")

[node name="CollisionShape2D" type="CollisionShape2D" parent="ObjectiveArea"]
position = Vector2(0, -16)
shape = SubResource("CapsuleShape2D_34dmq")

[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_w87bk")
Loading

0 comments on commit df728a8

Please sign in to comment.