Levels are now described by a class.
Levels are now described by a class.

file:a/App.cpp -> file:b/App.cpp
--- a/App.cpp
+++ b/App.cpp
@@ -1,6 +1,6 @@
 #include "App.h"
 
-#include "CrateObject.h"
+#include "WallLevel.h"
 
 App::App()
   : _device(0),_cannon(0),_cannonControl(0)
@@ -76,11 +76,6 @@
   ICollisionShape *cubeShape=new IBoxShape(cube,0,false);
   IRigidBody *cubeBody=_bullet->addRigidBody(cubeShape);
 
-  for(s32 i=-10;i<10;i++)
-    for(s32 k=0;k<10;k++)
-      addCube(vector3df(i*0.5,0.35+k*0.5,-6));
-
-
   /*s32 pyramidHeight=5;
   for(s32 k=0;k<pyramidHeight;k++)
     for(s32 i=-pyramidHeight+k;i<pyramidHeight-k;i++)
@@ -92,6 +87,9 @@
 
   _cannonControl=new CannonSceneNodeAnimator();
   _cannon->addAnimator(_cannonControl);
+
+  _level=new WallLevel(_smgr,_bullet);
+  _level->setup();
 }
 
 bool App::OnEvent(const SEvent &event)
@@ -112,6 +110,10 @@
 	{
 	  _cannon->fire();
 	}
+      if(event.KeyInput.Key==KEY_KEY_R && !event.KeyInput.PressedDown)
+	{
+	  _level->reset();
+	}
       break;
     default:
       break;
@@ -121,11 +123,6 @@
     return _cannonControl->OnEvent(event);
   else
     return false;
-}
-
-void App::addCube(vector3df pos)
-{
-  CrateObject *crate=new CrateObject(pos,_smgr,_bullet);
 }
 
 void App::handleCollisions()

file:a/App.h -> file:b/App.h
--- a/App.h
+++ b/App.h
@@ -11,6 +11,8 @@
 
 #include "CannonSceneNode.h"
 #include "CannonSceneNodeAnimator.h"
+
+#include "Level.h"
 
 class App : public IEventReceiver
 {
@@ -30,6 +32,8 @@
   CannonSceneNode *_cannon;
   CannonSceneNodeAnimator *_cannonControl;
 
+  Level *_level;
+
   void init();
 
   void addCube(vector3df pos);

file:b/Level.cpp (new)
--- /dev/null
+++ b/Level.cpp
@@ -1,1 +1,47 @@
+#include "Level.h"
+#include "CrateObject.h"
 
+Level::Level(ISceneManager *smgr,irrBulletWorld *bullet)
+  :_smgr(smgr),_bullet(bullet)
+{ }
+
+Level::~Level()
+{ 
+  destroy();
+}
+
+void Level::reset()
+{
+  destroy();
+  setup();
+}
+
+void Level::destroy()
+{
+  for(std::vector<DestroyableObject *>::const_iterator iter=_objects.begin();
+      iter!=_objects.end();
+      iter++)
+    {
+      (*iter)->destroy();
+    }
+
+  _objects.clear();
+}
+
+ISceneManager* Level::sceneManager()
+{ return _smgr; }
+
+irrBulletWorld* Level::bullet()
+{ return _bullet; }
+
+void Level::addCrate(vector3df pos)
+{
+  CrateObject *crate=new CrateObject(pos,_smgr,_bullet);
+  addObject(crate);
+}
+
+void Level::addObject(DestroyableObject *object)
+{
+  _objects.push_back(object);
+}
+

file:b/Level.h (new)
--- /dev/null
+++ b/Level.h
@@ -1,1 +1,40 @@
+#ifndef LEVEL_H_
+#define LEVEL_H_
 
+#include "DestroyableObject.h"
+
+#include <vector>
+
+#include <irrlicht.h>
+#include <irrbullet.h>
+
+using namespace irr;
+using namespace irr::core;
+using namespace irr::video;
+using namespace irr::scene;
+
+class Level
+{
+public:
+  Level(ISceneManager *smgr,irrBulletWorld *bullet);
+  ~Level();
+
+  virtual void setup() =0;
+  void reset();
+  void destroy();
+
+protected:
+  void addCrate(vector3df pos);
+  void addObject(DestroyableObject *object);
+
+  ISceneManager* sceneManager();
+  irrBulletWorld* bullet();
+
+private:
+  std::vector<DestroyableObject*> _objects;
+  ISceneManager *_smgr;
+  irrBulletWorld *_bullet;
+};
+
+#endif // LEVEL_H_
+

file:a/Makefile -> file:b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-OBJS=main.o App.o CannonSceneNode.o CannonSceneNodeAnimator.o DestroyableObject.o CrateObject.o
+OBJS=main.o App.o CannonSceneNode.o CannonSceneNodeAnimator.o DestroyableObject.o CrateObject.o Level.o WallLevel.o
 APP=bullet
 
 CFLAGS=-I/home/kkrizka/dev/irrlicht-svn/include/irrlicht -I/home/kkrizka/dev/irrbullet-svn/include/irrBullet -g `pkg-config bullet --cflags`

file:b/WallLevel.cpp (new)
--- /dev/null
+++ b/WallLevel.cpp
@@ -1,1 +1,16 @@
+#include "WallLevel.h"
 
+WallLevel::WallLevel(ISceneManager *smgr,irrBulletWorld *bullet)
+  : Level(smgr,bullet)
+{ }
+
+WallLevel::~WallLevel()
+{ }
+
+void WallLevel::setup()
+{ 
+  for(s32 i=-10;i<10;i++)
+    for(s32 k=0;k<10;k++)
+      addCrate(vector3df(i*0.5,0.35+k*0.5,-6));
+}
+

file:b/WallLevel.h (new)
--- /dev/null
+++ b/WallLevel.h
@@ -1,1 +1,18 @@
+#ifndef WALLLEVEL_H_
+#define WALLLEVEL_H_
 
+#include "Level.h"
+
+class WallLevel : public Level
+{
+public:
+  WallLevel(ISceneManager *smgr,irrBulletWorld *bullet);
+  ~WallLevel();
+
+  void setup();
+
+private:
+};
+
+#endif // WALLLEVEL_H_
+