-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoin.h
54 lines (53 loc) · 1.52 KB
/
coin.h
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
const int frameDelayCoin = 15;
int coinCount = 0, coinDisplay = 0;
void newCoin(Bloco* s, posi pos, int* id, int coinsId[], int* qntdCoins){
s->s.img = al_load_bitmap(URI_COIN);
s->s.pos = pos;
s->s.bound.x = 20;
s->s.bound.y = 24;
s->s.w = 40;
s->s.h = 40;
s->s.frameDelay = 3;
s->s.curFrame = 0;
s->s.frameCount = 0;
s->s.loop = false;
s->s.maxFrame = 2;
s->type = COIN;
coinsId[(*qntdCoins)++] = (*id)++;
}
void updateSpriteCoin(Bloco* c){
if (++c->s.frameCount >= frameDelayCoin) {
if(c->s.loop){
if(--c->s.curFrame < 0){
c->s.curFrame = 0;
c->s.loop = false;
}
}
else{
if(++c->s.curFrame == c->s.maxFrame)
c->s.loop = true;
}
c->s.frameCount = 0;
}
}
void updateCoins() {
if (coinCount > coinDisplay) {
coinDisplay++;
somCollectCoin();
}
else if (coinCount < coinDisplay) {
coinDisplay--;
somCollectCoin();
}
}
bool handleCoinCollision(Sprite mario, Bloco* bloco, int* alturaPulo) {
bool colidiu = false;
if (mario.pos.x + mario.bound.x > bloco->s.pos.x - bloco->s.bound.x &&
mario.pos.x - mario.bound.x < bloco->s.pos.x + bloco->s.bound.x &&
mario.pos.y - *alturaPulo + mario.bound.y > bloco->s.pos.y - bloco->s.bound.y &&
mario.pos.y - *alturaPulo - mario.bound.y < bloco->s.pos.y + bloco->s.bound.y) {
coinCount++;
bloco->destroyed = true;
}
return colidiu;
}