public PlayerFactory(GameData gameData, GameUtils gameUtils, ContentManager contentManager, World physicsWorld, GameWorld gameWorld, AnimationFactory animationFactory, WeaponInventory weaponInventory, FilteredKeyListener keyListener) { GameData = gameData; GameUtils = gameUtils; Content = contentManager; PhysicsWorld = physicsWorld; GameWorld = gameWorld; AnimationFactory = animationFactory; WeaponInventory = weaponInventory; FilteredInputListener = keyListener; }
/// <summary> /// ctor /// </summary> /// <param name="texture"></param> /// <param name="positionTexture"></param> /// <param name="upperBoundTexture"></param> /// <param name="lowerBoundTexture"></param> /// <param name="shape"></param> /// <param name="rigidBody"></param> public Player( ContentManager contentManager, World world, Texture2D texture, GameWorld gameWorld, Shape shape, Body rigidBody, AnimationFactory animationFactory, WeaponInventory weaponInventory, FilteredKeyListener filteredInputListener, GameData gameData, GameUtils gameUtils) : base(world, texture, shape, rigidBody, 0, gameData, gameUtils) { ShootingEffect = contentManager.Load <SoundEffect>(gameData.ShootingEffect).CreateInstance(); DeathEffect = contentManager.Load <SoundEffect>(gameData.DeathEffect).CreateInstance(); HealthEffect = contentManager.Load <SoundEffect>(gameData.HealthEffect).CreateInstance(); WeaponEffect = contentManager.Load <SoundEffect>(gameData.WeaponEffect).CreateInstance(); WeaponEffect.Volume = 1.0f; Active = true; AnimationFactory = animationFactory; GameWorld = gameWorld; Hp = MaxHp; _lastProjectileTime = DateTime.MinValue; WeaponInventory = weaponInventory; FilteredInputListener = filteredInputListener; RenderScale = new Vector2(1, 1); LivesRemaining = MaxLives; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Window.AllowUserResizing = true; Window.Title = "Invaders"; var gameData = JsonConvert.DeserializeObject <GameData>(File.ReadAllText("./GameData.json")); this.TargetElapsedTime = System.TimeSpan.FromSeconds(1f / gameData.Fps); var gameUtils = new GameUtils(gameData); //create physics bounds var aabb = new AABB(); aabb.LowerBound = new Vec2(0, 0); aabb.UpperBound = new Vec2(gameData.MaxXDimension, gameData.MaxYDimension); PhysicsWorld = new World(aabb, new Vec2(0, 0), doSleep: false); PhysicsWorld.SetContactListener(new GameContactListener()); var trackKeys = new Keys[] { Keys.OemCloseBrackets, Keys.OemOpenBrackets, Keys.Left, Keys.Right, Keys.Escape }; FilteredInputListener = new FilteredKeyListener(trackKeys); Container.Register(Component.For <FilteredKeyListener>().Instance(FilteredInputListener).LifestyleSingleton()); Container.Register(Component.For <GraphicsDevice>().Instance(GraphicsDevice).LifestyleSingleton()); Container.Register(Component.For <GameData>().Instance(gameData).LifestyleSingleton()); Container.Register(Component.For <GameUtils>().Instance(gameUtils).LifestyleSingleton()); Container.Register(Component.For <GameWorld>().ImplementedBy <GameWorld>().LifestyleSingleton()); Container.Register(Component.For <World>().Instance(PhysicsWorld).LifestyleSingleton()); Container.Register(Component.For <ContentManager>().Instance(Content).LifestyleSingleton()); Container.Register(Component.For <FontFactory>().ImplementedBy <FontFactory>().LifestyleSingleton()); Container.Register(Component.For <MenuFactory>().ImplementedBy <MenuFactory>().LifestyleSingleton()); Container.Register(Component.For <AnimationFactory>().ImplementedBy <AnimationFactory>().LifestyleSingleton()); Container.Register(Component.For <WeaponFactory>().ImplementedBy <WeaponFactory>().LifestyleSingleton()); Container.Register(Component.For <HealthBarFactory>().ImplementedBy <HealthBarFactory>().LifestyleSingleton()); Container.Register(Component.For <AlienFactory>().ImplementedBy <AlienFactory>().LifestyleSingleton()); Container.Register(Component.For <WeaponInventory>().ImplementedBy <WeaponInventory>().LifestyleSingleton()); Container.Register(Component.For <Background>().ImplementedBy <Background>().LifestyleSingleton()); Container.Register(Component.For <WallFactory>().ImplementedBy <WallFactory>().LifestyleSingleton()); Container.Register(Component.For <Hud.Hud>().ImplementedBy <Hud.Hud>()); Container.Register(Component.For <BasicGameMode>().ImplementedBy <BasicGameMode>()); Container.Register(Component.For <PickupFactory>().ImplementedBy <PickupFactory>()); Container.Register(Component.For <PlayerFactory>().ImplementedBy <PlayerFactory>().LifestyleSingleton()); float xpix = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; float ypix = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; viewport = new Vector2(Window.ClientBounds.Width, Window.ClientBounds.Height); var crateTexture = Content.Load <Texture2D>("sprites/ships/ship1small"); Player = Container.Resolve <PlayerFactory>().CreatePlayer(crateTexture); Container.Register(Component.For <Player>().Instance(Player).LifestyleSingleton()); //load up aliens using (var stream = new FileStream("./AlienDefinitions.json", FileMode.Open)) { Container.Resolve <AlienFactory>().Load(stream); } //load up weapons using (var stream = new FileStream("./Weapons/WeaponDefinitions.json", FileMode.Open)) { Container.Resolve <WeaponFactory>().Load(stream); } //load up pickups using (var stream = new FileStream("./Pickups/PickupDefinitions.json", FileMode.Open)) { Container.Resolve <PickupFactory>().Load(stream); } //load up fonts using (var stream = new FileStream("./Fonts/FontDefinitions.json", FileMode.Open)) { Container.Resolve <FontFactory>().Load(stream); } //load up animations using (var stream = new FileStream("./Animations/AnimationDefinitions.json", FileMode.Open)) { Container.Resolve <AnimationFactory>().Load(stream); } //load up menus using (var stream = new FileStream("./Menu/MenuDefinitions.json", FileMode.Open)) { Container.Resolve <MenuFactory>().Load(stream); CurrentMenu = Container.Resolve <MenuFactory>().Get("root"); } //load up the HUD using (var stream = new FileStream("./Hud/HudDefinition.json", FileMode.Open)) { var hud = Container.Resolve <Hud.Hud>(); hud.Load(stream); hud.OnWindowResized(viewport); } base.Initialize(); }