Initial commit
This commit is contained in:
42
scripts/camera_controller.gd
Normal file
42
scripts/camera_controller.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
class_name CameraController extends Camera2D
|
||||
|
||||
const DRAG_THRESHOLD := 8.0
|
||||
|
||||
var _dragging := false
|
||||
var _left_pending := false
|
||||
var _drag_start := Vector2.ZERO
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
match event.button_index:
|
||||
MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
_left_pending = true
|
||||
_drag_start = event.position
|
||||
else:
|
||||
_left_pending = false
|
||||
if _dragging:
|
||||
_dragging = false
|
||||
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
||||
get_viewport().set_input_as_handled()
|
||||
MOUSE_BUTTON_MIDDLE:
|
||||
if event.pressed:
|
||||
_dragging = true
|
||||
_drag_start = event.position
|
||||
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
|
||||
else:
|
||||
_dragging = false
|
||||
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event is InputEventMouseMotion:
|
||||
if _left_pending and not _dragging:
|
||||
if event.position.distance_to(_drag_start) >= DRAG_THRESHOLD:
|
||||
_dragging = true
|
||||
_left_pending = false
|
||||
Input.set_default_cursor_shape(Input.CURSOR_DRAG)
|
||||
if _dragging:
|
||||
var delta: Vector2 = _drag_start - event.position
|
||||
_drag_start = event.position
|
||||
position += delta / zoom
|
||||
get_viewport().set_input_as_handled()
|
||||
1
scripts/camera_controller.gd.uid
Normal file
1
scripts/camera_controller.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://csdcbi2gtwrly
|
||||
33
scripts/combat_ui.gd
Normal file
33
scripts/combat_ui.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
class_name CombatUI extends CanvasLayer
|
||||
|
||||
@onready var unit_panel: PanelContainer = %UnitPanel
|
||||
@onready var name_label: Label = %NameLabel
|
||||
@onready var hp_bar: ProgressBar = %HPBar
|
||||
|
||||
var _selected_unit: Unit
|
||||
|
||||
func _ready() -> void:
|
||||
unit_panel.visible = false
|
||||
for unit: Unit in get_tree().get_nodes_in_group("units"):
|
||||
unit.unit_selected_changed.connect(_on_unit_selected_changed)
|
||||
get_tree().node_added.connect(_on_node_added)
|
||||
|
||||
func _on_node_added(node: Node) -> void:
|
||||
if node is Unit and node.is_in_group("units"):
|
||||
node.unit_selected_changed.connect(_on_unit_selected_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _selected_unit:
|
||||
hp_bar.max_value = _selected_unit.current_stats.max_hp
|
||||
hp_bar.value = _selected_unit.current_stats.current_hp
|
||||
|
||||
func _on_unit_selected_changed(unit: Unit, selected: bool) -> void:
|
||||
if selected:
|
||||
_selected_unit = unit
|
||||
name_label.text = unit.current_info.name
|
||||
hp_bar.max_value = unit.current_stats.max_hp
|
||||
hp_bar.value = unit.current_stats.current_hp
|
||||
unit_panel.visible = true
|
||||
else:
|
||||
_selected_unit = null
|
||||
unit_panel.visible = false
|
||||
1
scripts/combat_ui.gd.uid
Normal file
1
scripts/combat_ui.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://w2wh6gtv3u2l
|
||||
16
scripts/grid_overlay.gd
Normal file
16
scripts/grid_overlay.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
class_name GridOverlay extends TileMapLayer
|
||||
|
||||
const SOURCE_ID = 0
|
||||
const HIGHLIGHT_SPRITE_ID = Vector2i(0,0)
|
||||
|
||||
@onready var targeting_selector: Sprite2D = $TargetingIndicator
|
||||
|
||||
func highlight_tile(coords: Vector2i) -> void:
|
||||
set_cell(coords, SOURCE_ID, HIGHLIGHT_SPRITE_ID)
|
||||
|
||||
func clear_tile(coords: Vector2i) -> void:
|
||||
set_cell(coords)
|
||||
|
||||
func target_tile(coords: Vector2i) -> void:
|
||||
targeting_selector.position = coords * tile_set.tile_size
|
||||
targeting_selector.visible = true
|
||||
1
scripts/grid_overlay.gd.uid
Normal file
1
scripts/grid_overlay.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cxl38x2m6sj3w
|
||||
38
scripts/test_map_generator.gd
Normal file
38
scripts/test_map_generator.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends Node
|
||||
|
||||
const GRID_SIZE := 5
|
||||
|
||||
@export var dl_map: CombatMap
|
||||
@export var unit_template: PackedScene
|
||||
@export var player_allegiance: UnitAllegiance
|
||||
@export var enemy_allegiance: UnitAllegiance
|
||||
|
||||
func _ready() -> void:
|
||||
for x in GRID_SIZE:
|
||||
for y in GRID_SIZE:
|
||||
var pos := Vector2i(x, y)
|
||||
var is_edge := x == 0 or x == GRID_SIZE - 1 or y == 0 or y == GRID_SIZE - 1
|
||||
if is_edge:
|
||||
dl_map.draw_wall(pos)
|
||||
else:
|
||||
dl_map.draw_floor(pos)
|
||||
|
||||
# Create a putit at the center belonging to the player
|
||||
var center := Vector2i(GRID_SIZE / 2, GRID_SIZE / 2)
|
||||
var unit: Unit = unit_template.instantiate()
|
||||
unit.stat_template = UnitStats.new(50)
|
||||
unit.info_template = UnitInfo.new()
|
||||
unit.allegiance_template = player_allegiance
|
||||
unit.info_template.name = "Putit"
|
||||
unit.position = dl_map.coords_to_world(center)
|
||||
get_parent().add_child.call_deferred(unit)
|
||||
|
||||
# Create a putit at one above the center belonging to the enemy
|
||||
var center_enemy := Vector2i(GRID_SIZE / 2, (GRID_SIZE / 2) - 1)
|
||||
var enemy_unit: Unit = unit_template.instantiate()
|
||||
enemy_unit.stat_template = UnitStats.new(50)
|
||||
enemy_unit.info_template = UnitInfo.new()
|
||||
enemy_unit.allegiance_template = enemy_allegiance
|
||||
enemy_unit.info_template.name = "Putit"
|
||||
enemy_unit.position = dl_map.coords_to_world(center_enemy)
|
||||
get_parent().add_child.call_deferred(enemy_unit)
|
||||
1
scripts/test_map_generator.gd.uid
Normal file
1
scripts/test_map_generator.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c8xb86ty7rduf
|
||||
37
scripts/tile_highlight.gd
Normal file
37
scripts/tile_highlight.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
extends ColorRect
|
||||
|
||||
signal tile_hovered(coords: Vector2i)
|
||||
|
||||
@export var tile_size: float = 48.0
|
||||
|
||||
var _time: float = 0.0
|
||||
var _previous_coords := Vector2i(INF, INF)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
size = Vector2(tile_size, tile_size)
|
||||
color = Color(1.0, 1.0, 1.0, 0.25)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_time += delta
|
||||
color.a = 0.25 + 0.1 * sin(_time * 4.0)
|
||||
var mouse_pos := get_global_mouse_position()
|
||||
var snapped_pos := _snap_to_grid(mouse_pos)
|
||||
global_position = snapped_pos
|
||||
var coords := Vector2i(snapped_pos / tile_size)
|
||||
if coords != _previous_coords:
|
||||
_previous_coords = coords
|
||||
tile_hovered.emit(coords)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_MOUSE_EXIT:
|
||||
hide()
|
||||
elif what == NOTIFICATION_WM_MOUSE_ENTER:
|
||||
show()
|
||||
|
||||
|
||||
func _snap_to_grid(pos: Vector2) -> Vector2:
|
||||
return Vector2(floorf(pos.x / tile_size), floorf(pos.y / tile_size)) * tile_size
|
||||
1
scripts/tile_highlight.gd.uid
Normal file
1
scripts/tile_highlight.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b31eyqov8w7bm
|
||||
Reference in New Issue
Block a user