mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
Directional shooting
This commit is contained in:
parent
155d210e31
commit
65ce30a2a4
7 changed files with 158 additions and 10 deletions
|
|
@ -8,6 +8,7 @@ radius = 2.23607
|
|||
|
||||
[node name="Bullet" type="Area2D"]
|
||||
script = ExtResource("1_jvxw3")
|
||||
Speed = 200.0
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ animations = [{
|
|||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_m27vu")
|
||||
Speed = 1800
|
||||
Speed = 2000
|
||||
BulletScene = ExtResource("2_ov36d")
|
||||
Muzzle = NodePath("Muzzle")
|
||||
metadata/_edit_group_ = true
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -12,9 +12,19 @@ public partial class Bullet : Area2D
|
|||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
Debug.WriteLine("Bullet Shot");
|
||||
|
||||
}
|
||||
|
||||
public void SetDirection(Vector2 direction)
|
||||
{
|
||||
var normalized = direction.Normalized();
|
||||
|
||||
_direction = normalized;
|
||||
|
||||
Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}");
|
||||
}
|
||||
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,13 +11,19 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D Muzzle {get;set;}
|
||||
public Marker2D Muzzle { get; set; }
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
}
|
||||
|
||||
/*public override _Process(float _delta)
|
||||
|
|
@ -41,12 +47,13 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
private void HandleShoot()
|
||||
{
|
||||
if (Input.IsActionJustPressed("shoot"))
|
||||
{
|
||||
{
|
||||
Debug.WriteLine("Shoot");
|
||||
Bullet bullet = BulletScene.Instantiate<Bullet>();
|
||||
Owner.AddChild(bullet);
|
||||
bullet.Transform = Muzzle.GlobalTransform;
|
||||
bullet.Position = this.Position;
|
||||
bullet.SetDirection(this._movementDirection);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -89,9 +96,12 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var inputDirection = GetInput();
|
||||
Velocity = inputDirection * (float)(Speed * delta);
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
if (_movementDirection != Vector2.Zero) {
|
||||
_facingDirection = _movementDirection;
|
||||
}
|
||||
Velocity = _movementDirection * (float)(Speed * delta);
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
|
|
|||
BIN
Sprites/tinyBlocks_NOiL_1.1update.png
(Stored with Git LFS)
Normal file
BIN
Sprites/tinyBlocks_NOiL_1.1update.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/tinyBlocks_NOiL_1.1update.png.import
Normal file
34
Sprites/tinyBlocks_NOiL_1.1update.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bxclo2fg3ulur"
|
||||
path="res://.godot/imported/tinyBlocks_NOiL_1.1update.png-50a5b3cb0e9f95f564631e9103861ec5.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/tinyBlocks_NOiL_1.1update.png"
|
||||
dest_files=["res://.godot/imported/tinyBlocks_NOiL_1.1update.png-50a5b3cb0e9f95f564631e9103861ec5.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
|
||||
Loading…
Add table
Add a link
Reference in a new issue