public Gun(World world, Vector2 position, Player player) { ObjectType = EObjectType.Gun; mPosition = position; mWorld = world; mPlayer = player; CurrentMagazine = new List<int>(); Vector2 size = new Vector2(10, 8); mBaseBox = new Box(world, position, size, "gun", true, player); size = new Vector2(10, 2); mBarrelBox = new Box(world, position, size, "barrel", true, player); Filter filter = new Filter(); filter.maskBits = 0; Fixture fixture = mBarrelBox.mBody.GetFixtureList(); fixture.SetFilterData(ref filter); fixture = mBaseBox.mBody.GetFixtureList(); fixture.SetFilterData(ref filter); mIsActive = false; mFilter = new Filter(); if (mPlayer.PlayerType == EntityCategory.Player2) mFilter.maskBits = (ushort)(EntityCategory.Player1); else mFilter.maskBits = (ushort)(EntityCategory.Player2); mFilter.categoryBits = (ushort)mPlayer.PlayerType; }
public Gameplay(Camera camera, UIManager uiManager) { mCamera = camera; mUIManager = uiManager; Player1 = new Player(EntityCategory.Player1, "Player1"); Player2 = new Player(EntityCategory.Player2, "Player2"); mActivePlayer = Player1; mUIManager.SetActivePlayer(mActivePlayer); mSwitchPlayer = false; mUIManager.GunChanged += mUIManager_GunChanged; }
public Box(World world, Vector2 position, Vector2 size, string texture, bool isStatic, Player player, float health = 100) { ObjectType = EObjectType.Box; mHealth = health; mStartHealth = health; mIsDestroyed = false; mSize = size; mWorld = world; mTexture = texture; mPlayer = player; DestroyTime = null; PolygonShape polygonShape = new PolygonShape(); polygonShape.SetAsBox(size.X / 2f, size.Y / 2f); BodyDef bodyDef = new BodyDef(); bodyDef.position = position; bodyDef.bullet = true; if (isStatic) { bodyDef.type = BodyType.Static; } else { bodyDef.type = BodyType.Dynamic; } mBody = world.CreateBody(bodyDef); FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = polygonShape;//Форма fixtureDef.density = 0.1f;//Плотность fixtureDef.friction = 0.3f;//Сила трения fixtureDef.restitution = 0f;//Отскок Filter filter = new Filter(); filter.maskBits = (ushort)(EntityCategory.Player1 | EntityCategory.Player2); filter.categoryBits = (ushort)player.PlayerType; var fixture = mBody.CreateFixture(fixtureDef); fixture.SetFilterData(ref filter); MassData data = new MassData(); data.mass = 0.01f; mBody.SetUserData(this); }
public Bullet(World world, Vector2 position, float maxDamageValue, Player player,int bulletType) { mPlayer = player; ObjectType = EObjectType.Bullet; switch (bulletType) { case 1: mDamageRadius = 10; break; case 2: mDamageRadius = 20; break; } mMaxDamageValue = maxDamageValue; Vector2 size = new Vector2(5, 5); mBox = new Box(world, position, size, "bullet", true, player); MassData massData = new MassData(); massData.mass = 1000; mBox.mBody.SetMassData(ref massData); mIsActive = false; mIsDestoyed = false; Body.SetUserData(this); }
public static List<Box> Destroy(Box box, World world, float explosionDistance, Player player) { List<Box> boxes = new List<Box>(); Vector2 pos = box.mBody.GetPosition(); Vector2 size = box.mSize; Vector2 partBoxSize = size / 2; if (size.X < 1f || size.Y < 1) { return boxes; } Vector2 force = new Vector2(1.1f / explosionDistance); Vector2 partBoxPos = pos - partBoxSize / 2; Box partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = pos + partBoxSize / 2; partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = new Vector2(pos.X + partBoxSize.X / 2, pos.Y - partBoxSize.Y / 2); partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); partBoxPos = new Vector2(pos.X - partBoxSize.X / 2, pos.Y + partBoxSize.Y / 2); partBox = new Box(world, partBoxPos, partBoxSize, box.Texture, false, player); partBox.mBody.ApplyLinearImpulse(force * partBox.mBody.GetMass(), Vector2.Zero); boxes.Add(partBox); return boxes; }
public void SetCurrentPlayer(Player player) { mPlayer = player; }
public void SetActivePlayer(Player player) { mPlayer = player; mPlayerName = "Игрок: " + mPlayer.Name; mBuilder.SetCurrentPlayer(player); mBuildModeActive = true; for (int i = 0; i < mControls.Count; i++) { mControls[i].Visible = true; } for (int i = 0; i < TAB_COUNT; i++) { for (int j = 0; j < mButtonsPerTab[i].Count; j++) { mButtonsPerTab[i][j].Visible = false; } } SetTabActive(0); if(player.Guns.Count>0) mActiveGun = player.Guns[0]; }
public void GameOver(Player player) { mBuilder.Deactivate(); string congrats = "Игра окончена\n" + player.Name + "ПОБЕДИЛ!"; Vector2 pos = new Vector2(200, 100); mSpriteBatch.DrawString(mFont, congrats, pos, Color.Red); }
public void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.Enter)) { if (!mSwitchPlayer) { mSwitchPlayer = true; DeactivatePlayerGuns(Player1); DeactivatePlayerGuns(Player2); if (mActivePlayer == Player1) { if (mSwitchPlayer) { mUIManager.SetActivePlayer(Player2); if (!mFirstTurns) { Player2.Resources.AddResourcesForTurn(); } SetCameraPosition(Player2.Guns[0]); mActivePlayer = Player2; } } else if (mActivePlayer == Player2) { if (mSwitchPlayer) { mFirstTurns = false; mUIManager.SetActivePlayer(Player1); if (!mFirstTurns) { Player1.Resources.AddResourcesForTurn(); } SetCameraPosition(Player1.Guns[0]); mActivePlayer = Player1; } } } } else { mSwitchPlayer = false; } }
public void StartGame() { mActivePlayer = Player1; mUIManager.SetActivePlayer(Player1); }
private void DeactivatePlayerGuns(Player player) { for (int i = 0; i < player.Guns.Count; i++) { player.Guns[i].IsActive = false; } }
protected override void Initialize() { mGameObjectCollection = new GameObjectCollection(); spriteBatch = new SpriteBatch(GraphicsDevice); mImmortalBoxes = new List<Box>(); mBasicEffect = new BasicEffect(graphics.GraphicsDevice); mBasicEffect.VertexColorEnabled = true; mCamera = new Camera(GraphicsDevice.Viewport, mBasicEffect); mPrimitiveRender = new PrimitiveRender(graphics.GraphicsDevice, spriteBatch, Content, mCamera); Vector2 gravity = new Vector2(0, -10f); mWorld = new World(gravity, true); mContactListener = new ContactListener(); mWorld.ContactListener = mContactListener; mTerrain = new Terrain(mWorld); mBuilder = new Builder(mWorld, mCamera, mGameObjectCollection); mUiManager = new UIManager(spriteBatch, Content, mBuilder); mGameplay = new Gameplay.Gameplay(mCamera, mUiManager); mPlayer = mGameplay.Player1; Vector2 pos = new Vector2(0, 30); Vector2 size = new Vector2(2, 2); pos = new Vector2(-150, -7); Gun gunPlayer1 = new Gun(mWorld, pos, mPlayer); mGameObjectCollection.Guns.Add(gunPlayer1); mPlayer.Guns.Add(gunPlayer1); pos = new Vector2(140, -7); Gun gunPlayer2 = new Gun(mWorld, pos, mGameplay.Player2); mGameObjectCollection.Guns.Add(gunPlayer2); mGameplay.Player2.Guns.Add(gunPlayer2); List<Box> baseBoxes = PlayerBaseFactory.CreateBuilding(mWorld, mGameplay, EntityCategory.Player1); mGameObjectCollection.Boxes.AddRange(baseBoxes); baseBoxes = PlayerBaseFactory.CreateBuilding(mWorld, mGameplay, EntityCategory.Player2); mGameObjectCollection.Boxes.AddRange(baseBoxes); mGameplay.StartGame(); mBuilder.Activate(); base.Initialize(); }