public Character CreateCharacter(float x, float y) { var data = GameModel.Instance.Game.Content.Load<CharacterDTO>("CharacterDTO"); // generate texture. const int width = 32 - 12; const int height = 48 - 8; var texture = GameModel.Instance.TextureHelper.GenerateSimpleTexture(width, height, Color.BlanchedAlmond); var instance = new Character(data.name, data.level) { Texture = texture, Width = width, Height = height, DrawLayerType = DrawManager.DrawLayerType.Character }; instance.Body = GameModel.Instance.BodyManager.CreateCharacterBody(instance); instance.Position = new Vector2(x, y); return instance; }
public Body CreateCharacterBody(Character character) { Body body = BodyFactory.CreateRectangle(GameModel.Instance.World, ConvertUnits.ToSimUnits(character.Width), ConvertUnits.ToSimUnits(character.Height), 1f); body.FixedRotation = true; body.SleepingAllowed = false; body.Position = ConvertUnits.ToSimUnits(new Vector2(Game1.ScreenWidth / 2, 0)); body.BodyType = BodyType.Dynamic; body.Restitution = 0.05f; body.Friction = 0f; body.CollisionCategories = Category.Cat2; body.CollidesWith = Category.Cat1; return body; /*Body body = BodyFactory.CreateBody(GameModel.Instance.World, ConvertUnits.ToSimUnits(new Vector2(Game1.ScreenWidth / 2, 0))); var topFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(18), ConvertUnits.ToSimUnits(2), 1f, new Vector2(0, ConvertUnits.ToSimUnits(-19)), body); topFixture.Friction = 0f; var bottomFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(18), ConvertUnits.ToSimUnits(2), 1f, new Vector2(0, ConvertUnits.ToSimUnits(19)), body); bottomFixture.Friction = .5f; var leftFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(1), ConvertUnits.ToSimUnits(38), 1f, new Vector2(ConvertUnits.ToSimUnits(-9.5), 0), body); leftFixture.Friction = 0; var rightFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(1), ConvertUnits.ToSimUnits(38), 1f, new Vector2(ConvertUnits.ToSimUnits(9.5), 0), body); rightFixture.Friction = 0; body.FixedRotation = true; body.SleepingAllowed = false; body.Restitution = 0.05f; body.BodyType = BodyType.Dynamic; body.CollisionCategories = Category.Cat2; body.CollidesWith = Category.Cat1; return body;*/ }
public CharacterMoves(Character character) { _character = character; GameModel.Instance.KeyboardInput.onPressedKeys += onPressedKeysHandler; }