Parenting changes

This commit is contained in:
Marco Giacomelli 2024-02-27 17:16:55 +01:00
commit 6fbbe7ee4c
7 changed files with 225 additions and 160 deletions

18
Scripts/Bullet.cs Normal file
View file

@ -0,0 +1,18 @@
using Godot;
using System;
using System.Diagnostics;
public partial class Bullet : RigidBody2D
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Debug.WriteLine("Bullet Shot");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}

View file

@ -1,11 +1,18 @@
using Godot;
using System;
using System.Diagnostics;
public partial class PlayerMovement : CharacterBody2D
{
[Export]
public int Speed { get; set; } = 400;
[Export]
public PackedScene BulletScene { get; set; }
[Export]
public Marker2D Muzzle {get;set;}
private AnimatedSprite2D _animatedSprite;
public override void _Ready()
@ -27,9 +34,22 @@ public partial class PlayerMovement : CharacterBody2D
public override void _Process(double delta)
{
HandleShoot();
SetAnimation();
}
private void HandleShoot()
{
if (Input.IsActionJustPressed("shoot"))
{
Bullet bullet = BulletScene.Instantiate<Bullet>();
Owner.AddChild(bullet);
bullet.Transform = Muzzle.GlobalTransform;
bullet.Position = this.Position;
}
}
private void SetAnimation()
{