-
Notifications
You must be signed in to change notification settings - Fork 0
/
question_mark.cpp
94 lines (70 loc) · 2.55 KB
/
question_mark.cpp
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
#include "question_mark.h"
#include "global_variables.h"
#include "dynamic_entities.h"
#include <iostream>
QuestionMark::QuestionMark(){
entityType = ENTITY_QUESTIONMARK;
isStatic = true;
isActive = true;
initAnimation();
initSounds();
currentAnimation = &blockUnused;
currentAnimation->wishedTimePerFrame = 0.5;
}
void QuestionMark::initAnimation(){
blockUnused.texture = texturesContainer.marioBlocks;
blockUnused.bBox = &boundingBox;
blockUnused.frames.push_back(SDL_Rect {384, 0, 16, 16});
blockUnused.frames.push_back(SDL_Rect {400, 0, 16, 16});
blockUnused.frames.push_back(SDL_Rect {416, 0, 16, 16});
blockUsed.texture = texturesContainer.marioBlocks;
blockUsed.bBox = &boundingBox;
blockUsed.frames.push_back(SDL_Rect {432, 0, 16, 16});
}
void QuestionMark::update(float deltaTime, Camera *camera){
if(state == QuestionMarkState::NORMAL){
currentAnimation = &blockUnused;
}
else if(state == QuestionMarkState::DISABLED){
currentAnimation = &blockUsed;
bumpingSound.play();
// if(!pushBlock && position.y == originalPosition) return;
if(pushBlock){
if(position.y > maxYmovement) position.y -= speed;
else pushBlock = false;
}else{
if(position.y < originalPosition) position.y += speed;
}
if(!pushBlock && position.y == originalPosition && spawnItem){
spawnItem = false;
switch(itemType){
case ITEM_MUSHROOM:{
Mushroom *m = new Mushroom(position, position.y - Tile::tileSize);
tilemapToSpawnItemsOn->dynamicEntities.push_back(m);
break;
}
case ITEM_FIRE_FLOWER:{
FireFlower *f = new FireFlower(position, position.y - Tile::tileSize);
tilemapToSpawnItemsOn->dynamicEntities.push_back(f);
break;
}
default:
std::cout << "NO TYPE" << std::endl;
}
}
// std::cout << static_cast<int>(itemType) << std::endl;
}
updatePosition();
// currentAnimation->update(0.5);
}
void QuestionMark::draw(){
currentAnimation->animateSprite();
}
void QuestionMark::initParameters(){
maxYmovement = position.y - 16;
originalPosition = position.y;
}
void QuestionMark::initSounds(){
bumpingSound.channel = 4;
bumpingSound.sound = soundsContainer.bump;
}