mining-asteroid-field.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. let shots = [];
  2. stages.push({
  3. id: "mining-asteroid-field",
  4. setup: () => {
  5. shots = [];
  6. getSet('starfield').setup();
  7. starMotion.velocity.x = 0.05;
  8. starMotion.velocity.y = 0.05;
  9. getSet('asteroid-field').setup();
  10. shots.push({x: 0, y: -30, velocity: {x: 0, y: -12}});
  11. },
  12. update: (delta) => {
  13. getSet('starfield').update(delta);
  14. getSet('asteroid-field').update(delta);
  15. let shootAnother = false;
  16. shots.forEach(shot => {
  17. shot.x += shot.velocity.x;
  18. shot.y += shot.velocity.y;
  19. if(!shootAnother && shots.length < 5 && shot.y < -250) {
  20. shootAnother = true;
  21. }
  22. if(shootAnother && shot.y > -200) {
  23. shootAnother = false;
  24. }
  25. });
  26. if(shootAnother) {
  27. shots.push({x: 0, y: -30, velocity: {x: 0, y: -12}});
  28. }
  29. shots = shots.filter(shot => shot.y > -400);
  30. },
  31. draw: (context, delta) => {
  32. getSet('starfield').draw(context, delta);
  33. getSet('asteroid-field').draw(context, delta);
  34. shots.forEach(shot => {
  35. atlas.drawCentered(context, "laserBlue12.png", { x: shot.x, y: shot.y });
  36. });
  37. atlas.drawCentered(context, userData.sprite, { x: 0, y: 0 });
  38. },
  39. cleanup: () => {
  40. shots = [];
  41. },
  42. });