fixes and added TODOs
This commit is contained in:
parent
dfb5d471a6
commit
84a9aad3e0
@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
|
Simulation::Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors):
|
||||||
p_map(_map)
|
p_map(_map)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
for(auto behavior : _behaviors){
|
for(BehaviorFunction &behavior : _behaviors){
|
||||||
glm::vec3 color;
|
glm::vec3 color;
|
||||||
color[i%3]=0.5f*(1 + i/3);
|
color[i%3]=0.5f*(1 + i/3);
|
||||||
m_teams.push_back(Team(color, color, behavior));
|
m_teams.push_back(Team(color, color, behavior));
|
||||||
i++;
|
i++;
|
||||||
|
// TODO : display the spawns on the map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::run()
|
void Simulation::update()
|
||||||
{
|
{
|
||||||
for(int i=0; i<m_teams.size(); ++i){
|
for(int i=0; i<m_teams.size(); ++i){
|
||||||
Team &t = m_teams[i];
|
Team &t = m_teams[i];
|
||||||
@ -26,5 +27,4 @@ void Simulation::run()
|
|||||||
}
|
}
|
||||||
t.updateDudes();
|
t.updateDudes();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,12 @@ private:
|
|||||||
Map *p_map;
|
Map *p_map;
|
||||||
std::vector<Team> m_teams;
|
std::vector<Team> m_teams;
|
||||||
public:
|
public:
|
||||||
Simulation(Map *_map, std::vector<BehaviorFunction> _behaviors);
|
Simulation(Map *_map, std::vector<BehaviorFunction> &_behaviors);
|
||||||
void run();
|
|
||||||
|
/**
|
||||||
|
* @brief update runs one step of simulation
|
||||||
|
*/
|
||||||
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIMULATION_H
|
#endif // SIMULATION_H
|
||||||
|
15
src/team.cpp
15
src/team.cpp
@ -12,13 +12,20 @@ Team::Team(const glm::vec3 &teamColor, const glm::vec3 &dudeColor, BehaviorFunct
|
|||||||
bool Team::updateSpawn()
|
bool Team::updateSpawn()
|
||||||
{
|
{
|
||||||
if(m_foodQuantity > 0)
|
if(m_foodQuantity > 0)
|
||||||
return !(--m_spawnCooldown);
|
{
|
||||||
|
--m_spawnCooldown;
|
||||||
|
if(!m_spawnCooldown)
|
||||||
|
{
|
||||||
|
m_spawnCooldown = SPAWN_COOLDOWN;
|
||||||
|
--m_foodQuantity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Team::spawn(Coord &d, Map &map)
|
void Team::spawn(Coord &d, Map &map)
|
||||||
{
|
{
|
||||||
m_spawnCooldown = SPAWN_COOLDOWN;
|
|
||||||
--m_foodQuantity;
|
|
||||||
m_dudes.push_back(Dude(d, map));
|
m_dudes.push_back(Dude(d, map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +34,6 @@ void Team::updateDudes()
|
|||||||
for (Dude &dude : m_dudes){
|
for (Dude &dude : m_dudes){
|
||||||
Action* action;
|
Action* action;
|
||||||
m_behavior(action, dude.getMemory(), &dude);
|
m_behavior(action, dude.getMemory(), &dude);
|
||||||
// TODO perform action
|
// TODO perform action (cf old_code/main.c -> void handleAction(t_dude* dude) )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user