Exemple #1
0
        private void Events_KeyboardDown(object sender, KeyboardEventArgs e)
        {
            this.pressedKey = e.Key;
            switch (e.Key)
            {
                case Key.Escape:
                case Key.Q:
                    Events.QuitApplication();
                    break;
                case Key.A:
                    var box = Box.Create(this.world, this.mousePos.X, this.mousePos.Y, 0.1f, 0.1f, 1f);
                    box.Color = Helper.GetRandomColor();
                    this.worldObjects.Add(box);
                    break;
                case Key.C:
                    var circle = Circle.Create(world, this.mousePos.X, this.mousePos.Y, 0.3f, 1.0f);
                    circle.Color = Helper.GetRandomColor();
                    this.worldObjects.Add(circle);

                    break;
                case Key.R:
                    var car = Car.Create(this.world, this.mousePos.X, this.mousePos.Y, 0.4f, 0.8f);
                    this.worldObjects.Add(car);
                    this.lastCar = car;
                    break;
                    /*  case Key.LeftArrow:
                    if (this.lastCar != null)
                    {
                        this.lastCar.Accelerate();
                    }
                    break;
                case Key.RightArrow:
                    if (this.lastCar != null)
                    {
                        this.lastCar.Deccelerate();
                    }
                    break;*/
            }
        }
Exemple #2
0
        public static Car Create(World world, float positionX, float positionY, float width, float height)
        {
            float poleHeightCarHeightRatio = 0.7f;

            var car = new Car();
            car.Width = width;
            car.Height = height;

            float carHeight = height * (1.0f - poleHeightCarHeightRatio);
            float bodyHeightWheelHeightRatio = 0.4f;
            float bodyHeight = carHeight * bodyHeightWheelHeightRatio;
            float wheelRadius = carHeight - bodyHeight;
            float bodyDensity = 1.5f;
            float wheelDensity = 0.4f;
            float wheelFriction = 0.9f;
            var poleDensity = 0.2f;

            float poleWidth = car.Width / 10.0f;
            float poleHeight = car.Height * poleHeightCarHeightRatio;

            car.CarBody = Box.Create(world, positionX, positionY, car.Width, bodyHeight, bodyDensity);
            car.FrontWheel = Circle.Create(
                    world,
                    positionX - car.Width + wheelRadius / 2.0f,
                    positionY - car.CarBody.Height,
                    wheelRadius,
                    wheelDensity,
                    wheelFriction);
            car.BackWheel = Circle.Create(
                    world,
                    positionX + car.Width - wheelRadius / 2.0f,
                    positionY - car.CarBody.Height,
                    wheelRadius,
                    wheelDensity,
                    wheelFriction);
            car.Pole = Box.Create(
                    world, positionX, positionY + bodyHeight*1f + poleHeight, poleWidth, poleHeight, poleDensity);

            car.BodyColor = Helper.GetRandomColor();
            car.WheelsColor = Helper.GetRandomColor();
            car.Pole.Color = Helper.GetRandomColor();
            car.CreatePhysics(world,positionX, positionY);
            return car;
        }
Exemple #3
0
 private void Draw(Car car)
 {
     Draw(car.CarBody);
     Draw(car.FrontWheel);
     Draw(car.BackWheel);
     Draw(car.Pole);
 }