Ejemplo n.º 1
0
        public Brick(int posx, int posy, string NameSprite, int Score, Breakout breakout) : base(true)
        {
            // initial placement
            Transform.x = posx;
            Transform.y = posy;
            AddComponent(new Engine.System.Graphics.SpriteComponent(this, NameSprite, true));
            AddComponent(new RuleComponent(this));
            AddComponent(CollisionComponentBuilder.CreateNew()
                         .Init(this, new Vector2(60, 30))
                         .SetBodyType(BodyType.Static)
                         .SetCollidesWith(Category.Cat1)
                         .SetCategoriesCollision(Category.Cat2)
                         .SetFriction(0f)
                         .AddOnCollisionEventHandler(delegate(Fixture sender, Fixture other, Contact contact)
            {
                other.Body.LinearVelocity = new Vector2(other.Body.LinearVelocity.X * 400, other.Body.LinearVelocity.Y * 400);
                return(true);
            })
                         .Build());
            breakout.wall.Add(this);
            breakout.nbBrick += 1;
            Name              = "Brick" + breakout.nbBrick;
            ScoreGiven        = Score;
            var msg = new RuleManager.EngineMessage();

            msg.entitybase  = EntityManager.GetEntity("Ball");
            msg.entityFocus = this;
            msg.Action      = RuleManager.ActionEngine.Collision;

            GetComponent <RuleComponent>().WatcherActionEngine(msg, BreakBricks, "brick", this, "breakout");
        }
Ejemplo n.º 2
0
        public static void CreateGameScene(Game game)
        {
            var bg_ent = new Entity(true);

            bg_ent.Transform.x = 0;
            bg_ent.Transform.y = 0;
            bg_ent.AddComponent(new SpriteComponent(bg_ent, "CloudBackgroundSmall", true));
            bg_ent.AddComponent(new AudioComponent(bg_ent, "NyanCat", false, false, true));

            Bat      bat      = new Bat();
            Ball     ball     = new Ball();
            Breakout breakout = new Breakout(1, 0, ball);

            /*    breakout.CreateBricks(200, 200, "Brick", 100);
             *  breakout.CreateBricks(200, 400, "Brick", 100);
             *  breakout.CreateBricks(200, 600, "Brick", 100);
             *  breakout.CreateBricks(200, 800, "Brick", 100);
             */

            var invisibleWallLeft  = new InvisibleWall(new Vector2(0, 0), new Vector2(5, 980));
            var invisibleWallRight = new InvisibleWall(new Vector2(640, 0), new Vector2(5, 980));
            var invisibleWallTop   = new InvisibleWall(new Vector2(0, 0), new Vector2(1240, 5));
            var invisibleWallDown  = new InvisibleWall(new Vector2(0, 480), new Vector2(1240, 5), true);


            var bricks    = BrickArenaBuilder.CreateNew().Init().Build();
            var santa_ent = SantaBuilder.CreateNew().Init(game).Build();

            var camera_ent = new Entity(true);

            /*    var cameraInput = new InputComponent(camera_ent);
             *  ActionDelegate cam_up = (entity, dict) => { CameraManager.MoveCameraY(-1); };
             *  ActionDelegate cam_down = (entity, dict) => { CameraManager.MoveCameraY(1); };
             *  ActionDelegate cam_right = (entity, dict) => { CameraManager.MoveCameraX(1); };
             *  ActionDelegate cam_left = (entity, dict) => { CameraManager.MoveCameraX(-1); };
             *
             *  cameraInput.AddAction("cam_up", OnKey.DOWN, Key.Z, null, cam_up);
             *  cameraInput.AddAction("cam_down", OnKey.DOWN, Key.S, null, cam_down);
             *  cameraInput.AddAction("cam_right", OnKey.DOWN, Key.D, null, cam_right);
             *  cameraInput.AddAction("cam_left", OnKey.DOWN, Key.Q, null, cam_left);
             *  camera_ent.AddComponent(cameraInput);*/

            var save_manager = new SavedFilesManager(Manager.Instance);
            var PreSave      = new List <Entity> {
                bg_ent,
                camera_ent, invisibleWallTop, invisibleWallDown, invisibleWallLeft, invisibleWallRight, breakout, ball, bat
            };

            //  PreSave.AddRange(bricks);
            PreSave.AddRange(breakout.wall);
            var scene = new SavedScene();

            scene.entities = PreSave;
            save_manager.SaveScene(scene, "game_scene");
        }