Game for OLC Code Jam 2022
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

bullet.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class Bullet extends Entity {
  2. constructor(x, y) {
  3. super(x, y, 0.001, 0.02);
  4. this.color = 'yellow';
  5. }
  6. update() {
  7. if (this.alive) {
  8. this.y -= 0.01;
  9. if (this.y < -0.1) {
  10. this.destroy();
  11. }
  12. for (let cloud of clouds) {
  13. if (this.isOverlapped(cloud)) {
  14. cloud.destroy();
  15. this.destroy();
  16. }
  17. }
  18. }
  19. }
  20. }
  21. class RainDrop extends Bullet {
  22. constructor(x, y) {
  23. super(x, y);
  24. this.color = 'cyan';
  25. }
  26. update() {
  27. if (this.alive) {
  28. this.y += 0.01;
  29. if (this.y > 1.1) {
  30. this.destroy();
  31. } else if (this.isOverlapped(shootingPad)) {
  32. shootingPad.lifeOver();
  33. this.destroy();
  34. }
  35. }
  36. }
  37. }
  38. const currentAngle = () => {
  39. const x = Date.now() / 10000;
  40. const n = noise.simplex2(x, 0);
  41. return mapNumber(n, -1, 1, 45, 135);
  42. };
  43. class BackgroundRaindrop extends Bullet {
  44. constructor(x, y, speed) {
  45. super(x, y);
  46. this.speed = speed;
  47. }
  48. draw() {
  49. CTX.save();
  50. const { x, y, w, h } = this.getScreenCoords();
  51. CTX.translate(x, y);
  52. CTX.rotate(toRadians(currentAngle() - 90));
  53. CTX.fillStyle = `rgba(200, 255, 255, 0.2)`;
  54. CTX.fillRect(0, 0, w, h);
  55. CTX.restore();
  56. }
  57. update() {
  58. const cs = Math.cos(toRadians(currentAngle()));
  59. const sn = Math.sin(toRadians(currentAngle()));
  60. this.x += this.speed * cs;
  61. this.y += this.speed * sn;
  62. if (this.y > 1.1) {
  63. this.y = randRange(-1, -0.1);
  64. this.x = randRange(-0.5, 1.5);
  65. }
  66. }
  67. }