public void Update(Point playerPoint) { if (_homing) { switch (_homingState) { case 0: if (_point.Y >= playerPoint.Y) { Direction = new Direction8(5); _homingState = 1; } break; case 1: _frame++; if (_frame <= 30) { return; } Direction = new Direction8( (byte)(Point.X < playerPoint.X ? 6 : 4)); _homingState = 2; break; } } const int speed = 5; const int skewSpeed = (short)(speed / 1.41421356); switch (Direction.Value) { case 8: _point.Y -= speed; break; case 9: _point.X += skewSpeed; _point.Y -= skewSpeed; break; case 6: _point.X += speed; break; case 3: _point.X += skewSpeed; _point.Y += skewSpeed; break; case 2: _point.Y += speed; break; case 1: _point.X -= skewSpeed; _point.Y += skewSpeed; break; case 4: _point.X -= speed; break; case 7: _point.X -= skewSpeed; _point.Y -= skewSpeed; break; } }
public int GetEarliest(Direction8 target) { int ti = Array.IndexOf(Directions, target._value); int ci = Array.IndexOf(Directions, _value); int i = ti - ci; if (i < 0) i += Directions.Length; else if (i >= Directions.Length) i -= Directions.Length; if (i < 4) return 1; else if (i != 4) return -1; return 0; }
// ReSharper restore InconsistentNaming public Character() { Life = 1; Direction = new Direction8(8); }
public void Update(Point playerPoint) { base.Update(); if (Life <= 0) return; _frame++; switch (State) { case MovingState.Group: if (_go) { State = _random.Next(2) == 0 ? MovingState.TurnLeft : MovingState.TurnRight; _frame = 0; } break; case MovingState.TurnLeft: case MovingState.TurnRight: if (_frame >= TurnTime * 4) { State = MovingState.Attack; Direction = new Direction8(2); _frame = 0; } break; case MovingState.Attack: if (Type == EnemyType.Gold && _random.Next(85) == 0) { _vectorX = 0; State = MovingState.SpinAttack; _frame = 0; } break; case MovingState.SpinAttack: if (Direction.Value == 2 && _random.Next(10) == 0) { State = MovingState.Attack; } break; } switch (State) { case MovingState.Group: int myFrame = _frame % 140; if (myFrame < 35) { _point.X += Speed; } else if (myFrame < 35 + 70) { _point.X -= Speed; } else { _point.X += Speed; } break; case MovingState.TurnLeft: Direction = new Direction8((byte)(_frame < TurnTime ? 8 : _frame < TurnTime * 2 ? 7 : _frame < TurnTime * 3 ? 4 : 1)); TurnMove(); break; case MovingState.TurnRight: Direction = new Direction8((byte)(_frame < TurnTime ? 8 : _frame < TurnTime * 2 ? 9 : _frame < TurnTime * 3 ? 6 : 3)); TurnMove(); break; case MovingState.Attack: // 移動 if (_point.X < playerPoint.X) _vectorX += Type == EnemyType.Blue ? 0.2 : 0.1; else if (_point.X > playerPoint.X) _vectorX -= Type == EnemyType.Blue ? 0.2 : 0.1; if (_vectorX > VectorMax) _vectorX = VectorMax; else if (_vectorX < -VectorMax) _vectorX = -VectorMax; _point.Y += Speed; _point.X += (short)_vectorX; // 旋回 if (Type == EnemyType.Blue || Type == EnemyType.Red || Type == EnemyType.Silver) { double radian = GetRadian(Point, playerPoint); Direction = Direction8.FromRadian(radian); if (Type == EnemyType.Blue || Type == EnemyType.Silver) { switch (Direction.Value) { case 8: Direction = new Direction8(2); break; case 7: case 4: Direction = new Direction8(1); break; case 9: case 6: Direction = new Direction8(3); break; } } } // 攻撃 if (_random.Next(100) == 0) Shot(this, EventArgs.Empty); if (_frame < TurnTime) break; Turn(); break; case MovingState.SpinAttack: if (_frame == 0) Shot(this, EventArgs.Empty); if (_frame < 3) break; Direction = Direction.TurnRight(); _frame = -1; break; } // 行動範囲制限 if (_point.Y >= Point.Height) _point.Y -= Point.Height; if (_point.X >= Point.Width - 13) { _point.X = Point.Width - 13 - 1; _vectorX = 0; } if (_point.X < 13) { _point.X = 13; _vectorX = 0; } }
public void Update(Input input, bool canShot) { base.Update(); if (Life <= 0) return; byte direction; if (_firstTime) { direction = input.Direction; _firstTime = false; } else { direction = input.DirectionToggled ? input.Direction : (byte)0; } bool shot = input.ShotToggled && input.Shot; if (direction > 0) Direction = new Direction8(direction); if (_reloadTime == 0) { if (canShot && shot) { Shot(this, EventArgs.Empty); ShotCount++; _reloadTime = 8; } } else { _reloadTime--; } switch (Direction.Value) { case 7: case 4: case 1: _point.X -= Speed; break; case 9: case 6: case 3: _point.X += Speed; break; } switch (Direction.Value) { case 7: case 8: case 9: _point.Y -= Speed; break; case 1: case 2: case 3: _point.Y += Speed; break; } if (_point.Y < EnemyArea) _point.Y = EnemyArea; if (_point.Y >= Point.Height - SafeArea) _point.Y = Point.Height - SafeArea - 1; if (_point.X >= Point.Width - SafeArea) _point.X = Point.Width - SafeArea - 1; if (_point.X < SafeArea) _point.X = SafeArea; }
public Shot(Direction8 direction, Point point, bool homing) { Direction = direction; _point = point; _homing = homing; }