From ddb50b0b66c838bc97e79c826ff5375e15f8f038 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 21 Jul 2026 01:42:31 +0200 Subject: init --- .editorconfig | 4 ++++ .gitattributes | 2 ++ .gitignore | 3 +++ .vscode/settings.json | 3 +++ Bullet.cs | 16 ++++++++++++++ Bullet.cs.uid | 1 + Bullet.tscn | 16 ++++++++++++++ Node2d.cs | 15 +++++++++++++ Node2d.cs.uid | 1 + Player.cs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ Player.cs.uid | 1 + icon.svg | 1 + icon.svg.import | 43 +++++++++++++++++++++++++++++++++++++ player.tscn | 19 +++++++++++++++++ project.godot | 42 ++++++++++++++++++++++++++++++++++++ testing.csproj | 7 ++++++ testing.sln | 19 +++++++++++++++++ 17 files changed, 252 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Bullet.cs create mode 100644 Bullet.cs.uid create mode 100644 Bullet.tscn create mode 100644 Node2d.cs create mode 100644 Node2d.cs.uid create mode 100644 Player.cs create mode 100644 Player.cs.uid create mode 100644 icon.svg create mode 100644 icon.svg.import create mode 100644 player.tscn create mode 100644 project.godot create mode 100644 testing.csproj create mode 100644 testing.sln 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"); + } + + 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 @@ + 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 @@ + + + net8.0 + net9.0 + true + + \ 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 -- cgit v1.2.3