aboutsummaryrefslogtreecommitdiff
path: root/src/et_ninja.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-11-05 11:22:55 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-11-05 11:31:28 +0000
commit2fbdf974338bde8576efdae40a819a76b2391033 (patch)
tree64d41a37470143f142344f9a439d96de3e7918c2 /src/et_ninja.c
downloadkitsunes-curse-2fbdf974338bde8576efdae40a819a76b2391033.tar.gz
kitsunes-curse-2fbdf974338bde8576efdae40a819a76b2391033.zip
Initial import of the open source release
Diffstat (limited to 'src/et_ninja.c')
-rw-r--r--src/et_ninja.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/et_ninja.c b/src/et_ninja.c
new file mode 100644
index 0000000..e1e8bb1
--- /dev/null
+++ b/src/et_ninja.c
@@ -0,0 +1,127 @@
+/*
+ Kitsune's Curse
+ Copyright (C) 2020-2023 Juan J. Martinez <jjm@usebox.net>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "splib.h"
+#include "main.h"
+
+#include "maps.h"
+
+// generated
+#include "ninja.h"
+
+#include "entities.h"
+#include "et_ninja.h"
+#include "et_player.h"
+#include "et_effect.h"
+
+void draw_ninja()
+{
+ if (*it_extra)
+ return;
+
+ put_sprite4(ninja[player_frames[*it_frame]], *it_x, *it_y, 3, *it_param);
+ erase_sprite(*it_ox, *it_oy, 3);
+}
+
+uint8_t try_magic()
+{
+ uint8_t target = *it_x;
+
+ if (*it_x == TW * TMW - 8 - 2
+ || *it_x == 2)
+ return 0;
+
+ for (it_k = 0; it_k < 6; it_k++)
+ {
+ if (*it_param)
+ target += 8;
+ else
+ target -= 8;
+
+ if (is_map_blocked(target, *it_y + 8)
+ || is_map_deadly(target, *it_y + 24)
+ || target < 4
+ || target > TW * TMW - 8 - 4)
+ break;
+
+ if (is_map_blocked(target, *it_y + 24))
+ {
+ erase_sprite(*it_ox, *it_oy, 3);
+ new_explo_et();
+ *it_x = (target / TW) * TW;
+ *it_extra = COOL_DOWN + 2;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+void update_ninja()
+{
+ if ((*it_delay)++ == 2)
+ {
+ *it_delay = 0;
+ if (++(*it_frame) > WALK_CYCLE)
+ *it_frame = WALK;
+ }
+
+ if (*it_extra)
+ {
+ --(*it_extra);
+ if (*it_extra == 0)
+ new_explo_et();
+ return;
+ }
+
+ if (*it_param)
+ {
+ if (is_map_blocked(*it_x + 8, *it_y + 8) || *it_x == TW * TMW - 8 - 2
+ || !is_map_blocked(*it_x + 8, *it_y + 24)
+ || is_map_deadly(*it_x + 8, *it_y + 24))
+ {
+ if (try_magic())
+ return;
+ goto ninja_change_dir;
+ }
+ else
+ *it_x += 1;
+ }
+ else
+ {
+ if (is_map_blocked(*it_x - 1, *it_y + 8) || *it_x == 2
+ || !is_map_blocked(*it_x - 1, *it_y + 24)
+ || is_map_deadly(*it_x - 1, *it_y + 24))
+ {
+ if (try_magic())
+ return;
+ goto ninja_change_dir;
+ }
+ else
+ *it_x -= 1;
+ }
+
+ if (*it_extra == 0 && check_for_player(24))
+ {
+ player_hit(1);
+
+ninja_change_dir:
+ *it_param ^= 128;
+ *it_delay = 0;
+ *it_frame = WALK;
+ }
+}