2
0

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. scene = new PhysicsScene2D(10, 50);
  7. checkShape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 90,10);
  8. scene->addCollisionChild(checkShape, PhysicsScene2DEntity::ENTITY_RECT);
  9. for(int i=0; i < 50; i++) {
  10. ScenePrimitive *shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 30,15);
  11. shape->setRoll(rand() % 360);
  12. shape->setPosition(640/2 - rand() % 640, 480/2 - rand() % 480);
  13. scene->addCollisionChild(shape, PhysicsScene2DEntity::ENTITY_RECT);
  14. }
  15. scene->addEventListener(this, PhysicsScene2DEvent::EVENT_NEW_SHAPE_COLLISION);
  16. scene->addEventListener(this, PhysicsScene2DEvent::EVENT_END_SHAPE_COLLISION);
  17. }
  18. void HelloPolycodeApp::handleEvent(Event *e) {
  19. if(e->getDispatcher() == scene) {
  20. PhysicsScene2DEvent *pe = (PhysicsScene2DEvent*)e;
  21. switch(e->getEventCode()) {
  22. case PhysicsScene2DEvent::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 PhysicsScene2DEvent::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-680/2+20, -mouse.y+480/2);
  40. checkShape->setRoll(checkShape->getRoll() + (core->getElapsed() * 100));
  41. return core->updateAndRender();
  42. }