예제 #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();
        }
예제 #2
0
 public override void OnKeyUp(Car car, KeyEventArgs e)
 {
     if (e.KeyCode == car.up)
     {
         car.currentState = new DeccelerationState();
     }
 }
예제 #3
0
 public override void OnKeyDown(Car car, KeyEventArgs e)
 {
     if (e.KeyCode == car.down)
     {
         car.currentState = new BreakingState();
     }
 }
예제 #4
0
 public override void Update(Car car)
 {
     Console.WriteLine("IdleState");
     if (car.speed != 0)
     {
         car.speed = 0;
     }
 }
예제 #5
0
 public override void Update(Car car)
 {
     Console.WriteLine("DrivingState");
     car.fuel -= 0.5;
     if (car.speed != car.maxSpeed)
     {
         car.speed = car.maxSpeed;
     }
 }
예제 #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;
 }
예제 #7
0
 public override void Update(Car car)
 {
     Console.WriteLine("BreakingState");
     if (car.speed > 0)
     {
         car.speed -= 0.20;
     }
     else
     {
         car.currentState = new IdleState();
     }
 }
예제 #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();
     }
 }
예제 #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();
     }
 }
예제 #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)
            {

            }
        }
예제 #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);
            }
        }
예제 #12
0
 public abstract void Update(Car car);
예제 #13
0
 public abstract void OnKeyUp(Car car,KeyEventArgs e);
예제 #14
0
 public abstract void OnKeyPress(Car car,KeyEventArgs e);
예제 #15
0
 public override void OnKeyPress(Car car, KeyEventArgs e)
 {
     return;
 }