Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local map #27

Merged
merged 14 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.import
.import
27 changes: 19 additions & 8 deletions godot/Game.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
extends Node

onready var combat_arena = $CombatArena
var combat_arena = preload("res://combat/CombatArena.tscn").instance()

onready var transition = $Overlays/TransitionColor
onready var local_map = get_node("LocalMap")

var transitioning = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid mutable state. This variable isn't necessary, it just makes the code more bug-prone if other scripts start to rely on it.

func _ready():
enter_battle()
#enter_battle()
local_map.connect("encounter", self, "enter_battle")
local_map.visible = true


func enter_battle():
func enter_battle(formation_name : String):
"""
Plays the combat transition animation and initializes the combat scene
"""
yield(transition.fade_to_color(), "completed")
combat_arena.initialize()
yield(get_tree().create_timer(0.8), "timeout")
yield(transition.fade_from_color(), "completed")
combat_arena.battle_start()
if not transitioning:
transitioning = true
yield(transition.fade_to_color(), "completed")
local_map.visible = false
add_child(combat_arena)
yield(get_tree().create_timer(0.8), "timeout")
combat_arena.initialize()
yield(transition.fade_from_color(), "completed")
combat_arena.battle_start()
transitioning = false
10 changes: 3 additions & 7 deletions godot/Game.tscn
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://combat/CombatArena.tscn" type="PackedScene" id=2]
[ext_resource path="res://local_map/LocalMap.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/shaders/TransitionColor.tscn" type="PackedScene" id=3]


[node name="Game" type="Node"]
script = ExtResource( 1 )

[node name="CombatArena" parent="." instance=ExtResource( 2 )]
[node name="LocalMap" parent="." instance=ExtResource( 2 )]

[node name="Overlays" type="CanvasLayer" parent="."]
layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )

[node name="TransitionColor" parent="Overlays" instance=ExtResource( 3 )]

3 changes: 1 addition & 2 deletions godot/combat/battlers/Battler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ func appear():
skin.appear()

func choose_target(targets : Array):
"""
"""
This function will return a target with the following policy:
There is a chance of DEFAULT_CHANCE to target the foe with min health
else it will randomly choose an opponent
"""
var this_chance = randi() % 100
Expand Down
3 changes: 3 additions & 0 deletions godot/local_map/LocalMap.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends Node

signal encounter(enemy_group)
59 changes: 59 additions & 0 deletions godot/local_map/LocalMap.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[gd_scene load_steps=9 format=2]

[ext_resource path="res://local_map/LocalMap.gd" type="Script" id=1]
[ext_resource path="res://local_map/tilesets/grid_lines/grid_lines_tileset.tres" type="TileSet" id=2]
[ext_resource path="res://local_map/tilesets/grid/grid_tileset.tres" type="TileSet" id=3]
[ext_resource path="res://local_map/grid/grid.gd" type="Script" id=4]
[ext_resource path="res://local_map/pawns/Actor.tscn" type="PackedScene" id=5]
[ext_resource path="res://local_map/pawns/pawn.gd" type="Script" id=6]
[ext_resource path="res://local_map/pawns/sprites/character_grey.png" type="Texture" id=7]
[ext_resource path="res://local_map/pawns/sprites/star.png" type="Texture" id=8]


[node name="LocalMap" type="Node2D"]
script = ExtResource( 1 )

[node name="GridLines" type="TileMap" parent="."]
modulate = Color( 1, 1, 1, 0.271059 )
z_index = -1
z_as_relative = false
tile_set = ExtResource( 2 )
format = 1
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18, 0, 0, 19, 0, 0, 20, 0, 0, 21, 0, 0, 22, 0, 0, 23, 0, 0, 24, 0, 0, 25, 0, 0, 26, 0, 0, 27, 0, 0, 28, 0, 0, 29, 0, 0, 65536, 0, 0, 65537, 0, 0, 65538, 0, 0, 65539, 0, 0, 65540, 0, 0, 65541, 0, 0, 65542, 0, 0, 65543, 0, 0, 65544, 0, 0, 65545, 0, 0, 65546, 0, 0, 65547, 0, 0, 65548, 0, 0, 65549, 0, 0, 65550, 0, 0, 65551, 0, 0, 65552, 0, 0, 65553, 0, 0, 65556, 0, 0, 65557, 0, 0, 65558, 0, 0, 65559, 0, 0, 65560, 0, 0, 65561, 0, 0, 65562, 0, 0, 65563, 0, 0, 65564, 0, 0, 65565, 0, 0, 131072, 0, 0, 131073, 0, 0, 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 131079, 0, 0, 131080, 0, 0, 131081, 0, 0, 131082, 0, 0, 131083, 0, 0, 131084, 0, 0, 131085, 0, 0, 131086, 0, 0, 131087, 0, 0, 131088, 0, 0, 131089, 0, 0, 131092, 0, 0, 131093, 0, 0, 131094, 0, 0, 131095, 0, 0, 131096, 0, 0, 131097, 0, 0, 131098, 0, 0, 131099, 0, 0, 131100, 0, 0, 131101, 0, 0, 196608, 0, 0, 196609, 0, 0, 196610, 0, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 196620, 0, 0, 196621, 0, 0, 196622, 0, 0, 196623, 0, 0, 196624, 0, 0, 196625, 0, 0, 196628, 0, 0, 196629, 0, 0, 196630, 0, 0, 196631, 0, 0, 196632, 0, 0, 196633, 0, 0, 196634, 0, 0, 196635, 0, 0, 196636, 0, 0, 196637, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 262149, 0, 0, 262150, 0, 0, 262151, 0, 0, 262152, 0, 0, 262153, 0, 0, 262154, 0, 0, 262155, 0, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262159, 0, 0, 262160, 0, 0, 262161, 0, 0, 262164, 0, 0, 262165, 0, 0, 262166, 0, 0, 262167, 0, 0, 262168, 0, 0, 262169, 0, 0, 262170, 0, 0, 262171, 0, 0, 262172, 0, 0, 262173, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 327687, 0, 0, 327688, 0, 0, 327689, 0, 0, 327690, 0, 0, 327691, 0, 0, 327692, 0, 0, 327693, 0, 0, 327694, 0, 0, 327695, 0, 0, 327696, 0, 0, 327697, 0, 0, 327698, 0, 0, 327699, 0, 0, 327700, 0, 0, 327701, 0, 0, 327702, 0, 0, 327703, 0, 0, 327704, 0, 0, 327705, 0, 0, 327706, 0, 0, 327707, 0, 0, 327708, 0, 0, 327709, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 393229, 0, 0, 393230, 0, 0, 393231, 0, 0, 393232, 0, 0, 393233, 0, 0, 393234, 0, 0, 393235, 0, 0, 393236, 0, 0, 393237, 0, 0, 393238, 0, 0, 393239, 0, 0, 393240, 0, 0, 393241, 0, 0, 393242, 0, 0, 393243, 0, 0, 393244, 0, 0, 393245, 0, 0, 458752, 0, 0, 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, 0, 0, 458765, 0, 0, 458766, 0, 0, 458767, 0, 0, 458768, 0, 0, 458769, 0, 0, 458770, 0, 0, 458771, 0, 0, 458772, 0, 0, 458773, 0, 0, 458774, 0, 0, 458775, 0, 0, 458776, 0, 0, 458777, 0, 0, 458778, 0, 0, 458779, 0, 0, 458780, 0, 0, 458781, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0, 524304, 0, 0, 524305, 0, 0, 524306, 0, 0, 524307, 0, 0, 524308, 0, 0, 524309, 0, 0, 524310, 0, 0, 524311, 0, 0, 524312, 0, 0, 524313, 0, 0, 524314, 0, 0, 524315, 0, 0, 524316, 0, 0, 524317, 0, 0, 589824, 0, 0, 589825, 0, 0, 589826, 0, 0, 589827, 0, 0, 589828, 0, 0, 589829, 0, 0, 589830, 0, 0, 589831, 0, 0, 589832, 0, 0, 589833, 0, 0, 589834, 0, 0, 589835, 0, 0, 589836, 0, 0, 589837, 0, 0, 589838, 0, 0, 589839, 0, 0, 589840, 0, 0, 589841, 0, 0, 589842, 0, 0, 589843, 0, 0, 589844, 0, 0, 589845, 0, 0, 589846, 0, 0, 589847, 0, 0, 589848, 0, 0, 589849, 0, 0, 589850, 0, 0, 589851, 0, 0, 589852, 0, 0, 589853, 0, 0, 655373, 0, 0, 655374, 0, 0, 655375, 0, 0, 655376, 0, 0, 655377, 0, 0, 655378, 0, 0, 655379, 0, 0, 655380, 0, 0, 655381, 0, 0, 655382, 0, 0, 655383, 0, 0, 655384, 0, 0, 655385, 0, 0, 655386, 0, 0, 655387, 0, 0, 655388, 0, 0, 655389, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720903, 0, 0, 720904, 0, 0, 720905, 0, 0, 720906, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720910, 0, 0, 720911, 0, 0, 720912, 0, 0, 720913, 0, 0, 720914, 0, 0, 720915, 0, 0, 720916, 0, 0, 720917, 0, 0, 720918, 0, 0, 720919, 0, 0, 720920, 0, 0, 720922, 0, 0, 720924, 0, 0, 720925, 0, 0, 786433, 0, 0, 786434, 0, 0, 786435, 0, 0, 786436, 0, 0, 786437, 0, 0, 786438, 0, 0, 786439, 0, 0, 786440, 0, 0, 786441, 0, 0, 786442, 0, 0, 786443, 0, 0, 786444, 0, 0, 786445, 0, 0, 786446, 0, 0, 786447, 0, 0, 786448, 0, 0, 786449, 0, 0, 786450, 0, 0, 786451, 0, 0, 786452, 0, 0, 786453, 0, 0, 786454, 0, 0, 786455, 0, 0, 786456, 0, 0, 786457, 0, 0, 786458, 0, 0, 786459, 0, 0, 786460, 0, 0, 786461, 0, 0, 851969, 0, 0, 851970, 0, 0, 851971, 0, 0, 851972, 0, 0, 851973, 0, 0, 851974, 0, 0, 851975, 0, 0, 851976, 0, 0, 851977, 0, 0, 851978, 0, 0, 851979, 0, 0, 851980, 0, 0, 851981, 0, 0, 851982, 0, 0, 851983, 0, 0, 851984, 0, 0, 851985, 0, 0, 851986, 0, 0, 851987, 0, 0, 851988, 0, 0, 851989, 0, 0, 851990, 0, 0, 851991, 0, 0, 851992, 0, 0, 851993, 0, 0, 851994, 0, 0, 851995, 0, 0, 851996, 0, 0, 851997, 0, 0, 917505, 0, 0, 917506, 0, 0, 917507, 0, 0, 917508, 0, 0, 917509, 0, 0, 917510, 0, 0, 917511, 0, 0, 917512, 0, 0, 917513, 0, 0, 917514, 0, 0, 917515, 0, 0, 917516, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 917523, 0, 0, 917524, 0, 0, 917525, 0, 0, 917526, 0, 0, 917527, 0, 0, 917528, 0, 0, 917529, 0, 0, 917530, 0, 0, 917531, 0, 0, 917532, 0, 0, 917533, 0, 0, 983041, 0, 0, 983042, 0, 0, 983043, 0, 0, 983044, 0, 0, 983045, 0, 0, 983046, 0, 0, 983047, 0, 0, 983048, 0, 0, 983049, 0, 0, 983050, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 983059, 0, 0, 983060, 0, 0, 983061, 0, 0, 983062, 0, 0, 983063, 0, 0, 983064, 0, 0, 983065, 0, 0, 983066, 0, 0, 983067, 0, 0, 983068, 0, 0, 983069, 0, 0, 1048605, 0, 0 )
__meta__ = {
"_edit_lock_": true
}

[node name="Grid" type="TileMap" parent="."]
tile_set = ExtResource( 3 )
format = 1
tile_data = PoolIntArray( 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 5, 1, 0, 6, 1, 0, 7, 1, 0, 8, 1, 0, 9, 1, 0, 10, 1, 0, 11, 1, 0, 12, 1, 0, 13, 1, 0, 14, 1, 0, 15, 1, 0, 16, 1, 0, 17, 1, 0, 18, 1, 0, 19, 1, 0, 20, 1, 0, 21, 1, 0, 22, 1, 0, 23, 1, 0, 24, 1, 0, 25, 1, 0, 26, 1, 0, 27, 1, 0, 28, 1, 0, 29, 1, 0, 65536, 1, 0, 65554, 1, 0, 65555, 1, 0, 65565, 1, 0, 131072, 1, 0, 131090, 1, 0, 131091, 1, 0, 131101, 1, 0, 196608, 1, 0, 196615, 1, 0, 196616, 1, 0, 196617, 1, 0, 196626, 1, 0, 196627, 1, 0, 196637, 1, 0, 262144, 1, 0, 262151, 1, 0, 262162, 1, 0, 262163, 1, 0, 262173, 1, 0, 327680, 1, 0, 327687, 1, 0, 327688, 1, 0, 327689, 1, 0, 327709, 1, 0, 393216, 1, 0, 393245, 1, 0, 458752, 1, 0, 458753, 1, 0, 458754, 1, 0, 458781, 1, 0, 524288, 1, 0, 524289, 1, 0, 524290, 1, 0, 524317, 1, 0, 589824, 1, 0, 589825, 1, 0, 589826, 1, 0, 589827, 1, 0, 589828, 1, 0, 589829, 1, 0, 589830, 1, 0, 589831, 1, 0, 589842, 1, 0, 589843, 1, 0, 589853, 1, 0, 655360, 1, 0, 655361, 1, 0, 655362, 1, 0, 655363, 1, 0, 655364, 1, 0, 655365, 1, 0, 655366, 1, 0, 655367, 1, 0, 655368, 1, 0, 655369, 1, 0, 655370, 1, 0, 655371, 1, 0, 655372, 1, 0, 655373, 1, 0, 655374, 1, 0, 655375, 1, 0, 655376, 1, 0, 655377, 1, 0, 655378, 1, 0, 655379, 1, 0, 655389, 1, 0, 720896, 1, 0, 720921, 1, 0, 720922, 1, 0, 720923, 1, 0, 720925, 1, 0, 786432, 1, 0, 786436, 1, 0, 786459, 1, 0, 786461, 1, 0, 851968, 1, 0, 851972, 1, 0, 851993, 1, 0, 851994, 1, 0, 851995, 1, 0, 851997, 1, 0, 917504, 1, 0, 917505, 1, 0, 917508, 1, 0, 917533, 1, 0, 983040, 1, 0, 983041, 1, 0, 983042, 1, 0, 983043, 1, 0, 983044, 1, 0, 983045, 1, 0, 983046, 1, 0, 983047, 1, 0, 983048, 1, 0, 983049, 1, 0, 983050, 1, 0, 983051, 1, 0, 983052, 1, 0, 983053, 1, 0, 983054, 1, 0, 983055, 1, 0, 983056, 1, 0, 983057, 1, 0, 983058, 1, 0, 983059, 1, 0, 983060, 1, 0, 983061, 1, 0, 983062, 1, 0, 983063, 1, 0, 983064, 1, 0, 983065, 1, 0, 983066, 1, 0, 983067, 1, 0, 983068, 1, 0, 983069, 1, 0, 1048576, 1, 0, 1048577, 1, 0, 1048578, 1, 0, 1048579, 1, 0, 1048580, 1, 0, 1048581, 1, 0, 1048582, 1, 0, 1048583, 1, 0, 1048584, 1, 0, 1048585, 1, 0, 1048586, 1, 0, 1048587, 1, 0, 1048588, 1, 0, 1048589, 1, 0, 1048590, 1, 0, 1048591, 1, 0, 1048592, 1, 0, 1048593, 1, 0, 1048594, 1, 0, 1048595, 1, 0, 1048596, 1, 0, 1048597, 1, 0, 1048598, 1, 0, 1048599, 1, 0, 1048600, 1, 0, 1048601, 1, 0, 1048602, 1, 0, 1048603, 1, 0, 1048604, 1, 0, 1048605, 1, 0 )
script = ExtResource( 4 )
__meta__ = {
"_edit_lock_": true
}

[node name="Actor" parent="Grid" instance=ExtResource( 5 )]
editor/display_folded = true
position = Vector2( 416, 288 )

[node name="Actor2" type="Node2D" parent="Grid" groups=[
"enemy",
]]
position = Vector2( 480, 480 )
z_index = 1
script = ExtResource( 6 )
formation_name = ""

[node name="Sprite" type="Sprite" parent="Grid/Actor2"]
texture = ExtResource( 7 )

[node name="Object" type="Node2D" parent="Grid"]
position = Vector2( 544, 288 )
script = ExtResource( 6 )

[node name="Sprite" type="Sprite" parent="Grid/Object"]
texture = ExtResource( 8 )


[editable path="Grid/Actor"]
37 changes: 37 additions & 0 deletions godot/local_map/grid/grid.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
extends TileMap

enum CELL_TYPES {EMPTY = -1, ACTOR, OBSTACLE, OBJECT}


func _ready():
for child in get_children():
set_cellv(world_to_map(child.position), child.type)


func get_cell_pawn(coordinates):
for node in get_children():
if world_to_map(node.position) == coordinates:
return(node)


func request_move(pawn, direction):
var cell_start = world_to_map(pawn.position)
var cell_target = cell_start + direction

var cell_target_type = get_cellv(cell_target)
match cell_target_type:
CELL_TYPES.EMPTY:
return update_pawn_position(pawn, cell_start, cell_target)
CELL_TYPES.OBJECT:
var object_pawn = get_cell_pawn(cell_target)
object_pawn.queue_free()
return update_pawn_position(pawn, cell_start, cell_target)
CELL_TYPES.ACTOR:
var enemy = get_cell_pawn(cell_target)
get_parent().emit_signal("encounter" , enemy.formation_name)


func update_pawn_position(pawn, cell_start, cell_target):
set_cellv(cell_target, pawn.type)
set_cellv(cell_start, CELL_TYPES.EMPTY)
return map_to_world(cell_target) + cell_size / 2
89 changes: 89 additions & 0 deletions godot/local_map/pawns/Actor.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://local_map/pawns/actor.gd" type="Script" id=1]
[ext_resource path="res://local_map/pawns/sprites/character.png" type="Texture" id=2]

[sub_resource type="Animation" id=1]

resource_name = "bump"
length = 0.1
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.02, 0.04, 0.06, 0.08, 0.1 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector2( 0, 0 ), Vector2( -1.5, -9 ), Vector2( 6.5, 2.5 ), Vector2( -11.5, 8.5 ), Vector2( 4, -5 ), Vector2( 0, 0 ) ]
}

[sub_resource type="Animation" id=2]

resource_name = "walk"
length = 0.25
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("Pivot/Sprite:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = false
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.25 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 0.9375, 0, 1 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Pivot/Sprite:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.1, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.303143, 2.61003, 1 ),
"update": 0,
"values": [ Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 1.43051e-06, -1.90735e-06 ), Vector2( 0, -20 ), Vector2( 1.43051e-06, -1.90735e-06 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Pivot/Sprite:scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.25 ),
"transitions": PoolRealArray( 1, 0.354553, 1, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 1.20007, 0.917384 ), Vector2( 0.916712, 1.13495 ), Vector2( 1, 1 ) ]
}

[node name="Actor" type="Node2D"]
position = Vector2( 32, 32 )
z_index = 1
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
_sections_unfolded = [ "Offset", "Transform", "Z Index" ]
type = 0

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/bump = SubResource( 1 )
anims/walk = SubResource( 2 )

[node name="Tween" type="Tween" parent="."]

[node name="Pivot" type="Position2D" parent="."]

[node name="Sprite" type="Sprite" parent="Pivot"]
position = Vector2( 1.43051e-06, -1.90735e-06 )
texture = ExtResource( 2 )
centered = false
offset = Vector2( -32, -32 )

55 changes: 55 additions & 0 deletions godot/local_map/pawns/actor.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
extends "pawn.gd"

onready var Grid = get_parent()

func _ready():
update_look_direction(Vector2(1, 0))


func _process(delta):
var input_direction = get_input_direction()
if not input_direction:
return
update_look_direction(input_direction)

var target_position = Grid.request_move(self, input_direction)
if target_position:
move_to(target_position)
else:
bump()


func get_input_direction():
return Vector2(
int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")),
int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))
)


func update_look_direction(direction):
$Pivot/Sprite.rotation = direction.angle()


func move_to(target_position):
set_process(false)
$AnimationPlayer.play("walk")

# Move the node to the target cell instantly,
# and animate the sprite moving from the start to the target cell
var move_direction = (target_position - position).normalized()
$Tween.interpolate_property($Pivot, "position", - move_direction * 32, Vector2(), $AnimationPlayer.current_animation_length, Tween.TRANS_LINEAR, Tween.EASE_IN)
position = target_position

$Tween.start()

# Stop the function execution until the animation finished
yield($AnimationPlayer, "animation_finished")

set_process(true)


func bump():
set_process(false)
$AnimationPlayer.play("bump")
yield($AnimationPlayer, "animation_finished")
set_process(true)
6 changes: 6 additions & 0 deletions godot/local_map/pawns/pawn.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Node2D

enum CELL_TYPES { ACTOR, OBSTACLE, OBJECT }
export(CELL_TYPES) var type = CELL_TYPES.ACTOR
# holds the formation
export (String) var formation_name
Binary file added godot/local_map/pawns/sprites/character.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions godot/local_map/pawns/sprites/character.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/character.png-94bb687dc75f85a5f83500b0a82295ad.stex"

[deps]

source_file="res://local_map/pawns/sprites/character.png"
dest_files=[ "res://.import/character.png-94bb687dc75f85a5f83500b0a82295ad.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added godot/local_map/pawns/sprites/character_grey.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions godot/local_map/pawns/sprites/character_grey.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/character_grey.png-e7ea3733a1c711455d1c2c831fd14564.stex"

[deps]

source_file="res://local_map/pawns/sprites/character_grey.png"
dest_files=[ "res://.import/character_grey.png-e7ea3733a1c711455d1c2c831fd14564.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added godot/local_map/pawns/sprites/star.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.