예제 #1
0
    //Increases the score depending on which goal the ball hit.
    public IEnumerator IncreaseScore(string goal)
    {
        BlueCar blueCar = GameObject.FindObjectOfType <BlueCar>();
        RedCar  redCar  = GameObject.FindObjectOfType <RedCar>();
        Ball    ball    = GameObject.FindObjectOfType <Ball>();

        if (roundActive)
        {
            if (goal.Equals("left"))
            {
                LeftPlayerScore   = leftPlayerScore + 1;
                destroyAllBullets = true;
                Debug.Log("left scored a point");
            }
            if (goal.Equals("right"))
            {
                RightPlayerScore  = rightPlayerScore + 1;
                destroyAllBullets = true;
                Debug.Log("right scored a point");
            }
            blueCar.returnToStartPos();
            redCar.returnToStartPos();
            ball.returnToStartPos();
        }
        yield return(new WaitForSeconds(0.5f));

        destroyAllBullets = false;
    }
예제 #2
0
    //Depending on what the bullet collides with, it either destroys itself or decreases the health of the other player.
    //I also check for accidental friendly fire, and if the bullet is fired from the blue car it cannot damage the blue car.
    void OnCollisionEnter2D(Collision2D other)
    {
        BlueCar blueCar = GameObject.FindObjectOfType <BlueCar>();
        RedCar  redCar  = GameObject.FindObjectOfType <RedCar>();

        if (other.gameObject.tag == "Ball")
        {
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "Wall")
        {
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "BlueCar")
        {
            if (tag == "RedBullet")
            {
                blueCar.Health -= damage;
            }
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "RedCar")
        {
            if (tag == "BlueBullet")
            {
                redCar.Health -= damage;
            }
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "BlueBullet" || other.gameObject.tag == "RedBullet")
        {
            Destroy(gameObject);
            Destroy(other.gameObject);
        }
    }
예제 #3
0
파일: RaceHub.cs 프로젝트: Dannaz/CarRace
        public void startRace(string pathToMap)
        {
            ReadMapFromFile rSystem = new ReadMapFromFile(pathToMap);
            Map             m       = new Map(rSystem.map, rSystem.allStarts, rSystem.finish);

            serverCallDrawMap(rSystem.map);

            //blueCar
            CarFactory blueCar = new BlueCar(m);

            //greenCar
            CarFactory greenCar = new GreenCar(m);

            //redCar
            CarFactory redCar = new RedCar(m);

            //Добавление всех автомобилей в списки
            List <CarFactory> cars = new List <CarFactory>();

            cars.Add(blueCar);
            cars.Add(greenCar);
            cars.Add(redCar);

            createCars(cars);

            Thread[] _carThread = new Thread[3];
            //Пока все автомобиле не достигнут финиша
            while (!blueCar.finished && !greenCar.finished && !redCar.finished)
            {
                //Создаем список текущих позиций всех машин
                List <CarState> allCS = new List <CarState>();
                foreach (CarFactory car in cars)
                {
                    allCS.Add(car.cState);
                }

                foreach (CarFactory car in cars)
                {
                    //Инициализируем в классе каждой машины поле со списком текущих позиций всех машин.
                    car.allCS = allCS;
                    int i = 0;
                    _carThread[i] = new Thread(new ParameterizedThreadStart(car.goForOneStep));
                    _carThread[i].Start(m);
                    i++;
                }

                foreach (CarFactory car in cars)
                {
                    drawCar(car, m.map);
                }

                Thread.Sleep(500);
            }
        }
예제 #4
0
    private void Start()
    {
        SetNextResponsibility(FindObjectOfType <CarSpawner>());

        redCar = Instantiate(redCar);
        redCar.gameObject.SetActive(false);

        blueCar = Instantiate(blueCar);
        blueCar.gameObject.SetActive(false);

        greenCar = Instantiate(greenCar);
        greenCar.gameObject.SetActive(false);
    }
예제 #5
0
        private static void Main()
        {
            Car ferrari = new Ferrari();

            WriteCarData(ferrari);

            ferrari = new RedCar(ferrari);
            WriteCarData(ferrari);

            Car zonda = new Zonda();

            WriteCarData(zonda);

            zonda = new CarbonCar(zonda);
            WriteCarData(zonda);

            zonda = new RedCar(zonda);
            WriteCarData(zonda);
        }
예제 #6
0
    //whenever a car collides with the boost we want to fill that car's boost level, then we want to hide the boost pad
    private void OnTriggerEnter2D(Collider2D other)
    {
        GameManager gM      = GameObject.FindObjectOfType <GameManager>();
        BlueCar     blueCar = GameObject.FindObjectOfType <BlueCar>();
        RedCar      redCar  = GameObject.FindObjectOfType <RedCar>();

        if (boostActive)
        {
            if (other.tag == "BlueCar")
            {
                blueCar.carBoostLevel = 10;
                StartCoroutine(hideBoostPad());
            }
            if (other.tag == "RedCar")
            {
                redCar.carBoostLevel = 10;
                StartCoroutine(hideBoostPad());
            }
        }
    }
예제 #7
0
        static void Main(string[] args)
        {
            Plane car = new RedCar();

            car.fly();
        }