aboutsummaryrefslogtreecommitdiff
path: root/src/et_ninja.c
blob: e1e8bb10c6421e1bbae6ea7dd6d0be30d406e5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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;
    }
}