State machine and crosshair
This commit is contained in:
parent
7d30fa63d1
commit
a32ac09b04
12 changed files with 116 additions and 5 deletions
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