mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 06:45:33 +00:00
Added crosshair
This commit is contained in:
parent
5012527bae
commit
9e3c75ca1d
5 changed files with 72 additions and 2 deletions
6
Scenes/crosshair.tscn
Normal file
6
Scenes/crosshair.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cfb3nsay84xdb"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cfrvb1moh857m" path="res://Sprites/Crosshair.png" id="1_hincd"]
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D"]
|
||||
texture = ExtResource("1_hincd")
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=22 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
[gd_scene load_steps=23 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
|
||||
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/bullet.tscn" id="2_ov36d"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"]
|
||||
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="5_cxvyt"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/crosshair.tscn" id="6_l43rf"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ai4rh"]
|
||||
size = Vector2(6, 8)
|
||||
|
|
@ -137,6 +138,7 @@ collision_layer = 2
|
|||
collision_mask = 3
|
||||
script = ExtResource("1_m27vu")
|
||||
Speed = 2000
|
||||
CrosshairDistance = 20.0
|
||||
BulletScene = ExtResource("2_ov36d")
|
||||
Muzzle = NodePath("Muzzle")
|
||||
metadata/_edit_group_ = true
|
||||
|
|
@ -168,3 +170,5 @@ script = ExtResource("5_cxvyt")
|
|||
y_sort_enabled = true
|
||||
sprite_frames = SubResource("SpriteFrames_q0rt3")
|
||||
animation = &"walk_left"
|
||||
|
||||
[node name="Crosshair" parent="." instance=ExtResource("6_l43rf")]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
[Export]
|
||||
public int Speed { get; set; } = 400;
|
||||
|
||||
[Export]
|
||||
public float CrosshairDistance { get; set; } = 10f;
|
||||
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
|
|
@ -19,9 +22,13 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
private Sprite2D _crosshair;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Crosshair");
|
||||
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
}
|
||||
|
|
@ -53,7 +60,7 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
Owner.AddChild(bullet);
|
||||
bullet.Transform = Muzzle.GlobalTransform;
|
||||
bullet.Position = this.Position;
|
||||
bullet.SetDirection(this._movementDirection);
|
||||
bullet.SetDirection(this._facingDirection);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +102,19 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
private Vector2 CalculateCrosshairPosition()
|
||||
{
|
||||
|
||||
return _facingDirection * CrosshairDistance;// + this.Position;
|
||||
|
||||
//var angle = Mathf.Atan2(this.Position.X, this.Position.Y);
|
||||
|
||||
|
||||
//var cPos = new Vector2(this.Position.X + CrosshairDistance * Godot.Mathf.Cos(angle), this.Position.Y + CrosshairDistance * Godot.Mathf.Sin(angle));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
|
|
@ -104,5 +124,8 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
Velocity = _movementDirection * (float)(Speed * delta);
|
||||
|
||||
MoveAndSlide();
|
||||
|
||||
_crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
Sprites/Crosshair.png
(Stored with Git LFS)
Normal file
BIN
Sprites/Crosshair.png
(Stored with Git LFS)
Normal file
Binary file not shown.
34
Sprites/Crosshair.png.import
Normal file
34
Sprites/Crosshair.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cfrvb1moh857m"
|
||||
path="res://.godot/imported/Crosshair.png-a2c6dd7c570cec81011a43a0b2be86c6.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sprites/Crosshair.png"
|
||||
dest_files=["res://.godot/imported/Crosshair.png-a2c6dd7c570cec81011a43a0b2be86c6.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