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. screen = new PhysicsScreen(10, 60);
  7. ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 600,30);
  8. shape->setColor(0.0,0.0,0.0,1.0);
  9. shape->setPosition(640/2, 400);
  10. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, true);
  11. for(int i=0; i < 50; i++) {
  12. shape = new ScreenShape(ScreenShape::SHAPE_RECT, 20,5);
  13. shape->setRotation(rand() % 360);
  14. shape->setPosition(rand() % 640, rand() % 300);
  15. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
  16. }
  17. collisionSound = new Sound("Resources/hit.wav");
  18. screen->addEventListener(this, PhysicsScreenEvent::EVENT_SOLVE_SHAPE_COLLISION);
  19. }
  20. void HelloPolycodeApp::handleEvent(Event *e) {
  21. if(e->getDispatcher() == screen) {
  22. switch(e->getEventCode()) {
  23. case PhysicsScreenEvent::EVENT_SOLVE_SHAPE_COLLISION:
  24. PhysicsScreenEvent *pe = (PhysicsScreenEvent*)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. }