-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start on implementing AI (and zombie stuff)
- Loading branch information
1 parent
cbb9f04
commit a64d9fc
Showing
14 changed files
with
244 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "AI.h" | ||
#include "../../WorldManager.h" | ||
|
||
glm::vec3 AI::GenerateRandomPosition(float distance) | ||
{ | ||
// get a random position within a distance from the current position | ||
|
||
// get a random angle | ||
|
||
float angle = (rand() % 360) * 3.14159 / 180; | ||
|
||
// get a random distance | ||
|
||
float dist = (rand() % (int)distance) + 1; | ||
|
||
// calculate the new position | ||
|
||
glm::vec3 newPos = glm::vec3(position.x + cos(angle) * dist, position.y, position.z + sin(angle) * dist); | ||
|
||
Chunk* c = WorldManager::instance->GetChunk(newPos.x, newPos.z); | ||
|
||
if (c == nullptr) | ||
return glm::vec3(); | ||
|
||
// get the lowest block from our position | ||
|
||
for (int y = (int)newPos.y; y > -1; y--) | ||
{ | ||
if (c->GetBlock(newPos.x, y, newPos.z) > 0) | ||
{ | ||
newPos.y = y + 1; | ||
break; | ||
} | ||
} | ||
|
||
return newPos; | ||
} | ||
|
||
void AI::MoveTo(glm::vec3 pos) | ||
{ | ||
target = pos; | ||
|
||
// get the path to the target | ||
|
||
|
||
} | ||
|
||
void AI::MoveToRandom() | ||
{ | ||
glm::vec3 r = GenerateRandomPosition(10); | ||
if (std::abs(r.y - position.y) > 4) | ||
return; | ||
|
||
MoveTo(r); | ||
} | ||
|
||
void AI::Draw() | ||
{ | ||
// move to target if we have one | ||
|
||
float distance = glm::distance(position, target); | ||
|
||
|
||
Entity::Draw(); // physics | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _AI_H | ||
#define _AI_H | ||
|
||
#include "Entity.h" | ||
|
||
class AI : public Entity | ||
{ | ||
public: | ||
AI(glm::vec3 pos) : Entity(pos) {} | ||
|
||
std::vector<glm::vec3> path; | ||
|
||
glm::vec3 target; | ||
glm::vec3 GenerateRandomPosition(float distance); | ||
|
||
void MoveTo(glm::vec3 pos); | ||
|
||
void MoveToRandom(); | ||
|
||
void Draw() override; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "Zombie.h" | ||
#include "../../LightingManager.h" | ||
#include <Game.h> | ||
|
||
Zombie::Zombie(glm::vec3 pos) : AI(pos) | ||
{ | ||
m = Model("Assets/Models/zombie_frim.obj"); | ||
m.LoadUVMap("zombie_frim"); | ||
|
||
m.scale = glm::vec3(0.7, 0.7, 0.7); | ||
|
||
|
||
// raise arms | ||
|
||
Mesh& leftArm = m.GetMesh("LeftArm"); | ||
Mesh& rightArm = m.GetMesh("RightArm"); | ||
|
||
leftArm.axis = glm::vec3(0, 0, 1); | ||
rightArm.axis = glm::vec3(0, 0, 1); | ||
|
||
leftArm.angle = 90; | ||
rightArm.angle = 90; | ||
|
||
// center them | ||
|
||
leftArm.position += glm::vec3(0.5, 0.5, 0); | ||
rightArm.position += glm::vec3(0.5, 0.5, 0); | ||
|
||
} | ||
|
||
void Zombie::Draw() | ||
{ | ||
m.position = position - glm::vec3(0,0.9f,0); | ||
m.angle = angle; | ||
|
||
// bind shader | ||
|
||
Game::instance->shader->Bind(); | ||
|
||
Game::instance->shader->SetUniform1f("lightLevel", (float)lightLevel); | ||
|
||
m.Draw(); | ||
|
||
Game::instance->shader->Bind(); | ||
|
||
Game::instance->shader->SetUniform1f("lightLevel", 10.0f); | ||
|
||
Game::instance->shader->Unbind(); | ||
|
||
AI::Draw(); // physics and AI pathing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef _ZOMBIE_H | ||
#define _ZOMBIE_H | ||
|
||
#include "AI.h" | ||
#include <OpenGL/Model.h> | ||
class Zombie : public AI | ||
{ | ||
Model m; | ||
|
||
public: | ||
|
||
Zombie(glm::vec3 pos); | ||
|
||
void Draw() override; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.