static game #1

This commit is contained in:
Sandro Sobczyński
2020-11-03 21:49:16 +01:00
parent 9e3ed74b45
commit 5399b1744f
18 changed files with 180 additions and 194 deletions
+17 -16
View File
@@ -14,7 +14,10 @@
// Constructors/Destructors
// ----
Floors::Floors() {}
const u8 FLOORS_COUNT = 64; // Temp change it also in floor_manager.hpp
Floors::Floors(const Engine &t_engine)
: engine(t_engine), floorManager(FLOORS_COUNT), camera(&engine.screen) {}
Floors::~Floors() {}
@@ -24,21 +27,18 @@ Floors::~Floors() {}
void Floors::onInit()
{
player = new Player();
camera = new Camera(&engine.screen);
engine.renderer->setCameraDefinitions(&camera->worldView, &camera->unitCirclePosition, camera->planes);
floorManager = new FloorManager(64); // Temp change it also in floor_manager.hpp
engine.renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
engine.audio.init(2);
engine.audio.addListener(floorManager);
engine.audio.addListener(&floorManager);
engine.audio.addListener(&lightManager);
engine.audio.loadSong("NF-CHILL.WAV");
engine.audio.play();
texRepo = engine.renderer->getTextureRepository();
texRepo->addByMesh("warrior/", player->mesh);
texRepo->addByMesh("floor/", *floorManager->meshes[0]);
for (size_t i = 1; i < floorManager->floorAmount; i++)
texRepo->getByMesh(floorManager->meshes[0]->getId(), floorManager->meshes[0]->getMaterial(0).getId())
->addLink(floorManager->meshes[i]->getId(), floorManager->meshes[i]->getMaterial(0).getId());
texRepo->addByMesh("warrior/", player.mesh);
texRepo->addByMesh("floor/", floorManager.floors[0].mesh);
for (u32 i = 1; i < floorManager.floorAmount; i++)
texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId())
->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId());
}
void Floors::onUpdate()
@@ -46,9 +46,10 @@ void Floors::onUpdate()
if (engine.pad.isCrossClicked)
printf("FPS:%f\n", engine.fps);
lightManager.update();
camera->update(engine.pad, player->mesh);
floorManager->update(*player);
player->update(engine.pad, *camera, *floorManager);
engine.renderer->draw(&player->mesh);
engine.renderer->drawByPath3(floorManager->meshes, floorManager->floorAmount, lightManager.bulbs, lightManager.bulbsCount);
camera.update(engine.pad, player.mesh);
floorManager.update(player);
player.update(engine.pad, camera, floorManager);
engine.renderer->draw(player.mesh);
for (u8 i = 0; i < FLOORS_COUNT; i++)
engine.renderer->drawByPath3(floorManager.floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount);
}
+4 -4
View File
@@ -24,7 +24,7 @@ class Floors : public Game
{
public:
Floors();
Floors(const Engine &t_engine);
~Floors();
void onInit();
@@ -35,9 +35,9 @@ public:
private:
TextureRepository *texRepo;
LightManager lightManager;
FloorManager *floorManager;
Player *player;
Camera *camera;
FloorManager floorManager;
Player player;
Camera camera;
};
#endif
+2 -2
View File
@@ -12,8 +12,8 @@
int main()
{
Floors game = Floors();
game.engine.setDefaultScreen();
Engine engine = Engine();
Floors game = Floors(engine);
game.engine.init(&game, 40000);
SleepThread();
return 0;
+7 -13
View File
@@ -33,7 +33,6 @@ FloorManager::FloorManager(int t_floorAmount)
FloorManager::~FloorManager()
{
delete[] spirals;
delete[] meshes;
}
// ----
@@ -78,17 +77,11 @@ void FloorManager::calcSpiral(int X, int Y)
void FloorManager::initFloors()
{
PRINT_LOG("Initializing floors");
meshes = new Mesh *[floorAmount];
meshes[0] = new Mesh();
meshes[0]->loadObj("floor/", "floor", 2.0F, false);
meshes[0]->shouldBeFrustumCulled = true;
meshes[0]->shouldBeLighted = true;
for (u8 i = 0; i < floorAmount; i++)
{
floors[i].init(meshes[0], spirals[i], i);
meshes[i] = &floors[i].mesh;
}
floors[0].mesh.loadObj("floor/", "floor", 2.0F, false);
floors[0].mesh.shouldBeFrustumCulled = true;
floors[0].mesh.shouldBeLighted = true;
for (u8 i = 1; i < floorAmount; i++)
floors[i].init(floors[0].mesh, spirals[i], i);
PRINT_LOG("Floors initialized!");
}
@@ -113,6 +106,7 @@ void FloorManager::update(Player &t_player)
/** Called by audio thread */
void FloorManager::onAudioTick()
{
printf("Hit!\n");
if (audioTick++ > 16)
{
if (audioMode == 0)
@@ -164,7 +158,7 @@ void FloorManager::onAudioTick()
{
for (u8 i = 0; i < floorAmount; i++)
{
if (i + 1 > floorAmount / (audioOffset + 1))
if (u8(i + 1) > floorAmount / (audioOffset + 1))
floors[i].isByAudioTriggered = true;
else
floors[i].isByAudioTriggered = false;
@@ -27,9 +27,8 @@ public:
FloorManager(int t_floorAmount);
~FloorManager();
Floor floors[64]; // Temp change it also in floors.cpp
int floorAmount;
u32 floorAmount;
void update(Player &t_player);
Mesh **meshes;
void onAudioTick();
private:
+2 -2
View File
@@ -36,10 +36,10 @@ Floor::~Floor() {}
* @param spiral Spiral position
* @param initOffset Number of floor (index)
*/
void Floor::init(Mesh *mother, Point &spiral, u8 &initOffset)
void Floor::init(const Mesh &mother, const Point &spiral, const u8 &initOffset)
{
this->mesh.position.set(0.00F, -10.00F, 0.00F);
this->mesh.loadFrom(*mother);
this->mesh.loadFrom(mother);
this->initOffset = initOffset;
this->animTimer = rand() % FLOOR_ANIMATION_LENGTH;
this->mesh.shouldBeLighted = true;
+1 -1
View File
@@ -29,7 +29,7 @@ public:
Floor();
~Floor();
void init(Mesh *mother, Point &spiral, u8 &initOffset);
void init(const Mesh &mother, const Point &spiral, const u8 &initOffset);
void animate(Player &player);
};
+2 -2
View File
@@ -80,7 +80,7 @@ void Player::updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager
this->isCollideFloor = 0;
Vector3 min = Vector3();
Vector3 max = Vector3();
for (int i = 0; i < floorManager.floorAmount; i++)
for (u32 i = 0; i < floorManager.floorAmount; i++)
{
getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max);
@@ -151,7 +151,7 @@ void Player::updateGravity(Pad &pad, FloorManager &floorManager)
this->velocity = this->lift;
this->isOnFloor = 0;
for (int i = 0; i < floorManager.floorAmount; i++)
for (u32 i = 0; i < floorManager.floorAmount; i++)
{
getMinMax(&floorManager.floors[i].mesh, &min, &max);
this->isOnFloor = this->mesh.position.isOnSquare(min, max);