other fixes
This commit is contained in:
+6
-4
@@ -1,10 +1,12 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
- [Demo] Game fadein
|
- [Demo] Enemy running and rotating to player
|
||||||
- [Demo] Running soldier
|
- [Demo] Crosshair
|
||||||
- [Demo] Heightmap for soldier
|
|
||||||
- [Demo] Running animation for soldier
|
|
||||||
- [Demo] 2D Health bar
|
- [Demo] 2D Health bar
|
||||||
|
- [Demo] Change enemy to monster
|
||||||
|
- [Demo] More monsters!
|
||||||
|
- [Demo] Add ship and other reality stuff
|
||||||
|
- [Demo] Game fadein
|
||||||
- [General] USB test
|
- [General] USB test
|
||||||
- [General] CI in Github via docker image
|
- [General] CI in Github via docker image
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <renderer/3d/mesh/dynamic/dynamic_mesh.hpp>
|
#include <renderer/3d/mesh/dynamic/dynamic_mesh.hpp>
|
||||||
#include <renderer/3d/pipeline/dynamic/dynpip_options.hpp>
|
#include <renderer/3d/pipeline/dynamic/dynpip_options.hpp>
|
||||||
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
||||||
|
#include "states/game/terrain/heightmap.hpp"
|
||||||
#include <renderer/renderer.hpp>
|
#include <renderer/renderer.hpp>
|
||||||
|
|
||||||
using Tyra::DynamicMesh;
|
using Tyra::DynamicMesh;
|
||||||
@@ -28,14 +29,14 @@ class Enemy {
|
|||||||
Enemy(TextureRepository* repo);
|
Enemy(TextureRepository* repo);
|
||||||
~Enemy();
|
~Enemy();
|
||||||
|
|
||||||
DynamicMesh* bodyMesh;
|
DynamicMesh* mesh;
|
||||||
DynamicMesh* gunMesh;
|
|
||||||
DynPipOptions* options;
|
DynPipOptions* options;
|
||||||
std::vector<RendererDynamicPair*> pairs;
|
RendererDynamicPair* pair;
|
||||||
|
|
||||||
void update(const Vec4& playerPosition);
|
void update(const Heightmap& heightmap, const Vec4& playerPosition);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Vec4 direction;
|
||||||
void allocateOptions();
|
void allocateOptions();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ class Heightmap {
|
|||||||
const Vec4& rightDown);
|
const Vec4& rightDown);
|
||||||
~Heightmap();
|
~Heightmap();
|
||||||
|
|
||||||
const float& getHeightOffset(const Vec4& playerPosition);
|
const float& getHeightOffset(const Vec4& playerPosition) const;
|
||||||
|
|
||||||
|
bool isOutside(const Vec4& position) const;
|
||||||
|
|
||||||
float** map;
|
float** map;
|
||||||
s16 mapWidth, mapHeight;
|
s16 mapWidth, mapHeight;
|
||||||
@@ -31,12 +33,12 @@ class Heightmap {
|
|||||||
Vec4 leftUp, rightDown;
|
Vec4 leftUp, rightDown;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float getWidthPercentage(const Vec4& playerPosition);
|
float getWidthPercentage(const Vec4& playerPosition) const;
|
||||||
float getHeightPercentage(const Vec4& playerPosition);
|
float getHeightPercentage(const Vec4& playerPosition) const;
|
||||||
void allocateMap(const unsigned char* data, const int& width,
|
void allocateMap(const unsigned char* data, const int& width,
|
||||||
const int& height);
|
const int& height);
|
||||||
float getGameHeight(const u8& inputColor, const u8& minColor,
|
float getGameHeight(const u8& inputColor, const u8& minColor,
|
||||||
const u8& maxColor);
|
const u8& maxColor) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Demo
|
} // namespace Demo
|
||||||
|
|||||||
@@ -19,45 +19,55 @@ using Tyra::ObjLoaderOptions;
|
|||||||
namespace Demo {
|
namespace Demo {
|
||||||
|
|
||||||
Enemy::Enemy(TextureRepository* repo) {
|
Enemy::Enemy(TextureRepository* repo) {
|
||||||
// ObjLoader loader;
|
ObjLoader loader;
|
||||||
|
|
||||||
// ObjLoaderOptions objOptions;
|
ObjLoaderOptions objOptions;
|
||||||
// objOptions.animation.count = 4;
|
objOptions.animation.count = 4;
|
||||||
// objOptions.flipUVs = true;
|
objOptions.flipUVs = true;
|
||||||
// objOptions.scale = 35.0F;
|
objOptions.scale = 60.0F;
|
||||||
|
|
||||||
// auto* bodyData = loader.load(
|
auto* data = loader.load(
|
||||||
// FileUtils::fromCwd("game/models/soldier/soldier.obj"), objOptions);
|
FileUtils::fromCwd("game/models/soldier/soldier.obj"), objOptions);
|
||||||
// bodyData->normalsEnabled = false;
|
data->normalsEnabled = false;
|
||||||
// bodyMesh = new DynamicMesh(*bodyData);
|
mesh = new DynamicMesh(*data);
|
||||||
|
|
||||||
// delete bodyData;
|
delete data;
|
||||||
|
|
||||||
// bodyMesh->playAnimation(0, bodyMesh->frames.size() - 1);
|
mesh->playAnimation(0, mesh->frames.size() - 1);
|
||||||
// bodyMesh->setAnimSpeed(0.1F);
|
mesh->setAnimSpeed(0.1F);
|
||||||
|
|
||||||
// repo->addByMesh(bodyMesh, FileUtils::fromCwd("game/models/soldier/"),
|
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/soldier/"), "png");
|
||||||
// "png");
|
|
||||||
|
|
||||||
// bodyMesh->translation.translateY(-5.0F);
|
mesh->translation.translateY(-5.0F);
|
||||||
|
|
||||||
// allocateOptions();
|
allocateOptions();
|
||||||
|
|
||||||
// pairs.push_back(new RendererDynamicPair{bodyMesh, options});
|
pair = new RendererDynamicPair{mesh, options};
|
||||||
// // pairs.push_back(new RendererDynamicPair{gunMesh, options});
|
|
||||||
|
direction = Vec4(1.0F, 0.0F, 1.0F, 0.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
Enemy::~Enemy() {
|
Enemy::~Enemy() {
|
||||||
delete bodyMesh;
|
delete mesh;
|
||||||
// delete gunMesh;
|
|
||||||
delete options;
|
delete options;
|
||||||
for (auto* pair : pairs) {
|
|
||||||
delete pair;
|
delete pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition) {
|
||||||
|
auto* pos = mesh->getPosition();
|
||||||
|
auto nextPos = *pos + direction;
|
||||||
|
|
||||||
|
if (heightmap.isOutside(nextPos)) {
|
||||||
|
direction.x = -direction.x;
|
||||||
|
direction.z = -direction.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::update(const Vec4& playerPosition) {
|
nextPos = *pos + direction;
|
||||||
// bodyMesh->animate();
|
nextPos.y = heightmap.getHeightOffset(nextPos) - 150.0F;
|
||||||
|
mesh->translation.identity();
|
||||||
|
mesh->translation.translate(nextPos);
|
||||||
|
|
||||||
|
mesh->animate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::allocateOptions() { options = new DynPipOptions(); }
|
void Enemy::allocateOptions() { options = new DynPipOptions(); }
|
||||||
|
|||||||
@@ -69,17 +69,16 @@ void GameState::update() {
|
|||||||
engine->renderer.beginFrame(cameraInfo);
|
engine->renderer.beginFrame(cameraInfo);
|
||||||
|
|
||||||
dbgObj->setPosition(*cameraInfo.looksAt);
|
dbgObj->setPosition(*cameraInfo.looksAt);
|
||||||
float terrainHeight = 0.0F;
|
float terrainHeight = terrain->getHeightOffset(player->getPosition());
|
||||||
// float terrainHeight = terrain->getHeightOffset(player->getPosition());
|
|
||||||
player->update(terrainHeight);
|
player->update(terrainHeight);
|
||||||
enemy->update(player->getPosition());
|
enemy->update(terrain->heightmap, player->getPosition());
|
||||||
|
|
||||||
renderer.clear();
|
renderer.clear();
|
||||||
{
|
{
|
||||||
renderer.add(skybox->pair);
|
renderer.add(skybox->pair);
|
||||||
renderer.add(player->pair);
|
renderer.add(player->pair);
|
||||||
// renderer.add(enemy->pairs);
|
renderer.add(enemy->pair);
|
||||||
// renderer.add(terrain->pair);
|
renderer.add(terrain->pair);
|
||||||
renderer.add(dbgObj->pair);
|
renderer.add(dbgObj->pair);
|
||||||
}
|
}
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void Player::handlePlayerPosition(const float& terrainHeight) {
|
|||||||
normalizedCamera *= speed;
|
normalizedCamera *= speed;
|
||||||
|
|
||||||
Vec4 nextPosition(position);
|
Vec4 nextPosition(position);
|
||||||
nextPosition.y = terrainHeight - 100.0F;
|
nextPosition.y = terrainHeight - 60.0F;
|
||||||
|
|
||||||
if (leftJoy.v <= 100) {
|
if (leftJoy.v <= 100) {
|
||||||
nextPosition.x += normalizedCamera.x;
|
nextPosition.x += normalizedCamera.x;
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ Heightmap::Heightmap(const float& t_minHeight, const float& t_maxHeight,
|
|||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Heightmap::isOutside(const Vec4& position) const {
|
||||||
|
return position.x <= leftUp.x || position.x >= rightDown.x ||
|
||||||
|
position.z <= leftUp.z || position.z >= rightDown.z;
|
||||||
|
}
|
||||||
|
|
||||||
Heightmap::~Heightmap() {
|
Heightmap::~Heightmap() {
|
||||||
if (map) {
|
if (map) {
|
||||||
for (int i = 0; i < mapHeight; i++) {
|
for (int i = 0; i < mapHeight; i++) {
|
||||||
@@ -43,7 +48,7 @@ Heightmap::~Heightmap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const float& Heightmap::getHeightOffset(const Vec4& playerPosition) {
|
const float& Heightmap::getHeightOffset(const Vec4& playerPosition) const {
|
||||||
float widthPercentage = getWidthPercentage(playerPosition);
|
float widthPercentage = getWidthPercentage(playerPosition);
|
||||||
float heightPercentage = getHeightPercentage(playerPosition);
|
float heightPercentage = getHeightPercentage(playerPosition);
|
||||||
|
|
||||||
@@ -56,11 +61,11 @@ const float& Heightmap::getHeightOffset(const Vec4& playerPosition) {
|
|||||||
return map[x][y];
|
return map[x][y];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Heightmap::getWidthPercentage(const Vec4& playerPosition) {
|
float Heightmap::getWidthPercentage(const Vec4& playerPosition) const {
|
||||||
return (playerPosition.x - leftUp.x) / (rightDown.x - leftUp.x);
|
return (playerPosition.x - leftUp.x) / (rightDown.x - leftUp.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Heightmap::getHeightPercentage(const Vec4& playerPosition) {
|
float Heightmap::getHeightPercentage(const Vec4& playerPosition) const {
|
||||||
return (playerPosition.z - leftUp.z) / (rightDown.z - leftUp.z);
|
return (playerPosition.z - leftUp.z) / (rightDown.z - leftUp.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +105,7 @@ void Heightmap::allocateMap(const unsigned char* data, const int& width,
|
|||||||
}
|
}
|
||||||
|
|
||||||
float Heightmap::getGameHeight(const u8& inputColor, const u8& minColor,
|
float Heightmap::getGameHeight(const u8& inputColor, const u8& minColor,
|
||||||
const u8& maxColor) {
|
const u8& maxColor) const {
|
||||||
const float mapRange = maxColor - minColor;
|
const float mapRange = maxColor - minColor;
|
||||||
const float gameRange = maxHeight - minHeight;
|
const float gameRange = maxHeight - minHeight;
|
||||||
|
|
||||||
|
|||||||
@@ -18,29 +18,29 @@ using Tyra::ObjLoaderOptions;
|
|||||||
|
|
||||||
namespace Demo {
|
namespace Demo {
|
||||||
Terrain::Terrain(TextureRepository* repo)
|
Terrain::Terrain(TextureRepository* repo)
|
||||||
: heightmap(-5.0F, // Min height
|
: heightmap(20.0F, // Min height
|
||||||
450.0F, // Max height
|
320.0F, // Max height
|
||||||
Vec4(-784.6F, 0.0F, -1648.0F, 1.0F), // Left up
|
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
||||||
Vec4(1144.0F, 0.0F, 1772.3F, 1.0F) // Right down
|
Vec4(920.0F, 0.0F, 1520.0F, 1.0F) // Right down
|
||||||
) {
|
) {
|
||||||
// ObjLoader loader;
|
ObjLoader loader;
|
||||||
|
|
||||||
// ObjLoaderOptions objOptions;
|
ObjLoaderOptions objOptions;
|
||||||
// objOptions.flipUVs = true;
|
objOptions.flipUVs = true;
|
||||||
// objOptions.scale = 100.0F;
|
objOptions.scale = 100.0F;
|
||||||
|
|
||||||
// auto* data = loader.load(
|
auto* data = loader.load(
|
||||||
// FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
||||||
// data->normalsEnabled = false;
|
data->normalsEnabled = false;
|
||||||
// mesh = new StaticMesh(*data);
|
mesh = new StaticMesh(*data);
|
||||||
|
|
||||||
// delete data;
|
delete data;
|
||||||
|
|
||||||
// repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
||||||
|
|
||||||
// allocateOptions();
|
allocateOptions();
|
||||||
|
|
||||||
// pair = new RendererStaticPair{mesh, options};
|
pair = new RendererStaticPair{mesh, options};
|
||||||
}
|
}
|
||||||
|
|
||||||
float Terrain::getHeightOffset(const Vec4& playerPosition) {
|
float Terrain::getHeightOffset(const Vec4& playerPosition) {
|
||||||
|
|||||||
Reference in New Issue
Block a user