Example #1
0
        public ActorLayer Clone()
        {
            ActorLayer copyLayer = new ActorLayer(this.Name, this.ZIndex, this.GameInstance);
            copyLayer.Height = this.Height;
            copyLayer.Width = this.Width;
            copyLayer.AlwaysCentered = this.AlwaysCentered;

            foreach (List<Actor> row in this.Actors)
            {
                List<Actor> newRow = new List<Actor>(row);
                copyLayer.Actors.Add(newRow);
            }
            return copyLayer;
        }
        public static byte[,] createByteGridFromLayer(ActorLayer layer)
        {
            byte[,] grid = new byte[layer.Width, layer.Height];

            int x = 0, y = 0;
            foreach(List<Actor> row in layer.Actors){
                foreach(Actor actor in row){
                    grid[x,y] = Convert.ToByte(actor.Clippable);
                    x++;
                }
                y++;
                x = 0;
            }
            return grid;
        }
Example #3
0
        public static ActorLayer CutLayerToSize(ActorLayer layer, Point center, int width, int height)
        {
            //Copy the original to a new layer
               ActorLayer original = layer.Clone();

               layer.Width = width;
               layer.Height = height;

               //Set the layer to the new cut size
               layer.Actors = CreateLayer(height, width);

            //Start going through and writing the trimmed cells from the
            //  original to the trimmed layer passed in
            int trimmedXToWrite = 0;
            int trimmedYToWrite = 0;

            int topPosition = center.Y -Convert.ToInt32(Math.Floor((decimal)height/2));
            int bottomPosition = center.Y + Convert.ToInt32(Math.Ceiling((decimal)height / 2));
            int leftPosition = center.X - Convert.ToInt32(Math.Floor((decimal)width / 2));
            int rightPosition = center.X + Convert.ToInt32(Math.Ceiling((decimal)width / 2));

            for(int y = topPosition;  y < bottomPosition; y++){
                    for (int x = leftPosition; x < rightPosition; x++){
                        if (x >= 0 && x < original.Width && y >= 0 && y < original.Height)
                        {
                            layer.Actors[trimmedYToWrite][trimmedXToWrite] = original.Actors[y][x];
                        }
                        else
                        {
                            layer.Actors[trimmedYToWrite][trimmedXToWrite] = new OutOfBounds();
                        }

                        trimmedXToWrite++;

                        }

                    trimmedXToWrite = 0;
                    trimmedYToWrite++;
            }
            return layer;
        }
        //Starts a game
        public void Initialize()
        {
            //Load in some layers of actors
            ActorLayer foreground = new ActorLayer("Foreground stuff", 1, (GameInstance)this);
            foreground.InitializeFromFile("Maps/foreground.txt");

            ActorLayer wallsAndItems = new ActorLayer("Main layer with players, walls, and items", 0, (GameInstance)this);
            wallsAndItems.InitializeFromFile("Maps/walls_and_items.txt");

            ActorLayer background = new ActorLayer("Background stuff", -1, (GameInstance)this);
            background.InitializeFromFile("Maps/background.txt");

            //initialize the pause menu/layer
            pausedLayer = new ActorLayer("Paused layer", -999, (GameInstance)this);
            pausedLayer.InitializeFromFile("Maps/paused.txt");
            pausedLayer.AlwaysCentered = true;
            pausedLayer.Visible = false;

            Layers = new List<ActorLayer>() {pausedLayer, foreground, wallsAndItems, background };
            Player = (Player)wallsAndItems.FindFirstObjectInWorldOfType(typeof(Player));

            //Make the enemy go to a point, for testing
            Follower = (Follower)wallsAndItems.FindFirstObjectInWorldOfType(typeof(Follower));
            Command moveToCommand = CommandHelpers.CreateMoveToCommand(Follower, Player.Location, true);
            Follower.AssignCommand(moveToCommand);

            //Create a viewport sized for this map
            view = new Viewport(25, 30);
            view.CameraLocation = Player.Location;

            //Start the game clock
            gameClock = new System.Threading.Timer(new TimerCallback(GameTick), null, 0, 1000 / TicksPerSecond);
            frameClock = new System.Threading.Timer(new TimerCallback(FrameTick), null, 0, 1000 / FramesPerSecond);

            //Draw the first frames
            FrameTick();

            //Read user keyboard input
            ReadInput();
        }