From 2c512d5764bdd6ac5aa51a730dd5802a2cda062d Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Fri, 15 Aug 2025 13:33:08 +1000 Subject: [PATCH] smaller map, eating apples, death --- assets/apple.png | Bin 0 -> 530 bytes assets/apple.png.import | 34 ++++++++++++++++++++++++++++++++++ assets/smallMap.png | Bin 0 -> 372 bytes assets/smallMap.png.import | 34 ++++++++++++++++++++++++++++++++++ braincell.gd | 12 ++++++------ camera_2d.gd | 2 +- prefabs/apple.tscn | 15 +++++++++++++++ prefabs/snake_segment.gd | 10 ++++++++++ prefabs/snake_segment.tscn | 12 +++++++++++- prefabs/wall.tscn | 9 +++++++++ project.godot | 5 +++++ test.tscn | 32 +++++++++++++++++++++++++++----- 12 files changed, 152 insertions(+), 13 deletions(-) create mode 100644 assets/apple.png create mode 100644 assets/apple.png.import create mode 100644 assets/smallMap.png create mode 100644 assets/smallMap.png.import create mode 100644 prefabs/apple.tscn create mode 100644 prefabs/wall.tscn diff --git a/assets/apple.png b/assets/apple.png new file mode 100644 index 0000000000000000000000000000000000000000..64335a3be45b1e424aa2b6a69c7e78d0381e33fa GIT binary patch literal 530 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij?1AIbUOhLUB*-uLKNv7bc{95K zg*Xd5B8wRq_zr_G*AN9$JwrVU>C9Iv zfNHj-MtG)qdTKFn06DA-QjDw&j6jwb5KBYZARlNjGK0mLfNVoXCI$f@9RM5`Y+_A4a2D$^Z<53G56kKotf?#s-WFAf|$Jur7d@GzG{80Vbe1OkkBkmKH!3 zRF|QF0Z4XrgQ9ToJPQpVv)9wbF~q|E>Lf$40}33@j;p`h7dbWuJ>42>Wx{;%iG9qH zUkmgZ7I|-DJaWb^hVi9lWs+R#)~;aV7QO{{j;#EB=IrN-Q_i|GI@_hXY~L&I!XYAS z?x5*akx;uZmqCyzww~E((f9nu28a9uZV~nktrCA(S^`)OA1x4kx&E+&N|C$klUMa? gUKDkHu?%?4sl7>9Y|5$zYmg&7UHx3vIVCg!0LWK}N&o-= literal 0 HcmV?d00001 diff --git a/assets/apple.png.import b/assets/apple.png.import new file mode 100644 index 0000000..9e91e2e --- /dev/null +++ b/assets/apple.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dmmdu0ayhmlnk" +path="res://.godot/imported/apple.png-d0c5a0e024efc439723035186c67a74a.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/apple.png" +dest_files=["res://.godot/imported/apple.png-d0c5a0e024efc439723035186c67a74a.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/assets/smallMap.png b/assets/smallMap.png new file mode 100644 index 0000000000000000000000000000000000000000..c24d86913d8a1c09b637e34f188ac173b426de95 GIT binary patch literal 372 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V6Od#Ihk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS0%1l`4X*~EphSslL`iUdT1k0gQ7S_~VrE{6o}X)of~lUN zo`rPgs}(>s+fpMu(>y)37&w3&Rt70XRt82O%L|C5p=^+AG#Ht|;vn}JGBPm;0O=?o z&TMA^i)R7ZAn>V-k>Le1f=08H0Vp+roq+|Y(!j{rfN=rDRFI9V3m_&<0kT1W31}`8 zSY?o<1&{^RWoTdkl0B0rR^t`?LI%iG_H=O!(FjgHvnNJvnexY1r?}Us2+LV2oNRID g^WY1<8y?5Nu void: # Add the gravity. - if not is_on_floor(): - velocity += get_gravity() * delta - - # Handle jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY + #if not is_on_floor(): + #velocity += get_gravity() * delta +# + ## Handle jump. + #if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + #velocity.y = JUMP_VELOCITY # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. diff --git a/camera_2d.gd b/camera_2d.gd index ac35fb3..6ca87f3 100644 --- a/camera_2d.gd +++ b/camera_2d.gd @@ -27,7 +27,7 @@ func _process(delta: float) -> void: snake_line.z_index = 9 else: position = Vector2(0,0) - zoom = Vector2(0.05,0.05) + zoom = Vector2(0.1,0.1) snake_line.modulate = Color(1,1,1,1) snake_line.z_index = 11 z_index = 1 diff --git a/prefabs/apple.tscn b/prefabs/apple.tscn new file mode 100644 index 0000000..5c6310d --- /dev/null +++ b/prefabs/apple.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://qpjwodeafyno"] + +[ext_resource type="Texture2D" uid="uid://dmmdu0ayhmlnk" path="res://assets/apple.png" id="1_sblxh"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_5v1qd"] +radius = 50.0 + +[node name="Apple" type="Area2D" groups=["apple"]] + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(10, 10) +texture = ExtResource("1_sblxh") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_5v1qd") diff --git a/prefabs/snake_segment.gd b/prefabs/snake_segment.gd index ebeefcf..60e1c31 100644 --- a/prefabs/snake_segment.gd +++ b/prefabs/snake_segment.gd @@ -61,3 +61,13 @@ func become_fake(): #modulate = Color.DIM_GRAY #collision_layer = 2 pass + + +func _on_eat_die_box_area_entered(area: Area2D) -> void: + if(area.is_in_group("apple")): + area.queue_free() + print("mmm tasty apple") + if(area.is_in_group("wall")): + print("i die") + get_tree().get_root().process_mode = Node.PROCESS_MODE_DISABLED + diff --git a/prefabs/snake_segment.tscn b/prefabs/snake_segment.tscn index dafddc1..ba1afbc 100644 --- a/prefabs/snake_segment.tscn +++ b/prefabs/snake_segment.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://bwoeu7ask0fck"] +[gd_scene load_steps=8 format=3 uid="uid://bwoeu7ask0fck"] [ext_resource type="Script" uid="uid://b5cqo12km1nh3" path="res://prefabs/snake_segment.gd" id="1_3ulhv"] [ext_resource type="Texture2D" uid="uid://l8x3dp68yyxr" path="res://assets/segement.png" id="1_6uqch"] @@ -9,6 +9,9 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_08kyq"] size = Vector2(8, 64) +[sub_resource type="CircleShape2D" id="CircleShape2D_08kyq"] +radius = 50.0 + [node name="SnakeSegment" type="AnimatableBody2D" node_paths=PackedStringArray("door")] script = ExtResource("1_3ulhv") door = NodePath("DoorArm") @@ -49,3 +52,10 @@ shape = SubResource("RectangleShape2D_08kyq") [node name="Sprite2D" type="Sprite2D" parent="DoorArm/Door"] texture = ExtResource("4_34t3n") + +[node name="EatDieBox" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="EatDieBox"] +shape = SubResource("CircleShape2D_08kyq") + +[connection signal="area_entered" from="EatDieBox" to="." method="_on_eat_die_box_area_entered"] diff --git a/prefabs/wall.tscn b/prefabs/wall.tscn new file mode 100644 index 0000000..03dd534 --- /dev/null +++ b/prefabs/wall.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=2 format=3 uid="uid://bl5py87o1qbgr"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_iy8pp"] +size = Vector2(6400, 320) + +[node name="Wall" type="Area2D" groups=["wall"]] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_iy8pp") diff --git a/project.godot b/project.godot index a7d64c6..64d186b 100644 --- a/project.godot +++ b/project.godot @@ -29,6 +29,11 @@ window/stretch/mode="canvas_items" enabled=PackedStringArray("res://addons/godot-donut-collision-polygon-2d-7780d026ae3d4a37fe68f43cc1f97ba664dd775d/addons/donut_collision_polygon2D/plugin.cfg") +[global_group] + +apple="" +wall="" + [input] left={ diff --git a/test.tscn b/test.tscn index 584d897..e2ef8c5 100644 --- a/test.tscn +++ b/test.tscn @@ -1,22 +1,24 @@ -[gd_scene load_steps=6 format=3 uid="uid://daqqurdrnk61h"] +[gd_scene load_steps=8 format=3 uid="uid://daqqurdrnk61h"] [ext_resource type="Script" uid="uid://bue4xxejdsmqh" path="res://snakeManager.gd" id="1_6uqi0"] [ext_resource type="PackedScene" uid="uid://bwoeu7ask0fck" path="res://prefabs/snake_segment.tscn" id="1_8uh7m"] -[ext_resource type="Texture2D" uid="uid://byibhn8fi6ve0" path="res://assets/bg.png" id="1_ppyta"] +[ext_resource type="Texture2D" uid="uid://b1sese4p8sck3" path="res://assets/smallMap.png" id="1_vbegm"] [ext_resource type="PackedScene" uid="uid://cusdydgg4b1bo" path="res://prefabs/braincell.tscn" id="2_6uqi0"] [ext_resource type="Script" uid="uid://b0djy8fmq4qjq" path="res://camera_2d.gd" id="5_ykrsh"] +[ext_resource type="PackedScene" uid="uid://qpjwodeafyno" path="res://prefabs/apple.tscn" id="6_g14j6"] +[ext_resource type="PackedScene" uid="uid://bl5py87o1qbgr" path="res://prefabs/wall.tscn" id="7_vbegm"] [node name="Node2D" type="Node2D"] [node name="Sprite2D" type="Sprite2D" parent="."] position = Vector2(-160, -160) scale = Vector2(320, 320) -texture = ExtResource("1_ppyta") +texture = ExtResource("1_vbegm") [node name="Snake" type="Node2D" parent="." node_paths=PackedStringArray("segements_holder", "snake_line", "player")] script = ExtResource("1_6uqi0") segements_holder = NodePath("SegementHolder") -SNAKE_SPEED = 0.3 +SNAKE_SPEED = 0.6 snake_line = NodePath("Line2D") player = NodePath("SegementHolder/SnakeSegment/Braincell") @@ -43,7 +45,27 @@ begin_cap_mode = 2 end_cap_mode = 2 [node name="Camera2D" type="Camera2D" parent="." node_paths=PackedStringArray("snake_line", "player")] -zoom = Vector2(0.05, 0.05) +zoom = Vector2(0.1, 0.1) script = ExtResource("5_ykrsh") snake_line = NodePath("../Snake/Line2D") player = NodePath("../Snake/SegementHolder/SnakeSegment/Braincell") + +[node name="Apple" parent="." instance=ExtResource("6_g14j6")] +position = Vector2(1276, -954) + +[node name="Apple2" parent="." instance=ExtResource("6_g14j6")] +position = Vector2(960, 1280) + +[node name="Wall" parent="." instance=ExtResource("7_vbegm")] +position = Vector2(-160, -1920) + +[node name="Wall2" parent="." instance=ExtResource("7_vbegm")] +position = Vector2(-160, 1600) + +[node name="Wall3" parent="." instance=ExtResource("7_vbegm")] +position = Vector2(-1920, -160) +rotation = 1.5708 + +[node name="Wall4" parent="." instance=ExtResource("7_vbegm")] +position = Vector2(1600, -160) +rotation = 1.5708