public override void Update(long gameTime, NamelessGame namelessGame)
 {
     while (namelessGame.Commander.DequeueCommand(out ChangeSwitchStateCommand command))
     {
         command.getTarget().setSwitchActive(command.isActive());
     }
 }
        public static GameContext GetWorldBoardContext(NamelessGame game)
        {
            if (WorldBoardContext != null)
            {
                return(WorldBoardContext);
            }
            else
            {
                var renderingSystem = new MapRenderingSystem(game.GetSettings(), game.WorldSettings);
                var systems         = new List <ISystem>();
                systems.Add(new InputSystem(new WorldMapKeyIntentTranslator(), game));
                systems.Add(new WorldBoardIntentSystem());
                systems.Add(new WorldBoardScreenSystem(renderingSystem));

                var uiSystem = new UIRenderSystem();

                // create and init the UI manager
                UiFactory.CreateWorldBoardScreen(game);
                WorldBoardContext = new GameContext(systems, new List <ISystem>()
                {
                    uiSystem, renderingSystem
                }, UiFactory.WorldBoardScreen);
                return(WorldBoardContext);
            }
        }
Esempio n. 3
0
 public void RenderingUpdate(long gameTime, NamelessGame namelessGame)
 {
     foreach (var system in RenderingSystems)
     {
         system.Update(gameTime, namelessGame);
     }
 }
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            while (namelessGame.Commander.DequeueCommand(out AttackCommand ac))
            {
                var random = new InternalRandom();

                var source = ac.getSource();
                var stats  = source.GetComponentOfType <Stats>();

                //TODO: attack damage based on stats, equipment etc.
                int damage = stats.Attack.Value;
                DamageHelper.ApplyDamage(ac.getTarget(), ac.getSource(), damage);

                Description targetDescription = ac.getTarget().GetComponentOfType <Description>();
                Description sourceDescription = ac.getSource().GetComponentOfType <Description>();
                if (targetDescription != null && sourceDescription != null)
                {
                    var logCommand = new HudLogMessageCommand();
                    namelessGame.Commander.EnqueueCommand(logCommand);

                    logCommand.LogMessage += (sourceDescription.Name + " deals " + (damage) +
                                              " damage to " + targetDescription.Name);
                    //namelessGame.WriteLineToConsole;
                }
            }
        }
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            foreach (var action in UiFactory.MainMenuScreen.SimpleActions)
            {
                switch (action)
                {
                case MainMenuAction.GenerateNewTimeline:
                    break;

                case MainMenuAction.NewGame:
                    namelessGame.ContextToSwitch = ContextFactory.GetIngameContext(namelessGame);
                    break;

                case MainMenuAction.Options:
                    break;

                case MainMenuAction.LoadGame:
                    break;

                case MainMenuAction.Exit:
                    namelessGame.Exit();
                    break;

                default:
                    break;
                }
            }

            UiFactory.MainMenuScreen.SimpleActions.Clear();
        }
Esempio n. 6
0
        public static Entity CreateRing(int x, int y, int i, NamelessGame game)
        {
            Entity item = new Entity();

            item.AddComponent(new Item(ItemType.Armor, 2, ItemQuality.Normal, 1, 1, ""));
            item.AddComponent(new Drawable('R', new Color(1f, 1f, 0)));
            item.AddComponent(new Description("Ring " + i.ToString(), "Simple ring"));
            item.AddComponent(new Equipment(new List <Slot>()
            {
                Slot.Ring1
            },
                                            new List <Slot>()
            {
                Slot.Ring2
            }));
            item.AddComponent(new Stats()
            {
                Attack      = new SimpleStat(10, 0, 100),
                AttackSpeed = new SimpleStat(100, 0, 100)
            });
            var position = new Position(x, y);

            item.AddComponent(position);
            game.WorldProvider.MoveEntity(item, position.Point);
            return(item);
        }
Esempio n. 7
0
        public static TimeLine BuildTimeline(NamelessGame game, HistoryGenerationSettings settings)
        {
            var timeline   = new TimeLine(game.WorldSettings.Seed);
            var worldBoard = InitialiseFirstBoard(game, settings);

            //timeline.WorldBoardAtEveryAge.Add(worldBoard);
            timeline.CurrentTimelineLayer = worldBoard;


            //String appPath = System.IO.Directory.GetCurrentDirectory();
            //Stopwatch s = new Stopwatch();
            //s.Start();
            //SaveManager.SaveTimelineLayer(appPath + "\\Layers", worldBoard,
            //    worldBoard.Age.ToString());
            //s.Stop();
            //s = new Stopwatch();
            //s.Start();
            //var timelineLayer = SaveManager.LoadTimelineLayer(appPath + "\\Layers",
            //    worldBoard.Age.ToString());
            //s.Stop();
            //timelineLayer.ToString();
            //for (int i = 1; i < settings.HowOldIsTheWorld; i++)
            //{

            //}
            return(timeline);
        }
 internal static void InitAllContexts(NamelessGame game)
 {
     GetIngameContext(game).ContextScreen.Hide();
     GetInventoryContext(game).ContextScreen.Hide();
     GetMainMenuContext(game).ContextScreen.Hide();
     GetPickUpItemContext(game).ContextScreen.Hide();
     GetWorldBoardContext(game).ContextScreen.Hide();
 }
 internal static void ReleaseAllContexts(NamelessGame game)
 {
     IngameContext     = null;
     inventoryContext  = null;
     mainMenuContext   = null;
     pickUpContext     = null;
     WorldBoardContext = null;
 }
Esempio n. 10
0
        public static Entity CreateTimeline(NamelessGame game)
        {
            Entity timepline = new Entity();

            timepline.AddComponent(HistoryGenerator.BuildTimeline(game, new HistoryGenerator.HistoryGenerationSettings()));

            return(timepline);
        }
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
                while (namelessGame.Commander.DequeueCommand(out DropItemCommand dropCommand))
                {
                    var tile = worldProvider.GetTile(dropCommand.WhereToDrop.X, dropCommand.WhereToDrop.Y);

                    foreach (var dropCommandItem in dropCommand.Items)
                    {
                        tile.AddEntity((Entity)dropCommandItem);
                        dropCommand.Holder.Items.Remove(dropCommandItem);
                        dropCommandItem.GetComponentOfType <Drawable>().Visible = true;
                        var position = dropCommandItem.GetComponentOfType <Position>();
                        position.Point = new Point(dropCommand.WhereToDrop.X, dropCommand.WhereToDrop.Y);
                    }
                }
                while (namelessGame.Commander.DequeueCommand(out PickUpItemCommand pickupCommand))
                {
                    if (pickupCommand != null)
                    {
                        foreach (var pickupCommandItem in pickupCommand.Items)
                        {
                            var tile = worldProvider.GetTile(pickupCommand.WhereToPickUp.X,
                                                             pickupCommand.WhereToPickUp.Y);
                            tile.RemoveEntity((Entity)pickupCommandItem);
                            pickupCommandItem.GetComponentOfType <Drawable>().Visible = false;
                            var ammo = pickupCommandItem.GetComponentOfType <Ammo>();
                            if (ammo != null)
                            {
                                var itemsEntities = pickupCommand.Holder.Items;
                                var itemsWithAmmo = itemsEntities.Select(x => x).Where(i => i.GetComponentOfType <Ammo>() != null);
                                var sameTypeItem  = itemsWithAmmo.FirstOrDefault(x => x.GetComponentOfType <Ammo>().Type.Name == ammo.Type.Name);
                                if (sameTypeItem != null)
                                {
                                    sameTypeItem.GetComponentOfType <Item>().Amount +=
                                        pickupCommandItem.GetComponentOfType <Item>().Amount;
                                    namelessGame.RemoveEntity(pickupCommandItem);
                                }
                                else
                                {
                                    pickupCommand.Holder.Items.Add(pickupCommandItem);
                                }
                            }
                            else
                            {
                                pickupCommand.Holder.Items.Add(pickupCommandItem);
                            }
                        }
                    }
                }
            }
        }
 public static IEntity CreateWindow(int x, int y, NamelessGame namelessGame)
 {
     IEntity window  = new Entity();
     window.AddComponent(new Position(x, y));
     window.AddComponent(new Drawable('O', new Engine.Utility.Color(0.9,0.9,0.9), new Engine.Utility.Color()));
     window.AddComponent(new Description("Window",""));
     window.AddComponent(new OccupiesTile());
     return window;
 }
        private Texture InitializeTexture(NamelessGame game)
        {
            tileAtlas = null;
            tileAtlas = game.Content.Load <Texture2D>("DFfont");
            effect    = game.Content.Load <Effect>("Shader");

            effect.Parameters["tileAtlas"].SetValue(tileAtlas);
            return(tileAtlas);
        }
Esempio n. 14
0
 static void Main()
 {
     //SerializationCodeGenerator.GenerateStorages(typeof(ConsoleCamera));
     //return;
     using (var game = new NamelessGame())
     {
         game.Run();
     }
 }
Esempio n. 15
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            var playerEntity = namelessGame.PlayerEntity;
            var ap           = playerEntity.GetComponentOfType <ActionPoints>();

            if (ap.Points >= 100)
            {
                return;
            }

            IEntity        worldEntity   = namelessGame.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }


            if (worldProvider != null)
            {
                foreach (IEntity entity in this.RegisteredEntities)
                {
                    AIControlled ac           = entity.GetComponentOfType <AIControlled>();
                    Dead         dead         = entity.GetComponentOfType <Dead>();
                    var          actionPoints = entity.GetComponentOfType <ActionPoints>();
                    if (dead == null && actionPoints.Points >= 100)
                    {
                        BasicAi  basicAi        = entity.GetComponentOfType <BasicAi>();
                        Position playerPosition = namelessGame.PlayerEntity
                                                  .GetComponentOfType <Position>();

                        switch (basicAi.State)
                        {
                        case BasicAiStates.Idle:
                        case BasicAiStates.Moving:
                            var pPos = playerPosition.Point.ToVector2();
                            MoveTo(entity, namelessGame, playerPosition.Point, true);
                            var route = basicAi.Route;
                            if (route.Count == 0)
                            {
                                basicAi.State = (BasicAiStates.Idle);
                            }

                            break;

                        case BasicAiStates.Attacking:
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
        private Texture InitializeTexture(NamelessGame game)
        {
            tileAtlas = null;
            tileAtlas = game.Content.Load <Texture2D>("DFfont");

            whiteRectangle = new Texture2D(game.GraphicsDevice, 1, 1);
            whiteRectangle.SetData(new[] { Microsoft.Xna.Framework.Color.White });

            return(tileAtlas);
        }
Esempio n. 17
0
        public InputSystem(IKeyIntentTraslator translator, NamelessGame namelessGame)
        {
            this.translator                = translator;
            this.namelessGame              = namelessGame;
            namelessGame.Window.TextInput += WindowOnTextInput;
            namelessGame.Window.KeyDown   += Window_KeyDown;

            Signature.Add(typeof(InputComponent));
            Signature.Add(typeof(InputReceiver));
        }
Esempio n. 18
0
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            foreach (IEntity entity in RegisteredEntities)
            {
                InputComponent inputComponent = entity.GetComponentOfType <InputComponent>();
                if (inputComponent != null)
                {
                    foreach (Intent intent in inputComponent.Intents)
                    {
                        switch (intent.Intention)
                        {
                        case IntentEnum.MoveUp:
                        case IntentEnum.MoveDown:
                        case IntentEnum.MoveLeft:
                        case IntentEnum.MoveRight:
                        case IntentEnum.MoveTopLeft:
                        case IntentEnum.MoveTopRight:
                        case IntentEnum.MoveBottomLeft:
                        case IntentEnum.MoveBottomRight:
                        {
                            var      cursorEntity = namelessGame.CursorEntity;
                            Position position     = cursorEntity.GetComponentOfType <Position>();
                            if (position != null)
                            {
                                int newX =
                                    intent.Intention == IntentEnum.MoveLeft || intent.Intention == IntentEnum.MoveBottomLeft ||
                                    intent.Intention == IntentEnum.MoveTopLeft ? position.Point.X - 1 :
                                    intent.Intention == IntentEnum.MoveRight || intent.Intention == IntentEnum.MoveBottomRight ||
                                    intent.Intention == IntentEnum.MoveTopRight ? position.Point.X + 1 :
                                    position.Point.X;
                                int newY =
                                    intent.Intention == IntentEnum.MoveDown || intent.Intention == IntentEnum.MoveBottomLeft ||
                                    intent.Intention == IntentEnum.MoveBottomRight ? position.Point.Y - 1 :
                                    intent.Intention == IntentEnum.MoveUp || intent.Intention == IntentEnum.MoveTopLeft ||
                                    intent.Intention == IntentEnum.MoveTopRight ? position.Point.Y + 1 :
                                    position.Point.Y;

                                position.Point = new Point(newX, newY);
                            }



                            break;
                        }

                        default:
                            break;
                        }
                    }

                    inputComponent.Intents.Clear();
                }
            }
        }
        private void MoveCamera(NamelessGame game, ConsoleCamera camera)
        {
            Position playerPosition = game.FollowedByCameraEntity
                                      .GetComponentOfType <Position>();

            Point p = camera.getPosition();

            p.X = (playerPosition.Point.X - game.GetSettings().GetWidthZoomed() / 2);
            p.Y = (playerPosition.Point.Y - game.GetSettings().GetHeightZoomed() / 2);
            camera.setPosition(p);
        }
Esempio n. 20
0
 public bool GetBlocksVision(NamelessGame namelessGame)
 {
     foreach (var entity in entitiesOnTile)
     {
         var blocksVision = entity.GetComponentOfType <BlocksVision>();
         if (blocksVision != null)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 21
0
        private static List <Region> GetRegions(TimelineLayer timelineLayer, NamelessGame game, InternalRandom rand, Func <WorldTile, bool> searchCriterion, Action <WorldTile, Region> onFoundRegion, Func <string> nameGenerator)
        {
            List <Region> regions     = new List <Region>();
            var           searchPoint = new Microsoft.Xna.Framework.Point();

            for (; searchPoint.X < game.WorldSettings.WorldBoardWidth; searchPoint.X++)
            {
                for (searchPoint.Y = 0; searchPoint.Y < game.WorldSettings.WorldBoardHeight; searchPoint.Y++)
                {
                    if (searchCriterion(timelineLayer.WorldTiles[searchPoint.X, searchPoint.Y]))
                    {
                        Region r = new Region();
                        r.Name  = nameGenerator();
                        r.Color = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 1f);
                        regions.Add(r);

                        var firstNode = timelineLayer.WorldTiles[searchPoint.X, searchPoint.Y];

                        var floodList = new Queue <WorldTile>();
                        floodList.Enqueue(firstNode);
                        onFoundRegion(firstNode, r);
                        r.SizeInTiles++;

                        void AddToFloodList(int x, int y, Region region)
                        {
                            if (searchCriterion(timelineLayer.WorldTiles[x, y]))
                            {
                                floodList.Enqueue(timelineLayer.WorldTiles[x, y]);
                                onFoundRegion(timelineLayer.WorldTiles[x, y], region);
                                region.SizeInTiles++;
                            }
                        }

                        while (floodList.Any())
                        {
                            var elem = floodList.Dequeue();

                            AddToFloodList(elem.WorldBoardPosiiton.X - 1, elem.WorldBoardPosiiton.Y, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X + 1, elem.WorldBoardPosiiton.Y, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X, elem.WorldBoardPosiiton.Y - 1, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X, elem.WorldBoardPosiiton.Y + 1, r);

                            AddToFloodList(elem.WorldBoardPosiiton.X - 1, elem.WorldBoardPosiiton.Y - 1, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X + 1, elem.WorldBoardPosiiton.Y + 1, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X + 1, elem.WorldBoardPosiiton.Y - 1, r);
                            AddToFloodList(elem.WorldBoardPosiiton.X - 1, elem.WorldBoardPosiiton.Y + 1, r);
                        }
                    }
                }
            }

            return(regions);
        }
Esempio n. 22
0
        public static Entity CreateSimplePlayerCharacter(int x, int y, NamelessGame game)
        {
            var    position        = new Position(x, y);
            Entity playerCharacter = new Entity();

            playerCharacter.AddComponent(new Character());
            playerCharacter.AddComponent(new Player());
            playerCharacter.AddComponent(new InputReceiver());
            playerCharacter.AddComponent(new FollowedByCamera());
            playerCharacter.AddComponent(new InputComponent());
            playerCharacter.AddComponent(position);
            playerCharacter.AddComponent(new Drawable('@', new Engine.Utility.Color(0.9, 0.9, 0.9)));
            playerCharacter.AddComponent(new Description("Player", ""));
            var holder = new ItemsHolder();

            playerCharacter.AddComponent(holder);
            playerCharacter.AddComponent(new EquipmentSlots(holder, game));
            playerCharacter.AddComponent(new OccupiesTile());


            var stats = new Stats();

            stats.Health.Value    = 100;
            stats.Health.MaxValue = 100;

            stats.Stamina.Value    = 100;
            stats.Stamina.MaxValue = 100;


            stats.Attack.Value      = 25;
            stats.Defence.Value     = 10;
            stats.AttackSpeed.Value = 100;
            stats.MoveSpeed.Value   = 100;

            stats.Strength.Value    = 10;
            stats.Reflexes.Value    = 10;
            stats.Perception.Value  = 10;
            stats.Willpower.Value   = 10;
            stats.Imagination.Value = 10;
            stats.Wit.Value         = 10;

            playerCharacter.AddComponent(stats);

            playerCharacter.AddComponent(new ActionPoints()
            {
                Points = 100
            });

            game.WorldProvider.MoveEntity(playerCharacter, position.Point);

            return(playerCharacter);
        }
        public override void Update(long gameTime, NamelessGame game)
        {
            this.gameTime = gameTime;

            game.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
            game.GraphicsDevice.SamplerStates[0]  = sampler;
            game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            //todo move to constructor or some other place better suited for initialization
            if (tileAtlas == null)
            {
                InitializeTexture(game);
            }

            IEntity        worldEntity   = game.TimelineEntity;
            IWorldProvider worldProvider = null;

            if (worldEntity != null)
            {
                worldProvider = worldEntity.GetComponentOfType <TimeLine>().CurrentTimelineLayer.Chunks;
            }

            var entity = game.CameraEntity;

            ConsoleCamera camera    = entity.GetComponentOfType <ConsoleCamera>();
            Screen        screen    = entity.GetComponentOfType <Screen>();
            Commander     commander = game.Commander;

            screen = UpdateZoom(game, commander, entity, screen, out bool zoomUpdate);

            if (foregroundModel == null || zoomUpdate)
            {
                foregroundModel = new TileModel(screen.Height, screen.Width);
            }

            if (backgroundModel == null || zoomUpdate)
            {
                backgroundModel = new TileModel(screen.Height, screen.Width);
            }


            if (camera != null && screen != null && worldProvider != null)
            {
                MoveCamera(game, camera);
                FillcharacterBufferVisibility(game, screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithWorld(screen, camera, game.GetSettings(), worldProvider);
                FillcharacterBuffersWithTileObjects(screen, camera, game.GetSettings(), game, worldProvider);
                FillcharacterBuffersWithWorldObjects(screen, camera, game.GetSettings(), game);
                RenderScreen(game, screen, game.GetSettings());
            }
        }
        private void FillcharacterBufferVisibility(NamelessGame game, Screen screen, ConsoleCamera camera,
                                                   GameSettings settings, IWorldProvider world)
        {
            int         camX           = camera.getPosition().X;
            int         camY           = camera.getPosition().Y;
            Position    playerPosition = game.PlayerEntity.GetComponentOfType <Position>();
            BoundingBox b = new BoundingBox(camera.getPosition(),
                                            new Point(settings.GetWidthZoomed() + camX, settings.GetHeightZoomed() + camY));

            for (int x = 0; x < settings.GetWidthZoomed(); x++)
            {
                for (int y = 0; y < settings.GetHeightZoomed(); y++)
                {
                    screen.ScreenBuffer[x, y].isVisible = false;
                }
            }

            //return;

            if (fov == null)
            {
                {
                    fov = new PermissiveVisibility((x, y) => { return(!world.GetTile(x, y).GetBlocksVision(game)); },
                                                   (x, y) =>
                    {
                        Stopwatch s           = Stopwatch.StartNew();
                        var lambdaLocalScreen = game.CameraEntity.GetComponentOfType <Screen>();
                        s.Stop();
                        s.ToString();

                        Point screenPoint = camera.PointToScreen(x, y);
                        if (screenPoint.X >= 0 && screenPoint.X < settings.GetWidthZoomed() && screenPoint.Y >= 0 &&
                            screenPoint.Y < settings.GetHeightZoomed())
                        {
                            lambdaLocalScreen.ScreenBuffer[screenPoint.X, screenPoint.Y].isVisible = true;
                        }
                    }, (x, y) =>
                    {
                        if (Math.Abs(x) > 60 || Math.Abs(y) > 60)
                        {
                            return(10000);
                        }
                        //   return (int)((x*x) + (y*y));
                        return(Math.Abs(x) + Math.Abs(y));
                    }
                                                   );
                }
            }
            fov.Compute(playerPosition.Point, 60);
        }
        void DrawTile(GraphicsDevice device, NamelessGame game, int screenPositionX, int screenPositionY, int positionX, int positionY,
                      AtlasTileData atlasTileData,
                      Color color, Color backGroundColor, TileModel foregroundModel, TileModel backgroundModel)
        {
            if (atlasTileData == null)
            {
                atlasTileData = new AtlasTileData(1, 1);
            }


            int tileHeight = game.GetSettings().GetFontSizeZoomed();
            int tileWidth  = game.GetSettings().GetFontSizeZoomed();


            float textureX = atlasTileData.X * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);
            float textureY = atlasTileData.Y * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            float textureXend = (atlasTileData.X + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Width);

            float textureYend = (atlasTileData.Y + 1f) * (Constants.tileAtlasTileSize / (float)tileAtlas.Height);

            var settings = game.GetSettings();

            var arrayPosition = (screenPositionX * 4) + (screenPositionY * settings.GetWidthZoomed() * 4);



            var foregroundvertices = foregroundModel.Vertices;

            foregroundvertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            foregroundvertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            foregroundvertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            foregroundvertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));

            var backgroundVertices = backgroundModel.Vertices;

            backgroundVertices[arrayPosition] = new Vertex(new Vector3(positionX, positionY, 0), color.ToVector4(),
                                                           backGroundColor.ToVector4(), new Vector2(textureX, textureY));
            backgroundVertices[arrayPosition + 1] = new Vertex(new Vector3(positionX + tileWidth, positionY, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureY));
            backgroundVertices[arrayPosition + 2] = new Vertex(new Vector3(positionX, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureX, textureYend));
            backgroundVertices[arrayPosition + 3] = new Vertex(new Vector3(positionX + tileWidth, positionY + tileHeight, 0), color.ToVector4(),
                                                               backGroundColor.ToVector4(), new Vector2(textureXend, textureYend));
        }
        private void RenderScreen(NamelessGame game, Screen screen, GameSettings settings)
        {
            effect.Parameters["tileAtlas"].SetValue(tileAtlas);
            var projectionMatrix = //Matrix.CreateOrthographic(game.getActualWidth(),game.getActualHeight(),0,1);
                                   Matrix.CreateOrthographicOffCenter(0, game.GetActualWidth(), game.GetActualHeight(), 0, 0, 2);

            effect.Parameters["xViewProjection"].SetValue(projectionMatrix);

            effect.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
            effect.GraphicsDevice.BlendState       = BlendState.AlphaBlend;

            var       device = game.GraphicsDevice;
            Stopwatch s      = Stopwatch.StartNew();

            for (int y = 0; y < settings.GetHeightZoomed(); y++)
            {
                for (int x = 0; x < settings.GetWidthZoomed(); x++)
                {
                    DrawTile(game.GraphicsDevice, game, x, y,
                             x * settings.GetFontSizeZoomed(),
                             y * settings.GetFontSizeZoomed(),
                             characterToTileDictionary[screen.ScreenBuffer[y, x].Char],
                             screen.ScreenBuffer[y, x].CharColor,
                             screen.ScreenBuffer[y, x].BackGroundColor, foregroundModel, backgroundModel
                             );
                }
            }
            s.Stop();
            var tileModel = backgroundModel;

            effect.CurrentTechnique = effect.Techniques["Background"];
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, tileModel.Vertices, 0, tileModel.Vertices.Length,
                                                 tileModel.Indices.ToArray(), 0, 2, this.VertexDeclaration);
            }

            effect.CurrentTechnique = effect.Techniques["Point"];

            tileModel = foregroundModel;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, tileModel.Vertices, 0, tileModel.Vertices.Length,
                                                 tileModel.Indices.ToArray(), 0, tileModel.Indices.Count() / 3, this.VertexDeclaration);
            }
        }
Esempio n. 27
0
        public static Entity CreateLightAmmo(int x, int y, int i, int amount, NamelessGame game, AmmoLibrary ammoLibrary)
        {
            Entity item     = new Entity();
            var    revoAmmo = ammoLibrary.AmmoTypes.First();

            item.AddComponent(new Item(ItemType.Ammo, 0.01f, ItemQuality.Normal, amount, 1, ""));
            item.AddComponent(new Ammo(new AmmoType()));
            item.AddComponent(new Drawable(revoAmmo.Name[0], new Color(0f, 1f, 0)));
            item.AddComponent(new Description(revoAmmo.Name + i.ToString(), revoAmmo.Name));
            var position = new Position(x, y);

            item.AddComponent(position);
            game.WorldProvider.MoveEntity(item, position.Point);
            return(item);
        }
        public override void Update(long gameTime, NamelessGame namelessGame)
        {
            foreach (IEntity entity in RegisteredEntities)
            {
                Damage     damage = entity.GetComponentOfType <Damage>();
                SimpleStat health = entity.GetComponentOfType <Stats>().Health;
                health.Value -= damage.DamageValue;
                if (health.Value <= health.MinValue)
                {
                    namelessGame.Commander.EnqueueCommand(new DeathCommand(entity));
                }

                entity.RemoveComponentOfType <Damage>();
            }
        }
Esempio n. 29
0
        public MainMenuScreen(NamelessGame game)
        {
            // Panel = new Panel(new Vector2(game.GetSettings().HudWidth(), game.GetActualCharacterHeight()), PanelSkin.Default, Anchor.Center);

            Panel = new Panel()
            {
                HorizontalAlignment = HorizontalAlignment.Center
            };
            var vPanel = new VerticalStackPanel();

            NewGame = new ImageTextButton()
            {
                Text = "New game", Width = 200, Height = 50, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center
            };
            LoadGame = new ImageTextButton()
            {
                Text = "Load", Width = 200, Height = 50, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center
            };;
            CreateTimeline = new ImageTextButton()
            {
                Text = "Create timeline", Width = 200, Height = 50, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center
            };
            Options = new ImageTextButton()
            {
                Text = "Options", Width = 200, Height = 50, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center
            };
            Exit = new ImageTextButton()
            {
                Text = "Exit", Width = 200, Height = 50, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center
            };

            NewGame.Click        += (sender, args) => { SimpleActions.Add(MainMenuAction.NewGame); };
            LoadGame.Click       += (sender, args) => { SimpleActions.Add(MainMenuAction.LoadGame); };
            CreateTimeline.Click += (sender, args) => { SimpleActions.Add(MainMenuAction.GenerateNewTimeline); };
            Options.Click        += (sender, args) => { SimpleActions.Add(MainMenuAction.Options); };
            Exit.Click           += (sender, args) => { SimpleActions.Add(MainMenuAction.Exit); };

            vPanel.Widgets.Add(NewGame);
            vPanel.Widgets.Add(LoadGame);
            vPanel.Widgets.Add(CreateTimeline);
            vPanel.Widgets.Add(Options);
            vPanel.Widgets.Add(Exit);
            Panel.Widgets.Add(vPanel);
            game.Desktop.Widgets.Add(Panel);
        }
Esempio n. 30
0
 public override void Update(long gameTime, NamelessGame namelessGame)
 {
     if (gameTime - previousGametimeForMove > inputsTimeLimit)
     {
         previousGametimeForMove = gameTime;
         foreach (IEntity entity in RegisteredEntities)
         {
             InputComponent inputComponent = entity.GetComponentOfType <InputComponent>();
             InputReceiver  receiver       = entity.GetComponentOfType <InputReceiver>();
             if (receiver != null && inputComponent != null && lastState != default)
             {
                 inputComponent.Intents.AddRange(translator.Translate(lastState.GetPressedKeys(), lastCommand));
                 lastCommand = Char.MinValue;
                 lastState   = default;
             }
         }
     }
 }