mirror of
https://github.com/GDQuest/godot-platformer-2d.git
synced 2026-01-23 02:14:19 +00:00
Use the "name :=" notation for type inference instead of "name: ="
This is the official GDScript guideline.
This commit is contained in:
parent
a281242b16
commit
92f8d67dc4
64 changed files with 281 additions and 281 deletions
|
|
@ -4,8 +4,8 @@ extends Control
|
|||
signal packed_scene_button_created(button)
|
||||
onready var grid_container: GridContainer = $VBoxContainer/GridContainer
|
||||
|
||||
const PackedSceneButtonScene: = preload("res://addons/level_design_dock/PackedSceneButton.tscn")
|
||||
const PackedSceneButton: = preload("res://addons/level_design_dock/PackedSceneButton.gd")
|
||||
const PackedSceneButtonScene := preload("res://addons/level_design_dock/PackedSceneButton.tscn")
|
||||
const PackedSceneButton := preload("res://addons/level_design_dock/PackedSceneButton.gd")
|
||||
|
||||
func drop_data(position: Vector2, data: Dictionary) -> void:
|
||||
for packed_scene_path in get_valid_files(data["files"]):
|
||||
|
|
@ -13,14 +13,14 @@ func drop_data(position: Vector2, data: Dictionary) -> void:
|
|||
|
||||
|
||||
func can_drop_data(position: Vector2, data: Dictionary) -> bool:
|
||||
var can_drop: = false
|
||||
var can_drop := false
|
||||
if data["type"] == "files":
|
||||
can_drop = get_valid_files(data["files"]).size() > 0
|
||||
return can_drop
|
||||
|
||||
|
||||
func create_packed_scene_button(packed_scene_path: String) -> void:
|
||||
var new_button: = PackedSceneButtonScene.instance() as PackedSceneButton
|
||||
var new_button := PackedSceneButtonScene.instance() as PackedSceneButton
|
||||
new_button.packed_scene = load(packed_scene_path)
|
||||
new_button.text = packed_scene_path.get_file().trim_suffix(".tscn")
|
||||
grid_container.add_child(new_button)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
tool
|
||||
extends EditorPlugin
|
||||
|
||||
const LevelDesignDockScene: = preload("res://addons/level_design_dock/LevelDesignDock.tscn")
|
||||
const LevelDesignDock: = preload("res://addons/level_design_dock/LevelDesignDock.gd")
|
||||
const PackedSceneButton: = preload("res://addons/level_design_dock/PackedSceneButton.gd")
|
||||
const LevelDesignDockScene := preload("res://addons/level_design_dock/LevelDesignDock.tscn")
|
||||
const LevelDesignDock := preload("res://addons/level_design_dock/LevelDesignDock.gd")
|
||||
const PackedSceneButton := preload("res://addons/level_design_dock/PackedSceneButton.gd")
|
||||
|
||||
var _interface: LevelDesignDock
|
||||
var _current_instance: Node2D setget _set_current_instance
|
||||
|
|
@ -28,7 +28,7 @@ func handles(object: Object) -> bool:
|
|||
|
||||
|
||||
func forward_canvas_gui_input(event: InputEvent) -> bool:
|
||||
var forward: = false
|
||||
var forward := false
|
||||
if event is InputEventMouseMotion:
|
||||
_move_instance()
|
||||
elif event is InputEventMouseButton:
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ onready var hook_target: Area2D = $HookTarget
|
|||
onready var body: Node2D = $Body
|
||||
onready var hitbox: Area2D = $Hitbox
|
||||
|
||||
export var can_be_hooked_while_stunned: = false
|
||||
export var move_speed: = 200
|
||||
export var direction: = -1
|
||||
export var can_be_hooked_while_stunned := false
|
||||
export var move_speed := 200
|
||||
export var direction := -1
|
||||
|
||||
func _ready() -> void:
|
||||
if can_be_hooked_while_stunned:
|
||||
|
|
@ -18,4 +18,4 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func get_collider() -> CollisionShape2D:
|
||||
return collider
|
||||
return collider
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ onready var hook_target: HookTarget = $HookTarget
|
|||
onready var collider: CollisionShape2D = $CollisionShape2D
|
||||
onready var body: Node2D = $Body
|
||||
|
||||
export(int, 0, 360, 1) var jump_angle_left: = 45
|
||||
export(int, 0, 360, 1) var jump_angle_right: = 45
|
||||
export var jump_power_left: = 500
|
||||
export var jump_power_right: = 500
|
||||
export(int, -1, 1, 2) var direction: = 1
|
||||
export var gravity: = 6000.0
|
||||
export(int, 0, 360, 1) var jump_angle_left := 45
|
||||
export(int, 0, 360, 1) var jump_angle_right := 45
|
||||
export var jump_power_left := 500
|
||||
export var jump_power_right := 500
|
||||
export(int, -1, 1, 2) var direction := 1
|
||||
export var gravity := 6000.0
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func initialize(grid : TileMap, obstacle_tile_ids : Array) -> void:
|
|||
_obstacles.append(cell)
|
||||
|
||||
# Find all walkable cells and store them in an array
|
||||
var points_array : = []
|
||||
var points_array := []
|
||||
for y in range(_y_min, _y_max):
|
||||
for x in range(_x_min, _x_max):
|
||||
var point = Vector2(x, y)
|
||||
|
|
@ -48,12 +48,12 @@ func initialize(grid : TileMap, obstacle_tile_ids : Array) -> void:
|
|||
var point_index = calculate_point_index(point)
|
||||
for y in range(0, 3):
|
||||
for x in range(0, 3):
|
||||
var point_relative: = Vector2(point.x + x - 1, point.y + y - 1)
|
||||
var point_relative := Vector2(point.x + x - 1, point.y + y - 1)
|
||||
|
||||
#only connect south-north and west-east, no diagonals
|
||||
if point_relative.x != point.x and point_relative.y != point.y:
|
||||
continue
|
||||
var point_relative_index: = calculate_point_index(point_relative)
|
||||
var point_relative_index := calculate_point_index(point_relative)
|
||||
|
||||
if (point_relative != point and not is_outside_map_bounds(point_relative)
|
||||
and astar.has_point(point_relative_index)):
|
||||
|
|
@ -77,4 +77,4 @@ func find_path(start : Vector2, end : Vector2) -> PoolVector3Array:
|
|||
# in grid coordinates
|
||||
var start_index = calculate_point_index(start)
|
||||
var end_index = calculate_point_index(end)
|
||||
return astar.get_point_path(start_index, end_index)
|
||||
return astar.get_point_path(start_index, end_index)
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@ extends KinematicBody2D
|
|||
# Detects gaps and walls, and turns around instead of getting stuck or falling in holes.
|
||||
|
||||
|
||||
const ARRIVE_THRESHOLD: = 3.0
|
||||
const ARRIVE_THRESHOLD := 3.0
|
||||
|
||||
onready var floor_detector: RayCast2D = $Pivot/FloorDetector
|
||||
onready var pivot: Position2D = $Pivot
|
||||
onready var timer: Timer = $Timer
|
||||
|
||||
export var speed: = 300.0
|
||||
export var gravity: = 1000.0
|
||||
export var speed := 300.0
|
||||
export var gravity := 1000.0
|
||||
|
||||
var waypoints: = {}
|
||||
var waypoints := {}
|
||||
var _target: Vector2
|
||||
|
||||
var _velocity: = Vector2(0, gravity)
|
||||
var _velocity := Vector2(0, gravity)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -76,8 +76,8 @@ func _draw() -> void:
|
|||
if not Engine.editor_hint or not $Start:
|
||||
return
|
||||
|
||||
var draw_radius: = 20.0
|
||||
var line_thickness: = 6.0
|
||||
var draw_radius := 20.0
|
||||
var line_thickness := 6.0
|
||||
|
||||
var start: Vector2 = waypoints.start
|
||||
var end: Vector2 = waypoints.end
|
||||
|
|
@ -88,12 +88,12 @@ func _draw() -> void:
|
|||
draw_circle(end, draw_radius, DrawingUtils.COLOR_BLUE_DEEP)
|
||||
|
||||
# Arrow
|
||||
var center: = (start + end) / 2
|
||||
var angle: = start.angle_to(end)
|
||||
var center := (start + end) / 2
|
||||
var angle := start.angle_to(end)
|
||||
DrawingUtils.draw_triangle(self, center, angle, draw_radius)
|
||||
|
||||
func _get_configuration_warning() -> String:
|
||||
var warning: = ""
|
||||
var warning := ""
|
||||
if not $Start or not $End:
|
||||
warning += "%s requires two Position2D children named Start and End to work." % name
|
||||
return warning
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func _add_new_job(job, frequency: int, phase: int) -> void:
|
|||
|
||||
|
||||
func _remove_job(job: SchedulableJob) -> void:
|
||||
var index: = _job_list.find(job)
|
||||
var index := _job_list.find(job)
|
||||
if index >= 0:
|
||||
_job_list.remove(index)
|
||||
|
||||
|
|
@ -24,9 +24,9 @@ func _run(microseconds_budget: int) -> void:
|
|||
|
||||
_run_list.clear()
|
||||
|
||||
var i: = _job_list.size()-1
|
||||
var i := _job_list.size()-1
|
||||
while i >= 0:
|
||||
var job: = ((_job_list[i] as WeakRef).get_ref() as SchedulableJob)
|
||||
var job := ((_job_list[i] as WeakRef).get_ref() as SchedulableJob)
|
||||
i -= 1
|
||||
if !job:
|
||||
_job_list.remove(i+1)
|
||||
|
|
@ -35,17 +35,17 @@ func _run(microseconds_budget: int) -> void:
|
|||
if (_current_frame + job.phase) % job.frequency == 0:
|
||||
_run_list.append(job)
|
||||
|
||||
var current_job: = 0
|
||||
var usec_budget: = microseconds_budget
|
||||
var last_time: = OS.get_ticks_usec()
|
||||
var current_job := 0
|
||||
var usec_budget := microseconds_budget
|
||||
var last_time := OS.get_ticks_usec()
|
||||
|
||||
var list_size: = _run_list.size()
|
||||
var list_size := _run_list.size()
|
||||
for i in range(0, list_size):
|
||||
var job: = _run_list[i] as SchedulableJob
|
||||
var current_time: = OS.get_ticks_usec()
|
||||
var job := _run_list[i] as SchedulableJob
|
||||
var current_time := OS.get_ticks_usec()
|
||||
usec_budget -= current_time - last_time
|
||||
|
||||
var available_time: = int(float(usec_budget) / float(_run_list.size() - current_job))
|
||||
var available_time := int(float(usec_budget) / float(_run_list.size() - current_job))
|
||||
job._run(available_time)
|
||||
|
||||
last_time = current_time
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ extends Node
|
|||
# `add_new_job`. It is a priority 1 job, and it will spread its allocated part of the budget evenly.
|
||||
|
||||
#int64_t's upper maximum, an equivalent to +infinity
|
||||
const MAX_INT: = 0x7FFFFFFFFFFFFFFF
|
||||
const MAX_INT := 0x7FFFFFFFFFFFFFFF
|
||||
|
||||
#4 milliseconds maximum budget by default
|
||||
var microseconds_budget: = 4000
|
||||
var microseconds_budget := 4000
|
||||
|
||||
var _sub_scheduler: = BalancedSubScheduler.new()
|
||||
var _current_frame: = 0
|
||||
var _simulation_frame_count: = 100
|
||||
var _job_list: = []
|
||||
var _run_list: = []
|
||||
var _phase_counters: = []
|
||||
var _sub_scheduler := BalancedSubScheduler.new()
|
||||
var _current_frame := 0
|
||||
var _simulation_frame_count := 100
|
||||
var _job_list := []
|
||||
var _run_list := []
|
||||
var _phase_counters := []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -40,9 +40,9 @@ func _process(delta) -> void:
|
|||
_run_list.clear()
|
||||
var total_priority: float = 0
|
||||
|
||||
var i: = _job_list.size()-1
|
||||
var i := _job_list.size()-1
|
||||
while i >= 0:
|
||||
var job: = ((_job_list[i] as WeakRef).get_ref() as SchedulableJob)
|
||||
var job := ((_job_list[i] as WeakRef).get_ref() as SchedulableJob)
|
||||
i -= 1
|
||||
if !job:
|
||||
_job_list.remove(i+1)
|
||||
|
|
@ -52,17 +52,17 @@ func _process(delta) -> void:
|
|||
_run_list.append(job)
|
||||
total_priority += job.priority
|
||||
|
||||
var current_usecs_to_run: = microseconds_budget
|
||||
var last_time: = OS.get_ticks_usec()
|
||||
var current_usecs_to_run := microseconds_budget
|
||||
var last_time := OS.get_ticks_usec()
|
||||
|
||||
var list_size: = _run_list.size()
|
||||
var list_size := _run_list.size()
|
||||
for i in range(0, list_size):
|
||||
var job:= _run_list[i] as SchedulableJob
|
||||
|
||||
var current_time: = OS.get_ticks_usec()
|
||||
var current_time := OS.get_ticks_usec()
|
||||
current_usecs_to_run -= (current_time - last_time)
|
||||
|
||||
var available_time: = int(current_usecs_to_run * job.priority / total_priority)
|
||||
var available_time := int(current_usecs_to_run * job.priority / total_priority)
|
||||
job._run(available_time)
|
||||
last_time = current_time
|
||||
total_priority -= job.priority
|
||||
|
|
@ -88,7 +88,7 @@ func add_new_job(job: SchedulableJob, frequency: int) -> void:
|
|||
# Unregisters a job from the scheduler. Note that jobs do not have to be removed when an object
|
||||
# is being erased - the scheduler only holds weak references.
|
||||
func remove_job(job: SchedulableJob) -> void:
|
||||
var index: = _job_list.find(job)
|
||||
var index := _job_list.find(job)
|
||||
if index >= 0:
|
||||
_job_list.remove(index)
|
||||
else:
|
||||
|
|
@ -113,8 +113,8 @@ func _calculate_phase(frequency: int) -> int:
|
|||
_phase_counters[i] = 0
|
||||
|
||||
for frame in range(0, _simulation_frame_count):
|
||||
var slot: = frame % frequency
|
||||
var i: = _job_list.size()-1
|
||||
var slot := frame % frequency
|
||||
var i := _job_list.size()-1
|
||||
while i >= 0:
|
||||
var job = ((_job_list[i] as WeakRef).get_ref() as SchedulableJob)
|
||||
i -= 1
|
||||
|
|
@ -125,8 +125,8 @@ func _calculate_phase(frequency: int) -> int:
|
|||
if (frame - job.phase) % job.frequency == 0:
|
||||
_phase_counters[slot] += 1
|
||||
|
||||
var min_value: = MAX_INT
|
||||
var min_value_at: = -1
|
||||
var min_value := MAX_INT
|
||||
var min_value_at := -1
|
||||
for i in range(0, frequency):
|
||||
if _phase_counters[i] < min_value:
|
||||
min_value = _phase_counters[i]
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ extends State
|
|||
onready var _behavior: StraightLineBehavior2D = get_node(behavior)
|
||||
onready var timer: Timer = $Timer
|
||||
|
||||
export var behavior: = NodePath()
|
||||
export var charge_time: = 1.0
|
||||
export var behavior := NodePath()
|
||||
export var charge_time := 1.0
|
||||
export var time_to_full_speed = 0.5
|
||||
|
||||
var _steering: = SteeringMotion2D.new()
|
||||
var _steering := SteeringMotion2D.new()
|
||||
|
||||
|
||||
func enter(msg: Dictionary = {}) -> void:
|
||||
|
|
@ -35,7 +35,7 @@ func exit() -> void:
|
|||
|
||||
func physics_process(delta: float) -> void:
|
||||
_behavior.calculate_steering(_steering)
|
||||
var velocity: = _steering.velocity
|
||||
var velocity := _steering.velocity
|
||||
|
||||
var speed_proportion: float = clamp((charge_time - timer.time_left) / time_to_full_speed, 0, 1)
|
||||
(_behavior.controller.actor as KinematicBody2D).move_and_slide(velocity * speed_proportion)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
extends State
|
||||
# Waits for a given amount of time
|
||||
|
||||
export var cooldown_time: = 1.5
|
||||
export var cooldown_time := 1.5
|
||||
|
||||
func enter(msg: Dictionary = {}) -> void:
|
||||
yield(get_tree().create_timer(cooldown_time), "timeout")
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ extends State
|
|||
|
||||
|
||||
onready var timer: Timer = $Cooldown
|
||||
onready var acceleration: = Vector2(0, owner.gravity)
|
||||
onready var move_direction: = Vector2(-owner.direction, 1)
|
||||
onready var acceleration := Vector2(0, owner.gravity)
|
||||
onready var move_direction := Vector2(-owner.direction, 1)
|
||||
onready var jump_vector_right = Vector2(cos(deg2rad(owner.jump_angle_right)), -sin(deg2rad(owner.jump_angle_right)))
|
||||
onready var jump_vector_left = Vector2(cos(deg2rad(owner.jump_angle_left)), -sin(deg2rad(owner.jump_angle_left)))
|
||||
|
||||
var _velocity: = Vector2.ZERO
|
||||
var _jumping: = false
|
||||
var _velocity := Vector2.ZERO
|
||||
var _jumping := false
|
||||
|
||||
|
||||
func enter(msg: Dictionary = {}) -> void:
|
||||
|
|
@ -52,8 +52,8 @@ func _on_Cooldown_timeout() -> void:
|
|||
|
||||
static func calculate_velocity(old_velocity: Vector2, acceleration: Vector2,
|
||||
delta: float, move_direction: Vector2) -> Vector2:
|
||||
var new_velocity: = old_velocity
|
||||
var new_velocity := old_velocity
|
||||
|
||||
new_velocity += move_direction * acceleration * delta
|
||||
|
||||
return new_velocity
|
||||
return new_velocity
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ extends State
|
|||
# and gets knocked away before transitioning.
|
||||
|
||||
|
||||
export var knock_back_speed: = 450.0
|
||||
export var knock_back_speed := 450.0
|
||||
|
||||
var knocked_away: = false
|
||||
var knocked_away := false
|
||||
var current_speed: float
|
||||
var knock_back_direction: Vector2
|
||||
|
||||
|
|
@ -29,4 +29,4 @@ func physics_process(delta: float) -> void:
|
|||
func _on_Player_hopped_off_entity() -> void:
|
||||
knocked_away = true
|
||||
yield(get_tree().create_timer(0.5), "timeout")
|
||||
_state_machine.transition_to("Destroyed")
|
||||
_state_machine.transition_to("Destroyed")
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@ class_name BehaviorController2D
|
|||
|
||||
|
||||
export var actor_path: NodePath
|
||||
export var max_speed: = 400.0
|
||||
export var max_acceleration: = 1000.0
|
||||
export var max_rotation_speed: = 10.0
|
||||
export var max_angular_acceleration: = 10.0
|
||||
export var max_speed := 400.0
|
||||
export var max_acceleration := 1000.0
|
||||
export var max_rotation_speed := 10.0
|
||||
export var max_angular_acceleration := 10.0
|
||||
|
||||
var velocity: = Vector2.ZERO
|
||||
var angular_velocity: = 0.0
|
||||
var target_velocity: = Vector2.ZERO
|
||||
var target_angular_velocity: = 0.0
|
||||
var velocity := Vector2.ZERO
|
||||
var angular_velocity := 0.0
|
||||
var target_velocity := Vector2.ZERO
|
||||
var target_angular_velocity := 0.0
|
||||
|
||||
onready var actor: Node2D = get_node(actor_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,25 +17,25 @@ class_name BlendedBehavior2D
|
|||
|
||||
# # The recommended use is to have a priority steering with a set of blended behaviors, based on need.
|
||||
|
||||
export var weights: = []
|
||||
export var weights := []
|
||||
|
||||
var _steering: = SteeringMotion2D.new()
|
||||
var _steering := SteeringMotion2D.new()
|
||||
|
||||
|
||||
# Returns the steering motion with a blend of all of the behavior's children, clamped to the controller's maximum values.
|
||||
func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2D:
|
||||
steering.reset_values()
|
||||
|
||||
var size: = get_child_count()
|
||||
var size := get_child_count()
|
||||
for i in range(0, size):
|
||||
var child: = get_child(i) as SteeringBehavior2D
|
||||
var child := get_child(i) as SteeringBehavior2D
|
||||
if not child:
|
||||
continue
|
||||
|
||||
var steering: = child as SteeringBehavior2D
|
||||
var steering := child as SteeringBehavior2D
|
||||
steering.calculate_steering(_steering)
|
||||
|
||||
var weight: = 1.0
|
||||
var weight := 1.0
|
||||
if weights.size() >= i:
|
||||
weight = weights[i]
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ class_name AlignBehavior2D
|
|||
# # The only target supported is Node2D and should be fed in ahead of time.
|
||||
|
||||
|
||||
export var deceleration_radius: = 0.0
|
||||
export var alignment_tolerance: = 0.0
|
||||
export var time_to_target: = 0.1
|
||||
export var deceleration_radius := 0.0
|
||||
export var alignment_tolerance := 0.0
|
||||
export var time_to_target := 0.1
|
||||
|
||||
var target: Node2D
|
||||
|
||||
|
|
@ -33,14 +33,14 @@ func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2
|
|||
# The internal function that calculates the alignment based on the radians passed into the function.
|
||||
# Returns the steering motion with the angular acceleration that will match its own to the rotation value.
|
||||
func _align(steering: SteeringMotion2D, desired_rotation: float) -> SteeringMotion2D:
|
||||
var rotation_size: = abs(desired_rotation - get_actor().rotation)
|
||||
var alignment_tolerance_rad: = deg2rad(alignment_tolerance)
|
||||
var rotation_size := abs(desired_rotation - get_actor().rotation)
|
||||
var alignment_tolerance_rad := deg2rad(alignment_tolerance)
|
||||
|
||||
if rotation_size <= alignment_tolerance_rad:
|
||||
steering.reset_values()
|
||||
else:
|
||||
var target_rotation: = deg2rad(controller.max_rotation_speed)
|
||||
var deceleration_radius_rad: = deg2rad(deceleration_radius)
|
||||
var target_rotation := deg2rad(controller.max_rotation_speed)
|
||||
var deceleration_radius_rad := deg2rad(deceleration_radius)
|
||||
|
||||
if rotation_size <= deceleration_radius_rad:
|
||||
target_rotation *= rotation_size / deceleration_radius_rad
|
||||
|
|
@ -48,8 +48,8 @@ func _align(steering: SteeringMotion2D, desired_rotation: float) -> SteeringMoti
|
|||
|
||||
steering.angular_velocity = (target_rotation - controller.angular_velocity) / time_to_target
|
||||
|
||||
var angular_acceleration: = abs(steering.angular_velocity)
|
||||
var max_angular_acceleration_rad: = deg2rad(controller.max_angular_acceleration)
|
||||
var angular_acceleration := abs(steering.angular_velocity)
|
||||
var max_angular_acceleration_rad := deg2rad(controller.max_angular_acceleration)
|
||||
if angular_acceleration > max_angular_acceleration_rad:
|
||||
steering.angular_velocity *= max_angular_acceleration_rad / angular_acceleration
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ class_name ArriveBehavior2D
|
|||
|
||||
#
|
||||
|
||||
export var arrival_tolerance: = 5.0
|
||||
export var deceleration_radius: = 200.0
|
||||
export var time_to_target: = 0.1
|
||||
export var arrival_tolerance := 5.0
|
||||
export var deceleration_radius := 200.0
|
||||
export var time_to_target := 0.1
|
||||
|
||||
var target: Node2D
|
||||
|
||||
|
|
@ -28,16 +28,16 @@ func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2
|
|||
|
||||
var actor = get_actor()
|
||||
var to_target: Vector2 = target.position - actor.position
|
||||
var distance: = to_target.length()
|
||||
var distance := to_target.length()
|
||||
|
||||
if distance <= arrival_tolerance:
|
||||
steering.reset_values()
|
||||
else:
|
||||
var target_speed: = controller.max_speed
|
||||
var target_speed := controller.max_speed
|
||||
if distance <= deceleration_radius:
|
||||
target_speed *= distance / deceleration_radius
|
||||
|
||||
var target_velocity: = to_target.normalized() * target_speed
|
||||
var target_velocity := to_target.normalized() * target_speed
|
||||
target_velocity = (target_velocity - controller.velocity) * (1.0 / time_to_target)
|
||||
|
||||
steering.velocity = target_velocity.clamped(controller.max_acceleration)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class_name FollowHeatmapBehavior2D
|
|||
var _heatmap
|
||||
|
||||
var _last_point_index: int = INF
|
||||
var _last_velocity: = Vector2(0, 0)
|
||||
var _last_velocity := Vector2(0, 0)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class_name InterceptBehavior2D
|
|||
# where the target is headed
|
||||
|
||||
|
||||
export var max_prediction_time: = 0.0
|
||||
export var max_prediction_time := 0.0
|
||||
|
||||
var target: Node2D
|
||||
|
||||
|
|
@ -20,11 +20,11 @@ func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2
|
|||
if not target:
|
||||
return steering.reset_values()
|
||||
|
||||
var target_position: = target.position
|
||||
var distance2: = (target_position - get_actor().position).length_squared()
|
||||
var speed2: = controller.velocity.length_squared()
|
||||
var target_position := target.position
|
||||
var distance2 := (target_position - get_actor().position).length_squared()
|
||||
var speed2 := controller.velocity.length_squared()
|
||||
|
||||
var prediction_time: = max_prediction_time
|
||||
var prediction_time := max_prediction_time
|
||||
|
||||
if speed2 > 0:
|
||||
var prediction_time2 = distance2 / speed2
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ extends SteeringBehavior2D
|
|||
class_name StraightLineBehavior2D
|
||||
# 2D Behavior that acts like Seek, but for a specific Vector2 position instead of an Object.
|
||||
|
||||
export var arrival_tolerance: = 5.0
|
||||
export var arrival_tolerance := 5.0
|
||||
|
||||
var target: Vector2
|
||||
|
||||
func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2D:
|
||||
var actor = get_actor()
|
||||
var to_target: Vector2 = target - actor.position
|
||||
var distance: = to_target.length()
|
||||
var distance := to_target.length()
|
||||
|
||||
if distance <= arrival_tolerance:
|
||||
steering.reset_values()
|
||||
else:
|
||||
steering.velocity = (target - get_actor().position).normalized() * controller.max_acceleration
|
||||
steering.angular_velocity = 0
|
||||
return steering
|
||||
return steering
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class_name PrioritySteering2D
|
|||
# usually want to act on them. For instance, evading an obstacle to avoid impact.
|
||||
|
||||
|
||||
var last_child_index: = 0
|
||||
var last_child_index := 0
|
||||
|
||||
|
||||
# Returns the child whose motion was non-zero. Returns null if no children produced an acceleration.
|
||||
|
|
@ -25,10 +25,10 @@ func get_last_selected_child() -> SteeringBehavior2D:
|
|||
# top to bottom.
|
||||
func _calculate_steering_internal(steering: SteeringMotion2D) -> SteeringMotion2D:
|
||||
last_child_index = -1
|
||||
var size: = get_child_count()
|
||||
var size := get_child_count()
|
||||
|
||||
for i in range(0, size):
|
||||
var child: = get_child(i) as SteeringBehavior2D
|
||||
var child := get_child(i) as SteeringBehavior2D
|
||||
if child == null:
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class_name SteeringBehavior2D
|
|||
# information to move the AI actor.
|
||||
|
||||
|
||||
var is_enabled: = true
|
||||
var is_enabled := true
|
||||
onready var controller: BehaviorController2D = _find_controller(self)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ class_name SteeringMotion2D
|
|||
# Data container for linear and angular steering velocities calculated by behaviors that extend SteeringBehavior2D.
|
||||
|
||||
|
||||
var velocity: = Vector2.ZERO
|
||||
var angular_velocity: = 0.0
|
||||
var velocity := Vector2.ZERO
|
||||
var angular_velocity := 0.0
|
||||
|
||||
|
||||
func reset_values() -> void:
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ var speed: float = 250
|
|||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var desired_velocity: = behavior.calculate_steering(_motion)
|
||||
position += _motion.velocity.normalized() * speed * delta
|
||||
var desired_velocity := behavior.calculate_steering(_motion)
|
||||
position += _motion.velocity.normalized() * speed * delta
|
||||
|
|
|
|||
|
|
@ -3,26 +3,26 @@ extends Node2D
|
|||
# to chase the player for economical pathfinding.
|
||||
|
||||
|
||||
export var spawner_count: = 50
|
||||
export var spawn_per_frame: = 10
|
||||
export var spawner_count := 50
|
||||
export var spawn_per_frame := 10
|
||||
export var swarmer: PackedScene
|
||||
export var spawn_radius: = 200
|
||||
export var spawn_radius := 200
|
||||
export var minimum_speed: float = 200
|
||||
export var maximum_speed: float = 300
|
||||
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
var r_squared: = spawn_radius*spawn_radius
|
||||
var r_squared := spawn_radius*spawn_radius
|
||||
|
||||
for i in range(spawner_count):
|
||||
if i % spawn_per_frame:
|
||||
yield(get_tree(), "idle_frame")
|
||||
var x: = rand_range(-spawn_radius, spawn_radius)
|
||||
var y: = rand_range(-1, 1) * sqrt(r_squared-x*x)
|
||||
var x := rand_range(-spawn_radius, spawn_radius)
|
||||
var y := rand_range(-1, 1) * sqrt(r_squared-x*x)
|
||||
|
||||
var instance: = swarmer.instance()
|
||||
var instance := swarmer.instance()
|
||||
instance.set_name("Swarmer%s"% i)
|
||||
add_child(instance)
|
||||
instance.speed = rand_range(minimum_speed, maximum_speed)
|
||||
instance.global_position = global_position + Vector2(x,y)
|
||||
instance.global_position = global_position + Vector2(x,y)
|
||||
|
|
|
|||
|
|
@ -2,31 +2,31 @@
|
|||
extends Node2D
|
||||
class_name DrawingUtils
|
||||
|
||||
const DEFAULT_POINTS_COUNT: = 32
|
||||
const DEFAULT_POINTS_COUNT := 32
|
||||
|
||||
const COLOR_BLUE_LIGHT: = Color("09a6ca")
|
||||
const COLOR_BLUE_DEEP: = Color("0046ff")
|
||||
const COLOR_BLUE_LIGHT := Color("09a6ca")
|
||||
const COLOR_BLUE_DEEP := Color("0046ff")
|
||||
|
||||
const COLOR_SUCCESS: = Color("2cb638")
|
||||
const COLOR_WARNING: = Color("ff9b00")
|
||||
const COLOR_ERROR: = Color("ff004e")
|
||||
const COLOR_SUCCESS := Color("2cb638")
|
||||
const COLOR_WARNING := Color("ff9b00")
|
||||
const COLOR_ERROR := Color("ff004e")
|
||||
|
||||
|
||||
static func draw_circle_outline(obj: CanvasItem=null, position:=Vector2.ZERO, radius:float=30.0, color:=Color(), thickness:=1.0) -> void:
|
||||
var points_array: = PoolVector2Array()
|
||||
var points_array := PoolVector2Array()
|
||||
for i in range(DEFAULT_POINTS_COUNT + 1):
|
||||
var angle: = 2 * PI * i / DEFAULT_POINTS_COUNT
|
||||
var point: = position + Vector2(cos(angle) * radius, sin(angle) * radius)
|
||||
var angle := 2 * PI * i / DEFAULT_POINTS_COUNT
|
||||
var point := position + Vector2(cos(angle) * radius, sin(angle) * radius)
|
||||
points_array.append(point)
|
||||
obj.draw_polyline(points_array, color, thickness, true)
|
||||
|
||||
|
||||
static func draw_triangle(obj: CanvasItem=null, center:Vector2=Vector2.ZERO, angle:float=0.0, radius:float=10.0, color:=Color.white) -> void:
|
||||
var points: = PoolVector2Array()
|
||||
var colors: = PoolColorArray([color])
|
||||
var points := PoolVector2Array()
|
||||
var colors := PoolColorArray([color])
|
||||
for i in range(3):
|
||||
var angle_point: = angle + i * 2.0 * PI / 3.0 + PI
|
||||
var offset: = Vector2(radius * cos(angle_point), radius * sin(angle_point))
|
||||
var point: = center + offset
|
||||
var angle_point := angle + i * 2.0 * PI / 3.0 + PI
|
||||
var offset := Vector2(radius * cos(angle_point), radius * sin(angle_point))
|
||||
var point := center + offset
|
||||
points.append(point)
|
||||
obj.draw_polygon(points, colors)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
extends Node
|
||||
# Loads and unloads levels
|
||||
|
||||
onready var scene_tree: = get_tree()
|
||||
onready var scene_tree := get_tree()
|
||||
|
||||
var _game: Node = null
|
||||
var _player: Player = null
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ signal controls_changed()
|
|||
|
||||
|
||||
enum { KBD_MOUSE, GAMEPAD }
|
||||
var controls: = KBD_MOUSE setget set_controls
|
||||
var controls := KBD_MOUSE setget set_controls
|
||||
|
||||
enum AimStick { LEFT=0, RIGHT=1 }
|
||||
const JOYSTICK_AIM_INPUTS: = {
|
||||
const JOYSTICK_AIM_INPUTS := {
|
||||
AimStick.LEFT: {
|
||||
'aim_left': {
|
||||
axis=JOY_AXIS_0,
|
||||
|
|
@ -78,11 +78,11 @@ func set_aim_stick(value: int) -> void:
|
|||
aim_stick = value
|
||||
ProjectSettings.set_setting('debug/testing/controls/aim_stick', value)
|
||||
|
||||
var action_suffixes: = ['left', 'right', 'up', 'down']
|
||||
var action_suffixes := ['left', 'right', 'up', 'down']
|
||||
for suffix in action_suffixes:
|
||||
var action_name: String = 'aim_' + suffix
|
||||
InputMap.action_erase_events(action_name)
|
||||
var event: = get_joypad_motion_event(action_name, aim_stick)
|
||||
var event := get_joypad_motion_event(action_name, aim_stick)
|
||||
InputMap.action_add_event(action_name, event)
|
||||
print(action_name)
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ func set_aim_stick(value: int) -> void:
|
|||
# using JOYSTICK_AIM_INPUTS for the base data
|
||||
# Use AimStick.* for the stick argument
|
||||
func get_joypad_motion_event(action: String, stick: int) -> InputEventJoypadMotion:
|
||||
var event: = InputEventJoypadMotion.new()
|
||||
var event := InputEventJoypadMotion.new()
|
||||
var action_data: Dictionary = JOYSTICK_AIM_INPUTS[stick][action]
|
||||
action_data.deadzone = 0.0
|
||||
event.axis = action_data.axis
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
# To use as an autoloaded Node
|
||||
extends Node
|
||||
|
||||
const DEFAULT_MASS: = 2.0
|
||||
const DEFAULT_SLOW_RADIUS: = 200.0
|
||||
const DEFAULT_MAX_SPEED: = 400.0
|
||||
const DEFAULT_MASS := 2.0
|
||||
const DEFAULT_SLOW_RADIUS := 200.0
|
||||
const DEFAULT_MAX_SPEED := 400.0
|
||||
|
||||
|
||||
static func follow(
|
||||
|
|
@ -12,8 +12,8 @@ static func follow(
|
|||
global_position: Vector2,
|
||||
target_position: Vector2,
|
||||
delta: float,
|
||||
max_speed: = DEFAULT_MAX_SPEED,
|
||||
mass: = DEFAULT_MASS
|
||||
max_speed := DEFAULT_MAX_SPEED,
|
||||
mass := DEFAULT_MASS
|
||||
) -> Vector2:
|
||||
# Calculates and returns a velocity steering towards target_position
|
||||
var desired_velocity: Vector2 = (target_position - global_position).normalized() * max_speed
|
||||
|
|
@ -26,13 +26,13 @@ static func arrive_to(
|
|||
global_position: Vector2,
|
||||
target_position: Vector2,
|
||||
delta: float,
|
||||
max_speed: = DEFAULT_MAX_SPEED,
|
||||
slow_radius: = DEFAULT_SLOW_RADIUS,
|
||||
mass: = DEFAULT_MASS
|
||||
max_speed := DEFAULT_MAX_SPEED,
|
||||
slow_radius := DEFAULT_SLOW_RADIUS,
|
||||
mass := DEFAULT_MASS
|
||||
) -> Vector2:
|
||||
# Calculates and returns a new velocity with the arrive steering behavior
|
||||
var to_target: = global_position.distance_to(target_position)
|
||||
var desired_velocity: = (target_position - global_position).normalized() * max_speed
|
||||
var to_target := global_position.distance_to(target_position)
|
||||
var desired_velocity := (target_position - global_position).normalized() * max_speed
|
||||
if to_target < slow_radius:
|
||||
desired_velocity *= (to_target / slow_radius) * .75 + .25
|
||||
var steering: Vector2 = (desired_velocity - velocity) / mass
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ static func get_aim_joystick_direction() -> Vector2:
|
|||
# Adds a circular deadzone, as Godot's built-in system is per-axis,
|
||||
# creating a rectangular deadzone on the joystick
|
||||
static func get_aim_joystick_strength() -> Vector2:
|
||||
var deadzone_radius: = 0.5
|
||||
var input_strength: = Vector2(
|
||||
var deadzone_radius := 0.5
|
||||
var input_strength := Vector2(
|
||||
Input.get_action_strength("aim_right") - Input.get_action_strength("aim_left"),
|
||||
Input.get_action_strength("aim_down") - Input.get_action_strength("aim_up")
|
||||
)
|
||||
|
|
@ -20,7 +20,7 @@ static func get_aim_joystick_strength() -> Vector2:
|
|||
|
||||
# Checks if two numbers are approximately equal
|
||||
static func is_equal_approx(a: float, b: float, cmp_epsilon: float = 1e-5) -> bool:
|
||||
var tolerance: = cmp_epsilon * abs(a)
|
||||
var tolerance := cmp_epsilon * abs(a)
|
||||
if tolerance < cmp_epsilon:
|
||||
tolerance = cmp_epsilon
|
||||
return abs(a - b) < tolerance
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# See DamageSource for more information.
|
||||
class_name Hit
|
||||
|
||||
var damage: = 0
|
||||
var damage := 0
|
||||
|
||||
func _init(source: DamageSource) -> void:
|
||||
damage = source.damage
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ extends Area2D
|
|||
|
||||
onready var collider: CollisionShape2D = $CollisionShape2D
|
||||
|
||||
var is_active: = true setget set_is_active
|
||||
var is_active := true setget set_is_active
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -10,7 +10,7 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _on_area_entered(damage_source: Area2D) -> void:
|
||||
var hit: = Hit.new(damage_source)
|
||||
var hit := Hit.new(damage_source)
|
||||
owner.take_damage(hit)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ signal damage_taken()
|
|||
|
||||
var modifiers = {}
|
||||
|
||||
var invulnerable: = false
|
||||
var invulnerable := false
|
||||
|
||||
var health: int
|
||||
export var max_health: int = 1 setget set_max_health
|
||||
|
|
@ -59,7 +59,7 @@ func remove_modifier(id: int) -> void:
|
|||
func set_invulnerable_for_seconds(time: float) -> void:
|
||||
invulnerable = true
|
||||
|
||||
var timer: = get_tree().create_timer(time)
|
||||
var timer := get_tree().create_timer(time)
|
||||
yield(timer, "timeout")
|
||||
|
||||
invulnerable = false
|
||||
invulnerable = false
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ extends Node
|
|||
|
||||
onready var transition: ColorRect = $UI/Transition
|
||||
|
||||
export(PackedScene) var StartLevel: = preload("res://src/Levels/Level1.tscn")
|
||||
export(PackedScene) var StartLevel := preload("res://src/Levels/Level1.tscn")
|
||||
|
||||
var visited_checkpoints: = {}
|
||||
var visited_checkpoints := {}
|
||||
var level: Node2D = null
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class_name State
|
|||
# Use State as a child of a StateMachine node.
|
||||
|
||||
|
||||
onready var _state_machine: = _get_state_machine(self)
|
||||
onready var _state_machine := _get_state_machine(self)
|
||||
var _parent: State = null
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class_name StateMachine
|
|||
# (_physics_process, _unhandled_input) to the active state.
|
||||
|
||||
|
||||
export var initial_state: = NodePath()
|
||||
export var initial_state := NodePath()
|
||||
|
||||
onready var state: State = get_node(initial_state) setget set_state
|
||||
onready var _state_name: = state.name
|
||||
onready var _state_name := state.name
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
|
|
@ -31,7 +31,7 @@ func transition_to(target_state_path: String, msg: Dictionary = {}) -> void:
|
|||
if not has_node(target_state_path):
|
||||
return
|
||||
|
||||
var target_state: = get_node(target_state_path)
|
||||
var target_state := get_node(target_state_path)
|
||||
|
||||
state.exit()
|
||||
self.state = target_state
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ extends Area2D
|
|||
|
||||
onready var collision_shape: CollisionShape2D = $CollisionShape2D
|
||||
|
||||
const COLOR_INACTIVE: = Color(1, 1, 1)
|
||||
const COLOR_INACTIVE := Color(1, 1, 1)
|
||||
|
||||
var is_visited: = false setget set_is_visited
|
||||
var is_visited := false setget set_is_visited
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ signal hooked_onto_from(hook_position)
|
|||
|
||||
onready var timer: Timer = $Timer
|
||||
|
||||
export var is_one_shot: = false
|
||||
export var is_one_shot := false
|
||||
|
||||
const COLOR_ACTIVE: Color = Color(1, 1, 1)
|
||||
const COLOR_INACTIVE: Color = Color(0.588235, 0.588235, 0.588235)
|
||||
|
||||
var is_active: = true setget set_is_active
|
||||
var is_active := true setget set_is_active
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _on_HookTarget_hooked_onto_from(hook_position: Vector2) -> void:
|
||||
var impulse_offset: = target.position
|
||||
var direction: = (hook_position - target.global_position).normalized()
|
||||
var impulse_offset := target.position
|
||||
var direction := (hook_position - target.global_position).normalized()
|
||||
body.propel(impulse_offset, direction)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ extends RigidBody2D
|
|||
|
||||
|
||||
func propel(from: Vector2, direction: Vector2) -> void:
|
||||
var impulse_strength: = 2000.0
|
||||
var impulse_strength := 2000.0
|
||||
|
||||
mode = MODE_RIGID
|
||||
apply_impulse(from, direction * impulse_strength)
|
||||
Engine.time_scale = 0.03
|
||||
var timer: = get_tree().create_timer(0.02)
|
||||
var timer := get_tree().create_timer(0.02)
|
||||
yield(timer, "timeout")
|
||||
Engine.time_scale = 1.0
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
# extends KinematicBody2D
|
||||
|
||||
# # onready var wait_timer: Timer = $Timer
|
||||
# onready var waypoints: = $Waypoints
|
||||
# onready var waypoints := $Waypoints
|
||||
|
||||
# # export var speed: = 400.0
|
||||
# # export var speed := 400.0
|
||||
|
||||
# # var target_position: = Vector2()
|
||||
# # var target_position := Vector2()
|
||||
|
||||
#
|
||||
# # func _ready() -> void:
|
||||
|
|
@ -20,9 +20,9 @@
|
|||
|
||||
#
|
||||
# # func _physics_process(delta: float) -> void:
|
||||
# var direction: = (target_position - position).normalized()
|
||||
# var motion: = direction * speed * delta
|
||||
# var distance_to_target: = position.distance_to(target_position)
|
||||
# var direction := (target_position - position).normalized()
|
||||
# var motion := direction * speed * delta
|
||||
# var distance_to_target := position.distance_to(target_position)
|
||||
# if motion.length() > distance_to_target:
|
||||
# position = target_position
|
||||
# target_position = waypoints.get_next_point_position()
|
||||
|
|
@ -33,9 +33,9 @@
|
|||
|
||||
#
|
||||
# # func _draw() -> void:
|
||||
# var shape: = $CollisionShape2D
|
||||
# var shape := $CollisionShape2D
|
||||
# var extents: Vector2 = shape.shape.extents * 2.0
|
||||
# var rect: = Rect2(shape.position - extents / 2.0, extents)
|
||||
# var rect := Rect2(shape.position - extents / 2.0, extents)
|
||||
# draw_rect(rect, Color('fff'))
|
||||
|
||||
#
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ extends Node2D
|
|||
|
||||
enum Mode {CYCLE, PING_PONG}
|
||||
|
||||
export(Mode) var mode: = Mode.CYCLE setget set_mode
|
||||
export(Mode) var mode := Mode.CYCLE setget set_mode
|
||||
|
||||
export var editor_process: = true setget set_editor_process
|
||||
export var editor_process := true setget set_editor_process
|
||||
|
||||
export var line_color: = Color(0.228943, 0.710254, 0.945312)
|
||||
export var line_width: = 10.0
|
||||
export var triangle_color: = Color(0.722656, 0.908997, 1)
|
||||
export var line_color := Color(0.228943, 0.710254, 0.945312)
|
||||
export var line_width := 10.0
|
||||
export var triangle_color := Color(0.722656, 0.908997, 1)
|
||||
|
||||
var _active_point_index: = 0
|
||||
var _direction: = 1
|
||||
var _active_point_index := 0
|
||||
var _direction := 1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -30,15 +30,15 @@ func _draw() -> void:
|
|||
return
|
||||
if not get_child_count() > 1:
|
||||
return
|
||||
var points: = PoolVector2Array()
|
||||
var triangles: = []
|
||||
var last_point: = Vector2.ZERO
|
||||
var points := PoolVector2Array()
|
||||
var triangles := []
|
||||
var last_point := Vector2.ZERO
|
||||
for child in get_children():
|
||||
assert(child is Node2D)
|
||||
points.append(child.position)
|
||||
if points.size() > 1:
|
||||
var center: Vector2 = (child.position + last_point) / 2
|
||||
var angle: = last_point.angle_to_point(child.position)
|
||||
var angle := last_point.angle_to_point(child.position)
|
||||
triangles.append({center=center, angle=angle})
|
||||
last_point = child.position
|
||||
|
||||
|
|
@ -46,8 +46,8 @@ func _draw() -> void:
|
|||
if mode == Mode.CYCLE:
|
||||
var first_child_position: Vector2 = get_child(0).position
|
||||
points.append(first_child_position)
|
||||
var center: = (first_child_position + last_point) / 2
|
||||
var angle: = last_point.angle_to_point(first_child_position)
|
||||
var center := (first_child_position + last_point) / 2
|
||||
var angle := last_point.angle_to_point(first_child_position)
|
||||
triangles.append({center=center, angle=angle})
|
||||
|
||||
draw_polyline(points, line_color, line_width, true)
|
||||
|
|
@ -68,7 +68,7 @@ func get_next_point_position():
|
|||
Mode.CYCLE:
|
||||
_active_point_index = (_active_point_index + 1) % get_child_count()
|
||||
Mode.PING_PONG:
|
||||
var index: = _active_point_index + _direction
|
||||
var index := _active_point_index + _direction
|
||||
if index < 0 or index > get_child_count() - 1:
|
||||
_direction *= -1
|
||||
_active_point_index += _direction
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
extends Area2D
|
||||
|
||||
|
||||
export(String, FILE) var next_level_file_path: = ""
|
||||
export(String) var next_level_portal_name: = ""
|
||||
export(String, FILE) var next_level_file_path := ""
|
||||
export(String) var next_level_portal_name := ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ extends Position2D
|
|||
|
||||
onready var camera: Camera2D = $ShakingCamera
|
||||
|
||||
export var offset: = Vector2(300.0, 300.0)
|
||||
export var mouse_range: = Vector2(100.0, 500.0)
|
||||
export var offset := Vector2(300.0, 300.0)
|
||||
export var mouse_range := Vector2(100.0, 500.0)
|
||||
|
||||
var is_active: = true
|
||||
var is_active := true
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
|
@ -22,10 +22,10 @@ func update_position(velocity: Vector2 = Vector2.ZERO) -> void:
|
|||
match Settings.controls:
|
||||
|
||||
Settings.GAMEPAD:
|
||||
var joystick_strength: = Utils.get_aim_joystick_strength()
|
||||
var joystick_strength := Utils.get_aim_joystick_strength()
|
||||
camera.position = joystick_strength * offset
|
||||
|
||||
Settings.KBD_MOUSE, _:
|
||||
var mouse_position: = get_local_mouse_position()
|
||||
var distance_ratio: = clamp(mouse_position.length(), mouse_range.x, mouse_range.y) / mouse_range.y
|
||||
var mouse_position := get_local_mouse_position()
|
||||
var distance_ratio := clamp(mouse_position.length(), mouse_range.x, mouse_range.y) / mouse_range.y
|
||||
camera.position = distance_ratio * mouse_position.normalized() * offset
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export var amplitude = 4.0
|
|||
export var duration = 0.3 setget set_duration
|
||||
export var DAMP_EASING = 1.0
|
||||
export var is_shaking = false setget set_is_shaking
|
||||
export var default_smoothing_speed: = {
|
||||
export var default_smoothing_speed := {
|
||||
mouse=3,
|
||||
gamepad=1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@ func get_floor_position() -> Vector2:
|
|||
|
||||
func get_floor_distance_ratio() -> float:
|
||||
force_raycast_update()
|
||||
var ratio: = 1.0 - abs(get_collision_point().y - global_position.y) / cast_to.y
|
||||
var ratio := 1.0 - abs(get_collision_point().y - global_position.y) / cast_to.y
|
||||
return ratio
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ onready var tween: Tween = $Tween
|
|||
|
||||
onready var start_length: float = head.position.x
|
||||
|
||||
var hook_position: = Vector2.ZERO setget set_hook_position
|
||||
var length: = 40.0 setget set_length
|
||||
var hook_position := Vector2.ZERO setget set_hook_position
|
||||
var length := 40.0 setget set_length
|
||||
|
||||
|
||||
func set_hook_position(value: Vector2) -> void:
|
||||
hook_position = value
|
||||
var to_target: = hook_position - global_position
|
||||
var to_target := hook_position - global_position
|
||||
self.length = to_target.length()
|
||||
rotation = to_target.angle()
|
||||
tween.interpolate_property(
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ onready var arrow: Node2D = $Arrow
|
|||
onready var snap_detector: Area2D = $SnapDetector
|
||||
onready var cooldown: Timer = $Cooldown
|
||||
|
||||
var is_aiming: = false setget set_is_aiming
|
||||
var is_active: = true setget set_is_active
|
||||
var is_aiming := false setget set_is_aiming
|
||||
var is_active := true setget set_is_active
|
||||
|
||||
onready var _radius: float = snap_detector.calculate_length()
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ func can_hook() -> bool:
|
|||
|
||||
|
||||
func get_aim_direction() -> Vector2:
|
||||
var direction: = Vector2.ZERO
|
||||
var direction := Vector2.ZERO
|
||||
match Settings.controls:
|
||||
Settings.GAMEPAD:
|
||||
direction = Utils.get_aim_joystick_direction()
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
# Allows the player to hook onto a target even if they pressed the hook key before the hook was in range
|
||||
extends Node
|
||||
|
||||
export var timer_duration: = 0.05
|
||||
export var timer_duration := 0.05
|
||||
|
||||
const ACTION_HOOK: = 'hook'
|
||||
const ACTION_HOOK := 'hook'
|
||||
|
||||
var _action_names: = []
|
||||
var _action_names := []
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(ACTION_HOOK) and not ACTION_HOOK in _action_names:
|
||||
|
|
@ -16,7 +16,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
|
||||
func _physics_process(delta: float) -> void:
|
||||
for action_name in _action_names:
|
||||
var event: = InputEventAction.new()
|
||||
var event := InputEventAction.new()
|
||||
event.action = action_name
|
||||
event.pressed = true
|
||||
Input.parse_input_event(event)
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@ func _physics_process(delta: float) -> void:
|
|||
# Returns the closest target, skipping targets when there is an obstacle
|
||||
# between the player and the target.
|
||||
func find_best_target() -> HookTarget:
|
||||
var targets: = get_overlapping_areas()
|
||||
var targets := get_overlapping_areas()
|
||||
|
||||
var closest_target: HookTarget = null
|
||||
var distance_to_closest: = 100000.0
|
||||
var distance_to_closest := 100000.0
|
||||
for t in targets:
|
||||
if not t.is_active:
|
||||
continue
|
||||
|
||||
var distance: = global_position.distance_to(t.global_position)
|
||||
var distance := global_position.distance_to(t.global_position)
|
||||
if distance > distance_to_closest:
|
||||
continue
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ func has_target() -> bool:
|
|||
# Returns the length of the hook, from the origin to the tip of the collision shape
|
||||
# Used to draw the hook's radius in the editor
|
||||
func calculate_length() -> float:
|
||||
var length: = -1.0
|
||||
var length := -1.0
|
||||
for collider in [$CapsuleH, $CapsuleV]:
|
||||
if not collider:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ func unhandled_input(event: InputEvent) -> void:
|
|||
|
||||
func physics_process(delta: float) -> void:
|
||||
var cast: Vector2 = owner.get_aim_direction() * owner._radius
|
||||
var angle: = cast.angle()
|
||||
var angle := cast.angle()
|
||||
owner.ray_cast.cast_to = cast
|
||||
owner.arrow.rotation = angle
|
||||
owner.snap_detector.rotation = angle
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ func enter(msg: Dictionary = {}) -> void:
|
|||
|
||||
var target: HookTarget = owner.snap_detector.target
|
||||
if not target:
|
||||
var distance: = min(owner._radius, owner.get_local_mouse_position().length())
|
||||
var distance := min(owner._radius, owner.get_local_mouse_position().length())
|
||||
owner.arrow.hook_position = owner.global_position + owner.get_local_mouse_position().normalized() * distance / 2.0
|
||||
_state_machine.transition_to("Aim")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ extends Position2D
|
|||
onready var ray_bottom: RayCast2D = $RayBottom
|
||||
onready var ray_top: RayCast2D = $RayTop
|
||||
|
||||
export var is_active: = true
|
||||
export var is_active := true
|
||||
|
||||
|
||||
func _ready():
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ onready var floor_detector: RayCast2D = $FloorDetector
|
|||
onready var pass_through: Area2D = $PassThrough
|
||||
|
||||
|
||||
const FLOOR_NORMAL: = Vector2.UP
|
||||
const FLOOR_NORMAL := Vector2.UP
|
||||
|
||||
var is_active: = true setget set_is_active
|
||||
var has_teleported: = false
|
||||
var is_active := true setget set_is_active
|
||||
var has_teleported := false
|
||||
var last_checkpoint: Area2D = null
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ extends Node2D
|
|||
# Draws a rectangle with an outline
|
||||
|
||||
|
||||
export var size: = Vector2(40.0, 40.0) setget set_size
|
||||
export var outline: = Vector2(6.0, 6.0) setget set_outline
|
||||
export var size := Vector2(40.0, 40.0) setget set_size
|
||||
export var outline := Vector2(6.0, 6.0) setget set_outline
|
||||
|
||||
export var color_fill: = Color(0.890625, 0.583793, 0.149597) setget set_color_fill
|
||||
export var color_outline: = Color(0.890625, 0.583793, 0.149597) setget set_color_outline
|
||||
export var color_fill := Color(0.890625, 0.583793, 0.149597) setget set_color_fill
|
||||
export var color_outline := Color(0.890625, 0.583793, 0.149597) setget set_color_outline
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
var size_complete: = size + outline
|
||||
var rect_outline: = Rect2(-size_complete / 2, size_complete)
|
||||
var rect_fill: = Rect2(-size / 2, size)
|
||||
var size_complete := size + outline
|
||||
var rect_outline := Rect2(-size_complete / 2, size_complete)
|
||||
var rect_fill := Rect2(-size / 2, size)
|
||||
draw_rect(rect_outline, color_outline)
|
||||
draw_rect(rect_fill, color_fill)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func _on_Anim_animation_finished(name: String) -> void:
|
|||
func _physics_process(delta: float) -> void:
|
||||
floor_detector.force_raycast_update()
|
||||
shadow.visible = floor_detector.is_close_to_floor()
|
||||
var ratio: = floor_detector.get_floor_distance_ratio()
|
||||
var ratio := floor_detector.get_floor_distance_ratio()
|
||||
shadow.scale = Vector2(ratio, ratio) * shadow.scale_start
|
||||
shadow.global_position = floor_detector.get_floor_position()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
extends Sprite
|
||||
|
||||
|
||||
var scale_start: = scale
|
||||
var scale_start := scale
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ signal jumped
|
|||
onready var jump_delay: Timer = $JumpDelay
|
||||
onready var controls_freeze: Timer = $ControlsFreeze
|
||||
|
||||
export var acceleration_x: = 5000.0
|
||||
export var acceleration_x := 5000.0
|
||||
|
||||
|
||||
func unhandled_input(event: InputEvent) -> void:
|
||||
|
|
@ -34,7 +34,7 @@ func physics_process(delta: float) -> void:
|
|||
|
||||
# Landing
|
||||
if owner.is_on_floor():
|
||||
var target_state: = "Move/Idle" if _parent.get_move_direction().x == 0 else "Move/Run"
|
||||
var target_state := "Move/Idle" if _parent.get_move_direction().x == 0 else "Move/Run"
|
||||
_state_machine.transition_to(target_state)
|
||||
|
||||
elif owner.ledge_wall_detector.is_against_ledge():
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ extends State
|
|||
# debug_sprint, assigned to Shift on the keyboard and B on an XBOX controller, moves the character faster
|
||||
|
||||
|
||||
var velocity: = Vector2.ZERO
|
||||
const speed: = Vector2(600.0, 600.0)
|
||||
var velocity := Vector2.ZERO
|
||||
const speed := Vector2(600.0, 600.0)
|
||||
|
||||
|
||||
func unhandled_input(event: InputEvent) -> void:
|
||||
|
|
@ -17,8 +17,8 @@ func unhandled_input(event: InputEvent) -> void:
|
|||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
var direction: = get_move_direction()
|
||||
var multiplier: = 3.0 if Input.is_action_pressed('debug_sprint') else 1.0
|
||||
var direction := get_move_direction()
|
||||
var multiplier := 3.0 if Input.is_action_pressed('debug_sprint') else 1.0
|
||||
velocity = speed * direction * multiplier
|
||||
owner.position += velocity * delta
|
||||
Events.emit_signal("player_moved", owner)
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ extends State
|
|||
# Preserves the character's inertia past the hooking point
|
||||
|
||||
|
||||
const HOOK_MAX_SPEED: = 1600.0
|
||||
const HOOK_MAX_SPEED := 1600.0
|
||||
|
||||
export var arrive_push: = 500.0
|
||||
export var arrive_push := 500.0
|
||||
|
||||
var target_global_position: = Vector2(INF, INF)
|
||||
var velocity: = Vector2.ZERO
|
||||
var _target_is_living_entity: = false
|
||||
var target_global_position := Vector2(INF, INF)
|
||||
var velocity := Vector2.ZERO
|
||||
var _target_is_living_entity := false
|
||||
|
||||
|
||||
func physics_process(delta: float) -> void:
|
||||
var new_velocity: = Steering.arrive_to(
|
||||
var new_velocity := Steering.arrive_to(
|
||||
velocity,
|
||||
owner.global_position,
|
||||
target_global_position,
|
||||
|
|
@ -25,7 +25,7 @@ func physics_process(delta: float) -> void:
|
|||
Events.emit_signal("player_moved", owner)
|
||||
|
||||
var to_target: Vector2 = target_global_position - owner.global_position
|
||||
var distance: = to_target.length()
|
||||
var distance := to_target.length()
|
||||
|
||||
if distance < velocity.length() * delta:
|
||||
velocity = velocity.normalized() * arrive_push
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ extends State
|
|||
|
||||
onready var timer: Timer = $Timer
|
||||
|
||||
export var hop_impulse: = 500.0
|
||||
export var wait_duration: = 0.6
|
||||
export var hop_impulse := 500.0
|
||||
export var wait_duration := 0.6
|
||||
|
||||
|
||||
func enter(msg: Dictionary = {}) -> void:
|
||||
owner.stats.set_invulnerable_for_seconds(wait_duration*3)
|
||||
|
||||
var timer: = get_tree().create_timer(wait_duration)
|
||||
var timer := get_tree().create_timer(wait_duration)
|
||||
yield(timer, "timeout")
|
||||
|
||||
owner.emit_signal("hopped_off_entity")
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@ extends State
|
|||
|
||||
const PASS_THROUGH_LAYER = 3
|
||||
|
||||
export var max_speed_default: = Vector2(500.0, 1500.0)
|
||||
export var acceleration_default: = Vector2(100000, 3000.0)
|
||||
export var jump_impulse: = 900.0
|
||||
export var max_speed_default := Vector2(500.0, 1500.0)
|
||||
export var acceleration_default := Vector2(100000, 3000.0)
|
||||
export var jump_impulse := 900.0
|
||||
|
||||
var acceleration: = acceleration_default
|
||||
var max_speed: = max_speed_default
|
||||
var velocity: = Vector2.ZERO
|
||||
var snap_distance: = 32.0
|
||||
var snap_vector: = Vector2(0, 32)
|
||||
var acceleration := acceleration_default
|
||||
var max_speed := max_speed_default
|
||||
var velocity := Vector2.ZERO
|
||||
var snap_distance := 32.0
|
||||
var snap_vector := Vector2(0, 32)
|
||||
|
||||
|
||||
func _on_Hook_hooked_onto_target(target_global_position: Vector2) -> void:
|
||||
|
|
@ -72,7 +72,7 @@ static func calculate_velocity(
|
|||
delta: float,
|
||||
move_direction: Vector2
|
||||
) -> Vector2:
|
||||
var new_velocity: = old_velocity
|
||||
var new_velocity := old_velocity
|
||||
|
||||
new_velocity += move_direction * acceleration * delta
|
||||
new_velocity.x = clamp(new_velocity.x, -max_speed.x, max_speed.x)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ extends State
|
|||
onready var slow_starter: Timer = $SlowStarter
|
||||
onready var tween: Tween = $Tween
|
||||
|
||||
export var slow_duration_seconds: = 0.4
|
||||
export var slow_duration_seconds := 0.4
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ extends State
|
|||
# Handles wall movement: sliding against the wall and wall jump
|
||||
|
||||
|
||||
export var slide_acceleration: = 1600.0
|
||||
export var max_slide_speed: = 400.0
|
||||
export (float, 0.0, 1.0) var friction_factor: = 0.15
|
||||
export var slide_acceleration := 1600.0
|
||||
export var max_slide_speed := 400.0
|
||||
export (float, 0.0, 1.0) var friction_factor := 0.15
|
||||
|
||||
export var jump_strength: = Vector2(500.0, 400.0)
|
||||
var _wall_normal: = -1
|
||||
var _velocity: = Vector2.ZERO
|
||||
export var jump_strength := Vector2(500.0, 400.0)
|
||||
var _wall_normal := -1
|
||||
var _velocity := Vector2.ZERO
|
||||
|
||||
|
||||
func unhandled_input(event: InputEvent) -> void:
|
||||
|
|
@ -28,7 +28,7 @@ func physics_process(delta: float) -> void:
|
|||
if owner.is_on_floor():
|
||||
_state_machine.transition_to("Move/Idle")
|
||||
|
||||
var is_moving_away_from_wall: = sign(_parent.get_move_direction().x) == sign(_wall_normal)
|
||||
var is_moving_away_from_wall := sign(_parent.get_move_direction().x) == sign(_wall_normal)
|
||||
if is_moving_away_from_wall or not owner.ledge_wall_detector.is_against_wall():
|
||||
_state_machine.transition_to("Move/Air", {"velocity":_velocity})
|
||||
|
||||
|
|
@ -49,8 +49,8 @@ func exit() -> void:
|
|||
|
||||
func jump() -> void:
|
||||
# The direction vector not being normalized is intended
|
||||
var impulse: = Vector2(_wall_normal, -1.0) * jump_strength
|
||||
var msg: = {
|
||||
var impulse := Vector2(_wall_normal, -1.0) * jump_strength
|
||||
var msg := {
|
||||
velocity = impulse,
|
||||
wall_jump = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func _get_configuration_warning() -> String:
|
|||
|
||||
|
||||
func track(property: String) -> void:
|
||||
var label: = Label.new()
|
||||
var label := Label.new()
|
||||
label.autowrap = true
|
||||
label.name = property.capitalize()
|
||||
_container.add_child(label)
|
||||
|
|
@ -56,7 +56,7 @@ func _update() -> void:
|
|||
var label: Label = _container.get_child(search_array.find(property))
|
||||
var value = reference.get(property)
|
||||
|
||||
var text: = ""
|
||||
var text := ""
|
||||
if value is Vector2:
|
||||
text = "(%01d %01d)" % [value.x, value.y]
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue