public void Setup(GraphicsDevice graphics, BasicCamera2D camera, PUIMenu menu) { Camera = camera; Graphics = graphics; Menu = menu; SelectedShips = new List <Ship>(); SelectedShipTypes = new Dictionary <ShipType, List <Ship> >(); SelectHomeShip(); DragSelectTexture = new RenderTarget2D(graphics, graphics.PresentationParameters.BackBufferWidth, graphics.PresentationParameters.BackBufferHeight); graphics.SetRenderTarget((RenderTarget2D)DragSelectTexture); graphics.Clear(new Color(120, 120, 120, 120)); graphics.SetRenderTarget(null); }
public override void Load(ContentManager Content, GraphicsDevice graphics) { _menu.Load(graphics, "GameplayMenuDefinition", "UITemplates"); Camera = new BasicCamera2D( new Rectangle(0, 0, graphics.PresentationParameters.BackBufferWidth, graphics.PresentationParameters.BackBufferHeight), new Rectangle(0, 0, WorldManager.WorldWidth, WorldManager.WorldHeight)); _currentZLevel = _zLevels.IndexOf(2.0f); Camera.Z = _zLevels[_currentZLevel]; UnitManager = new UnitManager(); WorldManager = new WorldManager(); UnitManager.Setup(graphics, Camera, _menu); WorldManager.Setup(graphics, Camera, UnitManager); WorldManager.PlayerEntity.UnitManager = UnitManager; Camera.CenterPosition(WorldManager.PlayerEntity.Position); }
public void Setup(GraphicsDevice graphics, BasicCamera2D camera, UnitManager unitManager) { UnitManager = unitManager; UnitManager.WorldManager = this; Graphics = graphics; Camera = camera; ScreenCenter = new Vector2(graphics.PresentationParameters.BackBufferWidth / 2, graphics.PresentationParameters.BackBufferHeight / 2); // todo - set world seed WorldData.RNG = new Random(); var bg = 1;// WorldData.RNG.Next(1, 9); var planet = ModManager.Instance.AssetManager.LoadTexture2D(graphics, "Planet" + WorldData.RNG.Next(1, 11).ToString(), true); var background = ModManager.Instance.AssetManager.LoadTexture2D(graphics, "Background" + bg.ToString(), true); Background = new RenderTarget2D(graphics, background.Width, background.Height); graphics.SetRenderTarget((RenderTarget2D)Background); graphics.Clear(Color.Transparent); using (SpriteBatch spriteBatch = new SpriteBatch(graphics)) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); spriteBatch.Draw(background, Vector2.Zero, Color.White); // todo : fix bg not lining up at right edge spriteBatch.Draw(planet, new Vector2() { X = background.Width / 2 - planet.Width / 2, Y = background.Height / 2 - planet.Height / 2 }, Color.White); spriteBatch.End(); } graphics.SetRenderTarget(null); Asteroids = new ObjectPool <Asteroid>(10000); // random asteroid field generation for (var x = AsteroidRegionWidth; x < (WorldWidth - AsteroidRegionWidth); x += AsteroidRegionWidth) { for (var y = AsteroidRegionHeight; y < (WorldHeight - AsteroidRegionHeight); y += AsteroidRegionHeight) { if (WorldData.RNG.Next(0, 10) < 2 && Asteroids.LastActiveIndex < (Asteroids.Size - 1)) { var newAsteroid = Asteroids.New(); newAsteroid.Sprite = TexturePacker.GetSprite("AsteroidsAtlas", "Asteroid" + WorldData.RNG.Next(1, WorldData.AsteroidTypes + 1).ToString()); newAsteroid.Position = new Vector2(x + WorldData.RNG.Next(0, 150), y + WorldData.RNG.Next(0, 150)); newAsteroid.Origin = new Vector2(newAsteroid.Sprite.SourceRect.Width / 2, newAsteroid.Sprite.SourceRect.Height / 2); newAsteroid.RotationSpeed = (float)PandaUtil.RandomDouble(WorldData.RNG, 0, 8); newAsteroid.Rotation = WorldData.RNG.Next(0, 360); if (WorldData.RNG.Next(0, 10) < 3) { newAsteroid.ResourceType = WorldData.ResourceTypes[WorldData.RNG.Next(0, WorldData.ResourceTypes.Count)]; newAsteroid.ResourceCount = WorldData.RNG.Next(50000, 100000); } } } } PlayerEntity = new Player(); PlayerEntity.Position = PlayerStartPosition; PlayerShips.Add(PlayerEntity); for (var i = 0; i < StartingMiners; i++) { UnitManager.SpawnShip(ShipType.Miner, PlayerEntity.Position + new Vector2(WorldData.RNG.Next(-200, 200), WorldData.RNG.Next(-200, 200)), PlayerEntity); } UnitManager.SpawnShip(ShipType.Fighter, new Vector2(4000, 4000), null); }
/// <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() { Graphics.PreferredBackBufferWidth = Constants.InternalResolutionWidth; Graphics.PreferredBackBufferHeight = Constants.InternalResolutionHeight; Graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false; Graphics.ApplyChanges(); //Components.Add(new FrameRateCounter(this, "Content\\Fonts\\fpsfont", 1f)); Components.Add(new GameObjectInfoDisplay(this, 0.5f, "Content\\Fonts\\debugfont", new Vector2(0f, 25f))); var componentFactory = new ComponentFactory(); var gameObjectFactory = new GameObjectFactory(this.Content); gameObjectFactory.PathToXML = "EntityDefinitions\\entity.xml"; var inputHandler = new InputHandler(false); var playerManager = new PlayerManager(); var collisionManager = new CollisionManager(new RectangleF(0f, 0f, Constants.InternalResolutionWidth, Constants.InternalResolutionHeight)); particleManager = new ParticleManager(Content, "ParticleEffects\\", "Textures\\"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); renderer = new Renderer(Graphics, spriteBatch); renderer.SpriteSortMode = SpriteSortMode.FrontToBack; renderer.SetInternalResolution(Constants.InternalResolutionWidth, Constants.InternalResolutionHeight); renderer.SetScreenResolution(1920, 1080, false); cameraService = new CameraManager(); var camera = new BasicCamera2D(GraphicsDevice, "main"); cameraService.AddCamera(camera); GameServiceManager.AddService(typeof(IGameObjectFactory), gameObjectFactory); GameServiceManager.AddService(typeof(IComponentFactory), componentFactory); GameServiceManager.AddService(typeof(RenderableFactory), new RenderableFactory(Content)); GameServiceManager.AddService(typeof(IInputHandler), inputHandler); GameServiceManager.AddService(typeof(PlayerManager), playerManager); GameServiceManager.AddService(typeof(IGameObjectManager), new GameObjectManager()); GameServiceManager.AddService(typeof(ICollisionManager), collisionManager); GameServiceManager.AddService(typeof(IBehaviorFactory), new BehaviorFactory()); GameServiceManager.AddService(typeof(IActionFactory), new ActionFactory()); GameServiceManager.AddService(typeof(IRandomGenerator), new RandomGenerator()); GameServiceManager.AddService(typeof(IParticleManager), particleManager); GameServiceManager.AddService(typeof(IProjectileManager), new ProjectileManager()); GameServiceManager.AddService(typeof(IActionManager), new ActionManager()); GameServiceManager.AddService(typeof(ILayerManager), new LayerManager("layers.xml", Content)); GameServiceManager.AddService(typeof(IRenderer), renderer); GameServiceManager.AddService(typeof(ICameraService), cameraService); GameServiceManager.AddService(typeof(ILevelLogicManager), new LevelLogicManager()); //Initialize the GameServices);); foreach (var service in GameServiceManager.Services) { service.Initialize(); } base.Initialize(); }
public override void Load(ContentManager Content, GraphicsDevice graphics) { GameWon = false; GameOver = false; Graphics = graphics; UpgradeManager = new UpgradeManager(); Menu = new PUIMenu(); Menu.AddMethod(BuildMiner); Menu.AddMethod(BuildFighter); Menu.AddMethod(BuildBomber); Menu.AddMethod(BuildRepairShip); Menu.AddMethod(BuildMissileFrigate); Menu.AddMethod(BuildBeamFrigate); Menu.AddMethod(BuildSupportCruiser); Menu.AddMethod(BuildHeavyCruiser); Menu.AddMethod(BuildBattleship); Menu.AddMethod(BuildCarrier); Menu.AddMethod(IdleMiners); Menu.AddMethod(Upgrades); Menu.AddMethod(Help); Menu.AddMethod(ExitToMenu); Menu.AddMethod(Build); Menu.AddMethod(UpgradeManager.UpgradeMinerCap1); Menu.AddMethod(UpgradeManager.UpgradeMinerCap2); Menu.AddMethod(UpgradeManager.UpgradeMiningRate1); Menu.AddMethod(UpgradeManager.UpgradeMiningRate2); Menu.AddMethod(UpgradeManager.UpgradeRepairRate); Menu.AddMethod(UpgradeManager.UpgradeShieldRegen1); Menu.AddMethod(UpgradeManager.UpgradeShieldRegen2); Menu.AddMethod(UpgradeManager.UpgradeWarmachine1); Menu.AddMethod(UpgradeManager.UpgradeWarmachine2); Menu.AddMethod(UpgradeManager.UpgradeHyperdrive); Menu.Load(graphics, "GameplayMenuDefinition", "UITemplates"); MinimapFrame = Menu.GetFrame("frmMinimap"); GameOver = false; Config.Load(); EntityData.Load(); WorldData.Load(); if (Config.HelpSeen) { var helpFrame = Menu.GetFrame("frmHelp"); helpFrame.Visible = false; helpFrame.Active = false; } Config.HelpSeen = true; SettingsManager.Instance.UpdateSetting("general", "helpseen", "true"); _lblProductionQueue = Menu.GetWidget <PUIWLabel>("lblProductionQueue"); _lblMetal = Menu.GetWidget <PUIWLabel>("lblMetal"); _lblGas = Menu.GetWidget <PUIWLabel>("lblGas"); _lblWater = Menu.GetWidget <PUIWLabel>("lblWater"); _lblCrystal = Menu.GetWidget <PUIWLabel>("lblCrystal"); _lblUranium = Menu.GetWidget <PUIWLabel>("lblUranium"); _lblUpgradesTitle = Menu.GetWidget <PUIWLabel>("lblUpgradesTitle"); _btnIdleMiners = Menu.GetWidget <PUIWBasicButton>("btnIdleMiners"); _btnUpgrades = Menu.GetWidget <PUIWBasicButton>("btnUpgrades"); ShipsKilled = new Dictionary <ShipType, int>(); ShipsLost = new Dictionary <ShipType, int>(); foreach (var kvp in EntityData.ShipTypes) { ShipsKilled.Add(kvp.Key, 0); ShipsLost.Add(kvp.Key, 0); } // create build menu tooltips foreach (var kvp in EntityData.ShipTypes) { if (!kvp.Value.CanBuild) { continue; } var button = Menu.GetWidget <PUIWBasicButton>("btnBuild" + kvp.Value.ShipType.ToString()); _sbGeneral.Clear(); _sbGeneral.Append("\n\n").Append(kvp.Value.Description.Replace("\\n", "\n")); foreach (var kvpBuild in kvp.Value.BuildCost) { var sprite = TexturePacker.GetSprite("ResourcesAtlas", kvpBuild.Key.ToString()); _sbGeneral .Append("[") .Append("ResourcesTexture-") .Append(sprite.SourceRect.X).Append(",") .Append(sprite.SourceRect.Y).Append(",") .Append(sprite.SourceRect.Width).Append(",") .Append(sprite.SourceRect.Height) .Append("] ") .Append(kvpBuild.Value) .Append(" "); } _sbGeneral.Remove(_sbGeneral.Length - 2, 2); button.SetTooltip(_sbGeneral.ToString(), _sbGeneral.ToString(), true); } _sbGeneral.Clear(); Camera = new BasicCamera2D( new Rectangle(0, 0, graphics.PresentationParameters.BackBufferWidth, graphics.PresentationParameters.BackBufferHeight), new Rectangle(0, 0, Config.WorldWidth, Config.WorldHeight)); _currentZoomLevel = _zoomLevels.IndexOf(0.5f); Camera.Zoom = _zoomLevels[_currentZoomLevel]; EffectsManager = new EffectsManager(); UnitManager = new UnitManager(); WorldManager = new WorldManager(); ProjectileManager = new ProjectileManager(); EnemyWaveManager = new EnemyWaveManager(); UpgradeManager.Load(); UnitManager.Setup(graphics, Menu); WorldManager.Setup(graphics); EnemyWaveManager.Start(); Camera.CenterPosition(WorldManager.PlayerEntity.Position); MinerResourceCounts = new Dictionary <ResourceType, int>(); foreach (var type in WorldData.ResourceTypes) { MinerResourceCounts.Add(type, 0); } } // Load