Beispiel #1
0
        protected override void StartCore()
        {
            _bodyComponent = GameObject.GetComponent<BodyComponent>();
            _rectRenderer = GameObject.GetComponent<RectRenderer>();
            _animatedSpriteComponent = GameObject.GetComponent<AnimatedSpriteComponent>();

            //TODO: If null => GameObject.OnComponentAdded += .... set the _bodyComponent
        }
Beispiel #2
0
        private Entity CreatePlayer(Vector2 pos)
        {
            Entity player = Engine.Entities.CreateEntity("player");

            //player.Transform.Scale = new Vector2(0.5f, 1f);
            player.Transform.Position = pos;

            const int playerWidth = 64; //96;
            const int playerHeight = 64; //96;

            AnimatedSpriteComponent animationComponent = new AnimatedSpriteComponent(player, Engine.Textures["lumberjack"]);
            animationComponent.AddAnimation("walk_left", new SpriteAnimation(64, 64, 4, 256, 64, 0, 64));
            animationComponent.AddAnimation("walk_right", new SpriteAnimation(64, 64, 4, 256, 64, 0, 128));
            animationComponent.AddAnimation("walk_up", new SpriteAnimation(64, 64, 4, 256, 64, 0, 196));
            animationComponent.AddAnimation("walk_down", new SpriteAnimation(64, 64, 4, 256, 64, 0, 0));
            animationComponent.SetCurrentAnimation("walk_right");

            player.AddComponent(animationComponent);
            //player.AddComponent(new SpriteComponent(player, Engine.Textures["crate"]));
            player.AddComponent(new PlayerInput(player));

            //Body body = BodyFactory.CreateRectangle(
            //    Engine.Entities.PhysicsSystem.World,
            //    ConvertUnits.ToSimUnits(playerWidth/2 * player.Transform.Scale.X),
            //    ConvertUnits.ToSimUnits(playerHeight * player.Transform.Scale.Y),
            //    1);

            //body.BodyType = BodyType.Dynamic;
            //body.FixedRotation = true;
            //body.Mass = 0;
            //body.Friction = 1f;
            //body.LinearDamping = 1f;

            //body.Position = new Vector2(
            //    ConvertUnits.ToSimUnits(player.Transform.Position.X),
            //    ConvertUnits.ToSimUnits(player.Transform.Position.Y));

            //body.Rotation = player.Transform.Rotation;
            //BodyComponent bodyComponent = new BodyComponent(player, body);

            //bodyComponent.OnCollision += (sender, args) =>
            //{
            //    if (args.BodyComponentB.GameObject.Tag == "ground")
            //        args.BodyComponentB.Body.IgnoreGravity = false;
            //};

            //player.AddComponent(bodyComponent);

            //e.AddComponent(new RectCollider(e) { Width = width, Height = height });
            player.AddComponent(new RectRenderer(player, Rectangle.Empty, new Texture2D(Engine.Window.GraphicsDevice, 1, 1)));

            return player;
        }