SQC-06 et une partie du SQC-09
This commit is contained in:
parent
8e40f17b75
commit
6668127f15
@ -65,5 +65,6 @@ enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BT
|
|||||||
#define SHADER_PATH "./media/shaders/"
|
#define SHADER_PATH "./media/shaders/"
|
||||||
#define AUDIO_PATH "./media/audio/"
|
#define AUDIO_PATH "./media/audio/"
|
||||||
#define CHUNK_PATH "./media/chunks/"
|
#define CHUNK_PATH "./media/chunks/"
|
||||||
|
#define MENU_ITEM_PATH "./media/menu_items/"
|
||||||
|
|
||||||
#endif // DEFINE_H__
|
#endif // DEFINE_H__
|
||||||
|
@ -14,7 +14,199 @@ Engine::~Engine() {
|
|||||||
m_world.GetChunks().Get(x, y)->~Chunk();
|
m_world.GetChunks().Get(x, y)->~Chunk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::DrawMenu()
|
||||||
|
{
|
||||||
|
static const int sTitle = 400;
|
||||||
|
static const int sButton = 225;
|
||||||
|
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glOrtho(0, Width(), 0, Height(), -1, 1);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
MenuBGTexture.Bind();
|
||||||
|
glLoadIdentity();
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(800, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(800, 600);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 600);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
|
||||||
|
if (m_gamestate != GameState::OPTIONS)
|
||||||
|
{
|
||||||
|
MenuTitleTexture.Bind();
|
||||||
|
glTranslated(200, 300, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sTitle, 200);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sTitle, 300);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 300);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
MenuStartTexture.Bind();
|
||||||
|
glTranslated(80, -225, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 100);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 100);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
/*MenuResumeTexture.Bind();
|
||||||
|
glTranslated(0, -100, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();*/
|
||||||
|
|
||||||
|
/*MenuOptionsTexture.Bind();
|
||||||
|
glTranslated(0, -100, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();*/
|
||||||
|
|
||||||
|
MenuQuitTexture.Bind();
|
||||||
|
glTranslated(0, -100, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 100);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 100);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*MenuOptionsTexture.Bind();
|
||||||
|
glTranslated(200, 0, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 0);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sTitle, 0);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sTitle, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
WireFrameTexture.Bind();
|
||||||
|
glTranslated(0, 300, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
OnOffBtnTexture.Bind();
|
||||||
|
glTranslated(200, 0, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
glTranslated(-400, -300, 0);
|
||||||
|
|
||||||
|
MusicTexture.Bind();
|
||||||
|
glTranslated(200, 200, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
OnOffBtnTexture.Bind();
|
||||||
|
glTranslated(200, 0, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 125);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 125);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
BackBtnTexture.Bind();
|
||||||
|
glTranslated(-375, 175, 0);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2i(0, 140);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2i(sButton, 140);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2i(sButton, 200);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2i(0, 200);
|
||||||
|
glEnd();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glPopMatrix();
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPopMatrix();
|
||||||
|
ShowCursor();
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::Init() {
|
void Engine::Init() {
|
||||||
|
m_gamestate = GameState::MAIN_MENU;
|
||||||
GLenum glewErr = glewInit();
|
GLenum glewErr = glewInit();
|
||||||
if (glewErr != GLEW_OK) {
|
if (glewErr != GLEW_OK) {
|
||||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||||
@ -63,6 +255,11 @@ void Engine::LoadResource() {
|
|||||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png");
|
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png");
|
||||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
|
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
|
||||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
|
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
|
||||||
|
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png");
|
||||||
|
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png");
|
||||||
|
LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png");
|
||||||
|
LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png");
|
||||||
|
LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png");
|
||||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||||
@ -185,6 +382,10 @@ void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) {
|
|||||||
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||||
|
|
||||||
void Engine::Render(float elapsedTime) {
|
void Engine::Render(float elapsedTime) {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
|
if (m_gamestate == GameState::PLAY)
|
||||||
|
{
|
||||||
//static float gameTime = elapsedTime;
|
//static float gameTime = elapsedTime;
|
||||||
static float pollTime = 0;
|
static float pollTime = 0;
|
||||||
static float bulletTime = 0;
|
static float bulletTime = 0;
|
||||||
@ -197,7 +398,6 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
Transformation all;
|
Transformation all;
|
||||||
Transformation skybox;
|
Transformation skybox;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
||||||
|
|
||||||
// Transformations initiales
|
// Transformations initiales
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@ -277,6 +477,14 @@ void Engine::Render(float elapsedTime) {
|
|||||||
fell = false;
|
fell = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||||
|
{
|
||||||
|
DrawMenu();
|
||||||
|
}
|
||||||
|
else if (m_gamestate == GameState::QUIT)
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::KeyPressEvent(unsigned char key) {
|
void Engine::KeyPressEvent(unsigned char key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@ -390,10 +598,15 @@ void Engine::MouseMoveEvent(int x, int y) {
|
|||||||
if (x == (Width() / 2) && y == (Height() / 2))
|
if (x == (Width() / 2) && y == (Height() / 2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CenterMouse();
|
//CenterMouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||||
|
m_mousemx = x;
|
||||||
|
m_mousemy = y;
|
||||||
|
|
||||||
|
if (m_gamestate == GameState::PLAY)
|
||||||
|
{
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case MOUSE_BUTTON_LEFT:
|
case MOUSE_BUTTON_LEFT:
|
||||||
m_mouseL = true;
|
m_mouseL = true;
|
||||||
@ -413,6 +626,14 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
|||||||
case MOUSE_BUTTON_NONE: break;
|
case MOUSE_BUTTON_NONE: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (m_gamestate == GameState::MAIN_MENU)
|
||||||
|
{
|
||||||
|
if ((m_mousemx >= 285 && m_mousemx <= 490) && (m_mousemy >= 150 && m_mousemy <= 250))
|
||||||
|
m_gamestate = GameState::PLAY;
|
||||||
|
if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400))
|
||||||
|
m_gamestate = GameState::QUIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
|
void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||||
switch (button) {
|
switch (button) {
|
||||||
|
@ -19,6 +19,7 @@ class Engine : public OpenglContext {
|
|||||||
public:
|
public:
|
||||||
Engine();
|
Engine();
|
||||||
virtual ~Engine();
|
virtual ~Engine();
|
||||||
|
virtual void DrawMenu();
|
||||||
virtual void Init();
|
virtual void Init();
|
||||||
virtual void DeInit();
|
virtual void DeInit();
|
||||||
virtual void LoadResource();
|
virtual void LoadResource();
|
||||||
@ -51,6 +52,7 @@ private:
|
|||||||
Texture m_textureFont;
|
Texture m_textureFont;
|
||||||
Texture m_textureCrosshair;
|
Texture m_textureCrosshair;
|
||||||
|
|
||||||
|
|
||||||
Skybox m_skybox;
|
Skybox m_skybox;
|
||||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
||||||
|
|
||||||
@ -61,6 +63,15 @@ private:
|
|||||||
|
|
||||||
Bullet* m_bullets[MAX_BULLETS];
|
Bullet* m_bullets[MAX_BULLETS];
|
||||||
|
|
||||||
|
//Menu
|
||||||
|
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||||
|
GameState m_gamestate;
|
||||||
|
Texture MenuTitleTexture;
|
||||||
|
Texture MenuBGTexture;
|
||||||
|
Texture MenuStartTexture;
|
||||||
|
Texture MenuQuitTexture;
|
||||||
|
Texture MenuOptionsTexture;
|
||||||
|
|
||||||
bool m_keyW = false;
|
bool m_keyW = false;
|
||||||
bool m_keyA = false;
|
bool m_keyA = false;
|
||||||
bool m_keyS = false;
|
bool m_keyS = false;
|
||||||
@ -72,6 +83,9 @@ private:
|
|||||||
bool m_mouseC = false;
|
bool m_mouseC = false;
|
||||||
bool m_mouseWU = false;
|
bool m_mouseWU = false;
|
||||||
bool m_mouseWD = false;
|
bool m_mouseWD = false;
|
||||||
|
//Pour trouver ou est la souris
|
||||||
|
float m_mousemx = 0;
|
||||||
|
float m_mousemy = 0;
|
||||||
|
|
||||||
bool m_block = false;
|
bool m_block = false;
|
||||||
bool m_flash = true;
|
bool m_flash = true;
|
||||||
|
BIN
SQCSim2021/media/menu_items/BasicPlay.png
Normal file
BIN
SQCSim2021/media/menu_items/BasicPlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
BIN
SQCSim2021/media/menu_items/BasicQuit.png
Normal file
BIN
SQCSim2021/media/menu_items/BasicQuit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
BIN
SQCSim2021/media/menu_items/test.png
Normal file
BIN
SQCSim2021/media/menu_items/test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 289 KiB |
Loading…
x
Reference in New Issue
Block a user