//using a specific skill void useWhiplash() { PongBall ballScript = ball.GetComponent <PongBall>(); ballScript.reflectX(); //ballScript.reflectY(); }
// Start is called before the first frame update public void Init(bool isBottomPaddle, PongBall ball) { width = transform.localScale.x; this.ball = ball; isBottom = isBottomPaddle; ResetPaddle(); }
public IEnumerator Answer(PongBall ball) { if (!GameManager.chatManager.isExpectingAnswer) { yield break; } GameManager.chatManager.isExpectingAnswer = false; for (int i = 0; i < balls.Count; i++) { //if (balls[i] == ball) continue; StartCoroutine(balls[i].Desummon(true)); } /* * float timeElapsed = 0; * float smoothProgress = 0; * Vector3 startPos = ball.transform.position; * ball.RevertToInitialSetting(); * ball.collider.enabled = false; * * while (smoothProgress < 1) * { * timeElapsed += GameManager.deltaTime; * smoothProgress = Mathf.SmoothStep(0, 1, timeElapsed / (ball.fadeDur)); * * ball.transform.position = Vector3.Lerp(startPos, playerPaddle.transform.position, smoothProgress); * ball.transform.localScale = Vector3.Lerp(ball.initialScale, Vector3.zero, smoothProgress); * yield return null; * } * * StartCoroutine(ball.Desummon(false)); */ GameManager.chatManager.Answer(ball.id); }
// Start is called before the first frame update void Start() { ball = (PongBall)FindObjectOfType(typeof(PongBall)); paddle1 = GameObject.Find("Paddle 1"); paddle2 = GameObject.Find("Paddle 2"); //Debug.Log(paddle2); }
public PaddleAI(GameObject playerObject, GameObject ballObject) { player = playerObject; pc = player.GetComponent<PlayerController>(); // ball = ballObject; ballscript = ball.GetComponent<PongBall>(); // //vMoveSpeed = player.tag == "Player2" ? -vMoveSpeed:vMoveSpeed; }
void ScaleDown(PongBall ball) { // Play sound ball.soundBall.PlayOneShot(ball.powerup); // Apply effect ball.gameObject.transform.localScale *= 0.5f; // Remove powerup Destroy(gameObject); }
void SpeedUp(PongBall ball) { // Play sound ball.soundBall.PlayOneShot(ball.powerup); // Apply effect ball.speed *= 2; // Remove powerup Destroy(gameObject); }
public PaddleAI(GameObject playerObject, GameObject ballObject) { player = playerObject; pc = player.GetComponent <PlayerController>(); // ball = ballObject; ballscript = ball.GetComponent <PongBall>(); // //vMoveSpeed = player.tag == "Player2" ? -vMoveSpeed:vMoveSpeed; }
// Start is called before the first frame update void Start() { bottomLeft = Camera.main.ScreenToWorldPoint(new Vector2(0, 0)); topRight = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)); ball = Instantiate(ball) as PongBall; playerPaddle = Instantiate(paddle) as PongPaddle; computerPaddle = Instantiate(paddle) as PongPaddle; playerPaddle.Init(true, ball); computerPaddle.Init(false, ball); }
private void OnCountdownTimerIsExpired() { if (!gameStarted) { StartGame(); } if (PhotonNetwork.IsMasterClient) { ball = PhotonNetwork.Instantiate("PongBall", Vector3.up, Quaternion.identity, 0).GetComponent <PongBall>(); } }
void SpawnBall() { ballCount += 1; Instantiate(ballPrefab, spawnPoint(), Quaternion.identity); ball = GameObject.FindGameObjectWithTag("Ball").GetComponent <PongBall>(); if (ball) { ball.rb.velocity = createDir(ball.transform.position, Dir) * 400.0f * difficulty_mod; } }
public void SpawnBall(int id, string qString, Color color) { PongBall b = Instantiate(ballPrefab, pongBallSpawn.transform.position, Quaternion.identity); b.id = id; b.qString = qString; b.GetComponent <SpriteRenderer>().color = color; b.moveDir = Random.insideUnitCircle.normalized; b.pongManager = this; balls.Add(b); }
public static string forBallMove(PongBall ball) { StringBuilder sb = new StringBuilder("{\"type\":\"").Append(PongCoordinator.TYPE_BALL_MOVE).Append("\", "); sb.Append("\"").Append(PongBall.FIELD_BALLID).Append("\": \"").Append(ball.ballid).Append("\""); sb.Append("\"").Append(PongBall.FIELD_POSITION).Append("\":"); PongSerializer.forVector(sb, ball.position); sb.Append("\"").Append(PongBall.FIELD_VELOCITY).Append("\":"); PongSerializer.forVector(sb, ball.velocity); sb.Append("\"").Append(PongBall.FIELD_DIAMETER).Append("\": ").Append(ball.diameter).Append(","); sb.Append("}"); return sb.ToString(); }
public void RespawnBall(int losePlayerID) { if (PhotonNetwork.IsMasterClient && !endOfGame) { if (ball == null) { ball = PhotonNetwork.Instantiate("PongBall", Vector3.up, Quaternion.identity, 0).GetComponent <PongBall>(); } else { ball.Respawn(losePlayerID); } } }
void checkBall() { PongBall ballScript = ball.GetComponent <PongBall>(); if (ball.transform.position.x < ballScript.getLowerBounds().x) //passed player 1's goal { p1script.takeDamage(3); ballScript.reset(); } else if (ball.transform.position.x > ballScript.getUpperBounds().x) //passed player 1's goal { p2script.takeDamage(3); ballScript.reset(); } }
public void TestBallInfo() { var ball1 = new PongBall(); ball1.ballid = "id of ball"; ball1.position = new Vector2(1f, 2f); ball1.velocity = new Vector2(3f, 4f); ball1.diameter = 5f; string msg = PongSerializer.forBallMove(ball1); object boe = JSON.JsonDecode(msg); PongBall second = new PongBall(); second = PongSerializer.fromBallMove(second, (Hashtable) boe); string msg2 = PongSerializer.forBallMove(second); Assert.AreEqual(msg, msg2); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Ball")) { ball = other.gameObject.GetComponent <PongBall>(); if (this.name.Equals("PowerUp 1")) { SpeedUp(ball); } if (this.name.Equals("PowerUp 2")) { ScaleDown(ball); } } }
public void ControlEnemyPaddle() { if (balls.Count == 0) { return; } int targetIndex = 0; for (int i = 0; i < balls.Count; i++) { if (balls[i] == null) { balls.RemoveAt(i); i--; continue; } if (balls[i].transform.position.y > balls[targetIndex].transform.position.y) { targetIndex = i; } } if (balls.Count == 0) { return; } PongBall target = balls[targetIndex]; if (target != null) { float dx = target.transform.position.x - enemyPaddle.transform.position.x; if (dx * dx > 0.35f) { enemyPaddle.Move(Vector3.right * dx); } } }
// Use this for initialization void Start() { ball = this; ball.init(); }
private void Start() { scoreDisplay = GameObject.Find("Scoreboard"); scores = scoreDisplay.GetComponent <ScoreDisplay>(); ball = (PongBall)FindObjectOfType(typeof(PongBall)); }
public static PongBall fromBallMove(PongBall pongBall, Hashtable BallInfo) { pongBall.ballid = (string)BallInfo[PongBall.FIELD_BALLID]; Hashtable vect = (Hashtable)BallInfo[PongBall.FIELD_POSITION]; pongBall.position = PongSerializer.toVector(vect); vect = (Hashtable)BallInfo[PongBall.FIELD_VELOCITY]; pongBall.velocity = PongSerializer.toVector(vect); pongBall.diameter = Convert.ToSingle((double)BallInfo[PongBall.FIELD_DIAMETER]); return pongBall; }
private void UpdateJoinedStarting() { //we're starting a new game this.playerInfo.Clear(); //@TODO: destroy gameobject paddles from previous game ArrayList players = (ArrayList)parsedGameSetup[PongPlayer.ARRAY_PLAYERS]; PongPlayer previousPlayer = null; for (int p = 0; p < players.Count; ++p) { PongPlayer newPlayer = new PongPlayer((Hashtable)players[p]); //now create the walls & goals: GameObject goal = Instantiate<GameObject>(PrefabGoal); createWall(goal, newPlayer.goalLeft, newPlayer.goalRight); goal.name = "Goal for " + newPlayer.playerid; newPlayer.paddle = CreatePaddle(newPlayer.playerid, goal.transform.rotation, newPlayer.playerLeft, newPlayer.playerRight); //@TODO: for local paddle, bind keys to the newly instantiated paddle this.playerInfo.Add(newPlayer.playerid, newPlayer); //@TODO: link goal to correct user, for points and awards if (previousPlayer != null) { GameObject wall = Instantiate<GameObject>(PrefabWall); createWall(wall, previousPlayer.goalRight, newPlayer.goalLeft); } previousPlayer = newPlayer; } this.localPlayer = this.playerInfo[this.localPlayerName]; //some ugly shenanigans to create the last wall (between first and last player) GameObject lastwall = Instantiate<GameObject>(PrefabWall); createWall(lastwall, previousPlayer.goalRight, PongSerializer.toVector((Hashtable) ((Hashtable)players[0])[PongPlayer.FIELD_GOALLEFT])); //now let's play ball! GameObject ballobject = Instantiate<GameObject>(PrefabBall); ballobject.name = "PongTestBall"; this.ball = new PongBall(ballobject.GetComponent<Rigidbody>()); //next frame, we can start playing! status = CoordinatorStatus.JOINED_PLAYING; }
private void StartNewGame() { Debug.Log("initializing playfield"); Vector3[] points = CreateEllipse(radius, radius, new Vector3(0f, 0f, 0f), this.playerInfo.Count * 2); GameObject wall; GameObject goal; var playerEnum = this.playerInfo.GetEnumerator(); for (int i = 0; i < points.Length - 2; i += 2) { //@TODO: should this stay here, or move to the corresponding receiveGameSetup? The server may not see its own gamesetup message wall = Instantiate<GameObject>(PrefabWall); createWall(wall, points[i + 1], points[i + 2]); goal = Instantiate<GameObject>(PrefabGoal); createWall(goal, points[i], points[i + 1]); if (playerEnum.MoveNext()) { var p = playerEnum.Current.Value; p.goalLeft = points[i]; p.goalRight = points[i + 1]; p.height = PADDLE_HEIGHT; p.length = PADDLE_LENGTH; p.playerLeft = p.goalLeft + (goal.transform.forward * PADDLE_DISTANCE); p.playerRight = p.goalRight + (goal.transform.forward * PADDLE_DISTANCE); p.paddle = CreatePaddle(p.playerid, goal.transform.rotation, p.playerLeft, p.playerRight); goal.name = p.playerid; } else { Debug.LogError("mismatch between playfield size(" + (points.Length/2) + ") and playercount(" + this.playerInfo.Count + ")"); } } //now let's play ball! GameObject ballobject = Instantiate<GameObject>(PrefabBall); ballobject.name = "PongTestBall"; this.ball = new PongBall(ballobject.GetComponent<Rigidbody>()); SendGameSetup(this.playerInfo); status = CoordinatorStatus.HOSTING_PLAYING; }