diff --git a/Cargo.toml b/Cargo.toml index a7892f8..68d56b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "2" members = [ "dodge-the-creeps/rust", "hot-reload/rust", + "squash-the-creeps/rust" ] # Note about Jetbrains IDEs: "IDE Sync" (Refresh Cargo projects) may cause static analysis errors such as diff --git a/squash-the-creeps/godot/.godot/extension_list.cfg b/squash-the-creeps/godot/.godot/extension_list.cfg new file mode 100644 index 0000000..e6cba92 --- /dev/null +++ b/squash-the-creeps/godot/.godot/extension_list.cfg @@ -0,0 +1 @@ +res://rust.gdextension diff --git a/squash-the-creeps/godot/art/House In a Forest Loop.ogg b/squash-the-creeps/godot/art/House In a Forest Loop.ogg new file mode 100644 index 0000000..ece3640 Binary files /dev/null and b/squash-the-creeps/godot/art/House In a Forest Loop.ogg differ diff --git a/squash-the-creeps/godot/art/body.material b/squash-the-creeps/godot/art/body.material new file mode 100644 index 0000000..b48a9a6 Binary files /dev/null and b/squash-the-creeps/godot/art/body.material differ diff --git a/squash-the-creeps/godot/art/eye.material b/squash-the-creeps/godot/art/eye.material new file mode 100644 index 0000000..cc5c787 Binary files /dev/null and b/squash-the-creeps/godot/art/eye.material differ diff --git a/squash-the-creeps/godot/art/mob.glb b/squash-the-creeps/godot/art/mob.glb new file mode 100644 index 0000000..82cded4 Binary files /dev/null and b/squash-the-creeps/godot/art/mob.glb differ diff --git a/squash-the-creeps/godot/art/mob_body.material b/squash-the-creeps/godot/art/mob_body.material new file mode 100644 index 0000000..78cc1e3 Binary files /dev/null and b/squash-the-creeps/godot/art/mob_body.material differ diff --git a/squash-the-creeps/godot/art/mob_eye.material b/squash-the-creeps/godot/art/mob_eye.material new file mode 100644 index 0000000..cb88f4f Binary files /dev/null and b/squash-the-creeps/godot/art/mob_eye.material differ diff --git a/squash-the-creeps/godot/art/player.glb b/squash-the-creeps/godot/art/player.glb new file mode 100644 index 0000000..9ba67bc Binary files /dev/null and b/squash-the-creeps/godot/art/player.glb differ diff --git a/squash-the-creeps/godot/art/pupil.material b/squash-the-creeps/godot/art/pupil.material new file mode 100644 index 0000000..6bb04fa Binary files /dev/null and b/squash-the-creeps/godot/art/pupil.material differ diff --git a/squash-the-creeps/godot/default_bus_layout.tres b/squash-the-creeps/godot/default_bus_layout.tres new file mode 100644 index 0000000..eb4accc --- /dev/null +++ b/squash-the-creeps/godot/default_bus_layout.tres @@ -0,0 +1,3 @@ +[gd_resource type="AudioBusLayout" format=2] + +[resource] diff --git a/squash-the-creeps/godot/default_env.tres b/squash-the-creeps/godot/default_env.tres new file mode 100644 index 0000000..b5f71ae --- /dev/null +++ b/squash-the-creeps/godot/default_env.tres @@ -0,0 +1,4 @@ +[gd_resource type="Environment" format=2] + +[resource] +ambient_light_color = Color( 0.341176, 0.341176, 0.466667, 1 ) diff --git a/squash-the-creeps/godot/fonts/LICENSE.txt b/squash-the-creeps/godot/fonts/LICENSE.txt new file mode 100644 index 0000000..399aae6 --- /dev/null +++ b/squash-the-creeps/godot/fonts/LICENSE.txt @@ -0,0 +1,43 @@ +Copyright 2011 The Montserrat Project Authors (https://github.com/JulietaUla/Montserrat) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + +—————————————————————————————- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +—————————————————————————————- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. + +DEFINITIONS +“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. + +“Reserved Font Name” refers to any names specified as such after the copyright statement(s). + +“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s). + +“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. + +“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/squash-the-creeps/godot/fonts/Montserrat-Medium.ttf b/squash-the-creeps/godot/fonts/Montserrat-Medium.ttf new file mode 100644 index 0000000..db5b1af Binary files /dev/null and b/squash-the-creeps/godot/fonts/Montserrat-Medium.ttf differ diff --git a/squash-the-creeps/godot/icon.png b/squash-the-creeps/godot/icon.png new file mode 100644 index 0000000..e0af83e Binary files /dev/null and b/squash-the-creeps/godot/icon.png differ diff --git a/squash-the-creeps/godot/main.tscn b/squash-the-creeps/godot/main.tscn new file mode 100644 index 0000000..8dadda1 --- /dev/null +++ b/squash-the-creeps/godot/main.tscn @@ -0,0 +1,135 @@ +[gd_scene load_steps=10 format=3 uid="uid://b70g8epauqibi"] + +[ext_resource type="PackedScene" uid="uid://d0jx5lcbm76jf" path="res://mob.tscn" id="1_h2yge"] +[ext_resource type="PackedScene" uid="uid://bvlv4saytitbk" path="res://player.tscn" id="1_ig7tw"] +[ext_resource type="FontFile" uid="uid://dl270v4sovdki" path="res://fonts/Montserrat-Medium.ttf" id="2_0xm2m"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"] +size = Vector3(60, 2, 60) + +[sub_resource type="BoxMesh" id="BoxMesh_ig7tw"] +size = Vector3(60, 2, 60) + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig7tw"] +albedo_color = Color(0.937816, 0, 0.125279, 1) + +[sub_resource type="CylinderMesh" id="CylinderMesh_0xm2m"] +material = SubResource("StandardMaterial3D_ig7tw") + +[sub_resource type="Curve3D" id="Curve3D_ig7tw"] +closed = true +_data = { +"points": PackedVector3Array(0, 0, 0, 0, 0, 0, -14.9857, 0, -14.0101, 0, 0, 0, 0, 0, 0, 12.0963, 0, -14.9296, 0, 0, 0, 0, 0, 0, 16.9048, 0, 18.8654, 0, 0, 0, 0, 0, 0, -16.1414, 0, 20.7598), +"tilts": PackedFloat32Array(0, 0, 0, 0) +} +point_count = 4 + +[sub_resource type="Theme" id="Theme_h2yge"] +default_font = ExtResource("2_0xm2m") +default_font_size = 22 + +[node name="Main" type="MainScene"] +mob_scene = ExtResource("1_h2yge") + +[node name="Ground" type="StaticBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0) +collision_layer = 4 +collision_mask = 0 +metadata/_edit_group_ = true + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Ground"] +shape = SubResource("BoxShape3D_7dm0k") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"] +mesh = SubResource("BoxMesh_ig7tw") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(0.25, -0.476727, 0.842752, -0.0669873, 0.85979, 0.506236, -0.965926, -0.183013, 0.183013, 0, 23, 0) +light_energy = 2.293 +light_specular = 2.455 +shadow_enabled = true +directional_shadow_blend_splits = true + +[node name="Player" parent="." instance=ExtResource("1_ig7tw")] + +[node name="Marker3D" type="Marker3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 5, 0) + +[node name="Camera3D" type="Camera3D" parent="Marker3D"] +transform = Transform3D(1, 0, 0, 0, 1, -2.98023e-08, 0, 2.98023e-08, 1, 0, -5, 19) +projection = 1 +current = true +size = 19.19 + +[node name="Cylinders" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18, 0, -14) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Cylinders"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0, 0) +mesh = SubResource("CylinderMesh_0xm2m") + +[node name="MeshInstance3D2" type="MeshInstance3D" parent="Cylinders"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 35) +mesh = SubResource("CylinderMesh_0xm2m") + +[node name="MeshInstance3D3" type="MeshInstance3D" parent="Cylinders"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 35, 0, 33) +mesh = SubResource("CylinderMesh_0xm2m") + +[node name="MeshInstance3D4" type="MeshInstance3D" parent="Cylinders"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 30, 0, -1) +mesh = SubResource("CylinderMesh_0xm2m") + +[node name="SpawnPath" type="Path3D" parent="."] +curve = SubResource("Curve3D_ig7tw") + +[node name="SpawnLocation" type="PathFollow3D" parent="SpawnPath"] +transform = Transform3D(0.0339328, 0, -0.999424, 0, 1, 0, 0.999424, 0, 0.0339328, -14.9857, 0, -14.0101) + +[node name="MobTimer" type="Timer" parent="."] +wait_time = 0.5 +autostart = true + +[node name="UserInterface" type="UserInterface" parent="."] +physics_interpolation_mode = 0 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = SubResource("Theme_h2yge") + +[node name="ScoreLabel" type="Label" parent="UserInterface"] +layout_mode = 0 +offset_left = 37.0 +offset_top = 45.0 +offset_right = 98.0 +offset_bottom = 68.0 +theme_override_colors/font_color = Color(0, 0, 0, 1) +text = "Score: 0" + +[node name="Retry" type="ColorRect" parent="UserInterface"] +layout_mode = 0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.0705882, 0.121569, 0.152941, 0.380392) + +[node name="Label" type="Label" parent="UserInterface/Retry"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -92.5 +offset_top = -14.0 +offset_right = 92.5 +offset_bottom = 14.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "Press enter retry" + +[connection signal="hit" from="Player" to="." method="on_player_hit"] +[connection signal="timeout" from="MobTimer" to="." method="on_mob_timer_timeout"] diff --git a/squash-the-creeps/godot/mob.tscn b/squash-the-creeps/godot/mob.tscn new file mode 100644 index 0000000..b9f9fdd --- /dev/null +++ b/squash-the-creeps/godot/mob.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=5 format=3 uid="uid://d0jx5lcbm76jf"] + +[ext_resource type="PackedScene" uid="uid://or56hj80wrrn" path="res://art/mob.glb" id="1_dy6sc"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_nokgg"] +size = Vector3(1.40546, 1.45325, 1.70323) + +[sub_resource type="Animation" id="Animation_dy6sc"] +resource_name = "float" +length = 1.2 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Pivot/Character:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0.3, 0.7), +"transitions": PackedFloat32Array(0.482968, 2), +"update": 0, +"values": [Vector3(0, 0, 0), Vector3(0, 0.65, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Pivot/Character:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0.1, 0.5), +"transitions": PackedFloat32Array(0.267943, 1.62451), +"update": 0, +"values": [Vector3(0, 0, 0), Vector3(0.139626, 0, 0)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_nokgg"] +_data = { +&"float": SubResource("Animation_dy6sc") +} + +[node name="Mob" type="Mob" groups=["mob"]] +min_speed = 10.0 +max_speed = 18.0 +collision_layer = 2 +collision_mask = 0 + +[node name="Pivot" type="Node3D" parent="."] + +[node name="Character" parent="Pivot" instance=ExtResource("1_dy6sc")] +transform = Transform3D(1, 0, 0, 0, 0.99963, -0.0272248, 0, 0.0272248, 0.99963, 0, 0.396094, 0) + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0510979, 0.226624, -0.0277531) +shape = SubResource("BoxShape3D_nokgg") + +[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="."] +transform = Transform3D(1.55638, 0, 0, 0, 1, 0, 0, 0, 1.86618, 0, 0, 0) +visible = false +aabb = AABB(-0.857277, -1, -1.03447, 1.71455, 2, 2.06894) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +&"": SubResource("AnimationLibrary_nokgg") +} +autoplay = "float" + +[connection signal="screen_exited" from="VisibleOnScreenNotifier3D" to="." method="on_visible_on_screen_notifier_3d_screen_exited"] diff --git a/squash-the-creeps/godot/music_player.tscn b/squash-the-creeps/godot/music_player.tscn new file mode 100644 index 0000000..2fa0b37 --- /dev/null +++ b/squash-the-creeps/godot/music_player.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://bjvmnxjbg7sfm"] + +[ext_resource type="AudioStream" uid="uid://de3ihy6kdsw2x" path="res://art/House In a Forest Loop.ogg" id="1_fvyft"] + +[node name="MusicPlayer" type="AudioStreamPlayer"] +stream = ExtResource("1_fvyft") +autoplay = true diff --git a/squash-the-creeps/godot/player.tscn b/squash-the-creeps/godot/player.tscn new file mode 100644 index 0000000..9b24e40 --- /dev/null +++ b/squash-the-creeps/godot/player.tscn @@ -0,0 +1,105 @@ +[gd_scene load_steps=7 format=3 uid="uid://bvlv4saytitbk"] + +[ext_resource type="PackedScene" uid="uid://ddyx1ju3dch3p" path="res://art/player.glb" id="1_4flbx"] + +[sub_resource type="SphereShape3D" id="SphereShape3D_onrkg"] +radius = 0.8 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_4flbx"] +height = 0.264771 +radius = 1.01904 + +[sub_resource type="Animation" id="Animation_onrkg"] +resource_name = "RESET" +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Pivot/Character:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 0, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Pivot/Character:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 0, 0)] +} + +[sub_resource type="Animation" id="Animation_4flbx"] +resource_name = "float" +length = 1.2 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Pivot/Character:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0.3, 0.7), +"transitions": PackedFloat32Array(0.482968, 2), +"update": 0, +"values": [Vector3(0, 0, 0), Vector3(0, 0.65, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Pivot/Character:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0.1, 0.5), +"transitions": PackedFloat32Array(0.267943, 1.62451), +"update": 0, +"values": [Vector3(0, 0, 0), Vector3(0.139626, 0, 0)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_i3pqv"] +_data = { +&"RESET": SubResource("Animation_onrkg"), +&"float": SubResource("Animation_4flbx") +} + +[node name="Player" type="Player"] +speed = 14.0 +jump_impulse = 20.0 +bounce_impulse = 16.0 +fall_acceleration = 75.0 +collision_mask = 6 + +[node name="Pivot" type="Node3D" parent="."] + +[node name="Character" parent="Pivot" instance=ExtResource("1_4flbx")] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.806328, 0) +shape = SubResource("SphereShape3D_onrkg") + +[node name="MobDetector" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 2 +monitorable = false + +[node name="CollisionShape3D" type="CollisionShape3D" parent="MobDetector"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.76011, 0) +shape = SubResource("CylinderShape3D_4flbx") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +&"": SubResource("AnimationLibrary_i3pqv") +} +autoplay = "float" + +[connection signal="body_entered" from="MobDetector" to="." method="on_mob_detector_body_entered"] diff --git a/squash-the-creeps/godot/project.godot b/squash-the-creeps/godot/project.godot new file mode 100644 index 0000000..9fd9f5a --- /dev/null +++ b/squash-the-creeps/godot/project.godot @@ -0,0 +1,74 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="Squash the Creeps (3D)" +run/main_scene="uid://b70g8epauqibi" +config/features=PackedStringArray("4.4") +config/icon="res://icon.png" + +[autoload] + +MusicPlayer="*res://music_player.tscn" + +[display] + +window/size/viewport_width=720 +window/size/viewport_height=540 + +[input] + +move_left={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, 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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) +] +} +move_right={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) +] +} +move_forward={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, 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":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +] +} +move_back={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, 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) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) +] +} +jump={ +"deadzone": 0.2, +"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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +, 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":2,"canceled":false,"pressed":false,"double_click":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null) +] +} + +[layer_names] + +3d_physics/layer_1="player" +3d_physics/layer_2="enemies" +3d_physics/layer_3="world" + +[rendering] + +quality/driver/driver_name="GLES2" +quality/filters/msaa=3 diff --git a/squash-the-creeps/godot/rust.gdextension b/squash-the-creeps/godot/rust.gdextension new file mode 100644 index 0000000..3123c80 --- /dev/null +++ b/squash-the-creeps/godot/rust.gdextension @@ -0,0 +1,16 @@ +[configuration] +entry_symbol = "gdext_rust_init" +compatibility_minimum = 4.3 +reloadable = true + +[libraries] +linux.debug.x86_64 = "res://../../target/debug/libsquash_the_creeps.so" +linux.release.x86_64 = "res://../../target/release/libsquash_the_creeps.so" +windows.debug.x86_64 = "res://../../target/debug/squash_the_creeps.dll" +windows.release.x86_64 = "res://../../target/release/squash_the_creeps.dll" +macos.debug = "res://../../target/debug/libsquash_the_creeps.dylib" +macos.release = "res://../../target/release/libsquash_the_creeps.dylib" +macos.debug.arm64 = "res://../../target/debug/libsquash_the_creeps.dylib" +macos.release.arm64 = "res://../../target/release/libsquash_the_creeps.dylib" +web.debug.wasm32 = "res://../../target/wasm32-unknown-emscripten/debug/squash_the_creeps.wasm" +web.release.wasm32 = "res://../../target/wasm32-unknown-emscripten/release/squash_the_creeps.wasm" diff --git a/squash-the-creeps/godot/rust.gdextension.uid b/squash-the-creeps/godot/rust.gdextension.uid new file mode 100644 index 0000000..b731d5f --- /dev/null +++ b/squash-the-creeps/godot/rust.gdextension.uid @@ -0,0 +1 @@ +uid://btqaumkweydgr diff --git a/squash-the-creeps/rust/.cargo/cargo.toml b/squash-the-creeps/rust/.cargo/cargo.toml new file mode 100644 index 0000000..2c30f41 --- /dev/null +++ b/squash-the-creeps/rust/.cargo/cargo.toml @@ -0,0 +1,12 @@ +# Users: see https://godot-rust.github.io/book/toolchain/export-web.html for details. + +# The cargo flag "-Zbuild-std" is also required but this cannot yet be specified for specific +# targets: https://github.com/rust-lang/cargo/issues/8733 +[target.wasm32-unknown-emscripten] +rustflags = [ + "-C", "link-args=-pthread", # /!\ Read 'Thread support' below regarding this flag + "-C", "link-args=-sSIDE_MODULE=2", + "-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", + "-Zlink-native-libraries=no", + "-Cllvm-args=-enable-emscripten-cxx-exceptions=0", +] diff --git a/squash-the-creeps/rust/.gitignore b/squash-the-creeps/rust/.gitignore new file mode 100644 index 0000000..827cd78 --- /dev/null +++ b/squash-the-creeps/rust/.gitignore @@ -0,0 +1,2 @@ +/target +/emsdk \ No newline at end of file diff --git a/squash-the-creeps/rust/Cargo.toml b/squash-the-creeps/rust/Cargo.toml new file mode 100644 index 0000000..ad52b7c --- /dev/null +++ b/squash-the-creeps/rust/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "squash-the-creeps" +version = "0.1.0" +edition = "2021" +rust-version = "1.85" +license = "MPL-2.0" +publish = false + +[lib] +crate-type = ["cdylib"] + +[dependencies] +rand = "0.9.0" +godot = { git = "https://github.com/godot-rust/gdext.git", branch = "master" } +# For Wasm, feature "experimental-wasm" can be added, but this is already done in build-wasm.sh script. diff --git a/squash-the-creeps/rust/build-wasm.sh b/squash-the-creeps/rust/build-wasm.sh new file mode 100644 index 0000000..c252680 --- /dev/null +++ b/squash-the-creeps/rust/build-wasm.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright (c) godot-rust; Bromeon and contributors. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. + +# Must be in squash-the-creep's rust directory in order to pick up the .cargo/config +cd `dirname "$0"` + +# We build the host gdextension first so that the godot editor doesn't complain. +cargo +nightly build --package squash-the-creeps && +cargo +nightly build --package squash-the-creeps \ + --features godot/experimental-wasm,godot/lazy-function-tables \ + --target wasm32-unknown-emscripten -Zbuild-std $@ \ No newline at end of file diff --git a/squash-the-creeps/rust/src/lib.rs b/squash-the-creeps/rust/src/lib.rs new file mode 100644 index 0000000..f485ca5 --- /dev/null +++ b/squash-the-creeps/rust/src/lib.rs @@ -0,0 +1,10 @@ +mod main_scene; +mod mob; +mod player; +mod scorelabel; +use godot::prelude::*; + +struct SquashTheCreeps; + +#[gdextension] +unsafe impl ExtensionLibrary for SquashTheCreeps {} diff --git a/squash-the-creeps/rust/src/main_scene.rs b/squash-the-creeps/rust/src/main_scene.rs new file mode 100644 index 0000000..aac1cc2 --- /dev/null +++ b/squash-the-creeps/rust/src/main_scene.rs @@ -0,0 +1,81 @@ +use crate::mob; +use crate::player; +use crate::scorelabel; + +use godot::classes::{ColorRect, InputEvent, PathFollow3D, Timer}; +use godot::prelude::*; +use rand::Rng; + +#[derive(GodotClass)] +#[class(init, base=Node)] +pub struct MainScene { + #[export] + mob_scene: OnEditor>, + + #[init(node = "MobTimer")] + mob_timer: OnReady>, + + #[init(node = "UserInterface")] + user_interface: OnReady>, + + base: Base, +} + +#[godot_api] +impl INode for MainScene { + fn ready(&mut self) { + self.base() + .get_node_as::("UserInterface/Retry") + .hide(); + } + fn unhandled_input(&mut self, event: Gd) { + if event.is_action_pressed("ui_accept") + && self + .base() + .get_node_as::("UserInterface/Retry") + .is_visible() + { + self.base().get_tree().unwrap().reload_current_scene(); + } + } +} +#[godot_api] +impl MainScene { + #[func] + fn on_mob_timer_timeout(&mut self) { + // Create mob instance. + let mut mob_spawn_location = self + .base() + .get_node_as::("SpawnPath/SpawnLocation"); + + // Choose a random location on the SpawnPath. + // Set random progress using proper rng. + mob_spawn_location.set_progress_ratio(rand::rng().random_range(0.0..=1.0)); + + // Communicate the spawn location and the player's location to the mob. + let player_position = self + .base() + .get_node_as::("Player") + .get_position(); + + let mut mob = self.mob_scene.instantiate_as::(); + + mob.bind_mut() + .initialize(mob_spawn_location.get_position(), player_position); + + // Spawn the mob by adding it to the Main scene. + self.base_mut().add_child(&mob); + + // We connect the mob to the score label to update the score upon squashing a mob. + mob.connect("squashed", &self.user_interface.callable("on_mob_squashed")); + } + + #[func] + pub fn on_player_hit(&mut self) { + self.mob_timer.stop(); + + self.base() + .get_node_as::("UserInterface/Retry") + .show(); + } +} diff --git a/squash-the-creeps/rust/src/mob.rs b/squash-the-creeps/rust/src/mob.rs new file mode 100644 index 0000000..c30f081 --- /dev/null +++ b/squash-the-creeps/rust/src/mob.rs @@ -0,0 +1,69 @@ +use godot::classes::{AnimationPlayer, CharacterBody3D, ICharacterBody3D}; +use godot::prelude::*; +use rand::Rng; +use std::f32::consts::PI; + +#[derive(GodotClass)] +#[class(init, base=CharacterBody3D)] +pub struct Mob { + // Minimum speed of the mob in meters per second. + #[export] + min_speed: f32, + // Maximum speed of the mob in meters per second. + #[export] + max_speed: f32, + base: Base, +} + +#[godot_api] +impl ICharacterBody3D for Mob { + fn physics_process(&mut self, _delta: f64) { + self.base_mut().move_and_slide(); + } +} +#[godot_api] +impl Mob { + #[func] + pub fn initialize(&mut self, start_position: Vector3, player_position: Vector3) { + self.base_mut() + .look_at_from_position(start_position, player_position); + + self.base_mut() + .rotate_y(rand::rng().random_range(-PI / 4.0..PI / 4.0)); + + let random_speed = rand::rng().random_range(self.min_speed..self.max_speed); + + // We calculate a forward velocity first, which represents the speed. + self.base_mut() + .set_velocity(Vector3::FORWARD * random_speed); + + let rotation = self.base().get_rotation(); + let velocity = self.base().get_velocity(); + + // We then rotate the vector based on the mob's Y rotation to move in the direction it's looking. + self.base_mut() + .set_velocity(velocity.rotated(Vector3::UP, rotation.y)); + + let animation_speed = rand::rng().random_range(1.0..6.0); + + self.base() + .get_node_as::("AnimationPlayer") + .set_speed_scale(animation_speed as f32) + } + + // Emitted when the player jumped on the mob. + #[signal] + pub fn squashed(); + + #[func] + pub fn squash(&mut self) { + self.signals().squashed().emit(); + + self.base_mut().queue_free(); + } + + #[func] + fn on_visible_on_screen_notifier_3d_screen_exited(&mut self) { + self.base_mut().queue_free(); + } +} diff --git a/squash-the-creeps/rust/src/player.rs b/squash-the-creeps/rust/src/player.rs new file mode 100644 index 0000000..d231ef8 --- /dev/null +++ b/squash-the-creeps/rust/src/player.rs @@ -0,0 +1,137 @@ +use crate::mob::Mob; +use godot::classes::{AnimationPlayer, CharacterBody3D, CollisionShape3D, ICharacterBody3D, Input}; +use godot::prelude::*; +use std::f32::consts::FRAC_PI_6; + +#[derive(GodotClass)] +#[class(init, base=CharacterBody3D)] +pub struct Player { + /// How fast the player moves in meters per second. + #[export] + speed: f32, + + /// Vertical impulse applied to the character upon jumping in meters per second. + #[export] + jump_impulse: f32, + + /// Vertical impulse applied to the character upon bouncing over a mob in meters per second. + #[export] + bounce_impulse: f32, + + /// The downward acceleration when in the air, in meters per second. + #[export] + fall_acceleration: f32, + + /// The target velocity of the character (node property) + #[export] + target_velocity: Vector3, + base: Base, +} +#[godot_api] +impl ICharacterBody3D for Player { + fn physics_process(&mut self, _delta: f64) { + let mut direction = Vector3::ZERO; + + let input = Input::singleton(); + + if input.is_action_pressed("move_right") { + direction += Vector3::RIGHT; + } + if input.is_action_pressed("move_left") { + direction += Vector3::LEFT; + } + if input.is_action_pressed("move_back") { + direction += Vector3::BACK; + } + if input.is_action_pressed("move_forward") { + direction += Vector3::FORWARD; + } + + if direction != Vector3::ZERO { + // In the lines below, we turn the character when moving and make the animation play faster. + direction = direction.normalized(); + + // Take the pivot node and rotate it to face the direction we're moving in. + let mut pivot = self.base_mut().get_node_as::("Pivot"); + + // Setting the basis property will affect the rotation of the node. + pivot.set_basis(Basis::looking_at(-direction, Vector3::UP, true)); + self.base() + .get_node_as::("AnimationPlayer") + .set_speed_scale(4.0); + } else { + self.base() + .get_node_as::("AnimationPlayer") + .set_speed_scale(1.0); + } + // Ground Velocity. + self.target_velocity.x = direction.x * self.speed; + self.target_velocity.z = direction.z * self.speed; + + // jumping. + if self.base().is_on_floor() && input.is_action_just_pressed("jump") { + self.target_velocity.y = self.jump_impulse; + } + // We apply gravity every frame so the character always collides with the ground when moving. + // This is necessary for the is_on_floor() function to work as a body can always detect + // the floor, walls, etc. when a collision happens the same frame. + if !self.base().is_on_floor() { + self.target_velocity.y -= self.fall_acceleration * _delta as f32; + } + // moving the Character + let velocity = self.target_velocity; + self.base_mut().set_velocity(velocity); + self.base_mut().move_and_slide(); + + // Here, we check if we landed on top of a mob and if so, we kill it and bounce. + // With move_and_slide(), Godot makes the body move sometimes multiple times in a row to + // smooth out the character's motion. So we have to loop over all collisions that may have + // happened. + // If there are no "slides" this frame, the loop below won't run. + for index in 0..self.base().get_slide_collision_count() { + let collision = self.base_mut().get_slide_collision(index).unwrap(); + if let Some(collider) = collision.get_collider() { + if let Ok(node) = collider.try_cast::() { + if node.is_in_group("mob") { + let mut mob = collision.get_collider().unwrap().cast::(); + if Vector3::UP.dot(collision.get_normal()) > 0.1 { + mob.bind_mut().squash(); + + self.target_velocity.y = self.bounce_impulse; + // Prevent this block from running more than once, + // which would award the player more than 1 point for squashing a single mob. + break; + } + } + } + } + } + // This makes the character follow a nice arc when jumping. + let mut pivot = self.base().get_node_as::("Pivot"); + let mut pivot_rotation = pivot.get_rotation(); + pivot_rotation.x = FRAC_PI_6 * self.base().get_velocity().y / self.jump_impulse; + pivot.set_rotation(pivot_rotation); + } +} + +#[godot_api] +impl Player { + #[signal] + pub fn hit(); + + #[func] + pub fn die(&mut self) { + self.signals().hit().emit(); + self.base_mut().queue_free(); + } + + #[func] + pub fn on_mob_detector_body_entered(&mut self, _body: Gd) { + let mut collision_shape = self + .base() + .get_node_as::("CollisionShape3D"); + collision_shape.set_deferred("disabled", &true.to_variant()); + + self.die(); + } +} diff --git a/squash-the-creeps/rust/src/scorelabel.rs b/squash-the-creeps/rust/src/scorelabel.rs new file mode 100644 index 0000000..db361b4 --- /dev/null +++ b/squash-the-creeps/rust/src/scorelabel.rs @@ -0,0 +1,20 @@ +use godot::classes::{Control, Label}; +use godot::prelude::*; + +#[derive(GodotClass)] +#[class(init, base=Control)] +pub struct UserInterface { + score: f32, + base: Base, +} + +#[godot_api] +impl UserInterface { + #[func] + pub fn on_mob_squashed(&mut self) { + self.score += 1.0; + + let mut label = self.base().get_node_as::