From 9149e898657322259ff702964c810dda14e99bca Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Sun, 2 Jun 2024 10:25:53 -0700 Subject: [PATCH] Moved actor direction into movement component. Velocity is going to be tough. --- Main.tscn | 7 +++++-- src/actor.gd | 8 +++++--- src/enemyC/EnemyC.tscn | 14 +++++++++++--- src/enemyC/enemyC_movement_component.gd | 13 +++++++++++-- src/movement_component.gd | 5 +++++ src/playerC/Player-KinematicBody2D.gd | 2 +- src/playerC/states/fall.gd | 8 ++------ src/playerC/states/idle.gd | 9 +++++---- src/playerC/states/jump.gd | 8 +++----- src/playerC/states/move.gd | 20 +++++++++----------- src/templates/Actor/states/fall.gd | 8 ++------ src/templates/Actor/states/idle.gd | 4 ++-- src/templates/Actor/states/move.gd | 12 ++++-------- 13 files changed, 65 insertions(+), 53 deletions(-) diff --git a/Main.tscn b/Main.tscn index 0dcd07a..478229c 100644 --- a/Main.tscn +++ b/Main.tscn @@ -153,13 +153,13 @@ tile_set = SubResource( 1 ) cell_size = Vector2( 16, 16 ) show_collision = true format = 1 -tile_data = PoolIntArray( -65536, 0, 196613, 0, 0, 196613, 79, 0, 196613, 65536, 0, 196613, 65615, 0, 196613, 131072, 0, 196613, 131151, 0, 196613, 196608, 0, 196613, 196687, 0, 196613, 262144, 0, 196613, 262223, 0, 196613, 327680, 0, 196613, 327759, 0, 196613, 393216, 0, 196613, 393260, 0, 196613, 393261, 0, 196613, 393295, 0, 196613, 458752, 0, 196613, 458792, 0, 196613, 458793, 0, 196613, 458794, 0, 196613, 458795, 0, 196613, 458796, 0, 196613, 458797, 0, 196613, 458831, 0, 196613, 524288, 0, 196613, 524307, 0, 196613, 524308, 0, 196613, 524327, 0, 196613, 524328, 0, 196613, 524329, 0, 196613, 524330, 0, 196613, 524334, 0, 196613, 524367, 0, 196613, 589824, 0, 196613, 589843, 0, 196613, 589844, 0, 196613, 589863, 0, 196613, 589864, 0, 196613, 589870, 0, 196613, 589903, 0, 196613, 655360, 0, 196613, 655361, 0, 2, 655362, 0, 2, 655363, 0, 2, 655364, 0, 2, 655365, 0, 2, 655366, 0, 2, 655367, 0, 2, 655368, 0, 2, 655369, 0, 2, 655370, 0, 2, 655371, 0, 2, 655372, 0, 2, 655373, 0, 2, 655374, 0, 2, 655375, 0, 2, 655376, 0, 2, 655377, 0, 2, 655378, 0, 2, 655379, 0, 196613, 655380, 0, 196613, 655381, 0, 196613, 655382, 0, 196613, 655383, 0, 196613, 655384, 0, 196613, 655385, 0, 196613, 655386, 0, 196613, 655387, 0, 196613, 655388, 0, 196613, 655389, 0, 196613, 655390, 0, 196613, 655391, 0, 196613, 655392, 0, 196613, 655393, 0, 196613, 655394, 0, 196613, 655395, 0, 196613, 655396, 0, 196613, 655397, 0, 196613, 655398, 0, 196613, 655399, 0, 196613, 655400, 0, 196613, 655406, 0, 196613, 655407, 0, 196613, 655408, 0, 196613, 655409, 0, 196613, 655410, 0, 196613, 655411, 0, 196613, 655412, 0, 196613, 655413, 0, 196613, 655414, 0, 196613, 655415, 0, 196613, 655416, 0, 196613, 655417, 0, 196613, 655418, 0, 196613, 655419, 0, 196613, 655420, 0, 196613, 655421, 0, 196613, 655422, 0, 196613, 655423, 0, 196613, 655424, 0, 196613, 655425, 0, 196613, 655426, 0, 196613, 655427, 0, 196613, 655428, 0, 196613, 655439, 0, 196613, 720896, 0, 196613, 720897, 0, 65538, 720898, 0, 65538, 720899, 0, 65538, 720900, 0, 65538, 720901, 0, 65538, 720902, 0, 65538, 720903, 0, 65538, 720904, 0, 65538, 720905, 0, 65538, 720906, 0, 65538, 720907, 0, 65538, 720908, 0, 65538, 720909, 0, 65538, 720910, 0, 65538, 720911, 0, 65538, 720912, 0, 65538, 720913, 0, 65538, 720914, 0, 65538, 720915, 0, 196613, 720916, 0, 196613, 720917, 0, 196613, 720918, 0, 196613, 720919, 0, 196613, 720920, 0, 196613, 720921, 0, 196613, 720959, 0, 0, 720961, 0, 196613, 720962, 0, 196613, 720963, 0, 196613, 720964, 0, 196613, 720965, 0, 196613, 720975, 0, 196613, 786432, 0, 196613, 786495, 0, 0, 786511, 0, 196613, 851968, 0, 196613, 852002, 0, 196613, 852031, 0, 0, 852047, 0, 196613, 917504, 0, 196613, 917583, 0, 196613, 983040, 0, 196613, 983119, 0, 196613, 1048576, 0, 196613, 1048655, 0, 196613, 1114112, 0, 196613, 1114167, 0, 196613, 1114168, 0, 196613, 1114169, 0, 196613, 1114170, 0, 196613, 1114171, 0, 196613, 1114191, 0, 196613, 1179648, 0, 196613, 1179701, 0, 196613, 1179702, 0, 196613, 1179703, 0, 196613, 1179707, 0, 196613, 1179708, 0, 196613, 1179709, 0, 196613, 1179727, 0, 196613, 1245184, 0, 196613, 1245236, 0, 196613, 1245237, 0, 196613, 1245245, 0, 196613, 1245246, 0, 196613, 1245247, 0, 196613, 1245263, 0, 196613, 1310720, 0, 196613, 1310771, 0, 196613, 1310772, 0, 196613, 1310783, 0, 196613, 1310784, 0, 196613, 1310799, 0, 196613, 1376256, 0, 196613, 1376257, 0, 196613, 1376258, 0, 196613, 1376259, 0, 196613, 1376260, 0, 196613, 1376261, 0, 196613, 1376262, 0, 196613, 1376263, 0, 196613, 1376264, 0, 196613, 1376265, 0, 196613, 1376266, 0, 196613, 1376267, 0, 196613, 1376268, 0, 196613, 1376269, 0, 196613, 1376270, 0, 196613, 1376271, 0, 196613, 1376272, 0, 196613, 1376273, 0, 196613, 1376274, 0, 196613, 1376275, 0, 196613, 1376276, 0, 196613, 1376277, 0, 196613, 1376278, 0, 196613, 1376279, 0, 196613, 1376280, 0, 196613, 1376281, 0, 196613, 1376282, 0, 196613, 1376283, 0, 196613, 1376284, 0, 196613, 1376285, 0, 196613, 1376286, 0, 196613, 1376287, 0, 196613, 1376288, 0, 196613, 1376289, 0, 196613, 1376290, 0, 196613, 1376291, 0, 196613, 1376292, 0, 196613, 1376293, 0, 196613, 1376294, 0, 196613, 1376295, 0, 196613, 1376296, 0, 196613, 1376297, 0, 196613, 1376298, 0, 196613, 1376299, 0, 196613, 1376300, 0, 196613, 1376301, 0, 196613, 1376302, 0, 196613, 1376303, 0, 196613, 1376304, 0, 196613, 1376305, 0, 196613, 1376306, 0, 196613, 1376307, 0, 196613, 1376308, 0, 196613, 1376309, 0, 196613, 1376310, 0, 196613, 1376311, 0, 196613, 1376312, 0, 196613, 1376313, 0, 196613, 1376314, 0, 196613, 1376315, 0, 196613, 1376316, 0, 196613, 1376317, 0, 196613, 1376318, 0, 196613, 1376319, 0, 196613, 1376320, 0, 196613, 1376321, 0, 196613, 1376322, 0, 196613, 1376323, 0, 196613, 1376324, 0, 196613, 1376325, 0, 196613, 1376326, 0, 196613, 1376327, 0, 196613, 1376328, 0, 196613, 1376329, 0, 196613, 1376330, 0, 196613, 1376331, 0, 196613, 1376332, 0, 196613, 1376333, 0, 196613, 1376334, 0, 196613, 1376335, 0, 196613, 1441792, 0, 196613, 1441793, 0, 196613, 1441794, 0, 196613, 1441795, 0, 196613, 1441796, 0, 196613, 1441797, 0, 196613, 1441798, 0, 196613, 1441799, 0, 196613, 1441800, 0, 196613, 1441801, 0, 196613, 1441802, 0, 196613, 1441803, 0, 196613, 1441804, 0, 196613, 1441805, 0, 196613, 1441806, 0, 196613, 1441807, 0, 196613, 1441808, 0, 196613, 1441809, 0, 196613, 1441810, 0, 196613, 1441811, 0, 196613, 1441812, 0, 196613, 1441813, 0, 196613, 1441814, 0, 196613, 1441815, 0, 196613, 1441816, 0, 196613, 1441817, 0, 196613, 1441818, 0, 196613, 1441819, 0, 196613, 1441820, 0, 196613, 1441821, 0, 196613, 1441822, 0, 196613, 1441823, 0, 196613, 1441824, 0, 196613, 1441825, 0, 196613, 1441826, 0, 196613, 1441827, 0, 196613, 1441828, 0, 196613, 1441829, 0, 196613, 1441830, 0, 196613, 1441831, 0, 196613, 1441832, 0, 196613, 1441833, 0, 196613, 1441834, 0, 196613, 1441835, 0, 196613, 1441836, 0, 196613, 1441837, 0, 196613, 1441838, 0, 196613, 1441839, 0, 196613, 1441840, 0, 196613, 1441841, 0, 196613, 1441842, 0, 196613, 1441843, 0, 196613, 1441844, 0, 196613, 1441845, 0, 196613, 1441846, 0, 196613, 1441847, 0, 196613, 1441848, 0, 196613, 1441849, 0, 196613, 1441850, 0, 196613, 1441851, 0, 196613, 1441852, 0, 196613, 1441853, 0, 196613, 1441854, 0, 196613, 1441855, 0, 196613, 1441856, 0, 196613, 1441857, 0, 196613, 1441858, 0, 196613, 1441859, 0, 196613, 1441860, 0, 196613, 1441861, 0, 196613, 1441862, 0, 196613, 1441863, 0, 196613, 1441864, 0, 196613, 1441865, 0, 196613, 1441866, 0, 196613, 1441867, 0, 196613, 1441868, 0, 196613, 1441869, 0, 196613, 1441870, 0, 196613, 1441871, 0, 196613 ) +tile_data = PoolIntArray( -65536, 0, 196613, 0, 0, 196613, 79, 0, 196613, 65536, 0, 196613, 65615, 0, 196613, 131072, 0, 196613, 131151, 0, 196613, 196608, 0, 196613, 196687, 0, 196613, 262144, 0, 196613, 262172, 0, 196613, 262173, 0, 196613, 262174, 0, 196613, 262175, 0, 196613, 262176, 0, 196613, 262177, 0, 196613, 262223, 0, 196613, 327680, 0, 196613, 327759, 0, 196613, 393216, 0, 196613, 393260, 0, 196613, 393261, 0, 196613, 393295, 0, 196613, 458752, 0, 196613, 458792, 0, 196613, 458793, 0, 196613, 458794, 0, 196613, 458795, 0, 196613, 458796, 0, 196613, 458797, 0, 196613, 458831, 0, 196613, 524288, 0, 196613, 524307, 0, 196613, 524308, 0, 196613, 524327, 0, 196613, 524328, 0, 196613, 524329, 0, 196613, 524330, 0, 196613, 524334, 0, 196613, 524367, 0, 196613, 589824, 0, 196613, 589843, 0, 196613, 589844, 0, 196613, 589863, 0, 196613, 589864, 0, 196613, 589870, 0, 196613, 589903, 0, 196613, 655360, 0, 196613, 655361, 0, 2, 655362, 0, 2, 655363, 0, 2, 655364, 0, 2, 655365, 0, 2, 655366, 0, 2, 655367, 0, 2, 655368, 0, 2, 655369, 0, 2, 655370, 0, 2, 655371, 0, 2, 655372, 0, 2, 655373, 0, 2, 655374, 0, 2, 655375, 0, 2, 655376, 0, 2, 655377, 0, 2, 655378, 0, 2, 655379, 0, 196613, 655380, 0, 196613, 655381, 0, 196613, 655382, 0, 196613, 655383, 0, 196613, 655384, 0, 196613, 655385, 0, 196613, 655386, 0, 196613, 655387, 0, 196613, 655388, 0, 196613, 655389, 0, 196613, 655390, 0, 196613, 655391, 0, 196613, 655392, 0, 196613, 655393, 0, 196613, 655394, 0, 196613, 655395, 0, 196613, 655396, 0, 196613, 655397, 0, 196613, 655398, 0, 196613, 655399, 0, 196613, 655400, 0, 196613, 655406, 0, 196613, 655407, 0, 196613, 655408, 0, 196613, 655409, 0, 196613, 655410, 0, 196613, 655411, 0, 196613, 655412, 0, 196613, 655413, 0, 196613, 655414, 0, 196613, 655415, 0, 196613, 655416, 0, 196613, 655417, 0, 196613, 655418, 0, 196613, 655419, 0, 196613, 655420, 0, 196613, 655421, 0, 196613, 655422, 0, 196613, 655423, 0, 196613, 655424, 0, 196613, 655425, 0, 196613, 655426, 0, 196613, 655427, 0, 196613, 655428, 0, 196613, 655439, 0, 196613, 720896, 0, 196613, 720897, 0, 65538, 720898, 0, 65538, 720899, 0, 65538, 720900, 0, 65538, 720901, 0, 65538, 720902, 0, 65538, 720903, 0, 65538, 720904, 0, 65538, 720905, 0, 65538, 720906, 0, 65538, 720907, 0, 65538, 720908, 0, 65538, 720909, 0, 65538, 720910, 0, 65538, 720911, 0, 65538, 720912, 0, 65538, 720913, 0, 65538, 720914, 0, 65538, 720915, 0, 196613, 720916, 0, 196613, 720917, 0, 196613, 720918, 0, 196613, 720919, 0, 196613, 720920, 0, 196613, 720921, 0, 196613, 720959, 0, 0, 720961, 0, 196613, 720962, 0, 196613, 720963, 0, 196613, 720964, 0, 196613, 720965, 0, 196613, 720975, 0, 196613, 786432, 0, 196613, 786495, 0, 0, 786511, 0, 196613, 851968, 0, 196613, 852002, 0, 196613, 852031, 0, 0, 852047, 0, 196613, 917504, 0, 196613, 917583, 0, 196613, 983040, 0, 196613, 983119, 0, 196613, 1048576, 0, 196613, 1048655, 0, 196613, 1114112, 0, 196613, 1114167, 0, 196613, 1114168, 0, 196613, 1114169, 0, 196613, 1114170, 0, 196613, 1114171, 0, 196613, 1114191, 0, 196613, 1179648, 0, 196613, 1179701, 0, 196613, 1179702, 0, 196613, 1179703, 0, 196613, 1179707, 0, 196613, 1179708, 0, 196613, 1179709, 0, 196613, 1179727, 0, 196613, 1245184, 0, 196613, 1245236, 0, 196613, 1245237, 0, 196613, 1245245, 0, 196613, 1245246, 0, 196613, 1245247, 0, 196613, 1245263, 0, 196613, 1310720, 0, 196613, 1310771, 0, 196613, 1310772, 0, 196613, 1310783, 0, 196613, 1310784, 0, 196613, 1310799, 0, 196613, 1376256, 0, 196613, 1376257, 0, 196613, 1376258, 0, 196613, 1376259, 0, 196613, 1376260, 0, 196613, 1376261, 0, 196613, 1376262, 0, 196613, 1376263, 0, 196613, 1376264, 0, 196613, 1376265, 0, 196613, 1376266, 0, 196613, 1376267, 0, 196613, 1376268, 0, 196613, 1376269, 0, 196613, 1376270, 0, 196613, 1376271, 0, 196613, 1376272, 0, 196613, 1376273, 0, 196613, 1376274, 0, 196613, 1376275, 0, 196613, 1376276, 0, 196613, 1376277, 0, 196613, 1376278, 0, 196613, 1376279, 0, 196613, 1376280, 0, 196613, 1376281, 0, 196613, 1376282, 0, 196613, 1376283, 0, 196613, 1376284, 0, 196613, 1376285, 0, 196613, 1376286, 0, 196613, 1376287, 0, 196613, 1376288, 0, 196613, 1376289, 0, 196613, 1376290, 0, 196613, 1376291, 0, 196613, 1376292, 0, 196613, 1376293, 0, 196613, 1376294, 0, 196613, 1376295, 0, 196613, 1376296, 0, 196613, 1376297, 0, 196613, 1376298, 0, 196613, 1376299, 0, 196613, 1376300, 0, 196613, 1376301, 0, 196613, 1376302, 0, 196613, 1376303, 0, 196613, 1376304, 0, 196613, 1376305, 0, 196613, 1376306, 0, 196613, 1376307, 0, 196613, 1376308, 0, 196613, 1376309, 0, 196613, 1376310, 0, 196613, 1376311, 0, 196613, 1376312, 0, 196613, 1376313, 0, 196613, 1376314, 0, 196613, 1376315, 0, 196613, 1376316, 0, 196613, 1376317, 0, 196613, 1376318, 0, 196613, 1376319, 0, 196613, 1376320, 0, 196613, 1376321, 0, 196613, 1376322, 0, 196613, 1376323, 0, 196613, 1376324, 0, 196613, 1376325, 0, 196613, 1376326, 0, 196613, 1376327, 0, 196613, 1376328, 0, 196613, 1376329, 0, 196613, 1376330, 0, 196613, 1376331, 0, 196613, 1376332, 0, 196613, 1376333, 0, 196613, 1376334, 0, 196613, 1376335, 0, 196613, 1441792, 0, 196613, 1441793, 0, 196613, 1441794, 0, 196613, 1441795, 0, 196613, 1441796, 0, 196613, 1441797, 0, 196613, 1441798, 0, 196613, 1441799, 0, 196613, 1441800, 0, 196613, 1441801, 0, 196613, 1441802, 0, 196613, 1441803, 0, 196613, 1441804, 0, 196613, 1441805, 0, 196613, 1441806, 0, 196613, 1441807, 0, 196613, 1441808, 0, 196613, 1441809, 0, 196613, 1441810, 0, 196613, 1441811, 0, 196613, 1441812, 0, 196613, 1441813, 0, 196613, 1441814, 0, 196613, 1441815, 0, 196613, 1441816, 0, 196613, 1441817, 0, 196613, 1441818, 0, 196613, 1441819, 0, 196613, 1441820, 0, 196613, 1441821, 0, 196613, 1441822, 0, 196613, 1441823, 0, 196613, 1441824, 0, 196613, 1441825, 0, 196613, 1441826, 0, 196613, 1441827, 0, 196613, 1441828, 0, 196613, 1441829, 0, 196613, 1441830, 0, 196613, 1441831, 0, 196613, 1441832, 0, 196613, 1441833, 0, 196613, 1441834, 0, 196613, 1441835, 0, 196613, 1441836, 0, 196613, 1441837, 0, 196613, 1441838, 0, 196613, 1441839, 0, 196613, 1441840, 0, 196613, 1441841, 0, 196613, 1441842, 0, 196613, 1441843, 0, 196613, 1441844, 0, 196613, 1441845, 0, 196613, 1441846, 0, 196613, 1441847, 0, 196613, 1441848, 0, 196613, 1441849, 0, 196613, 1441850, 0, 196613, 1441851, 0, 196613, 1441852, 0, 196613, 1441853, 0, 196613, 1441854, 0, 196613, 1441855, 0, 196613, 1441856, 0, 196613, 1441857, 0, 196613, 1441858, 0, 196613, 1441859, 0, 196613, 1441860, 0, 196613, 1441861, 0, 196613, 1441862, 0, 196613, 1441863, 0, 196613, 1441864, 0, 196613, 1441865, 0, 196613, 1441866, 0, 196613, 1441867, 0, 196613, 1441868, 0, 196613, 1441869, 0, 196613, 1441870, 0, 196613, 1441871, 0, 196613 ) __meta__ = { "_edit_lock_": true } [node name="Player" parent="." instance=ExtResource( 2 )] -position = Vector2( 136, 35 ) +position = Vector2( 642, 62 ) [node name="CameraControl" type="Position2D" parent="."] process_priority = 1 @@ -210,6 +210,9 @@ stream = ExtResource( 4 ) [node name="EnemyC" parent="." instance=ExtResource( 7 )] position = Vector2( 394, 47 ) +[node name="EnemyC2" parent="." instance=ExtResource( 7 )] +position = Vector2( 492, 27 ) + [node name="ActorTemplate" parent="." instance=ExtResource( 6 )] position = Vector2( 262, 44 ) actor_type = "NPC" diff --git a/src/actor.gd b/src/actor.gd index 65ac884..dcdbe8a 100644 --- a/src/actor.gd +++ b/src/actor.gd @@ -2,11 +2,12 @@ class_name Actor extends KinematicBody2D var velocity = Vector2(0,0) -var direction = Vector2(-1,0) +#var direction = Vector2(-1,0) export(String, "Player", "Enemy", "NPC") var actor_type -export var sprite_facing_right: bool = true +#export var sprite_facing_right: bool = true export(Array, Resource) var SoundEffects +export var debug_actor: bool = false onready var movement_animations: AnimatedSprite = $AnimatedSprite @@ -44,6 +45,7 @@ func _unhandled_input(event: InputEvent) -> void: movement_state_machine.process_input(event) func _physics_process(delta: float) -> void: + movement_component.process_physics(delta) movement_state_machine.process_physics(delta) func _process(delta: float) -> void: @@ -67,4 +69,4 @@ func play_sound_frame(animation: String, frame: int ): if sound_effects_dict.has(sound_index): sound_effect_player.stream = sound_effects_dict[sound_index] sound_effect_player.play() - print("Playing SE: ", sound_index) + print(self.name, " Playing SE: ", sound_index) diff --git a/src/enemyC/EnemyC.tscn b/src/enemyC/EnemyC.tscn index 8295ae4..ec45f5d 100644 --- a/src/enemyC/EnemyC.tscn +++ b/src/enemyC/EnemyC.tscn @@ -117,7 +117,7 @@ actor_type = "Enemy" position = Vector2( 11, -7 ) frames = SubResource( 20 ) animation = "idle" -frame = 0 +frame = 1 __meta__ = { "_aseprite_wizard_config_": { "layer": "", @@ -156,10 +156,18 @@ animation_sequence = [ "attack" ] [node name="move" parent="movement_state_machine" index="3"] animation_sequence = [ "walk" ] -[node name="PlayerDetection" type="RayCast2D" parent="." index="6"] +[node name="EdgeDetection" type="RayCast2D" parent="." index="6"] +modulate = Color( 0.054902, 1, 0, 1 ) +show_behind_parent = true +position = Vector2( 15, 3 ) +enabled = true +cast_to = Vector2( 0, 17 ) +collide_with_areas = true + +[node name="PlayerDetection" type="RayCast2D" parent="." index="7"] cast_to = Vector2( 21, 0 ) -[node name="Hitbox_Component" type="Area2D" parent="." index="7"] +[node name="Hitbox_Component" type="Area2D" parent="." index="8"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component" index="0"] modulate = Color( 1, 0.596078, 0.121569, 1 ) diff --git a/src/enemyC/enemyC_movement_component.gd b/src/enemyC/enemyC_movement_component.gd index 567ac06..26325ae 100644 --- a/src/enemyC/enemyC_movement_component.gd +++ b/src/enemyC/enemyC_movement_component.gd @@ -1,12 +1,20 @@ extends MovementComponent onready var idle_timeout = $IdleTimeout +onready var edge_detector:RayCast2D = $"../EdgeDetection" var flip_flop = false +func process_physics(delta): + if current_movement_state == "move" and edge_detector.is_colliding() == false: + #print(owner.name, "uh oh gonna fall!") + stop() + return + func process(delta): if current_movement_state == "idle" and idle_timeout.time_left == 0: - print ("Time to move!") + if debug_component: + print ("Time to move!") if flip_flop: flip_flop = false go_right() @@ -16,7 +24,8 @@ func process(delta): go_left() idle_timeout.start() if current_movement_state == "move" and idle_timeout.time_left == 0: - print("Time to stop.") + if debug_component: + print("Time to stop.") idle_timeout.start() stop() return diff --git a/src/movement_component.gd b/src/movement_component.gd index 566ce0f..87fe755 100644 --- a/src/movement_component.gd +++ b/src/movement_component.gd @@ -1,6 +1,8 @@ class_name MovementComponent extends Node +export var debug_component: bool = false + onready var desired_movement_vector: Vector2 = Vector2(0,0) var current_movement_state:String @@ -12,6 +14,9 @@ const DOWN = 1.0 const LEFT = -1.0 const RIGHT = 1.0 +func process_physics(delta): + pass + func process(delta): pass diff --git a/src/playerC/Player-KinematicBody2D.gd b/src/playerC/Player-KinematicBody2D.gd index 51f2211..1b03a9e 100644 --- a/src/playerC/Player-KinematicBody2D.gd +++ b/src/playerC/Player-KinematicBody2D.gd @@ -28,7 +28,7 @@ func set_hurtbox(enabled: bool): func shoot_projectile(): var is_shooting = false - is_shooting = gun.shoot(direction.x) + is_shooting = gun.shoot(movement_component.get_movement_direction()) #func play_sound(): # sound_effects.stream = "res://assets/Sounds/crappy pew.wav" diff --git a/src/playerC/states/fall.gd b/src/playerC/states/fall.gd index 4e62111..2f4df06 100644 --- a/src/playerC/states/fall.gd +++ b/src/playerC/states/fall.gd @@ -24,12 +24,8 @@ func process_physics(delta: float) -> State: # if parent.velocity.x != 0.0: # parent.direction.x = parent.velocity.x - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - - parent.transform.x.x = parent.direction.x + if move_component.get_movement_direction() != 0.0: + parent.transform.x.x = move_component.get_movement_direction() # if move_component.flipped_sprite == false: # #parent.scale.x = parent.direction.x * -1 # parent.transform.x.x = parent.direction.x * -1 # -1 diff --git a/src/playerC/states/idle.gd b/src/playerC/states/idle.gd index 7c61a59..8420c66 100644 --- a/src/playerC/states/idle.gd +++ b/src/playerC/states/idle.gd @@ -37,10 +37,11 @@ func process_input(_event: InputEvent) -> State: return null func process_physics(delta: float) -> State: - debugTimeTracker += delta - if debugTimeTracker > 2: - debugTimeTracker = 0.0 - print("DEBUG TRANSFORM:", parent.transform) + if debug_state: + debugTimeTracker += delta + if debugTimeTracker > 2: + debugTimeTracker = 0.0 + print(owner.name, " DEBUG TRANSFORM:", parent.transform) parent.velocity.y += gravity * delta #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) diff --git a/src/playerC/states/jump.gd b/src/playerC/states/jump.gd index acff475..d8b4417 100644 --- a/src/playerC/states/jump.gd +++ b/src/playerC/states/jump.gd @@ -29,11 +29,9 @@ func process_physics(delta: float) -> State: parent.velocity.x = move_component.desired_movement_vector.x * move_speed parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - parent.transform.x.x = parent.direction.x + if move_component.get_movement_direction() != 0.0: + parent.transform.x.x = move_component.get_movement_direction() + # if move_component.flipped_sprite == false: # #parent.scale.x = parent.direction.x * -1 # parent.transform.x.x = parent.direction.x * -1 # -1 diff --git a/src/playerC/states/move.gd b/src/playerC/states/move.gd index 8e8fd67..df649de 100644 --- a/src/playerC/states/move.gd +++ b/src/playerC/states/move.gd @@ -24,10 +24,11 @@ func process_input(_event: InputEvent) -> State: func process_physics(delta: float) -> State: # if move_component.wants_jump() and parent.is_on_floor(): # return jump_state - debugTimeTracker += delta - if debugTimeTracker > 2: - debugTimeTracker = 0.0 - print("DEBUG TRANSFORM:", parent.transform) + if debug_state: + debugTimeTracker += delta + if debugTimeTracker > 2: + debugTimeTracker = 0.0 + print("DEBUG TRANSFORM:", parent.transform) parent.velocity.y += gravity * delta @@ -45,13 +46,10 @@ func process_physics(delta: float) -> State: if parent.velocity.x == 0.0: return idle_state - else: - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - - parent.transform.x.x = parent.direction.x + + if move_component.get_movement_direction() != 0.0: + parent.transform.x.x = move_component.get_movement_direction() + # if move_component.flipped_sprite == true: # animations.flip_h = parent.direction.x > 0 # else: diff --git a/src/templates/Actor/states/fall.gd b/src/templates/Actor/states/fall.gd index a9b707a..650424e 100644 --- a/src/templates/Actor/states/fall.gd +++ b/src/templates/Actor/states/fall.gd @@ -10,12 +10,8 @@ func process_physics(delta: float) -> State: parent.velocity.x = move_component.desired_movement_vector.x * move_speed parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - - parent.transform.x.x = parent.direction.x + if move_component.get_movement_direction() != 0.0: + parent.transform.x.x = move_component.get_movement_direction() if parent.is_on_floor(): return idle_state diff --git a/src/templates/Actor/states/idle.gd b/src/templates/Actor/states/idle.gd index 88796cf..fac2305 100644 --- a/src/templates/Actor/states/idle.gd +++ b/src/templates/Actor/states/idle.gd @@ -10,7 +10,8 @@ func enter() -> void: .enter() # parent.set_hurtbox(true) parent.velocity.x = 0 - print("Move Component: ", move_component.desired_movement_vector.x) + if debug_state: + print(owner.name, " Move Component: ", move_component.desired_movement_vector.x) func process_physics(delta: float) -> State: @@ -23,7 +24,6 @@ func process_physics(delta: float) -> State: if parent.velocity.x != 0.0: return move_state - if !parent.is_on_floor(): return fall_state diff --git a/src/templates/Actor/states/move.gd b/src/templates/Actor/states/move.gd index ecc6a77..273ff38 100644 --- a/src/templates/Actor/states/move.gd +++ b/src/templates/Actor/states/move.gd @@ -9,16 +9,12 @@ onready var idle_state: State = get_node(idle_node) func process_physics(delta: float) -> State: move_actor_as_desired(delta) - + if parent.velocity.x == 0.0: return idle_state - else: - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - - parent.transform.x.x = parent.direction.x + + #Flip the character before tha actual move maybe. + parent.transform.x.x = move_component.get_movement_direction() if !parent.is_on_floor(): return fall_state