summaryrefslogtreecommitdiff
path: root/src/playerItem/playerItemLantern.c
blob: 0466446470cb3456a62d704b31d89e0ce971dd4d (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
/**
 * @file playerItemLantern.c
 * @ingroup Items
 *
 * @brief Lantern Player Item
 */
#include "entity.h"
#include "functions.h"
#include "item.h"
#include "object.h"
#include "player.h"

void PlayerItemLantern_Init(Entity* this);
void PlayerItemLantern_Action1(Entity* this);

void PlayerItemLantern(Entity* this) {
    static void (*const PlayerItemLantern_Actions[])(Entity*) = {
        PlayerItemLantern_Init,
        PlayerItemLantern_Action1,
    };
    PlayerItemLantern_Actions[this->action](this);
    this->contactFlags = 0;
}

void PlayerItemLantern_Init(Entity* this) {
    this->flags |= (ENT_PERSIST | ENT_COLLIDE);
    this->action = 1;
    this->timer = 4;
    this->frameIndex = -1;
    this->updatePriority = 6;
    this->collisionFlags = 7;
    this->flags2 = -0x80;
    this->animationState = gPlayerEntity.base.animationState & 0xe;
    if (AllocMutableHitbox(this) == NULL) {
        DeleteThisEntity();
    }
    sub_0801766C(this);
    LoadSwapGFX(this, 1, 3);
    PlayerItemLantern_Action1(this);
}

void PlayerItemLantern_Action1(Entity* this) {
    Entity* object;
    static const s8 offsets[] = { 6, -6, 7, -3, -5, 2, -7, -3 };
    this->animationState = gPlayerEntity.base.animationState & 0xe;
    this->hitbox->offset_x = offsets[this->animationState];
    this->hitbox->offset_y = offsets[this->animationState + 1];
    this->hitbox->width = 4;
    this->hitbox->height = 4;
    if (!((gPlayerEntity.base.frameIndex < 0x37) && ((u32)gPlayerEntity.base.spriteIndex == 6))) {
        this->frameIndex = 0xff;
        this->flags &= ~ENT_COLLIDE;
    } else {
        this->flags |= ENT_COLLIDE;
        this->spriteSettings.flipX = gPlayerEntity.base.spriteSettings.flipX;
        this->spriteSettings.flipY = gPlayerEntity.base.spriteSettings.flipY;
        if (gPlayerEntity.base.frameIndex != this->frameIndex) {
            this->frameIndex = gPlayerEntity.base.frameIndex;
            sub_080042D0(this, this->frameIndex, this->spriteIndex);
        }
        this->frame = gPlayerEntity.base.frame;
        this->frameSpriteSettings = gPlayerEntity.base.frameSpriteSettings;
    }
    if (IsItemEquipped(ITEM_LANTERN_ON) < EQUIP_SLOT_NONE) {
        if (((this->frameIndex != 0xff) && (gPlayerEntity.base.spriteSettings.draw != 0)) && (this->timer-- == 0)) {
            this->timer = 4;
            object = CreateObject(LAMP_PARTICLE, 0, 0x10);
            if (object != NULL) {
                PositionRelative(this, object, 0, Q_16_16(2.0));
                object->spritePriority.b0 = this->spritePriority.b0;
                object->spriteOffsetX = offsets[this->animationState];
                object->spriteOffsetY = offsets[this->animationState + 1];
            }
        }
        sub_08078E84(this, &gPlayerEntity.base);
    } else {
        DeleteThisEntity();
    }
}