mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
Improve style in many demos (#1263)
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
extends Camera3D
|
||||
|
||||
|
||||
const ROTATION_COEFF = 0.02
|
||||
|
||||
var _rotation_enabled := false
|
||||
var _rotation_enabled: bool = false
|
||||
var _rotation_pivot: Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_initialize_pivot.call_deferred()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = event.pressed
|
||||
func _unhandled_input(input_event: InputEvent) -> void:
|
||||
if input_event is InputEventMouseButton:
|
||||
if input_event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
_rotation_enabled = input_event.pressed
|
||||
|
||||
return
|
||||
|
||||
if not _rotation_enabled:
|
||||
return
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
var rotation_delta: float = event.screen_relative.x
|
||||
if input_event is InputEventMouseMotion:
|
||||
var rotation_delta: float = input_event.screen_relative.x
|
||||
_rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF)
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var _stop_on_slopes := false
|
||||
@export var use_snap := false
|
||||
|
||||
var _gravity := 20.0
|
||||
@export var _stop_on_slopes: bool = false
|
||||
@export var use_snap: bool = false
|
||||
|
||||
var _gravity: float = 20.0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Control
|
||||
|
||||
|
||||
const MAX_ENTRIES = 100
|
||||
|
||||
var _entry_template: Label
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
extends Control
|
||||
|
||||
|
||||
@export var world_offset := Vector3.ZERO
|
||||
|
||||
var _pos_offset: Vector2
|
||||
var _attachment: Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_pos_offset = position
|
||||
_attachment = get_parent()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var engine_name := ""
|
||||
var engine_name: String = ""
|
||||
match System.get_physics_engine():
|
||||
System.PhysicsEngine.GODOT_PHYSICS:
|
||||
engine_name = "GodotPhysics 3D"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
text = "%d FPS (%.2f mspf)" % [Engine.get_frames_per_second(), 1000.0 / Engine.get_frames_per_second()]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
visible = get_tree().paused
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
extends Label
|
||||
|
||||
var test_name := "":
|
||||
|
||||
var test_name: String = "":
|
||||
set(value):
|
||||
if (test_name != value):
|
||||
return
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Label
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
set_text("Godot Version: %s" % Engine.get_version_info().string)
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
class_name OptionMenu
|
||||
extends MenuButton
|
||||
|
||||
|
||||
signal option_selected(item_path: String)
|
||||
signal option_changed(item_path: String, checked: bool)
|
||||
|
||||
|
||||
func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = false) -> void:
|
||||
var path_elements := item_path.split("/", false)
|
||||
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 path_element_count - 1:
|
||||
var popup_label := path_elements[element_index]
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
extends RigidBody3D
|
||||
|
||||
var _dir := 1.0
|
||||
var _distance := 10.0
|
||||
var _walk_spd := 100.0
|
||||
var _acceleration := 22.0
|
||||
var _is_on_floor := false
|
||||
|
||||
var _dir: float = 1.0 # -1.0 or 1.0
|
||||
var _distance: float = 10.0
|
||||
var _walk_spd: float = 100.0
|
||||
var _acceleration: float = 22.0
|
||||
var _is_on_floor: bool = false
|
||||
|
||||
@onready var _forward := -transform.basis.z
|
||||
@onready var _collision_shape := $CollisionShape
|
||||
@onready var _material: StandardMaterial3D = $CollisionShape/MeshInstance3D.get_active_material(0)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not _material:
|
||||
_material = StandardMaterial3D.new()
|
||||
@@ -24,20 +26,20 @@ func _process(_delta: float) -> void:
|
||||
|
||||
|
||||
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||
var delta := state.step
|
||||
var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
|
||||
var delta: float = state.step
|
||||
var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP)
|
||||
state.linear_velocity = state.linear_velocity.move_toward(velocity, _acceleration * delta)
|
||||
|
||||
if state.transform.origin.z < -_distance:
|
||||
_dir = -1
|
||||
_dir = -1.0
|
||||
if state.transform.origin.z > _distance:
|
||||
_dir = 1
|
||||
_dir = 1.0
|
||||
|
||||
ground_check()
|
||||
|
||||
|
||||
func ground_check() -> void:
|
||||
var space_state := get_world_3d().direct_space_state
|
||||
var space_state: PhysicsDirectSpaceState3D = get_world_3d().direct_space_state
|
||||
var shape := PhysicsShapeQueryParameters3D.new()
|
||||
shape.transform = _collision_shape.global_transform
|
||||
shape.shape_rid = _collision_shape.shape.get_rid()
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
extends RigidBody3D
|
||||
|
||||
const MOUSE_DELTA_COEFFICIENT = 0.01
|
||||
const CAMERA_DISTANCE_COEFFICIENT = 0.2
|
||||
|
||||
var _picked := false
|
||||
const MOUSE_DELTA_COEFFICIENT: float = 0.01
|
||||
const CAMERA_DISTANCE_COEFFICIENT: float = 0.2
|
||||
|
||||
var _picked: bool = false
|
||||
var _last_mouse_pos := Vector2.ZERO
|
||||
var _mouse_pos := Vector2.ZERO
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
input_ray_pickable = true
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if not event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
func _input(any_input_event: InputEvent) -> void:
|
||||
if any_input_event is InputEventMouseButton:
|
||||
if not any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = false
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
_mouse_pos = event.position
|
||||
if any_input_event is InputEventMouseMotion:
|
||||
_mouse_pos = any_input_event.position
|
||||
|
||||
|
||||
func _input_event(_camera: Camera3D, event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
func _input_event(_camera: Camera3D, any_input_event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void:
|
||||
if any_input_event is InputEventMouseButton:
|
||||
if any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_picked = true
|
||||
_mouse_pos = event.position
|
||||
_mouse_pos = any_input_event.position
|
||||
_last_mouse_pos = _mouse_pos
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
extends ScrollContainer
|
||||
|
||||
@export var auto_scroll := false
|
||||
|
||||
@export var auto_scroll: bool = false
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if auto_scroll:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Node
|
||||
|
||||
|
||||
enum PhysicsEngine {
|
||||
GODOT_PHYSICS,
|
||||
JOLT_PHYSICS,
|
||||
@@ -8,6 +9,7 @@ enum PhysicsEngine {
|
||||
|
||||
var _engine := PhysicsEngine.OTHER
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Node
|
||||
|
||||
|
||||
enum LogType {
|
||||
LOG,
|
||||
ERROR,
|
||||
@@ -7,6 +8,7 @@ enum LogType {
|
||||
|
||||
signal entry_logged(message: String, type: LogType)
|
||||
|
||||
|
||||
func print_log(message: String) -> void:
|
||||
print(message)
|
||||
entry_logged.emit(message, LogType.LOG)
|
||||
|
||||
Reference in New Issue
Block a user