mirror of
https://github.com/Nokorpo/LibreAim.git
synced 2025-06-10 18:10:50 +09:00
Refactors for #14
This commit is contained in:
parent
c6fddf8e14
commit
cf28cfe793
13 changed files with 78 additions and 75 deletions
|
@ -4,7 +4,7 @@ signal destroyed
|
||||||
|
|
||||||
@onready var _mesh_instance := $CollisionShape3D/MeshInstance3D
|
@onready var _mesh_instance := $CollisionShape3D/MeshInstance3D
|
||||||
|
|
||||||
var current_velocity = null
|
var _current_velocity: Vector3 = Vector3.ZERO
|
||||||
var max_health: float
|
var max_health: float
|
||||||
var health: float = 0.0:
|
var health: float = 0.0:
|
||||||
set(value):
|
set(value):
|
||||||
|
@ -19,10 +19,10 @@ func _ready() -> void:
|
||||||
_set_target_material()
|
_set_target_material()
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if current_velocity:
|
if _current_velocity != Vector3.ZERO:
|
||||||
var collision_info = move_and_collide(current_velocity * delta)
|
var collision_info = move_and_collide(_current_velocity * delta)
|
||||||
if collision_info:
|
if collision_info:
|
||||||
current_velocity = current_velocity.bounce(collision_info.get_normal())
|
_current_velocity = _current_velocity.bounce(collision_info.get_normal())
|
||||||
|
|
||||||
func init(size = {"radius": .5, "height": 1}, movement = {"x": 0, "y": 0}) -> void:
|
func init(size = {"radius": .5, "height": 1}, movement = {"x": 0, "y": 0}) -> void:
|
||||||
await ready
|
await ready
|
||||||
|
@ -31,7 +31,7 @@ func init(size = {"radius": .5, "height": 1}, movement = {"x": 0, "y": 0}) -> vo
|
||||||
collision_shape.shape.height = size.height
|
collision_shape.shape.height = size.height
|
||||||
_mesh_instance.mesh.radius = size.radius
|
_mesh_instance.mesh.radius = size.radius
|
||||||
_mesh_instance.mesh.height = size.height
|
_mesh_instance.mesh.height = size.height
|
||||||
current_velocity = Vector3(randf_range(-movement.x, movement.x),\
|
_current_velocity = Vector3(randf_range(-movement.x, movement.x),\
|
||||||
randf_range(-movement.y, movement.y), 0)
|
randf_range(-movement.y, movement.y), 0)
|
||||||
|
|
||||||
func _set_health() -> void:
|
func _set_health() -> void:
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://baj568pnwc4ph"]
|
[gd_scene load_steps=8 format=3 uid="uid://baj568pnwc4ph"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/game_world/target.gd" id="1_mc4da"]
|
[ext_resource type="Script" path="res://scenes/enemies/target.gd" id="1_nte11"]
|
||||||
[ext_resource type="Script" path="res://scenes/enemies/health_slider.gd" id="2_usxmj"]
|
[ext_resource type="Script" path="res://scenes/enemies/health_slider.gd" id="2_usxmj"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_do5mn"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_do5mn"]
|
||||||
|
@ -28,7 +28,7 @@ size = Vector2(3, 0.3)
|
||||||
[node name="Target" type="CharacterBody3D" groups=["Enemy"]]
|
[node name="Target" type="CharacterBody3D" groups=["Enemy"]]
|
||||||
collision_mask = 2
|
collision_mask = 2
|
||||||
motion_mode = 1
|
motion_mode = 1
|
||||||
script = ExtResource("1_mc4da")
|
script = ExtResource("1_nte11")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
shape = SubResource("CapsuleShape3D_do5mn")
|
shape = SubResource("CapsuleShape3D_do5mn")
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
extends Control
|
extends Control
|
||||||
## Renders the user crosshair
|
## Renders the user crosshair
|
||||||
|
|
||||||
var color := Color(0, 255, 255, 1)
|
var _color := Color(0, 255, 255, 1)
|
||||||
var outline_color := Color(0,0,0)
|
var _outline_color := Color(0,0,0)
|
||||||
|
|
||||||
var enable_outline := true
|
var _enable_outline := true
|
||||||
var dot_enable := false
|
var _dot_enable := false
|
||||||
|
|
||||||
var dot_size := 6.0
|
var _dot_size := 6.0
|
||||||
var outline_width := 1.0
|
var _outline_width := 1.0
|
||||||
var thickness := 2.0
|
var _thickness := 2.0
|
||||||
var length := 12.0
|
var _length := 12.0
|
||||||
var gap := 5.0
|
var _gap := 5.0
|
||||||
|
|
||||||
var current_crosshair := {
|
var current_crosshair := {
|
||||||
"top": [],
|
"top": [],
|
||||||
|
@ -29,7 +29,7 @@ func _draw() -> void:
|
||||||
_draw_part(current_crosshair["right"])
|
_draw_part(current_crosshair["right"])
|
||||||
_draw_part(current_crosshair["bottom"])
|
_draw_part(current_crosshair["bottom"])
|
||||||
_draw_part(current_crosshair["left"])
|
_draw_part(current_crosshair["left"])
|
||||||
if dot_enable:
|
if _dot_enable:
|
||||||
_draw_part(current_crosshair["dot"])
|
_draw_part(current_crosshair["dot"])
|
||||||
|
|
||||||
func _on_options_refresh_crosshair() -> void:
|
func _on_options_refresh_crosshair() -> void:
|
||||||
|
@ -37,57 +37,57 @@ func _on_options_refresh_crosshair() -> void:
|
||||||
|
|
||||||
func _load_save() -> void:
|
func _load_save() -> void:
|
||||||
var category = DataManager.categories.CROSSHAIR
|
var category = DataManager.categories.CROSSHAIR
|
||||||
dot_enable = DataManager.set_parameter_if_exists(category, dot_enable, "dot")
|
_dot_enable = DataManager.set_parameter_if_exists(category, _dot_enable, "dot")
|
||||||
dot_size = DataManager.set_parameter_if_exists(category, dot_size, "dot_size")
|
_dot_size = DataManager.set_parameter_if_exists(category, _dot_size, "dot_size")
|
||||||
length = DataManager.set_parameter_if_exists(category, length, "length")
|
_length = DataManager.set_parameter_if_exists(category, _length, "length")
|
||||||
thickness = DataManager.set_parameter_if_exists(category, thickness, "thickness")
|
_thickness = DataManager.set_parameter_if_exists(category, _thickness, "thickness")
|
||||||
gap = DataManager.set_parameter_if_exists(category, gap, "gap")
|
_gap = DataManager.set_parameter_if_exists(category, _gap, "gap")
|
||||||
enable_outline = DataManager.set_parameter_if_exists(category, enable_outline, "outline_enable")
|
_enable_outline = DataManager.set_parameter_if_exists(category, _enable_outline, "outline_enable")
|
||||||
outline_width = DataManager.set_parameter_if_exists(category, outline_width, "outline_width")
|
_outline_width = DataManager.set_parameter_if_exists(category, _outline_width, "outline_width")
|
||||||
color = DataManager.set_color_if_exists(category, color, "color")
|
_color = DataManager.set_color_if_exists(category, _color, "color")
|
||||||
outline_color = DataManager.set_color_if_exists(category, outline_color, "outline_color")
|
_outline_color = DataManager.set_color_if_exists(category, _outline_color, "outline_color")
|
||||||
|
|
||||||
func _load_crosshair() -> void:
|
func _load_crosshair() -> void:
|
||||||
current_crosshair["dot"] = [
|
current_crosshair["dot"] = [
|
||||||
Vector2(-dot_size, -dot_size), # top left
|
Vector2(-_dot_size, -_dot_size), # top left
|
||||||
Vector2(dot_size, -dot_size), # top right
|
Vector2(_dot_size, -_dot_size), # top right
|
||||||
Vector2(dot_size, dot_size), # bottom right
|
Vector2(_dot_size, _dot_size), # bottom right
|
||||||
Vector2(-dot_size, dot_size) # bottom left
|
Vector2(-_dot_size, _dot_size) # bottom left
|
||||||
]
|
]
|
||||||
current_crosshair["left"] = [
|
current_crosshair["left"] = [
|
||||||
Vector2(-length-gap, -thickness), # top left
|
Vector2(-_length -_gap, -_thickness), # top left
|
||||||
Vector2(-gap, -thickness), # top right
|
Vector2(-_gap, -_thickness), # top right
|
||||||
Vector2(-gap, thickness), # bottom right
|
Vector2(-_gap, _thickness), # bottom right
|
||||||
Vector2(-length-gap, thickness) # bottom left
|
Vector2(-_length -_gap, _thickness) # bottom left
|
||||||
]
|
]
|
||||||
current_crosshair["top"] = [
|
current_crosshair["top"] = [
|
||||||
Vector2(-thickness, -length-gap), # top left
|
Vector2(-_thickness, -_length -_gap), # top left
|
||||||
Vector2(thickness, -length-gap), # top right
|
Vector2(_thickness, -_length -_gap), # top right
|
||||||
Vector2(thickness, -gap), # bottom right
|
Vector2(_thickness, -_gap), # bottom right
|
||||||
Vector2(-thickness, -gap) # bottom left
|
Vector2(-_thickness, -_gap) # bottom left
|
||||||
]
|
]
|
||||||
current_crosshair["right"] = [
|
current_crosshair["right"] = [
|
||||||
Vector2(gap,-thickness), # top left
|
Vector2(_gap, -_thickness), # top left
|
||||||
Vector2(length+gap,-thickness), # top right
|
Vector2(_length + _gap, -_thickness), # top right
|
||||||
Vector2(length+gap,thickness), # bottom right
|
Vector2(_length +_gap, _thickness), # bottom right
|
||||||
Vector2(gap,thickness) # bottom left
|
Vector2(_gap, _thickness) # bottom left
|
||||||
]
|
]
|
||||||
current_crosshair["bottom"] = [
|
current_crosshair["bottom"] = [
|
||||||
Vector2(-thickness, gap), # top left
|
Vector2(-_thickness, _gap), # top left
|
||||||
Vector2(thickness,gap), # top right
|
Vector2(_thickness, _gap), # top right
|
||||||
Vector2(thickness,gap+length), # bottom right
|
Vector2(_thickness, _gap + _length), # bottom right
|
||||||
Vector2(-thickness,gap+length) # bottom left
|
Vector2(-_thickness, _gap + _length) # bottom left
|
||||||
]
|
]
|
||||||
|
|
||||||
func _draw_part(points: PackedVector2Array) -> void:
|
func _draw_part(points: PackedVector2Array) -> void:
|
||||||
draw_polygon(points, [color])
|
draw_polygon(points, [_color])
|
||||||
var polygon := Polygon2D.new()
|
var polygon := Polygon2D.new()
|
||||||
polygon.set_polygon(points)
|
polygon.set_polygon(points)
|
||||||
if enable_outline:
|
if _enable_outline:
|
||||||
_draw_outline(polygon)
|
_draw_outline(polygon)
|
||||||
|
|
||||||
func _draw_outline(polygon: Polygon2D) -> void:
|
func _draw_outline(polygon: Polygon2D) -> void:
|
||||||
var poly = polygon.get_polygon()
|
var poly = polygon.get_polygon()
|
||||||
for i in range(1 , poly.size()):
|
for i in range(1 , poly.size()):
|
||||||
draw_line(poly[i-1] , poly[i], outline_color , outline_width)
|
draw_line(poly[i-1] , poly[i], _outline_color , _outline_width)
|
||||||
draw_line(poly[poly.size() - 1] , poly[0], outline_color , outline_width)
|
draw_line(poly[poly.size() - 1] , poly[0], _outline_color , _outline_width)
|
||||||
|
|
|
@ -11,5 +11,5 @@ func set_score(score: int, high_score: int, missed_shots: int) -> void:
|
||||||
text += "\nShots missed: " + str(missed_shots)
|
text += "\nShots missed: " + str(missed_shots)
|
||||||
$Score.text = text
|
$Score.text = text
|
||||||
|
|
||||||
func _on_button_pressed():
|
func _on_button_pressed() -> void:
|
||||||
get_tree().change_scene_to_file("res://scenes/main_menu/main_menu.tscn")
|
get_tree().change_scene_to_file("res://scenes/main_menu/main_menu.tscn")
|
||||||
|
|
|
@ -69,7 +69,7 @@ func _spawn_initial_targets():
|
||||||
_spawn_target()
|
_spawn_target()
|
||||||
|
|
||||||
func _update_world_appareance() -> void:
|
func _update_world_appareance() -> void:
|
||||||
var world_material: StandardMaterial3D = preload("res://assets/images/mat_filldummy.tres")
|
var world_material: StandardMaterial3D = preload("res://assets/material_default.tres")
|
||||||
world_material.albedo_texture = Global.get_current_world_texture()
|
world_material.albedo_texture = Global.get_current_world_texture()
|
||||||
const CATEGORY = DataManager.categories.SETTINGS
|
const CATEGORY = DataManager.categories.SETTINGS
|
||||||
$DirectionalLight3D.light_color = DataManager.set_color_if_exists(CATEGORY, \
|
$DirectionalLight3D.light_color = DataManager.set_color_if_exists(CATEGORY, \
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=31 format=3 uid="uid://cdbhv0p0jfr75"]
|
[gd_scene load_steps=31 format=3 uid="uid://cdbhv0p0jfr75"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/game_world/game_world.gd" id="1_4pv4x"]
|
[ext_resource type="Script" path="res://scenes/game_world/game_world.gd" id="1_4pv4x"]
|
||||||
[ext_resource type="Material" uid="uid://dsqe2mx1kgicf" path="res://assets/images/mat_filldummy.tres" id="2_ldkna"]
|
[ext_resource type="Material" uid="uid://dsqe2mx1kgicf" path="res://assets/material_default.tres" id="2_ldkna"]
|
||||||
[ext_resource type="Script" path="res://scenes/game_world/player/player_manager.gd" id="3_cvlpu"]
|
[ext_resource type="Script" path="res://scenes/game_world/player/player_manager.gd" id="3_cvlpu"]
|
||||||
[ext_resource type="Script" path="res://scenes/game_world/crosshair.gd" id="4_pc15u"]
|
[ext_resource type="Script" path="res://scenes/game_world/crosshair.gd" id="4_pc15u"]
|
||||||
[ext_resource type="Script" path="res://scenes/game_world/gameplay_ui.gd" id="5_of43n"]
|
[ext_resource type="Script" path="res://scenes/game_world/gameplay_ui.gd" id="5_of43n"]
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
extends Control
|
extends Control
|
||||||
## Gameplay UI with game stats
|
## Gameplay UI with game stats
|
||||||
|
|
||||||
@onready var animation_kill = $AnimationKill
|
@onready var _animation_kill = $AnimationKill
|
||||||
@onready var kills = $MarginContainer/Panel/MarginContainer/VBoxContainer/targets/label2
|
@onready var _kills = $MarginContainer/Panel/MarginContainer/VBoxContainer/targets/label2
|
||||||
@onready var timer = $"../../Timer"
|
@onready var _timer = $"../../Timer"
|
||||||
@onready var timer_label = $MarginContainer/Panel/MarginContainer/VBoxContainer/time/label2
|
@onready var _timer_label = $MarginContainer/Panel/MarginContainer/VBoxContainer/time/label2
|
||||||
|
|
||||||
func update_kills(value: int) -> void:
|
func update_kills(value: int) -> void:
|
||||||
kills.set_text((str(value)))
|
_kills.set_text((str(value)))
|
||||||
if not animation_kill.is_playing():
|
if not _animation_kill.is_playing():
|
||||||
animation_kill.play("kill")
|
_animation_kill.play("kill")
|
||||||
|
|
||||||
func update_timer_ui(time_left) -> void:
|
func update_timer_ui(time_left) -> void:
|
||||||
timer_label.set_text("%.f s" % time_left)
|
_timer_label.set_text("%.f s" % time_left)
|
||||||
|
|
||||||
func _on_player_shoot() -> void:
|
func _on_player_shoot() -> void:
|
||||||
if timer.is_stopped():
|
if _timer.is_stopped():
|
||||||
timer.start()
|
_timer.start()
|
||||||
$PressAny.queue_free()
|
$PressAny.queue_free()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extends Control
|
extends Control
|
||||||
## Main menu manager
|
## Main menu manager
|
||||||
|
|
||||||
@onready var right_panel := $RightControl
|
@onready var _right_panel := $RightControl
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$LeftControl/VBoxContainer/Play.grab_focus()
|
$LeftControl/VBoxContainer/Play.grab_focus()
|
||||||
|
@ -9,19 +9,19 @@ func _ready() -> void:
|
||||||
|
|
||||||
func _on_play_pressed() -> void:
|
func _on_play_pressed() -> void:
|
||||||
_hide_options()
|
_hide_options()
|
||||||
right_panel.get_node("SelectGamemode").visible = true
|
_right_panel.get_node("SelectGamemode").visible = true
|
||||||
|
|
||||||
func _on_quit_pressed() -> void:
|
func _on_quit_pressed() -> void:
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
func _on_settings_pressed() -> void:
|
func _on_settings_pressed() -> void:
|
||||||
_hide_options()
|
_hide_options()
|
||||||
right_panel.get_node("Settings").visible = true
|
_right_panel.get_node("Settings").visible = true
|
||||||
|
|
||||||
func _on_source_code_pressed() -> void:
|
func _on_source_code_pressed() -> void:
|
||||||
OS.shell_open("https://github.com/antimundo/libre-aim")
|
OS.shell_open("https://github.com/antimundo/libre-aim")
|
||||||
|
|
||||||
## Hide all right panel options
|
## Hide all right panel options
|
||||||
func _hide_options() -> void:
|
func _hide_options() -> void:
|
||||||
for child in right_panel.get_children():
|
for child in _right_panel.get_children():
|
||||||
child.visible = false
|
child.visible = false
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
extends Control
|
extends Control
|
||||||
## Gamemode selection in main menu
|
## Gamemode selection in main menu
|
||||||
|
|
||||||
func _on_play_pressed() -> void:
|
|
||||||
_start_gamemode()
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_add_gamemode_buttons()
|
_add_gamemode_buttons()
|
||||||
_select_gamemode("random")
|
_select_gamemode("random")
|
||||||
|
|
||||||
|
func _on_play_pressed() -> void:
|
||||||
|
_start_gamemode()
|
||||||
|
|
||||||
## Adds the gamemodes button list
|
## Adds the gamemodes button list
|
||||||
func _add_gamemode_buttons() -> void:
|
func _add_gamemode_buttons() -> void:
|
||||||
var gamemode_list := $ListGamemodes/Gamemodes
|
var gamemode_list := $ListGamemodes/Gamemodes
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extends VBoxContainer
|
extends VBoxContainer
|
||||||
|
## FPS limit settings
|
||||||
|
|
||||||
@onready var fps_limit_slider = $FPSLimitSlider
|
@onready var fps_limit_slider = $FPSLimitSlider
|
||||||
@onready var fps_limit_label = $FPSLimitLabel
|
@onready var fps_limit_label = $FPSLimitLabel
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extends HBoxContainer
|
extends HBoxContainer
|
||||||
|
## FPS Overlay settings
|
||||||
|
|
||||||
@onready var fps_overlay_checkbox = $FPSOverlayCheckBox
|
@onready var fps_overlay_checkbox = $FPSOverlayCheckBox
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
@tool
|
@tool
|
||||||
extends Node
|
extends Node
|
||||||
|
## A component to make settings options
|
||||||
|
|
||||||
signal change_value(value)
|
signal change_value(value: float)
|
||||||
signal toggle_checkbox(value)
|
signal toggle_checkbox(value: bool)
|
||||||
|
|
||||||
@export var label_text := "Label":
|
@export var label_text := "Label":
|
||||||
set(new_value):
|
set(new_value):
|
||||||
|
@ -44,11 +45,11 @@ signal toggle_checkbox(value)
|
||||||
|
|
||||||
@onready var slider = $Slider
|
@onready var slider = $Slider
|
||||||
|
|
||||||
func _on_spin_box_value_changed(new_value):
|
func _on_spin_box_value_changed(new_value: float) -> void:
|
||||||
value = new_value
|
value = new_value
|
||||||
|
|
||||||
func _on_slider_value_changed(new_value):
|
func _on_slider_value_changed(new_value: float) -> void:
|
||||||
value = new_value
|
value = new_value
|
||||||
|
|
||||||
func _on_check_box_toggled(button_pressed):
|
func _on_check_box_toggled(button_pressed: bool) -> void:
|
||||||
toggle_checkbox.emit(button_pressed)
|
toggle_checkbox.emit(button_pressed)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue