static game #1
This commit is contained in:
+74
-86
@@ -16,7 +16,13 @@
|
||||
// Constructors/Destructors
|
||||
// ----
|
||||
|
||||
Ari::Ari() {}
|
||||
const u8 WATER_TILES_COUNT = 64;
|
||||
|
||||
Ari::Ari(const Engine &t_engine) : engine(t_engine), camera(&engine.screen)
|
||||
{
|
||||
waterFloors = new Mesh[WATER_TILES_COUNT];
|
||||
spirals = new Point[WATER_TILES_COUNT];
|
||||
}
|
||||
|
||||
Ari::~Ari() {}
|
||||
|
||||
@@ -24,13 +30,74 @@ Ari::~Ari() {}
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
// TEST START
|
||||
const u8 WATER_TILES_COUNT = 64;
|
||||
Mesh *island, *islandAddons, *skybox, *test;
|
||||
Mesh **waterFloors;
|
||||
Point *spirals;
|
||||
void Ari::onInit()
|
||||
{
|
||||
|
||||
void calcSpiral(int X, int Y)
|
||||
engine.renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
|
||||
engine.audio.init(0);
|
||||
engine.audio.setVolume(40);
|
||||
engine.audio.loadSong("MOV-CIRC.WAV");
|
||||
engine.audio.play();
|
||||
|
||||
texRepo = engine.renderer->getTextureRepository();
|
||||
|
||||
island.loadDff("sunnyisl/", "sunnyisl", 0.1F, false);
|
||||
island.rotation.x = -1.6F;
|
||||
island.position.set(0.0F, 10.0F, 20.0F);
|
||||
island.shouldBeBackfaceCulled = true;
|
||||
island.shouldBeFrustumCulled = false;
|
||||
|
||||
islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
|
||||
islandAddons.rotation.x = -1.6F;
|
||||
islandAddons.position.set(0.0F, 10.0F, 20.0F);
|
||||
|
||||
skybox.loadObj("skybox/", "skybox", 100.0F, false);
|
||||
skybox.shouldBeFrustumCulled = false;
|
||||
|
||||
waterFloors[0].loadObj("water/", "water", 5.0F, false);
|
||||
waterFloors[0].position.set(0.0F, 8.0F, 0.0F);
|
||||
texRepo->addByMesh("water/", waterFloors[0]);
|
||||
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||
{
|
||||
spirals[i].x = 1.0F;
|
||||
spirals[i].y = 2.0F;
|
||||
}
|
||||
u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT);
|
||||
calcSpiral(spiralOffset, spiralOffset);
|
||||
for (u8 i = 1; i < WATER_TILES_COUNT; i++)
|
||||
{
|
||||
waterFloors[i].loadFrom(waterFloors[0]);
|
||||
waterFloors[i].position.set(10.0F * spirals[i].x, 8.0F, 10.0F * spirals[i].y);
|
||||
texRepo->getByMesh(waterFloors[0].getId(), waterFloors[0].getMaterial(0).getId())
|
||||
->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId());
|
||||
}
|
||||
|
||||
texRepo->addByMesh("sunnyisl/", island);
|
||||
texRepo->addByMesh("sunnyisl/", islandAddons);
|
||||
texRepo->addByMesh("skybox/", skybox);
|
||||
texRepo->addByMesh("ari/", player.mesh);
|
||||
}
|
||||
|
||||
void Ari::initBulb()
|
||||
{
|
||||
bulb.intensity = 15;
|
||||
bulb.position.set(5.0F, 10.0F, 10.0F);
|
||||
}
|
||||
|
||||
void Ari::onUpdate()
|
||||
{
|
||||
if (engine.pad.isCrossClicked)
|
||||
printf("FPS:%f\n", engine.fps);
|
||||
camera.update(engine.pad, player.mesh);
|
||||
engine.renderer->draw(skybox);
|
||||
engine.renderer->draw(island);
|
||||
engine.renderer->draw(islandAddons);
|
||||
engine.renderer->draw(player.mesh);
|
||||
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||
engine.renderer->draw(waterFloors[i]);
|
||||
}
|
||||
|
||||
void Ari::calcSpiral(int X, int Y)
|
||||
{
|
||||
int x, y, dx;
|
||||
x = y = dx = 0;
|
||||
@@ -54,82 +121,3 @@ void calcSpiral(int X, int Y)
|
||||
y += dy;
|
||||
}
|
||||
}
|
||||
// TEST END
|
||||
|
||||
// TODO 1 - const & in parameters
|
||||
// TODO 2 - Destructor mesh
|
||||
|
||||
void Ari::onInit()
|
||||
{
|
||||
player = new Player();
|
||||
camera = new Camera(&engine.screen);
|
||||
engine.renderer->setCameraDefinitions(&camera->worldView, &camera->unitCirclePosition, camera->planes);
|
||||
engine.audio.init(0);
|
||||
engine.audio.setVolume(40);
|
||||
engine.audio.loadSong("MOV-CIRC.WAV");
|
||||
engine.audio.play();
|
||||
|
||||
texRepo = engine.renderer->getTextureRepository();
|
||||
|
||||
island = new Mesh();
|
||||
island->loadDff("sunnyisl/", "sunnyisl", 0.1F, false);
|
||||
island->rotation.x = -1.6F;
|
||||
island->position.set(0.0F, 10.0F, 20.0F);
|
||||
island->shouldBeBackfaceCulled = true;
|
||||
island->shouldBeFrustumCulled = false;
|
||||
|
||||
islandAddons = new Mesh();
|
||||
islandAddons->loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
|
||||
islandAddons->rotation.x = -1.6F;
|
||||
islandAddons->position.set(0.0F, 10.0F, 20.0F);
|
||||
|
||||
skybox = new Mesh();
|
||||
skybox->loadObj("skybox/", "skybox", 100.0F, false);
|
||||
skybox->shouldBeFrustumCulled = false;
|
||||
|
||||
waterFloors = new Mesh *[WATER_TILES_COUNT];
|
||||
spirals = new Point[WATER_TILES_COUNT];
|
||||
waterFloors[0] = new Mesh();
|
||||
waterFloors[0]->loadObj("water/", "water", 5.0F, false);
|
||||
waterFloors[0]->position.set(0.0F, 8.0F, 0.0F);
|
||||
texRepo->addByMesh("water/", *waterFloors[0]);
|
||||
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||
{
|
||||
spirals[i].x = 1.0F;
|
||||
spirals[i].y = 2.0F;
|
||||
}
|
||||
u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT);
|
||||
calcSpiral(spiralOffset, spiralOffset);
|
||||
for (u8 i = 1; i < WATER_TILES_COUNT; i++)
|
||||
{
|
||||
waterFloors[i] = new Mesh();
|
||||
waterFloors[i]->loadFrom(*waterFloors[0]);
|
||||
waterFloors[i]->position.set(10.0F * spirals[i].x, 8.0F, 10.0F * spirals[i].y);
|
||||
texRepo->getByMesh(waterFloors[0]->getId(), waterFloors[0]->getMaterial(0).getId())
|
||||
->addLink(waterFloors[i]->getId(), waterFloors[i]->getMaterial(0).getId());
|
||||
}
|
||||
|
||||
texRepo->addByMesh("sunnyisl/", *island);
|
||||
texRepo->addByMesh("sunnyisl/", *islandAddons);
|
||||
texRepo->addByMesh("skybox/", *skybox);
|
||||
texRepo->addByMesh("ari/", player->mesh);
|
||||
}
|
||||
|
||||
void Ari::initBulb()
|
||||
{
|
||||
bulb.intensity = 15;
|
||||
bulb.position.set(5.0F, 10.0F, 10.0F);
|
||||
}
|
||||
|
||||
void Ari::onUpdate()
|
||||
{
|
||||
if (engine.pad.isCrossClicked)
|
||||
printf("FPS:%f\n", engine.fps);
|
||||
camera->update(engine.pad, player->mesh);
|
||||
engine.renderer->draw(skybox);
|
||||
engine.renderer->draw(island);
|
||||
engine.renderer->draw(islandAddons);
|
||||
engine.renderer->draw(&player->mesh);
|
||||
for (u8 i = 0; i < WATER_TILES_COUNT; i++)
|
||||
engine.renderer->draw(waterFloors[i]);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Ari : public Game
|
||||
{
|
||||
|
||||
public:
|
||||
Ari();
|
||||
Ari(const Engine &t_engine);
|
||||
~Ari();
|
||||
|
||||
void onInit();
|
||||
@@ -33,9 +33,13 @@ public:
|
||||
|
||||
private:
|
||||
void initBulb();
|
||||
void calcSpiral(int X, int Y);
|
||||
LightBulb bulb;
|
||||
Player *player;
|
||||
Camera *camera;
|
||||
Player player;
|
||||
Mesh island, islandAddons, skybox;
|
||||
Mesh *waterFloors;
|
||||
Point *spirals;
|
||||
Camera camera;
|
||||
TextureRepository *texRepo;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
Ari game = Ari();
|
||||
game.engine.setDefaultScreen();
|
||||
Engine engine = Engine();
|
||||
Ari game = Ari(engine);
|
||||
game.engine.init(&game, 40000);
|
||||
SleepThread();
|
||||
return 0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user