Merge branch 'master' into sqc-20_audiobullet
This commit is contained in:
commit
18a5d98c57
5
.gitignore
vendored
5
.gitignore
vendored
@ -373,3 +373,8 @@ FodyWeavers.xsd
|
||||
/x64/Release/SQCSim2023.exe
|
||||
/x64/Debug/SQCSim2023.exe
|
||||
/x64/Debug/SQCSim2021.pdb
|
||||
/SQCSim-srv/cmake/*
|
||||
!/SQCSim-srv/cmake/CMakeLists.txt
|
||||
/SQCSim2021/cmake/*
|
||||
!/SQCSim2021/cmake/CMakeLists.txt
|
||||
/SQCSim2021/SQCSim-client
|
||||
|
@ -53,6 +53,7 @@ typedef uint64_t Timestamp;
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <cstring>
|
||||
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
|
@ -130,7 +130,7 @@ void World::GetScope(unsigned int& x, unsigned int& y) {
|
||||
y = m_center[1];
|
||||
}
|
||||
|
||||
void World::Update(Bullet* bullets[MAX_BULLETS], Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) {
|
||||
UpdateWorld(player_pos, blockinfo);
|
||||
//TransposeWorld(player_pos, bullets);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType = BTYPE_AIR) const;
|
||||
BlockType BlockAt(const Vector3f& pos, BlockType defaultBlockType = BTYPE_AIR) const;
|
||||
|
||||
void Update(Bullet* bullets[MAX_BULLETS], Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
void Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
|
||||
void GetScope(unsigned int& x, unsigned int& y);
|
||||
|
||||
|
30
SQCSim-srv/cmake/CMakeLists.txt
Normal file
30
SQCSim-srv/cmake/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
cmake_minimum_required(VERSION 3.18.4)
|
||||
|
||||
project(SQCSim-Server VERSION 0.1)
|
||||
|
||||
add_compile_options("-Wno-narrowing")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_STANDARD_REQUIRED True)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../out")
|
||||
|
||||
set(SQCSIM_COMMON_DIR "../../SQCSim-common/")
|
||||
|
||||
add_library(SQCSim-common
|
||||
"${SQCSIM_COMMON_DIR}blockinfo.cpp"
|
||||
"${SQCSIM_COMMON_DIR}bullet.cpp"
|
||||
"${SQCSIM_COMMON_DIR}chunk.cpp"
|
||||
"${SQCSIM_COMMON_DIR}netprotocol.cpp"
|
||||
"${SQCSIM_COMMON_DIR}opensimplex.cpp"
|
||||
"${SQCSIM_COMMON_DIR}player.cpp"
|
||||
"${SQCSIM_COMMON_DIR}transformation.cpp"
|
||||
"${SQCSIM_COMMON_DIR}world.cpp"
|
||||
)
|
||||
|
||||
add_executable(SQCSim-server
|
||||
"../connection.cpp"
|
||||
"../server.cpp"
|
||||
"../main.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(SQCSim-server PUBLIC SQCSim-common)
|
@ -85,7 +85,7 @@ int Server::Ready() {
|
||||
|
||||
while (!readystart) {
|
||||
sockaddr_in sockad;
|
||||
int addrlen = sizeof(sockad);
|
||||
unsigned int addrlen = sizeof(sockad);
|
||||
SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen);
|
||||
|
||||
if (sock < 0)
|
||||
@ -140,7 +140,7 @@ void Server::Run() {
|
||||
Log("Partie en cours...", false, false);
|
||||
}
|
||||
|
||||
inline std::string Server::Timestamp() {
|
||||
inline std::string Server::LogTimestamp() {
|
||||
time_t rawtime;
|
||||
struct tm timeinfo;
|
||||
char buffer[80];
|
||||
@ -162,11 +162,11 @@ inline std::string Server::Timestamp() {
|
||||
void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) {
|
||||
switch (m_log) {
|
||||
case LOG_DEST::LOGFILE:
|
||||
m_logfile << Timestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
|
||||
m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
|
||||
break;
|
||||
case LOG_DEST::CONSOLE:
|
||||
default:
|
||||
std::cout << Timestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
|
||||
std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ private:
|
||||
|
||||
World* m_world = nullptr;
|
||||
|
||||
std::string Timestamp();
|
||||
std::string LogTimestamp();
|
||||
void Log(std::string str, bool is_error, bool is_fatal);
|
||||
void buildIdList(size_t size);
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
#ifndef AUDIO_H__
|
||||
#define AUDIO_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <irrKlang.h>
|
||||
#include <ik_ISoundSource.h>
|
||||
#else
|
||||
#include "./external/irrKlang-64bit-1.6.0/include/irrKlang.h"
|
||||
#include "./external/irrKlang-64bit-1.6.0/include/ik_ISoundSource.h"
|
||||
#endif
|
||||
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include "define.h"
|
||||
|
||||
|
68
SQCSim2021/cmake/CMakeLists.txt
Normal file
68
SQCSim2021/cmake/CMakeLists.txt
Normal file
@ -0,0 +1,68 @@
|
||||
cmake_minimum_required(VERSION 3.18.4)
|
||||
|
||||
project(SQCSim-Client VERSION 0.8)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_STANDARD_REQUIRED True)
|
||||
|
||||
set(CMAKE_BUILD_DIRECTORY "./build")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../")
|
||||
|
||||
set(SQCSIM_COMMON_DIR "../../SQCSim-common/")
|
||||
set(SQCSIM_EXTERN_DIR "../external/")
|
||||
|
||||
find_package(SFML COMPONENTS system window graphics REQUIRED)
|
||||
find_package(DevIL REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW REQUIRED)
|
||||
|
||||
find_library(IRRKLANG_LIBRARY
|
||||
NAMES libIrrKlang.so
|
||||
PATHS "${SQCSIM_EXTERN_DIR}/irrKlang-64bit-1.6.0/lib/linux-gcc-64/")
|
||||
|
||||
include_directories(
|
||||
${SQCSIM_EXTERN_DIR}/irrKlang-64bit-1.6.0/include/
|
||||
${SFML_INCLUDE_DIRS}
|
||||
${IL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
add_library(SQCSim-common
|
||||
"${SQCSIM_COMMON_DIR}blockinfo.cpp"
|
||||
"${SQCSIM_COMMON_DIR}bullet.cpp"
|
||||
"${SQCSIM_COMMON_DIR}chunk.cpp"
|
||||
"${SQCSIM_COMMON_DIR}netprotocol.cpp"
|
||||
"${SQCSIM_COMMON_DIR}opensimplex.cpp"
|
||||
"${SQCSIM_COMMON_DIR}player.cpp"
|
||||
"${SQCSIM_COMMON_DIR}transformation.cpp"
|
||||
"${SQCSIM_COMMON_DIR}world.cpp"
|
||||
)
|
||||
|
||||
add_executable(SQCSim-client
|
||||
"../audio.cpp"
|
||||
"../connector.cpp"
|
||||
"../engine.cpp"
|
||||
"../mesh.cpp"
|
||||
"../openglcontext.cpp"
|
||||
"../shader.cpp"
|
||||
"../skybox.cpp"
|
||||
"../texture.cpp"
|
||||
"../textureatlas.cpp"
|
||||
"../tool.cpp"
|
||||
"../vertexbuffer.cpp"
|
||||
"../worldrenderer.cpp"
|
||||
"../main.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(SQCSim-client PUBLIC SQCSim-common
|
||||
${IRRKLANG_LIBRARY}
|
||||
sfml-system
|
||||
sfml-window
|
||||
sfml-graphics
|
||||
GL
|
||||
GLU
|
||||
GLEW
|
||||
${IL_LIBRARIES}
|
||||
${ILU_LIBRARIES}
|
||||
)
|
||||
|
@ -6,14 +6,18 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <GL/glew.h>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "../SQCSim-common/define.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <GL/glew.h>
|
||||
#include <gl/GL.h>
|
||||
#include <gl/GLU.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <climits>
|
||||
#endif
|
||||
|
||||
#define NETWORK_TEST false
|
||||
@ -22,12 +26,14 @@
|
||||
|
||||
#define BULLET_UPDATES_PER_FRAME 20
|
||||
|
||||
#define BASE_WIDTH 1920
|
||||
#define BASE_HEIGHT 1080
|
||||
#define BASE_WIDTH 640
|
||||
#define BASE_HEIGHT 480
|
||||
|
||||
|
||||
#define TEXTURE_PATH "./media/textures/"
|
||||
#define SHADER_PATH "./media/shaders/"
|
||||
#define AUDIO_PATH "./media/audio/"
|
||||
#define CHUNK_PATH "./media/chunks/"
|
||||
#define MENU_ITEM_PATH "./media/menu_items/"
|
||||
|
||||
#endif // DEFINE_H__
|
||||
|
0
SQCSim2021/docs/analyse_preliminaire.md
Normal file
0
SQCSim2021/docs/analyse_preliminaire.md
Normal file
1
SQCSim2021/docs/analyse_serveur.md
Normal file
1
SQCSim2021/docs/analyse_serveur.md
Normal file
@ -0,0 +1 @@
|
||||
|
@ -28,6 +28,200 @@ Engine::~Engine() {
|
||||
m_world.GetChunks().Get(x, y)->~Chunk();
|
||||
}
|
||||
|
||||
void Engine::DrawMenu()
|
||||
{
|
||||
static const int sTitle = 400;
|
||||
static const int sButton = 225;
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_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();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
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() {
|
||||
GLenum glewErr = glewInit();
|
||||
if (glewErr != GLEW_OK) {
|
||||
@ -53,6 +247,7 @@ void Engine::Init() {
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
//
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
@ -67,18 +262,18 @@ void Engine::Init() {
|
||||
}
|
||||
|
||||
uint64_t seed = SEED;
|
||||
std::string playname = "La Chienne à Jacques";
|
||||
if (NETWORK_TEST) { // Test connexion réseau.
|
||||
std::string playname = "La Chienne <EFBFBD> Jacques";
|
||||
if (NETWORK_TEST) { // Test connexion r<EFBFBD>seau.
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(SRV_ADDR, playname)) {
|
||||
// setup jeu en réseau.
|
||||
std::cout << "ID reçu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed reçu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
// setup jeu en r<EFBFBD>seau.
|
||||
std::cout << "ID re<EFBFBD>u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
|
||||
std::cout << "Seed re<EFBFBD>u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
|
||||
seed = m_conn.getSeed();
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de création de socket." << std::endl;
|
||||
else std::cout << "Erreur de cr<EFBFBD>ation de socket." << std::endl;
|
||||
}
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
@ -99,8 +294,13 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
|
||||
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", true);
|
||||
|
||||
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 texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||
@ -192,8 +392,6 @@ void Engine::ProcessNotificationQueue() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
|
||||
|
||||
PrintText(xOffset, y, scale, it->message);
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
@ -240,6 +438,7 @@ void Engine::DisplayCrosshair() {
|
||||
void Engine::DisplayCurrentItem() {
|
||||
}
|
||||
|
||||
|
||||
void Engine::DisplayHud(int timer) {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glLoadIdentity();
|
||||
@ -253,7 +452,7 @@ void Engine::DisplayHud(int timer) {
|
||||
float playerHp = m_player.GetHP();
|
||||
float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f;
|
||||
|
||||
// Arrière-plan (Barre HP)
|
||||
// Arri<EFBFBD>re-plan (Barre HP)
|
||||
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(fPosX, fPosY - fBarHeight); // Bas-Gauche
|
||||
@ -262,7 +461,7 @@ void Engine::DisplayHud(int timer) {
|
||||
glVertex2f(fPosX, fPosY); // Haut-Gauche
|
||||
glEnd();
|
||||
|
||||
//TODO: Associer avec méchanique de vie du joueur
|
||||
//TODO: Associer avec m<EFBFBD>chanique de vie du joueur
|
||||
|
||||
// Barre HP
|
||||
glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
|
||||
@ -273,7 +472,7 @@ void Engine::DisplayHud(int timer) {
|
||||
glVertex2f(fPosX, fPosY); // Haut-Gauche
|
||||
glEnd();
|
||||
|
||||
// Barre équip
|
||||
// Barre <EFBFBD>quip
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
|
||||
@ -294,7 +493,7 @@ void Engine::DisplayHud(int timer) {
|
||||
glTexCoord2f(1, 1); glVertex2i(0, itemHeight);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
//glDisable(GL_BLEND);
|
||||
|
||||
// Username
|
||||
glEnable(GL_BLEND);
|
||||
@ -331,7 +530,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted();
|
||||
PrintText(x, Height() - (Height() / 10.7), scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l ’ operateur << pour afficher la position
|
||||
ss << " Velocity : " << m_player.GetVelocity(); // IMPORTANT : on utilise l <EFBFBD> operateur << pour afficher la position
|
||||
PrintText(x, Height() / 48, scale, ss.str());
|
||||
ss.str("");
|
||||
ss << " Direction : " << m_player.GetDirection();
|
||||
@ -356,6 +555,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
@ -447,82 +647,80 @@ int Engine::GetCountdown(float elapsedTime) {
|
||||
}
|
||||
|
||||
void Engine::Render(float elapsedTime) {
|
||||
//static float gameTime = elapsedTime;
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float pollTime = 0;
|
||||
static float bulletTime = 0;
|
||||
static BlockType bloc = 1;
|
||||
|
||||
if (elapsedTime > 0.1f) return;
|
||||
|
||||
//gameTime += elapsedTime;
|
||||
pollTime += elapsedTime;
|
||||
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
Vector3f vstep;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Transformations initiales
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
if (m_gamestate == GameState::PLAY)
|
||||
{
|
||||
HideCursor();
|
||||
CenterMouse(); //D<>placement de centermouse dans l'action de jouer
|
||||
|
||||
if (bulletTime > 0.f) bulletTime -= elapsedTime;
|
||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||
//static float gameTime = elapsedTime;
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float pollTime = 0;
|
||||
static float bulletTime = 0;
|
||||
static BlockType bloc = 1;
|
||||
|
||||
static bool leftright = false;
|
||||
if (pollTime >= .005f) {
|
||||
Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime);
|
||||
switch (snd) {
|
||||
case Player::Sound::STEP:
|
||||
if (leftright)
|
||||
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
|
||||
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
|
||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, .8f);
|
||||
leftright = !leftright;
|
||||
break;
|
||||
case Player::Sound::FALL:
|
||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, 1.f);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnées du joueur et
|
||||
// son vecteur de vélocité (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
}
|
||||
if (elapsedTime > 0.1f) return;
|
||||
|
||||
m_player.ApplyTransformation(all);
|
||||
//gameTime += elapsedTime;
|
||||
pollTime += elapsedTime;
|
||||
|
||||
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
|
||||
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
Vector3f vstep;
|
||||
|
||||
if (m_mouseWU) bloc++;
|
||||
else if (m_mouseWD) bloc--;
|
||||
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
|
||||
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST équipe l'arme.
|
||||
m_mouseWU = m_mouseWD = false;
|
||||
// Transformations initiales
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
if (m_mouseL) {
|
||||
if (bloc != BTYPE_LAST)
|
||||
m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
||||
else if (bulletTime <= 0.f) {
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||
if (!m_bullets[x]) {
|
||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
break;
|
||||
}
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
|
||||
m_bullets[0]->~Bullet();
|
||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
}
|
||||
bulletTime = .1f;
|
||||
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
|
||||
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
|
||||
glClearColor(.8f, .8f, .8f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
return;
|
||||
if (bulletTime > 0.f) bulletTime -= elapsedTime;
|
||||
if (bulletTime < 0.f) bulletTime = 0.f;
|
||||
|
||||
static bool leftright = false;
|
||||
if (pollTime >= .005f) {
|
||||
Player::Sound snd = m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime);
|
||||
switch (snd) {
|
||||
case Player::Sound::STEP:
|
||||
if (leftright)
|
||||
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
|
||||
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
|
||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), .8f);
|
||||
leftright = !leftright;
|
||||
break;
|
||||
case Player::Sound::FALL:
|
||||
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), 1.f);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<6E>es du joueur et
|
||||
// son vecteur de v<>locit<69> (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
}
|
||||
|
||||
m_player.ApplyTransformation(all);
|
||||
|
||||
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation
|
||||
// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
|
||||
|
||||
if (m_mouseWU) bloc++;
|
||||
else if (m_mouseWD) bloc--;
|
||||
if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1;
|
||||
else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST <20>quipe l'arme.
|
||||
m_mouseWU = m_mouseWD = false;
|
||||
|
||||
if (m_mouseL) {
|
||||
if (bloc != BTYPE_LAST)
|
||||
m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block);
|
||||
else if (bulletTime <= 0.f) {
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||
if (!m_bullets[x]) {
|
||||
m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
break;
|
||||
}
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<6D>re balle de l'array.
|
||||
m_bullets[0]->~Bullet();
|
||||
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_mouseR)
|
||||
@ -546,24 +744,32 @@ void Engine::Render(float elapsedTime) {
|
||||
}
|
||||
}
|
||||
|
||||
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
ProcessNotificationQueue();
|
||||
DrawHud(elapsedTime, bloc);
|
||||
ProcessNotificationQueue();
|
||||
DrawHud(elapsedTime, bloc);
|
||||
|
||||
static bool fell = false;
|
||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), 1.f);
|
||||
fell = true;
|
||||
}
|
||||
else if (m_player.GetPosition().y < -20.f) {
|
||||
m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
|
||||
fell = false;
|
||||
}
|
||||
|
||||
static bool fell = false;
|
||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
|
||||
fell = true;
|
||||
}
|
||||
else if (m_player.GetPosition().y < -20.f) {
|
||||
m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde.
|
||||
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) {
|
||||
@ -589,14 +795,15 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
}
|
||||
break;
|
||||
case 36: // ESC - Quitter
|
||||
Stop();
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
//Stop();
|
||||
break;
|
||||
case 57: // Space - Sauter
|
||||
if (!m_keySpace) {
|
||||
m_keySpace = true;
|
||||
}
|
||||
break;
|
||||
case 94: // F10 - Plein écran
|
||||
case 94: // F10 - Plein <EFBFBD>cran
|
||||
IsFullscreen() ? SetFullscreen(false) : SetFullscreen(true);
|
||||
//SetFullscreen(!IsFullscreen());
|
||||
break;
|
||||
@ -606,7 +813,7 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
break;
|
||||
case 10: // K - Debugging DisplayNotification()
|
||||
m_keyK = true;
|
||||
m_messageNotification = "notifications systeme peuvent être affiché";
|
||||
m_messageNotification = "notifications systeme peuvent <EFBFBD>tre affich<63>";
|
||||
break;
|
||||
case 11: // L - Debugging DisplayNotification()
|
||||
m_keyL = true;
|
||||
@ -676,7 +883,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
m_bullets[x] = new Bullet(m_player.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f,0.f,1.f));
|
||||
break;
|
||||
}
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array.
|
||||
else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la premi<EFBFBD>re balle de l'array.
|
||||
m_bullets[0]->~Bullet();
|
||||
m_bullets[0] = new Bullet(m_player.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f, 0.f, 1.f));
|
||||
}
|
||||
@ -711,35 +918,47 @@ void Engine::MouseMoveEvent(int x, int y) {
|
||||
m_player.TurnLeftRight(x - (Width() / 2));
|
||||
m_player.TurnTopBottom(y - (Height() / 2));
|
||||
|
||||
// Centrer la souris seulement si elle n'est pas déjà centrée
|
||||
// Il est nécessaire de faire la vérification pour éviter de tomber
|
||||
// dans une boucle infinie où l'appel à CenterMouse génère un
|
||||
// Centrer la souris seulement si elle n'est pas d<EFBFBD>j<EFBFBD> centr<74>e
|
||||
// Il est n<EFBFBD>cessaire de faire la v<>rification pour <20>viter de tomber
|
||||
// dans une boucle infinie o<EFBFBD> l'appel <20> CenterMouse g<>n<EFBFBD>re un
|
||||
// MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre
|
||||
// MouseMoveEvent, etc
|
||||
if (x == (Width() / 2) && y == (Height() / 2))
|
||||
return;
|
||||
|
||||
CenterMouse();
|
||||
}
|
||||
|
||||
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
switch (button) {
|
||||
case MOUSE_BUTTON_LEFT:
|
||||
m_mouseL = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_RIGHT:
|
||||
m_mouseR = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_MIDDLE:
|
||||
m_mouseC = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_WHEEL_UP:
|
||||
m_mouseWU = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_WHEEL_DOWN:
|
||||
m_mouseWD = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_NONE: break;
|
||||
m_mousemx = x;
|
||||
m_mousemy = y;
|
||||
|
||||
if (m_gamestate == GameState::PLAY)
|
||||
{
|
||||
switch (button) {
|
||||
case MOUSE_BUTTON_LEFT:
|
||||
m_mouseL = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_RIGHT:
|
||||
m_mouseR = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_MIDDLE:
|
||||
m_mouseC = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_WHEEL_UP:
|
||||
m_mouseWU = true;
|
||||
break;
|
||||
case MOUSE_BUTTON_WHEEL_DOWN:
|
||||
m_mouseWD = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ class Engine : public OpenglContext {
|
||||
public:
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
virtual void DrawMenu();
|
||||
virtual void Init();
|
||||
virtual void DeInit();
|
||||
virtual void LoadResource();
|
||||
@ -78,6 +79,15 @@ private:
|
||||
|
||||
Bullet* m_bullets[MAX_BULLETS];
|
||||
|
||||
//Menu
|
||||
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||
GameState m_gamestate = GameState::MAIN_MENU;
|
||||
Texture MenuTitleTexture;
|
||||
Texture MenuBGTexture;
|
||||
Texture MenuStartTexture;
|
||||
Texture MenuQuitTexture;
|
||||
Texture MenuOptionsTexture;
|
||||
|
||||
float m_scale;
|
||||
float m_time = 0;
|
||||
|
||||
@ -106,6 +116,9 @@ private:
|
||||
bool m_mouseC = false;
|
||||
bool m_mouseWU = false;
|
||||
bool m_mouseWD = false;
|
||||
//Pour trouver ou est la souris
|
||||
float m_mousemx = 0;
|
||||
float m_mousemy = 0;
|
||||
|
||||
std::string m_messageNotification = "";
|
||||
};
|
||||
|
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 |
@ -7,7 +7,7 @@ void main()
|
||||
texel = texture2D(tex,gl_TexCoord[0].st);
|
||||
|
||||
texel *= light;
|
||||
texel.a = 255;
|
||||
texel.a = 255.;
|
||||
gl_FragColor = texel;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user