Example #1
0
        /// <summary>
        /// Create new game.
        /// </summary>
        /// <returns>The new game.</returns>
        /// <param name="game">Game.</param>
        public static GameSession CreateNewGame(TotemGame game)
        {
            var s = new GameSession(game);

            s.SetPlanet(TotemGame.Random.Next());
            return(s);
        }
Example #2
0
        /// <summary>
        /// Loads game session from a file.
        /// </summary>
        /// <returns>A game session.</returns>
        /// <param name="game">TotemGame.</param>
        /// <param name="stream">An IO stream.</param>
        public static GameSession LoadGame(TotemGame game, Stream stream)
        {
            var s = new GameSession(game);

            using (BinaryReader reader = new BinaryReader(stream))
            {
                s.Deserialize(reader);
            }
            return(s);
        }
Example #3
0
 public static void Initialize(TotemGame game)
 {
     Time         = 0;
     Game         = game;
     NamePosition = new ResolutionResolver(game, new Vector2(.5f), Vector2.Zero);
     if (Stars == null)
     {
         System.Threading.Tasks.Task.Run(() =>
         {
             GenerateTexture();
         });
     }
 }
Example #4
0
        static void LoadParallax(Core.TotemGame game, string asset, int[] movable, params string[] layers)
        {
            var parallax = new Parallax(layers.Length);

            for (int i = 0; i < layers.Length; ++i)
            {
                parallax.Textures[i] = Textures[layers[i]];
            }
            for (int i = 0; i < movable.Length; ++i)
            {
                parallax.Offsetable[movable[i]] = true;
            }
            Parallaxes.Add(asset, parallax);
        }
Example #5
0
        public MenuStateManager(TotemGame game)
        {
            Game  = game;
            Menus = new Dictionary <string, Menu>()
            {
                { "main", new Menu(game) }
            };

            // Building main menu
            Menus["main"].Controls.Add(new MenuButton(game)
            {
                OnClick  = () => { game.LoadNewGame(); },
                Text     = "New Game",
                Position = new ResolutionResolver(game, new Vector2(0, .9f), new Vector2(12, -64 * 2))
            });
            Menus["main"].Controls.Add(new MenuButton(game)
            {
                OnClick  = () => { game.Exit(); },
                Text     = "Exit",
                Position = new ResolutionResolver(game, new Vector2(0, .9f), new Vector2(12, -64))
            });
        }
Example #6
0
        /// <summary>
        /// Primary constructor.
        /// </summary>
        /// <param name="game">Game.</param>
        public DeveloperConsole(TotemGame game)
        {
            Game = game;

            // Test input handling
            TextInputEXT.TextInput += (ch) =>
            {
                if (Enabled && ch != '`' && ch != '~' && Font.Characters.Contains(ch))
                {
                    if (!string.IsNullOrEmpty(Input))
                    {
                        Input = Input.Substring(0, Input.Length - _cursorIndex) + ch + Input.Substring(Input.Length - _cursorIndex);                         // Insert character at cursor
                    }
                    else
                    {
                        Input = string.Empty + ch;
                    }

                    RefreshCursor();
                }
            };
            Console.SetOut(new ConsoleWriter(this));

            AddCommand("help", "Shows the help menu.", args =>             // Help command
            {
                if (args.Length == 0)
                {
                    WriteLine(Constants.ProjectName + ", ver: " + Constants.Version);
                    Commands.ToList().ForEach(pair =>
                    {
                        Console.WriteLine("{0} - {1} {2}", pair.Key, pair.Value.Description,
                                          pair.Value.ArgumentString != null ? "(args: " + pair.Value.ArgumentString + ")" : string.Empty);
                    });
                }
                else
                {
                    if (Commands.ContainsKey(args[0]))
                    {
                        var command = Commands[args[0]];
                        Console.WriteLine("{0} - {1} {2}", args[0], command.Description,
                                          command.ArgumentString != null ? "(args: " + command.ArgumentString + ")" : string.Empty);
                    }
                    else
                    {
                        Console.WriteLine("Command '{0}' does not exist.", args[0]);
                    }
                }
            }, "[command]");
            AddCommand("clear", "Clears the console output.", args =>
            {
                Output.Clear();
                Output.Add(string.Empty);
            });
            AddCommand("echo", "Prints every argument to the console.", args =>             // Echo command
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    WriteLine(args[i]);
                }
            }, "strings");
            AddCommand("exit", "Quits the game.", args =>             // Exit command
            {
                Game.Exit();
            });

            #region Entity commands
            AddCommand("list_ents", "Lists all entities in GameWorld.", args =>             // List of entities
            {
                int index = 0;
                WorldInstance.Entities.ForEach(e =>
                {
                    string pos = "none";
                    var body   = e.GetComponent <BodyComponent>();
                    if (body != null)
                    {
                        pos = body.Position.ToString();
                    }
                    Console.WriteLine("Index: {0}, UID: {1}, Position: {2}", index++, e.UID, pos);
                });
            });
            AddCommand("ent_spawn", "Spawns an entity loaded from assets.", args =>
            {
                var terrain = WorldInstance.GetComponent <TerrainComponent>();
                Vector2 pos = new Vector2(float.Parse(args[1]), args.Length >= 3 ? float.Parse(args[2]) : terrain != null ? terrain.HeightMap(float.Parse(args[1])) : 0);
                var ent     = WorldInstance.CreateEntity(args[0]);
                var body    = ent.GetComponent <BodyComponent>();
                if (body != null)
                {
                    body.LegPosition = pos;
                }
            }, "asset", "x", "[y]");
            #endregion

            /*AddCommand("terrain_test", "Spawns an entity loaded from assets.", args =>
             * {
             *      Game.World.Terrain.CreateDamage(new List<IntPoint>() { new IntPoint(200, 0), new IntPoint(250, 0), new IntPoint(250, 1990), new IntPoint(200, 2000) });
             * }, "asset", "x", "y");
             */
            AddCommand("camera_controls", "Set camera controls on/off.", args =>
            {
                WorldInstance.CameraControls = bool.Parse(args[0]);
            }, "true/false");

            AddCommand("timescale", "Set the timescale.", args =>
            {
                WorldInstance.TimeScale = float.Parse(args[0]);
            }, "float");

            AddCommand("heightmap", "Get the height for specified x.", args =>
            {
                var x       = float.Parse(args[0]);
                var terrain = WorldInstance.GetComponent <TerrainComponent>();
                Console.WriteLine("Height on {0}: {1}", x, terrain?.HeightMap(x));
            }, "x");

            AddCommand("weather", "Set the weather.", args =>
            {
                var weather = WorldInstance?.GetComponent <WeatherComponent>();
                if (weather == null)
                {
                    return;
                }
                switch (args[0].ToLower())
                {
                case "rain":
                    weather.CurrentWeather = new RainWeather();
                    break;

                default:
                    weather.CurrentWeather = null;
                    break;
                }
            }, "float");

            AddCommand("guitest", "Show GUI test.", args =>
            {
                if (args.Length > 0)
                {
                    Game.GuiManager.Add(new Gui.MessageBox(args[0]));
                }
            }, "text");

            AddCommand("chat", "Show GUI test.", args =>
            {
                Game.Hud.Chat(args[0]);
            }, "text", "[color]");

            AddCommand("hurt", "Hurt yourself.", args =>
            {
                Game.Hud.Observed.GetComponent <CharacterComponent>().Stamina -= int.Parse(args[0]);
            }, "amount");

            AddCommand("additem", "Add an item to your inventory.", args =>
            {
                Game.Hud.Observed.GetComponent <InventoryComponent>()
                .AddItem(Item.Create(args[0], args.Length >= 2 ? int.Parse(args[1]) : 1));
            }, "id", "[count]");

            AddCommand("debugview", "Toggle debugview.", args =>
            {
                if (args.Length > 0)
                {
                    WorldInstance.DebugView.Enabled = bool.Parse(args[0]);
                }
                else
                {
                    WorldInstance.DebugView.Enabled = !WorldInstance.DebugView.Enabled;
                }
            }, "[on]");
        }
Example #7
0
        public static void Load(Core.TotemGame game)
        {
            // Generate a pixel texture
            Pixel = new Texture2D(game.GraphicsDevice, 1, 1);
            Pixel.SetData <Color>(new Color[] { Color.White });

            // Load Textures
            LoadContentFile(game, "textures/", ".xnb", Textures);

            // Load Sounds
            LoadContentFile(game, "sounds/", ".xnb", Sounds);

            // Load Parallaxes
            foreach (string file in FindAllFiles("Content/assets/parallaxes", ".parallax"))
            {
                var name = Path.GetFileNameWithoutExtension(file);
                Console.WriteLine("Loading a parallax: {0}", name);
                using (FileStream stream = new FileStream(file, FileMode.Open))
                    using (StreamReader sReader = new StreamReader(stream))
                        using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(sReader))
                        {
                            var obj      = JObject.Load(reader);
                            var array    = JArray.FromObject(obj["textures"]);
                            var movArray = JArray.FromObject(obj["movable"]);

                            var textures = new string[array.Count];
                            var movable  = new int[movArray.Count];

                            for (int i = 0; i < textures.Length; ++i)
                            {
                                textures[i] = (string)array[i];
                            }
                            for (int i = 0; i < movable.Length; ++i)
                            {
                                movable[i] = (int)movArray[i];
                            }

                            LoadParallax(game, name, movable, textures);
                        }
            }

            // Load Fonts
            LoadContentFile(game, "fonts/", ".xnb", Fonts);

            // Load shaders
            Shaders.Add("ground", game.Content.Load <Effect>("shaders/GroundShader"));
            Shaders.Add("menu", game.Content.Load <Effect>("shaders/MenuShader"));

            LoadAssetFile(game, "Content/assets/sprites", ".sprite", Sprites, null, "sprite");

            {
                var file = "Content/textures/sprites.scml";
                using (FileStream stream = new FileStream(file, FileMode.Open))
                    using (StreamReader sReader = new StreamReader(stream))
                    {
                        var spriter  = SpriterReader.Default.Read(sReader.ReadToEnd());
                        var provider = new SpriterDotNet.Providers.DefaultProviderFactory <ISprite, SoundEffect>(new Config()
                        {
                            SoundsEnabled = false
                        });
                        foreach (SpriterFolder folder in spriter.Folders)
                        {
                            foreach (SpriterFile sfile in folder.Files)
                            {
                                var sprite = new SpriterDotNet.MonoGame.Sprites.TextureSprite(Textures[sfile.Name.Replace(".png", "")]);
                                provider.SetSprite(spriter, folder, sfile, sprite);
                            }
                        }

                        // Add wrapper
                        foreach (SpriterEntity ent in spriter.Entities)
                        {
                            BoneSprites.Add(ent.Name, new SpriteWrapper(ent, provider));
                        }
                    }
            }

            LoadAssetFile(game, "Content/assets/items", ".item", Items, "id");
            LoadAssetFile(game, "Content/assets/entities", ".entity", Entities, null, "entity");
            LoadAssetFile(game, "Content/assets/particles", ".particle", Particles);
        }
Example #8
0
 public Menu(TotemGame game)
 {
     Game     = game;
     Controls = new List <UiControl>();
 }
Example #9
0
 public MenuButton(TotemGame game, UiControl parent = null) : base(game, parent)
 {
 }
Example #10
0
 public Container(TotemGame game, UiControl parent = null) : base(game, parent)
 {
 }
Example #11
0
 public UiControl(TotemGame game, UiControl parent)
 {
     Game   = game;
     Parent = parent;
 }
Example #12
0
 GameSession(TotemGame game)
 {
     Game         = game;
     UniverseTime = new DateTime(2034, 5, 27, 12, 0, 0);
 }
Example #13
0
 public YResScaleResolver(TotemGame game, float itemScale)
 {
     Game      = game;
     ItemScale = itemScale;
 }
Example #14
0
 public HUD(TotemGame game)
 {
     Game = game;
 }
Example #15
0
 public Camera(TotemGame game)
 {
     Game = game;
     Game.OnResolutionChange += (x, y) => { RecalculateBoundingBox(); };
     RecalculateBoundingBox();
 }
Example #16
0
 public ResolutionResolver(TotemGame game, Vector2 relOrigin, Vector2 offset)
 {
     Game           = game;
     RelativeOrigin = relOrigin;
     Offset         = offset;
 }