HelloPolycodeApp.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
  3. core = new POLYCODE_CORE(view, 640,480,false,true,0,0,90, 0, true);
  4. CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
  5. CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
  6. scene = new PhysicsScene();
  7. ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 10, 10);
  8. ground->loadTexture("Resources/green_texture.png");
  9. scene->addPhysicsChild(ground, PhysicsSceneEntity::SHAPE_PLANE, 0.0);
  10. for(int i=0; i < 100; i++) {
  11. ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.5,0.5,0.5);
  12. box->loadTexture("Resources/pink_texture.png");
  13. box->Roll(-45 + (rand() % 90));
  14. box->Pitch(-45 + (rand() % 90));
  15. box->setPosition(-2 + (rand() % 4), i*0.5, -2 + (rand() % 4));
  16. scene->addPhysicsChild(box, PhysicsSceneEntity::SHAPE_BOX, 1.0);
  17. }
  18. scene->getDefaultCamera()->setPosition(7,7,7);
  19. scene->getDefaultCamera()->lookAt(Vector3(0,0,0));
  20. scene->addEventListener(this, PhysicsSceneEvent::COLLISION_EVENT);
  21. collisionSound = new Sound("Resources/hit.wav");
  22. }
  23. HelloPolycodeApp::~HelloPolycodeApp() {
  24. }
  25. void HelloPolycodeApp::handleEvent(Event *event) {
  26. if(event->getDispatcher() == scene) {
  27. PhysicsSceneEvent *physicsEvent = (PhysicsSceneEvent*) event;
  28. if(physicsEvent->appliedImpulse > 2.0) {
  29. collisionSound->Play();
  30. }
  31. }
  32. }
  33. bool HelloPolycodeApp::Update() {
  34. return core->updateAndRender();
  35. }