function Sprite_Keiken() { this.initialize(...arguments); } Sprite_Keiken.prototype = Object.create(Sprite.prototype); Sprite_Keiken.prototype.constructor = Sprite_Keiken; Sprite_Keiken.prototype.initialize = function () { Sprite.prototype.initialize.call(this); this.anchor.x = 0.5; this.anchor.y = 0.5; this.scale.x = 0.3; this.scale.y = 0.3; this.speed = 0; this.disX = $gameMap._parallaxX; this.disY = $gameMap._parallaxY; this.setCharacterBitmap(); }; //場所移動するだけでいいや Sprite_Keiken.prototype.update = function () { if (this.death) { return; } Sprite.prototype.update.call(this); this.x -= ($gameMap._parallaxX - this.disX) * 48; this.disX = $gameMap._parallaxX; this.y -= ($gameMap._parallaxY - this.disY) * 48; this.disY = $gameMap._parallaxY; if (!this.speed) { var kyori = (this.x - (Graphics.boxWidth - SURVIVOR_CONST.RIGHT_MARGIN) / 2) * (this.x - (Graphics.boxWidth - SURVIVOR_CONST.RIGHT_MARGIN) / 2); kyori += (this.y - Graphics.boxHeight / 2) * (this.y - Graphics.boxHeight / 2); kyori = Math.sqrt(kyori); //プレイヤーが接触したら if (kyori < $gameTemp.SURVIVOR_player_data.collect_range) { this.speed = -8; } } else { //atan2使うと微妙に遅いからx^2 + y^2 = r^2 、y=kxを使ってspeed(移動させたい距離r)として動かしたいxとyの大きさを導く var sa_x = this.x - (Graphics.boxWidth - SURVIVOR_CONST.RIGHT_MARGIN) / 2; var sa_y = this.y - Graphics.boxHeight / 2; if (this.speed < 0) { sa_x *= -1; sa_y *= -1; } var k = sa_y / sa_x; var x = Math.sqrt((this.speed * this.speed) / (1 + k * k)); //xを基に導くけど2乗してるから+-どっちかわからん if (0 < sa_x) { x = -x; } var y = k * x; //xかyどちらかが中央超えたら削除 if (sa_x * (sa_x + x) < 0 || sa_y * (sa_y + y) < 0) { //this.visible = false; this.death = true; this.speed = 0; survivorState.keikenDel.push(this.spriteId); if (!survivorState.se_cool) { AudioManager.playSe({ name: "Item1", volume: 20, pitch: 150, pan: 0 }); survivorState.se_cool = 5; } } this.x += x; this.y += y; this.speed += 0.2; } }; Sprite_Keiken.prototype.setCharacterBitmap = function () { this.bitmap = ImageManager.loadCharacter("!Door2"); this.setFrame(48 * 3, 48 * 2, 48, 48); };