/// <summary> /// Hits the ball on the host. /// </summary> /// <param name="code">The message data from the packets.</param> internal void UpdateBalls(string code) { SerializationScript.BallShot ballShot = SerializationScript.DeserializeBallShot(code); GameObject ball = ballShot.isAbilityBall ? golfBallManager.GetAbilityBallOfId(ballShot.ballID) : golfBallManager.GetBallOfId(ballShot.ballID); BallRetrieval br = ball.GetComponent <BallRetrieval>(); ball.GetComponent <Rigidbody>().velocity = ballShot.direction; if (br) { ball.GetComponent <BallRetrieval>().SetNewBallPos(); } GolfBall golf = ball.GetComponent <GolfBall>(); golf.HitBall(ballShot.shooterID, network.IsHost()); if (network.IsHost()) { if (golf.IsAbilityBall()) { MovingAbilityBalls.Add(golf); } if (ballShot.shouldHome) { Honing theHone = ball.gameObject.GetComponent <Honing>(); if (theHone != null && ballShot.homingTargetID >= 0) { theHone.HoneToPlayer(network.GetPlayerOfID(ballShot.homingTargetID)); } } } }
public override void HandleEvent(EventMessage e) { if (e is NearbyGolfBallMessage golfBallMessage) { currentBall = golfBallMessage.golfBall; DrawTrajectory(power, false); } else if (e is ClubPowerChangedMessage powerChangedMessage) { power = powerChangedMessage.power; //proj.material = projMats[currentPower]; precentage = (powerChangedMessage.power / maxPower); currentOffset = initialOffset + precentage * maxOffSet; DrawTrajectory(powerChangedMessage.power, !powerChangedMessage.isInit); } else if (e is ClubChangedMessage clubChangedMessage) { maxPower = clubChangedMessage.stats.MaxDistance; precentage = (clubChangedMessage.stats.MinDistance / clubChangedMessage.stats.MaxDistance); currentOffset = initialOffset + precentage * maxOffSet; currentClub = clubChangedMessage.index; vectorYIncrease = clubChangedMessage.stats.VectorYIncrease; //proj.material = projMats[currentPower]; endPoint.SetActive(false); DrawTrajectory(clubChangedMessage.stats.MinDistance, false); } }
/// <summary> /// 根据地图数据加载地图 /// </summary> /// <param name="map"></param> public void LoadMap2Ball(GolfCourseMap map) { if (map == null) { return; } ResourceManger.LoadMap("GolfMap", transform, false, false, (g) => { if (g != null) { GolfRuler ruler = g.AddComponent <GolfRuler>(); ruler.SetAABB(map.AA2, map.BB2); } }); ResourceManger.LoadBall("GolfBall", transform, false, false, (ballGo) => { if (ballGo != null) { GolfBall ball = ballGo.GetComponent <GolfBall>(); if (ball == null) { ball = ballGo.AddComponent <GolfBall>(); } if (ball != null) { ball.SetBallPos(map.StartPos); } } }); }
private void Start() { GolfBall golfBall = Context.Get <GolfBall>(); golfBall.transform.position = _startPoint.transform.position; golfBall.SetActing(true); }
public void Draw(SpriteBatch batch, Vector2 worldTranslation) { if (Game.Transitioning) { return; } if (Par < 0 || State == PlayerState.Done) { return; } if (WaterPosition != null) { Sprites.Splash.Draw(batch, (Vector2)WaterPosition + worldTranslation - new Vector2(10, 19), 0.9f); } else { var pos = Node.WorldPosition + worldTranslation - GolfBall.Center; GolfBall.Draw(batch, Node.WorldPosition + worldTranslation - GolfBall.Center / 2f, Layer == 1 ? 0.5f : 0.71f, Color.Black * 0.25f); GolfBall.Draw(batch, pos, Layer == 1 ? 0.55f : 0.75f, Color); if (State != PlayerState.Ready) { return; } var direction = Location - pos; Rotation = (float)Math.Atan2(direction.Y, direction.X); batch.Draw(Textures.Starter, pos + GolfBall.Center, null, null, new Vector2(15, 5), Rotation - (float)(Math.PI * 0.5f), new Vector2(1, 1f + Power / 4f), Color.White * 0.4f, SpriteEffects.None, Layer == 1 ? 0.49f : 0.7f); batch.Draw(Textures.StarterTop, pos + GolfBall.Center, null, null, new Vector2(15, 5), Rotation - (float)(Math.PI * 0.5f), new Vector2(1, 1f + Power / 4f), Color.White * 0.4f, SpriteEffects.None, 1f); } }
} // End private Unity method OnMouseUp // Additional Methods private void fire(Vector2 shotVector) { GolfBall myBall = nextInPool(); if (myBall == null) { return; } incrementStrokes(); if (shotVector.sqrMagnitude > 0.99f) { ++consecutiveStrokesAtFullPower; if (consecutiveStrokesAtFullPower >= Commentator.FULL_POWER_STROKES_THRESHOLD) { Commentator.raiseEvent(CommentEvent.AlwaysFullPower); } } else { consecutiveStrokesAtFullPower = 0; } playLaunchClip(); myBall.launch(transform.position, shotVector * LAUNCH_POWER, this); Game.setState(Game.State.WaitingOnBall); } // End private method fire
IEnumerator WaitForSwing(GolfBall golfball, ClubStat clubStat, float power) { while (!swing) { yield return(new WaitForEndOfFrame()); } if (clubStats.ClubName == "Putter") { SoundManager.PlaySoundAt("Putter Hit", golfball.transform.position); } if (clubStats.ClubName == "Wedge") { SoundManager.PlaySoundAt("Wedge Hit", golfball.transform.position); SoundManager.PlaySoundAt("Golf Swing", golfball.transform.position); } if (clubStats.ClubName == "Driver") { SoundManager.PlaySoundAt("Driver Hit", golfball.transform.position); SoundManager.PlaySoundAt("Golf Swing", golfball.transform.position); } EventController.FireEvent(new GolfStrokeMessage(power)); golfball.HitBall(MyID, NetworkManager.instance == null); EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.TheHurricane, SuperlativeController.ConditionFlag.additive, 1)); //For tutorial if (PlayerTutorialChecker.instance != null) { PlayerTutorialChecker.instance.ClubWasHit(clubStats.ClubName); } EndShot(); }
public void SetHoleInfo(int holeNumber, int par, GolfBall ball, Cup cup) { currentHole = holeNumber; this.ball = ball; cup.onBallEnterCup.AddListener(ShowScoreCard); holeData[holeNumber] = new HoleData(par); }
private void Awake() { ball = Instantiate(ballPrefab).GetComponent <GolfBall> (); ball.Reset(transform.position, BallSpawnOffset); cameraTransform = Camera.main.transform; cameraManager = GetComponent <CameraManager> (); SetState(ControllerState.HittingBall); }
public void ProjectileId_Set_Get() { var packet = new GolfBall(); packet.ProjectileId = 1; Assert.Equal(1, packet.ProjectileId); }
public void NumberOfHits_Set_Get() { var packet = new GolfBall(); packet.NumberOfHits = 1; Assert.Equal(1, packet.NumberOfHits); }
public void Y_Set_Get() { var packet = new GolfBall(); packet.Y = 1; Assert.Equal(1, packet.Y); }
public void X_Set_Get() { var packet = new GolfBall(); packet.X = 1; Assert.Equal(1, packet.X); }
public void PlayerIndex_Set_Get() { var packet = new GolfBall(); packet.PlayerIndex = 1; Assert.Equal(1, packet.PlayerIndex); }
private void OnTriggerEnter(Collider other) { GolfBall ball = other.GetComponent <GolfBall>(); if (ball != null) { Debug.Log("Ball in hole!"); } }
private void SpawnBallAt(GolfBall gb, Vector3 pos, int index) { gb.gameObject.SetActive(true); float intenseMath = Mathf.Abs(-((2 * index) % 10) + 5) * 2; Vector3 variation = new Vector3(intenseMath * Mathf.Sin(index), 0, intenseMath * Mathf.Cos(index)); gb.transform.position = pos + variation; gb.Prepare(); }
private void OnTriggerEnter(Collider other) { GolfBall ball = other.GetComponent <GolfBall>(); if (ball != null) { Debug.Log("Ball found"); ball.MoveBackBall(); } }
public void RespawnBall(GolfBall gb) { Debug.Log("Previous: " + gb.transform.position); gb.transform.position = transform.position; int randomIndex = UnityEngine.Random.Range(0, spawnLocations.Length); SpawnBallAt(gb, spawnLocations[randomIndex].position, randomIndex); Debug.Log("New: " + gb.transform.position); }
private void OnTriggerStay(Collider other) { if (other.CompareTag("Player")) { GolfBall ball = other.gameObject.GetComponent <GolfBall>(); if (!ball.IsMoving()) { m_winUI.SetActive(true); } } }
public async Task <GolfBall> Create([FromBody] GolfBall golfball) { using (var session = this.documentStore.OpenAsyncSession()) { await session.StoreAsync(golfball); await session.SaveChangesAsync(); return(golfball); } }
protected virtual void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("GolfBall") && network && network.IsHost()) { GolfBall ball = collision.gameObject.GetComponent <GolfBall>(); if (ball.GetVelocity().sqrMagnitude >= golfBallSpeedThreshold * golfBallSpeedThreshold) { TakeDamage(ball.GetDamage(), ball.GetLastShotId()); } } }
public async Task <GolfBall> Update([FromRoute] string id, [FromBody] GolfBall golfBall) { using (var session = this.documentStore.OpenAsyncSession()) { var fromDb = await session.LoadAsync <GolfBall>($"GolfBalls/{id}"); fromDb.Make = golfBall.Make; fromDb.Model = golfBall.Model; await session.SaveChangesAsync(); return(fromDb); } }
public void PlayerThrowAction(bool value) { if (player_GolfBall != null && player_GolfBall == lastSpawned_player_GolfBall) { GolfBall golfBall = player_GolfBall.GetComponent <GolfBall>(); Trajectory trajectory = player_GolfBall.GetComponent <Trajectory>(); golfBall.Throw(golfBall.CalculateForce(player_GolfBall.transform.position, trajectory.lastMarkerObj.transform.position, 60f)); actualTimer = ballLifeTime; runTimer = true; autoThrow = value; throwUsed = true; } }
private void Awake() { ball = FindObjectOfType <GolfBall>(); ball.onShotEnd.AddListener(OnShotEnd); ball.onShotStart.AddListener(OnShotStart); camera = GetComponent <Camera>(); // set up pivot pivot = new GameObject("Camera Pivot").transform; pivot.position = ball.transform.position; transform.SetParent(pivot); arrow = Instantiate(arrowPrefab); ResetArrow(); }
private void OnTriggerExit(Collider other) { GolfBall gb = other.GetComponent <GolfBall>(); if (gb) { ReliableOnTriggerExit.NotifyTriggerExit(other, gameObject); if (gb is AbilityBall ab) { ab.StartCooldown(); } nearbyBalls.Remove(gb); } }
private void OnTriggerEnter(Collider other) { GolfBall gb = other.GetComponent <GolfBall>(); if (gb) { if (gb is AbilityBall ability) { if (!ability.CheckInUse()) { return; } } nearbyBalls.Add(gb); ReliableOnTriggerExit.NotifyTriggerEnter(other, gameObject, OnTriggerExit); } }
} // End Unity method Awake private void OnTriggerStay2D(Collider2D other) { if (other.gameObject.layer == (int)Game.Layers.GolfBall) { GolfBall ballScript = other.gameObject.GetComponent <GolfBall>(); if (ballScript != null) { float distanceScalar = 1.0f; if (!ignoreDistance) { distanceScalar = Vector2.Distance((Vector2)transform.position, (Vector2)ballScript.transform.position); distanceScalar = 1.0f - Mathf.Clamp01((distanceScalar - insideRadius) / (influenceRadius - insideRadius)); } float pullStrength = gravStrength * distanceScalar * distanceScalar * Time.fixedDeltaTime; ballScript.pull((Vector2)transform.position, pullStrength); } } // End if the object is a golfball } // End Unity method OnTriggerStay2D
IEnumerator NoNetworkingWaitForSwing(GolfBall golfBall, Vector3 dir) { while (!swing) { yield return(new WaitForEndOfFrame()); } golfBall.GetComponent <Rigidbody>().velocity = dir; if (clubStats.ClubName == "Driver") { Honing theHone = golfBall.gameObject.GetComponent <Honing>(); GameObject obj = theHone?.GetObjOfClosestPlayer(); if (obj != null) { theHone.HoneToPlayer(obj); } } }
private void Start() { golfBallScript = this.GetComponent <GolfBall>(); lastMarkerObj = Instantiate(trajectoryMarkerPrefab, transform); lastMarkerObj.SetActive(false); runIncrease = false; throwChanceUsed = false; throwDistance = 0; markers = new GameObject[maxNumberOfMarkers]; for (int i = 0; i < maxNumberOfMarkers; i++) { GameObject singleMarker = Instantiate(trajectoryMarkerPrefab, transform); markers[i] = singleMarker; markers[i].SetActive(false); } actualNumberOfMarkers = 5; }
public void Initialize() { _eventTriggerer.Trigger(new AddSurfaceRequest( new RectangleSurface( new RectangleBoundingBox( new Vector2(20, 20), new Vector2(800, 700)), new ConstantResistiveForce(150)))); _eventTriggerer.Trigger(new AddBarrierRequest(new LineBarrier( new Vector2(400, 40), new Vector2(400, 680)))); PlayersBall = new GolfBall { Mass = 1.0 }; _eventTriggerer.Trigger(new AddGameObjectRequest(PlayersBall)); _eventTriggerer.Trigger(new PositionChangeRequest(PlayersBall, new Vector2(100, 100))); //_eventTriggerer.Trigger(new AddForceRequest(PlayersBall, new MagnetForce(new Vector2(400, 350), 100000))); }
public void CheckBallScore(GolfBall gb) { if (isActive) { //Ensure the ball is colored and not an ability ball if (gb is ColoredBall cb) { gb.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero; EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.Albatross, SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, gb.GetComponent <BallRetrieval>().GetLastPos()), gb.GetLastShotId())); if (!network || (network && network.IsHost())) { StartCoroutine(BeamFlash()); if (dbsRoutine == null) { dbsRoutine = StartCoroutine(DelayedBallDespawn(gb, duration)); SoundManager.PlaySoundAt("Ball Scored", transform.position); SoundManager.PlaySound("Golf Clap"); } } //For tutorial purposes if (PlayerTutorialChecker.instance != null) { PlayerTutorialChecker.instance.BallScored(); } return; } else if (gb is AbilityBall ab) { ab.GetComponent <Rigidbody>().velocity *= yeetFactor; } } else { gb.GetComponent <Rigidbody>().velocity *= yeetFactor; } }
void Update() { if (alive && movementAllowed) { // Toggle aim arrow visibility if (putting) { proj.gameObject.SetActive(true); } else { proj.gameObject.SetActive(false); } // Reset velocity to 0 rb.velocity = new Vector3(0,0,0); // Update ball object and see if player is close enough to putt if (!putting) { GameObject[] balls = GameObject.FindGameObjectsWithTag("Ball"); float distance = Mathf.Infinity; Vector3 position = transform.position; foreach (GameObject obj in balls) { float currentDistance = Mathf.Sqrt(Mathf.Pow((obj.transform.position.x - position.x), 2) + Mathf.Pow((obj.transform.position.z - position.z), 2)); if (currentDistance < distance) { ball = obj.GetComponent<GolfBall>(); distance = currentDistance; } } if (ball == null) { distanceToBall = 0; canHitBall = false; } else { distanceToBall = Mathf.Sqrt (Mathf.Pow ((ball.transform.position.x - transform.position.x), 2) + Mathf.Pow ((ball.transform.position.z - transform.position.z), 2)); canHitBall = (distanceToBall < 2); } } // Move player in x and z directions xDirection = 0; zDirection = 0; float xVel = GetXVelocity(); float zVel = GetZVelocity(); Vector3 newPosition = new Vector3(xVel,0,zVel); if (!putting) { transform.position = transform.position + newPosition; // If input has been given change to face new input direction if (newPosition != new Vector3(0,0,0)) { transform.rotation = Quaternion.LookRotation(-newPosition); transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y + 90, transform.eulerAngles.z); } } else { // If currently aiming a putt allow the stick to rotate the character around the ball if (!swinging) { float dir = walkSpeed*xVel-walkSpeed*zVel; if ((dir < 0 && canRotateLeft) || (dir > 0 && canRotateRight)) { rotatingLeft = (dir < 0); if (rotatingLeft) { canRotateRight = true; } else { canRotateLeft = true; } Transform sweetspot = transform.FindChild("Sweetspot"); sweetspot.SetParent (null); transform.SetParent (sweetspot); sweetspot.RotateAround (ball.transform.position, Vector3.up, dir); transform.SetParent (null); sweetspot.SetParent (this.transform); } } } // Check if player is attacking GetAttacking(putting, canHitBall); CheckAnimStateForAttacking(); } // Update player color and respawn player if necessary else if (Time.time >= timeOfDeath + respawnTime) { proj.gameObject.SetActive(false); Respawn(); } GetRespawn(); }