Refactor game into multiple files.

linux_template
sigonasr2 2 years ago
parent 89da6f65b1
commit 725853c0b2
  1. 0
      Faceball2030/Editor.cpp
  2. 11
      Faceball2030/Editor.h
  3. 3
      Faceball2030/Faceball2030.vcxproj
  4. 9
      Faceball2030/Faceball2030.vcxproj.filters
  5. 23
      Faceball2030/MapFormat.txt
  6. 0
      Faceball2030/assets/map/map1.map
  7. 1359
      Faceball2030/main.cpp
  8. 185
      Faceball2030/main.h

@ -0,0 +1,11 @@
#pragma once
#include "pixelGameEngine.h"
using namespace olc;
class Editor {
std::string filename;
vi2d MAP_SIZE;
void Update(float fElapsedTime) {
}
};

@ -127,9 +127,12 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Editor.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Editor.h" />
<ClInclude Include="main.h" />
<ClInclude Include="pixelGameEngine.h" /> <ClInclude Include="pixelGameEngine.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

@ -18,10 +18,19 @@
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Editor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="pixelGameEngine.h"> <ClInclude Include="pixelGameEngine.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Editor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="main.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,23 @@
Map Format:
Width
Height
Width*Height 16-bit values
16 bits
Dir
vv
0000 0000 0000 0000
^ ^ En ID^ ^^^^
| ^^^ NESW
| Wave 321
Blink
Armor
Speed
Shot
Camo
Stop
Shield
Map

File diff suppressed because it is too large Load Diff

@ -0,0 +1,185 @@
#pragma once
#include "pixelGameEngine.h"
using namespace olc;
const float PI = 3.14159f;
enum GAMEMODE {
GAME,
EDITOR
};
enum Direction {
NORTH = 1,
EAST = 2,
SOUTH = 4,
WEST = 8
};
struct vec2d
{
float u = 0;
float v = 0;
float w = 1;
};
struct vec3d
{
float x = 0;
float y = 0;
float z = 0;
float w = 1;
};
struct Triangle
{
vec3d p[3];
vec2d uv[3];
Pixel col;
Decal* tex;
};
struct MapSquare {
Decal* wallN = NULL;
Decal* wallE = NULL;
Decal* wallS = NULL;
Decal* wallW = NULL;
};
struct Mesh
{
std::vector<Triangle> tris;
Decal* texture = NULL;
Mesh() {}
Mesh(std::string filename, Decal* tex)
:texture(tex) {
LoadFromObjectFile(filename);
}
private:
void Parse(std::string str, int& v, int& uv) {
std::cout << str << "\n";
std::stringstream s(str.substr(0, str.find("/") + 1));
s >> v;
str.erase(0, str.find("/") + 1);
std::stringstream s2(str.substr(0, str.find("/") + 1));
s2 >> uv;
//std::cout<<" "<<v<<"/"<<uv<<"\n";
}
bool LoadFromObjectFile(std::string sFilename)
{
std::ifstream f(sFilename);
if (!f.is_open())
return false;
// Local cache of verts
std::vector<vec3d> verts;
std::vector<vec2d> uvs;
std::string data;
while (f.good()) {
f >> data;
if (data == "v") {
float x, y, z;
f >> x >> y >> z;
verts.push_back({ x,y,z });
std::cout << x << " " << y << " " << z << "\n";
}
else
if (data == "vt") {
float u, v;
f >> u >> v;
uvs.push_back({ u,1 - v });
std::cout << u << " " << v << "\n";
}
else
if (data == "f") {
//std::cout<<"face\n";
std::string t1, t2, t3;
f >> t1 >> t2 >> t3;
int v1, v2, v3, uv1, uv2, uv3;
Parse(t1, v1, uv1);
Parse(t2, v2, uv2);
Parse(t3, v3, uv3);
tris.push_back({ verts[v1 - 1],verts[v2 - 1],verts[v3 - 1],
uvs[uv1 - 1],uvs[uv2 - 1],uvs[uv3 - 1],WHITE });
}
}
return true;
}
};
struct Object {
Mesh mesh;
vf2d pos = { 0,0 };
float rot = 0;
};
struct mat4x4
{
float m[4][4] = { 0 };
};
class FaceBall : public PixelGameEngine
{
bool freeRoam = false;
public:
FaceBall()
{
sAppName = "3D Demo";
}
private:
Mesh mapMesh;
Decal* dot, * enemy_ShootMe_tex;
vi2d MAP_SIZE = { 10,10 };
std::vector<std::vector<MapSquare>>map;
std::vector<Object>objects;
GAMEMODE mode=GAMEMODE::GAME;
mat4x4 matProj;
vec3d vCamera = { 5,0.5,5 };
vec3d vLookDir;
float zOffset = 2;
float fTheta = 0;
float fYaw = 0;
float pitch = -PI / 6;
vec3d Matrix_MultiplyVector(mat4x4& m, vec3d& i);
mat4x4 Matrix_MakeIdentity();
mat4x4 Matrix_MakeRotationX(float fAngleRad);
mat4x4 Matrix_MakeRotationY(float fAngleRad);
mat4x4 Matrix_MakeRotationZ(float fAngleRad);
mat4x4 Matrix_MakeTranslation(float x, float y, float z);
mat4x4 Matrix_MakeProjection(float fFovDegrees, float fAspectRatio, float fNear, float fFar);
mat4x4 Matrix_MultiplyMatrix(mat4x4& m1, mat4x4& m2);
mat4x4 Matrix_PointAt(vec3d& pos, vec3d& target, vec3d& up);
mat4x4 Matrix_QuickInverse(mat4x4& m);
vec3d Vector_Add(vec3d& v1, vec3d& v2);
vec3d Vector_Sub(vec3d& v1, vec3d& v2);
vec3d Vector_Mul(vec3d& v1, float k);
vec3d Vector_Div(vec3d& v1, float k);
float Vector_DotProduct(vec3d& v1, vec3d& v2);
float Vector_Length(vec3d& v);
vec3d Vector_Normalise(vec3d& v);
vec3d Vector_CrossProduct(vec3d& v1, vec3d& v2);
vec3d Vector_IntersectPlane(vec3d& plane_p, vec3d& plane_n, vec3d& lineStart, vec3d& lineEnd, float& t);
int Triangle_ClipAgainstPlane(vec3d plane_p, vec3d plane_n, Triangle& in_tri, Triangle& out_tri1, Triangle& out_tri2);
void RenderWorld();
void HandleKeys(float fElapsedTime);
void AddWall(Direction dir, vi2d gridSquare);
bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override;
};
FaceBall* game;
Loading…
Cancel
Save