Skip to content

Commit

Permalink
ADD - power up
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang-git committed Jun 14, 2020
1 parent ab32e4c commit bd25256
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_subdirectory(GameScene)
add_subdirectory(Menu)
add_subdirectory(Settings)
add_subdirectory(Storage)
add_subdirectory(PowerUp)


# define sources to use
set(SRCS Application/main.cpp CPack/win32.rc)
Expand All @@ -59,6 +61,7 @@ target_link_libraries(${PROJECT_NAME} menu)
target_link_libraries(${PROJECT_NAME} settings)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} storage)
target_link_libraries(${PROJECT_NAME} power_up)

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} ${Irrlicht_LIBRARIES})
Expand Down
4 changes: 3 additions & 1 deletion GameObject/IGameObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class IGameObject {
WALL,
DESTRUCTABLE_WALL,
GROUND,
BONUS
BONUS,
PWU_SKATE,
PWU_WALL_PASS
};
enum status_e {
OK = 0,
Expand Down
1 change: 1 addition & 0 deletions GameScene/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} game_object)
target_link_libraries(${PROJECT_NAME} player)
target_link_libraries(${PROJECT_NAME} map_generator)
target_link_libraries(${PROJECT_NAME} power_up)
25 changes: 25 additions & 0 deletions GameScene/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#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)
Expand All @@ -20,6 +21,28 @@ GameScene::~GameScene()

}

std::shared_ptr<IGameObject> GameScene::initPowerUp(irr::core::vector3df pos, const std::string name)
{
std::shared_ptr<PowerUp> power_up = std::make_shared<PowerUp>(_ctrl, name);
power_up->Init();
power_up->SetPosition(pos);
return power_up;
}

void GameScene::addPowerUp(unsigned int prob)
{
std::random_device dev;
std::mt19937 _prob(dev());
std::uniform_int_distribution<std::mt19937::result_type> distribution(1,100);
std::vector<std::shared_ptr<IGameObject>>::iterator ptr;

for (ptr = _obj_list.begin(); ptr < _obj_list.end(); ptr++)
if (ptr->get()->GetType() == IGameObject::type_e::GROUND || ptr->get()->GetType() == IGameObject::type_e::DESTRUCTABLE_WALL)
if (distribution(_prob) <= prob) {
_obj_list.push_back(initPowerUp(ptr->get()->GetPosition(), "skate"));
}
}

void GameScene::Init(void)
{
irr::SKeyMap keyMap[5]; // re-assigne les commandes
Expand Down Expand Up @@ -51,4 +74,6 @@ void GameScene::Init(void)
map->generateWall(_ctrl, _obj_list, WALL_PATH);
map->generateBorder(_ctrl, _obj_list, WALL_PATH);
map->generateBlock(_ctrl, _obj_list, BLOCK_PATH, 30);
addPowerUp(3);

}
3 changes: 3 additions & 0 deletions GameScene/GameScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define GAMESCENE_HPP_

#include "AScene.hpp"
#include "PowerUp.hpp"

class GameScene : public AScene {
public:
Expand All @@ -17,6 +18,8 @@ class GameScene : public AScene {
~GameScene();
protected:
private:
void addPowerUp(unsigned int prob);
std::shared_ptr<IGameObject> initPowerUp(irr::core::vector3df pos, const std::string name);
};

#endif /* !GAMESCENE_HPP_ */
6 changes: 3 additions & 3 deletions MapGenerator/MapGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include <random>
#include "blockMap.hpp"

#define BLOCK_PATH "../assets/wall_2.obj"
#define WALL_PATH "../assets/wall_1.obj"
#define GROUND_PATH "../assets/floor.obj"
#define BLOCK_PATH "../assets/map/wall_2.obj"
#define WALL_PATH "../assets/map/wall_1.obj"
#define GROUND_PATH "../assets/map/floor.obj"

using namespace irr;
using namespace core;
Expand Down
20 changes: 20 additions & 0 deletions PowerUp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.11)

# project name
project(power_up)

# c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

# define sources to use
set(SRCS PowerUp.cpp PowerUp.hpp)

# define the binary output
add_library(${PROJECT_NAME} ${SRCS})

# expose the headers
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} game_object)
61 changes: 61 additions & 0 deletions PowerUp/PowerUp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
** EPITECH PROJECT, 2020
** epitech-indiestudio
** File description:
** [enter description here]
*/

#include "PowerUp.hpp"

PowerUp::PowerUp(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name) : GameObject(ctrl, irr::core::vector3df(5, 5, 5), name)
{
_position = irr::core::vector3df(0, 0, 0);
_rotation = irr::core::vector3df(0, 0, 0);
_node = NULL;
}

void PowerUp::Init(void)
{
std::random_device dev;
std::mt19937 _prob(dev());
std::uniform_int_distribution<std::mt19937::result_type> distribution(1, 2);

if (distribution(_prob) == 1)
_node = _ctrl->_scene_mgr->addAnimatedMeshSceneNode(_ctrl->_scene_mgr->getMesh(SKATE));
else
_node = _ctrl->_scene_mgr->addAnimatedMeshSceneNode(_ctrl->_scene_mgr->getMesh(SKATE));
_node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
_node->setMD2Animation(scene::EMAT_STAND);
}

void PowerUp::SetPosition(irr::core::vector3df position)
{
_position = position;
if (_node)
_node->setPosition(position);
_collider->SetPosition(position);
}

PowerUp::~PowerUp()
{

}

void PowerUp::Update(std::vector<std::shared_ptr<IGameObject>> &obj)
{

}

void PowerUp::Delete(void)
{
_status = DELETED;
}

const IGameObject::type_e PowerUp::GetType(void)
{
if (_id.compare("skate") == 0)
return IGameObject::type_e::PWU_SKATE;
if (_id.compare("wall_pass") == 0)
return IGameObject::type_e::PWU_WALL_PASS;
return IGameObject::type_e::BONUS;
}
31 changes: 31 additions & 0 deletions PowerUp/PowerUp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2020
** epitech-indiestudio
** File description:
** [enter description here]
*/

#ifndef BLOCK_HPP_
#define BLOCK_HPP_

#include "GameObject.hpp"

#include <random>
#include <iostream>

#define SKATE "../assets/skate.obj"

class PowerUp : public GameObject {
public:
PowerUp(const std::shared_ptr<IrrlichtController> &ctrl, const std::string name);
void Init(void);
void Update(std::vector<std::shared_ptr<IGameObject>> &obj);
void Delete();
void SetPosition(irr::core::vector3df position);
const IGameObject::type_e GetType(void);
~PowerUp();
private:
irr::scene::IAnimatedMeshSceneNode *_node;
};

#endif /* !BLOCK_HPP_ */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions assets/skate.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl Material.003
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.020902 0.800000 0.710829
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
40 changes: 40 additions & 0 deletions assets/skate.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Blender v2.83.0 OBJ File: ''
# www.blender.org
mtllib skate.mtl
o Cube_Cube.001
v 0.247360 1.167307 1.000000
v 0.247360 1.167307 -1.000000
v 0.247360 3.167307 -0.007055
v 0.247360 2.167307 -0.503528
v 0.247360 2.167307 -0.507050
v 0.079821 1.167307 1.000000
v 0.079821 3.167307 -0.007055
v 0.079821 1.167307 -1.000000
v 0.079821 2.167307 -0.503528
vt 0.500000 0.188381
vt 0.375000 0.250000
vt 0.500000 0.187941
vt 0.375000 1.000000
vt 0.875000 0.624118
vt 0.875000 0.624118
vt 0.375000 1.000000
vt 0.625000 0.125882
vt 0.625000 0.125882
vt 0.500000 0.187941
vt 0.375000 0.250000
vt 0.375000 0.000000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.4497 0.8932
vn 1.0000 -0.0000 0.0000
vn 0.0000 0.4447 -0.8957
vn 0.0000 -1.0000 0.0000
usemtl Material.003
s off
f 5/1/1 2/2/1 4/3/1
f 1/4/2 3/5/2 7/6/2 6/7/2
f 4/3/1 3/8/1 5/1/1
f 5/1/3 3/5/3 1/4/3 2/2/3
f 7/9/1 9/10/1 8/11/1 6/12/1
f 3/8/4 4/3/4 9/10/4 7/9/4
f 4/3/4 2/2/4 8/11/4 9/10/4
f 2/2/5 1/4/5 6/7/5 8/11/5

0 comments on commit bd25256

Please sign in to comment.