add basic shoot on enemy
This commit is contained in:
+4
-2
@@ -1,5 +1,9 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
|
- [Renderer] utility functions
|
||||||
|
- [Renderer] drawLine()
|
||||||
|
- [Renderer] drawBBox()
|
||||||
|
- [Renderer] drawPoint()
|
||||||
- [Demo] Red screen on hit
|
- [Demo] Red screen on hit
|
||||||
- [Demo] Count of killed zombies
|
- [Demo] Count of killed zombies
|
||||||
- [Demo] Crosshair
|
- [Demo] Crosshair
|
||||||
@@ -36,9 +40,7 @@ because Mesh rendering uses only core.render()
|
|||||||
- [renderer] fog
|
- [renderer] fog
|
||||||
- [renderer] bbox parts optimization
|
- [renderer] bbox parts optimization
|
||||||
- [md2] refactor
|
- [md2] refactor
|
||||||
- [3D] Add drawLine(x, y , color, size)
|
|
||||||
- [2D] Fixed font support
|
- [2D] Fixed font support
|
||||||
- [3D] Add drawBBox(x, y , color, size)
|
|
||||||
- [File] Async file loading
|
- [File] Async file loading
|
||||||
- [obj] Add multicolor support to obj
|
- [obj] Add multicolor support to obj
|
||||||
- [Obj] Improve obj importing for multiple usemtl with same names
|
- [Obj] Improve obj importing for multiple usemtl with same names
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <tyra>
|
#include <tyra>
|
||||||
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
||||||
#include "states/game/terrain/heightmap.hpp"
|
#include "states/game/terrain/heightmap.hpp"
|
||||||
|
#include "states/game/player/player_shoot_action.hpp"
|
||||||
#include "./enemy_info.hpp"
|
#include "./enemy_info.hpp"
|
||||||
|
|
||||||
using Tyra::AnimationSequenceCallback;
|
using Tyra::AnimationSequenceCallback;
|
||||||
@@ -35,7 +36,8 @@ class Enemy {
|
|||||||
DynPipOptions* options;
|
DynPipOptions* options;
|
||||||
RendererDynamicPair* pair;
|
RendererDynamicPair* pair;
|
||||||
|
|
||||||
void update(const Heightmap& heightmap, const Vec4& playerPosition);
|
void update(const Heightmap& heightmap, const Vec4& playerPosition,
|
||||||
|
const PlayerShootAction& shootAction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<u32> walkSequence;
|
std::vector<u32> walkSequence;
|
||||||
@@ -45,9 +47,11 @@ class Enemy {
|
|||||||
void walk(const Heightmap& heightmap, const Vec4& positionDiff);
|
void walk(const Heightmap& heightmap, const Vec4& positionDiff);
|
||||||
void animationCallback(const AnimationSequenceCallback& callback);
|
void animationCallback(const AnimationSequenceCallback& callback);
|
||||||
void fight();
|
void fight();
|
||||||
|
void handlePlayerShoot(const PlayerShootAction& shootAction);
|
||||||
|
|
||||||
bool isWalking = true;
|
bool isWalking = true;
|
||||||
bool isFighting = false;
|
bool isFighting = false;
|
||||||
|
Vec4 spawnPoint;
|
||||||
|
|
||||||
Audio* audio;
|
Audio* audio;
|
||||||
EnemyInfo info;
|
EnemyInfo info;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <tyra>
|
#include <tyra>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "states/game/terrain/heightmap.hpp"
|
#include "states/game/terrain/heightmap.hpp"
|
||||||
|
#include "states/game/player/player_shoot_action.hpp"
|
||||||
#include "./enemy.hpp"
|
#include "./enemy.hpp"
|
||||||
|
|
||||||
using Tyra::DynamicMesh;
|
using Tyra::DynamicMesh;
|
||||||
@@ -28,7 +29,8 @@ class EnemyManager {
|
|||||||
EnemyManager(Engine* engine, const Heightmap& heightmap);
|
EnemyManager(Engine* engine, const Heightmap& heightmap);
|
||||||
~EnemyManager();
|
~EnemyManager();
|
||||||
|
|
||||||
void update(const Heightmap& heightmap, const Vec4& playerPosition);
|
void update(const Heightmap& heightmap, const Vec4& playerPosition,
|
||||||
|
const PlayerShootAction& shootAction);
|
||||||
|
|
||||||
std::vector<RendererDynamicPair*> getPairs() const;
|
std::vector<RendererDynamicPair*> getPairs() const;
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) {
|
|||||||
walkSequence = {0, 1, 2};
|
walkSequence = {0, 1, 2};
|
||||||
fightSequence = {3, 4, 5};
|
fightSequence = {3, 4, 5};
|
||||||
|
|
||||||
|
spawnPoint = info.spawnPoint;
|
||||||
mesh->setPosition(info.spawnPoint);
|
mesh->setPosition(info.spawnPoint);
|
||||||
|
|
||||||
mesh->animation.setSequence(walkSequence);
|
mesh->animation.setSequence(walkSequence);
|
||||||
@@ -61,9 +62,12 @@ Enemy::~Enemy() {
|
|||||||
delete pair;
|
delete pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition) {
|
void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition,
|
||||||
|
const PlayerShootAction& shootAction) {
|
||||||
auto* enemyPosition = mesh->getPosition();
|
auto* enemyPosition = mesh->getPosition();
|
||||||
|
|
||||||
|
handlePlayerShoot(shootAction);
|
||||||
|
|
||||||
auto diff = *enemyPosition - playerPosition;
|
auto diff = *enemyPosition - playerPosition;
|
||||||
auto ang = Math::atan2(diff.x, diff.z);
|
auto ang = Math::atan2(diff.x, diff.z);
|
||||||
|
|
||||||
@@ -81,6 +85,23 @@ void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition) {
|
|||||||
mesh->update();
|
mesh->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Enemy::handlePlayerShoot(const PlayerShootAction& shootAction) {
|
||||||
|
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());
|
||||||
|
|
||||||
|
if (isOnEnemy) {
|
||||||
|
mesh->setPosition(spawnPoint);
|
||||||
|
TYRA_LOG("Enemy hit!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Enemy::walk(const Heightmap& heightmap, const Vec4& positionDiff) {
|
void Enemy::walk(const Heightmap& heightmap, const Vec4& positionDiff) {
|
||||||
if (isFighting) {
|
if (isFighting) {
|
||||||
mesh->animation.setSequence(walkSequence);
|
mesh->animation.setSequence(walkSequence);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ EnemyManager::EnemyManager(Engine* engine, const Heightmap& heightmap) {
|
|||||||
auto* sample = engine->audio.adpcm.load(
|
auto* sample = engine->audio.adpcm.load(
|
||||||
FileUtils::fromCwd("game/models/zombie/punch.adpcm"));
|
FileUtils::fromCwd("game/models/zombie/punch.adpcm"));
|
||||||
|
|
||||||
const int enemyCount = 10;
|
const int enemyCount = 2;
|
||||||
for (int i = 0; i < enemyCount; i++) {
|
for (int i = 0; i < enemyCount; i++) {
|
||||||
EnemyInfo info;
|
EnemyInfo info;
|
||||||
info.adpcmChannel = 9 + i;
|
info.adpcmChannel = 9 + i;
|
||||||
@@ -80,9 +80,10 @@ std::vector<RendererDynamicPair*> EnemyManager::getPairs() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EnemyManager::update(const Heightmap& heightmap,
|
void EnemyManager::update(const Heightmap& heightmap,
|
||||||
const Vec4& playerPosition) {
|
const Vec4& playerPosition,
|
||||||
|
const PlayerShootAction& shootAction) {
|
||||||
for (auto* enemy : enemies) {
|
for (auto* enemy : enemies) {
|
||||||
enemy->update(heightmap, playerPosition);
|
enemy->update(heightmap, playerPosition, shootAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,12 +67,8 @@ void GameState::update() {
|
|||||||
|
|
||||||
skybox->update(player->getPosition());
|
skybox->update(player->getPosition());
|
||||||
player->update(terrain->heightmap);
|
player->update(terrain->heightmap);
|
||||||
enemyManager->update(terrain->heightmap, player->getPosition());
|
|
||||||
|
|
||||||
auto shootAction = player->getShootAction();
|
auto shootAction = player->getShootAction();
|
||||||
if (shootAction.isShooting) {
|
enemyManager->update(terrain->heightmap, player->getPosition(), shootAction);
|
||||||
shootAction.ray.value().print();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto cameraInfo = player->getCameraInfo();
|
auto cameraInfo = player->getCameraInfo();
|
||||||
dbgObj->setPosition(*cameraInfo.looksAt);
|
dbgObj->setPosition(*cameraInfo.looksAt);
|
||||||
|
|||||||
Reference in New Issue
Block a user