Ejemplo n.º 1
22
        /// <summary>
        /// Initializes a new Player
        /// </summary>
        /// <param name="id">The id of the player</param>
        /// <param name="playerName">The name of the player</param>
        /// <param name="startPos">The start position of the car</param>
        /// <param name="startRot">The start rotation of the car</param>
        /// <param name="playerImage">The image used as a car</param>
        /// <param name="playerKeysToUse">All the keys that work with this player</param>
        public Player(string id,string playerName, Point startPos, int startRot, Bitmap playerImage, List<Keys> playerKeysToUse)
        {
            this.name = id;
            this.playerName = playerName;

            //Assign a car to each player
            this.playerCar = new Car(int.Parse(name),startPos,startRot,playerImage,0.25f,0.25f);
            this.playerKeys = playerKeysToUse;

            //Register with graphicsEngine
            GraphicsEngine.AddAsset(new Asset(++GraphicsEngine.assetsToRender,playerCar.image,playerCar.pos,playerCar.rot,playerCar.scaleX,playerCar.scaleY),RenderType.Player);

            //Player control timer
            Timer playerTimer = new Timer();
            playerTimer.Interval = 1;
            playerTimer.Tick += Timer_Tick;
            playerTimer.Start();

            //Player event timer
            Timer EventTimer = new Timer();
            EventTimer.Interval = 10;
            EventTimer.Tick += Event_Tick;
            EventTimer.Start();
        }
Ejemplo n.º 2
0
 public override void OnKeyUp(Car car, KeyEventArgs e)
 {
     if (e.KeyCode == car.up)
     {
         car.currentState = new DeccelerationState();
     }
 }
Ejemplo n.º 3
0
 public override void OnKeyDown(Car car, KeyEventArgs e)
 {
     if (e.KeyCode == car.down)
     {
         car.currentState = new BreakingState();
     }
 }
Ejemplo n.º 4
0
 public override void Update(Car car)
 {
     Console.WriteLine("IdleState");
     if (car.speed != 0)
     {
         car.speed = 0;
     }
 }
Ejemplo n.º 5
0
 public override void Update(Car car)
 {
     Console.WriteLine("DrivingState");
     car.fuel -= 0.5;
     if (car.speed != car.maxSpeed)
     {
         car.speed = car.maxSpeed;
     }
 }
Ejemplo n.º 6
0
 public Player(Control control, ITexture2DHolder carImage, Vector2 position, float startRotation)
 {
     IsHuman = true;
     Control = control;
     Car = new Car(carImage, position);
     Car.X = position.X;
     Car.Y = position.Y;
     Car.Rotation = startRotation;
 }
Ejemplo n.º 7
0
 public override void Update(Car car)
 {
     Console.WriteLine("BreakingState");
     if (car.speed > 0)
     {
         car.speed -= 0.20;
     }
     else
     {
         car.currentState = new IdleState();
     }
 }
Ejemplo n.º 8
0
 public override void Update(Car car)
 {
     Console.WriteLine("AccelerationState");
     car.fuel -= 0.05;
     if (car.speed < car.maxSpeed)
     {
         car.speed += 0.05;
     }
     else
     {
         car.currentState = new DrivingState();
     }
 }
Ejemplo n.º 9
0
 public override void Update(Car car)
 {
     Console.WriteLine("DeccelerationState");
     car.fuel -= 0.5;
     if (car.speed > 0)
     {
         car.speed -= 0.05;
     }
     else
     {
         car.currentState = new IdleState();
     }
 }
Ejemplo n.º 10
0
        public override void OnKeyDown(Car car,KeyEventArgs e)
        {
            if (e.KeyCode == car.up)
            {
                car.currentState = new AccelerationState();
            } else if (e.KeyCode == car.down)
            {
                // TODO: create driving backwards compatibility (accelerate backwards)
                return;
            } else if (e.KeyCode == car.left)
            {

            }
        }
Ejemplo n.º 11
0
        public Game()
        {
            InitializeComponent();

            WinHeight = Height;
            WinWidth = Width;

            // create a car and add to cars list
            Car car1 = new Car(320, 250, Cars.blue, Keys.Up, Keys.Down, Keys.Left, Keys.Right);
            cars.Add(car1);
            // check if multiplayer is set
            if (SettingsForm.MULTIPLAYER)
            {
                Car car2 = new Car(100, 100, Cars.green, Keys.W, Keys.S, Keys.A, Keys.D);
                cars.Add(car2);
            }
        }
Ejemplo n.º 12
0
 public abstract void Update(Car car);
Ejemplo n.º 13
0
 public abstract void OnKeyUp(Car car,KeyEventArgs e);
Ejemplo n.º 14
0
 public abstract void OnKeyPress(Car car,KeyEventArgs e);
Ejemplo n.º 15
0
 public override void OnKeyPress(Car car, KeyEventArgs e)
 {
     return;
 }