Compare commits
8 Commits
debed53cb6
...
basic_unit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb0af893b5 | ||
|
|
71297fff2d | ||
|
|
f26be55c71 | ||
|
|
dcfa6fa925 | ||
|
|
ebfa23f500 | ||
|
|
e69ffeef7c | ||
|
|
6431603630 | ||
|
|
858122b8a1 |
@@ -1,4 +1,4 @@
|
||||
[gd_resource type="TileSet" load_steps=6 format=3 uid="uid://duodt2t14xjc8"]
|
||||
[gd_resource type="TileSet" load_steps=11 format=3 uid="uid://duodt2t14xjc8"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cgvyfsuri6vmx" path="res://Graphics/TileMaps/kenney_rpgUrbanKit/Tilemap/tilemap.png" id="1_q1pea"]
|
||||
|
||||
@@ -11,6 +11,21 @@ tile_data = PackedInt32Array(0, 1, 15, 65536, 1, 16, 131072, 1, 17)
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_cfbhl"]
|
||||
tile_data = PackedInt32Array(0, 655361, 16, 65536, 655361, 16, 131072, 655361, 16, 196608, 655361, 16, 262144, 655361, 16, 327680, 655361, 16, 393216, 655361, 16, 458752, 655361, 16, 1, 65537, 17, 65537, 65537, 17, 131073, 65537, 17, 196609, 65537, 17, 262145, 65537, 17, 327681, 65537, 17, 393217, 65537, 17, 458753, 65537, 17, 2, 131073, 17, 65538, 131073, 17, 131074, 131073, 17, 196610, 131073, 17, 262146, 131073, 17, 327682, 131073, 17, 393218, 131073, 17, 458754, 131073, 17, 3, 196609, 17, 65539, 196609, 17, 131075, 196609, 17, 196611, 196609, 17, 262147, 196609, 17, 327683, 196609, 17, 393219, 196609, 17, 458755, 196609, 17, 4, 262145, 17, 65540, 262145, 17, 131076, 262145, 17, 196612, 262145, 17, 262148, 262145, 17, 327684, 262145, 17, 393220, 262145, 17, 458756, 262145, 17, 5, 65537, 17, 65541, 65537, 17, 131077, 65537, 17, 196613, 65537, 17, 262149, 65537, 17, 327685, 65537, 17, 393221, 65537, 17, 458757, 65537, 17, 6, 655361, 16, 65542, 655361, 16, 131078, 655361, 16, 196614, 655361, 16, 262150, 655361, 16, 327686, 655361, 16, 393222, 655361, 16, 458758, 655361, 16)
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_o6jka"]
|
||||
tile_data = PackedInt32Array(0, 1179649, 8, 65536, 1179649, 9, 131072, 1179649, 10, 1, 1245185, 8, 65537, 1245185, 9, 131073, 1245185, 10, 2, 1310721, 8, 65538, 1310721, 9, 131074, 1310721, 10)
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_ora7a"]
|
||||
tile_data = PackedInt32Array(0, 1048577, 8, 65536, 1048577, 9)
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_71vg4"]
|
||||
tile_data = PackedInt32Array(0, 1048577, 8, 65536, 1048577, 10)
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_edyo3"]
|
||||
tile_data = PackedInt32Array(0, 1114113, 8, 65536, 1114113, 9)
|
||||
|
||||
[sub_resource type="TileMapPattern" id="TileMapPattern_ypif2"]
|
||||
tile_data = PackedInt32Array(0, 1114113, 8, 65536, 1114113, 10)
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_vqaso"]
|
||||
resource_name = "UrbanKit"
|
||||
texture = ExtResource("1_q1pea")
|
||||
@@ -1174,3 +1189,8 @@ sources/1 = SubResource("TileSetAtlasSource_vqaso")
|
||||
pattern_0 = SubResource("TileMapPattern_vrbvq")
|
||||
pattern_1 = SubResource("TileMapPattern_07llt")
|
||||
pattern_2 = SubResource("TileMapPattern_cfbhl")
|
||||
pattern_3 = SubResource("TileMapPattern_o6jka")
|
||||
pattern_4 = SubResource("TileMapPattern_ora7a")
|
||||
pattern_5 = SubResource("TileMapPattern_71vg4")
|
||||
pattern_6 = SubResource("TileMapPattern_edyo3")
|
||||
pattern_7 = SubResource("TileMapPattern_ypif2")
|
||||
|
||||
@@ -2,16 +2,66 @@ extends Control
|
||||
|
||||
var grid: AStarGrid2D:
|
||||
set(v): grid = v; queue_redraw()
|
||||
var show_grid_display: bool:
|
||||
var unit_grid: AStarGrid2D:
|
||||
set(v): unit_grid = v; queue_redraw()
|
||||
|
||||
@export var show_grid_display: bool:
|
||||
set(v): show_grid_display = v; queue_redraw()
|
||||
@export var show_move_range: bool:
|
||||
set(v): show_move_range = v; queue_redraw()
|
||||
|
||||
func toggle_grid_display(on: bool):
|
||||
grid = MapGlobal.GetGrid()
|
||||
show_grid_display = on
|
||||
|
||||
func toggle_move_range(on: bool):
|
||||
unit_grid = get_parent().get_parent().get_node("Player").GetMoveGrid()
|
||||
show_move_range = on
|
||||
|
||||
func getNewGrid():
|
||||
grid = MapGlobal.GetGrid()
|
||||
|
||||
func drawMoveRange():
|
||||
var walkableCells: Array[Vector2] = []
|
||||
var activeUnit = get_parent().get_parent().get_node("Player")
|
||||
var unitCellPosition = activeUnit.pos_to_cell(activeUnit.global_position)
|
||||
var unitRange = activeUnit.unitData["MoveRange"]
|
||||
|
||||
# max right, down, left, up
|
||||
for x in range(unitCellPosition.x, unitCellPosition.x + unitRange): # right +x
|
||||
walkableCells.append(Vector2(x, unitCellPosition.y))
|
||||
for y in range(unitCellPosition.y, unitCellPosition.y + unitRange): # down +y
|
||||
walkableCells.append(Vector2(unitCellPosition.x, y))
|
||||
for x in range(unitCellPosition.x, unitCellPosition.x - unitRange, -1): # left -x
|
||||
walkableCells.append(Vector2(x, unitCellPosition.y))
|
||||
for y in range(unitCellPosition.x, unitCellPosition.y - unitRange, -1): # up -y
|
||||
walkableCells.append(Vector2(unitCellPosition.x, y))
|
||||
|
||||
# diagonals?
|
||||
for x in unit_grid.region.size.x:
|
||||
for y in unit_grid.region.size.y:
|
||||
var p = Vector2(x + unit_grid.region.position.x, y + unit_grid.region.position.y)
|
||||
var col = Color(1,0,0,0.3) if unit_grid.is_point_solid(p) else Color(0,1,0,0.3)
|
||||
draw_rect(Rect2(p*unit_grid.cell_size, unit_grid.cell_size), col)
|
||||
|
||||
for cell in walkableCells:
|
||||
draw_rect(Rect2(cell*grid.cell_size, grid.cell_size), Color(0, 0, 1, 0.5))
|
||||
|
||||
func _draw():
|
||||
if not grid or not show_grid_display: return
|
||||
if unit_grid and show_move_range:
|
||||
drawMoveRange()
|
||||
|
||||
if grid and show_grid_display:
|
||||
drawNavigationGrid()
|
||||
|
||||
func drawNavigationGrid():
|
||||
for x in grid.region.size.x:
|
||||
for y in grid.region.size.y:
|
||||
var p = Vector2(x, y)
|
||||
var col = Color(1,0,0,0.3) if grid.is_point_solid(p) else Color(0,1,0,0.3)
|
||||
var p := Vector2(x + grid.region.position.x, y + grid.region.position.y)
|
||||
var col := Color(1,0,0,0.3) if grid.is_point_solid(p) else Color(0,1,0,0.3)
|
||||
draw_rect(Rect2(p*grid.cell_size, grid.cell_size), col)
|
||||
|
||||
|
||||
|
||||
func _on_player_move_finished() -> void:
|
||||
getNewGrid() # Replace with function body.
|
||||
|
||||
@@ -1,53 +1,16 @@
|
||||
extends Node
|
||||
|
||||
@export var grid: Resource
|
||||
|
||||
@onready var _Map: Node = $Map
|
||||
@onready var _Camera = $CameraController
|
||||
|
||||
# Units
|
||||
var _UnitScene = preload("res://Scenes/Unit/unit.tscn")
|
||||
var _Units: Array[Unit] = []
|
||||
|
||||
# MovingMarker
|
||||
var _MovingMarkerScene = preload("res://Scenes/Unit/marker.tscn")
|
||||
var _MovingMarker: Node2D = _MovingMarkerScene.instantiate()
|
||||
#@export var mapSize: int = 15
|
||||
|
||||
@onready var UnitCamera: SmartCamera2D = $SmartCamera2D
|
||||
|
||||
@onready var GroundLayer: TileMapLayer = $Map/Ground
|
||||
|
||||
var aStarGrid: AStarGrid2D:
|
||||
set(v): aStarGrid = v;
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
aStarGrid = MapGlobal.GenerateGridFromLayer($Map/Obstacles)
|
||||
if $Player.is_node_ready():
|
||||
$Player.setup($Map.getGrid())
|
||||
$Player.setup(MapGlobal.GetGrid())
|
||||
$GameBoard/Cursor.moved.connect($Player.setTarget)
|
||||
$GameBoard/Cursor.accept_pressed.connect($Player.selectUnit)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _createUnit(pos: Vector2i):
|
||||
var newUnit = _UnitScene.instantiate()
|
||||
newUnit.set("_spawnPosition", pos)
|
||||
_Units.append(newUnit as Unit)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("SetMarker"):
|
||||
print("Action is SetMarker")
|
||||
# _MovingMarker.global_position = _getMousePosition(event).position
|
||||
_MovingMarker.position = GroundLayer.local_to_map(event.position)
|
||||
_MovingMarker.show()
|
||||
|
||||
func selectUnitAt(cell: Vector2i):
|
||||
pass
|
||||
|
||||
|
||||
func _getScreenCenter():
|
||||
return get_viewport().get_camera_2d().get_screen_center_position()
|
||||
|
||||
@@ -55,19 +18,11 @@ func _getScreenCenter():
|
||||
func _getMousePosition(event: InputEvent):
|
||||
return get_viewport().get_camera_2d().make_input_local(event)
|
||||
|
||||
|
||||
#func prepareAStarGrid():
|
||||
# var astarGrid = AStarGrid2D.new()
|
||||
# astarGrid.cell_size = GroundLayer.tile_set.tile_size
|
||||
# astarGrid.region = Rect2(Vector2.ZERO, ceil(get_viewport_rect().size / astarGrid.cell_size))
|
||||
# astarGrid.update()
|
||||
#
|
||||
# for id in ObstacleLayer.get_used_cells():
|
||||
# var data: TileData = ObstacleLayer.get_cell_tile_data(id)
|
||||
# if data and data.get_custom_data('obstacle'):
|
||||
# astarGrid.set_point_solid(id)
|
||||
#
|
||||
# %GridDisplay.grid = astarGrid
|
||||
|
||||
func get_cell_information(cell):
|
||||
print(cell)
|
||||
|
||||
func ResetLevel():
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
func ResetPlayer():
|
||||
$Player.reset(Vector2(50, 50))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://d05j5yuhlsxp0"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://d05j5yuhlsxp0"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cywuuce71rmgb" path="res://Scenes/Map/map.tscn" id="1_1r6ip"]
|
||||
[ext_resource type="Script" uid="uid://btdvxp8ckmeb3" path="res://Scenes/Main/main.gd" id="1_qw60k"]
|
||||
[ext_resource type="Script" uid="uid://76bfwrwrqfqr" path="res://Scenes/Map/map_global.gd" id="3_hryqi"]
|
||||
[ext_resource type="Script" uid="uid://14cwbxcvt5dx" path="res://Scenes/Main/game_board.gd" id="4_5yls4"]
|
||||
[ext_resource type="Resource" uid="uid://bpf7mj7w5kftq" path="res://Resource/Grid.tres" id="5_p6jpk"]
|
||||
[ext_resource type="Script" uid="uid://dukn3yshfepum" path="res://Scenes/Main/grid_debug.gd" id="5_y3v7k"]
|
||||
@@ -13,9 +14,9 @@
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource("1_qw60k")
|
||||
grid = ExtResource("5_p6jpk")
|
||||
|
||||
[node name="Map" parent="." instance=ExtResource("1_1r6ip")]
|
||||
script = ExtResource("3_hryqi")
|
||||
|
||||
[node name="GameBoard" type="Node2D" parent="."]
|
||||
script = ExtResource("4_5yls4")
|
||||
@@ -37,12 +38,12 @@ position = Vector2(10, -10)
|
||||
wait_time = 0.1
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2(50, 50)
|
||||
scale = Vector2(2, 2)
|
||||
texture = SubResource("PlaceholderTexture2D_y3v7k")
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="."]
|
||||
visible = false
|
||||
|
||||
[node name="GridDisplay" type="Control" parent="HUD"]
|
||||
unique_name_in_owner = true
|
||||
@@ -51,6 +52,7 @@ anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("8_y3v7k")
|
||||
show_grid_display = true
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="HUD/GridDisplay"]
|
||||
layout_mode = 0
|
||||
@@ -60,12 +62,52 @@ offset_bottom = 40.0
|
||||
[node name="PanelContainer" type="PanelContainer" parent="HUD/GridDisplay/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ShowGrid" type="CheckBox" parent="HUD/GridDisplay/MarginContainer/PanelContainer"]
|
||||
[node name="VBoxContainer" type="HBoxContainer" parent="HUD/GridDisplay/MarginContainer/PanelContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ShowGrid" type="CheckBox" parent="HUD/GridDisplay/MarginContainer/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Show Grid"
|
||||
|
||||
[node name="ShowMove" type="CheckBox" parent="HUD/GridDisplay/MarginContainer/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Show Movement Range"
|
||||
|
||||
[node name="GameControl" type="Control" parent="HUD"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -40.0
|
||||
offset_right = 40.0
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 8
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="HUD/GameControl"]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="HUD/GameControl/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="HBoxContainer" parent="HUD/GameControl/MarginContainer/PanelContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ResetLevel" type="Button" parent="HUD/GameControl/MarginContainer/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Reset Level"
|
||||
|
||||
[node name="ResetPlayer" type="Button" parent="HUD/GameControl/MarginContainer/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Reset Player"
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("9_hryqi")]
|
||||
position = Vector2(8, 8)
|
||||
position = Vector2(150, 150)
|
||||
|
||||
[connection signal="accept_pressed" from="GameBoard/Cursor" to="." method="get_cell_information"]
|
||||
[connection signal="toggled" from="HUD/GridDisplay/MarginContainer/PanelContainer/ShowGrid" to="HUD/GridDisplay" method="toggle_grid_display"]
|
||||
[connection signal="toggled" from="HUD/GridDisplay/MarginContainer/PanelContainer/VBoxContainer/ShowGrid" to="HUD/GridDisplay" method="toggle_grid_display"]
|
||||
[connection signal="toggled" from="HUD/GridDisplay/MarginContainer/PanelContainer/VBoxContainer/ShowMove" to="HUD/GridDisplay" method="toggle_move_range"]
|
||||
[connection signal="pressed" from="HUD/GameControl/MarginContainer/PanelContainer/VBoxContainer/ResetLevel" to="." method="ResetLevel"]
|
||||
[connection signal="pressed" from="HUD/GameControl/MarginContainer/PanelContainer/VBoxContainer/ResetPlayer" to="." method="ResetPlayer"]
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var SPEED = 400.0
|
||||
@export var unitData: Dictionary[String, Variant] = {
|
||||
"MoveRange": 5,
|
||||
"MoveRangeVi": Vector2i(5, 5),
|
||||
"MoveRangeV": Vector2(5, 5),
|
||||
"Speed": 400.0
|
||||
}
|
||||
|
||||
var grid: AStarGrid2D
|
||||
var currentCell: Vector2i
|
||||
var currentPoint: int
|
||||
|
||||
var moveGrid: AStarGrid2D
|
||||
|
||||
var selected: bool:
|
||||
set(v):
|
||||
selected = v; $PathPrev.visible = selected;
|
||||
selected = v;
|
||||
$PathPrev.visible = selected;
|
||||
if selected: setMoveGrid();
|
||||
# if selected: MapGlobal.SetRegion(calculateMovementRegion())
|
||||
var moving: bool:
|
||||
set(v):
|
||||
moving = v; $PathPrev.visible = not moving; set_physics_process(moving)
|
||||
|
||||
signal MoveFinished
|
||||
|
||||
var targetCell: Vector2i
|
||||
var movePts: Array
|
||||
|
||||
@@ -23,9 +37,19 @@ func setup(_grid: AStarGrid2D):
|
||||
grid = _grid
|
||||
currentCell = pos_to_cell(global_position)
|
||||
targetCell = currentCell
|
||||
setMoveGrid()
|
||||
|
||||
func reset(pos: Vector2):
|
||||
stopMove()
|
||||
global_position = pos
|
||||
currentCell = pos_to_cell(global_position)
|
||||
targetCell = currentCell
|
||||
movePts = []
|
||||
$PathPrev.points = movePts
|
||||
currentPoint = 0
|
||||
|
||||
func pos_to_cell(pos: Vector2):
|
||||
return pos / grid.cell_size
|
||||
return pos / Vector2(MapGlobal.getData()["cellSize"])
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if moving: return
|
||||
@@ -35,26 +59,36 @@ func _input(event: InputEvent) -> void:
|
||||
func setTarget(target: Vector2i):
|
||||
if !selected: return
|
||||
if moving: return
|
||||
if currentCell.distance_to(target) > unitData["MoveRange"]: return
|
||||
if target != targetCell:
|
||||
movePts = grid.get_point_path(currentCell, target)
|
||||
print("Setting target: ")
|
||||
movePts = MapGlobal.GetGrid().get_point_path(currentCell, target)
|
||||
movePts = (movePts as Array).map(func (point): return point + grid.cell_size/2.0)
|
||||
$PathPrev.points = movePts
|
||||
targetCell = target
|
||||
print (targetCell)
|
||||
|
||||
|
||||
func startMove():
|
||||
if movePts.is_empty(): return
|
||||
currentPoint = 0; moving = true
|
||||
|
||||
func stopMove():
|
||||
if !moving: return
|
||||
moving = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if currentPoint == movePts.size() - 1:
|
||||
velocity = Vector2.ZERO
|
||||
global_position = movePts[-1]
|
||||
currentCell = pos_to_cell(global_position)
|
||||
$PathPrev.points = []; moving = false
|
||||
$PathPrev.points = [];
|
||||
moving = false; MoveFinished.emit();
|
||||
#MapGlobal.SetRegion(calculateMovementRegion(), -unitData["MoveRangeVi"])
|
||||
|
||||
else:
|
||||
var direction = (movePts[currentPoint+1] - movePts[currentPoint]).normalized()
|
||||
velocity = direction * SPEED
|
||||
velocity = direction * unitData["Speed"]
|
||||
move_and_slide()
|
||||
if (movePts[currentPoint+1] - global_position).length() < 4:
|
||||
currentCell = pos_to_cell(global_position)
|
||||
@@ -65,3 +99,16 @@ func selectUnit(cell: Vector2i):
|
||||
selected = true
|
||||
else:
|
||||
selected = false
|
||||
|
||||
func setMoveGrid():
|
||||
if not grid: return
|
||||
moveGrid = grid
|
||||
|
||||
# [moveRange]-tiles in each direction + center
|
||||
var gridSize = unitData["MoveRange"] * 2 + 1
|
||||
# moveGrid.set_size(Vector2i(gridSize, gridSize))
|
||||
moveGrid.region = (Rect2i(global_position, Vector2i(gridSize, gridSize)))
|
||||
moveGrid.offset = unitData["MoveRangeV"]
|
||||
|
||||
func GetMoveGrid() -> AStarGrid2D:
|
||||
return moveGrid
|
||||
File diff suppressed because one or more lines are too long
120
Scenes/Map/map_global.gd
Normal file
120
Scenes/Map/map_global.gd
Normal file
@@ -0,0 +1,120 @@
|
||||
extends Node2D
|
||||
|
||||
@onready var GroundLayer: TileMapLayer = $Ground
|
||||
@onready var ObstacleLayer: TileMapLayer = $Obstacles
|
||||
# Maybe a SubClass that is a Singleton, so we can create one grid
|
||||
# and then change it per Map
|
||||
var _aStarGrid: AStarGrid2D
|
||||
|
||||
var _gridData = {
|
||||
"cellSize": Vector2.ZERO,
|
||||
"fullRegion": Rect2i(0,0,0,0),
|
||||
"currentRegion": Rect2i(0,0,0,0)
|
||||
}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
#_aStarGrid = generateSimpleGrid()
|
||||
# _aStarGrid = generateObstacleGrid()
|
||||
# %GridDisplay.grid = _aStarGrid
|
||||
pass
|
||||
|
||||
func generateSimpleGrid() -> AStarGrid2D:
|
||||
var grid = newGrid(Vector2.ZERO, Rect2i(0,0,0,0))
|
||||
|
||||
for id in GroundLayer.get_used_cells():
|
||||
var data: TileData = GroundLayer.get_cell_tile_data(id)
|
||||
if data and data.get_custom_data('obstacle'):
|
||||
grid.set_point_solid(id)
|
||||
|
||||
return grid
|
||||
|
||||
func generateObstacleGrid() -> AStarGrid2D:
|
||||
var grid = newGrid(Vector2.ZERO, Rect2i(0,0,0,0))
|
||||
|
||||
var layers = ObstacleLayer.get_children()
|
||||
for layer in layers:
|
||||
for id in layer.get_used_cells():
|
||||
var data: TileData = layer.get_cell_tile_data(id)
|
||||
if data and data.get_custom_data('obstacle'):
|
||||
grid.set_point_solid(id)
|
||||
|
||||
return grid
|
||||
|
||||
func GenerateGridFromLayer(layer: TileMapLayer):
|
||||
var ground = layer.get_parent().get_node("Ground")
|
||||
#var grid = newGrid(ground.tile_set.tile_size, ground.get_used_rect())
|
||||
var grid = GetGrid()
|
||||
|
||||
if _gridData["cellSize"] == Vector2.ZERO:
|
||||
SetCellSize(ground.tile_set.tile_size)
|
||||
|
||||
if _gridData["fullRegion"] == Rect2i(0,0,0,0):
|
||||
_gridData["fullRegion"] = ground.get_used_rect()
|
||||
|
||||
_updateRegionFrom("fullRegion")
|
||||
|
||||
var childLayers = layer.get_children()
|
||||
if childLayers.size() > 0:
|
||||
for childLayer in childLayers:
|
||||
for id in childLayer.get_used_cells():
|
||||
var data: TileData = childLayer.get_cell_tile_data(id)
|
||||
if data and data.get_custom_data('obstacle'):
|
||||
GetGrid().set_point_solid(id)
|
||||
else:
|
||||
for id in layer.get_used_cells():
|
||||
var data: TileData = layer.get_cell_tile_data(id)
|
||||
if data and data.get_custom_data('obstacle'):
|
||||
GetGrid().set_point_solid(id)
|
||||
|
||||
GetGrid().update()
|
||||
|
||||
func newGrid(cellSize: Vector2, region: Rect2i) -> AStarGrid2D:
|
||||
_gridData["cellSize"] = cellSize
|
||||
_gridData["fullRegion"] = region
|
||||
var _astarGrid = AStarGrid2D.new()
|
||||
_astarGrid.default_compute_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
|
||||
_astarGrid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
|
||||
_astarGrid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_ONLY_IF_NO_OBSTACLES
|
||||
_astarGrid.cell_size = cellSize
|
||||
_astarGrid.region = region
|
||||
|
||||
_astarGrid.update()
|
||||
|
||||
_aStarGrid = _astarGrid
|
||||
|
||||
return _astarGrid
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func GetGrid():
|
||||
if !_aStarGrid:
|
||||
_aStarGrid = newGrid(Vector2.ZERO, Rect2i())
|
||||
|
||||
return _aStarGrid
|
||||
|
||||
func SetGridData(key: Variant, value: Variant):
|
||||
if _gridData.has(key):
|
||||
_gridData[key] = value
|
||||
|
||||
func getData():
|
||||
return _gridData
|
||||
|
||||
func SetRegion(region: Rect2i, offset: Vector2i = Vector2i.ZERO):
|
||||
_gridData["currentRegion"] = region
|
||||
_aStarGrid.offset = offset
|
||||
_updateRegionFrom("currentRegion")
|
||||
|
||||
func _updateRegionFrom(region: String):
|
||||
_aStarGrid.region = _gridData[region]
|
||||
_aStarGrid.update()
|
||||
|
||||
func SetCellSize(cellSize: Vector2):
|
||||
_gridData["cellSize"] = cellSize
|
||||
_updateCellSize()
|
||||
|
||||
func _updateCellSize():
|
||||
_aStarGrid.cell_size = _gridData["cellSize"]
|
||||
_aStarGrid.update()
|
||||
1
Scenes/Map/map_global.gd.uid
Normal file
1
Scenes/Map/map_global.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://76bfwrwrqfqr
|
||||
@@ -9,8 +9,14 @@ size = Vector2(16, 16)
|
||||
size = Vector2(32, 32)
|
||||
|
||||
[node name="BaseUnit" type="CharacterBody2D"]
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_bo1wp")
|
||||
currentCell = Vector2i(20, 20)
|
||||
unitData = {
|
||||
"MoveRange": 10,
|
||||
"MoveRangeV": Vector2(5, 5),
|
||||
"MoveRangeVi": Vector2i(5, 5),
|
||||
"Speed": 400.0
|
||||
}
|
||||
|
||||
[node name="PathPrev" type="Line2D" parent="."]
|
||||
top_level = true
|
||||
@@ -21,4 +27,5 @@ default_color = Color(0, 0.3372549, 0.3372549, 1)
|
||||
texture = SubResource("PlaceholderTexture2D_imbg2")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
shape = SubResource("RectangleShape2D_hfg1r")
|
||||
|
||||
21
addons/godot-git-plugin/LICENSE
Normal file
21
addons/godot-git-plugin/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016-2023 The Godot Engine community
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1346
addons/godot-git-plugin/THIRDPARTY.md
Normal file
1346
addons/godot-git-plugin/THIRDPARTY.md
Normal file
File diff suppressed because it is too large
Load Diff
10
addons/godot-git-plugin/git_plugin.gdextension
Normal file
10
addons/godot-git-plugin/git_plugin.gdextension
Normal file
@@ -0,0 +1,10 @@
|
||||
[configuration]
|
||||
|
||||
entry_symbol = "git_plugin_init"
|
||||
compatibility_minimum = "4.2.0"
|
||||
|
||||
[libraries]
|
||||
|
||||
linux.editor.x86_64 = "linux/libgit_plugin.linux.editor.x86_64.so"
|
||||
macos.editor = "macos/libgit_plugin.macos.editor.universal.dylib"
|
||||
windows.editor.x86_64 = "windows/libgit_plugin.windows.editor.x86_64.dll"
|
||||
1
addons/godot-git-plugin/git_plugin.gdextension.uid
Normal file
1
addons/godot-git-plugin/git_plugin.gdextension.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://coeqykxqx1fl6
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,7 @@ config/icon="uid://dorwg1gp5fr41"
|
||||
[autoload]
|
||||
|
||||
CameraControl="*res://addons/smartcamera2D/CameraControl.gd"
|
||||
MapGlobal="*res://Scenes/Map/map_global.gd"
|
||||
|
||||
[display]
|
||||
|
||||
@@ -30,6 +31,11 @@ window/size/no_focus=true
|
||||
|
||||
project/assembly_name="TurnBasedStrategyGame"
|
||||
|
||||
[editor]
|
||||
|
||||
version_control/plugin_name="GitPlugin"
|
||||
version_control/autoload_on_startup=true
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray("res://addons/smartcamera2D/plugin.cfg")
|
||||
|
||||
Reference in New Issue
Block a user