示例#1
0
        public static void MouseInputHandler(MouseButtons button, InGameEngine engine)
        {
            switch (button)
            {
            case MouseButtons.Left:
                engine.MainPlayer.Shoot();
                break;

            case MouseButtons.None:
                break;

            case MouseButtons.Right:
                break;

            case MouseButtons.Middle:
                break;

            case MouseButtons.XButton1:
                break;

            case MouseButtons.XButton2:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(button), button, null);
            }
        }
示例#2
0
        private static Colliding PlayerColliding(Player player, InGameEngine engine, Direction direction,
                                                 NormalMoveAnimation animation)
        {
            if (engine.Field.Objects.Where(o => o is Block)
                .Select(player.Cuts)
                .Any(cutting => (cutting != Direction.Nothing) && (animation.Direction == cutting)))
            {
                return(Colliding.Collided);
            }
            if (engine.Field.Objects.Where(o => o is Hole || o is Bullet)
                .Select(player.Cuts)
                .Any(cutting => cutting != Direction.Nothing))
            {
                return(Colliding.PlayerVanishing);
            }
            if (engine.Field.Objects.Where(o => o is Bullet)
                .Select(player.Cuts)
                .Any(cutting => cutting != Direction.Nothing))
            {
                return(Colliding.PlayerVanishing);
            }

            return((BiggerThanFieldX(player, engine.Field) &&
                    (direction == Direction.Right)) ||
                   (BiggerThanFieldY(player, engine.Field) &&
                    (direction == Direction.Down)) ||
                   ((player.Position.X < 0) &&
                    (direction == Direction.Left)) ||
                   ((player.Position.Y < 0) &&
                    (direction == Direction.Up))
                ? Colliding.Collided
                : Colliding.NoCollide);
        }
示例#3
0
        private static Colliding ObjectColliding(GameObject obj, InGameEngine engine, Animation animation)
        {
            var bullet = obj as Bullet;
            var player = obj as Player;

            if (bullet != null)
            {
                return(BulletColliding(bullet, engine));
            }
            if (player != null)
            {
                return(PlayerColliding(player, engine, ((NormalMoveAnimation)animation).Direction,
                                       (NormalMoveAnimation)animation));
            }
            return(Colliding.Nothing);
        }
示例#4
0
        private static Colliding BulletColliding(Bullet bullet, InGameEngine engine)
        {
            foreach (var o in engine.Field.Objects.Where(o => o is Block))
            {
                var cutting = bullet.Cuts(o);
                if (cutting == Direction.Nothing)
                {
                    continue;
                }
                return(bullet.AvailableCollisionCount > 0
                    ? ((cutting == Direction.Left) || (cutting == Direction.Right)
                        ? Colliding.ReboundedHorizontal
                        : Colliding.ReboundedVertical)
                    : Colliding.Collided);
            }
            if (engine.Field.Objects.Where(o => o is Player || o is Bullet).Select(p => p.Cuts(bullet)).Any(cutting => cutting != Direction.Nothing))
            {
                return(Colliding.Collided);
            }
            if (engine.Field.Objects.Any(o => o is Mine && o.Cuts(bullet) != Direction.Nothing))
            {
                return(Colliding.MineShooted);
            }
            var normalBullet = bullet as NormalBullet;

            if (normalBullet == null)
            {
                return(Colliding.Nothing);
            }
            var xInvalid = BiggerThanFieldX(normalBullet, engine.Field) || (normalBullet.Position.X < 0);
            var yinvalid = BiggerThanFieldY(normalBullet, engine.Field) || (normalBullet.Position.Y < 0);

            return(xInvalid || yinvalid
                ? (normalBullet.AvailableCollisionCount > 0
                    ? (xInvalid ? Colliding.ReboundedHorizontal : Colliding.ReboundedVertical)
                    : Colliding.Collided)
                : Colliding.NoCollide);
        }
示例#5
0
 private static Animation PlayerVanishing(InGameEngine engine, Player player)
 {
     player.Die();
     return(new ExplodeAnimation(engine.Field.Objects.Last(), 10,
                                 player.Size));
 }
示例#6
0
        private delegate void Del(GameObject obj); //Just that I've used a delegate in a more or less (here mainly less) useful way :)

        public static ObservableCollection <Animation> UpdateAnimations(IEnumerable <Animation> animations,
                                                                        InGameEngine engine)
        {
            var fin        = new ObservableCollection <Animation>();
            var enumerable = animations as IList <Animation> ?? animations.ToList();

            foreach (var animation in enumerable)
            {
                var animation1 = animation;
                var gameObject = engine.Field.Objects.FirstOrDefault(o => o.Id == animation1.AnimatedObject.Id);
                if (animation is AngularMoveAnimation || animation is NormalMoveAnimation)
                {
                    var colliding = ObjectColliding(animation.AnimatedObject, engine, animation);
                    switch (colliding)
                    {
                    case Colliding.NoCollide:
                        fin.Add(animation);
                        break;

                    case Colliding.Collided:
                        if (!(gameObject is Bullet))
                        {
                            break;
                        }
                        engine.Field.AddObject(AddableObjects.NotDestroyingExplosion, engine,
                                               gameObject.CenterPosition());
                        fin.Add(new ExplodeAnimation(engine.Field.Objects.Last(), 10f,
                                                     gameObject.Size.QuadraticForm()));
                        break;

                    case Colliding.ReboundedHorizontal:
                    case Colliding.ReboundedVertical:
                        if (gameObject == null)
                        {
                            break;
                        }
                        gameObject.Rotation = (colliding == Colliding.ReboundedHorizontal
                                                      ? 180 - gameObject.Rotation
                                                      : -gameObject.Rotation) % 360;
                        ((Bullet)gameObject).AvailableCollisionCount--;
                        fin.Add(new AngularMoveAnimation(gameObject, gameObject.Rotation, 10));
                        break;

                    case Colliding.PlayerVanishing:
                        fin.Add(PlayerVanishing(engine, (Player)gameObject));
                        break;

                    case Colliding.MineShooted:
                        ((Mine)engine.Field.Objects
                         .Where(o => o is Mine).First(m => engine.Field.Objects
                                                      .Any(b => b is Bullet && b.Cuts(m) != Direction.Nothing))).Timer = 0;
                        break;

                    case Colliding.Nothing:
                        throw new NotImplementedException("Colliding for this Object not yet implemented!");

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (animation is ExplodeAnimation && gameObject != null &&
                         ((ExplodeAnimation)animation).MaxSize.CompareTo(gameObject.Size) == 1)
                {
                    fin.Add(animation);
                    if (!((Explosion)animation.AnimatedObject).Destroying)
                    {
                        continue;
                    }
                    for (var j = 0; j < engine.Field.Objects.Count; j++)
                    {
                        var obj    = engine.Field.Objects[j];
                        var block  = obj as Block;
                        var player = obj as Player;
                        var mine   = obj as Mine;

                        Del explode = ob =>
                        {
                            engine.Field.AddObject(AddableObjects.NotDestroyingExplosion, engine, ob.CenterPosition());
                            fin.Add(new ExplodeAnimation(engine.Field.Objects.Last(), 5, ob.Size));
                        };
                        if (block != null && block.Destroyable &&
                            animation.AnimatedObject.Cuts(block) != Direction.Nothing)
                        {
                            engine.Field.Objects.Remove(block);
                            explode(block);
                        }
                        else if (player != null && animation.AnimatedObject.Cuts(player) != Direction.Nothing)
                        {
                            explode(player);
                            PlayerVanishing(engine, player);
                        }
                        else if (mine != null && animation.AnimatedObject.Cuts(mine) != Direction.Nothing)
                        {
                            mine.Timer = 0;
                        }
                    }
                }
                else if (animation is MineAnimation && gameObject != null)
                {
                    if ((gameObject as Mine)?.Timer > 0)
                    {
                        fin.Add(animation);
                    }
                    else
                    {
                        engine.Field.AddObject(AddableObjects.DestroyingExplosion, engine,
                                               animation.AnimatedObject.CenterPosition());
                        fin.Add(new ExplodeAnimation(engine.Field.Objects.Last(), 10,
                                                     ((Mine)animation.AnimatedObject).ExplosionSize));
                    }
                }
                else if (animation is RotationAnimation && gameObject != null)
                {
                    if (Math.Abs(((RotationAnimation)animation).Aim - gameObject.Rotation) > animation.Speed)
                    {
                        fin.Add(animation);
                    }
                    else
                    {
                        gameObject.Rotation = ((RotationAnimation)animation).Aim;
                    }
                }
            }
            var players = engine.Field.Objects.Where(f => f is Player).ToList();

            foreach (var player in players)
            {
                if (engine.Field.Objects.Where(o => o is Bullet)
                    .Select(player.Cuts)
                    .Any(cutting => cutting != Direction.Nothing))
                {
                    fin.Add(PlayerVanishing(engine, (Player)player));
                }
            }
            return(fin);
        }
示例#7
0
        public static void KeyInPutHandler(InGameEngine engine, Keys key, KeyHandlerAction action)
        {
            switch (key)
            {
            case Keys.KeyCode:
                break;

            case Keys.Modifiers:
                break;

            case Keys.None:
                break;

            case Keys.LButton:
                break;

            case Keys.RButton:
                break;

            case Keys.Cancel:
                break;

            case Keys.MButton:
                break;

            case Keys.XButton1:
                break;

            case Keys.XButton2:
                break;

            case Keys.Back:
                break;

            case Keys.Tab:
                break;

            case Keys.LineFeed:
                break;

            case Keys.Clear:
                break;

            case Keys.Return:
                break;

            case Keys.ShiftKey:
                break;

            case Keys.ControlKey:
                break;

            case Keys.Menu:
                break;

            case Keys.Pause:
                break;

            case Keys.Capital:
                break;

            case Keys.KanaMode:
                break;

            case Keys.JunjaMode:
                break;

            case Keys.FinalMode:
                break;

            case Keys.HanjaMode:
                break;

            case Keys.Escape:
                engine.Window.Close();
                break;

            case Keys.IMEConvert:
                break;

            case Keys.IMENonconvert:
                break;

            case Keys.IMEAccept:
                break;

            case Keys.IMEModeChange:
                break;

            case Keys.Space:
                break;

            case Keys.Prior:
                break;

            case Keys.Next:
                break;

            case Keys.End:
                break;

            case Keys.Home:
                break;

            case Keys.Left:
                break;

            case Keys.Up:
                break;

            case Keys.Right:
                break;

            case Keys.Down:
                engine.Window.WindowState = FormWindowState.Minimized;
                break;

            case Keys.Select:
                break;

            case Keys.Print:
                break;

            case Keys.Execute:
                break;

            case Keys.Snapshot:
                break;

            case Keys.Insert:
                break;

            case Keys.Delete:
                break;

            case Keys.Help:
                break;

            case Keys.D0:
                break;

            case Keys.D1:
                break;

            case Keys.D2:
                break;

            case Keys.D3:
                break;

            case Keys.D4:
                break;

            case Keys.D5:
                break;

            case Keys.D6:
                break;

            case Keys.D7:
                break;

            case Keys.D8:
                break;

            case Keys.D9:
                break;

            case Keys.A:
                switch (action)
                {
                case KeyHandlerAction.Down:
                    engine.MainPlayer.Move(Direction.Left);
                    break;

                case KeyHandlerAction.Up:
                    engine.MainPlayer.StopMoving(Direction.Left);
                    break;
                }
                break;

            case Keys.B:
                break;

            case Keys.C:
                break;

            case Keys.D:
                switch (action)
                {
                case KeyHandlerAction.Down:
                    engine.MainPlayer.Move(Direction.Right);
                    break;

                case KeyHandlerAction.Up:
                    engine.MainPlayer.StopMoving(Direction.Right);
                    break;
                }
                break;

            case Keys.E:
                break;

            case Keys.F:
                break;

            case Keys.G:
                break;

            case Keys.H:
                break;

            case Keys.I:
                break;

            case Keys.J:
                break;

            case Keys.K:
                break;

            case Keys.L:
                break;

            case Keys.M:
                break;

            case Keys.N:
                break;

            case Keys.O:
                break;

            case Keys.P:
                break;

            case Keys.Q:
                break;

            case Keys.R:
                break;

            case Keys.S:
                switch (action)
                {
                case KeyHandlerAction.Down:
                    engine.MainPlayer.Move(Direction.Down);
                    break;

                case KeyHandlerAction.Up:
                    engine.MainPlayer.StopMoving(Direction.Down);
                    break;
                }
                break;

            case Keys.T:
                break;

            case Keys.U:
                break;

            case Keys.V:
                break;

            case Keys.W:
                switch (action)
                {
                case KeyHandlerAction.Down:
                    engine.MainPlayer.Move(Direction.Up);
                    break;

                case KeyHandlerAction.Up:
                    engine.MainPlayer.StopMoving(Direction.Up);
                    break;
                }
                break;

            case Keys.X:
                break;

            case Keys.Y:
                break;

            case Keys.Z:
                break;

            case Keys.LWin:
                break;

            case Keys.RWin:
                break;

            case Keys.Apps:
                break;

            case Keys.Sleep:
                break;

            case Keys.NumPad0:
                break;

            case Keys.NumPad1:
                break;

            case Keys.NumPad2:
                break;

            case Keys.NumPad3:
                break;

            case Keys.NumPad4:
                break;

            case Keys.NumPad5:
                break;

            case Keys.NumPad6:
                break;

            case Keys.NumPad7:
                break;

            case Keys.NumPad8:
                break;

            case Keys.NumPad9:
                break;

            case Keys.Multiply:
                break;

            case Keys.Add:
                break;

            case Keys.Separator:
                break;

            case Keys.Subtract:
                break;

            case Keys.Decimal:
                break;

            case Keys.Divide:
                break;

            case Keys.F1:
                break;

            case Keys.F2:
                break;

            case Keys.F3:
                if (action == KeyHandlerAction.Up)
                {
                    engine.Debugging = !engine.Debugging;
                }
                break;

            case Keys.F4:
                break;

            case Keys.F5:
                break;

            case Keys.F6:
                break;

            case Keys.F7:
                break;

            case Keys.F8:
                break;

            case Keys.F9:
                break;

            case Keys.F10:
                break;

            case Keys.F11:
                break;

            case Keys.F12:
                break;

            case Keys.F13:
                break;

            case Keys.F14:
                break;

            case Keys.F15:
                break;

            case Keys.F16:
                break;

            case Keys.F17:
                break;

            case Keys.F18:
                break;

            case Keys.F19:
                break;

            case Keys.F20:
                break;

            case Keys.F21:
                break;

            case Keys.F22:
                break;

            case Keys.F23:
                break;

            case Keys.F24:
                break;

            case Keys.NumLock:
                break;

            case Keys.Scroll:
                break;

            case Keys.LShiftKey:
                break;

            case Keys.RShiftKey:
                break;

            case Keys.LControlKey:
                break;

            case Keys.RControlKey:
                break;

            case Keys.LMenu:
                break;

            case Keys.RMenu:
                break;

            case Keys.BrowserBack:
                break;

            case Keys.BrowserForward:
                break;

            case Keys.BrowserRefresh:
                break;

            case Keys.BrowserStop:
                break;

            case Keys.BrowserSearch:
                break;

            case Keys.BrowserFavorites:
                break;

            case Keys.BrowserHome:
                break;

            case Keys.VolumeMute:
                break;

            case Keys.VolumeDown:
                break;

            case Keys.VolumeUp:
                break;

            case Keys.MediaNextTrack:
                break;

            case Keys.MediaPreviousTrack:
                break;

            case Keys.MediaStop:
                break;

            case Keys.MediaPlayPause:
                break;

            case Keys.LaunchMail:
                break;

            case Keys.SelectMedia:
                break;

            case Keys.LaunchApplication1:
                break;

            case Keys.LaunchApplication2:
                break;

            case Keys.OemSemicolon:
                break;

            case Keys.Oemplus:
                break;

            case Keys.Oemcomma:
                break;

            case Keys.OemMinus:
                break;

            case Keys.OemPeriod:
                break;

            case Keys.OemQuestion:
                break;

            case Keys.Oemtilde:
                break;

            case Keys.OemOpenBrackets:
                break;

            case Keys.OemPipe:
                break;

            case Keys.OemCloseBrackets:
                break;

            case Keys.OemQuotes:
                break;

            case Keys.Oem8:
                break;

            case Keys.OemBackslash:
                break;

            case Keys.ProcessKey:
                break;

            case Keys.Packet:
                break;

            case Keys.Attn:
                break;

            case Keys.Crsel:
                break;

            case Keys.Exsel:
                break;

            case Keys.EraseEof:
                break;

            case Keys.Play:
                break;

            case Keys.Zoom:
                break;

            case Keys.NoName:
                break;

            case Keys.Pa1:
                break;

            case Keys.OemClear:
                break;

            case Keys.Shift:
                break;

            case Keys.Control:
                break;

            case Keys.Alt:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }