-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenu.cpp
83 lines (62 loc) · 1.51 KB
/
Menu.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
#pragma once
#include "Menu.h"
Menu::Menu()
{
initialize();
}
void Menu::initialize()
{
is_playing = false;
is_updateSmoke = false;
is_intro1 = true;
intro = NULL;
}
Menu::~Menu()
{
free();
smoke_left.free();
smoke_right.free();
Mix_FreeChunk(intro);
intro = NULL;
Mix_FreeChunk(move_mouseEffect);
move_mouseEffect = NULL;
}
bool Menu::playing()
{
intro = Mix_LoadWAV("sound/intro.ogg");
move_mouseEffect = Mix_LoadWAV("sound/menu_music.ogg");
return is_playing;
}
void Menu::render()
{
if (!is_updateSmoke)
smoke_left.Update_LeftRight(true),
smoke_right.Update_LeftRight(false),
is_updateSmoke = true;
if (is_intro1)
loadFromFile("menu/intro1.png");
else
loadFromFile("menu/intro2.png");
SDL_Rect renderquad = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
SDL_RenderCopy(gRenderer, mTexture, NULL, &renderquad);
smoke_left.render();
smoke_right.render();
}
void Menu::HandleInputAction(SDL_Event e)
{
if ((e.button.x > 0 && e.button.x < SCREEN_WIDTH) &&
(e.button.y > 0 && e.button.y < SCREEN_HEIGHT))
{
if (is_intro1)
Mix_PlayChannel(-1, move_mouseEffect, 0);
is_intro1 = false;
if (e.type == SDL_MOUSEBUTTONDOWN)
is_playing = true,
free(),
smoke_left.free(),
smoke_right.free(),
Mix_FreeChunk(move_mouseEffect),
Mix_PlayChannel(-1, intro, 0);
}
else is_intro1 = true;
}