HelloPolycodeApp.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. PhysicsScreen *screen = new PhysicsScreen(10, 50);
  9. ScreenShape *ceiling = new ScreenShape(ScreenShape::SHAPE_RECT, 640, 20);
  10. ceiling->setColor(0.0, 0.0, 0.0, 1.0);
  11. ceiling->setPosition(640/2, 10);
  12. screen->addPhysicsChild(ceiling, PhysicsScreenEntity::ENTITY_RECT, true);
  13. // Revolute Joint
  14. ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
  15. shape->setPosition(150, 20+15);
  16. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
  17. screen->createRevoluteJoint(shape, ceiling, 0, -15);
  18. screen->applyImpulse(shape, 10, 0);
  19. // Distance Joint
  20. shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
  21. shape->setPosition(250, 20+25);
  22. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
  23. screen->createDistanceJoint(shape, ceiling, false);
  24. screen->applyImpulse(shape, 200, 0);
  25. ScreenLine *line = new ScreenLine(shape, ceiling);
  26. line->setColor(1.0, 0.0, 0.0, 1.0);
  27. screen->addChild(line);
  28. // Prismatic Joint
  29. shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
  30. shape->setPosition(450, 20+25);
  31. screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
  32. screen->createPrismaticJoint(ceiling, shape, Vector2(0,1), 0,0, false, 100, 0, true);
  33. ScreenEntity *lineAnchor = new ScreenEntity();
  34. lineAnchor->setPosition(450,10);
  35. line = new ScreenLine(shape, lineAnchor);
  36. line->setColor(0.0, 1.0, 0.0, 1.0);
  37. screen->addChild(line);
  38. }
  39. HelloPolycodeApp::~HelloPolycodeApp() {
  40. }
  41. bool HelloPolycodeApp::Update() {
  42. return core->Update();
  43. }