public Movement(Player p, Country o, Country d, Type t) { owner = p; origin = o; dest = d; myType = t; o.isActive = true; }
public HUD2(Player player,SpriteFont font,Texture2D tex,SpriteBatch spriteBatch) { this.player = player; this.heart = tex; this.font = font; this.spriteBatch = spriteBatch; //IsPopup = true; //this.ScreenState = ScreenState.TransitionOff; }
// Constructors public ClickableObject(ContentManager content, String text, String glowText, Vector2 pos, Player player, String buttonName, int buttonType) { leftState = objState.NORMAL; texture = content.Load<Texture2D>(text); glowTexture = content.Load<Texture2D>(glowText); this.position = pos; this.player = player; this.buttonName = buttonName; rectangle = new Rectangle((int)pos.X, (int)pos.Y, texture.Width, texture.Height); }
/// <summary> /// Constructor. /// </summary> public HUD(Player player) { TransitionOnTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); this.player = player; //IsPopup = true; this.ScreenState = ScreenState.TransitionOff; }
public Camera(Player player) { this.player = player; }
/// <summary> /// Updates the state of the game. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (IsActive) { if (curGameState == GameState.Placement) { if (curPlayer.GetType() == typeof(AI)) { ((AI)curPlayer).place(); int newIdx = (players.IndexOf(curPlayer) + 1) % players.Count; curPlayer = players[newIdx]; if (--toPlace <= 0) { curGameState = GameState.Countdown; countdownTime = COUNTDOWN_LENGTH; } pruneMovements(); } } else if (curGameState == GameState.Countdown) { countdownTime -= gameTime.ElapsedGameTime.TotalSeconds; if (countdownTime <= 0) curGameState = GameState.Playing; } else if (curGameState == GameState.Playing) { totalGameTime += gameTime.ElapsedGameTime.TotalSeconds; // perform all active movements at their correct times if (movements.Count > 0) { Movement m = movements[0]; if (m.lastRan + Movement.frequency <= totalGameTime) { movements.RemoveAt(0); if (m.origin.hasStrength()) { bool repeat = m.perform(totalGameTime); if (repeat) movements.Add(m); else m.origin.isActive = false; } else { m.origin.isActive = false; } pruneMovements(); } } // deploy new guys to contries every deployFreq double deployProgress = totalGameTime - lastDeployment; progressBar.value = (float)deployProgress; progressBar.Update(gameTime); if (deployProgress >= deployFreq) { lastDeployment = totalGameTime; foreach (KeyValuePair<string, Country> c in territories) { c.Value.addStrength(1); } if (OptionsMenuScreen.currentMap == OptionsMenuScreen.Map.World) { foreach (Continent cont in continents) { if (cont.owner != noone) cont.owner.captures += cont.value; } foreach (Player p in players) { p.captures++; } } } double aiProgress = totalGameTime - lastAI; if (aiProgress >= aiFreq) { lastAI = totalGameTime; foreach (Player p in players) { if (p.GetType() == typeof(AI)) { ((AI)p).update(); } } } // if someone was just invincible, we might have to switch up our music if (invMusicEnd < totalGameTime && invMusicEnd + gameTime.ElapsedGameTime.TotalSeconds > totalGameTime) { MediaPlayer.Play(bgMusic); } } } }
public void transfer(Player p) { int excess=0; List<Country> frontLines = new List<Country>(); foreach (KeyValuePair<string, Country> c in territories) { if (c.Value.getOwner() == p) { if (isFrontLines(c.Value)) { frontLines.Add(c.Value); } else { excess += c.Value.getStrength() - 1; c.Value.setStrength(1); } } } int perEach = excess / frontLines.Count; excess -= perEach * frontLines.Count; foreach (Country c in frontLines) { c.addStrength(perEach); if (excess-- > 0) c.addStrength(1); } }
private void SpawnUnit(string name, Player player, Vector3 offsetV) { BattleUnit unit = _simulation.Spawn(name); unit.Simulation = _simulation; unit.Player = player; unit.Avatar.Position = player.InitialPosition + offsetV; _simulation.Add(unit); }
public double getInvDuration(Player p) { double factor = 1.0; if(OptionsMenuScreen.currentMap == OptionsMenuScreen.Map.World) { foreach(Continent cont in continents){ if (cont.owner == p) factor -= cont.value / 10f; } } factor = Math.Max(factor, 0.3); return baseInvDuration * factor; }
public void defect(Player p, Country c) { c.setOwner(p); c.changedHands = true; pruneMovements(); }
public void CreateMap() { screenWidth = GameStateManagementGame.width; screenHeight = GameStateManagementGame.height; noone = new Player(this, PlayerIndex.One, GRAY, new Vector2(0, 0)); if (PlayersMenuScreen.player1 == PlayersMenuScreen.PlayerType.Human) players.Add(new Player(this, PlayerIndex.One, BLUE, new Vector2(50, 10))); else if (PlayersMenuScreen.player1 == PlayersMenuScreen.PlayerType.AI) players.Add(new AI(this, PlayerIndex.One, BLUE, new Vector2(50, 10))); if (PlayersMenuScreen.player2 == PlayersMenuScreen.PlayerType.Human) players.Add(new Player(this, PlayerIndex.Two, YELLOW, new Vector2(930, 10))); else if (PlayersMenuScreen.player2 == PlayersMenuScreen.PlayerType.AI) players.Add(new AI(this, PlayerIndex.Two, YELLOW, new Vector2(930, 10))); if (PlayersMenuScreen.player3 == PlayersMenuScreen.PlayerType.Human) players.Add(new Player(this, PlayerIndex.Three, GREEN, new Vector2(50, 652))); if (PlayersMenuScreen.player3 == PlayersMenuScreen.PlayerType.AI) players.Add(new AI(this, PlayerIndex.Three, GREEN, new Vector2(50, 652))); if (PlayersMenuScreen.player4 == PlayersMenuScreen.PlayerType.Human) players.Add(new Player(this, PlayerIndex.Four, ORANGE, new Vector2(930, 652))); if (PlayersMenuScreen.player4 == PlayersMenuScreen.PlayerType.AI) players.Add(new AI(this, PlayerIndex.Four, ORANGE, new Vector2(930, 652))); curPlayer = players[random.Next(players.Count)]; progressBar = new UI.ProgressBar(ScreenManager.Game, new Rectangle((screenWidth - 300)/2, 50, 300, 16)); progressBar.maximum = (float)deployFreq; progressBar.fillColor = Color.White; progressBar.backgroundColor = Color.Black; if (OptionsMenuScreen.currentMap != OptionsMenuScreen.Map.World) { CreateGrid(); } else { CreateWorld(); } // we have to initialze the hover territory Dictionary<string, Country>.Enumerator e = territories.GetEnumerator(); e.MoveNext(); foreach (Player p in players) { p.hover = e.Current.Value; } //foreach (KeyValuePair<string, Country> c in territories) //{ // Player owner = c.Value.getOwner(); // bool frontLines = false; // foreach (Country n in c.Value) // { // if (n.getOwner() != owner) // frontLines = true; // } // if (frontLines) // c.Value.setStrength(4); //} if (OptionsMenuScreen.currentPlacement == OptionsMenuScreen.Placement.Random) AssignRandomly(); else AssignManually(); pruneMovements(); }
private bool HandlePlacementInputButtons(InputState input, Player cP) { PlayerIndex output; if (cP == curPlayer && cP.hover.getOwner() == noone && input.IsSelect(cP.PI, out output)) { cP.hover.setOwner(cP); int newIdx = (players.IndexOf(curPlayer) + 1)%players.Count; curPlayer = players[newIdx]; if (--toPlace <= 0) { curGameState = GameState.Countdown; countdownTime = COUNTDOWN_LENGTH; } //Console.Out.WriteLine(toPlace); pruneMovements(); selectCountry.Play(); } else { return false; } return true; }
private bool HandleGameplayInputButtons(InputState input, Player cP) { PlayerIndex output; if (input.IsSelect(cP.PI, out output)) { if (cP.selected == false && cP.hover.getOwner() == cP && cP.hover.canAddMove()) { cP.selected = true; cP.origin = cP.hover; } else if (cP.selected == true) { cP.selected = false; if (cP.target == Player.Tgt.Self && cP.hover != cP.origin && cP.origin.canAddMove()) { //cP.origin.transfer(cP.dest); cP.dest = cP.hover; movements.Add(new Movement(cP, cP.origin, cP.dest, Movement.Type.Transfer)); } if (cP.target == Player.Tgt.Enemy && cP.origin.canAddMove()) { //cP.origin.attack(cP.dest); cP.dest = cP.hover; movements.Add(new Movement(cP, cP.origin, cP.dest, Movement.Type.Attack)); } } } else if (input.IsMenuCancel(cP.PI, out output)) { if (cP.selected == true) { cP.selected = false; } else { cP.hover.cancelOutgoing = true; pruneMovements(); } } else if (input.IsScrollLeft(cP.PI)) { cP.decPower(); } else if (input.IsScrollRight(cP.PI)) { cP.incPower(); } else if (input.IsUsePower(cP.PI)) { if (cP.usePower()) { if (cP.curPower == Player.Power.Transfer) transfer(cP); else if (cP.curPower == Player.Power.Reinforce) reinforce(cP); else if (cP.curPower == Player.Power.Invincible) invincible(cP); else if (cP.curPower == Player.Power.Defect) defect(cP, cP.hover); } } else { return false; } return true; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); wallSprite = Content.Load<Texture2D>("box"); pixel = Content.Load<Texture2D>("blankPixel"); background = Content.Load<Texture2D>("floor"); mouseSprite = Content.Load<Texture2D>("crosshair"); enemySprite = Content.Load<Texture2D>("Enemy/standing"); playerSprite = Content.Load<Texture2D>("Player/standing"); map = new Map("F:/XNA/Sos2/trunk/SoS/Content/map.txt", graphics, wallSprite); List<Obstacle> walls = new List<Obstacle>(); //walls.Add(new Wall(wallSprite, 10, 10, 2, 5)); //walls.Add(new Wall(wallSprite, 100, 300, 10, 1)); //walls.Add(new Wall(wallSprite, 1000, 100, 3, 3)); //walls.Add(new Wall(wallSprite, 100, 700, 1, 1)); map.loadObstacles(walls); player = new Player(playerSprite, new Rectangle(100,100,playerSprite.Width/2,playerSprite.Height/2),Color.White, this); beings.Add(new Being(100, 10, enemySprite)); beings.Add(new BoxBeing(950, 60, enemySprite, 200)); beings.Add(player); //Movement //0=standing; 1=walking; 2=shooting; 3=dead playerMovement.Add(new List<Texture2D> {Content.Load<Texture2D>("Player/standing")}); playerMovement.Add(new List<Texture2D> {Content.Load<Texture2D>("Player/frame 2_walking"), Content.Load<Texture2D>("Player/frame 1 and 3_walking"), Content.Load<Texture2D>("Player/frame 4_walking")}); playerMovement.Add(new List<Texture2D> {Content.Load<Texture2D>("Player/aiming"), Content.Load<Texture2D>("Player/frame 2_firing"), Content.Load<Texture2D>("Player/firing gunfire 1"), Content.Load<Texture2D>("Player/firing gunfire 2"), Content.Load<Texture2D>("Player/frame 2_firing"), Content.Load<Texture2D>("Player/frame 1 and 3_firing"), Content.Load<Texture2D>("Player/aiming")}); playerMovement.Add(new List<Texture2D> {Content.Load<Texture2D>("Player/dead")}); player.loadMovementList(playerMovement); //Menu Stuff spriteBatch = new SpriteBatch(GraphicsDevice); BG = Content.Load<Texture2D>("bg"); font = Content.Load<SpriteFont>("TimesNewRoman"); menuItems = new String[4] { "play", "options", "intro", "exit" }; optionsMenuItems = new String[2] { "controls", "back" }; // TODO: use this.Content to load your game content here }
void GameStart() { //myPic = Texture2D.FromStream(ScreenManager.GraphicsDevice, MainMenuScreen.myProfile.GetGamerPicture()); // Set the position of the camera in world space, for our view matrix. cameraPosition = new Vector3(0.0f, 0.0f, 5000.0f); graphicsDevice = ScreenManager.GraphicsDevice; thisViewport = graphicsDevice.Viewport; a1 = new Asteroids(thisViewport, asteroidsModel, cameraPosition); a2 = new Asteroids(thisViewport, asteroidsModel, cameraPosition); a3 = new Asteroids(thisViewport, asteroidsModel, cameraPosition); FirstPlayer = new Player(thisViewport, Player1Texture, new Vector2(thisViewport.Width / 2, thisViewport.Height / 2), BulletTexture, PlayerIndex.One); EntityManager.Add(FirstPlayer); PlayerStatus.Reset(); ParticleManager = new ParticleManager<ParticleState>(1024 * 20, ParticleState.UpdateParticle); Pixel = new Texture2D(ScreenManager.GraphicsDevice, 1, 1); Pixel.SetData(new[] { Color.White }); Vector2 gridSpacing = new Vector2((float)Math.Sqrt(thisViewport.Width * thisViewport.Height / 1600)); GridManager = new Grid(thisViewport.Bounds, gridSpacing); enemySpawner = new EnemySpawner(thisViewport); }
public void invincible(Player p) { double invDuration = getInvDuration(p); p.becomeInvincible(invDuration); invMusicEnd = Math.Max(invMusicEnd, totalGameTime + invDuration); MediaPlayer.Play(invincibleMusic); }
public ClickableButton(ContentManager content, String texture, String glowTexture, Vector2 position, Player player, string buttonName, int buttonType) : base(content, texture, glowTexture, position, player, buttonName, buttonType) { this.buttonName = buttonName; this.buttonType = buttonType; }
public void reinforce(Player p) { foreach (KeyValuePair<string, Country> c in territories) { if (c.Value.getOwner() == p) c.Value.addStrength(1); } }
public void init() { this.player = new Player(); this.camera = new Camera(player); this.level = new Level(0,camera,model,model2,model_zombie); player.setLevel(level); level.SetUpBoundingBoxes(); hud2 = new HUD2(player, gameFont, heart,ScreenManager.SpriteBatch); }
protected void InitializeScene() { _simulation = new Simulation(); LoadUnits(); var layer = new Layer(-1.25f); layer.Drawables.Add(_simulation); _scene.Layers.Add(layer); // TODO: remove hardcoded paths //string[] files = System.IO.Directory.GetFiles("Content/Maps", "*.lua"); var lua = LuaMachine.Instance; object[] luaResult = lua.DoFile("Content/Maps/" + _map); var tbl = (LuaTable) luaResult[0]; foreach ( var asset in tbl.Values.Cast<LuaTable>().Select(el => LuaMachine.LoadAsset(el, _content))) { _scene.Unlayered.Add(asset); } //var ships = (LuaTable)luaResult["statki"]; var ships = (LuaTable) lua["statki"]; Sprite3D ship1 = LuaMachine.LoadAsset((LuaTable) ships["ship1"], _content); _scene.Unlayered.Add(ship1); Sprite3D ship2 = LuaMachine.LoadAsset((LuaTable) ships["ship2"], _content); _scene.Unlayered.Add(ship2); var initialPositionY = (float) (double) lua["initialY"]; _simulation.GroundLevel = initialPositionY + 0.5f; _player1 = new Player("p1") { InitialPosition = new Vector3(ship1.Position.X, initialPositionY, ship1.Position.Z - 0.05f), Direction = 1.0f, Ship = new Ship(ship1.Position) }; _player2 = new Player("p2") { InitialPosition = new Vector3(ship2.Position.X, initialPositionY, ship2.Position.Z - 0.05f), Direction = -1.0f, Ship = new Ship(ship2.Position) }; _simulation.PlayerOne = _player1; _simulation.PlayerTwo = _player2; _scene.SimpleLights.InsertRange(0, _lights); _cameraManager.Camera.Position = new Vector3(ship1.Position.X, _camera.Position.Y, _camera.Position.Z); _cameraManager.Goto(new Vector3(ship2.Position.X, _camera.Position.Y, _camera.Position.Z)); }