main.js 978 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var drawables = [];
  2. function addDrawable(d) {
  3. drawables.push(d);
  4. }
  5. function init() {
  6. addDrawable(new Spinner({}));
  7. addDrawable(new Revolver({}));
  8. // override default properties like this
  9. addDrawable(new Revolver({
  10. position: pt(460, 240),
  11. speed: 1.0,
  12. radius: 120,
  13. size: 35,
  14. }));
  15. addDrawable(new Pulse({}));
  16. // draw order determines above and below
  17. // the snake will appear on top of the heart because it is drawn afterward
  18. addDrawable(new Snake({}));
  19. }
  20. function drawLoop(ctx, timeElapsed, input) {
  21. // this code preserves the order objects are added above
  22. drawables.map(function(d) {
  23. var fn = d.frameMove;
  24. if(typeof(fn) != 'function') {
  25. console.log("missing frameMove function");
  26. return;
  27. }
  28. fn.call(d, timeElapsed, input);
  29. });
  30. drawables.map(function(d) {
  31. var fn = d.draw;
  32. if(typeof(fn) != 'function') {
  33. console.log("missing draw function");
  34. return;
  35. }
  36. fn.call(d, ctx);
  37. });
  38. }