small cleanup
This commit is contained in:
@@ -54,7 +54,6 @@ class Enemy {
|
||||
bool isFighting = false;
|
||||
Vec4 spawnPoint;
|
||||
|
||||
Renderer3DUtility* utility;
|
||||
Audio* audio;
|
||||
EnemyInfo info;
|
||||
};
|
||||
|
||||
@@ -42,7 +42,6 @@ class Player {
|
||||
private:
|
||||
void handlePlayerPosition(const Heightmap& heightmap,
|
||||
const float& terrainHeight);
|
||||
Renderer3DUtility* utility;
|
||||
|
||||
float speed;
|
||||
Pad* pad;
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
#include "states/game/enemy/enemy.hpp"
|
||||
#include <functional>
|
||||
|
||||
using Tyra::Color;
|
||||
using Tyra::Math;
|
||||
|
||||
namespace Demo {
|
||||
|
||||
Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) {
|
||||
info = t_info;
|
||||
utility = &engine->renderer.renderer3D.utility;
|
||||
|
||||
mesh = new DynamicMesh(*info.motherMesh);
|
||||
|
||||
@@ -87,20 +87,23 @@ void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition,
|
||||
}
|
||||
|
||||
void Enemy::handlePlayerShoot(const PlayerShootAction& shootAction) {
|
||||
if (!shootAction.isShooting) {
|
||||
return;
|
||||
}
|
||||
// if (!shootAction.isShooting) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
const auto& ray = shootAction.ray.value();
|
||||
|
||||
auto bbox =
|
||||
mesh->getCurrentBoundingBox().getTransformed(mesh->getModelMatrix());
|
||||
|
||||
auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max());
|
||||
float length = -1.0F;
|
||||
auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max(), &length);
|
||||
|
||||
if (isOnEnemy) {
|
||||
mesh->setPosition(spawnPoint);
|
||||
TYRA_LOG("Enemy hit!");
|
||||
} else {
|
||||
if (length != -1.0F) TYRA_LOG("Distance: ", length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ EnemyManager::EnemyManager(Engine* engine, const Heightmap& heightmap) {
|
||||
auto* sample = engine->audio.adpcm.load(
|
||||
FileUtils::fromCwd("game/models/zombie/punch.adpcm"));
|
||||
|
||||
const int enemyCount = 10;
|
||||
const int enemyCount = 1;
|
||||
for (int i = 0; i < enemyCount; i++) {
|
||||
EnemyInfo info;
|
||||
info.adpcmChannel = 9 + i;
|
||||
|
||||
@@ -85,6 +85,14 @@ void GameState::update() {
|
||||
renderer.add(terrain->pair);
|
||||
renderer.render();
|
||||
|
||||
// Debug
|
||||
auto& utility = engine->renderer.renderer3D.utility;
|
||||
utility.drawBox(*player->getCameraInfo().looksAt, 0.3F);
|
||||
|
||||
auto* firstEnemy = enemyManager->getPairs().front()->mesh;
|
||||
utility.drawBBox(firstEnemy->getCurrentBoundingBox().getTransformed(
|
||||
firstEnemy->getModelMatrix()));
|
||||
|
||||
// End frame
|
||||
engine->renderer.endFrame();
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ Player::Player(Engine* engine)
|
||||
position = Vec4(3.0F, 50.0F, 0.0F);
|
||||
camera.lookAt = Vec4(0.0F, 0.0F, -30.0F);
|
||||
speed = 5.0F;
|
||||
|
||||
utility = &engine->renderer.renderer3D.utility;
|
||||
}
|
||||
|
||||
Player::~Player() { delete pair; }
|
||||
@@ -37,14 +35,9 @@ PlayerShootAction Player::getShootAction() const {
|
||||
PlayerShootAction action;
|
||||
action.isShooting = weapon.isShooting;
|
||||
|
||||
if (action.isShooting) {
|
||||
action.ray = Ray(camera.position, camera.lookAt.getNormalized());
|
||||
}
|
||||
|
||||
utility->drawBox(camera.lookAt, 1.0F);
|
||||
|
||||
// utility->drawLine(ray.origin, ray.direction);
|
||||
utility->drawLine(camera.position + Vec4(0.0F, 1.0F, 0.0F), camera.lookAt);
|
||||
// if (action.isShooting) {
|
||||
action.ray = Ray(camera.position, camera.lookAt.getNormalized());
|
||||
// }
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user