State machine and crosshair
This commit is contained in:
parent
7d30fa63d1
commit
a32ac09b04
12 changed files with 116 additions and 5 deletions
|
|
@ -16,6 +16,7 @@ environment = ExtResource("1_i6jab")
|
|||
|
||||
[node name="Player" parent="." instance=ExtResource("2_ajphm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.073462, 1.5000002, -0.5869317)
|
||||
SPEED = 10.0
|
||||
TOGGLE_CROUCH = false
|
||||
|
||||
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="."]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ run/main_scene="uid://cqrh2cc7m2i7f"
|
|||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
PlayerGlobal="*res://scritps/player/player_global.gd"
|
||||
|
||||
[input]
|
||||
|
||||
plr_forward={
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://dpsr6ug3pkb40"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dpsr6ug3pkb40"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://3dphlay25fih" path="res://scritps/player/player.gd" id="1_g2els"]
|
||||
[ext_resource type="Script" uid="uid://dalwlndejfdhm" path="res://scritps/player/crosshair.gd" id="3_dqkch"]
|
||||
[ext_resource type="Script" uid="uid://bjhbdh6xsjgnn" path="res://scritps/player/player_camera.gd" id="3_qhqgy"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_u8vuu"]
|
||||
|
|
@ -44,9 +45,6 @@ tracks/2/keys = {
|
|||
"values": [Vector3(0, 2, 0), Vector3(0, 1.5, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_qhqgy"]
|
||||
resource_name = "Stand"
|
||||
|
||||
[sub_resource type="Animation" id="Animation_dqkch"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
|
|
@ -86,6 +84,9 @@ tracks/2/keys = {
|
|||
"values": [Vector3(0, 2, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_qhqgy"]
|
||||
resource_name = "Stand"
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qlg0r"]
|
||||
_data = {
|
||||
&"Crouch": SubResource("Animation_g2els"),
|
||||
|
|
@ -125,3 +126,31 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
|||
shape = SubResource("CapsuleShape3D_g2els")
|
||||
debug_color = Color(0.9878064, 0, 0.31407458, 0.41960785)
|
||||
debug_fill = false
|
||||
|
||||
[node name="HUD" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Crosshair" type="Control" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("3_dqkch")
|
||||
crosses_width = 2.0
|
||||
crosses_length = 6.0
|
||||
crosses_offset = 3.0
|
||||
|
||||
[node name="MovementMachine" type="Node" parent="."]
|
||||
|
|
|
|||
21
scritps/player/crosshair.gd
Normal file
21
scritps/player/crosshair.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Control
|
||||
|
||||
|
||||
@export var outline: bool = true
|
||||
@export var outline_color: Color = Color.BLACK
|
||||
@export var outline_width: float = 0.1
|
||||
|
||||
@export var dot_radius: float = 1.0
|
||||
@export var dot_color: Color = Color.WHITE
|
||||
|
||||
@export var crosses_width: float = 1.0
|
||||
@export var crosses_length: float = 2.0
|
||||
@export var crosses_offset: float = 0.2
|
||||
@export var crosses_color: Color = Color.WHITE
|
||||
|
||||
func _draw() -> void:
|
||||
draw_circle(Vector2(0,0),dot_radius,dot_color,true,outline_width)
|
||||
for i in range(0,4):
|
||||
var direction: Vector2 = Vector2.RIGHT.rotated(i*PI/2)
|
||||
var offset_position: Vector2 = direction * crosses_offset
|
||||
draw_line(offset_position,direction*crosses_length+offset_position,crosses_color,crosses_width)
|
||||
1
scritps/player/crosshair.gd.uid
Normal file
1
scritps/player/crosshair.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dalwlndejfdhm
|
||||
|
|
@ -22,7 +22,7 @@ var crouched: bool = false:
|
|||
|
||||
var potential_crouched: bool = crouched
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
if potential_crouched != crouched:
|
||||
crouched = potential_crouched
|
||||
|
||||
|
|
|
|||
4
scritps/player/player_global.gd
Normal file
4
scritps/player/player_global.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends Node
|
||||
|
||||
|
||||
var player: CharacterBody3D
|
||||
1
scritps/player/player_global.gd.uid
Normal file
1
scritps/player/player_global.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dv3pm11t6p4si
|
||||
36
scritps/state_machine/machine.gd
Normal file
36
scritps/state_machine/machine.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
extends Node
|
||||
|
||||
|
||||
class_name StateMachine
|
||||
|
||||
@export var current_state: State
|
||||
var states: Dictionary[StringName,State] = {}
|
||||
|
||||
func _ready() -> void:
|
||||
for child in get_children():
|
||||
if child is State:
|
||||
states[child.name] = child
|
||||
child.transition.connect(on_transition_required)
|
||||
else:
|
||||
push_warning("Child of state machine is not state")
|
||||
|
||||
func on_transition_required(to: StringName):
|
||||
if states.has(to) == false:
|
||||
push_warning("Incorrect state request: " + to)
|
||||
return
|
||||
|
||||
current_state.exit()
|
||||
current_state = states[to]
|
||||
current_state.enter()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.update(delta)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
push_error("State is not set")
|
||||
return
|
||||
current_state.physics_update(delta)
|
||||
1
scritps/state_machine/machine.gd.uid
Normal file
1
scritps/state_machine/machine.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3777rkbebgjm
|
||||
12
scritps/state_machine/state.gd
Normal file
12
scritps/state_machine/state.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
@abstract
|
||||
extends Node
|
||||
|
||||
|
||||
class_name State
|
||||
|
||||
signal transition(to: StringName)
|
||||
|
||||
@abstract func enter() -> void
|
||||
@abstract func exit() -> void
|
||||
@abstract func update(delta: float) -> void
|
||||
@abstract func physics_update(delta: float) -> void
|
||||
1
scritps/state_machine/state.gd.uid
Normal file
1
scritps/state_machine/state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cmsphnymgquwq
|
||||
Loading…
Add table
Add a link
Reference in a new issue