commit f8b11b590bab7c0ee5919417cd5ae3c6809d68b1 Author: DerTyp7 Date: Tue Sep 19 15:17:39 2023 +0200 first commit 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..4709183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/Bullet.gd b/Bullet.gd new file mode 100644 index 0000000..39015d7 --- /dev/null +++ b/Bullet.gd @@ -0,0 +1,23 @@ +extends RigidBody2D + +var destroy_timer := Timer.new() + +func _ready(): + add_child(destroy_timer) + destroy_timer.wait_time = 5.0 + destroy_timer.one_shot = true # Automatically stops after timing out + + # Start the timer + destroy_timer.start() + + # Connect the "timeout" signal + destroy_timer.connect("timeout", _on_destroy_timer_timeout) + + # Set the wait time for the timer (5 seconds) + + + + +func _on_destroy_timer_timeout(): + # This function will be called when the timer times out + queue_free() # Destroy the object diff --git a/Bullet.tscn b/Bullet.tscn new file mode 100644 index 0000000..0272750 --- /dev/null +++ b/Bullet.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=5 format=3 uid="uid://day7or3kp8x5u"] + +[ext_resource type="Script" path="res://Bullet.gd" id="1_0l6ar"] +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="1_cjg2r"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_suj8m"] +size = Vector2(4, 4) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_lfity"] +size = Vector2(4, 4) + +[node name="RigidBody2D" type="RigidBody2D"] +gravity_scale = 0.0 +script = ExtResource("1_0l6ar") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_suj8m") + +[node name="Sprite2D" type="Sprite2D" parent="."] +position = Vector2(-2.38419e-07, -2.38419e-07) +scale = Vector2(0.4, 0.4) +texture = ExtResource("1_cjg2r") + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource("RectangleShape2D_lfity") diff --git a/Player.gd b/Player.gd new file mode 100644 index 0000000..ed6a07b --- /dev/null +++ b/Player.gd @@ -0,0 +1,91 @@ +extends CharacterBody2D + +var movespeed = 300; +var bullet_speed = 2000; +var bullet = preload("res://Bullet.tscn") + +var shoot_timer := Timer.new() +var can_shoot := true + +func _ready(): + add_child(shoot_timer); + shoot_timer.wait_time = 0.3 + shoot_timer.start() + shoot_timer.connect("timeout", _on_shoot_timer_timeout) + +func _on_shoot_timer_timeout(): + can_shoot = true + + +func _physics_process(delta): + look() + move() + + if Input.is_action_pressed("shoot"): + shoot() + +func shoot(): + if can_shoot: + fire() + can_shoot = false + shoot_timer.start() + +func look(): + var look_direction = Vector2.ZERO + + if Input.is_action_pressed("look_up"): + look_direction.y -= 1 + if Input.is_action_pressed("look_down"): + look_direction.y += 1 + if Input.is_action_pressed("look_left"): + look_direction.x -= 1 + if Input.is_action_pressed("look_right"): + look_direction.x += 1 + + # Diagonal look + if Input.is_action_pressed("look_up") && Input.is_action_pressed("look_left"): + look_direction = Vector2(-1, -1).normalized() + if Input.is_action_pressed("look_up") && Input.is_action_pressed("look_right"): + look_direction = Vector2(1, -1).normalized() + if Input.is_action_pressed("look_down") && Input.is_action_pressed("look_left"): + look_direction = Vector2(-1, 1).normalized() + if Input.is_action_pressed("look_down") && Input.is_action_pressed("look_right"): + look_direction = Vector2(1, 1).normalized() + + if look_direction != Vector2.ZERO: + look_direction = look_direction.normalized() + rotation = look_direction.angle() + +func move(): + velocity = Vector2.ZERO + + if Input.is_action_pressed("walk_up"): + velocity.y -= 1 + if Input.is_action_pressed("walk_down"): + velocity.y += 1 + if Input.is_action_pressed("walk_left"): + velocity.x -= 1 + if Input.is_action_pressed("walk_right"): + velocity.x += 1 + + velocity = velocity.normalized() * movespeed + + move_and_slide() + + +func fire(): + var bullet_instance = bullet.instantiate() # Create an instance of the bullet + var offset = Vector2(20, 0).rotated(rotation) # Adjust the offset as needed + bullet_instance.position = global_position + offset + bullet_instance.rotation_degrees = rotation_degrees + + # Calculate the bullet direction based on the player's rotation + var bullet_direction = Vector2(bullet_speed, 0).rotated(rotation) + + # Apply the impulse in the correct direction + bullet_instance.apply_impulse(bullet_direction, Vector2()) + + # Add the bullet to the scene + get_tree().get_root().call_deferred("add_child", bullet_instance) + + diff --git a/Player.tscn b/Player.tscn new file mode 100644 index 0000000..2bb0fc5 --- /dev/null +++ b/Player.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://dvppgl1s0b3mv"] + +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="1_1rt42"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_dty8l"] +size = Vector2(10, 10) + +[node name="Node2D" type="Node2D"] + +[node name="CharacterBody2D" type="CharacterBody2D" parent="."] + +[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"] +texture = ExtResource("1_1rt42") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] +shape = SubResource("RectangleShape2D_dty8l") diff --git a/Untitled.png b/Untitled.png new file mode 100644 index 0000000..9f7469b Binary files /dev/null and b/Untitled.png differ diff --git a/Untitled.png.import b/Untitled.png.import new file mode 100644 index 0000000..8c6fe16 --- /dev/null +++ b/Untitled.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dafsi3dqavgnb" +path="res://.godot/imported/Untitled.png-30da513a925d9064453decddf41ecbd4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Untitled.png" +dest_files=["res://.godot/imported/Untitled.png-30da513a925d9064453decddf41ecbd4.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/icon.svg b/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..76ec1e1 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://sjxc2jsooye" +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/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 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/mai97AF.tmp b/mai97AF.tmp new file mode 100644 index 0000000..58efbab --- /dev/null +++ b/mai97AF.tmp @@ -0,0 +1,35 @@ +[gd_scene load_steps=6 format=3 uid="uid://b0i261cp1ugkh"] + +[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"] +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"] +size = Vector2(10, 10) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_my1x2"] +size = Vector2(12, 12) + +[node name="World" type="Node2D"] + +[node name="Player" type="CharacterBody2D" parent="."] +script = ExtResource("1_6ke6x") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource("RectangleShape2D_fs1q0") + +[node name="Sprite2D" type="Sprite2D" parent="Player"] +texture = ExtResource("2_w1il1") + +[node name="Sprite2D" type="Sprite2D" parent="Player/Sprite2D"] +material = SubResource("ShaderMaterial_tqqca") +position = Vector2(-4.00596, 0) +scale = Vector2(0.202, 0.2) +texture = ExtResource("2_w1il1") +offset = Vector2(45.275, 0) + +[node name="Area2D" type="Area2D" parent="Player"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"] +shape = SubResource("RectangleShape2D_my1x2") diff --git a/maiA829.tmp b/maiA829.tmp new file mode 100644 index 0000000..58efbab --- /dev/null +++ b/maiA829.tmp @@ -0,0 +1,35 @@ +[gd_scene load_steps=6 format=3 uid="uid://b0i261cp1ugkh"] + +[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"] +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"] +size = Vector2(10, 10) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_my1x2"] +size = Vector2(12, 12) + +[node name="World" type="Node2D"] + +[node name="Player" type="CharacterBody2D" parent="."] +script = ExtResource("1_6ke6x") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource("RectangleShape2D_fs1q0") + +[node name="Sprite2D" type="Sprite2D" parent="Player"] +texture = ExtResource("2_w1il1") + +[node name="Sprite2D" type="Sprite2D" parent="Player/Sprite2D"] +material = SubResource("ShaderMaterial_tqqca") +position = Vector2(-4.00596, 0) +scale = Vector2(0.202, 0.2) +texture = ExtResource("2_w1il1") +offset = Vector2(45.275, 0) + +[node name="Area2D" type="Area2D" parent="Player"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"] +shape = SubResource("RectangleShape2D_my1x2") diff --git a/maiD9D6.tmp b/maiD9D6.tmp new file mode 100644 index 0000000..58efbab --- /dev/null +++ b/maiD9D6.tmp @@ -0,0 +1,35 @@ +[gd_scene load_steps=6 format=3 uid="uid://b0i261cp1ugkh"] + +[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"] +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"] +size = Vector2(10, 10) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_my1x2"] +size = Vector2(12, 12) + +[node name="World" type="Node2D"] + +[node name="Player" type="CharacterBody2D" parent="."] +script = ExtResource("1_6ke6x") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource("RectangleShape2D_fs1q0") + +[node name="Sprite2D" type="Sprite2D" parent="Player"] +texture = ExtResource("2_w1il1") + +[node name="Sprite2D" type="Sprite2D" parent="Player/Sprite2D"] +material = SubResource("ShaderMaterial_tqqca") +position = Vector2(-4.00596, 0) +scale = Vector2(0.202, 0.2) +texture = ExtResource("2_w1il1") +offset = Vector2(45.275, 0) + +[node name="Area2D" type="Area2D" parent="Player"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"] +shape = SubResource("RectangleShape2D_my1x2") diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..58efbab --- /dev/null +++ b/main.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=6 format=3 uid="uid://b0i261cp1ugkh"] + +[ext_resource type="Script" path="res://Player.gd" id="1_6ke6x"] +[ext_resource type="Texture2D" uid="uid://dafsi3dqavgnb" path="res://Untitled.png" id="2_w1il1"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_fs1q0"] +size = Vector2(10, 10) + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tqqca"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_my1x2"] +size = Vector2(12, 12) + +[node name="World" type="Node2D"] + +[node name="Player" type="CharacterBody2D" parent="."] +script = ExtResource("1_6ke6x") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"] +shape = SubResource("RectangleShape2D_fs1q0") + +[node name="Sprite2D" type="Sprite2D" parent="Player"] +texture = ExtResource("2_w1il1") + +[node name="Sprite2D" type="Sprite2D" parent="Player/Sprite2D"] +material = SubResource("ShaderMaterial_tqqca") +position = Vector2(-4.00596, 0) +scale = Vector2(0.202, 0.2) +texture = ExtResource("2_w1il1") +offset = Vector2(45.275, 0) + +[node name="Area2D" type="Area2D" parent="Player"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"] +shape = SubResource("RectangleShape2D_my1x2") diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..0cb891e --- /dev/null +++ b/project.godot @@ -0,0 +1,69 @@ +; 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="TopDownShooter" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.1", "Forward Plus") +config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="TopDownShooter" + +[input] + +walk_up={ +"deadzone": 0.5, +"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":87,"key_label":0,"unicode":119,"echo":false,"script":null) +] +} +walk_down={ +"deadzone": 0.5, +"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":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} +walk_left={ +"deadzone": 0.5, +"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":65,"key_label":0,"unicode":97,"echo":false,"script":null) +] +} +walk_right={ +"deadzone": 0.5, +"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":68,"key_label":0,"unicode":100,"echo":false,"script":null) +] +} +shoot={ +"deadzone": 0.5, +"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":1,"position":Vector2(445, 14),"global_position":Vector2(449, 57),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"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":32,"key_label":0,"unicode":32,"echo":false,"script":null) +] +} +look_up={ +"deadzone": 0.5, +"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":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +look_down={ +"deadzone": 0.5, +"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":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +look_left={ +"deadzone": 0.5, +"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":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +look_right={ +"deadzone": 0.5, +"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":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +] +}