Skip to content

Commit

Permalink
Map converted to entity child
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Mar 23, 2014
1 parent 6231700 commit 5ac8ce2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion BGJ07/src/game.cpp
Expand Up @@ -105,7 +105,6 @@ void Game::run() {
m_CameraViewport.h = m_MainViewport.h;

SDL_RenderClear(m_Renderer);
arena->drawLevel(m_Renderer);
m_World.draw(m_Renderer);
SDL_SetRenderTarget(m_Renderer, 0);
SDL_RenderCopy(m_Renderer, m_DrawTexture, &m_CameraViewport, NULL);
Expand Down
6 changes: 5 additions & 1 deletion BGJ07/src/map.cpp
@@ -1,6 +1,10 @@
#include "map.hpp"
#include <SDL2_gfxPrimitives.h>

void Map::onInit(){
physicsShape = createMap();
}

btBvhTriangleMeshShape* Map::createMap(){
btTriangleMesh* triMesh = new btTriangleMesh();

Expand All @@ -24,7 +28,7 @@ btBvhTriangleMeshShape* Map::createMap(){
return triMeshShape;
}

void Map::drawLevel(SDL_Renderer* renderer){
void Map::onDraw(SDL_Renderer* renderer){
SDL_SetRenderDrawColor(renderer, 255, 100, 0, 255);
for (std::size_t count = 0; count < m_Vector.size(); count ++){
SDL_Point points[4];
Expand Down
6 changes: 4 additions & 2 deletions BGJ07/src/map.hpp
Expand Up @@ -4,11 +4,13 @@
#include <btBulletDynamicsCommon.h>
#include <vector>
#include <SDL.h>
#include "entity.hpp"

class Map{
class Map : public Entity{
public:
btBvhTriangleMeshShape* createMap();
void drawLevel(SDL_Renderer* renderer);
void onDraw(SDL_Renderer* renderer) override;
void onInit() override;

private:
std::vector<std::vector<btVector3>> m_Vector;
Expand Down
2 changes: 2 additions & 0 deletions BGJ07/src/world.cpp
Expand Up @@ -4,6 +4,7 @@

#include "game.hpp"
#include "player.hpp"
#include "map.hpp"

void bulletTickCallback(btDynamicsWorld *world, btScalar timeStep) {
auto w = static_cast<World*>(world->getWorldUserInfo());
Expand Down Expand Up @@ -58,6 +59,7 @@ void World::init(Game* g) {
m_DynamicsWorld->setGravity(btVector3(0, 2, 0));

addEntity(new Player());
addEntity(new Map());
}

void World::destroy() {
Expand Down

0 comments on commit 5ac8ce2

Please sign in to comment.