public TankMain(Point location, TankDirection direction) { dictDirection = new Dictionary <TankDirection, Image> { [TankDirection.Up] = Image.FromFile(pathImage + @"\TankMain\TankUp.png"), [TankDirection.Right] = Image.FromFile(pathImage + @"\TankMain\TankRight.png"), [TankDirection.Down] = Image.FromFile(pathImage + @"\TankMain\TankDown.png"), [TankDirection.Left] = Image.FromFile(pathImage + @"\TankMain\TankLeft.png") }; Direction = direction; Location = location; Size = Image.Size; }
public Tank(String aTankName, String aTurretName, Vector2 aPosition, Vector2 aSize, bool aIsPlayer) : base(aTankName, aPosition, aSize) { //turret = new TexturedPrimitive(aTurretName, aPosition, aSize); m_turret = Game1.sContent.Load<Texture2D>(aTurretName); m_turretRotation = 0f; m_isEnabled = true; m_isPlayer = aIsPlayer; m_RotationDirection = TankDirection.Up; m_MovementDirection = TankDirection.None; m_TimeSpan = new TimeSpan(); m_TimeRespawn = new TimeSpan(); }
public TankDirection GetOpositeSideOf(TankDirection side) { if (side == TankDirection.up) { return(TankDirection.down); } else if (side == TankDirection.down) { return(TankDirection.up); } else if (side == TankDirection.right) { return(TankDirection.left); } else { return(TankDirection.right); } }
void SwitchDirection() { switch (currentDirection) { case TankDirection.Up: currentDirection = TankDirection.Left; break; case TankDirection.Down: currentDirection = TankDirection.Right; break; case TankDirection.Left: currentDirection = TankDirection.Down; break; case TankDirection.Right: currentDirection = TankDirection.Up; break; } }
public void Reset() { m_isEnabled = true; m_turretRotation = 0; m_RotationDirection = TankDirection.Up; m_MovementDirection = TankDirection.None; }
public void Update(GameTime gameTime) { // Is this tank is the player, update with the controller if (m_isPlayer) { // Get the direction of the tank Vector2 input = InputWrapper.ThumbSticks.Left; if (input.X != 0) { if (input.X > 0) m_RotationDirection = TankDirection.Right; else m_RotationDirection = TankDirection.Left; } else if (input.Y != 0) { if (input.Y > 0) m_RotationDirection = TankDirection.Up; else m_RotationDirection = TankDirection.Down; } // Change the movement position if (input == Vector2.Zero) m_MovementDirection = TankDirection.None; else m_MovementDirection = m_RotationDirection; // Change the turret rotation m_turretRotation += GraphicsSupport.InputWrapper.ThumbSticks.Right.X / 5; } else // Is it's an enemy tank: AI movement { m_TimeSpan += gameTime.ElapsedGameTime; if (m_TimeSpan.Milliseconds % 21 == 0) { m_RotationDirection = (TankDirection)Game1.sRan.Next(5); m_MovementDirection = m_RotationDirection; m_turretRotation = (float)(Game1.sRan.NextDouble() * 2 * 3.14159265359); } } // Rotate the tank if (m_RotationDirection == TankDirection.Left || m_RotationDirection == TankDirection.Right) RotateAngleInRadian = (float)(3.14159265359 / 2); else RotateAngleInRadian = 0; // Move if inside the window if (GraphicsSupport.Camera.CollidedWithCameraWindow(this) == Camera.CameraWindowCollisionStatus.InsideWindow) { switch (m_MovementDirection) { case TankDirection.None: break; case TankDirection.Up: mPosition += new Vector2(0, 1); break; case TankDirection.Right: mPosition += new Vector2(1, 0); break; case TankDirection.Down: mPosition += new Vector2(0, -1); break; case TankDirection.Left: mPosition += new Vector2(-1, 0); break; } } else // move reverse if on the edge { switch (m_MovementDirection) { case TankDirection.None: break; case TankDirection.Up: mPosition += new Vector2(0, -2); break; case TankDirection.Right: mPosition += new Vector2(-2, 0); break; case TankDirection.Down: mPosition += new Vector2(0, 2); break; case TankDirection.Left: mPosition += new Vector2(2, 0); break; } m_MovementDirection = TankDirection.None; } // Check if need to be re-enabled - to respwan m_TimeRespawn += gameTime.ElapsedGameTime; if(!m_isEnabled && m_TimeRespawn.Seconds >= 5) { SetIsEnabled(true); Reset(); m_TimeRespawn = TimeSpan.Zero; } }