Esempio n. 1
0
 public JunkbotActor(AnimationStore store, Scene scene, Point location, FacingDirection initialDirection)
 {
     Animation = new AnimationServer(store);
     Location  = location;
     SetWalkingDirection(initialDirection);
     Scene = scene;
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes this <see cref="IGameState"/> with references to the game
        /// engine and animation store repository instances.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the game engine instance.
        /// </param>
        /// <param name="animationStore">
        /// A reference to the animation store repository instance.
        /// </param>
        /// <returns>True if the initialization routine was successful.</returns>
        public bool Initialize(JunkbotGame gameReference, AnimationStore animationStore)
        {
            Game      = gameReference;
            Interface = new JunkbotInterface();

            return(true);
        }
Esempio n. 3
0
        public BrickActor(AnimationStore store, Point location, Color color, BrickSize size)
        {
            Animation      = new AnimationServer(store);
            _BoundingBoxes = new List <Rectangle>().AsReadOnly();
            _Color         = color;
            _GridSize      = new Size((int)size, 1);
            Location       = location;
            _Size          = size;

            UpdateBrickAnim();
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes this <see cref="IGameState"/> with references to the game
        /// engine and animation store repository instances.
        /// </summary>
        /// <param name="gameReference">
        /// A reference to the game engine instance.
        /// </param>
        /// <param name="animationStore">
        /// A reference to the animation store repository instance.
        /// </param>
        /// <returns>True if the initialization routine was successful.</returns>
        public bool Initialize(JunkbotGame gameReference, AnimationStore animationStore)
        {
            AnimationStore = animationStore;
            Game           = gameReference;
            Interface      = new JunkbotInterface();
            Scene          = Scene.FromLevel(
                File.ReadAllLines(Environment.CurrentDirectory + @"\Content\Levels\loading_level.txt"),
                AnimationStore
                );

            return(true);
        }
Esempio n. 5
0
 public void Hover(bool hover, AnimationStore animations)
 {
     IsHover = hover;
     if (hover)
     {
         Sprite.StartAnimating(animations[HoverAnimationKey]);
     }
     else
     {
         Sprite.ClearAnimation();
     }
 }
Esempio n. 6
0
 public DecalActor(AnimationStore store, Point location)
 {
     Animation = new AnimationServer(store);
     Location  = location;
 }
Esempio n. 7
0
 void Awake()
 {
     me = this;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JunkbotGame"/> class.
 /// </summary>
 public JunkbotGame()
 {
     AnimationStore = new AnimationStore();
 }
Esempio n. 9
0
        public Scene(JunkbotLevelData levelData, AnimationStore store)
        {
            _MobileActors   = new List <IActor>();
            _ImmobileBricks = new List <BrickActor>();
            AnimationStore  = store;
            PlayField       = new IActor[levelData.Size.Width, levelData.Size.Height];
            CellSize        = levelData.Spacing;
            Size            = levelData.Size;

            foreach (JunkbotPartData part in levelData.Parts)
            {
                IActor actor    = null;
                Color  color    = Color.FromName(levelData.Colors[part.ColorIndex]);
                Point  location = part.Location; // Subtract one to get zero-indexed location

                switch (levelData.Types[part.TypeIndex])
                {
                case "brick_01":
                    actor = new BrickActor(store, location, color, BrickSize.One);
                    break;

                case "brick_02":
                    actor = new BrickActor(store, location, color, BrickSize.Two);
                    break;

                case "brick_03":
                    actor = new BrickActor(store, location, color, BrickSize.Three);
                    break;

                case "brick_04":
                    actor = new BrickActor(store, location, color, BrickSize.Four);
                    break;

                case "brick_06":
                    actor = new BrickActor(store, location, color, BrickSize.Six);
                    break;

                case "brick_08":
                    actor = new BrickActor(store, location, color, BrickSize.Eight);
                    break;

                case "minifig":
                    actor = new JunkbotActor(store, this, location, (part.AnimationName == "WALK_L" ? FacingDirection.Left : FacingDirection.Right));
                    break;

                default:
                    Console.WriteLine("Unknown actor: " + levelData.Types[part.TypeIndex]);
                    continue;
                }

                actor.Location = location.Subtract(new Point(1, actor.GridSize.Height));
                UpdateActorGridPosition(actor, actor.Location);

                actor.LocationChanged += Actor_LocationChanged;

                if (actor is BrickActor)
                {
                    var brick = (BrickActor)actor;

                    _ImmobileBricks.InsertSorted((BrickActor)actor);
                }
                else
                {
                    _MobileActors.Add(actor);
                }
            }
        }
Esempio n. 10
0
        public static Scene FromLevel(string[] lvlFile, AnimationStore store)
        {
            var levelData = new JunkbotLevelData();
            var parts     = new List <JunkbotPartData>();

            foreach (string line in lvlFile)
            {
                // Try retrieving the data
                //
                string[] definition = line.Split('=');

                if (definition.Length != 2)
                {
                    continue; // Not a definition
                }
                // Retrieve key and value
                //
                string key   = definition[0].ToLower();
                string value = definition[1];

                switch (key)
                {
                case "colors":
                    levelData.Colors = value.ToLower().Split(',');
                    break;

                case "hint":
                    levelData.Hint = value;
                    break;

                case "par":
                    levelData.Par = Convert.ToUInt16(value);
                    break;

                case "parts":
                    string[] partsDefs = value.ToLower().Split(',');

                    foreach (string def in partsDefs)
                    {
                        string[] partData = def.Split(';');

                        if (partData.Length != 7)
                        {
                            Console.WriteLine("Invalid part data encountered");
                            continue;
                        }

                        var part = new JunkbotPartData();

                        part.Location = new Point(
                            Convert.ToInt32(partData[0]),
                            Convert.ToInt32(partData[1])
                            );

                        part.TypeIndex = (byte)(Convert.ToByte(partData[2]) - 1);     // Minus one to convert to zero-indexed index

                        part.ColorIndex = (byte)(Convert.ToByte(partData[3]) - 1);    // Minus one to convert to zero-indexed index

                        part.AnimationName = partData[4].ToLower();

                        parts.Add(part);
                    }

                    break;

                case "scale":
                    levelData.Scale = Convert.ToByte(value);
                    break;

                case "size":
                    string[] sizeCsv = value.Split(',');

                    if (sizeCsv.Length != 2)
                    {
                        Console.WriteLine("Invalid playfield size encountered");
                        continue;
                    }

                    levelData.Size = new Size(
                        Convert.ToInt32(sizeCsv[0]),
                        Convert.ToInt32(sizeCsv[1])
                        );

                    break;

                case "spacing":
                    string[] spacingCsv = value.Split(',');

                    if (spacingCsv.Length != 2)
                    {
                        Console.WriteLine("Invalid playfield spacing encountered");
                        continue;
                    }

                    levelData.Spacing = new Size(
                        Convert.ToInt32(spacingCsv[0]),
                        Convert.ToInt32(spacingCsv[1])
                        );

                    break;

                case "title":
                    levelData.Title = value;
                    break;

                case "types":
                    var types = new List <string>();

                    if (levelData.Types != null)
                    {
                        types.AddRange(levelData.Types);
                    }

                    types.AddRange(value.ToLower().Split(','));

                    levelData.Types = types.ToArray();

                    break;

                case "decals":
                    string[] decalsDef = value.Split(',');     //Splits up each decal in a row.

                    foreach (string def in decalsDef)
                    {
                        string[] decalData = def.Split(';');     //first two define X and Y, then the Decal type
                        if (decalData.Length != 3)
                        {
                            Console.WriteLine("Invalid decal data encountered");
                            continue;
                        }
                        var decals = new JunkbotDecalData();     //a new struct for storing decal data: its sprite and position.
                        decals.Location = new Point(
                            Convert.ToInt32(decalData[0]),
                            Convert.ToInt32(decalData[1])
                            );
                        decals.Decal = decalData[2];     //If I'm not mistaken, this will pass the relevant information from the level to the decal entry.
                                                         //Now, all that remains is to get stuff sorted out.
                    }
                    break;

                case "backdrop":
                    levelData.Backdrop = value;
                    break;
                }
            }

            levelData.Parts = parts.AsReadOnly();

            return(new Scene(levelData, store));
        }
Esempio n. 11
0
 public void Click(AnimationStore animations)
 {
     Sprite.StartAnimating(animations[ClickAnimationKey]);
 }