mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
Improve style in many demos (#1263)
This commit is contained in:
@@ -3,17 +3,17 @@ extends Node2D
|
||||
|
||||
signal wait_done()
|
||||
|
||||
@export var _enable_debug_collision := true
|
||||
@export var _enable_debug_collision: bool = true
|
||||
|
||||
var _timer: Timer
|
||||
var _timer_started := false
|
||||
var _timer_started: bool = false
|
||||
|
||||
var _wait_physics_ticks_counter := 0
|
||||
var _wait_physics_ticks_counter: int = 0
|
||||
|
||||
class Circle2D:
|
||||
extends Node2D
|
||||
var center := Vector2()
|
||||
var radius := 0.0
|
||||
var radius: float = 0.0
|
||||
var color := Color()
|
||||
|
||||
func _draw() -> void:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Node
|
||||
|
||||
var _tests := [
|
||||
var _tests: Array[Dictionary] = [
|
||||
{
|
||||
"id": "Functional Tests/Shapes",
|
||||
"path": "res://tests/functional/test_shapes.tscn",
|
||||
@@ -58,5 +58,5 @@ var _tests := [
|
||||
|
||||
func _ready() -> void:
|
||||
var test_menu: OptionMenu = $TestsMenu
|
||||
for test: Variant in _tests:
|
||||
for test: Dictionary in _tests:
|
||||
test_menu.add_test(test.id, test.path)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class_name TestCharacter
|
||||
extends Test
|
||||
|
||||
|
||||
enum BodyType {
|
||||
CHARACTER_BODY,
|
||||
CHARACTER_BODY_RAY,
|
||||
@@ -20,19 +21,19 @@ const OPTION_MOVE_CHARACTER_CONSTANT_SPEED = "Move Options/Use constant speed (C
|
||||
|
||||
@export var _initial_velocity := Vector2.ZERO
|
||||
@export var _constant_velocity := Vector2.ZERO
|
||||
@export var _motion_speed := 400.0
|
||||
@export var _gravity_force := 50.0
|
||||
@export var _jump_force := 1000.0
|
||||
@export var _snap_distance := 0.0
|
||||
@export var _floor_max_angle := 45.0
|
||||
@export var _motion_speed: float = 400.0
|
||||
@export var _gravity_force: float = 50.0
|
||||
@export var _jump_force: float = 1000.0
|
||||
@export var _snap_distance: float = 0.0
|
||||
@export var _floor_max_angle: float = 45.0
|
||||
@export var _body_type := BodyType.CHARACTER_BODY
|
||||
|
||||
@onready var options: OptionMenu = $Options
|
||||
|
||||
var _use_snap := true
|
||||
var _use_stop_on_slope := true
|
||||
var _use_floor_only := true
|
||||
var _use_constant_speed := false
|
||||
var _use_snap: bool = true
|
||||
var _use_stop_on_slope: bool = true
|
||||
var _use_floor_only: bool = true
|
||||
var _use_constant_speed: bool = false
|
||||
|
||||
var _body_parent: Node = null
|
||||
var _character_body_template: CharacterBody2D = null
|
||||
@@ -99,8 +100,8 @@ func _process(_delta: float) -> void:
|
||||
label_floor.visible = false
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var key_event := event as InputEventKey
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
var key_event := input_event as InputEventKey
|
||||
if key_event and not key_event.pressed:
|
||||
if key_event.keycode == KEY_1:
|
||||
if _character_body_template:
|
||||
@@ -180,7 +181,7 @@ func _start_test() -> void:
|
||||
_moving_body.queue_free()
|
||||
_moving_body = null
|
||||
|
||||
var test_label := "Testing: "
|
||||
var test_label: String = "Testing: "
|
||||
|
||||
var template: PhysicsBody2D = null
|
||||
match _body_type:
|
||||
|
||||
@@ -7,12 +7,13 @@ const OPTION_TEST_CASE_DETECT_FLOOR_MOTION_CHANGES = "Test Cases/Floor detection
|
||||
const MOTION_CHANGES_DIR = Vector2(1.0, 1.0)
|
||||
const MOTION_CHANGES_SPEEDS: Array[float] = [0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0]
|
||||
|
||||
var _test_floor_detection := false
|
||||
var _test_motion_changes := false
|
||||
var _floor_detected := false
|
||||
var _floor_lost := false
|
||||
var _test_floor_detection: bool = false
|
||||
var _test_motion_changes: bool = false
|
||||
var _floor_detected: bool = false
|
||||
var _floor_lost: bool = false
|
||||
|
||||
var _failed_reason: String = ""
|
||||
|
||||
var _failed_reason := ""
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
@@ -42,11 +43,11 @@ func _physics_process(delta: float) -> void:
|
||||
#Log.print_log("Velocity: %s" % velocity)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
super._input(event)
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
super._input(input_event)
|
||||
|
||||
if event is InputEventKey and not event.pressed:
|
||||
if event.keycode == KEY_0:
|
||||
if input_event is InputEventKey and not input_event.pressed:
|
||||
if input_event.keycode == KEY_0:
|
||||
await _on_option_selected(OPTION_TEST_CASE_ALL)
|
||||
|
||||
|
||||
@@ -118,7 +119,7 @@ func _test_all() -> void:
|
||||
|
||||
|
||||
func _set_result(test_passed: bool) -> void:
|
||||
var result := ""
|
||||
var result: String = ""
|
||||
if test_passed:
|
||||
result = "PASSED"
|
||||
else:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends TestCharacter
|
||||
|
||||
|
||||
const OPTION_TEST_CASE_ALL = "Test Cases/TEST ALL (0)"
|
||||
const OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID = "Test Cases/Jump through one-way tiles (Rigid Body)"
|
||||
const OPTION_TEST_CASE_JUMP_ONE_WAY_CHARACTER = "Test Cases/Jump through one-way tiles (Character Body)"
|
||||
@@ -7,13 +8,14 @@ const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID = "Test Cases/Jump through one-
|
||||
const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_CHARACTER = "Test Cases/Jump through one-way corner (Character Body)"
|
||||
const OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER = "Test Cases/Fall and pushed on one-way tiles (Character Body)"
|
||||
|
||||
var _test_jump_one_way := false
|
||||
var _test_jump_one_way_corner := false
|
||||
var _test_fall_one_way := false
|
||||
var _test_jump_one_way: bool = false
|
||||
var _test_jump_one_way_corner: bool = false
|
||||
var _test_fall_one_way: bool = false
|
||||
|
||||
var _extra_body: PhysicsBody2D = null
|
||||
|
||||
var _failed_reason := ""
|
||||
var _failed_reason: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
@@ -26,11 +28,11 @@ func _ready() -> void:
|
||||
options.add_menu_item(OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
super._input(event)
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
super._input(input_event)
|
||||
|
||||
if event is InputEventKey and not event.pressed:
|
||||
if event.keycode == KEY_0:
|
||||
if input_event is InputEventKey and not input_event.pressed:
|
||||
if input_event.keycode == KEY_0:
|
||||
await _on_option_selected(OPTION_TEST_CASE_ALL)
|
||||
|
||||
|
||||
@@ -113,7 +115,7 @@ func _test_all() -> void:
|
||||
|
||||
|
||||
func _set_result(test_passed: bool) -> void:
|
||||
var result := ""
|
||||
var result: String = ""
|
||||
if test_passed:
|
||||
result = "PASSED"
|
||||
else:
|
||||
@@ -187,7 +189,7 @@ func _start_fall_one_way() -> void:
|
||||
|
||||
|
||||
func _finalize_jump_one_way() -> void:
|
||||
var passed := true
|
||||
var passed: bool = true
|
||||
if not $JumpTargetArea2D.overlaps_body(_moving_body):
|
||||
passed = false
|
||||
_failed_reason = ": the body wasn't able to jump all the way through."
|
||||
@@ -199,7 +201,7 @@ func _finalize_jump_one_way() -> void:
|
||||
|
||||
|
||||
func _finalize_fall_one_way() -> void:
|
||||
var passed := true
|
||||
var passed: bool = true
|
||||
if $FallTargetArea2D.overlaps_body(_moving_body):
|
||||
passed = false
|
||||
_failed_reason = ": the body was pushed through the one-way collision."
|
||||
|
||||
@@ -19,7 +19,7 @@ const OFFSET_RANGE = 120.0
|
||||
|
||||
@onready var options: OptionMenu = $Options
|
||||
|
||||
var _update_collision := false
|
||||
var _update_collision: bool = false
|
||||
var _collision_test_index := 0
|
||||
var _collision_shapes: Array[Shape2D] = []
|
||||
|
||||
@@ -50,8 +50,8 @@ func _ready() -> void:
|
||||
_update_collision = true
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var key_event := event as InputEventKey
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
var key_event := input_event as InputEventKey
|
||||
if key_event and not key_event.pressed:
|
||||
if key_event.keycode == KEY_1:
|
||||
_on_option_selected(OPTION_TYPE_RECTANGLE)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_JOINT_TYPE = "Joint Type/%s Joint (%d)"
|
||||
|
||||
const OPTION_TEST_CASE_BODIES_COLLIDE = "Test case/Attached bodies collide"
|
||||
@@ -10,27 +11,28 @@ const OPTION_TEST_CASE_CHANGE_POSITIONS = "Test case/Set body positions after ad
|
||||
|
||||
const BOX_SIZE = Vector2(64, 64)
|
||||
|
||||
var _update_joint := false
|
||||
var _update_joint: bool = false
|
||||
var _selected_joint: Joint2D = null
|
||||
|
||||
var _bodies_collide := false
|
||||
var _world_attachement := false
|
||||
var _dynamic_attachement := false
|
||||
var _destroy_body := false
|
||||
var _change_positions := false
|
||||
var _bodies_collide: bool = false
|
||||
var _world_attachement: bool = false
|
||||
var _dynamic_attachement: bool = false
|
||||
var _destroy_body: bool = false
|
||||
var _change_positions: bool = false
|
||||
|
||||
var _joint_types: Dictionary[String, Joint2D] = {}
|
||||
|
||||
var _joint_types := {}
|
||||
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
|
||||
var joints: Node2D = $Joints
|
||||
for joint_index in joints.get_child_count():
|
||||
var joint_node := joints.get_child(joint_index)
|
||||
var joint_node: Joint2D = joints.get_child(joint_index)
|
||||
joint_node.visible = false
|
||||
var joint_name := String(joint_node.name)
|
||||
var joint_short := joint_name.substr(0, joint_name.length() - 7)
|
||||
var option_name := OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
|
||||
var joint_short: String = joint_name.substr(0, joint_name.length() - 7)
|
||||
var option_name: String = OPTION_JOINT_TYPE % [joint_short, joint_index + 1]
|
||||
options.add_menu_item(option_name)
|
||||
_joint_types[option_name] = joint_node
|
||||
|
||||
@@ -54,9 +56,9 @@ func _process(_delta: float) -> void:
|
||||
$LabelJointType.text = "Joint Type: " + String(_selected_joint.name)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and not event.pressed:
|
||||
var joint_index: int = event.keycode - KEY_1
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
if input_event is InputEventKey and not input_event.pressed:
|
||||
var joint_index: int = input_event.keycode - KEY_1
|
||||
if joint_index >= 0 and joint_index < _joint_types.size():
|
||||
_selected_joint = _joint_types.values()[joint_index]
|
||||
_update_joint = true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@tool
|
||||
extends Test
|
||||
|
||||
|
||||
signal all_tests_done()
|
||||
signal test_done()
|
||||
|
||||
@@ -18,23 +19,23 @@ const OPTION_TEST_CASE_MOVING_PLATFORM_CHARACTER = "Test Cases/Moving Platform (
|
||||
const TEST_ALL_ANGLES_STEP = 15.0
|
||||
const TEST_ALL_ANGLES_MAX = 344.0
|
||||
|
||||
@export_range(64, 256, 0.1) var _platform_size := 128.0:
|
||||
@export_range(64, 256, 0.1) var _platform_size: float = 128.0:
|
||||
set(value):
|
||||
if value == _platform_size:
|
||||
return
|
||||
_platform_size = value
|
||||
_update_platform_size(value)
|
||||
|
||||
@export_range(0, 360, 0.1) var _platform_angle := 0.0:
|
||||
@export_range(0, 360, 0.1) var _platform_angle: float = 0.0:
|
||||
set(value):
|
||||
if value == _platform_angle:
|
||||
return
|
||||
_platform_angle = value
|
||||
_update_platform_angle(value)
|
||||
|
||||
@export var _platform_speed := 0.0
|
||||
@export var _platform_speed: float = 0.0
|
||||
|
||||
@export_range(0, 360, 0.1) var _body_angle := 0.0:
|
||||
@export_range(0, 360, 0.1) var _body_angle: float = 0.0:
|
||||
set(value):
|
||||
if value == _body_angle:
|
||||
return
|
||||
@@ -42,7 +43,7 @@ const TEST_ALL_ANGLES_MAX = 344.0
|
||||
_update_rigidbody_angle(value)
|
||||
|
||||
@export var _body_velocity := Vector2(400.0, 0.0)
|
||||
@export var _use_character_body := false
|
||||
@export var _use_character_body: bool = false
|
||||
|
||||
@onready var options: OptionMenu = $Options
|
||||
|
||||
@@ -56,15 +57,15 @@ var _platform_velocity := Vector2.ZERO
|
||||
|
||||
@onready var _target_area: Area2D = $TargetArea2D
|
||||
|
||||
var _contact_detected := false
|
||||
var _target_entered := false
|
||||
var _test_passed := false
|
||||
var _contact_detected: bool = false
|
||||
var _target_entered: bool = false
|
||||
var _test_passed: bool = false
|
||||
var _test_step := 0
|
||||
|
||||
var _test_all_angles := false
|
||||
var _lock_controls := false
|
||||
var _test_all_angles: bool = false
|
||||
var _lock_controls: bool = false
|
||||
|
||||
var _test_canceled := false
|
||||
var _test_canceled: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -124,13 +125,13 @@ func _physics_process(delta: float) -> void:
|
||||
_platform_body.global_position += motion
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventKey and not event.pressed:
|
||||
if event.keycode == KEY_0:
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
if input_event is InputEventKey and not input_event.pressed:
|
||||
if input_event.keycode == KEY_0:
|
||||
await _on_option_selected(OPTION_TEST_CASE_ALL)
|
||||
if event.keycode == KEY_1:
|
||||
if input_event.keycode == KEY_1:
|
||||
await _on_option_selected(OPTION_OBJECT_TYPE_RIGIDBODY)
|
||||
elif event.keycode == KEY_2:
|
||||
elif input_event.keycode == KEY_2:
|
||||
await _on_option_selected(OPTION_OBJECT_TYPE_CHARACTER)
|
||||
|
||||
|
||||
@@ -347,7 +348,7 @@ func _test_all() -> void:
|
||||
|
||||
|
||||
func _start_test() -> void:
|
||||
var test_label := "Testing: "
|
||||
var test_label: String = "Testing: "
|
||||
|
||||
var platform_angle := _platform_template.rotation
|
||||
if _platform_body:
|
||||
@@ -510,7 +511,7 @@ func _on_timeout() -> void:
|
||||
|
||||
|
||||
func _set_result() -> void:
|
||||
var result := ""
|
||||
var result: String = ""
|
||||
if _test_passed:
|
||||
result = "PASSED"
|
||||
$LabelResult.self_modulate = Color.GREEN
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
extends Test
|
||||
|
||||
@export_range(1, 100) var height := 10
|
||||
|
||||
@export_range(1, 100) var height: int = 10
|
||||
@export var box_size := Vector2(40.0, 40.0)
|
||||
@export var box_spacing := Vector2(0.0, 0.0)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_create_pyramid()
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
extends Test
|
||||
|
||||
|
||||
const OPTION_TEST_CASE_HIT_FROM_INSIDE = "Test case/Hit from inside"
|
||||
|
||||
var _hit_from_inside := false
|
||||
var _do_raycasts := false
|
||||
var _hit_from_inside: bool = false
|
||||
var _do_raycasts: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var options: OptionMenu = $Options
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
extends Test
|
||||
|
||||
@export var height := 10
|
||||
@export var width := 1
|
||||
|
||||
@export var height: int = 10
|
||||
@export var width: int = 1
|
||||
@export var box_size := Vector2(40.0, 40.0)
|
||||
@export var box_spacing := Vector2(0.0, 0.0)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_create_stack()
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const BOX_SPACE = Vector2(50, 50)
|
||||
|
||||
var _objects: Array[Node2D] = []
|
||||
|
||||
var _log_physics := false
|
||||
var _log_physics: bool = false
|
||||
var _log_physics_time := 0
|
||||
var _log_physics_time_start := 0
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const OPTION_TYPE_CONCAVE_POLYGON = "Shape type/Concave Polygon"
|
||||
|
||||
var _object_templates: Array[Node2D] = []
|
||||
|
||||
var _log_physics := false
|
||||
var _log_physics: bool = false
|
||||
var _log_physics_time := 0
|
||||
var _log_physics_time_start := 0
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ extends OptionMenu
|
||||
|
||||
|
||||
class TestData:
|
||||
var id := ""
|
||||
var scene_path := ""
|
||||
var id: String = ""
|
||||
var scene_path: String = ""
|
||||
|
||||
|
||||
var _test_list := []
|
||||
@@ -11,6 +11,7 @@ var _test_list := []
|
||||
var _current_test: TestData = null
|
||||
var _current_test_scene: Node = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
option_selected.connect(_on_option_selected)
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ var _jump_force := 1000.0
|
||||
var _velocity := Vector2.ZERO
|
||||
var _snap := 0.0
|
||||
var _floor_max_angle := 45.0
|
||||
var _stop_on_slope := false
|
||||
var _move_on_floor_only := false
|
||||
var _constant_speed := false
|
||||
var _jumping := false
|
||||
var _keep_velocity := false
|
||||
var _stop_on_slope: bool = false
|
||||
var _move_on_floor_only: bool = false
|
||||
var _constant_speed: bool = false
|
||||
var _jumping: bool = false
|
||||
var _keep_velocity: bool = false
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Label
|
||||
|
||||
func _ready() -> void:
|
||||
var engine_name := ""
|
||||
var engine_name: String = ""
|
||||
|
||||
match System.get_physics_engine():
|
||||
System.PhysicsEngine.GODOT_PHYSICS:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Label
|
||||
|
||||
var test_name := "":
|
||||
var test_name: String = "":
|
||||
set(value):
|
||||
if (test_name != value):
|
||||
return
|
||||
|
||||
@@ -10,7 +10,7 @@ func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = fa
|
||||
var path_element_count := path_elements.size()
|
||||
assert(path_element_count > 0)
|
||||
|
||||
var path := ""
|
||||
var path: String = ""
|
||||
var popup := get_popup()
|
||||
for element_index in range(path_element_count - 1):
|
||||
var popup_label := path_elements[element_index]
|
||||
|
||||
@@ -7,9 +7,9 @@ var _gravity_force := 50.0
|
||||
var _jump_force := 1000.0
|
||||
var _velocity := Vector2.ZERO
|
||||
var _floor_max_angle := 45.0
|
||||
var _on_floor := false
|
||||
var _jumping := false
|
||||
var _keep_velocity := false
|
||||
var _on_floor: bool = false
|
||||
var _jumping: bool = false
|
||||
var _keep_velocity: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
gravity_scale = 0.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends RigidBody2D
|
||||
|
||||
var _picked := false
|
||||
var _picked: bool = false
|
||||
var _last_mouse_pos := Vector2.ZERO
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ func _ready() -> void:
|
||||
input_pickable = true
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
var mouse_event := event as InputEventMouseButton
|
||||
func _input(any_input_event: InputEvent) -> void:
|
||||
var mouse_event := any_input_event as InputEventMouseButton
|
||||
if mouse_event and not mouse_event.pressed:
|
||||
_picked = false
|
||||
|
||||
|
||||
func _input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
|
||||
var mouse_event := event as InputEventMouseButton
|
||||
func _input_event(_viewport: Node, any_input_event: InputEvent, _shape_idx: int) -> void:
|
||||
var mouse_event := any_input_event as InputEventMouseButton
|
||||
if mouse_event and mouse_event.pressed:
|
||||
_picked = true
|
||||
_last_mouse_pos = get_global_mouse_position()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends ScrollContainer
|
||||
|
||||
@export var auto_scroll := false
|
||||
@export var auto_scroll: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
var scrollbar := get_v_scroll_bar()
|
||||
|
||||
Reference in New Issue
Block a user