private int 索敵(double R) // ? { -1, 0, 1 } == { 上に居る, 見つからない, 下に居る } { double X_SPAN_後方 = R; double X_SPAN_前方 = 5.0; double X_SPAN_L; double X_SPAN_R; if (this.FacingLeft) // ? 左へ進行している。 { X_SPAN_L = X_SPAN_前方; // 左が前方 X_SPAN_R = X_SPAN_後方; // 右が後方 } else { X_SPAN_L = X_SPAN_後方; // 左が後方 X_SPAN_R = X_SPAN_前方; // 右が前方 } foreach (Enemy enemy in Game.I.Enemies.Iterate()) { if ( 1 <= enemy.HP && !DDUtils.IsOutOfCamera(new D2Point(enemy.X, enemy.Y)) && SCommon.IsRange(enemy.X, this.X - X_SPAN_L, this.X + X_SPAN_R) ) { return(enemy.Y < this.Y ? -1 : 1); } } return(0); }
/// <summary> /// 周辺テーブルを作成する。 /// </summary> /// <param name="x">指定座標(X-座標_ドット単位)</param> /// <param name="y">指定座標(Y-座標_ドット単位)</param> /// <param name="size">周辺テーブルの幅・高さ</param> public Around(int x, int y, int size) { I2Point pt = new I2Point(x, y); this.Size = size; this.Table = new MapCell[size, size]; // 周辺テーブルの左上へ移動 x -= (size - 1) * GameConsts.TILE_W / 2; y -= (size - 1) * GameConsts.TILE_H / 2; const int TMP_SPAN = 1000; // マップ座標(ドット単位) -> マップテーブル座標 x += GameConsts.TILE_W * TMP_SPAN; y += GameConsts.TILE_W * TMP_SPAN; x /= GameConsts.TILE_W; y /= GameConsts.TILE_H; x -= TMP_SPAN; y -= TMP_SPAN; for (int xc = 0; xc < size; xc++) { for (int yc = 0; yc < size; yc++) { this.Table[xc, yc] = Game.I.Map.GetCell(x + xc, y + yc); } } // マップテーブル座標 -> マップ座標(ドット単位) x += TMP_SPAN; y += TMP_SPAN; x *= GameConsts.TILE_W; y *= GameConsts.TILE_H; x -= GameConsts.TILE_W * TMP_SPAN; y -= GameConsts.TILE_W * TMP_SPAN; // 周辺テーブルの中心へ移動 x += size * GameConsts.TILE_W / 2; y += size * GameConsts.TILE_H / 2; this.CenterPoint = new I2Point(x, y); this.RelativePoint = new I2Point(pt.X - x, pt.Y - y); if (!SCommon.IsRange(this.RelativePoint.X, -16, 15)) { ProcMain.WriteLog("RP_X: " + this.RelativePoint.X); // test } if (!SCommon.IsRange(this.RelativePoint.Y, -16, 15)) { ProcMain.WriteLog("RP_Y: " + this.RelativePoint.Y); // test } }
public bool IsCookie() { return(SCommon.IsRange((int)this.Kind, (int)Kind_e.COOKIE_時計回り_1, (int)Kind_e.COOKIE_反時計回り_9)); }
public static void Shoot(Enemy enemy, int shotType) { if (DDUtils.IsOut(new D2Point(enemy.X, enemy.Y), new D4Rect(0, 0, GameConsts.FIELD_W, GameConsts.FIELD_H))) // ? フィールド外 { return; } switch (shotType) { case 0: // ショット無し break; case 100: // 自機狙い_Normal_W case 101: // 自機狙い_Normal_R { int frm = enemy.OnFieldFrame; int cyc = 10; int div = frm / cyc; int mod = frm % cyc; if (mod == 0 && SCommon.IsRange(div, 3, 12)) { TAMA_COLOR_e color; switch (shotType) { case 100: color = TAMA_COLOR_e.WHITE; break; case 101: color = TAMA_COLOR_e.RED; break; default: throw null; // never } Game.I.Enemies.Add(new Enemy_Tama_01(enemy.X, enemy.Y, TAMA_KIND_e.NORMAL, color, 4.0, 0.0)); } } break; case 110: // 自機狙い_Normal_W + 吸収 case 111: // 自機狙い_Normal_R + 吸収 { int frm = enemy.OnFieldFrame; int cyc = 10; int div = frm / cyc; int mod = frm % cyc; if (mod == 0 && SCommon.IsRange(div, 3, 12)) { if (div == 3) { int absorbableWeapon; switch (shotType) { case 110: absorbableWeapon = 1; break; case 111: absorbableWeapon = 2; break; default: throw null; // never } Game.I.Enemies.Add(new Enemy_Tama_01(enemy.X, enemy.Y, TAMA_KIND_e.NORMAL, TAMA_COLOR_e.BLUE, 4.0, 0.0, absorbableWeapon)); } else { TAMA_COLOR_e color; switch (shotType) { case 110: color = TAMA_COLOR_e.WHITE; break; case 111: color = TAMA_COLOR_e.RED; break; default: throw null; // never } Game.I.Enemies.Add(new Enemy_Tama_01(enemy.X, enemy.Y, TAMA_KIND_e.NORMAL, color, 4.0, 0.0)); } } } break; case 200: // 三角形_Normal_W { int frm = enemy.OnFieldFrame; int cyc = 5; int div = frm / cyc; int mod = frm % cyc; div -= 10; div %= 15; if (mod == 0 && SCommon.IsRange(div, 0, 5)) { TAMA_COLOR_e color; switch (shotType) { case 200: color = TAMA_COLOR_e.WHITE; break; default: throw null; // never } for (int c = 0; c <= div; c++) { double angleStep = 0.1; double angle = c * angleStep - div * angleStep / 2.0; Game.I.Enemies.Add(new Enemy_Tama_01(enemy.X, enemy.Y, TAMA_KIND_e.NORMAL, color, 5.0, angle)); } } } break; case 210: // 三角形_Normal_W + 吸収 { int frm = enemy.OnFieldFrame; int cyc = 5; int div = frm / cyc; int mod = frm % cyc; div -= 10; div %= 15; if (mod == 0 && SCommon.IsRange(div, 0, 5)) { for (int c = 0; c <= div; c++) { double angleStep = 0.1; double angle = c * angleStep - div * angleStep / 2.0; TAMA_COLOR_e color = TAMA_COLOR_e.YELLOW; int absorbableWeapon = -1; if (div == 5 && (c == 0 || c == 5)) { color = TAMA_COLOR_e.BLUE; absorbableWeapon = 3; } Game.I.Enemies.Add(new Enemy_Tama_01(enemy.X, enemy.Y, TAMA_KIND_e.NORMAL, color, 5.0, angle, absorbableWeapon)); } } } break; default: throw null; // never } }
public bool PlayerWasDead = false; // 死亡すると true にセットされる。 public void Perform() { DDUtils.Random = new DDRandom(1u, 1u, 1u, 1u); // 電源パターン確保のため DDCurtain.SetCurtain(); DDEngine.FreezeInput(); Func <bool> f_ゴミ回収 = SCommon.Supplier(this.E_ゴミ回収()); // reset { RippleEffect.Clear(); 画面分割.Enabled = false; } this.Player.Reset(false); // ★★★★★ ステータス反映 { this.Score = this.Status.Score; this.Player.Power = this.Status.PlayerPower; this.Zanki = this.Status.PlayerZanki; this.ZanBomb = this.Status.PlayerZanBomb; } for (this.Frame = 0; ; this.Frame++) { if (!this.Script.EachFrame()) // シナリオ進行 { break; } if (DDConfig.LOG_ENABLED) // チート機能 { if (DDKey.IsPound(DX.KEY_INPUT_PGUP)) { this.Player.Power += GameConsts.PLAYER_POWER_PER_LEVEL; } if (DDKey.IsPound(DX.KEY_INPUT_PGDN)) { this.Player.Power -= GameConsts.PLAYER_POWER_PER_LEVEL; } DDUtils.ToRange(ref this.Player.Power, 0, GameConsts.PLAYER_POWER_MAX); } if (DDInput.PAUSE.GetInput() == 1 && 10 < this.Frame) // ポーズ { this.Pause(); if (this.Pause_RestartGame) { GameMaster.RestartFlag = true; break; } if (this.Pause_ReturnToTitleMenu) { GameMaster.ReturnToTitleMenu = true; break; } } if (DDConfig.LOG_ENABLED && DDKey.GetInput(DX.KEY_INPUT_RETURN) == 1) { this.DebugPause(); } this.LastInput = this.Input; // 前回のプレイヤー入力を退避 // プレイヤー入力 { this.Input.Dir2 = 1 <= DDInput.DIR_2.GetInput(); this.Input.Dir4 = 1 <= DDInput.DIR_4.GetInput(); this.Input.Dir6 = 1 <= DDInput.DIR_6.GetInput(); this.Input.Dir8 = 1 <= DDInput.DIR_8.GetInput(); this.Input.Slow = 1 <= DDInput.A.GetInput(); this.Input.Shoot = 1 <= DDInput.B.GetInput(); this.Input.Bomb = 1 <= DDInput.C.GetInput(); } this.Player.LastX = this.Player.X; this.Player.LastY = this.Player.Y; startBornPlayer: if (1 <= this.Player.BornFrame) // プレイヤー登場中の処理 { int frm = this.Player.BornFrame - 1; if (GameConsts.PLAYER_BORN_FRAME_MAX < frm) { this.Player.BornFrame = 0; goto endBornPlayer; } this.Player.BornFrame++; double rate = (double)frm / GameConsts.PLAYER_BORN_FRAME_MAX; if (frm == 0) // init { this.Player.BornFollowX = GameConsts.FIELD_W * 0.5; this.Player.BornFollowY = GameConsts.FIELD_H * 1.2; } double approachingRate = 0.99 - 0.01 * frm; DDUtils.ToRange(ref approachingRate, 0.0, 1.0); DDUtils.Approach(ref this.Player.BornFollowX, this.Player.X, approachingRate); DDUtils.Approach(ref this.Player.BornFollowY, this.Player.Y, approachingRate); } endBornPlayer: //startDeadPlayer: if (1 <= this.Player.DeadFrame) // プレイヤー死亡中の処理 { int frm = this.Player.DeadFrame - 1; if (GameConsts.PLAYER_DEAD_FRAME_MAX < frm) { if (this.Zanki <= 0) // 残機不足のため終了 { GameMaster.ReturnToTitleMenu = true; break; } this.Zanki--; this.Player.Reset(true); goto startBornPlayer; } this.Player.DeadFrame++; if (frm == 0) // init { this.DeadPlayerMoment(); this.PlayerEffects.Add(SCommon.Supplier(Effects.PlayerDead(this.Player.X, this.Player.Y))); } goto endPlayerMove; } //endDeadPlayer: //startBombPlayer: if (1 <= this.Player.BombFrame) // ボム使用中の処理 { int frm = this.Player.BombFrame - 1; if (GameConsts.PLAYER_BOMB_FRAME_MAX < frm) { this.Player.BombFrame = 0; goto endBombPlayer; } this.Player.BombFrame++; if (frm == 0) // init { this.Player.Bomb(); } } endBombPlayer: //startPlayerMove: // プレイヤー移動 { bool d2 = this.Input.Dir2; bool d4 = this.Input.Dir4; bool d6 = this.Input.Dir6; bool d8 = this.Input.Dir8; double speed; if (this.Input.Slow) { speed = 2.5; } else { speed = 5.0; } double nanameSpeed = speed / Math.Sqrt(2.0); if (d2 && d4) // 左下 { this.Player.X -= nanameSpeed; this.Player.Y += nanameSpeed; } else if (d2 && d6) // 右下 { this.Player.X += nanameSpeed; this.Player.Y += nanameSpeed; } else if (d4 && d8) // 左上 { this.Player.X -= nanameSpeed; this.Player.Y -= nanameSpeed; } else if (d6 && d8) // 右上 { this.Player.X += nanameSpeed; this.Player.Y -= nanameSpeed; } else if (d2) // 下 { this.Player.Y += speed; } else if (d4) // 左 { this.Player.X -= speed; } else if (d6) // 右 { this.Player.X += speed; } else if (d8) // 上 { this.Player.Y -= speed; } DDUtils.ToRange(ref this.Player.X, 0.0, (double)GameConsts.FIELD_W); DDUtils.ToRange(ref this.Player.Y, 0.0, (double)GameConsts.FIELD_H); if (d4) // 左 { DDUtils.Minim(ref this.Player.XMoveFrame, 0); this.Player.XMoveFrame--; } else if (d6) // 右 { DDUtils.Maxim(ref this.Player.XMoveFrame, 0); this.Player.XMoveFrame++; } else { this.Player.XMoveFrame = 0; } if (d8) // 上 { DDUtils.Minim(ref this.Player.YMoveFrame, 0); this.Player.YMoveFrame--; } else if (d2) // 下 { DDUtils.Maxim(ref this.Player.YMoveFrame, 0); this.Player.YMoveFrame++; } else { this.Player.YMoveFrame = 0; } DDUtils.Approach(ref this.Player.XMoveRate, DDUtils.Sign(this.Player.XMoveFrame), 0.95); DDUtils.Approach(ref this.Player.YMoveRate, DDUtils.Sign(this.Player.YMoveFrame), 0.95); } endPlayerMove: if (this.Input.Slow) { DDUtils.Maxim(ref this.Player.SlowFrame, 0); this.Player.SlowFrame++; } else { DDUtils.Minim(ref this.Player.SlowFrame, 0); this.Player.SlowFrame--; } if (this.Input.Shoot) { DDUtils.Maxim(ref this.Player.ShootFrame, 0); this.Player.ShootFrame++; } else { DDUtils.Minim(ref this.Player.ShootFrame, 0); this.Player.ShootFrame--; } DDUtils.Approach(ref this.Player.SlowRate, this.Player.SlowFrame < 0 ? 0.0 : 1.0, 0.85); DDUtils.Approach(ref this.Player.ShootRate, this.Player.ShootFrame < 0 ? 0.0 : 1.0, 0.85); if (this.LastInput.Shoot && this.Input.Shoot && SCommon.IsRange(this.Player.SlowFrame, -1, 1)) // ? ショット中に低速・高速を切り替えた。 { this.Player.ShootRate = 0.0; } // ---- if (this.Input.Shoot && this.Player.DeadFrame == 0) // プレイヤー攻撃 { this.Player.Shoot(); } if (this.Input.Bomb && this.Player.DeadFrame == 0 && this.Player.BombFrame == 0 && 1 <= this.ZanBomb) // ボム使用 { this.ZanBomb--; this.Player.BombFrame = 1; } // 当たり判定 reset { this.PlayerCrashes.Clear(); this.GrazeCrashes.Clear(); this.EnemyCrashes.Clear(); this.ShotCrashes.Clear(); } this.Player.Put当たり判定(); // ==== // 描画ここから // ==== // Swap { DDSubScreen tmp = this.Field; this.Field = this.Field_Last; this.Field_Last = tmp; } using (this.Field.Section()) // フィールド描画 { // Walls { int filledIndex = -1; for (int index = 0; index < this.Walls.Count; index++) { Wall wall = this.Walls[index]; if (!wall.Draw()) { this.Walls[index] = null; } else if (wall.Filled) { filledIndex = index; } } for (int index = 0; index < filledIndex; index++) { this.Walls[index] = null; } this.Walls.RemoveAll(v => v == null); } RippleEffect.EachFrame(this.Field); this.EL_AfterDrawWalls.ExecuteAllTask(); // Shots { for (int index = 0; index < this.Shots.Count; index++) { Shot shot = this.Shots[index]; if (!shot.Draw()) { this.Shots[index] = null; } } this.Shots.RemoveAll(v => v == null); } this.EL_AfterDrawShots.ExecuteAllTask(); if (this.Player.DeadFrame == 0) { this.Player.Draw(); } this.EL_AfterDrawPlayer.ExecuteAllTask(); // Enemies { foreach (Enemy.Kind_e kind in new Enemy.Kind_e[] { Enemy.Kind_e.ENEMY, Enemy.Kind_e.TAMA, Enemy.Kind_e.ITEM, }) { for (int index = 0; index < this.Enemies.Count; index++) { Enemy enemy = this.Enemies[index]; if (enemy != null && enemy.Kind == kind) { if (!enemy.Draw()) { this.Enemies[index] = null; } } } } this.Enemies.RemoveAll(v => v == null); } this.EnemyEffects.ExecuteAllTask(); this.PlayerEffects.ExecuteAllTask(); // 当たり判定表示 // -- デバッグ用だが、ボタン設定に割り当てがあるので、常に使えるようにする。 if (1 <= DDInput.R.GetInput()) { this.Draw当たり判定(); } 画面分割.EachFrame(this.Field); } { DDUtils.Approach(ref this.BackgroundSlideRate, this.Player.Y * 1.0 / GameConsts.FIELD_H, 0.99); // HACK D4Rect rect = DDUtils.AdjustRectExterior( new D2Size(GameConsts.FIELD_W, GameConsts.FIELD_H), new D4Rect(0, 0, DDConsts.Screen_W, DDConsts.Screen_H), this.BackgroundSlideRate //this.Player.Y * 1.0 / GameConsts.FIELD_H ); DDDraw.DrawRect(this.Field.ToPicture(), rect); } { const int MARGIN = 5; DDDraw.SetBright(0, 0, 0); DDDraw.DrawRect( Ground.I.Picture.WhiteBox, GameConsts.FIELD_L - MARGIN, GameConsts.FIELD_T - MARGIN, GameConsts.FIELD_W + MARGIN * 2, GameConsts.FIELD_H + MARGIN * 2 ); DDDraw.Reset(); } DX.GraphFilter( DDGround.MainScreen.GetHandle(), DX.DX_GRAPH_FILTER_GAUSS, 16, SCommon.ToInt(500.0) ); DDCurtain.DrawCurtain(-0.2); DDDraw.DrawSimple(this.Field.ToPicture(), GameConsts.FIELD_L, GameConsts.FIELD_T); this.DrawStatus(); this.SurfaceManager.Draw(); // ==== // 描画ここまで // ==== foreach (Enemy enemy in this.Enemies.Iterate()) { if (!DDUtils.IsOut(new D2Point(enemy.X, enemy.Y), new D4Rect(0, 0, GameConsts.FIELD_W, GameConsts.FIELD_H))) // ? フィールド内 { DDUtils.CountDown(ref enemy.TransFrame); enemy.OnFieldFrame++; } } this.当たり判定(); if (this.AH_Grazed) { if ( 1 <= this.Player.BornFrame || 1 <= this.Player.DeadFrame ) { // 登場中・死亡中は何もしない。 } else { Ground.I.SE.SE_KASURI.Play(); this.Score++; } } if (this.AH_PlayerCrashedFlag) { if ( 1 <= this.Player.BornFrame || 1 <= this.Player.DeadFrame || 1 <= this.Player.BombFrame ) { // 登場中・死亡中・ボム使用中は何もしない。 } else { this.Player.DeadFrame = 1; // プレイヤー死亡 this.PlayerWasDead = true; } } if (Ground.I.HiScore < this.Score) { if (Ground.I.HiScore + 10L < this.Score) { Ground.I.HiScore -= this.Score; Ground.I.HiScore /= 2L; Ground.I.HiScore += this.Score; } else { Ground.I.HiScore++; } } f_ゴミ回収(); this.Enemies.RemoveAll(v => v.HP == -1); this.Shots.RemoveAll(v => v.Vanished); DDEngine.EachFrame(); // ★★★ ゲームループの終わり ★★★ } DDUtils.Maxim(ref Ground.I.HiScore, this.Score); // 確実な同期 // ★★★★★ ステータス反映 { this.Status.Score = this.Score; this.Status.PlayerPower = this.Player.Power; this.Status.PlayerZanki = this.Zanki; this.Status.PlayerZanBomb = this.ZanBomb; } DDMain.KeepMainScreen(); DDMusicUtils.Fade(); DDCurtain.SetCurtain(60, -1.0); foreach (DDScene scene in DDSceneUtils.Create(120)) { DDDraw.DrawRect(DDGround.KeptMainScreen.ToPicture(), 0, 0, DDConsts.Screen_W, DDConsts.Screen_H); DDEngine.EachFrame(); } // ★★★ end of Perform() ★★★ }
public void Test01() { for (int frame = 0; ; frame++) { DDCurtain.DrawCurtain(); DDPrint.SetPrint(0, 16); DDPrint.Print("" + frame); switch (frame) { case 60: ProcMain.WriteLog("*1 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // False, False DDSoundUtils.Play(Ground.I.Music.Title.Sound.GetHandle(0), false, false); //Ground.I.Music.Title.Play(); // タイムラグ有り ProcMain.WriteLog("*2 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, True break; case 120: ProcMain.WriteLog("*3 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, True DDSoundUtils.Stop(Ground.I.Music.Title.Sound.GetHandle(0)); //DDMusicUtils.Stop(); // タイムラグ有り ProcMain.WriteLog("*4 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, False break; case 180: ProcMain.WriteLog("*5 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, False DDSoundUtils.Play(Ground.I.Music.Title.Sound.GetHandle(0), false, false); ProcMain.WriteLog("*6 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, True break; case 240: ProcMain.WriteLog("*7 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, True DDSoundUtils.Stop(Ground.I.Music.Title.Sound.GetHandle(0)); ProcMain.WriteLog("*8 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, False break; case 300: ProcMain.WriteLog("*9 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, False DDSoundUtils.Play(Ground.I.Music.Title.Sound.GetHandle(0), false, false); ProcMain.WriteLog("*10 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, True DDSoundUtils.Stop(Ground.I.Music.Title.Sound.GetHandle(0)); ProcMain.WriteLog("*11 " + Ground.I.Music.Title.Sound.IsLoaded() + ", " + Ground.I.Music.Title.Sound.IsPlaying()); // True, False break; case 360: ProcMain.WriteLog("*12 " + Ground.I.SE.Jump.Sound.IsLoaded() + ", " + Ground.I.SE.Jump.Sound.IsPlaying()); // False, False DDSoundUtils.Play(Ground.I.SE.Jump.Sound.GetHandle(0), true, false); ProcMain.WriteLog("*13 " + Ground.I.SE.Jump.Sound.IsLoaded() + ", " + Ground.I.SE.Jump.Sound.IsPlaying()); // True, True break; } if (SCommon.IsRange(frame, 361, 419)) { ProcMain.WriteLog("*14 " + Ground.I.SE.Jump.Sound.IsLoaded() + ", " + Ground.I.SE.Jump.Sound.IsPlaying()); // True, True ~ True, False } DDEngine.EachFrame(); } }