HelloPolycodeApp.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
  3. #ifdef __APPLE__
  4. core = new CocoaCore(view, 640,480,false,false,0,0,90);
  5. #else
  6. core = new SDLCore(view, 640,480,false,false,0,0,90);
  7. #endif
  8. CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
  9. CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
  10. screen = new PhysicsScreen(10, 50);
  11. checkShape = new ScreenShape(ScreenShape::SHAPE_RECT, 90,10);
  12. screen->addCollisionChild(checkShape, PhysicsScreenEntity::ENTITY_RECT);
  13. for(int i=0; i < 50; i++) {
  14. ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 30,15);
  15. shape->setRotation(rand() % 360);
  16. shape->setPosition(rand() % 640, rand() % 480);
  17. screen->addCollisionChild(shape, PhysicsScreenEntity::ENTITY_RECT);
  18. }
  19. screen->addEventListener(this, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
  20. screen->addEventListener(this, PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION);
  21. }
  22. void HelloPolycodeApp::handleEvent(Event *e) {
  23. if(e->getDispatcher() == screen) {
  24. PhysicsScreenEvent *pe = (PhysicsScreenEvent*)e;
  25. switch(e->getEventCode()) {
  26. case PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION:
  27. if(pe->entity1 == checkShape || pe->entity2 == checkShape) {
  28. pe->entity1->setColor(1.0f, 0.0f, 0.0f, 1.0f);
  29. pe->entity2->setColor(1.0f, 0.0f, 0.0f, 1.0f);
  30. }
  31. break;
  32. case PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION:
  33. pe->entity1->setColor(1.0f, 1.0f, 1.0f, 1.0f);
  34. pe->entity2->setColor(1.0f, 1.0f, 1.0f, 1.0f);
  35. break;
  36. }
  37. }
  38. }
  39. HelloPolycodeApp::~HelloPolycodeApp() {
  40. }
  41. bool HelloPolycodeApp::Update() {
  42. Vector2 mouse = core->getInput()->getMousePosition();
  43. checkShape->setPosition(mouse.x, mouse.y);
  44. checkShape->setRotation(checkShape->getRotation() + (core->getElapsed() * 100));
  45. return core->Update();
  46. }