Esempio n. 1
0
        public Panel(int[,] tiles)
        {
            Tiles = tiles;
            _gameObjectManager = new GameObjectManager();

            _wallTexture = AssetManager.LoadTexture("wall");

            _gameObjectManager.AddGameObject(Player.Instance);
        }
Esempio n. 2
0
        public Panel(int[,] tiles)
        {
            Tiles = tiles;
            _gameObjectManager = new GameObjectManager();

            _wallTexture = AssetManager.LoadTexture("wall");

            _gameObjectManager.AddGameObject(Player.Instance);
        }
Esempio n. 3
0
        public override void Initialize()
        {
            MapManager   = new MapManager(Game, Path.Combine("cfg", "mengine.cfg"));
            WorldObjects = new GameObjectManager(null);
            WorldObjects.EnableBackgroundTransfers();

            Player = new FarmPlayer(Game, this, PlayerIndex.One);
            Player.Initialize();
            WorldObjects.AddGameObject(Player);

            MapManager.ChangeMap("farm");
        }
        public GameObjectManager Process(SerializedObjectLayer serializedObjectLayer, Layer <ObjectTile> layer, TileMap tileMap)
        {
            #region Object parsing and creation
            GameObjectManager         objectManager = new GameObjectManager(layer);
            List <MapObjectArguments> parameters    = GetContainingObjectsParameters(serializedObjectLayer);

            // Loopataan jokainen parametri läpi.
            foreach (MapObjectArguments parameter in parameters)
            {
                Type       objectType = null;
                GameObject mapObject  = null;


                // Loopataan jokainen userin syöttämä nimiavaruus.
                foreach (string objectNamespace in objectNamespaces)
                {
                    // Koitetaan saada tyyppiä nimiavaruudesta.
                    objectType = Type.GetType(objectNamespace + "." + parameter.SerializedData.Name);

                    // Jos tyyppi löytyi, yrittää luoda uuden kartta objectin, jos tämä ei onnistu ja
                    // debugataan, heittää poikkeuksen.
                    if (objectType != null)
                    {
                        parameter.MapContainedIn = tileMap.Name;
                        parameter.Origin         = layer.Tiles[parameter.OriginTileIndex.Y][parameter.OriginTileIndex.X].Position;
                        mapObject = CreateObject(game, objectType, parameter);
                        objectManager.AddGameObject(mapObject);
                        break;
                    }
                }

                // Heittää poikkeuksen jos debugataan ja
                // olio jää nulliksi.
                #region Debug exception
#if DEBUG
                if (mapObject == null)
                {
                    ThrowFailedToResolve(parameter);
                }
#endif
                #endregion
            }
            #endregion

            return(objectManager);
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a new GameObject.
 /// </summary>
 /// <param name="id">The unique identification name
 /// to give to this GameObject.</param>
 public GameObject(string id)
 {
     this.id = id;
     world   = Matrix.Identity;
     GameObjectManager.AddGameObject(this);
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new GameObject.
 /// </summary>
 /// <param name="id">The unique id for this GameObject.</param>
 public GameObject(string id)
 {
     this.id = id;
     GameObjectManager.AddGameObject(this);
     transform = Matrix.Identity;
 }
Esempio n. 7
0
        public void Initialise()
        {
            if (isInit)
            {
                return;
            }

            isInit = true;

            GameObjectManager.AddGameObject(Camera.Orthographic("mainCamera", new Vector3(0, 0, 1f), Vector3.Zero));

            materials = new Material[1];

            RenderTargetSettings settings_target = new RenderTargetSettings()
            {
                blend   = BlendState.AlphaBlend,
                depth   = DepthStencilState.DepthRead,
                effect  = null,
                mode    = SpriteSortMode.Deferred,
                sampler = SamplerState.LinearClamp
            };

            Resources.LoadRenderTarget2D("UI_dithered", this, GraphicsHelper.screen.Width, GraphicsHelper.screen.Height, false, SurfaceFormat.Color, DepthFormat.Depth16, 0, RenderTargetUsage.DiscardContents, settings_target);
            RenderTargetRenderer dithered = RenderTargetRenderer.MakeRenderTargetRenderer("UI_dithered", new RenderTargetSettings(), 1);

            materials[0]             = Resources.LoadAsset(new Material().GetType(), "shader_noise", this) as Material;
            dithered.settings.effect = materials[0];
            dithered.settings.effect.CurrentTechnique = dithered.settings.effect.Techniques["RCDCLSB"];
            dithered.settings.effect.Parameters["S"].SetValue(Random.Range());
            dithered.settings.effect.Parameters["N"].SetValue(0.001f);

            settings_target = new RenderTargetSettings()
            {
                blend   = BlendState.AlphaBlend,
                depth   = DepthStencilState.DepthRead,
                effect  = null,
                mode    = SpriteSortMode.Deferred,
                sampler = SamplerState.PointClamp
            };
            Resources.LoadRenderTarget2D("UI_nearest", this, GraphicsHelper.screen.Width, GraphicsHelper.screen.Height, false, SurfaceFormat.Color, DepthFormat.Depth16, 0, RenderTargetUsage.DiscardContents, settings_target);
            RenderTargetRenderer nearest = RenderTargetRenderer.MakeRenderTargetRenderer("UI_nearest", new RenderTargetSettings(), 2);

            //materials[1] = Resources.LoadAsset(new Material().GetType(), "shader_noise", this) as Material;
            //nearest.settings.effect = materials[1];
            //nearest.settings.effect.CurrentTechnique = nearest.settings.effect.Techniques["RCDCLSB"];
            //nearest.settings.effect.Parameters["S"].SetValue(Random.Range());
            //nearest.settings.effect.Parameters["N"].SetValue(0.0005f);

            sky_bottom_gradient = new Gradient(
                new Color[]
            {
                new Color(112, 181, 255),
                new Color(181, 112, 255),
                new Color(255, 71, 71),
                new Color(25, 25, 94),
                new Color(0, 0, 25),
                new Color(0, 0, 25),
                new Color(25, 25, 94),
                new Color(255, 71, 71),
                new Color(181, 112, 255),
                new Color(112, 181, 255)
            },
                new float[]
            {
                0.0f,
                0.11f,
                0.25f,
                0.30f,
                0.35f,
                0.65f,
                0.70f,
                0.75f,
                0.89f,
                1.0f
            });

            sky_sun_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 196),
                new Color(255, 128, 128),
                new Color(255, 128, 64),
                new Color(255, 128, 64),
                new Color(255, 128, 128),
                new Color(255, 255, 196)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.35f,
                0.65f,
                0.75f,
                1.0f
            });

            sky_sun_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 196, 64),
                new Color(255, 0, 0, 128),
                new Color(255, 196, 196, 255),
                new Color(255, 196, 196, 255),
                new Color(255, 0, 0, 128),
                new Color(255, 255, 196, 64)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.35f,
                0.65f,
                0.75f,
                1.0f
            });

            sky_moon_gradient = new Gradient(
                new Color[]
            {
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(1.0f, 1.0f, 0.75f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_stars_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 255, 0),
                new Color(255, 255, 255, 32),
                new Color(255, 255, 255, 255),
                new Color(255, 255, 255, 32),
                new Color(255, 255, 255, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            });

            sky_top_gradient = new Gradient(
                new Color[]
            {
                new Color(25, 25, 128),
                new Color(50, 50, 128),
                new Color(110, 25, 110),
                new Color(0, 0, 25),
                new Color(0, 0, 0),
                new Color(0, 0, 0),
                new Color(0, 0, 25),
                new Color(110, 25, 110),
                new Color(50, 50, 128),
                new Color(25, 25, 128)
            },
                new float[]
            {
                0.0f,
                0.11f,
                0.25f,
                0.30f,
                0.35f,
                0.65f,
                0.70f,
                0.75f,
                0.89f,
                1.0f
            });

            title_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 255),
                new Color(255, 255, 255),
                new Color(255, 255, 128),
                new Color(255, 255, 255),
                new Color(255, 255, 255)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_gradient = new Gradient(
                new Color[]
            {
                new Color(0.5f, 0.5f, 0.5f, 1.0f),
                new Color(0.5f, 0.5f, 0.5f, 1.0f),
                new Color(0.0f, 0.0f, 0.0f, 1.0f),
                new Color(0.1f, 0.1f, 0.1f, 1.0f),
                new Color(0.25f, 0.25f, 0.25f, 1.0f),
                new Color(0.5f, 0.5f, 0.5f, 1.0f)
            },
                new float[]
            {
                0.0f,
                0.20f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_windows_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 255),
                new Color(175, 125, 195, 128),
                new Color(16, 16, 16, 255),
                new Color(175, 125, 195, 128),
                new Color(125, 175, 195, 255)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 0),
                new Color(175, 125, 195, 196),
                new Color(255, 255, 127, 255),
                new Color(175, 125, 195, 196),
                new Color(125, 175, 195, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 0),
                new Color(175, 125, 195, 32),
                new Color(255, 255, 127, 128),
                new Color(175, 125, 195, 32),
                new Color(125, 175, 195, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_top      = new UIImage("Backdrop", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.TopLeft), new UIAlignment(UIAlignment.Alignment.TopLeft), UIObject.flags.None, "blank", "UI_dithered");
            sky_stars    = new UIImage("Stars", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "stars", "UI_dithered");
            sky_moon     = new UIImage("Moon", new Rectangle(0, 0, 128, 128), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "moon", "UI_dithered");
            sky_bottom   = new UIImage("Backdrop_gradient", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "gradient_white_to_transparent", "UI_dithered");
            sky_sun_glow = new UIImage("Sun_glow", new Rectangle(0, 0, 2000, 2000), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "glow_center_circle", "UI_dithered");
            sky_sun      = new UIImage("Sun", new Rectangle(0, 0, 128, 128), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "sun", "UI_dithered");

            sky_glow = new UIImage("Glow", new Rectangle(0, 0, GraphicsHelper.screen.Width * 2, GraphicsHelper.screen.Height * 2), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "glow_bottom_circle", "UI_dithered");

            skyline         = new UIImage[5];
            skyline_windows = new UIImage[5];
            skyline_glow    = new UIImage[5];

            skyline[0]         = new UIImage("Skyline0", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0", "UI_nearest");
            skyline_windows[0] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0_window", "UI_nearest");
            skyline_glow[0]    = new UIImage("Skyline0_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0_glow", "UI_nearest");
            skyline[1]         = new UIImage("Skyline1", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1", "UI_nearest");
            skyline_windows[1] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1_window", "UI_nearest");
            skyline_glow[1]    = new UIImage("Skyline1_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1_glow", "UI_nearest");
            skyline[2]         = new UIImage("Skyline2", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2", "UI_nearest");
            skyline_windows[2] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2_window", "UI_nearest");
            skyline_glow[2]    = new UIImage("Skyline2_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2_glow", "UI_nearest");
            skyline[3]         = new UIImage("Skyline3", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3", "UI_nearest");
            skyline_windows[3] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3_window", "UI_nearest");
            skyline_glow[3]    = new UIImage("Skyline3_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3_glow", "UI_nearest");
            skyline[4]         = new UIImage("Skyline4", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4", "UI_nearest");
            skyline_windows[4] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4_window", "UI_nearest");
            skyline_glow[4]    = new UIImage("Skyline4_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4_glow", "UI_nearest");

            title = new UIText("Title", new UIAlignment(UIAlignment.Alignment.TopLeft), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "microtype", "I am poor and hungry", 128);
            //title.bounds = new Rectangle(title.bounds.X + 16, title.bounds.Y + 16, title.bounds.Width, title.bounds.Height);

            //logo = new UIImage("Logo", new Rectangle(0, 0, 100, 100), new UIAlignment(UIAlignment.Alignment.BottomRight), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "monogameLogo");
        }
Esempio n. 8
0
        protected override void LoadContent()
        {
            _camera2D = new Camera2D(GraphicsDevice.Viewport);
            Services.AddService(_camera2D);

            Services.AddService(_penumbra);
            Services.AddService(_timeService = new TimeService(Services));
            Services.AddService(GraphicsDevice);
            Services.AddService(_aiService = new AIService(Services, Content));

            var mapService = new MapService();

            Services.AddService(mapService);

            _gameObjectManager = new GameObjectManager();
            Services.AddService(_gameObjectManager);

            _pathFindingService = new PathFindingService(mapService, _gameObjectManager);

            _character = new PlayerCharacter(Services);
            _character.LoadContent(Content);
            Services.AddService(_character);

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            Services.AddService(_uiManager = new UIManager(Services, Content));

            //var mapGenerator = new MapGenerator(Services, GraphicsDevice, Guid.NewGuid().GetHashCode(), Content);
            var mapGenerator = new MapGenerator(Services, GraphicsDevice, -425262119, Content);

            _map = mapGenerator.Generate(400, 400);
            //_map = mapGenerator.Generate(100, 100);

            mapService.Map      = _map;
            _character.Position = _map.StartPosition;

            _gameObjectManager.LoadAll(Content);

            _pathFindingService = new PathFindingService(mapService, _gameObjectManager);
            _pathFindingService.Initialize();
            Services.AddService(_pathFindingService);


            _mapRenderer = new MapRenderer(Services, _map);
            _mapRenderer.LoadContent(Content);


            _uiManager.Initialize();
            _uiManager.AddVisual(new HotbarPanel());
            _uiManager.AddVisual(new TimePanel(Services)
            {
                Position = new UVector2(UDim.Relative(0.01f), UDim.Relative(0.5f))
            });

            _chicken = new Chicken(Services);
            _chicken.LoadContent(Content);
            _chicken.Position = _character.Position + new Vector2(4f * 32f, 4f * 32f);

            _gameObjectManager.AddGameObject(_chicken);
            _gameObjectManager.AddGameObject(_character);

            _temp = new PrimitiveRectangle(GraphicsDevice, Color.Black, false);
        }
        internal override void Process()
        {
            Player Player = this.Device.GameMode.Level.Player;

            GameObjectManager GameObjectManager = this.Device.GameMode.Level.GameObjectManager;

            try
            {
                GameObjectManager.GameObjects[0][0].Clear();
                GameObjectManager.GameObjects[3][0].Clear();
                GameObjectManager.GameObjects[4][0].Clear();
                GameObjectManager.GameObjects[6][0].Clear();

                GameObjectManager.ObstaclesIndex[0] = 0;
                GameObjectManager.DecoIndex[0]      = 0;

                Player.TownHallLevel            = 0;
                Player.CastleLevel              = -1;
                Player.CastleTotalCapacity      = 0;
                Player.CastleTotalSpellCapacity = 0;
                Player.CastleUsedCapacity       = 0;
                Player.CastleUsedSpellCapacity  = 0;

                if (Player.AllianceUnits != null)
                {
                    Player.AllianceUnits.Clear();
                }

                Data TownHall = CSV.Tables.Get(Gamefile.Buildings).GetDataWithID(1000001);
                Data Castle   = CSV.Tables.Get(Gamefile.Buildings).GetDataWithID(1000014);
                Data Builder  = CSV.Tables.Get(Gamefile.Buildings).GetDataWithID(1000015);

                GameObjectManager.AddGameObject(new Building(TownHall, this.Device.GameMode.Level)
                {
                    Position =
                    {
                        X     = 24 << 9,
                            Y = 23 << 9
                    }
                });

                GameObjectManager.AddGameObject(new Building(Castle, this.Device.GameMode.Level)
                {
                    Position =
                    {
                        X     = 28 << 9,
                            Y = 35 << 9
                    },
                    Locked = true
                });

                GameObjectManager.AddGameObject(new Building(Builder, this.Device.GameMode.Level)
                {
                    Position =
                    {
                        X     = 21 << 9,
                            Y = 23 << 9
                    }
                });

                this.SendChatMessage("Successfully cleaned your main village. Enjoy!");

                new OwnHomeDataMessage(this.Device).Send();
            }
            catch (Exception Exception)
            {
                Logging.Error(Exception.GetType(), "Unable to clean the village for user with ID: " + this.Device.GameMode.Level.Player.UserId + Environment.NewLine + Exception.StackTrace);
                this.SendChatMessage($"Failed to clean the village! Error code: {Exception.GetType()}");
            }
        }