HelloPolycodeApp.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
  3. core = new POLYCODE_CORE(view, 640,480,false,false,0,0,90);
  4. CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
  5. CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
  6. scene = new PhysicsScene(10, 60);
  7. ScenePrimitive *shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 600,30);
  8. shape->setColor(0.0,0.0,0.0,1.0);
  9. shape->setPosition(0, -480/2+40);
  10. scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, true);
  11. for(int i=0; i < 50; i++) {
  12. shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 20,5);
  13. shape->setRoll(rand() % 360);
  14. shape->setPosition(-640/2 + rand() % 640, 480/2 - rand() % 300);
  15. scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
  16. }
  17. collisionSound = new Sound("Resources/hit.wav");
  18. scene->addEventListener(this, PhysicsSceneEvent::EVENT_SOLVE_SHAPE_COLLISION);
  19. }
  20. void HelloPolycodeApp::handleEvent(Event *e) {
  21. if(e->getDispatcher() == scene) {
  22. switch(e->getEventCode()) {
  23. case PhysicsSceneEvent::EVENT_SOLVE_SHAPE_COLLISION:
  24. PhysicsSceneEvent *pe = (PhysicsSceneEvent*)e;
  25. if(pe->impactStrength > 5)
  26. collisionSound->Play();
  27. break;
  28. }
  29. }
  30. }
  31. HelloPolycodeApp::~HelloPolycodeApp() {
  32. }
  33. bool HelloPolycodeApp::Update() {
  34. return core->updateAndRender();
  35. }