Merge pull request #261 from GDquest/grid-based-movement-2d
Add 2d grid-based movement demo
99
2d/grid_based_movement/Game.tscn
Normal file
@@ -0,0 +1,99 @@
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://tilesets/grid_lines/grid_lines_tileset.tres" type="TileSet" id=1]
|
||||
[ext_resource path="res://tilesets/grid/grid_tileset.tres" type="TileSet" id=2]
|
||||
[ext_resource path="res://grid/grid.gd" type="Script" id=3]
|
||||
[ext_resource path="res://pawns/Actor.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://pawns/pawn.gd" type="Script" id=5]
|
||||
[ext_resource path="res://pawns/sprites/character_grey.png" type="Texture" id=6]
|
||||
[ext_resource path="res://pawns/sprites/star.png" type="Texture" id=7]
|
||||
|
||||
[node name="Game" type="Node"]
|
||||
|
||||
[node name="GridLines" type="TileMap" parent="." index="0"]
|
||||
|
||||
modulate = Color( 1, 1, 1, 0.271059 )
|
||||
z_index = -1
|
||||
z_as_relative = false
|
||||
mode = 0
|
||||
tile_set = ExtResource( 1 )
|
||||
cell_size = Vector2( 64, 64 )
|
||||
cell_quadrant_size = 16
|
||||
cell_custom_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
cell_half_offset = 2
|
||||
cell_tile_origin = 0
|
||||
cell_y_sort = false
|
||||
cell_clip_uv = false
|
||||
collision_use_kinematic = false
|
||||
collision_friction = 1.0
|
||||
collision_bounce = 0.0
|
||||
collision_layer = 1
|
||||
collision_mask = 1
|
||||
occluder_light_mask = 1
|
||||
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, 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, 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, 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, 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, 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, 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, 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, 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, 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 )
|
||||
_sections_unfolded = [ "Visibility", "Z Index" ]
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Grid" type="TileMap" parent="." index="1"]
|
||||
|
||||
mode = 0
|
||||
tile_set = ExtResource( 2 )
|
||||
cell_size = Vector2( 64, 64 )
|
||||
cell_quadrant_size = 16
|
||||
cell_custom_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
cell_half_offset = 2
|
||||
cell_tile_origin = 0
|
||||
cell_y_sort = false
|
||||
cell_clip_uv = false
|
||||
collision_use_kinematic = false
|
||||
collision_friction = 1.0
|
||||
collision_bounce = 0.0
|
||||
collision_layer = 1
|
||||
collision_mask = 1
|
||||
occluder_light_mask = 1
|
||||
format = 1
|
||||
tile_data = PoolIntArray( 18, 1, 0, 19, 1, 0, 65554, 1, 0, 65555, 1, 0, 131090, 1, 0, 131091, 1, 0, 196615, 1, 0, 196616, 1, 0, 196617, 1, 0, 196626, 1, 0, 196627, 1, 0, 262151, 1, 0, 262162, 1, 0, 262163, 1, 0, 327687, 1, 0, 327688, 1, 0, 327689, 1, 0, 327698, 1, 0, 327699, 1, 0, 393234, 1, 0, 393235, 1, 0, 458753, 1, 0, 458754, 1, 0, 458770, 1, 0, 458771, 1, 0, 524289, 1, 0, 524290, 1, 0, 524306, 1, 0, 524307, 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, 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, 720896, 1, 0, 720897, 1, 0, 720898, 1, 0, 720899, 1, 0, 720900, 1, 0, 720901, 1, 0, 720902, 1, 0, 720903, 1, 0, 720904, 1, 0, 720905, 1, 0, 720906, 1, 0, 720907, 1, 0, 720908, 1, 0, 720909, 1, 0, 720910, 1, 0, 720911, 1, 0, 720912, 1, 0, 720913, 1, 0, 720914, 1, 0, 720915, 1, 0 )
|
||||
script = ExtResource( 3 )
|
||||
_sections_unfolded = [ "Visibility" ]
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Actor" parent="Grid" index="0" instance=ExtResource( 4 )]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 416, 288 )
|
||||
|
||||
[node name="Sprite" parent="Grid/Actor/Pivot" index="0"]
|
||||
|
||||
position = Vector2( 1.43051e-06, -1.90735e-06 )
|
||||
|
||||
[node name="Actor2" type="Node2D" parent="Grid" index="1"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 480, 480 )
|
||||
z_index = 1
|
||||
script = ExtResource( 5 )
|
||||
_sections_unfolded = [ "Offset" ]
|
||||
type = 0
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Actor2" index="0"]
|
||||
|
||||
texture = ExtResource( 6 )
|
||||
|
||||
[node name="Object" type="Node2D" parent="Grid" index="2"]
|
||||
|
||||
editor/display_folded = true
|
||||
position = Vector2( 544, 288 )
|
||||
script = ExtResource( 5 )
|
||||
type = 2
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Grid/Object" index="0"]
|
||||
|
||||
texture = ExtResource( 7 )
|
||||
|
||||
|
||||
[editable path="Grid/Actor"]
|
||||
101
2d/grid_based_movement/default_env.tres
Normal file
@@ -0,0 +1,101 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
radiance_size = 4
|
||||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
|
||||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
|
||||
sky_curve = 0.25
|
||||
sky_energy = 1.0
|
||||
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
|
||||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
|
||||
ground_curve = 0.01
|
||||
ground_energy = 1.0
|
||||
sun_color = Color( 1, 1, 1, 1 )
|
||||
sun_latitude = 35.0
|
||||
sun_longitude = 0.0
|
||||
sun_angle_min = 1.0
|
||||
sun_angle_max = 100.0
|
||||
sun_curve = 0.05
|
||||
sun_energy = 16.0
|
||||
texture_size = 2
|
||||
|
||||
[resource]
|
||||
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
background_sky_custom_fov = 0.0
|
||||
background_color = Color( 0, 0, 0, 1 )
|
||||
background_energy = 1.0
|
||||
background_canvas_max_layer = 0
|
||||
ambient_light_color = Color( 0, 0, 0, 1 )
|
||||
ambient_light_energy = 1.0
|
||||
ambient_light_sky_contribution = 1.0
|
||||
fog_enabled = false
|
||||
fog_color = Color( 0.5, 0.6, 0.7, 1 )
|
||||
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
|
||||
fog_sun_amount = 0.0
|
||||
fog_depth_enabled = true
|
||||
fog_depth_begin = 10.0
|
||||
fog_depth_curve = 1.0
|
||||
fog_transmit_enabled = false
|
||||
fog_transmit_curve = 1.0
|
||||
fog_height_enabled = false
|
||||
fog_height_min = 0.0
|
||||
fog_height_max = 100.0
|
||||
fog_height_curve = 1.0
|
||||
tonemap_mode = 0
|
||||
tonemap_exposure = 1.0
|
||||
tonemap_white = 1.0
|
||||
auto_exposure_enabled = false
|
||||
auto_exposure_scale = 0.4
|
||||
auto_exposure_min_luma = 0.05
|
||||
auto_exposure_max_luma = 8.0
|
||||
auto_exposure_speed = 0.5
|
||||
ss_reflections_enabled = false
|
||||
ss_reflections_max_steps = 64
|
||||
ss_reflections_fade_in = 0.15
|
||||
ss_reflections_fade_out = 2.0
|
||||
ss_reflections_depth_tolerance = 0.2
|
||||
ss_reflections_roughness = true
|
||||
ssao_enabled = false
|
||||
ssao_radius = 1.0
|
||||
ssao_intensity = 1.0
|
||||
ssao_radius2 = 0.0
|
||||
ssao_intensity2 = 1.0
|
||||
ssao_bias = 0.01
|
||||
ssao_light_affect = 0.0
|
||||
ssao_color = Color( 0, 0, 0, 1 )
|
||||
ssao_quality = 0
|
||||
ssao_blur = 3
|
||||
ssao_edge_sharpness = 4.0
|
||||
dof_blur_far_enabled = false
|
||||
dof_blur_far_distance = 10.0
|
||||
dof_blur_far_transition = 5.0
|
||||
dof_blur_far_amount = 0.1
|
||||
dof_blur_far_quality = 1
|
||||
dof_blur_near_enabled = false
|
||||
dof_blur_near_distance = 2.0
|
||||
dof_blur_near_transition = 1.0
|
||||
dof_blur_near_amount = 0.1
|
||||
dof_blur_near_quality = 1
|
||||
glow_enabled = false
|
||||
glow_levels/1 = false
|
||||
glow_levels/2 = false
|
||||
glow_levels/3 = true
|
||||
glow_levels/4 = false
|
||||
glow_levels/5 = true
|
||||
glow_levels/6 = false
|
||||
glow_levels/7 = false
|
||||
glow_intensity = 0.8
|
||||
glow_strength = 1.0
|
||||
glow_bloom = 0.0
|
||||
glow_blend_mode = 2
|
||||
glow_hdr_threshold = 1.0
|
||||
glow_hdr_scale = 2.0
|
||||
glow_bicubic_upscale = false
|
||||
adjustment_enabled = false
|
||||
adjustment_brightness = 1.0
|
||||
adjustment_contrast = 1.0
|
||||
adjustment_saturation = 1.0
|
||||
|
||||
36
2d/grid_based_movement/grid/grid.gd
Normal file
@@ -0,0 +1,36 @@
|
||||
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:
|
||||
EMPTY:
|
||||
return update_pawn_position(pawn, cell_start, cell_target)
|
||||
OBJECT:
|
||||
var object_pawn = get_cell_pawn(cell_target)
|
||||
object_pawn.queue_free()
|
||||
return update_pawn_position(pawn, cell_start, cell_target)
|
||||
ACTOR:
|
||||
var pawn_name = get_cell_pawn(cell_target).name
|
||||
print("Cell %s contains %s" % [cell_target, pawn_name])
|
||||
|
||||
|
||||
func update_pawn_position(pawn, cell_start, cell_target):
|
||||
set_cellv(cell_target, pawn.type)
|
||||
set_cellv(cell_start, EMPTY)
|
||||
return map_to_world(cell_target) + cell_size / 2
|
||||
BIN
2d/grid_based_movement/icon.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
32
2d/grid_based_movement/icon.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
source_md5="3280104cdf8f7a9be38f70f9ff95cf50"
|
||||
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||
dest_md5="df9a76b96b1fde8b55778a269d647ca3"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
111
2d/grid_based_movement/pawns/Actor.tscn
Normal file
@@ -0,0 +1,111 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://pawns/actor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://pawns/sprites/character.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
|
||||
resource_name = "bump"
|
||||
length = 0.1
|
||||
loop = false
|
||||
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
|
||||
loop = false
|
||||
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" index="0"]
|
||||
|
||||
position = Vector2( 32, 32 )
|
||||
z_index = 1
|
||||
script = ExtResource( 1 )
|
||||
_sections_unfolded = [ "Offset", "Transform", "Z Index" ]
|
||||
__meta__ = {
|
||||
"_edit_group_": true
|
||||
}
|
||||
type = 0
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="0"]
|
||||
|
||||
root_node = NodePath("..")
|
||||
autoplay = ""
|
||||
playback_process_mode = 1
|
||||
playback_default_blend_time = 0.0
|
||||
playback_speed = 1.0
|
||||
anims/bump = SubResource( 1 )
|
||||
anims/walk = SubResource( 2 )
|
||||
blend_times = [ ]
|
||||
|
||||
[node name="Tween" type="Tween" parent="." index="1"]
|
||||
|
||||
repeat = false
|
||||
playback_process_mode = 1
|
||||
playback_speed = 1.0
|
||||
playback/active = false
|
||||
playback/repeat = false
|
||||
playback/speed = 1.0
|
||||
|
||||
[node name="Pivot" type="Position2D" parent="." index="2"]
|
||||
|
||||
_sections_unfolded = [ "Transform" ]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Pivot" index="0"]
|
||||
|
||||
position = Vector2( 1.43051e-06, -1.90735e-06 )
|
||||
texture = ExtResource( 2 )
|
||||
centered = false
|
||||
offset = Vector2( -32, -32 )
|
||||
_sections_unfolded = [ "Transform", "Visibility" ]
|
||||
|
||||
|
||||
55
2d/grid_based_movement/pawns/actor.gd
Normal file
@@ -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)
|
||||
4
2d/grid_based_movement/pawns/pawn.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends Node2D
|
||||
|
||||
enum CELL_TYPES { ACTOR, OBSTACLE, OBJECT }
|
||||
export(CELL_TYPES) var type = ACTOR
|
||||
BIN
2d/grid_based_movement/pawns/sprites/character.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
32
2d/grid_based_movement/pawns/sprites/character.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/character.png-98ed16816c5b464731c4fa68fe5b8613.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://pawns/sprites/character.png"
|
||||
source_md5="03a1bf4fdd91e5a89e323e1a956b8b2e"
|
||||
|
||||
dest_files=[ "res://.import/character.png-98ed16816c5b464731c4fa68fe5b8613.stex" ]
|
||||
dest_md5="dc0e808a19cb41bd3e4b8af9a1a2878e"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
BIN
2d/grid_based_movement/pawns/sprites/character_grey.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/character_grey.png-a95d64c2e947e85f04dd1c6474e46965.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://pawns/sprites/character_grey.png"
|
||||
source_md5="b2fc93bb6418bd5a1aeb9d4b23281b7d"
|
||||
|
||||
dest_files=[ "res://.import/character_grey.png-a95d64c2e947e85f04dd1c6474e46965.stex" ]
|
||||
dest_md5="119083c34b0b039b9f6742e1aa84bcd1"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
BIN
2d/grid_based_movement/pawns/sprites/star.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
32
2d/grid_based_movement/pawns/sprites/star.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/star.png-4f164f82cf41ace82182660f1be8e68d.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://pawns/sprites/star.png"
|
||||
source_md5="c9eed33ac490155814b63a96281718bc"
|
||||
|
||||
dest_files=[ "res://.import/star.png-4f164f82cf41ace82182660f1be8e68d.stex" ]
|
||||
dest_md5="b5e67be995733c89f151fdfd57ade882"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
24
2d/grid_based_movement/project.godot
Normal file
@@ -0,0 +1,24 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=3
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Grid Movement"
|
||||
run/main_scene="res://Game.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/width=1280
|
||||
window/size/height=720
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
||||
27
2d/grid_based_movement/tilesets/grid/GridTiles.tscn
Normal file
@@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://tilesets/grid/actor.png" type="Texture" id=1]
|
||||
[ext_resource path="res://tilesets/grid/obstacle.png" type="Texture" id=2]
|
||||
[ext_resource path="res://tilesets/grid/object.png" type="Texture" id=3]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
|
||||
[node name="Actor" type="Sprite" parent="." index="0"]
|
||||
|
||||
position = Vector2( 32, 32 )
|
||||
texture = ExtResource( 1 )
|
||||
_sections_unfolded = [ "Visibility" ]
|
||||
|
||||
[node name="Obstacle" type="Sprite" parent="." index="1"]
|
||||
|
||||
position = Vector2( 96, 32 )
|
||||
texture = ExtResource( 2 )
|
||||
_sections_unfolded = [ "Visibility" ]
|
||||
|
||||
[node name="Object" type="Sprite" parent="." index="2"]
|
||||
|
||||
position = Vector2( 160, 32 )
|
||||
texture = ExtResource( 3 )
|
||||
_sections_unfolded = [ "Visibility" ]
|
||||
|
||||
|
||||
BIN
2d/grid_based_movement/tilesets/grid/actor.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
32
2d/grid_based_movement/tilesets/grid/actor.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/actor.png-6a88af8a7bcb079732153877dfb0db8b.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://tilesets/grid/actor.png"
|
||||
source_md5="1a3d788099e6d0431c41627de71ee5f9"
|
||||
|
||||
dest_files=[ "res://.import/actor.png-6a88af8a7bcb079732153877dfb0db8b.stex" ]
|
||||
dest_md5="ca104a9f5ec006ce67b9996d27f4efa2"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
37
2d/grid_based_movement/tilesets/grid/grid_tileset.tres
Normal file
@@ -0,0 +1,37 @@
|
||||
[gd_resource type="TileSet" load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://tilesets/grid/actor.png" type="Texture" id=1]
|
||||
[ext_resource path="res://tilesets/grid/obstacle.png" type="Texture" id=2]
|
||||
[ext_resource path="res://tilesets/grid/object.png" type="Texture" id=3]
|
||||
|
||||
[resource]
|
||||
|
||||
0/name = "Actor"
|
||||
0/texture = ExtResource( 1 )
|
||||
0/tex_offset = Vector2( 0, 0 )
|
||||
0/modulate = Color( 1, 1, 1, 1 )
|
||||
0/region = Rect2( 0, 0, 64, 64 )
|
||||
0/is_autotile = false
|
||||
0/occluder_offset = Vector2( 32, 32 )
|
||||
0/navigation_offset = Vector2( 32, 32 )
|
||||
0/shapes = [ ]
|
||||
1/name = "Obstacle"
|
||||
1/texture = ExtResource( 2 )
|
||||
1/tex_offset = Vector2( 0, 0 )
|
||||
1/modulate = Color( 1, 1, 1, 1 )
|
||||
1/region = Rect2( 0, 0, 64, 64 )
|
||||
1/is_autotile = false
|
||||
1/occluder_offset = Vector2( 32, 32 )
|
||||
1/navigation_offset = Vector2( 32, 32 )
|
||||
1/shapes = [ ]
|
||||
2/name = "Object"
|
||||
2/texture = ExtResource( 3 )
|
||||
2/tex_offset = Vector2( 0, 0 )
|
||||
2/modulate = Color( 1, 1, 1, 1 )
|
||||
2/region = Rect2( 0, 0, 64, 64 )
|
||||
2/is_autotile = false
|
||||
2/occluder_offset = Vector2( 32, 32 )
|
||||
2/navigation_offset = Vector2( 32, 32 )
|
||||
2/shapes = [ ]
|
||||
_sections_unfolded = [ "0", "1" ]
|
||||
|
||||
BIN
2d/grid_based_movement/tilesets/grid/object.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
32
2d/grid_based_movement/tilesets/grid/object.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/object.png-3e89ebfb3424e8759914732b2b0130c1.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://tilesets/grid/object.png"
|
||||
source_md5="53b421d6eb9175f4b3900f7d48ad814e"
|
||||
|
||||
dest_files=[ "res://.import/object.png-3e89ebfb3424e8759914732b2b0130c1.stex" ]
|
||||
dest_md5="1351b2d127dc461bda55bfde616cbdd6"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
BIN
2d/grid_based_movement/tilesets/grid/obstacle.png
Normal file
|
After Width: | Height: | Size: 595 B |
32
2d/grid_based_movement/tilesets/grid/obstacle.png.import
Normal file
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/obstacle.png-9f01dd1d06d7b99515918b65b46bd6c1.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://tilesets/grid/obstacle.png"
|
||||
source_md5="49a4f8eb121c949de35502481ec7e96a"
|
||||
|
||||
dest_files=[ "res://.import/obstacle.png-9f01dd1d06d7b99515918b65b46bd6c1.stex" ]
|
||||
dest_md5="432d869b849ac70d4f76935622b2e37b"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://tilesets/grid_lines/grid_lines.png" type="Texture" id=1]
|
||||
|
||||
[node name="TileSet" type="Node2D" index="0"]
|
||||
|
||||
[node name="Grass" type="Sprite" parent="." index="0"]
|
||||
|
||||
position = Vector2( 32, 32 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
|
||||
BIN
2d/grid_based_movement/tilesets/grid_lines/grid_lines.png
Normal file
|
After Width: | Height: | Size: 656 B |
@@ -0,0 +1,32 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/grid_lines.png-beef853b47aa830c8383e5f6cc4d03ce.stex"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://tilesets/grid_lines/grid_lines.png"
|
||||
source_md5="9c6f3c1506ccfc666a4988a3b9655b1c"
|
||||
|
||||
dest_files=[ "res://.import/grid_lines.png-beef853b47aa830c8383e5f6cc4d03ce.stex" ]
|
||||
dest_md5="411604865dd58a1618832442af953934"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=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
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
@@ -0,0 +1,16 @@
|
||||
[gd_resource type="TileSet" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://tilesets/grid_lines/grid_lines.png" type="Texture" id=1]
|
||||
|
||||
[resource]
|
||||
|
||||
0/name = "Grass"
|
||||
0/texture = ExtResource( 1 )
|
||||
0/tex_offset = Vector2( 0, 0 )
|
||||
0/modulate = Color( 1, 1, 1, 1 )
|
||||
0/region = Rect2( 0, 0, 64, 64 )
|
||||
0/is_autotile = false
|
||||
0/occluder_offset = Vector2( 32, 32 )
|
||||
0/navigation_offset = Vector2( 32, 32 )
|
||||
0/shapes = [ ]
|
||||
|
||||