private void ChangeDirection(Vector2 relativePosition, ref Balle b) { Bounds bounds = GetComponent <Collider2D>().bounds; //if the right side of the collider is hit if (relativePosition.x > 0f && relativePosition.y <= bounds.max.y && relativePosition.y >= bounds.min.y) { //print ("Collided with the right side"); b.SwapX(); } //if the left side of the collider is hit else if (relativePosition.x < 0 && relativePosition.y <= bounds.max.y && relativePosition.y >= bounds.min.y) { //print ("Collided with the left side"); b.SwapX(); } //if the upper side of the collider is hit else if (relativePosition.y > 0 && relativePosition.x <= bounds.max.x && relativePosition.x >= bounds.min.x) { //print ("Collided with the upper side"); b.SwapY(); } //if the lower side of the collider is hit else if (relativePosition.y < 0 && relativePosition.x <= bounds.max.x && relativePosition.x >= bounds.min.x) { //print ("Collided with the lower side"); b.SwapY(); } else { b.SwapX(); } }
public override void Shoot() { GameObject Balle; Balle = Instantiate(BalleType, null); Balle.transform.position = gameObject.transform.position; int direction = gameObject.transform.parent.gameObject.GetComponent <PlayerMovement>().lookAtLeft == true ? 1 : -1; Balle.GetComponent <Bullet>().SetWay(new Vector2(direction, 0)); if (isDoubleBullet) { GameObject Balle2; Balle2 = Instantiate(BalleType, null); Balle2.transform.position = gameObject.transform.position; int direction2 = gameObject.transform.parent.gameObject.GetComponent <PlayerMovement>().lookAtLeft == false ? 1 : -1; Balle2.GetComponent <Bullet>().SetWay(new Vector2(direction2, 0)); } if (isVerticalBullet) { GameObject Balle3; Balle3 = Instantiate(BalleType, null); Balle3.transform.position = gameObject.transform.position; Balle3.GetComponent <Bullet>().SetWay(new Vector2(0, 1)); } Balle.GetComponent <Bullet>().speed += ballSpeedBonus; Balle.GetComponent <Bullet>().sizeBonus += ballSizeBonus; Balle.GetComponent <Bullet>().bulletCrossing = isBulletCrossing; }
public void Draw(SpriteBatch g) { //Argent g.Draw(Ressources.Argent, new Rectangle((int)Position.X - 340, (int)Position.Y - 220, Ressources.Argent.Width / 3, Ressources.Argent.Height / 3), Color.LightGreen); g.DrawString(Ressources.TexteItalic, Argent.ToString(), new Vector2(Position.X - 300, Position.Y - 220), Color.LightGreen); //Balle if (!PersoSpeciaux) { if (Arme == 0) { Chargeur.Draw(g); g.DrawString(Ressources.TexteItalic, Balle.ToString(), new Vector2(Position.X - 300, Position.Y - 190), Color.OrangeRed); } else if (Arme == 1) { Chargeur.Draw(g); g.DrawString(Ressources.TexteItalic, Fleche.ToString(), new Vector2(Position.X - 300, Position.Y - 190), Color.OrangeRed); } else if (Arme == 2) { Chargeur.Draw(g); g.DrawString(Ressources.TexteItalic, BalleShotgun.ToString(), new Vector2(Position.X - 300, Position.Y - 190), Color.OrangeRed); } else if (Arme == 4) { Chargeur.Draw(g); g.DrawString(Ressources.TexteItalic, Convert.ToInt32(Laser).ToString(), new Vector2(Position.X - 300, Position.Y - 190), Color.OrangeRed); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { GameObject balle_GO = GameObject.Instantiate(m_Balle); Balle balle = balle_GO.GetComponent <Balle>(); balle.Shoot(transform.forward, 10f, 20); } }
// Update is called once per frame void Update() { Direction = new Vector3((Balle.position.x - PositionPrecedente.x), 0, (Balle.position.z - PositionPrecedente.z)).magnitude != 0 ? new Vector3((Balle.position.x - PositionPrecedente.x), 0, (Balle.position.z - PositionPrecedente.z)) : Direction; if (Input.GetKey(KeyCode.W)) { ForceRes = ForceRes + Direction.normalized * VitesseDAcceleration; // + Threashold/2 pour éviter de rester à 0 } if (Input.GetKey(KeyCode.S)) { ForceRes -= VitesseDeFreinage * Vector3.LerpUnclamped(Direction.normalized, Vector3.zero, VitesseDeFreinage / (VitesseDeFreinage + 1)); //if (Direction.magnitude > 0.5f) // ForceRes -= Direction; //else // Balle.GetComponent<Rigidbody>().constraints = (RigidbodyConstraints)10; //Freeze la position X et Z //Balle.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None; } if (Input.GetKey(KeyCode.A)) { ForceRes += DonnerVecteurNormal(Direction.normalized) * VitesseDeSteering; } if (Input.GetKey(KeyCode.D)) { ForceRes -= DonnerVecteurNormal(Direction.normalized) * VitesseDeSteering; } ForceRes = (!ToucheAuSol() ? ForceRes * 0.25f : ForceRes); if (ForceRes.magnitude > 0 || (PositionPrecedente - Balle.position).magnitude > Threashold) { PositionPrecedente.Set(Balle.position.x, 0, Balle.position.z); Balle.GetComponentInChildren <Rigidbody>().AddForce(ForceRes * VitesseDAcceleration * Time.deltaTime * 1000); } ForceRes = Vector3.zero; Debug.DrawLine(Balle.position, Balle.position + Direction, Color.blue, 3f); //Pour quitter if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
void Update() { //Player shoot if (Input.GetKeyDown(KeyCode.Space)) { GameObject ballGO; ballGO = GameObject.Instantiate(m_Balle_Prefab, transform.position, Quaternion.identity); Debug.Log(ballGO); Balle ball = ballGO.GetComponent <Balle>(); ball.Shoot(transform.right); } }
private void InstatiationBallFunction(GameObject balle) { if (m_ammo > 0) { //Avec la rotation d'un object, on le enfant pour qu'il garde sa direction GameObject ballGo = GameObject.Instantiate(balle, transform.position, Quaternion.identity); Balle ball = ballGo.GetComponent <Balle>(); ball.m_Player = this; m_ammo--; if (m_ammo == 0) { Debug.Log("Je dois recharger"); StartCoroutine("ShootDelay"); } } }
private void OnTriggerEnter2D(Collider2D c) { //print(name); if (c.gameObject.tag == "Balle") { if (aud != null) { aud.Play(); } Balle b = c.gameObject.GetComponent <Balle>(); b.SwapX(); //if(Maths.FastApproximate(b.MirrorY, 0f, .1f) && name != "Main") //{ // b.appliedForce = new Vector3(b.appliedForce.x, b.appliedForce.y + addedForce); //} //else //{ float f = Mathf.Abs(raquette.forceAddedToBall); if (f > .2f) { if (b.MirrorY != (int)Mathf.Sign(raquette.forceAddedToBall)) { b.MirrorY = (int)Mathf.Sign(raquette.forceAddedToBall); } } else { if (b.MirrorY == 0) { b.MirrorY = (int)Mathf.Sign(raquette.forceAddedToBall); } f = 1f; } b.appliedForce = new Vector3(b.appliedForce.x, f); //} } }
private void SpawnBalles(Balle b) { Vector3 v = b.t.position; v.y += .5f; GameObject g1 = pool.SpawnFromPool("extra_balle", v, Quaternion.identity); v.y -= 1f; GameObject g2 = pool.SpawnFromPool("extra_balle", v, Quaternion.identity); Balle b1 = g1.GetComponent <Balle>(); Balle b2 = g2.GetComponent <Balle>(); b1.MirrorY = 1; b2.MirrorY = -1; b1.appliedForce = b.appliedForce; b2.appliedForce = b.appliedForce; }
// Use this for initialization void Start() { timeSec = timeToLose; hud = GameObject.FindGameObjectWithTag("HUD").GetComponent <HudManager> (); balle = GameObject.FindGameObjectWithTag("Balle").GetComponent <Balle>(); gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> (); Xmin = gameZone.transform.position.x - gameZone.transform.localScale.x / 2; Xmax = gameZone.transform.position.x + gameZone.transform.localScale.x / 2; Ymin = gameZone.transform.position.y - gameZone.transform.localScale.y / 2; Ymax = gameZone.transform.position.y + gameZone.transform.localScale.y / 2; MenuGameOver.SetActive(false); changeCible(); source = GetComponent <AudioSource>(); hud.UpdateScoreText(0); textPlay.SetActive(false); textEdit.SetActive(true); launchModeEdit(); sonPlay = true; isGameActive = true; timePerdu = lostTime; }
//private void OnDrawGizmos() //{ // Bounds bounds = GetComponent<Collider2D>().bounds; // Gizmos.color = Color.red; // Gizmos.DrawSphere(bounds.min, .1f); // Gizmos.color = Color.green; // Gizmos.DrawSphere(bounds.max, .1f); // Gizmos.color = Color.yellow; // Gizmos.DrawSphere(new Vector3(bounds.min.x, bounds.max.y), .1f); // Gizmos.color = Color.blue; // Gizmos.DrawSphere(new Vector3(bounds.max.x, bounds.min.y), .1f); // Gizmos.color = Color.magenta; // Gizmos.DrawSphere(relativePosition, .1f); //} private void AddPowerUp(Balle b) { if (!givePowerUp) { return; } int alea = UnityEngine.Random.Range(1, 6); SpawnPrefabsOnPowerUp(alea); switch (alea) { case 1: AgrandirRaquettes(); break; //case 2: // RetrecirRaquettes(); // break; case 3: SpawnBalles(b); break; case 4: EnableProjectiles(); break; case 5: AddExtraLife(); break; default: break; } }
public void Initialize() { _playerInformations = new PlayerInformation("Joueur 1"); _levelHUD = new LevelHUD(this, _playerInformations); _palet = new Palet(this); _balle = new Balle(this); _balle.balleMissed += this.BalleMissed_Event; _bricksManager = new BricksManager(this); removeSpriteIndex = -1; canPlay = true; retry = false; allSprites.Clear(); _levelHUD.Initialize(); _palet.Initialize(); _balle.Initialize(); _bricksManager.Initialize(); // Le palet est en première position dans la collection // La balle à la deuxième position, cela permet de ne pas itérer toute la collection // pour trouver une collision allSprites.Insert(0, _palet); allSprites.Insert(1, _balle); foreach (Brick b in _bricksManager.ListBricks) { b.brickDestroyed += this.BrickAsDestroyed_Event; allSprites.Add(b); } foreach (Sprite s in allSprites) { s.Scale = spriteScale; } }
bool ToucheAuSol() { return(Balle.GetComponentInChildren <Saut>().toucheAuSol); }
// Use this for initialization void Start() { ball = GameObject.Find("Balle").GetComponent <Balle>(); GenerateMagnets(); }
private void OnTriggerEnter2D(Collider2D c) { if (c.gameObject.tag == "Balle") { Balle b = c.gameObject.GetComponent <Balle>(); if (b.checkNextCollision) { b.checkNextCollision = false; relativePosition = b.t.position; //print(b.MirrorX + ", " + b.MirrorY); ChangeDirection(relativePosition, ref b); //print(b.MirrorX + ", " + b.MirrorY); //StopCoroutine(b.CheckNextCollision()); b.checkNextCollision = true; //StartCoroutine(b.CheckNextCollision()); } if (isDestructible) { if (nbOfHitsBeforeDestroy == 0) { SpawnPrefabsOnDeath(); AddPowerUp(b); gameObject.SetActive(false); ScoreManager.instance.AddScore(scorePoints); } else { nbOfHitsBeforeDestroy--; SpawnPrefabsOnHit(); } } else { SpawnPrefabsOnHit(); } } else if (c.gameObject.tag == "Projectile") { if (isDestructible) { if (nbOfHitsBeforeDestroy == 0) { SpawnPrefabsOnDeath(); gameObject.SetActive(false); ScoreManager.instance.AddScore(scorePoints); } else { nbOfHitsBeforeDestroy--; SpawnPrefabsOnHit(); } } else { SpawnPrefabsOnHit(); } c.gameObject.SetActive(false); } }
/// <summary> /// Mise à jour de la logique du niveau /// </summary> /// <param name="gameTime">Temps de jeu</param> public void Update(GameTime gameTime) { if (retry) // On relance la partie { Initialize(); } if (canPlay) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { OnLevelisFinish(new LevelFinishEventArgs(LevelFinish.loose)); } if (allSprites.Count == 2) { OnLevelisFinish(new LevelFinishEventArgs(LevelFinish.win)); // Le joueur à gagné } _levelHUD.Update(gameTime); // Suppression des sprites non visibles for (int i = 0; i < allSprites.Count; i++) { if (!allSprites[i].Show) { Sprite s = allSprites[i]; allSprites.RemoveAt(i); s = null; } } #if WINDOWS_PHONE touchPoints = TouchPanel.GetState(); if (!_balle.Moving) { foreach (var point in touchPoints) { if (point.State == TouchLocationState.Pressed) { if (_palet.DestinationRectangle.Contains((int)point.Position.X, (int)point.Position.Y)) { _balle.Moving = true; } } } } #else // Lance la balle if (!_balle.Moving && Keyboard.GetState().IsKeyDown(Keys.Space)) { _balle.Moving = true; } #endif // --- // --- Mise à jour de la collection de sprite // --- foreach (Sprite s in allSprites) { if (s.Show) { if (s is Balle) { Balle b = (Balle)s; b.Update(gameTime, allSprites); } else { s.Update(gameTime); } } } } else // Fin de partie { #if WINDOWS_PHONE touchPoints = TouchPanel.GetState(); foreach (var point in touchPoints) { if (point.State == TouchLocationState.Pressed) { OnLevelisFinish(new LevelFinishEventArgs(LevelFinish.loose)); } } #else if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { retry = true; canPlay = true; } else if (Keyboard.GetState().IsKeyDown(Keys.Space)) { OnLevelisFinish(new LevelFinishEventArgs(LevelFinish.loose)); } #endif } }