diff --git a/scenes/assets/dreamer_body.tscn b/scenes/assets/dreamer_body.tscn index 3bf930d..47b4f70 100644 --- a/scenes/assets/dreamer_body.tscn +++ b/scenes/assets/dreamer_body.tscn @@ -3,50 +3,6 @@ [ext_resource type="Texture2D" uid="uid://dp3jbqmr5toth" path="res://textures/character-body.png" id="1_06ej8"] [ext_resource type="Texture2D" uid="uid://3ptkafoafq14" path="res://textures/character-leg.png" id="2_54k0m"] [ext_resource type="Texture2D" uid="uid://rgxhw23471ut" path="res://textures/character-arm.png" id="3_yptk5"] -[ext_resource type="Texture2D" uid="uid://bkthnj23dxsc4" path="res://textures/slash.png" id="4_ny5xw"] - -[sub_resource type="AtlasTexture" id="AtlasTexture_vtaks"] -atlas = ExtResource("4_ny5xw") -region = Rect2(0, 0, 48, 48) - -[sub_resource type="AtlasTexture" id="AtlasTexture_kvpfn"] -atlas = ExtResource("4_ny5xw") -region = Rect2(48, 0, 48, 48) - -[sub_resource type="AtlasTexture" id="AtlasTexture_dinhu"] -atlas = ExtResource("4_ny5xw") -region = Rect2(96, 0, 48, 48) - -[sub_resource type="AtlasTexture" id="AtlasTexture_kvuet"] -atlas = ExtResource("4_ny5xw") -region = Rect2(144, 0, 48, 48) - -[sub_resource type="AtlasTexture" id="AtlasTexture_trtic"] -atlas = ExtResource("4_ny5xw") -region = Rect2(192, 0, 48, 48) - -[sub_resource type="SpriteFrames" id="SpriteFrames_ir15t"] -animations = [{ -"frames": [{ -"duration": 1.0, -"texture": SubResource("AtlasTexture_vtaks") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_kvpfn") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_dinhu") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_kvuet") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_trtic") -}], -"loop": false, -"name": &"default", -"speed": 16.0 -}] [sub_resource type="Animation" id="Animation_gee14"] length = 0.001 @@ -637,16 +593,6 @@ texture_filter = 0 render_priority = -1 texture = ExtResource("3_yptk5") -[node name="Slash" type="AnimatedSprite3D" parent="Body/ArmPivot" unique_id=387297010] -transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, -0.1500001, 0) -pixel_size = 0.04 -no_depth_test = true -texture_filter = 0 -render_priority = 99 -sprite_frames = SubResource("SpriteFrames_ir15t") -frame = 4 -frame_progress = 1.0 - [node name="Animations" type="AnimationPlayer" parent="." unique_id=705651586] libraries/ = SubResource("AnimationLibrary_vtaks") diff --git a/scenes/effects/slash.tscn b/scenes/effects/slash.tscn new file mode 100644 index 0000000..4a58a82 --- /dev/null +++ b/scenes/effects/slash.tscn @@ -0,0 +1,58 @@ +[gd_scene format=3 uid="uid://eycadu74k5yx"] + +[ext_resource type="Texture2D" uid="uid://bkthnj23dxsc4" path="res://textures/slash.png" id="1_edkvd"] +[ext_resource type="Script" uid="uid://d26yt0riuggb4" path="res://scripts/effects/slash.gd" id="2_dcbvk"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_vtaks"] +atlas = ExtResource("1_edkvd") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kvpfn"] +atlas = ExtResource("1_edkvd") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dinhu"] +atlas = ExtResource("1_edkvd") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kvuet"] +atlas = ExtResource("1_edkvd") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_trtic"] +atlas = ExtResource("1_edkvd") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_ir15t"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_vtaks") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kvpfn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dinhu") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kvuet") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_trtic") +}], +"loop": false, +"name": &"default", +"speed": 16.0 +}] + +[node name="Slash" type="AnimatedSprite3D" unique_id=1787289120] +transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 0, 0) +pixel_size = 0.04 +no_depth_test = true +texture_filter = 0 +render_priority = 99 +sprite_frames = SubResource("SpriteFrames_ir15t") +frame = 4 +frame_progress = 1.0 +script = ExtResource("2_dcbvk") diff --git a/scripts/effects/slash.gd b/scripts/effects/slash.gd new file mode 100644 index 0000000..d5d99ec --- /dev/null +++ b/scripts/effects/slash.gd @@ -0,0 +1,9 @@ +extends AnimatedSprite3D + + +func play_effect(): + play("default") + + await animation_finished + + queue_free() diff --git a/scripts/effects/slash.gd.uid b/scripts/effects/slash.gd.uid new file mode 100644 index 0000000..e142904 --- /dev/null +++ b/scripts/effects/slash.gd.uid @@ -0,0 +1 @@ +uid://d26yt0riuggb4 diff --git a/scripts/global.gd b/scripts/global.gd index 2ea2539..76af2bf 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -1,5 +1,17 @@ extends Node const weapons = { - + "test_sword": { + "combo_weapon": true, + "hits_to_finish": 3, + "swing_time": 0.1, + "combo_timeout": 0.35, + "swing_time_combo_finish": 0.42, + "damage": 15, + "damage_mid_combo": 10, + + "knockback": 3.5, + "knockback_mid_combo": 0.25, + "stun_time": 0.4, + } } diff --git a/scripts/player.gd b/scripts/player.gd index 15eceaf..c1e98f2 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -13,6 +13,14 @@ var iframes = 0 var knockback_time = 0 var health = 100 +var combo_hits = 0 +var combo_timer = 0 +var swing_timer = 0 + +var queue_swing = false + +var current_weapon = "test_sword" + @onready var game = get_parent() @onready var camera = game.get_node("PlayerCamera") @@ -20,6 +28,16 @@ func hit_me(): iframes = 0.5 health -= 10 +func get_my_weapon_info(value: String): + return get_weapon_info(current_weapon, value) + +func get_weapon_info(weapon: String, value: String): + print(weapon, value) + if value in Global.weapons[weapon]: + print("YAYA", Global.weapons[weapon][value]) + return Global.weapons[weapon][value] + else: return null + func on_hit(hitter: Node3D = null) -> void: iframes = 0.8 @@ -56,10 +74,11 @@ func _physics_process(delta: float) -> void: $DreamerBody.rotation.y = face_rotation + deg_to_rad(180) else: $DreamerBody.rotation.y = face_rotation + + var mouse_point_angle = player_position.angle_to_point(get_viewport().get_mouse_position()) if combatable: - var mouse_point_angle = player_position.angle_to_point(get_viewport().get_mouse_position()) - $DreamerBody/Body/ArmPivot.rotation.z = mouse_point_angle + #$DreamerBody/Body/ArmPivot.rotation.z = mouse_point_angle $HitCollision.rotation.y = -mouse_point_angle + face_rotation if abs(rad_to_deg(mouse_point_angle) - (-90)) < 50: @@ -69,12 +88,11 @@ func _physics_process(delta: float) -> void: if (rad_to_deg(mouse_point_angle) < -90) or (rad_to_deg(mouse_point_angle) > 90): face_left = true - $DreamerBody/Body/ArmPivot.scale.y = -1 - $DreamerBody/Body/ArmPivot.scale.x = -1 + var mouse_pos = get_viewport().get_mouse_position() mouse_pos.y = (viewport_half.y) + ((viewport_half.y) - mouse_pos.y) - $DreamerBody/Body/ArmPivot.rotation.z = viewport_half.angle_to_point(mouse_pos) + #$DreamerBody/Body/ArmPivot.rotation.z = viewport_half.angle_to_point(mouse_pos) else: face_left = false $DreamerBody/Body/ArmPivot.scale.y = 1 @@ -95,29 +113,75 @@ func _physics_process(delta: float) -> void: face_left = false if input_dir.x < 0: face_left = true - - if Input.is_action_just_pressed("attack"): - $DreamerBody/Body/ArmPivot/Slash.play("default") - var hits = $HitCollision.get_overlapping_bodies() - - for body in hits: - if body == self: continue - if "health" in body: - body.health -= 10 - - body.position.y += 0.2 - body.velocity.y = 0.4 - body.velocity += global_position.direction_to(body.global_position) * 5 - - if body.velocity.length() > 5: - body.velocity = body.velocity.normalized() * 5 + if swing_timer > 0: swing_timer -= delta + if combo_timer > 0: + combo_timer -= delta + if combo_timer <= 0: + combo_hits = 0 + + if Input.is_action_just_pressed("attack") or queue_swing: + if swing_timer > 0: + if swing_timer < 0.1: + queue_swing = true + else: + queue_swing = false + + swing_timer = get_my_weapon_info("swing_time") + combo_timer = get_my_weapon_info("combo_timeout") + if swing_timer == null: swing_timer = 0.0 + if combo_timer == null: combo_timer = 0.0 + + combo_hits += 1 + + var slash = load("res://scenes/effects/slash.tscn").instantiate() + game.add_child(slash) + slash.global_position = global_position + slash.rotation.x = face_rotation + slash.rotation.z = -mouse_point_angle + deg_to_rad(180) + slash.play_effect() + + var hits = $HitCollision.get_overlapping_bodies() + + var knockback = 0 + var damage = 0 + + if get_my_weapon_info("combo_weapon"): + if combo_hits < get_my_weapon_info("hits_to_finish"): + damage = get_my_weapon_info("damage_mid_combo") + knockback = get_my_weapon_info("knockback_mid_combo") + else: + damage = get_my_weapon_info("damage") + knockback = get_my_weapon_info("knockback") - if "mid_knockback" in body: - body.mid_knockback = true + combo_hits = 0 - if "on_knockback" in body: - body.on_knockback() + swing_timer = get_my_weapon_info("swing_time_combo_finish") + if swing_timer == null: swing_timer = 0.0 + else: + damage = get_my_weapon_info("damage") + knockback = get_my_weapon_info("knockback") + + combo_hits = 0 + + for body in hits: + if body == self: continue + + if "health" in body: + body.health -= damage + + body.position.y += 0.2 + body.velocity.y = 0.4 + body.velocity += global_position.direction_to(body.global_position) * knockback + + if body.velocity.length() > knockback: + body.velocity = body.velocity.normalized() * knockback + + if "mid_knockback" in body: + body.mid_knockback = true + + if "on_knockback" in body: + body.on_knockback() var direction = (camera.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction and (knockback_time <= 0): diff --git a/scripts/slime.gd b/scripts/slime.gd index 82890b9..0e78c95 100644 --- a/scripts/slime.gd +++ b/scripts/slime.gd @@ -84,9 +84,6 @@ func _physics_process(delta: float) -> void: var viewport_half = (get_viewport().get_visible_rect().size / 2.0) var player_position = camera.unproject_position(global_transform.origin) - print(viewport_half) - print(player_position) - if face_left: $Body.rotation.y = face_rotation + deg_to_rad(180) else: diff --git a/textures/test-sword.png b/textures/test-sword.png index eda81be..4e81f6c 100644 Binary files a/textures/test-sword.png and b/textures/test-sword.png differ