HelloPolycodeApp.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
  3. #ifdef __APPLE__
  4. core = new CocoaCore(view, 640,480,false,0,90);
  5. #else
  6. core = new SDLCore(view, 640,480,false,0,90);
  7. #endif
  8. CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
  9. CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
  10. screen = new PhysicsScreen(10, 60);
  11. ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 600,30);
  12. shape->setColor(0.0,0.0,0.0,1.0);
  13. shape->setPosition(640/2, 400);
  14. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, true);
  15. for(int i=0; i < 50; i++) {
  16. shape = new ScreenShape(ScreenShape::SHAPE_RECT, 20,5);
  17. shape->setRotation(rand() % 360);
  18. shape->setPosition(rand() % 640, rand() % 300);
  19. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
  20. }
  21. collisionSound = new Sound("Resources/hit.wav");
  22. screen->addEventListener(this, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
  23. }
  24. void HelloPolycodeApp::handleEvent(Event *e) {
  25. if(e->getDispatcher() == screen) {
  26. switch(e->getEventCode()) {
  27. case PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION:
  28. PhysicsScreenEvent *pe = (PhysicsScreenEvent*)e;
  29. if(pe->impactStrength > 5)
  30. collisionSound->Play();
  31. break;
  32. }
  33. }
  34. }
  35. HelloPolycodeApp::~HelloPolycodeApp() {
  36. }
  37. bool HelloPolycodeApp::Update() {
  38. return core->Update();
  39. }