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