Skip to content

Commit

Permalink
FIX - bugs from everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Dleyzzex committed Jun 14, 2020
1 parent 743e155 commit dd400be
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 61 deletions.
25 changes: 24 additions & 1 deletion BlockMap/blockMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ void BlockMap::Init(IAnimatedMesh* &mesh)
_node->setMD2Animation(scene::EMAT_STAND);
}

void BlockMap::Init()
{
std::string path = "../assets/wall_2.obj";

if (GetType() == IGameObject::type_e::GROUND)
path = "../assets/floor.obj";
if (GetType() == IGameObject::type_e::DESTRUCTABLE_WALL)
path = "../assets/wall_2.obj";
if (GetType() == IGameObject::type_e::WALL)
path = "../assets/wall_1.obj";
if (GetType() == IGameObject::type_e::BORDER)
path = "../assets/wall_1.obj";
_node = _ctrl->_scene_mgr->addAnimatedMeshSceneNode(_ctrl->_scene_mgr->getMesh(path.c_str()));
_node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
_node->setMD2Animation(scene::EMAT_STAND);
_node->setPosition(GetPosition());

}

void BlockMap::SetPosition(irr::core::vector3df position)
{
_position = position;
Expand All @@ -41,7 +60,11 @@ void BlockMap::Update(std::vector<std::shared_ptr<IGameObject>> &obj)

void BlockMap::Delete(void)
{
_status = DELETED;
if (this->_node) {
this->_node->remove();
this->_node = NULL;
}
//_status = DELETED;
}

const IGameObject::type_e BlockMap::GetType(void)
Expand Down
1 change: 1 addition & 0 deletions BlockMap/blockMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BlockMap : public GameObject {
public:
BlockMap(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name);
void Init(IAnimatedMesh* &mesh);
void Init();
void Update(std::vector<std::shared_ptr<IGameObject>> &obj);
void Delete();
void SetPosition(irr::core::vector3df position);
Expand Down
1 change: 1 addition & 0 deletions Controller/IrrlichtController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void IrrlichtController::Init(irr::video::E_DRIVER_TYPE driver_type, int width,
_context.Position.Y = -1;
_context.settings = false;
_context.sceneName = "";
_context.clear_obj = false;
_context.down_volume = false;
_context.up_volume = false;
_context.down_volume_sound = false;
Expand Down
1 change: 1 addition & 0 deletions EventReceiver/MyEventReceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct SAppContext {
core::position2di Position;
bool settings;
std::string sceneName;
bool clear_obj;
float volume_music;
float volume_sound;
bool up_volume;
Expand Down
9 changes: 6 additions & 3 deletions GameScene/AScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ void AScene::Update(void)
i->get()->Delete();
_obj_list.erase(i);
}
if (i == _obj_list.end())
break;
}

if (this->_ctrl->_receiver->IsKeyDown(irr::KEY_ESCAPE)) {
this->_ctrl->_context.sceneName = "pauseScene";
}

for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
if (i->get()->GetStatus() != IGameObject::status_e::DELETED)
i->get()->Update(_obj_list);
}

if (this->_ctrl->_receiver->IsKeyDown(irr::KEY_ESCAPE))
this->_ctrl->_context.sceneName = "pauseScene";
}

void AScene::Render(void)
Expand Down
90 changes: 62 additions & 28 deletions GameScene/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*/

#include "GameScene.hpp"
#include "Player.hpp"
#include "MapGenerator.hpp"
#include <iostream>

GameScene::GameScene(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : AScene(ctrl, name)
{

this->player_one_set = false;
this->map_set = false;
}

GameScene::~GameScene()
Expand All @@ -22,33 +20,69 @@ GameScene::~GameScene()

void GameScene::Init(void)
{
irr::SKeyMap keyMap[5]; // re-assigne les commandes
keyMap[0].Action = irr::EKA_MOVE_FORWARD; // avancer
keyMap[0].KeyCode = irr::KEY_KEY_Z; // w
keyMap[1].Action = irr::EKA_MOVE_BACKWARD; // reculer
keyMap[1].KeyCode = irr::KEY_KEY_S; // s
keyMap[2].Action = irr::EKA_STRAFE_LEFT; // a gauche
keyMap[2].KeyCode = irr::KEY_KEY_Q; // a
keyMap[3].Action = irr::EKA_STRAFE_RIGHT; // a droite
keyMap[3].KeyCode = irr::KEY_KEY_D; // d
keyMap[4].Action = irr::EKA_JUMP_UP; // saut
keyMap[4].KeyCode = irr::KEY_SPACE;
if (this->_ctrl->_context.clear_obj) {
_obj_list.clear();
this->_ctrl->_context.clear_obj = false;
this->player_one_set = false;
this->map_set = false;
this->player_two_set = false;
}
for (auto i = _obj_list.cbegin(); i != _obj_list.cend(); i++) {
if (i->get()->GetType() == IGameObject::type_e::BORDER) {
i->get()->Init();
map_set = true;
}
if (i->get()->GetType() == IGameObject::type_e::DESTRUCTABLE_WALL) {
i->get()->Init();
map_set = true;
}
if (i->get()->GetType() == IGameObject::type_e::WALL) {
i->get()->Init();
map_set = true;
}
if (i->get()->GetType() == IGameObject::type_e::GROUND) {
i->get()->Init();
map_set = true;
}
if (i->get()->GetId().compare("p1") == 0){
i->get()->Init();
player_one_set = true;
}
if (i->get()->GetId().compare("p2") == 0){
i->get()->Init();
player_two_set = true;
}
}

/* Camera */
_ctrl->_scene_mgr->addCameraSceneNode(0, vector3df(30, 57 , 24), vector3df(10, -300, 24));
irr::scene::ICameraSceneNode *camera = _ctrl->_scene_mgr->getActiveCamera();
camera->setPosition(irr::core::vector3df(30, 57, 24));
std::shared_ptr<Player> p = std::make_shared<Player>(_ctrl, "p1", Player::WHITE, Player::LEFT);
std::shared_ptr<Player> p2 = std::make_shared<Player>(_ctrl, "p2", Player::GREEN, Player::RIGHT);
p->Init();
p2->Init();
p->SetPosition(irr::core::vector3df(0, 0, 0));
p2->SetPosition(irr::core::vector3df(20, 0, 0));
AddGameObject(p);
AddGameObject(p2);

/* Map */
if (!map_set) {
std::shared_ptr<mapGenerator> map = std::make_shared<mapGenerator>(vector3df(0, 0, 0), 6, 11, 11);
map->generate(_ctrl, _obj_list, "../assets/floor.obj", 100);
map->generateWall(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBorder(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBlock(_ctrl, _obj_list, "../assets/wall_2.obj", 30);
}

/* Music */
this->_ctrl->_music->Play("../assets/audio/music_game.ogg");
std::shared_ptr<mapGenerator> map = std::make_shared<mapGenerator>(vector3df(0,0,0), 6, 11, 11);
map->generate(_ctrl, _obj_list, "../assets/floor.obj", 100);
map->generateWall(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBorder(_ctrl, _obj_list, "../assets/wall_1.obj");
map->generateBlock(_ctrl, _obj_list, "../assets/wall_2.obj", 30);

if (!player_one_set) {
std::shared_ptr<Player> p = std::make_shared<Player>(_ctrl, "p1",
(Player::BomberType) this->_ctrl->_context.skin_player_one,
Player::LEFT);
p->SetPosition(irr::core::vector3df(0, 0, 0));
p->Init();
AddGameObject(p);
}
if (this->_ctrl->_context.nb_player > 1 && !player_two_set) {
std::shared_ptr<Player> p2 = std::make_shared<Player>(_ctrl, "p2",(Player::BomberType) this->_ctrl->_context.skin_player_two,Player::RIGHT);
p2->SetPosition(irr::core::vector3df(48, 0, 48));
p2->Init();
AddGameObject(p2);
}
}
7 changes: 7 additions & 0 deletions GameScene/GameScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#ifndef GAMESCENE_HPP_
#define GAMESCENE_HPP_

#include <iostream>
#include "AScene.hpp"
#include "Player.hpp"
#include "MapGenerator.hpp"

class GameScene : public AScene {
public:
Expand All @@ -17,6 +20,10 @@ class GameScene : public AScene {
~GameScene();
protected:
private:
bool map_set;
bool player_one_set;
bool player_two_set;
std::shared_ptr<mapGenerator> map;
};

#endif /* !GAMESCENE_HPP_ */
9 changes: 7 additions & 2 deletions GameScene/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ void SceneManager::LoadScene(const std::string name)
if (i->get()->GetId() == name) {
if (_current_scene) {
if (_ctrl->_scene_mgr->getSceneLoaderCount() > 0) {
_ctrl->_scene_mgr->clear();
_ctrl->_env->clear();
std::cout << "name " << name << std::endl;
std::cout << _current_scene->GetId() << std::endl;
// if (_current_scene->GetId() != "gameScene" && name != "pauseScene" || _current_scene->GetId() != "pauseScene" && name != "gameScene") {
// _ctrl->_scene_mgr->clear();
_ctrl->_scene_mgr->clear();
_ctrl->_env->clear();
// }
}
}
_current_scene = i->get();
Expand Down
1 change: 1 addition & 0 deletions Menu/EndScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ void EndScene::Render(void)
void EndScene::Clear(void)
{
this->_ctrl->_env->clear();
this->_ctrl->_context.clear_obj = true;
}
5 changes: 3 additions & 2 deletions Menu/SelectSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ void SelectSkin::Update(void)
int idx = 0;

_ctrl->_driver->beginScene(true, true, SColor(100, 150, 150, 150));
for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
/* for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
if (i->get()->GetStatus() == IGameObject::status_e::DELETED)
_obj_list.erase(i);
}
for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
i->get()->Update(_obj_list);
}
}*/

if (this->_first_skin->updateButton(this->_ctrl->_context))
this->_buttonSound->Play();
Expand Down Expand Up @@ -76,6 +76,7 @@ void SelectSkin::Render(void)
void SelectSkin::Clear(void)
{
this->_ctrl->_env->clear();
this->_ctrl->_context.clear_obj = true;
}

void SelectSkin::SelectPlayer()
Expand Down
5 changes: 3 additions & 2 deletions Menu/SelectSkins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void SelectSkins::Update(void)
int idx = 0;

_ctrl->_driver->beginScene(true, true, SColor(100, 150, 150, 150));
for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
/* for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
if (i->get()->GetStatus() == IGameObject::status_e::DELETED)
_obj_list.erase(i);
}
for (auto i = _obj_list.begin(); i != _obj_list.end(); i++) {
i->get()->Update(_obj_list);
}
}*/

if (this->_first_skin_one->updateButton(this->_ctrl->_context))
this->_buttonSound->Play();
Expand Down Expand Up @@ -91,6 +91,7 @@ void SelectSkins::Render(void)
void SelectSkins::Clear(void)
{
this->_ctrl->_env->clear();
this->_ctrl->_context.clear_obj = true;
}

void SelectSkins::SelectPlayerOne()
Expand Down
56 changes: 43 additions & 13 deletions Player/Bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "Bomb.hpp"
#include <memory>

Bomb::Bomb(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : GameObject(ctrl, irr::core::vector3df(1, 1, 1), name)
{
Expand Down Expand Up @@ -74,52 +75,81 @@ void Bomb::Update(std::vector<std::shared_ptr<IGameObject>> &obj)
}
} else if (this->_boom) {
if (this->elapsed_seconds.count() > TIME_ALIVE) {
this->Delete();
SetStatus(IGameObject::status_e::DELETED);
}
}
}

bool Bomb::calculateCollision(irr::core::vector3df position)
{
std::unique_ptr<Collider> tmp = std::make_unique<Collider>(position, 5, 5, 5);
bool ret = false;

for (auto i = _obj->cbegin(); i != _obj->cend(); i++) {
if (i->get()->GetId() != _id && (i->get()->GetId().compare("p1") == 0 || i->get()->GetId().compare("p2") == 0)) {
for (auto i = _obj->begin(); i != _obj->end(); i++) {

if (i->get()->GetId() != _id && i->get()->GetType() == IGameObject::type_e::PLAYER) {
if (tmp->Collide(*i->get()->GetCollider())) {
i->get()->SetStatus(IGameObject::status_e::DELETED);
}
}

if (i->get()->GetId() != _id && i->get()->GetType() == IGameObject::type_e::DESTRUCTABLE_WALL) {
if (tmp->Collide(*i->get()->GetCollider())) {
i->get()->SetStatus(IGameObject::status_e::DELETED);
}
}
if (i->get()->GetId() != _id && i->get()->GetId().compare("p1") != 0 && i->get()->GetId().compare("p2") != 0 && i->get()->GetId().compare("ground") != 0) {

if (i->get()->GetId() != _id && i->get()->GetType() == IGameObject::type_e::BOMB) {
//std::unique_ptr<Collider> temp = std::make_unique<Collider>(position, 50, 50, 50);
//if (tmp->Collide(*i->get()->GetCollider())) {
std::cout << "Bomb" << std::endl;
//Bomb *bomb = dynamic_cast<Bomb*>(i->get());
//auto bomb = std::dynamic_pointer_cast<Bomb>(i.base());
//bomb->explosion();
//}
}

if (i->get()->GetId() != _id && i->get()->GetType() != IGameObject::type_e::PLAYER && i->get()->GetType() != IGameObject::type_e::DESTRUCTABLE_WALL && i->get()->GetType() != IGameObject::type_e::GROUND) {
if (tmp->Collide(*i->get()->GetCollider())) {
return (true);
ret = true;
}
}
}
return (false);
return (ret);
}

void Bomb::explosion()
{
irr::core::vector3df pos = this->GetPosition();

this->_particles->clear();
if (!calculateCollision(vector3df(pos.X - 5, pos.Y, pos.Z)))
if (!calculateCollision(vector3df(pos.X - 6, pos.Y, pos.Z)))
this->_upperExplosion->Init();
if (!calculateCollision(vector3df(pos.X + 5, pos.Y, pos.Z)))
if (!calculateCollision(vector3df(pos.X + 6, pos.Y, pos.Z)))
this->_downExplosion->Init();
if (!calculateCollision(vector3df(pos.X, pos.Y, pos.Z - 5)))
if (!calculateCollision(vector3df(pos.X, pos.Y, pos.Z - 6)))
this->_leftExplosion->Init();
if (!calculateCollision(vector3df(pos.X, pos.Y, pos.Z + 5)))
if (!calculateCollision(vector3df(pos.X, pos.Y, pos.Z + 6)))
this->_rightExplosion->Init();
}

void Bomb::Delete()
{
this->_upperExplosion->clear();
//std::cout << "ok" << std::endl;
this->_particles->Delete();
this->_upperExplosion->Delete();
this->_downExplosion->Delete();
this->_rightExplosion->Delete();
this->_leftExplosion->Delete();
if (this->_node) {
this->_node->remove();
this->_node = NULL;
//this->_node->setVisible(false);
}
/* this->_upperExplosion->clear();
this->_downExplosion->clear();
this->_leftExplosion->clear();
this->_rightExplosion->clear();
//_status = DELETED;
this->_rightExplosion->clear();*/
//this->_node->remove();
}

Expand Down
Loading

0 comments on commit dd400be

Please sign in to comment.