From 62e90b444315245ef24606fa51d3fccba5f18e08 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 28 Sep 2024 15:29:16 +0200 Subject: initial commit --- Player/Assets/arrow.kra | Bin 0 -> 32160 bytes Player/Assets/arrow.kra~ | Bin 0 -> 31971 bytes Player/Assets/arrow.png | Bin 0 -> 170 bytes Player/Assets/arrow.png.import | 34 ++++++++++++++++ Player/Assets/arrow.png~ | Bin 0 -> 165 bytes Player/Assets/bow.kra | Bin 0 -> 32879 bytes Player/Assets/bow.kra~ | Bin 0 -> 32897 bytes Player/Assets/bow.png | Bin 0 -> 202 bytes Player/Assets/bow.png.import | 34 ++++++++++++++++ Player/Assets/bow.png~ | Bin 0 -> 226 bytes Player/arrow.gd | 27 +++++++++++++ Player/arrow.tscn | 35 +++++++++++++++++ Player/arrow_head_shape.tres | 4 ++ Player/bow.gd | 86 +++++++++++++++++++++++++++++++++++++++++ Player/bow.tscn | 20 ++++++++++ Player/target_line.gd | 26 +++++++++++++ 16 files changed, 266 insertions(+) create mode 100644 Player/Assets/arrow.kra create mode 100644 Player/Assets/arrow.kra~ create mode 100644 Player/Assets/arrow.png create mode 100644 Player/Assets/arrow.png.import create mode 100644 Player/Assets/arrow.png~ create mode 100644 Player/Assets/bow.kra create mode 100644 Player/Assets/bow.kra~ create mode 100644 Player/Assets/bow.png create mode 100644 Player/Assets/bow.png.import create mode 100644 Player/Assets/bow.png~ create mode 100644 Player/arrow.gd create mode 100644 Player/arrow.tscn create mode 100644 Player/arrow_head_shape.tres create mode 100644 Player/bow.gd create mode 100644 Player/bow.tscn create mode 100644 Player/target_line.gd (limited to 'Player') diff --git a/Player/Assets/arrow.kra b/Player/Assets/arrow.kra new file mode 100644 index 0000000..57ca2a8 Binary files /dev/null and b/Player/Assets/arrow.kra differ diff --git a/Player/Assets/arrow.kra~ b/Player/Assets/arrow.kra~ new file mode 100644 index 0000000..376471d Binary files /dev/null and b/Player/Assets/arrow.kra~ differ diff --git a/Player/Assets/arrow.png b/Player/Assets/arrow.png new file mode 100644 index 0000000..4e71ad9 Binary files /dev/null and b/Player/Assets/arrow.png differ diff --git a/Player/Assets/arrow.png.import b/Player/Assets/arrow.png.import new file mode 100644 index 0000000..0c475ca --- /dev/null +++ b/Player/Assets/arrow.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b6mkb436giuns" +path="res://.godot/imported/arrow.png-a9f919cad48f96a83e2a88829bb8141c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Player/Assets/arrow.png" +dest_files=["res://.godot/imported/arrow.png-a9f919cad48f96a83e2a88829bb8141c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Player/Assets/arrow.png~ b/Player/Assets/arrow.png~ new file mode 100644 index 0000000..bc6209b Binary files /dev/null and b/Player/Assets/arrow.png~ differ diff --git a/Player/Assets/bow.kra b/Player/Assets/bow.kra new file mode 100644 index 0000000..c08370d Binary files /dev/null and b/Player/Assets/bow.kra differ diff --git a/Player/Assets/bow.kra~ b/Player/Assets/bow.kra~ new file mode 100644 index 0000000..ce0934a Binary files /dev/null and b/Player/Assets/bow.kra~ differ diff --git a/Player/Assets/bow.png b/Player/Assets/bow.png new file mode 100644 index 0000000..c315267 Binary files /dev/null and b/Player/Assets/bow.png differ diff --git a/Player/Assets/bow.png.import b/Player/Assets/bow.png.import new file mode 100644 index 0000000..bd33d5d --- /dev/null +++ b/Player/Assets/bow.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://e0214m2jyp81" +path="res://.godot/imported/bow.png-8d7cdf3a1d17167a06b6f444c5720069.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Player/Assets/bow.png" +dest_files=["res://.godot/imported/bow.png-8d7cdf3a1d17167a06b6f444c5720069.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Player/Assets/bow.png~ b/Player/Assets/bow.png~ new file mode 100644 index 0000000..00ee2d9 Binary files /dev/null and b/Player/Assets/bow.png~ differ diff --git a/Player/arrow.gd b/Player/arrow.gd new file mode 100644 index 0000000..f6cce57 --- /dev/null +++ b/Player/arrow.gd @@ -0,0 +1,27 @@ +extends CharacterBody2D + + +var deacceleration := 10.0 +var flying := false + + +func _ready(): + if OS.has_feature("mobile"): + scale = Vector2(2, 2) + + +func _physics_process(delta: float) -> void: + velocity = velocity.move_toward(Vector2.ZERO, deacceleration * delta) + + if abs(velocity) > Vector2.ZERO: + flying = true + $ArrowHead/CollisionShape2D.disabled = false + + if flying and velocity == Vector2.ZERO: + queue_free() + + move_and_slide() + + +func _on_visible_on_screen_notifier_2d_screen_exited() -> void: + queue_free() diff --git a/Player/arrow.tscn b/Player/arrow.tscn new file mode 100644 index 0000000..a9f7c98 --- /dev/null +++ b/Player/arrow.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=4 format=3 uid="uid://ctkfjrwg171fr"] + +[ext_resource type="Texture2D" uid="uid://b6mkb436giuns" path="res://Player/Assets/arrow.png" id="1_1lalc"] +[ext_resource type="Script" path="res://Player/arrow.gd" id="1_q6ess"] +[ext_resource type="Shape2D" uid="uid://vny1lmq7xr3s" path="res://Player/arrow_head_shape.tres" id="3_b2q2f"] + +[node name="Arrow" type="CharacterBody2D"] +z_index = 1 +collision_layer = 0 +collision_mask = 8 +script = ExtResource("1_q6ess") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +rotation = -3.14159 +texture = ExtResource("1_1lalc") + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +position = Vector2(-7.15256e-07, -3.27826e-07) +scale = Vector2(0.8, 0.5) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-4.5, 0) +shape = ExtResource("3_b2q2f") + +[node name="ArrowHead" type="Area2D" parent="." groups=["arrow"]] +collision_layer = 2 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="ArrowHead"] +position = Vector2(-4.5, 0) +shape = ExtResource("3_b2q2f") +disabled = true + +[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/Player/arrow_head_shape.tres b/Player/arrow_head_shape.tres new file mode 100644 index 0000000..0c29169 --- /dev/null +++ b/Player/arrow_head_shape.tres @@ -0,0 +1,4 @@ +[gd_resource type="RectangleShape2D" format=3 uid="uid://vny1lmq7xr3s"] + +[resource] +size = Vector2(3, 4) diff --git a/Player/bow.gd b/Player/bow.gd new file mode 100644 index 0000000..aa3fafc --- /dev/null +++ b/Player/bow.gd @@ -0,0 +1,86 @@ +extends Node2D + + +var anchor := Vector2.ZERO +var anchor_mode := false +var drag_distance := Vector2.ZERO +var max_length := 75.0 + +var arrow_scene = preload("res://Player/arrow.tscn") +var arrow: Node2D + +var process_touch := false + + +func _ready() -> void: + if OS.has_feature("mobile"): + scale = Vector2(2, 2) + + $DrawLine.visible = false + $TargetLine.visible = false + + +func _input(event: InputEvent) -> void: + if event is InputEventScreenTouch: + if event.is_pressed(): + process_touch = true + elif event.is_released(): + process_touch = false + + +func _process(_delta: float) -> void: + if Input.is_action_just_pressed("click"): + global_position = get_global_mouse_position() + anchor = get_global_mouse_position() + anchor_mode = true + + arrow = arrow_scene.instantiate() + arrow.global_position = global_position + + get_tree().current_scene.add_child(arrow) + $DrawLine.visible = true + + $TargetLine.visible = true + $TargetLine.origin = anchor + $TargetLine.queue_redraw() + + elif Input.is_action_just_released("click"): + anchor_mode = false + + arrow.velocity = -drag_distance * 1.5 + arrow.flying = true + arrow = null + + $DrawLine.visible = false + $DrawLine.clear_points() + + $TargetLine.visible = false + $TargetLine.queue_redraw() + + elif Input.is_action_pressed("click"): + drag_distance = get_global_mouse_position() - anchor + rotation = atan2(drag_distance.y, drag_distance.x) + + var max_distance = get_global_mouse_position() + if drag_distance.length() > max_length: + drag_distance = (max_length / drag_distance.length()) * drag_distance + max_distance = anchor + drag_distance + + $DrawLine.clear_points() + $DrawLine.add_point(Vector2.ZERO) + $DrawLine.add_point((max_distance - global_position) / scale) + $DrawLine.rotation = -rotation + + $TargetLine.direction = (max_distance - global_position).normalized() * -1 + $TargetLine.rotation = -rotation + $TargetLine.queue_redraw() + + if not anchor_mode: + if OS.has_feature("mobile"): + if process_touch: + global_position = get_global_mouse_position() + else: + global_position = get_global_mouse_position() + + if is_instance_valid(arrow): + arrow.rotation = rotation diff --git a/Player/bow.tscn b/Player/bow.tscn new file mode 100644 index 0000000..e1ec9da --- /dev/null +++ b/Player/bow.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=3 uid="uid://bn0h50n6fr6n1"] + +[ext_resource type="Texture2D" uid="uid://e0214m2jyp81" path="res://Player/Assets/bow.png" id="1_7j25w"] +[ext_resource type="Script" path="res://Player/bow.gd" id="1_f5b6e"] +[ext_resource type="Script" path="res://Player/target_line.gd" id="3_r056j"] + +[node name="Bow" type="Node2D"] +z_index = 1 +script = ExtResource("1_f5b6e") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +texture = ExtResource("1_7j25w") + +[node name="DrawLine" type="Line2D" parent="."] +width = 1.0 + +[node name="TargetLine" type="Node2D" parent="."] +script = ExtResource("3_r056j") +color = Color(0.464322, 0.282893, 0, 1) diff --git a/Player/target_line.gd b/Player/target_line.gd new file mode 100644 index 0000000..8a321af --- /dev/null +++ b/Player/target_line.gd @@ -0,0 +1,26 @@ +extends Node2D + + +@export var direction := Vector2.ZERO +@export var origin := Vector2.ZERO +@export var spacing_factor := 15 +@export var color := Color("#ffa500") + + +func _draw() -> void: + var target_direction = direction * (get_viewport_rect().size).length() + var points = target_direction.length() / spacing_factor + var fraction = (target_direction / points) + for point in range(points): + color.a = 1.0 / clamp(log(point), 1.0, 10.0) + draw_circle( + (point + 1) * fraction, + 1.0, + color + ) + draw_circle( + (point + 1) * fraction, + 1.0, + Color(1.0, 1.0, 1.0, color.a), + false + ) -- cgit v1.2.3