diff --git a/Scenes/bullet.tscn b/Scenes/bullet.tscn index 4bc0a87b..fb42cf34 100644 --- a/Scenes/bullet.tscn +++ b/Scenes/bullet.tscn @@ -8,6 +8,7 @@ radius = 2.23607 [node name="Bullet" type="Area2D"] script = ExtResource("1_jvxw3") +Speed = 500.0 metadata/_edit_group_ = true [node name="Sprite2D" type="Sprite2D" parent="."] @@ -18,3 +19,7 @@ shape = SubResource("CircleShape2D_jxptd") [node name="Node2D" type="Node2D" parent="."] editor_description = "Player Bullet" + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] + +[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/Scenes/fragola.tscn b/Scenes/fragola.tscn index c1ecc80a..63e3646d 100644 --- a/Scenes/fragola.tscn +++ b/Scenes/fragola.tscn @@ -63,17 +63,18 @@ animations = [{ [sub_resource type="CircleShape2D" id="CircleShape2D_bbnjh"] radius = 7.0 -[node name="Fragola" type="Node2D"] - -[node name="Fragola" type="RigidBody2D" parent="."] +[node name="Fragola" type="RigidBody2D"] collision_layer = 4 collision_mask = 7 mass = 0.03 gravity_scale = 0.0 +metadata/_edit_group_ = true -[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Fragola"] +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] sprite_frames = SubResource("SpriteFrames_7uyln") animation = &"idle" -[node name="CollisionShape2D" type="CollisionShape2D" parent="Fragola"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_bbnjh") + +[node name="Fragola" type="Node2D" parent="."] diff --git a/Scenes/reisen.tscn b/Scenes/reisen.tscn new file mode 100644 index 00000000..91856059 --- /dev/null +++ b/Scenes/reisen.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=7 format=3 uid="uid://cxmcqehjjy82j"] + +[ext_resource type="Texture2D" uid="uid://b4ynnb14mb4uq" path="res://Sprites/Reisen.png" id="1_lfysk"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_rf4l1"] +atlas = ExtResource("1_lfysk") +region = Rect2(0, 0, 8, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6mmet"] +atlas = ExtResource("1_lfysk") +region = Rect2(8, 0, 8, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_okgvq"] +atlas = ExtResource("1_lfysk") +region = Rect2(16, 0, 8, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_8n5rt"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_rf4l1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_6mmet") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_okgvq") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_car73"] +size = Vector2(6, 9) + +[node name="CharacterBody2D" type="CharacterBody2D"] +metadata/_edit_group_ = true + +[node name="Sprite2D" type="AnimatedSprite2D" parent="."] +sprite_frames = SubResource("SpriteFrames_8n5rt") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(0, 0.5) +shape = SubResource("RectangleShape2D_car73") diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 7595a382..f007a5c0 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://bv451a8wgty4u"] +[gd_scene load_steps=8 format=3 uid="uid://bv451a8wgty4u"] [ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"] +[ext_resource type="PackedScene" uid="uid://cxmcqehjjy82j" path="res://Scenes/reisen.tscn" id="3_8k37m"] [ext_resource type="PackedScene" uid="uid://rp4jhx0tuh24" path="res://Scenes/fragola.tscn" id="4_s7wq6"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_qui05"] @@ -60,3 +61,6 @@ position = Vector2(62, 10) [node name="Player" parent="." instance=ExtResource("2_8mh54")] position = Vector2(-7, -15) + +[node name="CharacterBody2D" parent="." instance=ExtResource("3_8k37m")] +position = Vector2(78, -15) diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index dafcae07..311bac96 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -2,8 +2,13 @@ using Godot; using System; using System.Diagnostics; -public partial class Bullet : RigidBody2D +public partial class Bullet : Area2D { + [Export] + public float Speed = 1900f; + + private Vector2 _direction = Vector2.Right; + // Called when the node enters the scene tree for the first time. public override void _Ready() { @@ -13,6 +18,16 @@ public partial class Bullet : RigidBody2D // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { - + this.Position += ((float) (Speed * delta) * _direction); } + + private void _on_visible_on_screen_notifier_2d_screen_exited() + { + Debug.WriteLine("Destroy bullet out of screen"); + QueueFree(); + } + + } + + diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index 47c53e4f..88bc3690 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -42,6 +42,7 @@ public partial class PlayerMovement : CharacterBody2D { if (Input.IsActionJustPressed("shoot")) { + Debug.WriteLine("Shoot"); Bullet bullet = BulletScene.Instantiate(); Owner.AddChild(bullet); bullet.Transform = Muzzle.GlobalTransform; diff --git a/Sprites/Reisen.aseprite b/Sprites/Reisen.aseprite new file mode 100644 index 00000000..5d36e51f --- /dev/null +++ b/Sprites/Reisen.aseprite @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1989968953e0dcbb2f47defc2fd67ab64bba0b5488403d9c6c9644ec2387c29a +size 1051 diff --git a/Sprites/Reisen.png b/Sprites/Reisen.png new file mode 100644 index 00000000..5a09e94a --- /dev/null +++ b/Sprites/Reisen.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2bf17cd5c986fecb3465dcc67fbcb0ab431828ee8d8fef8dcc4506d605775dd +size 303 diff --git a/Sprites/Reisen.png.import b/Sprites/Reisen.png.import new file mode 100644 index 00000000..265b4c54 --- /dev/null +++ b/Sprites/Reisen.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b4ynnb14mb4uq" +path="res://.godot/imported/Reisen.png-8f337c31d7f03a02d98c68db42ec7137.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Reisen.png" +dest_files=["res://.godot/imported/Reisen.png-8f337c31d7f03a02d98c68db42ec7137.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