/// <summary> /// Checks the currently pressed keys and changes the acceleration vector accordingly /// </summary> private void ApplyAcceleration() { var shape = Shape.AsDynamicShape(); if (mA[0] == 1 && mA[1] == 0 && mA[2] == 0) { Force.ApplyForce(new Vec2F(-Constants.TAXI_ACCEL_X, 0f), shape); taxiDirection = TaxiDirection.Left; } else if (mA[0] == 1 && mA[1] == 1 && mA[2] == 0) { Force.ApplyForce(new Vec2F(-Constants.TAXI_ACCEL_X, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.LeftAndUp; } else if (mA[0] == 0 && mA[1] == 1 && mA[2] == 0) { Force.ApplyForce(new Vec2F(0f, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.Up; } else if (mA[0] == 0 && mA[1] == 1 && mA[2] == 1) { Force.ApplyForce(new Vec2F(Constants.TAXI_ACCEL_X, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.RightAndUp; } else if (mA[0] == 0 && mA[1] == 0 && mA[2] == 1) { Force.ApplyForce(new Vec2F(Constants.TAXI_ACCEL_X, 0f), shape); taxiDirection = TaxiDirection.Right; } else if (mA[0] == 0 && mA[1] == 0 && mA[2] == 0) { taxiDirection = TaxiDirection.None; } Force.ApplyGravity(shape.AsDynamicShape()); }
private int[] mA; //input key array. 0 = left, 1 = up, 2 = right public Player(DynamicShape shape, IBaseImage image) : base(shape, image) { mA = new int[3]; taxiOrientation = TaxiOrientation.Left; taxiDirection = TaxiDirection.None; imageContainer = ImageContainer.GetInstance(); Shape = new DynamicShape( new Vec2F(), new Vec2F(Constants.EXTENT_X * 2, Constants.EXTENT_Y)); Image = imageContainer.GetPlayerStride(taxiOrientation, taxiDirection); SpaceTaxiBus.GetBus().Subscribe(GameEventType.PlayerEvent, this); }
public void GetPlayerStridesReturnsImageStrideForAllPossibleDirections( TaxiOrientation orientation, TaxiDirection direction) { //if test doesn't fail, the images were successfully retrieved from the ImageContainer var strides = imageContainer.GetPlayerStride(orientation, direction); }
/// <summary> /// Returns an IBaseImage of the player taxi depending on the TaxiOrientation and /// TaxiDirection parameters given /// </summary> /// <param name="orientation"></param> /// <param name="direction"></param> /// <returns>IBaseImage of player taxi</returns> public IBaseImage GetPlayerStride(TaxiOrientation orientation, TaxiDirection direction) { return(playerStrides[(int)orientation, (int)direction]); }