public void Update(MouseControls mc, KeyboardControls01 kc) { // GameBall and GameBall2 do not have mouse controls built into Update UpdateMouseControls(mc); if (ball != null) { ball.Update(); } if (ball2 != null) { ball2.Update(); } if (ball != null) { UpdateCollisionPointList(); } if (ball2 != null) { UpdateCollisionPointList2(); } // GameBall04 ball4 has mouse controls and collision detection logic built into Update function if (ball4 != null) { ball4.Update(mc, cplist); } DrawToBuffer(); }
private void DrawMouseDebugText(PointF position) { MouseControls mc = gameControl.MControls; string mousePosition = "Mouse Position: " + mc.Position.ToString(); float textHeight = bbg.MeasureString(mousePosition, font).Height; DrawText(mousePosition, position); position.Y += textHeight; string leftButtonStatus = "Left Button: " + mc.LeftButton.State.ToString(); string leftButtonDownPos = "Down: " + mc.LeftButton.DownPosition.ToString(); string leftButtonUpPos = "Up: " + mc.LeftButton.UpPosition.ToString(); DrawText(leftButtonStatus, position); position.Y += textHeight; DrawText(leftButtonDownPos, position); position.Y += textHeight; DrawText(leftButtonUpPos, position); position.Y += textHeight; string rightButtonStatus = "Right Button: " + mc.RightButton.State.ToString(); string rightButtonDownPos = "Down: " + mc.RightButton.DownPosition.ToString(); string rightButtonUpPos = "Up: " + mc.RightButton.UpPosition.ToString(); DrawText(rightButtonStatus, position); position.Y += textHeight; DrawText(rightButtonDownPos, position); position.Y += textHeight; DrawText(rightButtonUpPos, position); position.Y += textHeight; }
//private void AddBlocks() //{ // if (blockList.Count > 0) // { // for (int i = 0; i < blockList.Count; i++) // { // blockList[i].position.Y += blockHeight; // } // } // int y = 0; // int x = 0; // int numOfBlocks = r.Next(1, maxBlocksWide); // int[] blockSpaces = GetRandomNumbersNoRepeats(numOfBlocks, 0, maxBlocksWide, true); // for (int i = 0; i < blockSpaces.Length; i++) // { // x = blockSpaces[i] * blockWidth; // blockList.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // } //} //private void AddBlocksForRound(int round) //{ // if (blockList.Count > 0) // { // for (int i = 0; i < blockList.Count; i++) // { // blockList[i].position.Y += blockHeight; // } // } // int y = 0; // int x = 0; // int numOfBlocks = r.Next(1, maxBlocksWide); // int[] blockSpaces = GetRandomNumbersNoRepeats(numOfBlocks, 0, maxBlocksWide, true); // for (int i = 0; i < blockSpaces.Length; i++) // { // x = (int)ball.minBallBoundsX + blockSpaces[i] * blockWidth; // AddBlock(round, new PointF(x, y)); // } //} //private void AddBlock(int round, PointF pos) //{ // blockList.Add(new Blockv0d2(pos, new SizeF(blockWidth, blockHeight))); // blockList[blockList.Count - 1].hitsToBreak = round; //} public void HandleMouseControls(MouseControls mc) { if (mc.LeftButton.State == UpDownState.Down && mc.LeftButton.LastState == UpDownState.Down) { if (ball.IsLaunched == false) { ball.SetAngle(mc.Position); } } if (mc.LeftButton.State == UpDownState.Up && mc.LeftButton.LastState == UpDownState.Down) { if (ball.IsLaunched == false) { ball.IsLaunched = true; } else { ball.IsLaunched = false; } } if (mc.RightButton.State == UpDownState.Down && mc.RightButton.LastState == UpDownState.Down) { ball.Reset(); } }
} // end of function ProcessGameControls(MouseControls mc) protected void HandleMouseControls(MouseControls mc) { //if (mc.LeftButton.State == UpDownState.Down && mc.LeftButton.LastState == UpDownState.Down) //{ // if (ball.IsLaunched == false) // { // ball.SetAngle(mc.Position); // } //} //if (mc.LeftButton.State == UpDownState.Up && mc.LeftButton.LastState == UpDownState.Down) //{ // if (ball.IsLaunched == false) // { // ball.IsLaunched = true; // } // else // { // ball.IsLaunched = false; // } //} //if (mc.RightButton.State == UpDownState.Down && mc.RightButton.LastState == UpDownState.Down) //{ // ball.Reset(); //} } // end of function HandleMouseControls(MouseControls mc)
void Start() { cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); Mc = cam.transform.GetComponent <MouseControls>(); Rc = cam.transform.GetComponent <ResourceController>(); Canvas.SetActive(false); Destination.SetActive(false); }
private void Awake() { cameraControls = new MouseControls(); inputProvider = GetComponentInChildren <CinemachineInputProvider>(); virtualCamera = GetComponentInChildren <CinemachineVirtualCamera>(); cameraTransform = virtualCamera.VirtualCameraGameObject.transform; }
void Start() { mouse = GameObject.Find("_Cam").GetComponent <MouseControls>(); for (int i = 0; i < menuPanels.Count; i++) { menuPanels[i].anchoredPosition = new Vector2(0, -menuPanels[i].rect.height); } for (int i = 0; i < menuSubPanels.Count; i++) { menuSubPanels[i].anchoredPosition = new Vector2(0, -menuSubPanels[i].rect.height); } }
private void Awake() { m_Data = DataManager.Instance; m_SelectedUnitsList = new List <GameObject>(); m_UnitMask = m_Data.mouseData.unitMask; m_StructureMask = m_Data.mouseData.structureMask; m_GroundMask = m_Data.mouseData.groundMask; m_MouseControls = new MouseControls(); m_MouseControls.Mouse.SetCallbacks(this); }
void Start() { controls = GetComponent <MouseControls>(); gameScript = GetComponent <PlayerGameScript>(); mainGameScript = FindObjectOfType <MainGameScript>(); direction = Vector2.right; startingPosition = transform.position; newDay = false; }
void Start() { controls = GetComponent <MouseControls>(); fishMeterNeedle = FindObjectOfType <FishMeterNeedle>(); audioPlayer = FindObjectOfType <AudioPlayer>(); mainGameScript = FindObjectOfType <MainGameScript>(); fishStack = GetComponentInChildren <FishStack>(); currentFishSchool = null; currentWeight = 0.0f; newDay = false; }
private void BallControlsWithMidAirClicks() { MouseControls mc = gameControl.MControls; //if (mc.LeftButton.State == UpDownState.Down && mc.LeftButton.LastState == UpDownState.Down && // ball.IsLaunched == false) //{ // if (mc.Position.Y > ball.Position.Y - (ball.ObjectSize.Height * 2)) // { // ball.Misfire = true; // } // else // { // ball.SettingLaunchAngle = true; // ball.SetLaunchAngle(mc.Position); // } //} //if (mc.LeftButton.State == UpDownState.Up && mc.LeftButton.LastState == UpDownState.Down) //{ // ball.SettingLaunchAngle = false; // //ball.Launch(); // ball.Launch(ball.AngleBetweenPoints(mc.Position), mc.Position); //} }
void HandleMouseInput(MouseControls mc) { bool dbgtxt = true; string fnId = $"[{clsName}.HandleMouseInput]"; if (dbgtxt) { DbgFuncs.AddStr($"{fnId} mc.LeftButtonState: {mc.LeftButtonState}"); } if (dbgtxt) { DbgFuncs.AddStr($"{fnId} mc.LastLeftButtonState: {mc.LastLeftButtonState}"); } mousePos.Set(mc.X, mc.Y); // Reset game screen if (mc.RightButtonState == UpDownState.Down && mc.LastRightButtonState == UpDownState.Up) { Reset(); return; } // Prevents aim and spin boxes from continuing to drag if mouse is not down if (mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Up && (adjustingAim || adjustingSpin || adjustingPosition)) { adjustingAim = adjustingSpin = adjustingPosition = false; return; } // Setting up the shot if (!launched) { // Building logic to move ball before the aim marker is placed (aimTraj.Placed) if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && !aimTraj.Placed && InCircle(mc.Position.X, mc.Position.Y)) { adjustingPosition = true; return; } // Place aim marker if (!aimTraj.Placed && mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { aimTraj.SetStartPoint(position); aimTraj.SetEndPoint(mc.Position); spinTraj.SetStartPoint(position); PointD spinStartPos = new PointD(); spinStartPos = position.HalfWayTo(mc.Position.X, mc.Position.Y); spinTraj.SetEndPoint(spinStartPos); return; } // Adjust aim or spin if (aimTraj.Placed && (!adjustingAim || !adjustingSpin) && mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { if (aimTraj.InEndRect(mc.X, mc.Y)) { adjustingAim = true; return; } if (spinTraj.InEndRect(mc.X, mc.Y)) { adjustingSpin = true; return; } } // Stop adjusting aim or spin if ((adjustingAim || adjustingSpin) && mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Down) { adjustingAim = adjustingSpin = false; return; } // Launch the ball and start the timer (when launch button is clicked) if ((!adjustingAim && !adjustingSpin) && mc.LastLeftButtonState == UpDownState.Up && mc.LeftButtonState == UpDownState.Down //&& InLaunchButtonRect(mc.X, mc.Y) && btnLaunch.InBoundingRect(mc.X, mc.Y)) { launched = true; gtimer.Start(); } } }
} // end of constructor BasicObjectController(float screenWidth, float screenHeight) #region building walls region //private void LoadTestWall() //{ // int blockWidth = 50; // int blockHeight = 50; // int wallLength = 500; // int blockCount = wallLength / blockWidth; // int startX = 300; // int startY = 75; // int x = startX; // int y = startY; // for (int i = 0; i < blockCount; i++) // { // Blockv0d1 r = new Blockv0d1(); // r.Load(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // x += blockWidth; // } //} // end of function LoadTestWall() //private void LoadWalls() //{ // int blockWidth = 50; // int blockHeight = 50; // //int blocksWide = (int)screenWidth / blockWidth; // //int blocksHigh = (int)screenHeight / blockHeight; // int blocksWide = (int)screenWidth / blockWidth; // int blocksHigh = (int)screenHeight / blockHeight; // float x, y; // #region north wall // x = y = 0; // for (int i = 0; i < blocksWide; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // x += blockWidth; // } // #endregion // #region test region 1 // x = blockWidth * 2; // y = blockHeight * 2; // for (int i = 0; i < 10; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // x += blockWidth; // } // x = blockWidth * 2; // y = blockHeight * 8; // for (int i = 0; i < 7; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // x += blockWidth; // } // #endregion test region 1 // #region south wall // x = 0; // y = screenHeight - blockHeight; // for (int i = 0; i < blocksWide; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // x += blockWidth; // } // #endregion // #region west wall // x = y = 0; // for (int i = 0; i < blocksHigh; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // y += blockHeight; // } // #endregion // #region east wall // x = screenWidth - blockWidth; // y = 0; // for (int i = 0; i < blocksHigh; i++) // { // Blockv0d1 r = new Blockv0d1(new PointF(x, y), new SizeF(blockWidth, blockHeight)); // //blockList.Add(r); // blockList2.Add(new Blockv0d2(new PointF(x, y), new SizeF(blockWidth, blockHeight))); // y += blockHeight; // } // #endregion //} // end of function LoadWalls() //private void LoadTestBlocks() //{ // int blockWidth = 50; // int blockHeight = 50; // Blockv0d1 r = new Blockv0d1(new PointF(300, 600), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(300, 600), new SizeF(blockWidth, blockHeight))); // //blockList.Add(r); // r = new Blockv0d1(new PointF(600, 200), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(600, 200), new SizeF(blockWidth, blockHeight))); // //blockList.Add(r); // r = new Blockv0d1(new PointF(400, 200), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(400, 200), new SizeF(blockWidth, blockHeight))); // //blockList.Add(r); // r = new Blockv0d1(new PointF(200, 200), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(200, 200), new SizeF(blockWidth, blockHeight))); // //blockList.Add(r); // r = new Blockv0d1(new PointF(200, 300), new SizeF(blockWidth, blockHeight)); // blockList2.Add(new Blockv0d2(new PointF(200, 300), new SizeF(blockWidth, blockHeight))); // //blockList.Add(r); //} // end of function LoadTestBlocks() #endregion building walls region public void ProcessGameControls(MouseControls mc) { //HandleMouseControls(mc); //lvl1.HandleMouseControls(mc); lvl2.HandleMouseControls(mc); } // end of function ProcessGameControls(MouseControls mc)
public void Update(MouseControls mc, List <CollisionPoint> blockCpList) { bool dbgtxt = true; string fnId = FnId(clsName, "Update"); HandleMouseInput(mc); if (dbgtxt) { DbgFuncs.AddStr($"{fnId} launched: {launched}"); } if (!launched) { if (adjustingPosition) { position.Set(mousePos); startPosition.Set(mousePos); } if (adjustingAim) { aimTraj.SetEndPoint(mousePos); } if (adjustingSpin) { spinTraj.SetEndPoint(mousePos); } SetInitialTrajectory(); CalculateDriftFactor(aimTraj.Rotation, spinTraj.Rotation); CalculateInitialDriftPerSecond(); } CheckForBlockCollision(blockCpList); ApplyDriftPerSecond(gtimer.TotalSeconds); if (launched) { gtimer.Update(); // 2020-01-01 Going to try applying bounce logic here. Collision is determined in the previous frame currently. CalculateBounceAngle(); rotation += bounceAngle; position.X = position.X + speed * Math.Cos(rotation); position.Y = position.Y + speed * Math.Sin(rotation); if (bounceAngle != 0) { lastBounceAngle = bounceAngle; bounceAngle = 0; } } MoveCollisionPoints(position.X, position.Y, radius, rotation); if (dbgtxt && DrawDbgTxt) { //gtimer.DbgTxt(); dbgPrintAngle(fnId, "driftFactor", driftFactor); dbgPrintAngle(fnId, "rotation", rotation); dbgPrintAngle(fnId, "initialDriftPerSecond", initialDriftPerSecond); DbgFuncs.AddStr($"{fnId} gtimer.TotalSeconds: {gtimer.TotalSeconds}"); DbgFuncs.AddStr($"{fnId} ~~~~ CHECK FOR BOUNCE DBG LOGIC ~~~"); DbgFuncs.AddStr($"{fnId} shouldBounce: {shouldBounce}"); DbgFuncs.AddStr($"{fnId} firstPointHit (index): {firstPointHit}"); dbgPrintAngle(fnId, "bounceAngle", bounceAngle); dbgPrintAngle(fnId, "lastBounceAngle", lastBounceAngle); dbgPrintAngle(fnId, "testBounceAngle", testBounceAngle); DbgFuncs.AddStr($"{fnId} hz: {hz}"); //if (firstPointHit > -1) { launched = aimTraj.Visible = spinTraj.Visible = false; } // For testing, stopping ball and hiding aim and spin markers } if (firstPointHit > -1) { launched = aimTraj.Visible = spinTraj.Visible = false; } // For testing, stopping ball and hiding aim and spin markers }
public void UpdateMouseControls(MouseControls mc) { if (ball == null) { goto Ball2Controls; } #region ball version 1 #region Setting up the shot if (!ball.BallLaunched) { if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && ball.SettingSpin) { if (ball.IsInSpinRect(mc.X, mc.Y)) { mStartX = mc.X; mStartY = mc.Y; deltaX = 0; deltaY = 0; ball.PlacingSpinRect = true; } } if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Down && ball.PlacingSpinRect) { deltaX = mc.X - mStartX; deltaY = mc.Y - mStartY; ball.AdjustSpinMarker(mc.X, mc.Y); } if (mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Down && ball.PlacingSpinRect) { ball.PlacingSpinRect = false; } // launch / set flight path if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { if (ball.IsInLaunchButtonRect(mc.X, mc.Y) && ball.ReadyForLaunch) { ball.LaunchBall(); } else //if (mc.Y < ball.Y - ball.Height * 2) // uncomment if here to restrict aim to only north side of the ball { ball.SetFlightPath(mc.X, mc.Y); } } } #endregion Setting up the shot // unpause if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && ball.BallLaunched == true) { ball.Pause = false; } // Reset if (mc.RightButtonState == UpDownState.Down && mc.LastRightButtonState == UpDownState.Up) { ball.Reset(); } #endregion ball version 1 Ball2Controls: if (ball2 == null) { goto EndControls; } #region ball2 only #region Setting up the shot if (!ball2.BallLaunched) { if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && ball2.SettingSpin) { if (ball2.IsInSpinRect(mc.X, mc.Y)) { mStartX = mc.X; mStartY = mc.Y; deltaX = 0; deltaY = 0; ball2.PlacingSpinRect = true; } } if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Down && ball2.PlacingSpinRect) { deltaX = mc.X - mStartX; deltaY = mc.Y - mStartY; ball2.AdjustSpinMarker(mc.X, mc.Y); } if (mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Down && ball2.PlacingSpinRect) { ball2.PlacingSpinRect = false; } // launch / set flight path if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { if (ball2.IsInLaunchButtonRect(mc.X, mc.Y) && ball2.ReadyForLaunch) { ball2.LaunchBall(); } else //if (mc.Y < ball2.Y - ball2.Height * 2) // uncomment if here to restrict aim to only north side of the ball2 { ball2.SetFlightPath(mc.X, mc.Y); } } } #endregion Setting up the shot // unpause if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && ball2.BallLaunched == true) { ball2.Pause = false; } // Reset if (mc.RightButtonState == UpDownState.Down && mc.LastRightButtonState == UpDownState.Up) { ball2.Reset(); } #endregion ball2 EndControls: return; }
public ValuesController() { mouse = new MouseControls(); }
void Awake() { instance = this; }