diff --git a/Tlob.csproj b/Tlob.csproj new file mode 100644 index 0000000..198256e --- /dev/null +++ b/Tlob.csproj @@ -0,0 +1,8 @@ + + + net6.0 + net7.0 + net8.0 + true + + \ No newline at end of file diff --git a/Tlob.sln b/Tlob.sln new file mode 100644 index 0000000..416432b --- /dev/null +++ b/Tlob.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tlob", "Tlob.csproj", "{DAF2229D-5187-4A27-A81D-0555D20817E2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DAF2229D-5187-4A27-A81D-0555D20817E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAF2229D-5187-4A27-A81D-0555D20817E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/scenes/box.tscn b/scenes/box.tscn new file mode 100644 index 0000000..b34e703 --- /dev/null +++ b/scenes/box.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://dur0i50oao18u"] + +[ext_resource type="Texture2D" uid="uid://be6qojhnjml47" path="res://sprites/box.png" id="1_uib42"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_pnqxx"] +size = Vector2(42, 42) + +[node name="Node2D" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.328125, 0.328125) +texture = ExtResource("1_uib42") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_pnqxx") diff --git a/scenes/main.tscn b/scenes/main.tscn index 9c6d1d9..db8e123 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -1,3 +1,12 @@ -[gd_scene format=3 uid="uid://byuw363qi2nwu"] +[gd_scene load_steps=3 format=3 uid="uid://byuw363qi2nwu"] + +[ext_resource type="PackedScene" uid="uid://cpqrufo1gdajy" path="res://scenes/tlob.tscn" id="1_f4jm3"] +[ext_resource type="PackedScene" uid="uid://dur0i50oao18u" path="res://scenes/box.tscn" id="2_n63uh"] [node name="Main" type="Node2D"] + +[node name="Tlob" parent="." instance=ExtResource("1_f4jm3")] +position = Vector2(0, -3) + +[node name="Node2D" parent="." instance=ExtResource("2_n63uh")] +position = Vector2(635, -362) diff --git a/scenes/tlob.cs b/scenes/tlob.cs new file mode 100644 index 0000000..496c357 --- /dev/null +++ b/scenes/tlob.cs @@ -0,0 +1,39 @@ +using Godot; +using System; + +public partial class tlob : CharacterBody2D +{ + public const float Speed = 300.0f; + public const float JumpVelocity = -400.0f; + + // Get the gravity from the project settings to be synced with RigidBody nodes. + public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle(); + + public override void _PhysicsProcess(double delta) + { + Vector2 velocity = Velocity; + + // Add the gravity. + if (!IsOnFloor()) + velocity.Y += gravity * (float)delta; + + // Handle Jump. + if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) + velocity.Y = JumpVelocity; + + // Get the input direction and handle the movement/deceleration. + // As good practice, you should replace UI actions with custom gameplay actions. + Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); + if (direction != Vector2.Zero) + { + velocity.X = direction.X * Speed; + } + else + { + velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed); + } + + Velocity = velocity; + MoveAndSlide(); + } +} diff --git a/scenes/tlob.tscn b/scenes/tlob.tscn index 220c160..3978d38 100644 --- a/scenes/tlob.tscn +++ b/scenes/tlob.tscn @@ -1,14 +1,20 @@ -[gd_scene load_steps=3 format=3 uid="uid://cpqrufo1gdajy"] +[gd_scene load_steps=4 format=3 uid="uid://cpqrufo1gdajy"] +[ext_resource type="Script" path="res://scenes/tlob.cs" id="1_i865j"] [ext_resource type="Texture2D" uid="uid://dfjrr8hcd3ol" path="res://sprites/tlob.png" id="1_tg6nh"] [sub_resource type="CircleShape2D" id="CircleShape2D_5pvct"] radius = 64.0 [node name="Tlob" type="CharacterBody2D"] +motion_mode = 1 +script = ExtResource("1_i865j") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_5pvct") [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_tg6nh") + +[node name="Camera2D" type="Camera2D" parent="."] +zoom = Vector2(0.5, 0.5) diff --git a/sprites/box.png b/sprites/box.png new file mode 100644 index 0000000..a132a51 Binary files /dev/null and b/sprites/box.png differ diff --git a/sprites/box.png.import b/sprites/box.png.import new file mode 100644 index 0000000..d6711e8 --- /dev/null +++ b/sprites/box.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://be6qojhnjml47" +path="res://.godot/imported/box.png-88e8c9a9152bfabd2b270e3db2186223.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/box.png" +dest_files=["res://.godot/imported/box.png-88e8c9a9152bfabd2b270e3db2186223.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