mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 06:09:46 +03:00
Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
extends TileMap
|
||||
|
||||
|
||||
var secret_layer: int # You can have multiple layers if you make this an array.
|
||||
var player_in_secret: bool
|
||||
# You can have multiple layers if you make this an array.
|
||||
var secret_layer := 0
|
||||
var player_in_secret := false
|
||||
var layer_alpha := 1.0
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
for i in get_layers_count(): # Find the secret layer by name.
|
||||
for i in get_layers_count():
|
||||
# Find the secret layer by name.
|
||||
if get_layer_name(i) == "Secret":
|
||||
secret_layer = i
|
||||
|
||||
@@ -19,7 +19,8 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
if player_in_secret:
|
||||
if layer_alpha > 0.3:
|
||||
layer_alpha = move_toward(layer_alpha, 0.3, delta) # Animate the layer transparency.
|
||||
# Animate the layer transparency.
|
||||
layer_alpha = move_toward(layer_alpha, 0.3, delta)
|
||||
set_layer_modulate(secret_layer, Color(1, 1, 1, layer_alpha))
|
||||
else:
|
||||
set_process(false)
|
||||
@@ -32,17 +33,17 @@ func _process(delta: float) -> void:
|
||||
|
||||
|
||||
func _use_tile_data_runtime_update(layer: int, _coords: Vector2i) -> bool:
|
||||
if layer == secret_layer:
|
||||
return true
|
||||
return false
|
||||
return layer == secret_layer
|
||||
|
||||
|
||||
func _tile_data_runtime_update(_layer: int, _coords: Vector2i, tile_data: TileData) -> void:
|
||||
tile_data.set_collision_polygons_count(0, 0) # Remove collision for secret layer.
|
||||
# Remove collision for secret layer.
|
||||
tile_data.set_collision_polygons_count(0, 0)
|
||||
|
||||
|
||||
func _on_secret_detector_body_entered(body: Node2D) -> void:
|
||||
if not body is CharacterBody2D: # Detect player only.
|
||||
if not body is CharacterBody2D:
|
||||
# Detect the player only.
|
||||
return
|
||||
|
||||
player_in_secret = true
|
||||
|
||||
Reference in New Issue
Block a user