Пример #1
0
        public void LoadFromDisk(QuickGameScene scene)
        {
            var         formatter = new BinaryFormatter();
            MapSaveInfo mapInfo;

            using (var stream = GetFileStream(scene.ID))
            {
                if (stream.Length == 0)
                {
                    mapInfo = new MapSaveInfo();
                }
                else
                {
                    mapInfo = formatter.Deserialize(stream) as MapSaveInfo;
                }
            }

            foreach (var key in mapInfo.Items.Keys)
            {
                foreach (var obj in mapInfo.Items[key])
                {
                    CreateObject(key, obj);
                }
            }
        }
Пример #2
0
 public EditorMenu(QuickGameScene Scene, LiveEditor editor) : base(Scene.InterfaceLayer, Fonts.SmallFont, GameTiles.Border(), Input.GetInput(Scene),
                                                                   new MenuKeys {
     Select = GameKeys.MenuOK, Cancel = GameKeys.EditorMenu
 })
 {
     AddOption(new ItemsOption()
     {
         Editor = editor
     });
     AddOption(new FreezeItemsOption(Scene)
     {
         Editor = editor
     });
     AddOption(new ReloadOption(Scene)
     {
         Editor = editor
     });
     AddOption(new SaveLevelOption()
     {
         Editor = editor
     });
     AddOption(new CancelOption()
     {
         Editor = editor
     });
 }
Пример #3
0
 private FrozenObject(IEditorPlaceable actual, QuickGameScene scene)
 {
     ActualObject = actual;
     scene.SolidLayer.AddObject(this);
     ActualObject.Remove();
     Scene = scene;
 }
Пример #4
0
        public static FrozenObject Create(IEditorPlaceable actual, QuickGameScene scene)
        {
            if (actual.IsRemoved)
            {
                return(null);
            }

            return((actual as FrozenObject) ?? new FrozenObject(actual, scene));
        }
Пример #5
0
        public void FreezeScene(QuickGameScene scene)
        {
            var mapObjects = scene.SolidLayer.CollidableObjects.OfType <IEditorPlaceable>().ToArray();

            foreach (var mo in mapObjects)
            {
                FrozenObject.Create(mo, scene);
            }
            scene.SolidLayer.Cleanup();
        }
Пример #6
0
        public MapSaveInfo GetMapObjects(QuickGameScene scene)
        {
            var ret = new MapSaveInfo();

            foreach (var obj in scene.SolidLayer.CollidableObjects.OfType <IEditorPlaceable>())
            {
                ret.GetList(obj.EditorType).Add(new ObjectStartInfo(obj));
            }
            return(ret);
        }
Пример #7
0
        public LiveEditor(QuickGameScene scene)
        {
            Scene         = scene;
            KeyboardInput = Input.GetInput(scene);
            MouseInput    = Input.GetMouseInput(scene);
            scene.AddObject(this);
            Cursor = new EditorCursor(scene);

            Menu         = new EditorMenu(scene, this);
            ItemSelector = new ItemSelector(scene, this);
        }
Пример #8
0
        public void UnfreezeScene(QuickGameScene scene)
        {
            var mapObjects = scene.SolidLayer.CollidableObjects.OfType <FrozenObject>().ToArray();

            foreach (var frozenObject in mapObjects)
            {
                frozenObject.Unfreeze();
            }

            scene.SolidLayer.Cleanup();
        }
Пример #9
0
        public void SaveToDisk(QuickGameScene scene)
        {
            var saveInfo  = GetMapObjects(scene);
            var formatter = new BinaryFormatter();

            using (var stream = GetFileStream(scene.ID))
            {
                formatter.Serialize(stream, saveInfo);
                stream.Flush();
            }
        }
Пример #10
0
 public ItemSelector(QuickGameScene Scene, LiveEditor editor) : base(Scene.InterfaceLayer, Fonts.SmallFont, GameTiles.Border(), Input.GetInput(Scene),
                                                                     new MenuKeys {
     Select = GameKeys.MenuOK, Cancel = GameKeys.EditorMenu
 })
 {
     foreach (var cellType in EnumHelper.GetValues <CellType>().Where(p => p != CellType.Empty))
     {
         AddOption(new EditorItem()
         {
             ItemType = cellType, Editor = editor
         });
     }
 }
Пример #11
0
        public GameOverText(QuickGameScene scene)
        {
            layer  = scene.InterfaceLayer;
            motion = new MotionManager(this);

            Text = new GameText(Fonts.BigFont, "GAME OVER", scene.InterfaceLayer);
            Text.StayRelativeTo(this, 0, 0, this);

            Position = new GameEngine.Rectangle();

            var screen = Engine.GetScreenSize();

            new PathMover(this, screen.BottomCenter, screen.Center);
        }
Пример #12
0
        Scene ISceneLoader.LoadScene(SceneID map, bool forceReload)
        {
            if (forceReload)
            {
                loadedScenes.Remove(map.ToString());
            }

            QuickGameScene ret = loadedScenes.TryGet(map.ToString());

            if (ret != null)
            {
                SetIntersceneActorPositions(ret);
                LastScene = ret;
                QuickGameScene.Current = ret;
                return(ret);
            }

            if (MasterTemplate == null)
            {
                MasterTemplate = new MapTemplate("map", new Vector2(16, 16));
            }

            if (map == Scenes.Intro)
            {
                return(new IntroScene());
            }

            ret = new QuickGameScene(map, MasterTemplate);

            SetIntersceneActorPositions(ret);

            DebugText.NewTextPosition = new Vector2(50, 50);
            LastScene = ret;

            if (!forceReload)
            {
                loadedScenes.Add(map.ToString(), ret);
            }

            return(ret);
        }
Пример #13
0
        /// <summary>
        /// Combines adjacent pieces into MovingBlock objects and adds them to the scene
        /// </summary>
        /// <param name="allPieces"></param>
        public static void CreateBlocks(QuickGameScene scene, IEnumerable <MovingBlockPiece> allPieces, IEnumerable <PathPoint> pathPoints)
        {
            var groups = AdjacentTileGroup <MovingBlockPiece> .ExtractGroups(allPieces);

            var paths = AdjacentTileGroup <PathPoint> .ExtractGroups(pathPoints);

            //don't like this here
            scene.SinglePathPoints = paths.Where(p => p.Tiles.Length == 1).Select(p => p.Tiles[0]).ToArray();

            paths = paths.Where(p => p.Tiles.Length > 1).ToArray();

            foreach (var group in groups)
            {
                var groupBox = group.GetBoundingBox();
                var path     = paths.FirstOrDefault(p => p.Tiles.Any(q => groupBox.CollidesWith(q.Position, false)));
                if (path != null)
                {
                    new MovingBlock(scene, group, path);
                }
            }
        }
Пример #14
0
        public ShopMenu(QuickGameScene scene) : base(scene.InterfaceLayer, Fonts.SmallFont, GameTiles.Border(), Input.GetInput(scene),
                                                     new MenuKeys {
            Select = GameKeys.MenuOK, Cancel = GameKeys.Start
        })
        {
            MenuPanel.AddItem(new GameText(Fonts.SmallFont, "WELCOME!", scene.InterfaceLayer));
            MenuPanel.AddItem(new DynamicText <King>(scene.Player, p => "COINS: " + p.Coins, Fonts.SmallFont, scene.InterfaceLayer));

            AddOption(new ExtraHeartShopItem()
            {
                Player = scene.Player, MenuPanel = MenuPanel
            });
            AddOption(new BetterAttackShopItem()
            {
                Player = scene.Player, MenuPanel = MenuPanel
            });
            AddOption(new ExitShopOption()
            {
                Player = scene.Player, MenuPanel = MenuPanel
            });
        }
Пример #15
0
        public Interface(QuickGameScene scene)
        {
            Scene = scene;

            var screen = Engine.GetScreenBoundary().Position;

            var tileset = GameTiles.Border();

            border = new BorderedRectangle(tileset, new Rectangle(0, 0, screen.Width.SnapTo(tileset.Texture.CellSize.X), 30.SnapTo(tileset.Texture.CellSize.Y)),
                                           scene.InterfaceLayer);

            hearts = new IconCounter(scene.Player.DamageHandler.Hitpoints.GetMax(), Textures.HeartTexture, 0, 1, 2, scene.InterfaceLayer);
            hearts.Position.SetCorner(8, 4);


            ScoreLabel = new DynamicText <King>(scene.Player, p => "SCORE: " + p.Score.ToString("000000"), Fonts.SmallFont, scene.InterfaceLayer);

            ScoreLabel.DockInside(border, BorderSide.Right).Nudge(-4, 0);

            scene.AddObject(this);
        }
Пример #16
0
        private void SetIntersceneActorPositions(QuickGameScene newScene)
        {
            if (LastScene != null)
            {
                var isa = LastScene.InterSceneActors.Where(p => p.NextScene != null && p.NextScene.Equals(newScene.ID)).ToArray();
                foreach (var actorInLastScene in isa)
                {
                    var actorInNewScene = newScene.InterSceneActors.SingleOrDefault(p => p.GetType().Name == actorInLastScene.GetType().Name);
                    if (actorInNewScene == null)
                    {
                        actorInNewScene = (IMovesBetweenScenes)Activator.CreateInstance(actorInLastScene.GetType());
                    }

                    actorInNewScene.Motion.Stop(Axis.X);
                    actorInNewScene.Motion.Stop(Axis.Y);
                    actorInNewScene.NextScene = null;

                    actorInNewScene.Position.Center = CalculateActorStart(actorInLastScene, LastScene.ID, newScene);
                    actorInNewScene.Position.KeepWithin(newScene.Position, 16);
                }

                newScene.AdjustCamera();
            }
        }
Пример #17
0
 public bool IsFrozen(QuickGameScene scene)
 {
     return(scene.SolidLayer.CollidableObjects.OfType <FrozenObject>().Any());
 }
Пример #18
0
 public Spike(QuickGameScene scene)
 {
     TileMap = scene.TileMap;
     scene.SolidLayer.CollidableObjects.Add(this);
 }
Пример #19
0
 public QuickGameCollisionManager(QuickGameScene scene) : base(scene.SolidLayer)
 {
     AddBackgroundCollisions();
     AddObjectCollisions();
 }
Пример #20
0
        public static QuickGameTileMap Create(QuickGameScene scene)
        {
            var masterMap = scene.MasterTemplate;

            var template = masterMap.Extract(scene.ID.MapNumber);

            CalculateObscuredTiles(template.Cells, template.GrassMap);
            CalculateObscuredTiles(template.Cells, template.WaterMap);
            ExtendTileMask(template.GrassMap);
            ExtendTileMask(template.WaterMap);

            var solidTiles = new QuickGameTileMap(scene.SolidLayer, template.BrownRockMap.TileSet.Texture, template.Cells.Size);

            solidTiles.EmptyCell = template.BrownRockMap.TileSet.GetCell(BorderSide.EmptySpace);

            template.BrownRockMap.Apply(solidTiles);
            template.LadderMap.Apply(solidTiles, applyEmptyCells: false);

            var grassTiles = new QuickGameTileMap(scene.SolidLayer, template.GrassMap.TileSet.Texture, template.Cells.Size);

            template.GrassMap.Apply(grassTiles);

            var waterTiles = new QuickGameTileMap(scene.WaterLayer, template.BrownRockMap.TileSet.Texture, template.Cells.Size);

            waterTiles.EmptyCell = solidTiles.EmptyCell;
            template.WaterMap.Apply(waterTiles, true);

            FixWaterSurfaceTiles(waterTiles, template.WaterMap.TileSet);

            scene.WaterLayer.FixedDisplayable = new IDisplayable[] { waterTiles };
            scene.SolidLayer.FixedDisplayable = new IDisplayable[] { grassTiles, solidTiles };

            List <MovingBlockPiece> movingBlockPieces = new List <MovingBlockPiece>();
            List <PathPoint>        pathPoints        = new List <PathPoint>();

            foreach (var point in template.Cells.Points)
            {
                if (template.Cells.GetFromPoint(point) == ImageCellType.PlayerStart)
                {
                    scene.PlayerStart = new Vector2(point.X * 16, point.Y * 16);
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.Spike)
                {
                    solidTiles.Tiles.Cells.Set(point, solidTiles.Tiles.Texture.PointToIndex(3, 7));
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.Spring)
                {
                    solidTiles.Tiles.Cells.Set(point, solidTiles.Tiles.Texture.PointToIndex(4, 2));
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.BreakableBlock)
                {
                    solidTiles.Tiles.Cells.Set(point, solidTiles.Tiles.Texture.PointToIndex(1, 7));
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.Box)
                {
                    new Box().SetPosition(point.X * 16, point.Y * 16);
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.MovingBlock)
                {
                    movingBlockPieces.Add(new MovingBlockPiece(point, solidTiles.Tiles.Texture.CellSize));
                }
                else if (template.Cells.GetFromPoint(point) == ImageCellType.Path)
                {
                    pathPoints.Add(new PathPoint((int)point.X * 16, (int)point.Y * 16));
                }
            }

            MovingBlockFactory.CreateBlocks(scene, movingBlockPieces, pathPoints);

            var agt = GameTiles.AutoGenTiles();

            agt.Apply(solidTiles);

            return(solidTiles);
        }
Пример #21
0
 public EditorCursor(QuickGameScene scene)
 {
     scene.SolidLayer.AddObject(this);
     Layer        = scene.InterfaceLayer;
     CursorSprite = new Animation(Layer, PointerPosition, new Sprite(Textures.CursorTexture), 0, 1, 2, 3, 4, 5, 6, 7);
 }
Пример #22
0
 public ReloadOption(QuickGameScene scene)
 {
     Scene = scene;
 }
Пример #23
0
 public FreezeItemsOption(QuickGameScene scene)
 {
     Scene = scene;
 }
Пример #24
0
 public QuickGameBoundaryTransition(QuickGameScene scene) : base(scene)
 {
     MasterTemplate = scene.MasterTemplate;
 }