Example #1
0
 public SpriteGrid(SpriteGridSettings settings) {
     Columns = settings.Columns;
     Rows = settings.Rows;
     Texture = settings.Texture;
     SpriteBatch = settings.SpriteBatch;
     Layer = settings.Layer;
 }
        public EditableGameContext(Size windowBoundsInPixels)
            : base(windowBoundsInPixels) {
            spriteBatch = new SpriteBatch() {
                IsTransparent = true,
                Layer = 1
            };

            Entity.Create(Entities.SpriteBatch, spriteBatch);

            Registry.Entered += OnEntityEntered;
            Registry.Removed += OnEntityRemoved;

            Registry.SetTrigger(
                component => component is Sprite,
                (sender, args) => {
                    foreach (Sprite sprite in args.AttachedComponents.ToList()) {
                        // instead attach to name~editor entity, it makes more sense... but remember to set transform parent to the original entity!
                        /*
                        SpriteDebug debug = new SpriteDebug();
                        {
                            sprite.Record.Add(debug);
                            spriteBatch.Add(debug);
                        }*/
                    }

                    foreach (Sprite sprite in args.DettachedComponents.ToList()) {
                        // todo: figure out how to remove the SpriteDebug component, since the `sprite` no longer
                        // knows which entity it was dettached from at this point...
                    }
                }
            );
        }
Example #3
0
        void CreateTheDungeon(SpriteBatch spriteBatch) {
            _dungeon = Entity.Create(Entities.Game.Dungeon,
                new Transformable2D() {
                    Position = new Vector2(
                        -(GameContext.Bounds.Width / 2),
                        -(GameContext.Bounds.Height / 2))
                });

            SpriteGridSettings gridSettings =
                new SpriteGridSettings() {
                    SpriteBatch = spriteBatch,
                    Columns = DungeonColumns,
                    Rows = DungeonRows
                };

            gridSettings.Layer = 0;

            Entity.Create(Entities.Game.DungeonFloor,
                new Transformable2D() {
                    Parent = _dungeon.GetComponent<Transformable2D>()
                },
                new SpriteGrid(gridSettings) {
                    Texture = Texture.FromFile("Content/Graphics/floor.png")
                }
            );

            string dungeonWallsMap =
                "11111011111" +
                "10000000001" +
                "10000000001" +
                "10000000001" +
                "10001000001" +
                "10001000001" +
                "10111110001" +
                "10001100001" +
                "10002000001" +
                "10000000001" +
                "10000000011" +
                "10000021111" +
                "10000000011" +
                "10000000001" +
                "10000000021" +
                "11000000011";

            gridSettings.Layer = 1;

            Entity.Create(Entities.Game.DungeonWalls,
                new Transformable2D() {
                    Parent = _dungeon.GetComponent<Transformable2D>()
                },
                new MappedSpriteGrid(gridSettings, dungeonWallsMap) {
                    Textures = new Texture[] { 
                        Texture.FromFile("Content/Graphics/wall.png"),       // #1
                        Texture.FromFile("Content/Graphics/wall-broken.png") // #2
                    }
                }
            );

            string dungeonEnemiesMap =
                "00000000000" +
                "00001111000" +
                "00000100000" +
                "00000000000" +
                "00010000000" +
                "00000010000" +
                "01000000000" +
                "01100010000" +
                "00000100000" +
                "00011100000" +
                "00000000000" +
                "00000000000" +
                "00000001100" +
                "00000000000" +
                "00000000000" +
                "00000000000";

            Entity.Create(Entities.Game.DungeonEnemies,
                new Transformable2D() {
                    Parent = _dungeon.GetComponent<Transformable2D>()
                },
                new MappedSpriteGrid(gridSettings, dungeonEnemiesMap) {
                    Texture = Texture.FromFile("Content/Graphics/enemy.png")
                }
            );
        }
Example #4
0
        void CreateSquad(SpriteBatch spriteBatch) {
            Entity.Define("squad-unit",
                typeof(Health));
            
            Texture unitTexture = Texture.FromFile("Content/Graphics/unit.png");

            _squadLeader = CreateSquadUnit("leader", _dungeon, new Vector2(unitTexture.Width * (DungeonColumns / 2), 0));
            _squadLeader.Add(
                new SquadLeader() {
                    MovementInPixels = unitTexture.Width
                });

            IEntityRecord squadUnitLeft = CreateSquadUnit("left", _squadLeader, new Vector2(-unitTexture.Width, -unitTexture.Width));
            IEntityRecord squadUnitRight = CreateSquadUnit("right", _squadLeader, new Vector2(unitTexture.Width, -unitTexture.Width));
            IEntityRecord squadUnitMiddle = CreateSquadUnit("middle", _squadLeader, new Vector2(0, -unitTexture.Width));
            
            spriteBatch.Add(_squadLeader.GetComponent<Sprite>());
            spriteBatch.Add(squadUnitLeft.GetComponent<Sprite>());
            spriteBatch.Add(squadUnitRight.GetComponent<Sprite>());
            spriteBatch.Add(squadUnitMiddle.GetComponent<Sprite>());
        }
Example #5
0
        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            _context = new EditableGameContext(
                windowBoundsInPixels: ClientRectangle.Size);

            _context.Registry.Entered += OnEntityEntered;
            _context.Registry.Removed += OnEntityRemoved;
            
            Sprite logoCactusSprite = new Sprite() {
                Layer = 1,
                Size = new Size(48, 48),
                TextureSourceRectangle = new Rectangle(Point.Empty, new Size(48, 48)),

                Texture = Texture.FromFile("fruitless-logo.png")
            };

            Sprite logoNameSprite = new Sprite() {
                Layer = 1,
                Size = new Size(184, 48),
                TextureSourceRectangle = new Rectangle(new Point(56, 0), new Size(184, 48)),

                Texture = Texture.FromFile("fruitless-logo.png")
            };

            Sprite backgroundSprite = new Sprite() {
                Repeats = true,
                Size = new Size(
                    _context.Bounds.Width, 
                    _context.Bounds.Height),

                Texture = Texture.FromFile("tile.png")
            };

            Sprite rectangleSprite = new Sprite()
            {
                TintColor = Color4.Red,
                Size = new Size(16, 16),
                Texture = Texture.FromFile("tile.png")
            };

            SpriteBatch spriteBatch = new SpriteBatch();
            {
                spriteBatch.Add(backgroundSprite);
                spriteBatch.Add(logoCactusSprite);
                spriteBatch.Add(logoNameSprite);

                // something is very wrong here :(((
                //spriteBatch.Add(rectangleSprite);
            }

            Entity.Create("background", backgroundSprite);
            Entity.Create("logo", new Bounce() { Speed = 0.005f });
            Entity.Create("logo-cactus", logoCactusSprite, new Jumps() { JumpDuration = TimeSpan.FromSeconds(0.5) }, new IsPulledByGravity());
            Entity.Create("logo-name", logoNameSprite);
            Entity.Create(rectangleSprite);
            Entity.Create("batch", spriteBatch);
            
            logoCactusSprite.Transform.Parent = Entity.Find("logo").GetComponent<Transformable2D>();
            logoCactusSprite.Transform.Position = new Vector2(-100, 0);
            logoNameSprite.Transform.Parent = Entity.Find("logo").GetComponent<Transformable2D>();
            logoNameSprite.Transform.Position = new Vector2(24, 0);
            logoNameSprite.Transform.Scale = new Vector2(0.8f, 0.8f);
            logoNameSprite.Transform.Rotation = MathHelper.DegreesToRadians(10);

            rectangleSprite.Transform.Position = new Vector2(-100, 0);
      /*
            SpriteFontDescription font = new SpriteFontDescription() {
                Characters = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}“ ",
                CharacterSize = new Size(8, 8),
                TextureSourceRectangle = new Rectangle(new Point(0, 16), new Size(128, 176)),

                Texture = Texture.FromFile("ass_font_tran.png")
            };

            Text text = new Text() {
                FontDescription = font,
                Content = "hold nu kaeft mand :D"
            };

            TextBatch textBatch = new TextBatch() {
                Layer = 1
            };

            textBatch.AddText(text);

            Entity.Create("text", text);
            // at this point 'text' will automatically add an entity for each character in the string
            // i.e. 'text~h', 'text~o', 'text~l', etc...
            Entity.Create("text batch", textBatch);
            */
            /*
            Text text = new Text() {
                Layer = 3,
                Content = "hold nu kaeft mand :D",
                Size = new Size(128, 176),
                TextureSourceRectangle = new Rectangle(new Point(0, 16), new Size(128, 176)),

                Texture = Texture.FromFile("ass_font_tran.png")
            };

            spriteBatch.Add(text);

            Entity.Create("text-sheet", text);
            */

            IEntityRecord walls = Entity.Create("walls", 
                new Area() { 
                    Boundaries = _context.Bounds 
                }
            );

            Entity.Find("logo-cactus").Add(new AreaIntersectionTrigger() {
                Area = walls.GetComponent<Area>()
            });

            Entity.Find("logo-cactus").Add(new Bounces() {
                Friction = 0.25f
            });

            Random r = new Random();

            for (int i = 3; i < 13; i++) {
                Sprite s = new Sprite() {
                    Layer = i,

                    Size = new Size(240 / 2, 48 / 2),

                    Texture = Texture.FromFile("fruitless-logo.png")
                };

                spriteBatch.Add(s);

                Entity.Create("" + i,
                    s,
                    new Spin() {
                        Speed = 10.0f * (float)r.NextDouble()
                    },
                    new HasVelocity() {
                        Velocity = new Vector2(
                            (r.Next(0, 450) * (r.Next(0, 2) > 0 ? 1 : -1)) * (float)r.NextDouble(),
                            (r.Next(2, 700)) * (float)r.NextDouble())
                    },
                    new IsPulledByGravity(),
                    new AreaIntersectionTrigger() {
                        Area = walls.GetComponent<Area>()
                    },
                    new Bounces());
            }
        }