Added static typing and enforced it
This commit is contained in:
parent
217f0ab18c
commit
cc80783d16
4 changed files with 47 additions and 29 deletions
|
|
@ -1,21 +1,23 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
class_name Glowling
|
class_name Glowling
|
||||||
|
|
||||||
@onready var tilemap = $"../TileMap" # This needs rectifying
|
@onready var tilemap : CustomTileMap = $"../TileMap" # This needs rectifying
|
||||||
var current_path : Array[Vector2i] = []
|
var current_path : Array[Vector2i] = []
|
||||||
|
|
||||||
|
@onready var animation_player : AnimationPlayer = $GlowlingAnimations
|
||||||
|
|
||||||
var speed : int = 40
|
var speed : int = 40
|
||||||
|
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
$GlowlingAnimations.play("GlowingPulse")
|
animation_player.play("GlowingPulse")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _process(delta : float) -> void:
|
||||||
if current_path.is_empty():
|
if current_path.is_empty():
|
||||||
return
|
return
|
||||||
|
|
||||||
var target_position = tilemap.map_to_local(current_path.front())
|
var target_position : Vector2 = tilemap.map_to_local(current_path.front() as Vector2i)
|
||||||
global_position = global_position.move_toward(target_position, speed * delta)
|
global_position = global_position.move_toward(target_position, speed * delta)
|
||||||
|
|
||||||
if global_position == target_position:
|
if global_position == target_position:
|
||||||
|
|
@ -23,8 +25,8 @@ func _process(delta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
## This is the temporary way for having something move
|
## This is the temporary way for having something move
|
||||||
func _unhandled_input(event):
|
func _unhandled_input(event : InputEvent) -> void:
|
||||||
var click_position = get_global_mouse_position()
|
var click_position : Vector2 = get_global_mouse_position()
|
||||||
if event.is_action_pressed("move_to"):
|
if event.is_action_pressed("move_to"):
|
||||||
if tilemap.is_point_walkable(click_position):
|
if tilemap.is_point_walkable(click_position):
|
||||||
current_path = tilemap.astar.get_id_path(
|
current_path = tilemap.astar.get_id_path(
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
extends TileMap
|
extends TileMap
|
||||||
|
class_name CustomTileMap
|
||||||
|
|
||||||
var astar : AStarGrid2D = AStarGrid2D.new()
|
var astar : AStarGrid2D = AStarGrid2D.new()
|
||||||
|
@onready var fog_overlay : ColorRect = $FogOverlay
|
||||||
|
|
||||||
@onready var tilemap_size : Vector2i = get_used_rect().end - get_used_rect().position
|
@onready var tilemap_size : Vector2i = get_used_rect().end - get_used_rect().position
|
||||||
@onready var map_rect : Rect2i = Rect2i(Vector2i.ZERO, tilemap_size)
|
@onready var map_rect : Rect2i = Rect2i(Vector2i.ZERO, tilemap_size)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
||||||
|
var tile_size : Vector2i = get_tileset().tile_size
|
||||||
|
var map_pixel_size : Vector2i = tilemap_size * tile_size
|
||||||
|
fog_overlay.size = map_pixel_size
|
||||||
|
|
||||||
|
|
||||||
setup_pathing()
|
setup_pathing()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -31,14 +39,14 @@ func update_passable() -> void:
|
||||||
for i in tilemap_size.x:
|
for i in tilemap_size.x:
|
||||||
for j in tilemap_size.y:
|
for j in tilemap_size.y:
|
||||||
var coords : Vector2i = Vector2i(i, j)
|
var coords : Vector2i = Vector2i(i, j)
|
||||||
var tile_data = get_cell_tile_data(0, coords)
|
var tile_data : TileData = get_cell_tile_data(0, coords)
|
||||||
if tile_data and tile_data.get_custom_data('navtype') == 'wall':
|
if tile_data and tile_data.get_custom_data('navtype') == 'wall':
|
||||||
astar.set_point_solid(coords)
|
astar.set_point_solid(coords)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func is_point_walkable(check_position) -> bool:
|
func is_point_walkable(check_position : Vector2i) -> bool:
|
||||||
var map_position = local_to_map(check_position)
|
var map_position : Vector2i = local_to_map(check_position)
|
||||||
if map_rect.has_point(map_position) and not astar.is_point_solid(map_position):
|
if map_rect.has_point(map_position) and not astar.is_point_solid(map_position):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -15,6 +15,14 @@ run/main_scene="res://levels/test_level.tscn"
|
||||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[debug]
|
||||||
|
|
||||||
|
gdscript/warnings/untyped_declaration=1
|
||||||
|
gdscript/warnings/unsafe_property_access=1
|
||||||
|
gdscript/warnings/unsafe_method_access=1
|
||||||
|
gdscript/warnings/unsafe_cast=1
|
||||||
|
gdscript/warnings/unsafe_call_argument=1
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/stretch/mode="canvas_items"
|
window/stretch/mode="canvas_items"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue