mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Parenting changes
This commit is contained in:
parent
b7fb003b70
commit
6fbbe7ee4c
7 changed files with 225 additions and 160 deletions
18
Scripts/Bullet.cs
Normal file
18
Scripts/Bullet.cs
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
{
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue