Compare commits
No commits in common. "4c837eff0a1c3677e5b0af88a43e5a73d8a5be9d" and "8f9a18d960ce7034e7d48e5ff2bf9b9a304d0306" have entirely different histories.
4c837eff0a
...
8f9a18d960
@ -8,7 +8,7 @@ namespace ZL {
|
|||||||
int Environment::windowHeaderHeight = 0;
|
int Environment::windowHeaderHeight = 0;
|
||||||
int Environment::width = 0;
|
int Environment::width = 0;
|
||||||
int Environment::height = 0;
|
int Environment::height = 0;
|
||||||
float Environment::zoom = 14.f;
|
float Environment::zoom = 6.f;
|
||||||
|
|
||||||
bool Environment::leftPressed = false;
|
bool Environment::leftPressed = false;
|
||||||
bool Environment::rightPressed = false;
|
bool Environment::rightPressed = false;
|
||||||
|
|||||||
156
Game.cpp
156
Game.cpp
@ -202,66 +202,7 @@ namespace ZL
|
|||||||
|
|
||||||
sparkEmitter.setTexture(sparkTexture);
|
sparkEmitter.setTexture(sparkTexture);
|
||||||
|
|
||||||
|
|
||||||
buttonTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/button.png", CONST_ZIP_FILE));
|
|
||||||
|
|
||||||
button.data.PositionData.push_back({ 100, 100, 0 });
|
|
||||||
button.data.PositionData.push_back({ 100, 150, 0 });
|
|
||||||
button.data.PositionData.push_back({ 300, 150, 0 });
|
|
||||||
button.data.PositionData.push_back({ 100, 100, 0 });
|
|
||||||
button.data.PositionData.push_back({ 300, 150, 0 });
|
|
||||||
button.data.PositionData.push_back({ 300, 100, 0 });
|
|
||||||
|
|
||||||
button.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
button.data.TexCoordData.push_back({ 0,1 });
|
|
||||||
button.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
button.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
button.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
button.data.TexCoordData.push_back({ 1,0 });
|
|
||||||
|
|
||||||
button.RefreshVBO();
|
|
||||||
|
|
||||||
musicVolumeBarTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/musicVolumeBarTexture.png", CONST_ZIP_FILE));
|
|
||||||
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1190, 100, 0 });
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1190, 600, 0 });
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1200, 600, 0 });
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1190, 100, 0 });
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1200, 600, 0 });
|
|
||||||
musicVolumeBar.data.PositionData.push_back({ 1200, 100, 0 });
|
|
||||||
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 0,1 });
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
musicVolumeBar.data.TexCoordData.push_back({ 1,0 });
|
|
||||||
|
|
||||||
musicVolumeBar.RefreshVBO();
|
|
||||||
|
|
||||||
|
|
||||||
musicVolumeBarButtonTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/musicVolumeBarButton.png", CONST_ZIP_FILE));
|
|
||||||
|
|
||||||
float musicVolumeBarButtonButtonCenterY = 350.0f;
|
|
||||||
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
musicVolumeBarButton.data.PositionData.push_back({ musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 });
|
|
||||||
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 0,1 });
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 0,0 });
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 1,1 });
|
|
||||||
musicVolumeBarButton.data.TexCoordData.push_back({ 1,0 });
|
|
||||||
|
|
||||||
musicVolumeBarButton.RefreshVBO();
|
|
||||||
renderer.InitOpenGL();
|
renderer.InitOpenGL();
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +264,7 @@ namespace ZL
|
|||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(spaceship);
|
renderer.DrawVertexRenderStruct(spaceship);
|
||||||
|
|
||||||
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
sparkEmitter.draw(renderer, Environment::zoom, Environment::width, Environment::height);
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
@ -374,77 +316,6 @@ namespace ZL
|
|||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
void Game::UpdateVolumeKnob() {
|
|
||||||
float musicVolumeBarButtonButtonCenterY = volumeBarMinY + musicVolume * (volumeBarMaxY - volumeBarMinY);
|
|
||||||
|
|
||||||
auto& pos = musicVolumeBarButton.data.PositionData;
|
|
||||||
|
|
||||||
pos[0] = { musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
pos[1] = { musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
pos[2] = { musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
pos[3] = { musicVolumeBarButtonButtonCenterX - musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
pos[4] = { musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY + musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
pos[5] = { musicVolumeBarButtonButtonCenterX + musicVolumeBarButtonButtonRadius, musicVolumeBarButtonButtonCenterY - musicVolumeBarButtonButtonRadius, 0 };
|
|
||||||
|
|
||||||
musicVolumeBarButton.RefreshVBO();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::UpdateVolumeFromMouse(int mouseX, int mouseY) {
|
|
||||||
|
|
||||||
int uiX = mouseX;
|
|
||||||
int uiY = Environment::height - mouseY;
|
|
||||||
Environment::shipVelocity = (musicVolume) * (20.0);
|
|
||||||
if (uiY < volumeBarMinY || uiY > volumeBarMaxY)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float t = (uiY - volumeBarMinY) / (volumeBarMaxY - volumeBarMinY);
|
|
||||||
if (t < 0.0f) t = 0.0f;
|
|
||||||
if (t > 1.0f) t = 1.0f;
|
|
||||||
musicVolume = t;
|
|
||||||
UpdateVolumeKnob();
|
|
||||||
}
|
|
||||||
void Game::drawUI()
|
|
||||||
{
|
|
||||||
static const std::string defaultShaderName = "default";
|
|
||||||
static const std::string envShaderName = "env";
|
|
||||||
static const std::string vPositionName = "vPosition";
|
|
||||||
static const std::string vTexCoordName = "vTexCoord";
|
|
||||||
static const std::string textureUniformName = "Texture";
|
|
||||||
|
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(defaultShaderName);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.PushProjectionMatrix(Environment::width, Environment::height, -1, 1);
|
|
||||||
renderer.PushMatrix();
|
|
||||||
|
|
||||||
renderer.LoadIdentity();
|
|
||||||
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, buttonTexture->getTexID());
|
|
||||||
renderer.DrawVertexRenderStruct(button);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, musicVolumeBarTexture->getTexID());
|
|
||||||
renderer.DrawVertexRenderStruct(musicVolumeBar);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, musicVolumeBarButtonTexture->getTexID());
|
|
||||||
renderer.DrawVertexRenderStruct(musicVolumeBarButton);
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
|
||||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
|
||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
CheckGlError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::drawScene() {
|
void Game::drawScene() {
|
||||||
static const std::string defaultShaderName = "default";
|
static const std::string defaultShaderName = "default";
|
||||||
@ -464,8 +335,6 @@ namespace ZL
|
|||||||
drawShip();
|
drawShip();
|
||||||
drawBoxes();
|
drawBoxes();
|
||||||
|
|
||||||
drawUI();
|
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,19 +419,6 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
// 1. Îáðàáîòêà íàæàòèÿ êíîïêè ìûøè
|
// 1. Îáðàáîòêà íàæàòèÿ êíîïêè ìûøè
|
||||||
|
|
||||||
int mx = event.button.x;
|
|
||||||
int my = event.button.y;
|
|
||||||
|
|
||||||
std::cout << mx << " " << my << '\n';
|
|
||||||
int uiX = mx;
|
|
||||||
int uiY = Environment::height - my;
|
|
||||||
if (uiX >= volumeBarMinX-40 && uiX <= volumeBarMaxX+40 &&
|
|
||||||
uiY >= volumeBarMinY-40 && uiY <= volumeBarMaxY+40) {
|
|
||||||
isDraggingVolume = true;
|
|
||||||
UpdateVolumeFromMouse(mx, my);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Environment::tapDownHold = true;
|
Environment::tapDownHold = true;
|
||||||
// Êîîðäèíàòû íà÷àëüíîãî íàæàòèÿ
|
// Êîîðäèíàòû íà÷àëüíîãî íàæàòèÿ
|
||||||
Environment::tapDownStartPos.v[0] = event.button.x;
|
Environment::tapDownStartPos.v[0] = event.button.x;
|
||||||
@ -571,22 +427,12 @@ namespace ZL
|
|||||||
Environment::tapDownCurrentPos.v[0] = event.button.x;
|
Environment::tapDownCurrentPos.v[0] = event.button.x;
|
||||||
Environment::tapDownCurrentPos.v[1] = event.button.y;
|
Environment::tapDownCurrentPos.v[1] = event.button.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
else if (event.type == SDL_MOUSEBUTTONUP) {
|
else if (event.type == SDL_MOUSEBUTTONUP) {
|
||||||
// 2. Îáðàáîòêà îòïóñêàíèÿ êíîïêè ìûøè
|
// 2. Îáðàáîòêà îòïóñêàíèÿ êíîïêè ìûøè
|
||||||
isDraggingVolume = false;
|
|
||||||
Environment::tapDownHold = false;
|
Environment::tapDownHold = false;
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_MOUSEMOTION) {
|
else if (event.type == SDL_MOUSEMOTION) {
|
||||||
// 3. Îáðàáîòêà ïåðåìåùåíèÿ ìûøè
|
// 3. Îáðàáîòêà ïåðåìåùåíèÿ ìûøè
|
||||||
int mx = event.motion.x;
|
|
||||||
int my = event.motion.y;
|
|
||||||
|
|
||||||
if (isDraggingVolume) {
|
|
||||||
// Äâèãàåì ìûøü ïî ñëàéäåðó — ìåíÿåì ãðîìêîñòü è ïîçèöèþ êðóæêà
|
|
||||||
UpdateVolumeFromMouse(mx, my);
|
|
||||||
}
|
|
||||||
if (Environment::tapDownHold) {
|
if (Environment::tapDownHold) {
|
||||||
// Îáíîâëåíèå òåêóùåé ïîçèöèè, åñëè êíîïêà óäåðæèâàåòñÿ
|
// Îáíîâëåíèå òåêóùåé ïîçèöèè, åñëè êíîïêà óäåðæèâàåòñÿ
|
||||||
Environment::tapDownCurrentPos.v[0] = event.motion.x;
|
Environment::tapDownCurrentPos.v[0] = event.motion.x;
|
||||||
|
|||||||
32
Game.h
32
Game.h
@ -25,7 +25,6 @@ namespace ZL {
|
|||||||
void update();
|
void update();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
|
||||||
bool shouldExit() const { return Environment::exitGameLoop; }
|
bool shouldExit() const { return Environment::exitGameLoop; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -34,7 +33,6 @@ namespace ZL {
|
|||||||
void drawCubemap();
|
void drawCubemap();
|
||||||
void drawShip();
|
void drawShip();
|
||||||
void drawBoxes();
|
void drawBoxes();
|
||||||
void drawUI();
|
|
||||||
|
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_GLContext glContext;
|
SDL_GLContext glContext;
|
||||||
@ -43,32 +41,6 @@ namespace ZL {
|
|||||||
size_t newTickCount;
|
size_t newTickCount;
|
||||||
size_t lastTickCount;
|
size_t lastTickCount;
|
||||||
|
|
||||||
|
|
||||||
std::vector<BoxCoords> boxCoordsArr;
|
|
||||||
std::vector<VertexRenderStruct> boxRenderArr;
|
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Texture> buttonTexture;
|
|
||||||
VertexRenderStruct button;
|
|
||||||
|
|
||||||
std::shared_ptr<Texture> musicVolumeBarTexture;
|
|
||||||
VertexRenderStruct musicVolumeBar;
|
|
||||||
|
|
||||||
std::shared_ptr<Texture> musicVolumeBarButtonTexture;
|
|
||||||
VertexRenderStruct musicVolumeBarButton;
|
|
||||||
|
|
||||||
|
|
||||||
bool isDraggingVolume = false;
|
|
||||||
float musicVolume = 0.0f;
|
|
||||||
float volumeBarMinX = 1190.0f;
|
|
||||||
float volumeBarMaxX = 1200.0f;
|
|
||||||
float volumeBarMinY = 100.0f;
|
|
||||||
float volumeBarMaxY = 600.0f;
|
|
||||||
float musicVolumeBarButtonButtonCenterX = 1195.0f;
|
|
||||||
float musicVolumeBarButtonButtonRadius = 25.0f;
|
|
||||||
void UpdateVolumeFromMouse(int mouseX, int mouseY);
|
|
||||||
void UpdateVolumeKnob();
|
|
||||||
|
|
||||||
static const size_t CONST_TIMER_INTERVAL = 10;
|
static const size_t CONST_TIMER_INTERVAL = 10;
|
||||||
static const size_t CONST_MAX_TIME_INTERVAL = 1000;
|
static const size_t CONST_MAX_TIME_INTERVAL = 1000;
|
||||||
|
|
||||||
@ -83,8 +55,10 @@ namespace ZL {
|
|||||||
std::shared_ptr<Texture> boxTexture;
|
std::shared_ptr<Texture> boxTexture;
|
||||||
VertexDataStruct boxBase;
|
VertexDataStruct boxBase;
|
||||||
|
|
||||||
|
std::vector<BoxCoords> boxCoordsArr;
|
||||||
|
std::vector<VertexRenderStruct> boxRenderArr;
|
||||||
|
|
||||||
SparkEmitter sparkEmitter;
|
SparkEmitter sparkEmitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
BIN
resources/button.png
(Stored with Git LFS)
BIN
resources/button.png
(Stored with Git LFS)
Binary file not shown.
BIN
resources/musicVolumeBarButton.png
(Stored with Git LFS)
BIN
resources/musicVolumeBarButton.png
(Stored with Git LFS)
Binary file not shown.
BIN
resources/musicVolumeBarTexture.png
(Stored with Git LFS)
BIN
resources/musicVolumeBarTexture.png
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user