summaryrefslogtreecommitdiff
path: root/src/object/rotatingTrapdoor.c
blob: f8e05f490d4cff671e540f529e0d0cccd2e7d1b6 (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
/**
 * @file rotatingTrapdoor.c
 * @ingroup Objects
 *
 * @brief Rotating Trapdoor object
 */
#include "asm.h"
#include "entity.h"
#include "functions.h"
#include "room.h"
#include "sound.h"

void RotatingTrapdoor_Init(Entity*);
void RotatingTrapdoor_Action1(Entity*);
void sub_0808E354(Entity*, u32);

void RotatingTrapdoor(Entity* this) {
    static void (*const RotatingTrapdoor_Actions[])(Entity*) = {
        RotatingTrapdoor_Init,
        RotatingTrapdoor_Action1,
    };

    RotatingTrapdoor_Actions[this->action]((Entity*)this);
}

void RotatingTrapdoor_Init(Entity* this) {
    int x;
    int y;

    this->collisionLayer = 2;
    this->action = 1;
    x = 0;
    y = 0;
    switch (GetTileTypeByEntity(this)) {
        case 0x343:
            x = 0x10;
        case 0x344:
            y = 0x10;
            break;
        case 0x345:
            x = 0x10;
            break;
        case 0x346:
            break;
        default:
            DeleteThisEntity();
            break;
    }

    this->x.HALF.HI = (this->x.HALF.HI + x) & 0xfff0;
    this->y.HALF.HI = (this->y.HALF.HI + y) & 0xfff0;
    InitializeAnimation(this, 0);
    sub_0808E354(this, 0x347);
    RotatingTrapdoor_Action1(this);
}

void RotatingTrapdoor_Action1(Entity* this) {
    GetNextFrame(this);
    if (this->frame & ANIM_DONE) {
        sub_0808E354(this, 0x343);
        DeleteThisEntity();
    } else {
        if (this->frame & 1) {
            EnqueueSFX(SFX_18B);
        }
    }
}

void sub_0808E354(Entity* this, u32 param_2) {
    u16 uVar1 = param_2;
    sub_0807B7D8(uVar1, COORD_TO_TILE_OFFSET(this, 0x10, 0x10), 2);
    sub_0807B7D8(uVar1 + 1, COORD_TO_TILE_OFFSET(this, 0, 0x10), 2);
    sub_0807B7D8(uVar1 + 2, COORD_TO_TILE_OFFSET(this, 0x10, 0), 2);
    sub_0807B7D8(uVar1 + 3, COORD_TO_TILE_OFFSET(this, 0, 0), 2);
}