HelloPolycodeApp.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
  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, 50);
  7. checkShape = new ScreenShape(ScreenShape::SHAPE_RECT, 90,10);
  8. screen->addCollisionChild(checkShape, PhysicsScreenEntity::ENTITY_RECT);
  9. for(int i=0; i < 50; i++) {
  10. ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 30,15);
  11. shape->setRotation(rand() % 360);
  12. shape->setPosition(rand() % 640, rand() % 480);
  13. screen->addCollisionChild(shape, PhysicsScreenEntity::ENTITY_RECT);
  14. }
  15. screen->addEventListener(this, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
  16. screen->addEventListener(this, PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION);
  17. }
  18. void HelloPolycodeApp::handleEvent(Event *e) {
  19. if(e->getDispatcher() == screen) {
  20. PhysicsScreenEvent *pe = (PhysicsScreenEvent*)e;
  21. switch(e->getEventCode()) {
  22. case PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION:
  23. if(pe->entity1 == checkShape || pe->entity2 == checkShape) {
  24. pe->entity1->setColor(1.0f, 0.0f, 0.0f, 1.0f);
  25. pe->entity2->setColor(1.0f, 0.0f, 0.0f, 1.0f);
  26. }
  27. break;
  28. case PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION:
  29. pe->entity1->setColor(1.0f, 1.0f, 1.0f, 1.0f);
  30. pe->entity2->setColor(1.0f, 1.0f, 1.0f, 1.0f);
  31. break;
  32. }
  33. }
  34. }
  35. HelloPolycodeApp::~HelloPolycodeApp() {
  36. }
  37. bool HelloPolycodeApp::Update() {
  38. Vector2 mouse = core->getInput()->getMousePosition();
  39. checkShape->setPosition(mouse.x, mouse.y);
  40. checkShape->setRotation(checkShape->getRotation() + (core->getElapsed() * 100));
  41. return core->Update();
  42. }