diff options
| author | alex <[email protected]> | 2026-07-21 01:42:31 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-21 01:42:31 +0200 |
| commit | ddb50b0b66c838bc97e79c826ff5375e15f8f038 (patch) | |
| tree | a4c08f1571cbeff61f7f94f1f3510494729f30df | |
| download | godot-testing-ddb50b0b66c838bc97e79c826ff5375e15f8f038.tar.xz godot-testing-ddb50b0b66c838bc97e79c826ff5375e15f8f038.zip | |
init
| -rw-r--r-- | .editorconfig | 4 | ||||
| -rw-r--r-- | .gitattributes | 2 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | .vscode/settings.json | 3 | ||||
| -rw-r--r-- | Bullet.cs | 16 | ||||
| -rw-r--r-- | Bullet.cs.uid | 1 | ||||
| -rw-r--r-- | Bullet.tscn | 16 | ||||
| -rw-r--r-- | Node2d.cs | 15 | ||||
| -rw-r--r-- | Node2d.cs.uid | 1 | ||||
| -rw-r--r-- | Player.cs | 59 | ||||
| -rw-r--r-- | Player.cs.uid | 1 | ||||
| -rw-r--r-- | icon.svg | 1 | ||||
| -rw-r--r-- | icon.svg.import | 43 | ||||
| -rw-r--r-- | player.tscn | 19 | ||||
| -rw-r--r-- | project.godot | 42 | ||||
| -rw-r--r-- | testing.csproj | 7 | ||||
| -rw-r--r-- | testing.sln | 19 |
17 files changed, 252 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f28239b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +root = true + +[*] +charset = utf-8 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4820519 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "godotTools.editorPath.godot4": "/home/bambi15/.local/share/Godot_v4.7.1-stable_mono_linux_x86_64/godot" +}
\ No newline at end of file diff --git a/Bullet.cs b/Bullet.cs new file mode 100644 index 0000000..aeefd94 --- /dev/null +++ b/Bullet.cs @@ -0,0 +1,16 @@ +using Godot; + +public partial class Bullet : Area2D +{ + [Export] public float Speed { get; set; } = 600.0f; + + // The player script will set this direction when the bullet spawns + public Vector2 Direction { get; set; } = Vector2.Zero; + + public override void _PhysicsProcess(double delta) + { + // Move the bullet over time. + // We multiply by delta to ensure movement is framerate-independent. + Position += Direction * Speed * (float)delta; + } +}
\ No newline at end of file diff --git a/Bullet.cs.uid b/Bullet.cs.uid new file mode 100644 index 0000000..1c8ceaf --- /dev/null +++ b/Bullet.cs.uid @@ -0,0 +1 @@ +uid://r11kb2e6g3g6 diff --git a/Bullet.tscn b/Bullet.tscn new file mode 100644 index 0000000..016cb0e --- /dev/null +++ b/Bullet.tscn @@ -0,0 +1,16 @@ +[gd_scene format=3 uid="uid://cchdwhewroga8"] + +[ext_resource type="Script" uid="uid://r11kb2e6g3g6" path="res://Bullet.cs" id="1_4s4u5"] +[ext_resource type="Texture2D" uid="uid://cuoc77romff78" path="res://icon.svg" id="1_ayd6b"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_0m7y3"] +size = Vector2(124, 126) + +[node name="Area2D" type="Area2D" unique_id=1047288677] +script = ExtResource("1_4s4u5") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=729865337] +texture = ExtResource("1_ayd6b") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1673067562] +shape = SubResource("RectangleShape2D_0m7y3") diff --git a/Node2d.cs b/Node2d.cs new file mode 100644 index 0000000..c10e391 --- /dev/null +++ b/Node2d.cs @@ -0,0 +1,15 @@ +using Godot; +using System; + +public partial class Node2d : Node2D +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } +} diff --git a/Node2d.cs.uid b/Node2d.cs.uid new file mode 100644 index 0000000..92e6071 --- /dev/null +++ b/Node2d.cs.uid @@ -0,0 +1 @@ +uid://do424ojeid4ol diff --git a/Player.cs b/Player.cs new file mode 100644 index 0000000..8a5f5d4 --- /dev/null +++ b/Player.cs @@ -0,0 +1,59 @@ +using Godot; + +public partial class Player : CharacterBody2D +{ + [Export] public float Speed { get; set; } = 300.0f; + [Export] public PackedScene BulletScene { get; set; } + + // Create a reference for your Sprite + private Sprite2D _sprite; + + public override void _Ready() + { + // Grab the Sprite2D node when the game starts + _sprite = GetNode<Sprite2D>("Sprite2D"); + } + + public override void _PhysicsProcess(double delta) + { + Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); + Velocity = direction * Speed; + MoveAndSlide(); + } + + public override void _Process(double delta) + { + // Get the mouse position + Vector2 mousePos = GetGlobalMousePosition(); + + // If the mouse is to the left of the player, flip the sprite. + // If it's to the right, keep it un-flipped. + _sprite.FlipH = mousePos.X < GlobalPosition.X; + + if (Input.IsActionJustPressed("shoot")) + { + Shoot(); + } + } + private void Shoot() + { + // Failsafe in case you forgot to assign the scene in the editor + if (BulletScene == null) return; + + // Create an instance of the bullet + Bullet bullet = (Bullet)BulletScene.Instantiate(); + + // Spawn it at the player's current position + bullet.GlobalPosition = GlobalPosition; + + // Calculate the direction from the player to the mouse + Vector2 mousePos = GetGlobalMousePosition(); + bullet.Direction = GlobalPosition.DirectionTo(mousePos); + + // Rotate the bullet to face the direction it's traveling + bullet.Rotation = bullet.Direction.Angle(); + + // Add the bullet to the current scene tree so it actually exists in the game + GetTree().Root.AddChild(bullet); + } +}
\ No newline at end of file diff --git a/Player.cs.uid b/Player.cs.uid new file mode 100644 index 0000000..87b8b2b --- /dev/null +++ b/Player.cs.uid @@ -0,0 +1 @@ +uid://6s17dw3nj0ne diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..c6bbb7d --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg> diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..f5bec8d --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cuoc77romff78" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/player.tscn b/player.tscn new file mode 100644 index 0000000..7e25da2 --- /dev/null +++ b/player.tscn @@ -0,0 +1,19 @@ +[gd_scene format=3 uid="uid://dydy08duw2lhf"] + +[ext_resource type="Texture2D" uid="uid://cuoc77romff78" path="res://icon.svg" id="1_4flbx"] +[ext_resource type="Script" uid="uid://6s17dw3nj0ne" path="res://Player.cs" id="1_onrkg"] +[ext_resource type="PackedScene" uid="uid://cchdwhewroga8" path="res://Bullet.tscn" id="2_i3pqv"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_0m7y3"] +size = Vector2(119, 123) + +[node name="Player" type="CharacterBody2D" unique_id=312289746] +script = ExtResource("1_onrkg") +BulletScene = ExtResource("2_i3pqv") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1627277964] +position = Vector2(-0.5, 0.5) +shape = SubResource("RectangleShape2D_0m7y3") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1865687544] +texture = ExtResource("1_4flbx") diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..76a1300 --- /dev/null +++ b/project.godot @@ -0,0 +1,42 @@ +; 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="testing" +run/main_scene="uid://dydy08duw2lhf" +config/features=PackedStringArray("4.7", "C#", "Forward Plus") +config/icon="res://icon.svg" + +[display] + +window/stretch/mode="canvas_items" +window/stretch/aspect="expand" + +[dotnet] + +project/assembly_name="testing" + +[input] + +shoot={ +"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) +, 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":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) +] +} + +[physics] + +3d/physics_engine="Jolt Physics" + +[rendering] + +rendering_device/driver.windows="d3d12" diff --git a/testing.csproj b/testing.csproj new file mode 100644 index 0000000..19b3a42 --- /dev/null +++ b/testing.csproj @@ -0,0 +1,7 @@ +<Project Sdk="Godot.NET.Sdk/4.7.1"> + <PropertyGroup> + <TargetFramework>net8.0</TargetFramework> + <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework> + <EnableDynamicLoading>true</EnableDynamicLoading> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/testing.sln b/testing.sln new file mode 100644 index 0000000..513f24f --- /dev/null +++ b/testing.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testing", "testing.csproj", "{4AD54E1B-0540-41F7-B000-49824D26FF15}" +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 + {4AD54E1B-0540-41F7-B000-49824D26FF15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AD54E1B-0540-41F7-B000-49824D26FF15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AD54E1B-0540-41F7-B000-49824D26FF15}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {4AD54E1B-0540-41F7-B000-49824D26FF15}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {4AD54E1B-0540-41F7-B000-49824D26FF15}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {4AD54E1B-0540-41F7-B000-49824D26FF15}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal |
