change enemy to monster
This commit is contained in:
+1
-1
@@ -1,8 +1,8 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
|
- [Demo] Animation table
|
||||||
- [Demo] Crosshair
|
- [Demo] Crosshair
|
||||||
- [Demo] 2D Health bar
|
- [Demo] 2D Health bar
|
||||||
- [Demo] Change enemy to monster
|
|
||||||
- [Demo] More monsters!
|
- [Demo] More monsters!
|
||||||
- [Demo] Add ship and other reality stuff
|
- [Demo] Add ship and other reality stuff
|
||||||
- [Demo] Game fadein
|
- [Demo] Game fadein
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
||||||
#include "states/game/renderer/renderer_static_pair.hpp"
|
#include "states/game/renderer/renderer_static_pair.hpp"
|
||||||
|
#include "states/game/terrain/heightmap.hpp"
|
||||||
#include "./weapon.hpp"
|
#include "./weapon.hpp"
|
||||||
#include "./camera.hpp"
|
#include "./camera.hpp"
|
||||||
#include <engine.hpp>
|
#include <engine.hpp>
|
||||||
@@ -32,10 +33,10 @@ class Player {
|
|||||||
|
|
||||||
RendererStaticPair* pair;
|
RendererStaticPair* pair;
|
||||||
|
|
||||||
void update(const float& terrainHeight);
|
void update(const Heightmap& heightmap);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handlePlayerPosition(const float& terrainHeight);
|
void handlePlayerPosition(const Heightmap& heightmap,const float& terrainHeight);
|
||||||
|
|
||||||
float speed;
|
float speed;
|
||||||
Pad* pad;
|
Pad* pad;
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ Enemy::Enemy(TextureRepository* repo) {
|
|||||||
ObjLoader loader;
|
ObjLoader loader;
|
||||||
|
|
||||||
ObjLoaderOptions objOptions;
|
ObjLoaderOptions objOptions;
|
||||||
objOptions.animation.count = 4;
|
objOptions.animation.count = 6;
|
||||||
objOptions.flipUVs = true;
|
objOptions.flipUVs = true;
|
||||||
objOptions.scale = 60.0F;
|
objOptions.scale = 250.0F;
|
||||||
|
|
||||||
auto* data = loader.load(
|
auto* data = loader.load(FileUtils::fromCwd("game/models/zombie/zombie.obj"),
|
||||||
FileUtils::fromCwd("game/models/soldier/soldier.obj"), objOptions);
|
objOptions);
|
||||||
data->normalsEnabled = false;
|
data->normalsEnabled = false;
|
||||||
mesh = new DynamicMesh(*data);
|
mesh = new DynamicMesh(*data);
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ Enemy::Enemy(TextureRepository* repo) {
|
|||||||
mesh->playAnimation(0, mesh->frames.size() - 1);
|
mesh->playAnimation(0, mesh->frames.size() - 1);
|
||||||
mesh->setAnimSpeed(0.1F);
|
mesh->setAnimSpeed(0.1F);
|
||||||
|
|
||||||
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/soldier/"), "png");
|
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/zombie/"), "png");
|
||||||
|
|
||||||
mesh->translation.translateY(-5.0F);
|
mesh->translation.translateY(-5.0F);
|
||||||
|
|
||||||
@@ -58,11 +58,11 @@ void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition) {
|
|||||||
auto diff = *enemyPosition - playerPosition;
|
auto diff = *enemyPosition - playerPosition;
|
||||||
auto ang = Math::atan2(diff.x, diff.z);
|
auto ang = Math::atan2(diff.x, diff.z);
|
||||||
|
|
||||||
if (diff.length() > 120.0F) {
|
if (diff.length() > 30.0F) {
|
||||||
diff.normalize();
|
diff.normalize();
|
||||||
const float speed = 1.5F;
|
const float speed = 1.5F;
|
||||||
auto nextPos = *enemyPosition - diff * speed;
|
auto nextPos = *enemyPosition - diff * speed;
|
||||||
nextPos.y = heightmap.getHeightOffset(nextPos) - 150.0F;
|
nextPos.y = heightmap.getHeightOffset(nextPos) - 60.0F;
|
||||||
|
|
||||||
mesh->translation.identity();
|
mesh->translation.identity();
|
||||||
mesh->translation.translate(nextPos);
|
mesh->translation.translate(nextPos);
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ void GameState::update() {
|
|||||||
engine->renderer.beginFrame(cameraInfo);
|
engine->renderer.beginFrame(cameraInfo);
|
||||||
|
|
||||||
dbgObj->setPosition(*cameraInfo.looksAt);
|
dbgObj->setPosition(*cameraInfo.looksAt);
|
||||||
float terrainHeight = terrain->getHeightOffset(player->getPosition());
|
|
||||||
player->update(terrainHeight);
|
player->update(terrain->heightmap);
|
||||||
enemy->update(terrain->heightmap, player->getPosition());
|
enemy->update(terrain->heightmap, player->getPosition());
|
||||||
|
|
||||||
renderer.clear();
|
renderer.clear();
|
||||||
@@ -78,7 +78,7 @@ void GameState::update() {
|
|||||||
renderer.add(skybox->pair);
|
renderer.add(skybox->pair);
|
||||||
renderer.add(player->pair);
|
renderer.add(player->pair);
|
||||||
renderer.add(enemy->pair);
|
renderer.add(enemy->pair);
|
||||||
// renderer.add(terrain->pair);
|
renderer.add(terrain->pair);
|
||||||
renderer.add(dbgObj->pair);
|
renderer.add(dbgObj->pair);
|
||||||
}
|
}
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|||||||
@@ -23,13 +23,16 @@ Player::Player(Engine* engine)
|
|||||||
|
|
||||||
Player::~Player() { delete pair; }
|
Player::~Player() { delete pair; }
|
||||||
|
|
||||||
void Player::update(const float& terrainHeight) {
|
void Player::update(const Heightmap& heightmap) {
|
||||||
handlePlayerPosition(terrainHeight);
|
float terrainHeight = heightmap.getHeightOffset(getPosition());
|
||||||
|
|
||||||
|
handlePlayerPosition(heightmap, terrainHeight);
|
||||||
camera.update(position, terrainHeight);
|
camera.update(position, terrainHeight);
|
||||||
weapon.update();
|
weapon.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::handlePlayerPosition(const float& terrainHeight) {
|
void Player::handlePlayerPosition(const Heightmap& heightmap,
|
||||||
|
const float& terrainHeight) {
|
||||||
const auto& leftJoy = pad->getLeftJoyPad();
|
const auto& leftJoy = pad->getLeftJoyPad();
|
||||||
|
|
||||||
auto normalizedCamera = Vec4(camera.unitCircle);
|
auto normalizedCamera = Vec4(camera.unitCircle);
|
||||||
@@ -37,7 +40,7 @@ void Player::handlePlayerPosition(const float& terrainHeight) {
|
|||||||
normalizedCamera *= speed;
|
normalizedCamera *= speed;
|
||||||
|
|
||||||
Vec4 nextPosition(position);
|
Vec4 nextPosition(position);
|
||||||
nextPosition.y = terrainHeight - 60.0F;
|
nextPosition.y = terrainHeight + 50.0F;
|
||||||
|
|
||||||
if (leftJoy.v <= 100) {
|
if (leftJoy.v <= 100) {
|
||||||
nextPosition.x += normalizedCamera.x;
|
nextPosition.x += normalizedCamera.x;
|
||||||
@@ -54,7 +57,7 @@ void Player::handlePlayerPosition(const float& terrainHeight) {
|
|||||||
nextPosition.z += normalizedCamera.x;
|
nextPosition.z += normalizedCamera.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
position = nextPosition;
|
if (!heightmap.isOutside(nextPosition)) position = nextPosition;
|
||||||
|
|
||||||
camera.position = position;
|
camera.position = position;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,29 +18,29 @@ using Tyra::ObjLoaderOptions;
|
|||||||
|
|
||||||
namespace Demo {
|
namespace Demo {
|
||||||
Terrain::Terrain(TextureRepository* repo)
|
Terrain::Terrain(TextureRepository* repo)
|
||||||
: heightmap(20.0F, // Min height
|
: heightmap(-70.0F, // Min height
|
||||||
320.0F, // Max height
|
240.0F, // Max height
|
||||||
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
||||||
Vec4(920.0F, 0.0F, 1520.0F, 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