summaryrefslogtreecommitdiff
path: root/src/object/lightDoor.c
blob: ebce1433139a06c09d959c816bc6a5f140351be2 (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
/**
 * @file lightDoor.c
 * @ingroup Objects
 *
 * @brief Light Door object
 */
#include "functions.h"
#include "object.h"
#include "screen.h"
#include "tiles.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[30];
    /*0x86*/ u16 flag;
} LightDoorEntity;

void LightDoor_Init(LightDoorEntity*);
void LightDoor_Action1(LightDoorEntity*);
void LightDoor_Action2(LightDoorEntity*);
void LightDoor_Action3(LightDoorEntity*);
void LightDoor_Action4(LightDoorEntity*);
void sub_080850FC(LightDoorEntity*);

void LightDoor(LightDoorEntity* this) {
    static void (*const LightDoor_Actions[])(LightDoorEntity*) = {
        LightDoor_Init, LightDoor_Action1, LightDoor_Action2, LightDoor_Action3, LightDoor_Action4,
    };
    LightDoor_Actions[super->action](this);
}

void LightDoor_Init(LightDoorEntity* this) {
    if (super->type == 0) {
        if (CheckFlags(this->flag)) {
            DeleteThisEntity();
        }
        super->action = 1;
        super->spritePriority.b0 = 7;
        sub_080850FC(this);
    } else {
        super->action = 2;
        super->timer = 240;
        super->speed = 0x80;
        super->direction = 0x18;
    }
    super->frameIndex = 0;
}

void LightDoor_Action1(LightDoorEntity* this) {
}

void LightDoor_Action2(LightDoorEntity* this) {
    u32 tmp;
    u32 tmp2;
    if (--super->timer == 0) {
        super->action = 3;
        super->timer = 30;
        super->spriteOffsetY = 4;
        gScreen.lcd.displayControl |= 0x2000;
        gScreen.controls.windowInsideControl = 0x1f;
        gScreen.controls.windowOutsideControl = 0xf;
        tmp2 = super->x.HALF.HI;
        tmp = gRoomControls.scroll_x;
        tmp2 = tmp2 - tmp;
        gScreen.controls.window0HorizontalDimensions = (((tmp2 - 0x18) & 0xff) << 8) | ((tmp2 + 0x18) & 0xff);
        tmp2 = super->y.HALF.HI;
        tmp = gRoomControls.scroll_y;
        tmp2 = tmp2 - tmp;
        gScreen.controls.window0VerticalDimensions = (((tmp2 - 0x18) & 0xff) << 8) | ((tmp2 + 0x18) & 0xff);
    }
}

void LightDoor_Action3(LightDoorEntity* this) {
    if (--super->timer == 0) {
        super->action = 4;
        super->timer = 96;
    }
}

void LightDoor_Action4(LightDoorEntity* this) {
    LinearMoveUpdate(super);
    if (--super->timer == 0) {
        gScreen.lcd.displayControl &= 0xdfff;
        DeleteEntity(super);
    }
}

void sub_080850FC(LightDoorEntity* this) {
    u32 tilePos = COORD_TO_TILE(super);
    u32 layer = super->collisionLayer;
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(-1, -1), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(0, -1), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(1, -1), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(-1, 0), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(0, 0), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(1, 0), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(-1, 1), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(0, 1), layer);
    SetTile(SPECIAL_TILE_61, tilePos + TILE_POS(1, 1), layer);
}