From b44ca800d348b3b0b1fc465d9537862f2bdab00f Mon Sep 17 00:00:00 2001 From: Nicholas Date: Sun, 18 May 2025 12:00:58 +0100 Subject: [PATCH] Added rock that detects mouse --- Rock.tscn | 24 ++++++++++++++++++++++++ project.godot | 5 +++++ rock.gd | 5 +++++ rock.gd.uid | 1 + rocks.png.import | 34 ++++++++++++++++++++++++++++++++++ startLevel.tscn | 8 ++++++-- 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 Rock.tscn create mode 100644 rock.gd create mode 100644 rock.gd.uid create mode 100644 rocks.png.import diff --git a/Rock.tscn b/Rock.tscn new file mode 100644 index 0000000..40e290f --- /dev/null +++ b/Rock.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=5 format=3 uid="uid://chpqjpcexhd3t"] + +[ext_resource type="Texture2D" uid="uid://8uv7dd4m5ne" path="res://rocks.png" id="1_6r1ml"] +[ext_resource type="Script" uid="uid://caa0o3l446c85" path="res://rock.gd" id="1_55vvm"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_55vvm"] +atlas = ExtResource("1_6r1ml") +region = Rect2(16.535, 15.865, 15.895, 17.055) + +[sub_resource type="CircleShape2D" id="CircleShape2D_55vvm"] +radius = 6.32456 + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_55vvm") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = SubResource("AtlasTexture_55vvm") + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource("CircleShape2D_55vvm") + +[connection signal="input_event" from="Area2D" to="." method="_on_area_2d_input_event"] diff --git a/project.godot b/project.godot index e64ee39..1561ca5 100644 --- a/project.godot +++ b/project.godot @@ -37,3 +37,8 @@ moveDown={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) ] } +Grab={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) +] +} diff --git a/rock.gd b/rock.gd new file mode 100644 index 0000000..5fd3670 --- /dev/null +++ b/rock.gd @@ -0,0 +1,5 @@ +extends Node2D + +func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void: + if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): + print("check") diff --git a/rock.gd.uid b/rock.gd.uid new file mode 100644 index 0000000..7e8667c --- /dev/null +++ b/rock.gd.uid @@ -0,0 +1 @@ +uid://caa0o3l446c85 diff --git a/rocks.png.import b/rocks.png.import new file mode 100644 index 0000000..9b1f450 --- /dev/null +++ b/rocks.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://8uv7dd4m5ne" +path="res://.godot/imported/rocks.png-f11897abd7424866675c3df5d51b470d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://rocks.png" +dest_files=["res://.godot/imported/rocks.png-f11897abd7424866675c3df5d51b470d.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/startLevel.tscn b/startLevel.tscn index d92a7ea..2d4a197 100644 --- a/startLevel.tscn +++ b/startLevel.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=4 format=4 uid="uid://ccjb75bercbw8"] +[gd_scene load_steps=5 format=4 uid="uid://ccjb75bercbw8"] [ext_resource type="TileSet" uid="uid://xnedi1edel2b" path="res://tileMaps/baseTileset.tres" id="1_a7uaa"] [ext_resource type="PackedScene" uid="uid://c1xy5bf2p6vmh" path="res://player.tscn" id="2_lsvd3"] [ext_resource type="PackedScene" uid="uid://darxbklsgh23m" path="res://collectableCrystal.tscn" id="3_x45i2"] +[ext_resource type="PackedScene" uid="uid://chpqjpcexhd3t" path="res://Rock.tscn" id="4_0dbve"] -[node name="Node2D" type="Node2D"] +[node name="Rock" type="Node2D"] [node name="wallLayer" type="TileMapLayer" parent="."] z_index = 10 @@ -22,3 +23,6 @@ position = Vector2(373, 125) [node name="Area2D" parent="." instance=ExtResource("3_x45i2")] position = Vector2(401, 240) + +[node name="Node2D" parent="." instance=ExtResource("4_0dbve")] +position = Vector2(498, 169)