summaryrefslogtreecommitdiff
path: root/src/object/object1F.c
blob: bbe7e1669447204e08c842b14b5d74436c4e46f4 (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
/**
 * @file object1F.c
 * @ingroup Objects
 *
 * @brief Object1F object
 */
#include "object.h"
#include "asm.h"
#include "effects.h"
#include "physics.h"
#include "player.h"
#include "tiles.h"

typedef struct {
    Entity base;
    u8 filler[0x4];
    u32 unk6c;
} Object1FEntity;

void Object1F_Init(Object1FEntity*);
void Object1F_Action1(Object1FEntity*);
void Object1F_Action2(Object1FEntity*);

void Object1F(Entity* this) {
    static void (*const Object1F_Actions[])(Object1FEntity*) = {
        Object1F_Init,
        Object1F_Action1,
        Object1F_Action2,
    };

    Object1F_Actions[this->action]((Object1FEntity*)this);
}

typedef struct {
    u8 animationState;
    u8 unk1;
    u8 unk2;
    u8 spriteVramOffset;
} gUnk_08120A18_struct;

void Object1F_Init(Object1FEntity* this) {
    static const gUnk_08120A18_struct gUnk_08120A18[] = {
        { 0x0, 0x2, 0xA, 0xE8 },
        { 0x0, 0x5, 0x20, 0xE0 },
    };
    static const s8 gUnk_08120A20[] = { 0, -18, 16, 0, 0, 12, -16, 0 };

    u32 temp;
    super->action = 1;
    super->zVelocity = Q_16_16(2.75);
    super->direction = super->animationState << 2 ^ 0x10;
    if (super->animationState == 0) {
        super->spritePriority.b0--;
    }
    super->x.HALF.HI = gUnk_08120A20[super->animationState] + super->x.HALF.HI;
    super->y.HALF.HI = gUnk_08120A20[super->animationState + 1] + super->y.HALF.HI;

    super->spriteVramOffset = gUnk_08120A18[super->subtimer].spriteVramOffset;
    temp = gUnk_08120A18[super->subtimer].unk1;
    super->palette.b.b0 = temp;
    this->unk6c = gUnk_08120A18[super->subtimer].unk2;
    super->collisionLayer = gPlayerEntity.base.collisionLayer;
    super->speed = 0x100;
    InitializeAnimation(super, gUnk_08120A18[super->subtimer].animationState);
}

void Object1F_Action1(Object1FEntity* this) {
    u32 uVar1;

    if (this->unk6c) {
        this->unk6c--;
        uVar1 = gPlayerState.moleMittsState;
    } else {
        ProcessMovement2(super);
        uVar1 = GravityUpdate(super, Q_8_8(40.0));
    }

    if (uVar1 == 0) {
        super->action = 2;
    }
}

void Object1F_Action2(Object1FEntity* this) {
    u8 collisionData = GetCollisionDataAtEntity(super);
    switch (collisionData) {
        case COLLISION_DATA_33:
            CreateFx(super, FX_FALL_DOWN, 0);
            break;
        case COLLISION_DATA_37:
            CreateFx(super, FX_LAVA_SPLASH, 0);
            break;
        case COLLISION_DATA_36:
        case COLLISION_DATA_48:
            CreateFx(super, FX_WATER_SPLASH, 0);
            break;
        default:
            if (super->type2 != 0) {
                if (super->type2 == 15) {
                    CreateFx(super, super->timer, 0x80);
                } else {
                    CreateObjectWithParent(super, super->type2, super->timer, 0);
                }
            }
    }
    DeleteThisEntity();
}