private static Point GetEnemyInitialPosition(Maze maze, Player player) { // プレイヤーから6ます以上離す Point enemyPosition; while (true) { enemyPosition = maze.RandomPoint(); if (Math.Sqrt((player.Position2.X - enemyPosition.X) * (player.Position2.X - enemyPosition.X) + (player.Position2.Y - enemyPosition.Y) * (player.Position2.Y - enemyPosition.Y)) > 6) { return enemyPosition; } } }
/// <summary> /// メインゲームシーン /// </summary> /// <param name="content"></param> /// <param name="graphicsDevice"></param> /// <param name="input"></param> public GameIn(ContentManager content, GraphicsDevice graphicsDevice, GameTime gameTime, StageSelect.SelectStage selectStage, StageSelect.SelectEnemy selectEnemy) { this.content = content; this.graphicsDevice = graphicsDevice; this.selectStage = selectStage; // 乱数の初期化 rand = new Random(); // 迷路初期化。難易度によって大きさを変える maze = new Maze(content, selectStage); Point playerPosition; Point goalPosition; while (true) { playerPosition = maze.RandomPoint(); goalPosition = maze.RandomPoint(); // 迷路の斜辺の長さを求める。三平方の定理 c^2 = sqrt(a^2 + b^2) double hypotenuse = Math.Sqrt(maze.Width * maze.Width + maze.Height * maze.Height); // 0.5斜辺 < 距離 < 0.6斜辺ならOK double distance = Math.Sqrt((playerPosition.X - goalPosition.X) * (playerPosition.X - goalPosition.X) + (playerPosition.Y - goalPosition.Y) * (playerPosition.Y - goalPosition.Y)); if (hypotenuse * 0.5 < distance && distance < hypotenuse * 0.6) { break; } } //プレイヤー初期化 player = new Player(content, playerPosition, Collidable.Collidable.Orientation.East, maze); //ゴール初期化 goalobj = new GoalObject(content, goalPosition, Collidable.Collidable.Orientation.East, maze); // Enemyマネージャ初期化 enemyManager = new EnemyManager(content, selectEnemy, selectStage, maze, player); //背景モデルの宣言 backmodel = new BackGround(content); //カメラの初期設定 camera = new Camera(player); // ミニマップの初期化 miniMap = new MiniMap(content, graphicsDevice); // スコアの初期化 score = new Score(content, graphicsDevice, gameTime, selectStage); //フェードアウト処理 fadeout = new FadeOut(content, graphicsDevice, FadeOut.SceneType.InGame); // カウントダウン countdown = new CountDown(content, graphicsDevice, gameTime); // BGMの再生 cueBGM = SoundManager.Instance.SoundBank.GetCue("game"); }