summaryrefslogtreecommitdiff
path: root/src/object/backgroundCloud.c
blob: 53d29d7575e314fe6d1144e380214ee7bca7b1e5 (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 backgroundCloud.c
 * @ingroup Objects
 *
 * @brief BackgroundCloud object
 */
#include "object.h"
#include "asm.h"
#include "room.h"
#include "physics.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unused1[16];
    /*0x78*/ s16 unk_78;
    /*0x7a*/ s16 unk_7a;
} BackgroundCloudEntity;

void BackgroundCloud_Init(BackgroundCloudEntity* this);
void BackgroundCloud_Action1(BackgroundCloudEntity* this);
void BackgroundCloud_Action2(BackgroundCloudEntity* this);

void BackgroundCloud(BackgroundCloudEntity* this) {
    static void (*const BackgroundCloud_Actions[])(BackgroundCloudEntity*) = {
        BackgroundCloud_Init,
        BackgroundCloud_Action1,
        BackgroundCloud_Action2,
    };
    BackgroundCloud_Actions[super->action](this);
}

void BackgroundCloud_Init(BackgroundCloudEntity* this) {
    static const u8 gUnk_08121EB0[] = { 0x30, 0x28, 0x20 };
    super->action = 1;
    super->spriteSettings.draw = 1;
    super->spriteOrientation.flipY = 3;
    super->spriteRendering.b3 = 3;
    super->spritePriority.b0 = super->type;
    super->frameIndex = super->type;
    super->direction = 8;
    super->speed = gUnk_08121EB0[super->type];
    this->unk_78 = gRoomControls.origin_x - 0x60;
    this->unk_7a = gRoomControls.origin_x + gRoomControls.width + 0x60;
    super->animationState = 0;
    super->x.HALF.HI += (Random() & 0xf) << 4;
    super->timer = 0;
    super->subAction = 0;
}

void BackgroundCloud_Action1(BackgroundCloudEntity* this) {
    LinearMoveUpdate(super);

    if (super->x.HALF.HI < this->unk_78 || super->x.HALF.HI > this->unk_7a)
        super->action = 2;
}

void BackgroundCloud_Action2(BackgroundCloudEntity* this) {
    static const u8 gUnk_08121EB3[] = { 0x8, 0x28, 0x48, 0x98, 0 };
    if (super->subAction == 0) {
        super->subAction = 1;
        super->timer = ((Random() & 7) << 3) + 31;

        if ((super->direction & 0x10)) {
            super->x.HALF.HI = this->unk_7a;
        } else {
            super->x.HALF.HI = this->unk_78;
        }

        if (super->type == 2)
            super->y.HALF.HI = gUnk_08121EB3[super->type2 * 2 + (Random() & 1)];
    }

    if (super->subAction == 1) {
        if (--super->timer == 0) {
            super->action = 1;
            super->subAction = 0;
        }
    }
}