Beispiel #1
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>());
        }
Beispiel #2
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());
            }
        }