{"id":159,"date":"2026-07-15T14:46:59","date_gmt":"2026-07-15T05:46:59","guid":{"rendered":"https:\/\/tate.stars.ne.jp\/wpa\/?p=159"},"modified":"2026-07-15T14:47:00","modified_gmt":"2026-07-15T05:47:00","slug":"myplayer2boss2","status":"publish","type":"post","link":"https:\/\/tate.stars.ne.jp\/wpa\/myplayer2boss2.html","title":{"rendered":"myPlayer2Boss2"},"content":{"rendered":"<pre><code class=\"swift\">\nimport * as Phaser from 'phaser';\nimport { BossBullet } from '.\/BossBullet';\nimport {Player} from '.\/Player';\nexport class Boss2 extends Phaser.Physics.Arcade.Sprite {\nprivate maxHp: number = 5;\nprivate currentHp: number = 5;\nprivate respawnTimer?: Phaser.Time.TimerEvent;\nprivate isDead: boolean = false;\nprivate fireTimer!: Phaser.Time.TimerEvent;\nprivate bulletGroup!: Phaser.Physics.Arcade.Group;\nprivate player!: Player;\nconstructor(scene: Phaser.Scene, x: number, y: number) {\nsuper(scene, x, y, 'boss');\nscene.add.existing(this);\nscene.physics.add.existing(this);\nthis.setCollideWorldBounds(true).setDepth(3);\n if (this.body) {\n   this.body!.immovable = true;\n }\nthis.currentHp = this.maxHp;\nthis.angle += 90;\nthis.bulletGroup = scene.physics.add.group({\n classType: BossBullet,\n runChildUpdate: true\n});\n\/\/ 2\u79d2\u3054\u3068\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u3092\u72d9\u3063\u3066\u767a\u5c04\u3059\u308b\u30bf\u30a4\u30de\u30fc\n this.startAttackRoutine();\n}\nprivate startAttackRoutine() {\n  this.fireTimer = this.scene.time.addEvent({\n  delay: 2500,\n  callback: this.attackPlayer,\n  callbackScope: this,\n  loop: true\n });\n }\nprivate attackPlayer() {\n\/\/ \u30b7\u30fc\u30f3\u5185\u304b\u3089\u30d7\u30ec\u30a4\u30e4\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u63a2\u3059\nconst player = (this.scene as any).player as Phaser.Physics.Arcade.Sprite;\nif (!player || !player.active) return;\nconst baseAngle = Phaser.Math.Angle.Between(this.x, this.y, player.x, player.y);\n\/\/ \u6247\u5f62\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u8a2d\u5b9a\nconst spreadAngle = Phaser.Math.DegToRad(60); \/\/ \u6247\u5168\u4f53\u306e\u5e83\u304c\u308a\uff0860\u5ea6\uff09\nconst bulletCount = 5;                        \/\/ \u5f3e\u306e\u6570\nconst startAngle = baseAngle - spreadAngle \/ 2;\nconst angleStep = spreadAngle \/ (bulletCount - 1);\nfor (let i = 0; i < bulletCount; i++) {\n \/\/ \u30b0\u30eb\u30fc\u30d7\u304b\u3089\u975e\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u5f3e\u3092\u53d6\u5f97\u3001\u306a\u3051\u308c\u3070\u65b0\u898f\u751f\u6210\nconst bullet = this.bulletGroup.get(this.x, this.y) as BossBullet;\nif (bullet) {\nconst targetAngle = startAngle + (angleStep * i);\n \/\/ \u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u5ea7\u6a19\u3068\u3001\u52d5\u3044\u3066\u3044\u308b\u65b9\u5411\uff08\u901f\u5ea6 velocity\uff09\u3092\u6e21\u3057\u3066\u767a\u5c04\nconst vx = player.body ? player.body.velocity.x : 0;\nconst vy = player.body ? player.body.velocity.y : 0;\n\/\/   bullet.fire(this.x, this.y, targetAngle);\n bullet.fire(player.x, player.y, vx, vy, 350, targetAngle);\n }\n }\n }\n\/\/ \u5f3e\u304c\u5f53\u305f\u3063\u305f\u6642\u306e\u51e6\u7406\npublic takeDamage(): void {\n if (!this.active) return;\nthis.currentHp--;\n \/\/ \u88ab\u5f3e\u6642\u306e\u30d5\u30e9\u30c3\u30b7\u30e5\u6f14\u51fa\uff08\u8996\u899a\u7684\u30d5\u30a3\u30fc\u30c9\u30d0\u30c3\u30af\uff09\n this.setTint(0xff0000);\n this.scene.time.delayedCall(100, () => this.clearTint());\n\/\/ HP\u304c0\u306b\u306a\u3063\u305f\u3089\u6b7b\u4ea1\u51e6\u7406\n   if (this.currentHp <= 0) {\n      this.die();\n }\n }\n\/\/ \u6b7b\u4ea1\u51e6\u7406\nprivate die(): void {\/\/ \u5f53\u305f\u308a\u5224\u5b9a\u3092\u7121\u52b9\u5316\nthis.isDead = true;\nthis.setActive(false);\nthis.setVisible(false);\nthis.body!.enable = false; \/\/ \u5f53\u305f\u308a\u5224\u5b9a\u3092\u7121\u52b9\u5316\nthis.fireTimer.paused = true; \/\/ \u6b7b\u4ea1\u4e2d\u306f\u5f3e\u3092\u6483\u305f\u306a\u3044\n\/\/ 4\u79d2\uff084000\u30df\u30ea\u79d2\uff09\u5f8c\u306b\u5fa9\u6d3b\u3055\u305b\u308b\u30bf\u30a4\u30de\u30fc\u3092\u30bb\u30c3\u30c8\nthis.respawnTimer = this.scene.time.delayedCall(4000, () => {\nthis.respawn();\n});\n }\n \/\/ \u5fa9\u6d3b\u51e6\u7406\nprivate respawn(): void {\n\/\/  this.hp = 5;\nthis.isDead = false;\n this.setActive(true);\n this.setVisible(true);\n this.body!.enable = true;\n this.fireTimer.paused = false;\n \/\/ \u753b\u9762\u5185\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u5ea7\u6a19\u3092\u8a08\u7b97\uff08\u753b\u9762\u7aef\u304b\u308950px\u306e\u5185\u5074\uff09\n const gameWidth = this.scene.scale.width;\n const gameHeight = this.scene.scale.height;\n const randomX = Phaser.Math.Between(50, gameWidth - 50);\n const randomY = Phaser.Math.Between(50, gameHeight - 50);\n \/\/ \u4f4d\u7f6e\u3092\u8a2d\u5b9a\u3057\u3066\u518d\u6d3b\u6027\u5316\n  this.setPosition(randomX, randomY);\n  this.currentHp = this.maxHp;\n }\n public getBullets(): Phaser.Physics.Arcade.Group {\n  return this.bulletGroup;\n}\n public destroy(fromScene?: boolean) {\n  if (this.fireTimer) this.fireTimer.remove();\n  this.bulletGroup.destroy(true);\n  super.destroy(fromScene);\n }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import * as Phaser from &#8216;phase&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":1,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":160,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/posts\/159\/revisions\/160"}],"wp:attachment":[{"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tate.stars.ne.jp\/wpa\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}