// NOTE: gameEvent message might be different, change if necessary public void ProcessEvent(GameEventType eventType, GameEvent <object> gameEvent) { if (eventType == GameEventType.PlayerEvent) { switch (gameEvent.Message) { case "BOOSTER_UPWARDS": mA[1] = 1; break; case "BOOSTER_TO_LEFT": mA[0] = 1; taxiOrientation = TaxiOrientation.Left; break; case "BOOSTER_TO_RIGHT": mA[2] = 1; taxiOrientation = TaxiOrientation.Right; break; case "STOP_ACCELERATE_LEFT": mA[0] = 0; break; case "STOP_ACCELERATE_RIGHT": mA[2] = 0; break; case "STOP_ACCELERATE_UP": mA[1] = 0; break; } } }
public Player() { orientation = TaxiOrientation.TaxiOrientedLeft; state = TaxiBoosterState.TaxiBoosterOff; SpaceTaxiBus.GetBus().Subscribe(GameEventType.PlayerEvent, this); Shape = new DynamicShape(new Vec2F(), new Vec2F(0.0625f, 0.045f)); PlayerIsMoving = true; }
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); }
// get player image public IBaseImage GetPlayerImage(TaxiOrientation orientation, TaxiBoosterState state) { switch (orientation) { case TaxiOrientation.TaxiOrientedLeft: switch (state) { case TaxiBoosterState.TaxiBoosterOff: return(playerTaxiThrustNone); case TaxiBoosterState.TaxiBoosterHorizontal: return(playerTaxiThrustBack); case TaxiBoosterState.TaxiBoosterUp: return(playerTaxiThrustBottom); case TaxiBoosterState.TaxiBoosterUpAndHorizontal: return(playerTaxiThrustBottomBack); default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } break; case TaxiOrientation.TaxiOrientedRight: switch (state) { case TaxiBoosterState.TaxiBoosterOff: return(playerTaxiThrustNoneRight); case TaxiBoosterState.TaxiBoosterHorizontal: return(playerTaxiThrustBackRight); case TaxiBoosterState.TaxiBoosterUp: return(playerTaxiThrustBottomRight); case TaxiBoosterState.TaxiBoosterUpAndHorizontal: return(playerTaxiThrustBottomBackRight); default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } break; default: throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null); } }
public void ProcessEvent(GameEventType eventType, GameEvent <object> gameEvent) { if (eventType == GameEventType.PlayerEvent) { switch (gameEvent.Message) { case "BOOSTER_UPWARDS": StartAccelerationY(); break; case "STOP_ACCELERATE_UP": StopAccelerationY(); break; case "BOOSTER_TO_LEFT": accelerationX = -Constants.PLAYER_ACCELERATION_CONST_X; orientation = TaxiOrientation.TaxiOrientedLeft; StartAccelerationX(); break; case "STOP_ACCELERATE_LEFT": StopAccelerationX(); break; case "BOOSTER_TO_RIGHT": accelerationX = Constants.PLAYER_ACCELERATION_CONST_X; orientation = TaxiOrientation.TaxiOrientedRight; StartAccelerationX(); break; case "STOP_ACCELERATE_RIGHT": StopAccelerationX(); break; } } }
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]); }