Exemple #1
0
 public FruitType(string name, ItemType drop, TimeSpan time)
 {
     this.Name    = name;
     this.Drop    = drop;
     this.Time    = time;
     this.Texture = GameImpl.LoadContent <Texture2D>("Objects/Trees/" + name + "Tree");
 }
Exemple #2
0
        public void Setup(string fileName)
        {
            Repository = new Repository();
            Repository.Load();
            _window = Substitute.For <IEmulatorWindow>();
            var settings      = Substitute.For <ISettings>();
            var recognition   = new TextRecognition();
            var loggerFactory = Substitute.For <ILoggerFactory>();

            _videoProvider = Substitute.For <IVideoProvider>();
            Game           = new GameImpl(_window, _videoProvider, Repository, loggerFactory, recognition, settings);
#if DEBUG
            Settings.SaveImages    = true;
            Settings.SaveRawImages = true;
#endif

            using var bitmap = new Bitmap(fileName);
            _window.Width.Returns(bitmap.Width);
            _window.Height.Returns(bitmap.Height);
            _window.GrabScreen(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <int>(), Arg.Any <int>())
            .Returns(info =>
            {
                using var bitmapLocal = new Bitmap(fileName);
                return(bitmapLocal.Crop(info.ArgAt <int>(0), info.ArgAt <int>(1), info.ArgAt <int>(2), info.ArgAt <int>(3)));
            });
            _videoProvider.GetCurrentFrame().Returns(info => bitmap);
        }
Exemple #3
0
 public Engine(GameImpl gameImpl)
 {
     graphics = new GraphicsDeviceManager(this);
     graphics.GraphicsProfile           = GraphicsProfile.HiDef;
     graphics.PreferredBackBufferWidth  = 1280;
     graphics.PreferredBackBufferHeight = 720;
     graphics.IsFullScreen = true;
     Content.RootDirectory = "Content";
     this.gameImpl         = gameImpl;
 }
Exemple #4
0
        /*-------------------------------------
         * CONSTRUCTORS
         *-----------------------------------*/
        public Engine(GameImpl gameImpl)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.SynchronizeWithVerticalRetrace = false;
            base.IsFixedTimeStep = false;

            this.gameImpl = gameImpl;
        }
 public FurnitureType(string name, RectangleF renderBounds, RectangleF collisionBounds, RectangleF?highlightBounds = null, RectangleF?placementBounds = null)
     : base(name, new Point(0, 0))
 {
     this.Texture      = GameImpl.LoadContent <Texture2D>("Objects/Furniture/" + name);
     this.RenderBounds = renderBounds;
     foreach (var dir in Direction.Values)
     {
         this.CollisionBounds[dir] = collisionBounds;
         this.PlacementBounds[dir] = placementBounds ?? collisionBounds;
         this.HighlightBounds[dir] = highlightBounds ?? renderBounds;
     }
 }
Exemple #6
0
        public void TestSave()
        {
            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();


            saver.Save(myGame);

            Assert.IsTrue(saver.IsSavingPresent());
            Assert.AreNotEqual(saver.Load(), new GameImpl());
            Assert.AreEqual(myGame, saver.Load());
        }
Exemple #7
0
        public static void Main()
        {
            var canvas = new HTMLCanvasElement();

            canvas.width  = 1280;
            canvas.height = 720;
            canvas.id     = "monogamecanvas";
            document.body.appendChild(canvas);

            game = new GameImpl();
            game.Run();
        }
Exemple #8
0
        public void TestEngineOldGame()
        {
            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();

            saver.Save(myGame);


            Engine engine = new Engine();

            engine.Update(true);

            Assert.AreEqual(engine.Game, myGame);
        }
Exemple #9
0
        public void TestEngineNewGame()
        {
            Engine engine = new Engine();

            engine.Update(false);

            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();

            saver.Save(myGame);

            Assert.NotNull(engine.Game);
            Assert.AreNotEqual(myGame, engine.Game);
        }
Exemple #10
0
        public Character(string name, Map map, Vector2 position) : base(map, position)
        {
            this.RenderBounds    = new RectangleF(-0.5F, -1.5F, 1, 2);
            this.CollisionBounds = new RectangleF(-0.4F, 0, 0.8F, 0.35F);

            this.AnimationFactory = new SpriteSheetAnimationFactory(new TextureAtlas(
                                                                        name,
                                                                        GameImpl.LoadContent <Texture2D>("Characters/" + name),
                                                                        GameImpl.LoadContent <Dictionary <string, Rectangle> >("Characters/Animation")));
            this.AnimationFactory.Add("StandingDown", new SpriteSheetAnimationData(new[] { 0 }));
            this.AnimationFactory.Add("Down", new SpriteSheetAnimationData(new[] { 1, 2, 3 }, isPingPong: true));
            this.AnimationFactory.Add("StandingUp", new SpriteSheetAnimationData(new[] { 4 }));
            this.AnimationFactory.Add("Up", new SpriteSheetAnimationData(new[] { 5, 6, 7 }, isPingPong: true));
            this.AnimationFactory.Add("StandingLeft", new SpriteSheetAnimationData(new[] { 8 }));
            this.AnimationFactory.Add("Left", new SpriteSheetAnimationData(new[] { 9, 10, 11 }, isPingPong: true));
            this.AnimationFactory.Add("StandingRight", new SpriteSheetAnimationData(new[] { 12 }));
            this.AnimationFactory.Add("Right", new SpriteSheetAnimationData(new[] { 13, 14, 15 }, isPingPong: true));
            this.CurrentAnimation = this.AnimationFactory.Create("StandingDown");
        }
        public void TestBasicEnemy()
        {
            GameImpl game = new GameImpl();

            AbstractEnemy basic = new BasicEnemy(game);


            basic.createThisEnemy();
            Assert.IsNotNull(basic);


            Pair <int, int> position = basic.Position;

            Assert.AreNotEqual(position, new Pair <int, int>(0, 0));
            basic.setDead();
            Assert.IsTrue(basic.Dead);
            basic.setAlive();
            Assert.IsFalse(basic.Dead);
        }
        public void TestBossEnemy()
        {
            GameImpl game = new GameImpl();

            AbstractEnemy boss = new BossEnemy(game);

            boss.createThisEnemy();
            Assert.IsNotNull(boss);

            Pair <int, int> position = boss.Position;

            Assert.AreNotEqual(position, new Pair <int, int>(0, 0));
            boss.update();



            boss.setDead();
            Assert.IsTrue(boss.Dead);
            boss.setAlive();
            Assert.IsFalse(boss.Dead);
        }
Exemple #13
0
        public Character(string name, Map map, Vector2 position) : base(map, position)
        {
            this.Size            = new Size2(0.75F, 0.95F) * this.Map.Scale;
            this.InteractionArea = new RectangleF(new Vector2(0, -0.5F) * this.Map.Scale, new Size2(0.75F, 1.95F) * this.Map.Scale);

            this.AnimationFactory = new SpriteSheetAnimationFactory(new TextureAtlas(
                                                                        name,
                                                                        GameImpl.LoadContent <Texture2D>("Objects/" + name),
                                                                        GameImpl.LoadContent <Dictionary <string, Rectangle> >("Objects/CharacterAnimation")));

            this.AnimationFactory.Add("StandingDown", new SpriteSheetAnimationData(new[] { 0 }));
            this.AnimationFactory.Add("Down", new SpriteSheetAnimationData(new[] { 1, 2, 3 }, isPingPong: true));
            this.AnimationFactory.Add("StandingUp", new SpriteSheetAnimationData(new[] { 4 }));
            this.AnimationFactory.Add("Up", new SpriteSheetAnimationData(new[] { 5, 6, 7 }, isPingPong: true));
            this.AnimationFactory.Add("StandingLeft", new SpriteSheetAnimationData(new[] { 8 }));
            this.AnimationFactory.Add("Left", new SpriteSheetAnimationData(new[] { 9, 10, 11 }, isPingPong: true));
            this.AnimationFactory.Add("StandingRight", new SpriteSheetAnimationData(new[] { 12 }));
            this.AnimationFactory.Add("Right", new SpriteSheetAnimationData(new[] { 13, 14, 15 }, isPingPong: true));

            this.CurrentAnimation = this.AnimationFactory.Create("StandingDown");
        }
 public TextureAtlas(string location, int regionWidth, int regionHeight)
 {
     this.RegionWidth  = regionWidth;
     this.RegionHeight = regionHeight;
     this.Texture      = GameImpl.LoadContent <Texture2D>(location);
 }
Exemple #15
0
 public static void Main()
 {
     using (var game = new GameImpl()) {
         game.Run();
     }
 }
Exemple #16
0
 public static void RunGame(GameImpl gameImpl)
 {
     inst = new Engine(gameImpl);
     inst.Run();
 }
Exemple #17
0
        public void OnWalkedOnto(Point pos)
        {
            var stuck = Direction2Helper.Adjacent.All(dir => {
                var offset = pos + dir.Offset();
                var tile   = this.Map.GetTile(offset.X, offset.Y);
                return(tile.IsBlank || !tile.GetTilesetTile(this.Map.Tiles).Properties.GetBool("Walkable"));
            });

            if (stuck)
            {
                CoroutineHandler.Start(GameImpl.Instance.DisplayTrigger("R to restart"));
            }

            foreach (var obj in this.Map.Tiles.GetObjects("Trigger", false, true))
            {
                if (obj.Properties.GetBool("Triggered"))
                {
                    continue;
                }
                if (!obj.GetArea(this.Map.Tiles).Contains(pos.ToVector2() + new Vector2(0.5F)))
                {
                    continue;
                }
                var content = obj.Properties.Get("Content");
                CoroutineHandler.Start(GameImpl.Instance.DisplayTrigger(content));
                obj.Properties.Add("Triggered", true.ToString());
                break;
            }

            foreach (var layer in this.Map.Tiles.TileLayers)
            {
                var tile = layer.GetTile(pos.X, pos.Y);
                if (tile.IsBlank)
                {
                    continue;
                }
                var tilesetTile = tile.GetTilesetTile(this.Map.Tiles);

                // buttons
                if (tilesetTile.Properties.GetBool("Activator"))
                {
                    foreach (var other in this.Map.Tiles.TileLayers)
                    {
                        if (other.Properties.GetBool("Activated"))
                        {
                            continue;
                        }
                        if (other.Properties.GetInt("ActivatorX") != pos.X || other.Properties.GetInt("ActivatorY") != pos.Y)
                        {
                            continue;
                        }
                        CoroutineHandler.Start(this.Map.AddLayerToGround(other));
                        other.Properties["Activated"] = true.ToString();
                        break;
                    }
                    var active = tilesetTile.Properties.GetInt("ActiveState");
                    if (active > 0)
                    {
                        this.Map.SetTile(pos.X, pos.Y, active, layer.Name);
                    }
                    MlemGame.LoadContent <SoundEffect>("Sounds/Button").Play();
                    continue;
                }

                // bed
                if (tilesetTile.Properties.GetBool("Goal"))
                {
                    this.Direction = Direction2.Down;
                    var nextLevel = Array.IndexOf(GameImpl.Levels, this.Map.Name) + 1;
                    GameImpl.Instance.Fade(0.005F, g => {
                        if (GameImpl.Levels.Length > nextLevel)
                        {
                            g.StartMap(GameImpl.Levels[nextLevel], g2 => g2.Fade(0.01F));
                        }
                        else
                        {
                            g.DisplayCaption(new[] {
                                "At last,\nI'm not panicking anymore.",
                                "I know it'll come back eventually,\nbut for now, I'm free."
                            }, g2 => g2.DisplayCaption(new[] {
                                "Thanks for playing this game.",
                                "If you're ever feeling depressed,\nplease reach out to someone."
                            }, g3 => {
                                g3.SetMap(null);
                                GameImpl.Save(null);
                                g3.OpenMainMenu();
                                g3.Fade(0.01F);
                            }));
                        }
                    });
                    MlemGame.LoadContent <SoundEffect>("Sounds/Bed").Play();
                    continue;
                }

                // step grid tiles
                var steppedOnOff = tile.GlobalIdentifier == 7;
                if (steppedOnOff || tile.GlobalIdentifier == 8)
                {
                    var grid = this.Map.Tiles.TileLayers.First(t => t.Properties.GetBool("StepGrid") && !t.GetTile(pos.X, pos.Y).IsBlank);
                    if (grid != layer)
                    {
                        var missing = grid.Tiles.Count(t => !t.IsBlank && this.Map.GetTile(t.X, t.Y).GlobalIdentifier != 8);
                        // only change tiles if the grid isn't complete
                        if (missing > 0)
                        {
                            // if we stepped on a disabled tile, turn it on
                            if (steppedOnOff)
                            {
                                this.Map.SetTile(pos.X, pos.Y, 8);
                            }
                            else
                            {
                                // otherwise, turn the whole grid off
                                foreach (var t in grid.Tiles.Where(t => !t.IsBlank))
                                {
                                    this.Map.SetTile(t.X, t.Y, (int)t.GlobalTileIdentifierWithFlags);
                                }
                            }
                        }
                        // if there's only one missing and we just switched on, we're done
                        if (missing == 1 && steppedOnOff)
                        {
                            foreach (var other in this.Map.Tiles.TileLayers)
                            {
                                if (other.Properties.Get("ActivatorGrid") != grid.Name)
                                {
                                    continue;
                                }
                                CoroutineHandler.Start(this.Map.AddLayerToGround(other));
                                other.Properties["Activated"] = true.ToString();
                                MlemGame.LoadContent <SoundEffect>("Sounds/Button").Play();
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #18
0
 public static void Main(string[] args)
 {
     using (var game = new GameImpl())
         game.Run();
 }
Exemple #19
0
        private void ConfigureSerivces(ServiceCollection serviceCollection)
        {
            var            uiLogger      = new CustomUiLoggerProvider();
            ILoggerFactory loggerFactory = LoggerFactory.Create(
                (builder) =>
            {
                builder
                .AddProvider(new CustomConsoleProvider())
                .AddProvider(new CustomTraceProvider())
                .AddProvider(uiLogger)
                .SetMinimumLevel(LogLevel.Debug);
            });

            Directory.CreateDirectory("Settings");
            var path = Path.Combine("Settings", "config.json");

            var setupDefaultConfig = !File.Exists(path);

            var settings = new ConfigurationBuilder <ISettings>()
                           .UseJsonFile(path).
                           Build();

            if (setupDefaultConfig)
            {
                SetupDefaultConfiguration(settings);
            }
            else
            {
                EnsureValidValues(settings);
            }

            serviceCollection.AddSingleton(settings);

            var recognition = new TextRecognition();

            var executioner   = new TaskExecutioner(loggerFactory.CreateLogger <TaskExecutioner>());
            var window        = SetupWindow(settings, loggerFactory, recognition);
            var videoProvider = new VideoProvider(window, settings.VideoCapture.FrameRate);

            serviceCollection.AddSingleton <IVideoProvider>(videoProvider);
            serviceCollection.AddSingleton <IVideoCapture, VideoCapture>();

            var repository = new Repository();

            repository.Load();
            var game = new GameImpl(window, videoProvider, repository, loggerFactory, recognition, settings);

            var overlay = new ImGuiOverlay(game, window, repository);

            if (settings.EnableOverlay)
            {
                //circular dependency. find better solution.
                game.Overlay = overlay;
                overlay.Setup();
            }
            serviceCollection.AddSingleton <IEmulatorOverlay>(overlay);

            var picker = new AreaPicker(window, overlay);

            serviceCollection.AddSingleton <ITaskExecutioner>(executioner);
            serviceCollection.AddSingleton <ITaskQueue>(executioner);
            serviceCollection.AddSingleton <IGame>(game);
            serviceCollection.AddSingleton <IAreaPicker>(picker);
            serviceCollection.AddSingleton <IUiRepository>(repository);
            serviceCollection.AddSingleton(window);
            serviceCollection.AddSingleton <IUiLogger>(uiLogger);
            ViewModelLocator.ConfigureServices(serviceCollection);

            if (settings.EnableOverlay)
            {
                Dispatcher.BeginInvoke(async() => await UpdateOverlay(overlay));
            }
        }
Exemple #20
0
 private static void Main()
 {
     using (var game = new GameImpl())
         game.Run();
 }
Exemple #21
0
 public static void Main(string[] args)
 {
     using (var game = new GameImpl(int.Parse(args[0]), int.Parse(args[1]))) {
         game.Run();
     }
 }