-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroStatusUnit.cpp
More file actions
81 lines (68 loc) · 2.08 KB
/
Copy pathIntroStatusUnit.cpp
File metadata and controls
81 lines (68 loc) · 2.08 KB
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
#include "IntroStatusUnit.hpp"
#include "GlobalUnit.hpp"
#include "OrthoUnit.hpp"
#include "GameUnit.hpp"
#include "LevelStatusUnit.hpp"
#include "FontUnit.hpp"
#include "TextureUnit.hpp"
#include "SoundUnit.hpp"
#include "ScreenUnit.hpp"
#include <GL/glu.h>
#include <algorithm>
TIntroStatus* IntroStatus = nullptr;
TIntroStatus::TIntroStatus() : lastTick(0), music(nullptr) {
music = Mix_LoadMUS("media/yeeha.xm");
if (music) {
Mix_PlayMusic(music, -1);
}
}
TIntroStatus::~TIntroStatus() {
if (music) Mix_FreeMusic(music);
}
void TIntroStatus::DoEnter() {
global.keystate->reset();
lastTick = SDL_GetTicks();
}
void TIntroStatus::DoExit() {
global.man->getSoundByName("x2")->play();
}
void TIntroStatus::DoLoop() {
uint32_t now = SDL_GetTicks();
uint32_t duration = now - lastTick;
lastTick = now;
TFloat s = std::max(0.001f, (TFloat)duration / 1000.0f);
DrawFrame(s);
}
void TIntroStatus::DrawFrame(TFloat delta) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(20, 20, 20, 0, 0, 0, 0, 1, 0);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
BeginOrtho(SCREEN_WIDTH, SCREEN_HEIGHT);
TTexture* intro = global.man->getTextureByName("intro");
if (intro) {
intro->bind();
glColor3f(1, 1, 1);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(0, 1); glVertex2f(0, (float)SCREEN_HEIGHT);
glTexCoord2f(1, 0); glVertex2f((float)SCREEN_WIDTH, 0);
glTexCoord2f(1, 1); glVertex2f((float)SCREEN_WIDTH, (float)SCREEN_HEIGHT);
glEnd();
}
EndOrtho();
SDL_GL_SwapWindow(global.screen->GetWindow());
}
void TIntroStatus::KeyDownEvent(const SDL_KeyboardEvent& event) {
if (event.keysym.sym == SDLK_SPACE) {
ChangeListener(LevelStatus);
}
if (event.keysym.sym == SDLK_ESCAPE) {
SDL_Event quitEv; quitEv.type = SDL_QUIT; SDL_PushEvent(&quitEv);
}
}
void TIntroStatus::MouseMoveEvent(const SDL_MouseMotionEvent& event) {
global.mx = event.x;
global.my = event.y;
}