added README, renamed teams in behaviors, fixed one of the joints graphical bug

This commit is contained in:
Anselme 2016-05-20 15:04:24 +02:00
parent 865b64ede0
commit a89b8ce142
9 changed files with 67 additions and 11 deletions

48
README.md Normal file
View File

@ -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

BIN
behaviors/hello.dll Normal file

Binary file not shown.

BIN
behaviors/hello1.dll Normal file

Binary file not shown.

BIN
behaviors/hello2.dll Normal file

Binary file not shown.

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();

View File

@ -41,6 +41,7 @@ private:
std::vector<BehaviorFunction> m_selectedBehaviors;
MapScene *m_map;
QLibrary *m_currentGeneratorLib;
bool m_availableGenerators;
signals:
void sendError(QString, int);