public void Escape() { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Tankontroller.Instance().SM().Transition(null); } }
public void GenerateNextTexture() { IGame game = Tankontroller.Instance(); GraphicsDevice graphicsDevice = game.GDM().GraphicsDevice; mNextTexture = new RenderTarget2D(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight, false, graphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); // Set the render target graphicsDevice.SetRenderTarget(mNextTexture); graphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true }; // Draw the scene graphicsDevice.Clear(Color.CornflowerBlue); mSpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); mNextScene.Draw(0); mSpriteBatch.End(); // Drop the render target graphicsDevice.SetRenderTarget(null); }
public void RepositionAsLosers() { int offset = 0; int loserCount = mPlayers.Count; if (mWinner != -1) { loserCount -= 1; } for (int i = 0; i < mPlayers.Count; i++) { if (i != mWinner) { Tankontroller game = (Tankontroller)Tankontroller.Instance(); float textureHeightOverWidth = (float)254 / (float)540; int textureWidth = game.GDM().GraphicsDevice.Viewport.Width / 2; int textureHeight = (int)(textureWidth * textureHeightOverWidth); int centreX = offset; int centreY = game.GDM().GraphicsDevice.Viewport.Height / 2 + textureHeight / 2; textureWidth = textureWidth / mPlayers.Count; textureHeight = (int)(textureWidth * textureHeightOverWidth); Rectangle newRectangle = new Rectangle(centreX, centreY, textureWidth, textureHeight); mPlayers[i].GUI.Reposition(newRectangle); offset += textureWidth; } } }
public void Transition(IScene pNextScene, bool replaceCurrent = true) { IScene currentScene = Top; // gain access to the scene before the current scene if (pNextScene == null) { pNextScene = Previous; } if (replaceCurrent) { Pop(); } if (pNextScene != null) { IScene transitionScene = new TransitionScene(currentScene, pNextScene); mScenes.Add(transitionScene); } else { // we should exit the game here... Tankontroller game = (Tankontroller)Tankontroller.Instance(); game.Exit(); } }
private void IntroFinished() { if (introMusicInstance.State == SoundState.Stopped) { Tankontroller game = (Tankontroller)Tankontroller.Instance(); game.ReplaceCurrentMusicInstance("Music/Music_loopable", true); } }
public void Update(float pSeconds) { mSecondsLeft -= pSeconds; if (mSecondsLeft <= 0.0f) { IGame game = Tankontroller.Instance(); game.SM().Transition(null); } }
public void Draw(float pSeconds) { Tankontroller.Instance().GDM().GraphicsDevice.Clear(Color.Black); mSpriteBatch.Begin(); mSpriteBatch.Draw(mPreviousTexture, mRectangle, Color.White); mSpriteBatch.Draw(mNextTexture, mNextPosition, mRectangle, Color.White); mSpriteBatch.End(); }
private ParticleManager() { m_Texture = Tankontroller.Instance().CM().Load <Texture2D>("circle"); m_Rectangle = new Rectangle(); m_Particles = new Particle[1000]; for (int i = 0; i < m_Particles.Length; i++) { m_Particles[i] = new Particle(); } }
public void Draw(float pSeconds) { Tankontroller.Instance().GDM().GraphicsDevice.Clear(Color.Black); mSpriteBatch.Begin(); mSpriteBatch.Draw(mBackgroundTexture, mRectangle, Color.White); for (int i = 0; i < mPlayers.Count; i++) { mPlayers[i].GUI.DrawHealthBar(mSpriteBatch); } mSpriteBatch.End(); }
public void RepositionAsWinner() { Tankontroller game = (Tankontroller)Tankontroller.Instance(); float textureHeightOverWidth = (float)254 / (float)540; int textureWidth = game.GDM().GraphicsDevice.Viewport.Width / 2; int textureHeight = (int)(textureWidth * textureHeightOverWidth); int centreX = game.GDM().GraphicsDevice.Viewport.Width / 2 - textureWidth / 2; int centreY = textureHeight / 2;// game.GDM().GraphicsDevice.Viewport.Height / 2 - textureHeight / 2; Rectangle newRectangle = new Rectangle(centreX, centreY, textureWidth, textureHeight); mPlayers[mWinner].GUI.Reposition(newRectangle); }
public void Update(float pSeconds) { Escape(); IntroFinished(); mController0.UpdateController(); mController1.UpdateController(); bool tankMoved = false; foreach (Player p in m_Teams) { tankMoved = tankMoved | p.DoTankControls(pSeconds); } m_World.Update(pSeconds); m_World.CollideAllTheThingsWithPlayArea(mPlayAreaRectangle); if (tankMoved) { tankMoveSound.Play(); } else { tankMoveSound.Pause(); } List <int> remainingTeamsList = remainingTeams(); if (remainingTeamsList.Count <= 1) { int winner = -1; if (remainingTeamsList.Count == 1) { winner = remainingTeamsList[0]; } Reset(); Tankontroller.Instance().SM().Transition(new GameOverScene(mBackgroundTexture, m_Teams, winner)); } m_SecondsTillTracksAdded -= pSeconds; if (m_SecondsTillTracksAdded <= 0) { m_SecondsTillTracksAdded += SECONDS_BETWEEN_TRACKS_ADDED; TrackSystem trackSystem = TrackSystem.GetInstance(); foreach (Player p in m_Teams) { trackSystem.AddTrack(p.Tank.GetWorldPosition(), p.Tank.GetRotation(), p.Tank.Colour()); } } }
public void Draw(float pSeconds) { Tankontroller.Instance().GDM().GraphicsDevice.Clear(Color.Black); mSpriteBatch.Begin(); Color backColour = Color.White; mSpriteBatch.Draw(mBackgroundTexture, mBackgroundRectangle, backColour); mSpriteBatch.Draw(mForgroundTexture, mBackgroundRectangle, backColour); mSpriteBatch.Draw(mTitleTexture, mTitleRectangle, backColour); mButtonList.Draw(mSpriteBatch); mSpriteBatch.End(); }
public void Update(float pSeconds) { mSecondsLeft -= pSeconds; mVelocity += mAcceleration; mNextPosition += mVelocity; if (mNextPosition.Y > 0) { IGame game = Tankontroller.Instance(); game.SM().Pop(); if (mNextScene != game.SM().Top) { game.SM().Push(mNextScene); } } }
public FlashScreenScene() { IGame game = Tankontroller.Instance(); mLogoTexture = game.CM().Load <Texture2D>("selogo"); mSpriteBatch = new SpriteBatch(game.GDM().GraphicsDevice); int screenWidth = game.GDM().GraphicsDevice.Viewport.Width; int screenHeight = game.GDM().GraphicsDevice.Viewport.Height; int height = screenHeight / 2; int width = (int)(mLogoTexture.Width * (float)height / mLogoTexture.Height); int x = (screenWidth - width) / 2; int y = (screenHeight - height) / 2; mRectangle = new Rectangle(x, y, width, height); mSecondsLeft = DGS.Instance.GetInt("SECONDS_TO_DISPLAY_FLASH_SCREEN"); }
public TransitionScene(IScene pPreviousScene, IScene pNextScene) { IGame game = Tankontroller.Instance(); mPreviousScene = pPreviousScene; mNextScene = pNextScene; mSpriteBatch = new SpriteBatch(game.GDM().GraphicsDevice); mRectangle = new Rectangle(0, 0, DGS.Instance.GetInt("SCREENWIDTH"), DGS.Instance.GetInt("SCREENHEIGHT")); mSecondsLeft = DGS.Instance.GetInt("SECONDS_TO_DISPLAY_FLASH_SCREEN"); GeneratePreviousTexture(); GenerateNextTexture(); mPreviousPosition = new Vector2(0, 0); mVelocity = new Vector2(0, 0); mAcceleration = new Vector2(0, 1); mNextPosition = new Vector2(0, -DGS.Instance.GetInt("SCREENHEIGHT")); }
public Tank(float pXPosition, float pYPosition, float pRotation, Color pColour, List <Bullet> pBullets, float pScale) { m_Scale = pScale; m_Bullets = pBullets; mRotation = pRotation; mOldRotation = mRotation; int screenWidth = Tankontroller.Instance().GDM().GraphicsDevice.Viewport.Width; int screenHeight = Tankontroller.Instance().GDM().GraphicsDevice.Viewport.Height; mPosition = new Vector3(pXPosition, pYPosition, 0); mOldPosition = mPosition; mCannonRotation = pRotation; m_Health = 5; mFired = 0; mColour = pColour; ChargeDown = false; m_LeftTrackFrame = 1; m_RightTrackFrame = 1; }
public GameOverScene(Texture2D pBackgroundTexture, List <Player> pPlayers, int pWinner) { Tankontroller game = (Tankontroller)Tankontroller.Instance(); mBackgroundTexture = pBackgroundTexture; mSpriteBatch = new SpriteBatch(game.GDM().GraphicsDevice); int screenWidth = game.GDM().GraphicsDevice.Viewport.Width; int screenHeight = game.GDM().GraphicsDevice.Viewport.Height; int height = screenHeight / 2; int width = (int)(mBackgroundTexture.Width * (float)height / mBackgroundTexture.Height); int x = (screenWidth - width) / 2; int y = (screenHeight - height) / 2; mRectangle = new Rectangle(0, 0, screenWidth, screenHeight); mSecondsLeft = DGS.Instance.GetInt("SECONDS_TO_DISPLAY_GAMEOVER_SCREEN"); game.ReplaceCurrentMusicInstance("Music/Music_start", true); mPlayers = pPlayers; mWinner = pWinner; RepositionGUIs(); }
private void StartGame() { IGame game = Tankontroller.Instance(); game.SM().Transition(new GameScene(), false); }
// private Effect m_Shader; // private RenderTarget2D m_ShaderRenderTarget; // might not need this // private Texture2D m_ShaderTexture; // might not need this public GameScene() { Tankontroller game = (Tankontroller)Tankontroller.Instance(); m_TankBaseTexture = game.CM().Load <Texture2D>("Tank-B-05"); m_TankBrokenTexture = game.CM().Load <Texture2D>("BrokenTank"); m_TankRightTrackTexture = game.CM().Load <Texture2D>("Tank track B-R"); m_TankLeftTrackTexture = game.CM().Load <Texture2D>("Tank track B-L"); m_CannonTexture = game.CM().Load <Texture2D>("cannon"); m_CannonFireTexture = game.CM().Load <Texture2D>("cannonFire"); m_BulletTexture = game.CM().Load <Texture2D>("circle"); mPlayAreaTexture = game.CM().Load <Texture2D>("playArea"); mPixelTexture = game.CM().Load <Texture2D>("block"); TrackSystem.SetupStaticMembers(game.CM().Load <Texture2D>("track")); TeamGUI.SetupStaticTextures( game.CM().Load <Texture2D>("port1"), game.CM().Load <Texture2D>("port2"), game.CM().Load <Texture2D>("port3"), game.CM().Load <Texture2D>("port4"), game.CM().Load <Texture2D>("port5"), game.CM().Load <Texture2D>("port6"), game.CM().Load <Texture2D>("port7"), game.CM().Load <Texture2D>("port8")); JackIcon.SetupStaticTextures( game.CM().Load <Texture2D>("leftTrackForward"), game.CM().Load <Texture2D>("leftTrackBackwards"), game.CM().Load <Texture2D>("rightTrackForward"), game.CM().Load <Texture2D>("rightTrackBackwards"), game.CM().Load <Texture2D>("fire"), game.CM().Load <Texture2D>("charge"), game.CM().Load <Texture2D>("none"), game.CM().Load <Texture2D>("turretLeft"), game.CM().Load <Texture2D>("turretRight")); PowerBar.SetupStaticTextures(game.CM().Load <Texture2D>("powerBar_border"), game.CM().Load <Texture2D>("powerBar_power")); m_CircleTexture = game.CM().Load <Texture2D>("circle"); m_SpriteBatch = new SpriteBatch(game.GDM().GraphicsDevice); /*m_Shader = game.CM().Load<Effect>("shader"); * m_ShaderRenderTarget = new RenderTarget2D(game.GDM().GraphicsDevice, * game.GDM().GraphicsDevice.PresentationParameters.BackBufferWidth, * game.GDM().GraphicsDevice.PresentationParameters.BackBufferHeight); * m_ShaderTexture = new Texture2D(game.GDM().GraphicsDevice, * game.GDM().GraphicsDevice.PresentationParameters.BackBufferWidth, * game.GDM().GraphicsDevice.PresentationParameters.BackBufferHeight, false, m_ShaderRenderTarget.Format); */ mBackgroundTexture = game.CM().Load <Texture2D>("background_01"); mBackgroundRectangle = new Rectangle(0, 0, game.GDM().GraphicsDevice.Viewport.Width, game.GDM().GraphicsDevice.Viewport.Height); mPlayAreaRectangle = new Rectangle(game.GDM().GraphicsDevice.Viewport.Width * 2 / 100, game.GDM().GraphicsDevice.Viewport.Height * 25 / 100, game.GDM().GraphicsDevice.Viewport.Width * 96 / 100, game.GDM().GraphicsDevice.Viewport.Height * 73 / 100); mPlayAreaOutlineRectangle = new Rectangle(mPlayAreaRectangle.X - 5, mPlayAreaRectangle.Y - 5, mPlayAreaRectangle.Width + 10, mPlayAreaRectangle.Height + 10); introMusicInstance = game.ReplaceCurrentMusicInstance("Music/Music_intro", false); mController0 = Tankontroller.Instance().Controller0(); mController1 = Tankontroller.Instance().Controller1(); mController2 = Tankontroller.Instance().Controller2(); mController3 = Tankontroller.Instance().Controller3(); mController0.ResetJacks(); mController1.ResetJacks(); if (DGS.Instance.GetInt("NUM_PLAYERS") > 2) { mController2.ResetJacks(); if (DGS.Instance.GetInt("NUM_PLAYERS") > 3) { mController3.ResetJacks(); } } //loopMusicInstance = game.GetSoundManager().GetLoopableSoundEffectInstance("Music/Music_loopable"); // Put the name of your song here instead of "song_title" // game.ReplaceCurrentMusicInstance("Music/Music_loopable", true); tankMoveSound = game.GetSoundManager().GetLoopableSoundEffectInstance("Sounds/Tank_Tracks"); // Put the name of your song here instead of "song_title" if (DGS.Instance.GetInt("NUM_PLAYERS") < 4) { setupNot4Player(mPlayAreaRectangle); } else { setup4Player(mPlayAreaRectangle); } foreach (Player p in m_Teams) { m_World.AddTank(p.Tank); } }
public void Draw(float pSeconds) { Tankontroller.Instance().GDM().GraphicsDevice.Clear(Color.CornflowerBlue); m_SpriteBatch.Begin(); m_SpriteBatch.Draw(mBackgroundTexture, mBackgroundRectangle, Color.White); foreach (Player player in m_Teams) { if (player.GUI != null) { player.GUI.Draw(m_SpriteBatch); } } m_SpriteBatch.Draw(mPixelTexture, mPlayAreaOutlineRectangle, Color.Black); m_SpriteBatch.Draw(mPixelTexture, mPlayAreaRectangle, DGS.Instance.GetColour("COLOUR_GROUND")); TrackSystem.GetInstance().Draw(m_SpriteBatch); // bullet background int bulletRadius = 10; int radius = bulletRadius + 2 * DGS.Instance.GetInt("PARTICLE_EDGE_THICKNESS"); Rectangle bulletRect = new Rectangle(0, 0, radius, radius); foreach (Player p in m_Teams) { List <Bullet> bullets = p.Tank.GetBulletList(); foreach (Bullet b in bullets) { bulletRect.X = (int)b.Position.X - radius / 2; bulletRect.Y = (int)b.Position.Y - radius / 2; m_SpriteBatch.Draw(m_BulletTexture, bulletRect, Color.Black); } } World.Particles.ParticleManager.Instance().Draw(m_SpriteBatch); // bullet colour bulletRect.Width = bulletRadius; bulletRect.Height = bulletRadius; foreach (Player p in m_Teams) { List <Bullet> bullets = p.Tank.GetBulletList(); foreach (Bullet b in bullets) { bulletRect.X = (int)b.Position.X - bulletRadius / 2; bulletRect.Y = (int)b.Position.Y - bulletRadius / 2; m_SpriteBatch.Draw(m_BulletTexture, bulletRect, b.Colour); } } Rectangle trackRect = new Rectangle(0, 0, m_TankLeftTrackTexture.Width, m_TankLeftTrackTexture.Height / 15); float tankScale = (float)mPlayAreaRectangle.Width / (50 * 40); for (int i = 0; true; i++) { Tank t = m_World.GetTank(i); if (t == null) { break; } if (t.Health() > 0) { trackRect.Y = t.LeftTrackFrame() * m_TankLeftTrackTexture.Height / 15; m_SpriteBatch.Draw(m_TankLeftTrackTexture, t.GetWorldPosition(), trackRect, t.Colour(), t.GetRotation(), new Vector2(m_TankBaseTexture.Width / 2, m_TankBaseTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); trackRect.Y = t.RightTrackFrame() * m_TankLeftTrackTexture.Height / 15; m_SpriteBatch.Draw(m_TankRightTrackTexture, t.GetWorldPosition(), trackRect, t.Colour(), t.GetRotation(), new Vector2(m_TankBaseTexture.Width / 2, m_TankBaseTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); m_SpriteBatch.Draw(m_TankBaseTexture, t.GetWorldPosition(), null, t.Colour(), t.GetRotation(), new Vector2(m_TankBaseTexture.Width / 2, m_TankBaseTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); if (t.Fired() == 0) { m_SpriteBatch.Draw(m_CannonTexture, t.GetCannonWorldPosition(), null, t.Colour(), t.GetCannonWorldRotation(), new Vector2(m_CannonTexture.Width / 2, m_CannonTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); } else { m_SpriteBatch.Draw(m_CannonFireTexture, t.GetCannonWorldPosition(), null, t.Colour(), t.GetCannonWorldRotation(), new Vector2(m_CannonTexture.Width / 2, m_CannonTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); } } else { m_SpriteBatch.Draw(m_TankBrokenTexture, t.GetWorldPosition(), null, t.Colour(), t.GetRotation(), new Vector2(m_TankBrokenTexture.Width / 2, m_TankBrokenTexture.Height / 2), tankScale, SpriteEffects.None, 0.0f); } } /* Vector2 bulletOffset = new Vector2(m_BulletTexture.Width / 2, m_BulletTexture.Height / 2); * foreach (Player p in m_Teams) * { * List<Bullet> bullets = p.Tank.GetBulletList(); * foreach (Bullet b in bullets) * { * m_SpriteBatch.Draw(m_BulletTexture, b.Position, null, p.Colour, 0, bulletOffset, 1f, SpriteEffects.None, 0.0f); * } * } */ foreach (RectWall w in m_World.Walls) { w.DrawOutlines(m_SpriteBatch); } foreach (RectWall w in m_World.Walls) { w.Draw(m_SpriteBatch); } m_SpriteBatch.End(); }
private void ExitGame() { IGame game = Tankontroller.Instance(); game.SM().Transition(null); }
private void setupNot4Player(Rectangle pPlayArea) { Tankontroller game = (Tankontroller)Tankontroller.Instance(); int middleBlockHeight = pPlayArea.Height / 3; int outerBlockHeight = pPlayArea.Height / 5; int blockThickness = pPlayArea.Width / 50; int outerBlockXOffset = pPlayArea.Width / 8; List <RectWall> Walls = new List <RectWall>(); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + outerBlockXOffset, pPlayArea.Y + outerBlockHeight, blockThickness, outerBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + outerBlockXOffset, pPlayArea.Y + outerBlockHeight, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + outerBlockXOffset, pPlayArea.Y + 3 * outerBlockHeight, blockThickness, outerBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + outerBlockXOffset, pPlayArea.Y + 4 * outerBlockHeight - blockThickness, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - outerBlockXOffset - blockThickness, pPlayArea.Y + outerBlockHeight, blockThickness, outerBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - outerBlockXOffset - outerBlockHeight, pPlayArea.Y + outerBlockHeight, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - outerBlockXOffset - blockThickness, pPlayArea.Y + 3 * outerBlockHeight, blockThickness, outerBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - outerBlockXOffset - outerBlockHeight, pPlayArea.Y + 4 * outerBlockHeight - blockThickness, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + 3 * outerBlockXOffset - 2 * blockThickness, pPlayArea.Y + middleBlockHeight, blockThickness, middleBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - 3 * outerBlockXOffset + blockThickness, pPlayArea.Y + middleBlockHeight, blockThickness, middleBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + pPlayArea.Width - 3 * outerBlockXOffset + 2 * blockThickness, pPlayArea.Y + (pPlayArea.Height - blockThickness) / 2, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + 3 * outerBlockXOffset - outerBlockHeight - 2 * blockThickness, pPlayArea.Y + (pPlayArea.Height - blockThickness) / 2, outerBlockHeight, blockThickness))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + (pPlayArea.Width - blockThickness) / 2, pPlayArea.Y, blockThickness, middleBlockHeight))); Walls.Add(new RectWall(Tankontroller.Instance().CM().Load <Texture2D>("block"), new Rectangle(pPlayArea.X + (pPlayArea.Width - blockThickness) / 2, pPlayArea.Y + pPlayArea.Height - middleBlockHeight, blockThickness, middleBlockHeight))); List <Vector2> tankPositions = new List <Vector2>(); List <float> tankRotations = new List <float>(); if (DGS.Instance.GetInt("NUM_PLAYERS") == 2) { float xPosition = pPlayArea.X + outerBlockXOffset; float yPosition = pPlayArea.Y + pPlayArea.Height / 2; Vector2 tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add(0); xPosition = pPlayArea.X + pPlayArea.Width - outerBlockXOffset; yPosition = pPlayArea.Y + pPlayArea.Height / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)Math.PI); } else if (DGS.Instance.GetInt("NUM_PLAYERS") == 3) { float xPosition = pPlayArea.X + outerBlockXOffset; float yPosition = pPlayArea.Y + pPlayArea.Height / 2; Vector2 tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add(0); xPosition = pPlayArea.X + pPlayArea.Width - outerBlockXOffset; yPosition = pPlayArea.Y + pPlayArea.Height / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)Math.PI); xPosition = pPlayArea.Width / 2 + 35; yPosition = pPlayArea.Y + pPlayArea.Height / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)Math.PI / 2); } else if (DGS.Instance.GetInt("NUM_PLAYERS") == 4) { float xPosition = pPlayArea.X + outerBlockXOffset / 2; float yPosition = pPlayArea.Y + outerBlockXOffset / 2; Vector2 tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)(-Math.PI + Math.PI / 4)); xPosition = pPlayArea.X + pPlayArea.Width - outerBlockXOffset / 2; yPosition = pPlayArea.Y + outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)-Math.PI / 4); xPosition = pPlayArea.X + outerBlockXOffset / 2; yPosition = pPlayArea.Y + pPlayArea.Height - outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)(Math.PI / 2 + Math.PI / 4)); xPosition = pPlayArea.X + pPlayArea.Width - outerBlockXOffset / 2; yPosition = pPlayArea.Y + pPlayArea.Height - outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)Math.PI / 4); } else if (DGS.Instance.GetInt("NUM_PLAYERS") == 5) { float xPosition = pPlayArea.X + pPlayArea.Width / 2 + 0 - outerBlockXOffset / 2; float yPosition = pPlayArea.Y + pPlayArea.Height / 2 - outerBlockXOffset / 2; Vector2 tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)(-Math.PI + Math.PI / 4)); xPosition = pPlayArea.X + pPlayArea.Width / 2 + 0 + outerBlockXOffset / 2; yPosition = pPlayArea.Y + pPlayArea.Height / 2 - outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)-Math.PI / 4); xPosition = pPlayArea.X + pPlayArea.Width / 2 + 0 - outerBlockXOffset / 2; yPosition = pPlayArea.Y + pPlayArea.Height / 2 + outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)(Math.PI / 2 + Math.PI / 4)); xPosition = pPlayArea.X + pPlayArea.Width / 2 + 0 + outerBlockXOffset / 2; yPosition = pPlayArea.Y + pPlayArea.Height / 2 + outerBlockXOffset / 2; tankPosition = new Vector2(xPosition, yPosition); tankPositions.Add(tankPosition); tankRotations.Add((float)Math.PI / 4); } float tankXPosition = pPlayArea.X + outerBlockXOffset; float tankYPosition = pPlayArea.Y + pPlayArea.Height / 2; float tankRotation = 0; float tankScale = (float)pPlayArea.Width / (50 * 40); float textureHeightOverWidth = (float)254 / (float)540; int textureWidth = game.GDM().GraphicsDevice.Viewport.Width / 4; int textureHeight = (int)(textureWidth * textureHeightOverWidth); m_Teams.Add(new Player( DGS.Instance.GetColour("COLOUR_TANK1"), Tankontroller.Instance().Controller0(), tankPositions[0].X, tankPositions[0].Y, tankRotations[0], tankScale, game.CM().Load <Texture2D>("healthbar_winterjack_06"), game.CM().Load <Texture2D>("healthbar_winterjack_05"), game.CM().Load <Texture2D>("healthbar_winterjack_04"), game.CM().Load <Texture2D>("healthbar_winterjack_03"), game.CM().Load <Texture2D>("healthbar_winterjack_02"), game.CM().Load <Texture2D>("healthbar_winterjack_01"), new Rectangle(0, 0, textureWidth, textureHeight), true)); tankXPosition = pPlayArea.X + pPlayArea.Width - outerBlockXOffset; tankRotation = (float)Math.PI; m_Teams.Add(new Player( DGS.Instance.GetColour("COLOUR_TANK2"), Tankontroller.Instance().Controller1(), tankPositions[1].X, tankPositions[1].Y, tankRotations[1], tankScale, game.CM().Load <Texture2D>("healthbar_engineer_06"), game.CM().Load <Texture2D>("healthbar_engineer_05"), game.CM().Load <Texture2D>("healthbar_engineer_04"), game.CM().Load <Texture2D>("healthbar_engineer_03"), game.CM().Load <Texture2D>("healthbar_engineer_02"), game.CM().Load <Texture2D>("healthbar_engineer_01"), new Rectangle(game.GDM().GraphicsDevice.Viewport.Width - textureWidth, 0, textureWidth, textureHeight), false)); if (DGS.Instance.GetInt("NUM_PLAYERS") > 2) { tankRotation = (float)Math.PI; if (DGS.Instance.GetInt("NUM_PLAYERS") <= 3) { tankXPosition = pPlayArea.Width / 2 + 35; tankRotation = (float)Math.PI / 2; } m_Teams.Add(new Player( DGS.Instance.GetColour("COLOUR_TANK3"), Tankontroller.Instance().Controller2(), tankPositions[2].X, tankPositions[2].Y, tankRotations[2], tankScale, game.CM().Load <Texture2D>("healthbar_robo_06"), game.CM().Load <Texture2D>("healthbar_robo_05"), game.CM().Load <Texture2D>("healthbar_robo_04"), game.CM().Load <Texture2D>("healthbar_robo_03"), game.CM().Load <Texture2D>("healthbar_robo_02"), game.CM().Load <Texture2D>("healthbar_robo_01"), new Rectangle(0 + textureWidth, 0, textureWidth, textureHeight), true)); tankXPosition = pPlayArea.X + outerBlockXOffset; tankRotation = 0; if (DGS.Instance.GetInt("NUM_PLAYERS") > 3) { tankYPosition = pPlayArea.Y + pPlayArea.Height / 2 + 50; m_Teams.Add(new Player( DGS.Instance.GetColour("COLOUR_TANK4"), Tankontroller.Instance().Controller3(), tankPositions[3].X, tankPositions[3].Y, tankRotations[3], tankScale, game.CM().Load <Texture2D>("healthbar_yeti_06"), game.CM().Load <Texture2D>("healthbar_yeti_05"), game.CM().Load <Texture2D>("healthbar_yeti_04"), game.CM().Load <Texture2D>("healthbar_yeti_03"), game.CM().Load <Texture2D>("healthbar_yeti_02"), game.CM().Load <Texture2D>("healthbar_yeti_01"), new Rectangle(game.GDM().GraphicsDevice.Viewport.Width - textureWidth * 2, 0, textureWidth, textureHeight), false)); } } m_World = new TheWorld(pPlayArea, Walls); }
public StartScene() { Tankontroller game = (Tankontroller)Tankontroller.Instance(); mControllers = new List <IController>(); mController0 = Tankontroller.Instance().Controller0(); if (mController0 != null) { mControllers.Add(mController0); } mController1 = Tankontroller.Instance().Controller1(); if (mController1 != null) { mControllers.Add(mController1); } mController2 = Tankontroller.Instance().Controller2(); if (mController2 != null) { mControllers.Add(mController2); } mController3 = Tankontroller.Instance().Controller3(); if (mController3 != null) { mControllers.Add(mController3); } mSpriteBatch = new SpriteBatch(game.GDM().GraphicsDevice); int screenWidth = game.GDM().GraphicsDevice.Viewport.Width; int screenHeight = game.GDM().GraphicsDevice.Viewport.Height; mBackgroundTexture = game.CM().Load <Texture2D>("background_01"); mBackgroundRectangle = new Rectangle(0, 0, screenWidth, screenHeight); mForgroundTexture = game.CM().Load <Texture2D>("menu_white"); mTitleTexture = game.CM().Load <Texture2D>("menu_title"); mTitleRectangle = new Rectangle((screenWidth / 2) - (644 / 2), (screenHeight / 2) - (128 / 2), 644, 128); mButtonList = new ButtonList(); Texture2D startGameButtonTexture = game.CM().Load <Texture2D>("menu_play_white"); Texture2D startGameButtonTexturePressed = game.CM().Load <Texture2D>("menu_play_dark"); Rectangle startGameButtonRectangle = new Rectangle( ((int)((screenWidth - startGameButtonTexture.Width) / 2) - (int)(startGameButtonTexture.Width * 0.75f)), (screenHeight) / 2 + startGameButtonTexture.Height, startGameButtonTexture.Width, startGameButtonTexture.Height); Button startGameButton = new Button(startGameButtonTexture, startGameButtonTexturePressed, startGameButtonRectangle, Color.Red, StartGame); startGameButton.Selected = true; mButtonList.Add(startGameButton); Texture2D exitGameButtonTexture = game.CM().Load <Texture2D>("menu_quit_white"); Texture2D exitGameButtonTexturePressed = game.CM().Load <Texture2D>("menu_quit_dark"); Rectangle exitGameButtonRectangle = new Rectangle((screenWidth - exitGameButtonTexture.Width) / 2 + (int)(startGameButtonTexture.Width * 0.75f), (screenHeight) / 2 + exitGameButtonTexture.Width, exitGameButtonTexture.Width, exitGameButtonTexture.Height); Button exitGameButton = new Button(exitGameButtonTexture, exitGameButtonTexturePressed, exitGameButtonRectangle, Color.Red, ExitGame); exitGameButton.Selected = false; mButtonList.Add(exitGameButton); mSecondsLeft = 0.1f; game.ReplaceCurrentMusicInstance("Music/Music_start", true); }
public void Update(float pSeconds) { Particles.ParticleManager.Instance().Update(pSeconds); Vector2 collisionNormal; for (int tankIndex = 0; tankIndex < m_Tanks.Count; tankIndex++) { List <Bullet> bulletList = m_Tanks[tankIndex].GetBulletList(); for (int i = bulletList.Count - 1; i >= 0; --i) { bool collided = false; bulletList[i].Update(pSeconds); for (int tankIndex2 = 0; tankIndex2 < m_Tanks.Count; tankIndex2++) { if (tankIndex == tankIndex2) { continue; } if (bulletList[i].Collide(m_Tanks[tankIndex2], out collisionNormal)) { ExplosionInitialisationPolicy explosion = new ExplosionInitialisationPolicy(bulletList[i].Position, collisionNormal, m_Tanks[tankIndex].Colour()); Particles.ParticleManager.Instance().InitialiseParticles(explosion, 100); m_Tanks[tankIndex2].TakeDamage(); int clang = rand.Next(1, 4); string tankClang = "Sounds/Tank_Clang" + clang; Microsoft.Xna.Framework.Audio.SoundEffectInstance tankClangSound = Tankontroller.Instance().GetSoundManager().GetSoundEffectInstance(tankClang); tankClangSound.Play(); collided = true; break; } } foreach (RectWall wall in Walls) { if (wall.Collide(bulletList[i], out collisionNormal)) { ExplosionInitialisationPolicy explosion = new ExplosionInitialisationPolicy(bulletList[i].Position, collisionNormal, m_Tanks[tankIndex].Colour()); Particles.ParticleManager.Instance().InitialiseParticles(explosion, 100); collided = true; break; } } if (collided) { bulletList.RemoveAt(i); } } } foreach (RectWall w in Walls) { foreach (Tank t in m_Tanks) { if (w.Collide(t)) { t.PutBack(); } } } for (int i = 0; i < m_Tanks.Count; i++) { for (int j = i + 1; j < m_Tanks.Count; j++) { if (m_Tanks[i].Collide(m_Tanks[j])) { m_Tanks[i].PutBack(); m_Tanks[j].PutBack(); } } } }