diff --git a/README.md b/README.md new file mode 100644 index 0000000..89affff --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +Pixel Wars is a programming game where two minimalistic civilizations +will grow and try to annihilate each other to conquer the Pixel World. +But you don't have any real-time control over the action of your units. +To be victorious, you'll have to code their behaviour in C/C++, +and pray for a good result. + +This repository is the application project, it has severay dependencies : +Qt5 modules: core gui widgets opengl, glm, SparrowRenderer, and cmake for the compilation + +### How to Use it from the precompiled builds (not available yet) : +- download the latest build (insert links here) +- unzip it anywhere +- the PixelWars executable is located in the bin folder +- you can now code your own Dude's behavior or map generator by +placing in the respective "behaviors" and "generators" folder your compiled code +in the form of a shared library, you can find an example in each folder named hello.cpp, +containing the minimal code, the necessary includes, +and the command line needed to compile it. + +### How to Build it from sources : + +download and install git, cmake, Qt5, and a c++ compiler (gcc on Unix or MinGW on Windows) + +get all required repositories : +git clone https://git.epicsparrow.com/epicsparrow/CMakeTemplate.git +git clone https://git.epicsparrow.com/epicsparrow/SparrowRenderer.git +git clone https://git.epicsparrow.com/epicsparrow/PixelWars.git + +get all required dependencies, +unzip this archive where you cloned the repositories : +https://epicsparrow.com/media/libs/glm.zip + +you can now compile the sparrow renderer : +- go in the SparrowRenderer folder +- mkdir build +- cd build +- cmake .. +- make + +after that, you'll be able to compile PixelWars : +(same procedure) +- go in the PixelWars folder +- mkdir build +- cd build +- cmake .. +- make + +That's it ! The PixelWars executable should have been generated in the build folder diff --git a/teams/hello.cpp b/behaviors/hello.cpp similarity index 100% rename from teams/hello.cpp rename to behaviors/hello.cpp diff --git a/behaviors/hello.dll b/behaviors/hello.dll new file mode 100644 index 0000000..d3f0b3a Binary files /dev/null and b/behaviors/hello.dll differ diff --git a/behaviors/hello1.dll b/behaviors/hello1.dll new file mode 100644 index 0000000..d3f0b3a Binary files /dev/null and b/behaviors/hello1.dll differ diff --git a/behaviors/hello2.dll b/behaviors/hello2.dll new file mode 100644 index 0000000..d3f0b3a Binary files /dev/null and b/behaviors/hello2.dll differ diff --git a/shaders/pixel.vert.glsl b/shaders/pixel.vert.glsl index 79b97b0..39dfd04 100644 --- a/shaders/pixel.vert.glsl +++ b/shaders/pixel.vert.glsl @@ -10,5 +10,5 @@ out vec3 color; void main(void) { color = inColor; - gl_Position = vec4(inTexPosition.x*texRatio.x -1, inTexPosition.y*texRatio.y -1, 0.0, 1.0); + gl_Position = vec4(inTexPosition*texRatio -1, 0.0, 1.0); } diff --git a/shaders/world.frag.glsl b/shaders/world.frag.glsl index aeea090..84b6ef7 100644 --- a/shaders/world.frag.glsl +++ b/shaders/world.frag.glsl @@ -21,6 +21,7 @@ vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 n void main() { + // looping the world in the shape of a toreiller (infinite flat surface) vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize.y; ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize)); if(abs(mod(nbRevolutions.y, 2)) > 0.5) @@ -29,8 +30,9 @@ void main() nbRevolutions.x = int(floor(worldCoord.x / worldSize.x)); } worldCoord = worldCoord - nbRevolutions*worldSize; - vec3 texColor = texelFetch(colorMap, ivec2(worldCoord)-1).xyz; + vec3 texColor = texelFetch(colorMap, ivec2(worldCoord)).xyz; + // computing lighting vec3 lighting = phongLighting(texColor, vec3(0.5), 50, vec3(1), normalize(normal), lightDir, normalize(lightDir+vec3(0, 0, -1))); outColor = vec4(texColor*0.2 + 0.8*lighting, 1.0); } diff --git a/src/simulationdialog.cpp b/src/simulationdialog.cpp index e7f5571..aef131d 100644 --- a/src/simulationdialog.cpp +++ b/src/simulationdialog.cpp @@ -16,17 +16,17 @@ SimulationDialog::SimulationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SimulationDialog), - m_map(NULL) + m_map(NULL), + m_availableGenerators(true) { ui->setupUi(this); connect(ui->behaviorsRefreshButton, SIGNAL(pressed()), this, SLOT(refreshBehaviors())); connect(ui->generatorsRefreshButton, SIGNAL(pressed()), this, SLOT(refreshGenerators())); connect(ui->generateButton, SIGNAL(pressed()), this, SLOT(generateMap())); connect(ui->behaviorsList, SIGNAL(clicked(QModelIndex)), this, SLOT(selectBehavior(QModelIndex))); + updatePreview(); refreshBehaviors(); refreshGenerators(); - ui->generatorsList->setCurrentRow(0); - updatePreview(); } SimulationDialog::~SimulationDialog() @@ -48,7 +48,7 @@ void SimulationDialog::refreshBehaviors() m_selectedBehaviors.clear(); ui->selectedBehaviors->clear(); QDir teamDir(QCoreApplication::applicationDirPath()); - if(teamDir.cd("../teams")) + if(teamDir.cd("../behaviors")) { for(const QFileInfo &info : teamDir.entryInfoList()) { @@ -100,15 +100,17 @@ void SimulationDialog::refreshGenerators() } else emit sendError(QString("ERROR : can't open the generators folder.\n"), 5000); - if(!m_genList.empty()) - ui->generatorsList->item(0)->setSelected(true); + bool canGenerate = !m_genList.empty(); + if(canGenerate) + { + ui->generatorsList->setCurrentRow(0); + generateMap(); + } + ui->generateButton->setEnabled(canGenerate); } void SimulationDialog::generateMap() { - if(m_map != NULL) - delete m_map; - m_map = NULL; QString path = m_genList[ui->generatorsList->currentRow()]; QLibrary lib(path); if(lib.load()) @@ -116,6 +118,9 @@ void SimulationDialog::generateMap() GenerateFunction func = (GenerateFunction)lib.resolve("generate"); if(func) { + if(m_map != NULL) + delete m_map; + m_map = NULL; m_map = new MapScene(m_selectedBehaviors.size(), ui->mapSizeSpinBox->value()); func((Map*)m_map); updatePreview(); diff --git a/src/simulationdialog.h b/src/simulationdialog.h index 058e7e0..920b77a 100644 --- a/src/simulationdialog.h +++ b/src/simulationdialog.h @@ -41,6 +41,7 @@ private: std::vector m_selectedBehaviors; MapScene *m_map; QLibrary *m_currentGeneratorLib; + bool m_availableGenerators; signals: void sendError(QString, int);