-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrough.h
75 lines (58 loc) · 1.24 KB
/
Trough.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include "Globals.h"
#include "Application.h"
#include "Module.h"
#include "Prop.h"
#include "ModulePhysics.h"
#include "ModuleTextures.h"
#include "ModuleAudio.h"
#include "ModuleScene.h"
class ModulePhysics;
class SDL_Texture;
class Trough : public Prop {
public:
Trough(PropType type) : Prop(type) {
loseSfx = App->audio->LoadFx("pinball/Sounds/lose.wav");
x = 120;
y = SCREEN_HEIGHT + 20;
pBody = App->physics->CreateRectangleSensor(x, y, 45, 5);
pBody->listener = (Module*)App->pManager;
pBody->body->SetTransform(b2Vec2(PIXEL_TO_METERS(x), PIXEL_TO_METERS(y)), 0.0f);
pBody->body->SetType(b2BodyType::b2_staticBody);
pBody->prop = this;
}
void PlaySFX() {
App->audio->PlayFx(loseSfx);
}
bool Update() {
if (switchLayer) {
App->scene->switchLayer(2);
switchLayer = false;
}
return true;
}
void OnCollision(PhysBody* bodyB) {
if (bodyB->prop != NULL) {
switch (bodyB->prop->type) {
case PropType::BALL:
PlaySFX();
App->scene->lives--;
App->scene->ResetTable();
switchLayer = true;
break;
}
}
}
bool CleanUp() {
delete pBody;
pBody = nullptr;
return true;
}
private:
int x;
int y;
PhysBody* pBody;
bool switchLayer = false;
// SFX
int loseSfx;
};