public bool AvailableToDigg(CharacterAction nextMove) { var player = _playerModule.GetModule <Player>(); var x = player.X; var y = player.Y; switch (nextMove) { case CharacterAction.DigLeft: if (y < _cellModule.Bottom && x > 0 && _cellModule.Get(x - 1, y + 1).IsNotHiddenBlock&& _cellModule.Get(x - 1, y).IsEmpty&& !_coinModule.IsCoin(x - 1, y)) { return(true); } break; case CharacterAction.DigRight: if (y < _cellModule.Bottom && x < _cellModule.Right && _cellModule.Get(x + 1, y + 1).IsNotHiddenBlock&& _cellModule.Get(x + 1, y).IsEmpty&& !_coinModule.IsCoin(x + 1, y)) { return(true); } break; } return(false); }
public void MoveStep(CharacterAction action, bool stayCurrPos) { var x = X; var xOffset = XOffset; var y = Y; var yOffset = YOffset; //var curShape = _runner.shape; //var newShape = curShape; var centerX = CharacterAction.Stop; var centerY = centerX; switch (action) { case CharacterAction.DigLeft: case CharacterAction.DigRight: xOffset = 0; yOffset = 0; break; case CharacterAction.Up: case CharacterAction.Down: case CharacterAction.Fall: if (xOffset > 0) { centerX = CharacterAction.Left; } else if (xOffset < 0) { centerX = CharacterAction.Right; } break; case CharacterAction.Left: case CharacterAction.Right: if (yOffset > 0) { centerY = CharacterAction.Up; } else if (yOffset < 0) { centerY = CharacterAction.Down; } break; } var curToken = _cellModule[x, y].Type; if (action == CharacterAction.Up) { yOffset -= GetModifiedValue(CharacterProperty.YMove);//_runner.yMove; if (stayCurrPos && yOffset < 0) { yOffset = 0; //stay on current position } else if (yOffset < -_cellModule.H2) { //move to y-1 position //if (curToken == CellType.Block || curToken == CellType.HLadr) curToken = CellType.Empty; //in hole or hide laddr //map[x, y].Act = curToken; //runner move to [x][y-1], so set [x][y].act to previous state y--; yOffset = _cellModule.TileH + yOffset; //if (map[x, y].Act == CubePlatformType.Guard && AI.Guard.guardAlive(x, y)) setRunnerDead(); //collision if (_guardModule.IsGuardAlive(x, y)) { Dead(); } } //newShape = "RunUpDn"; } if (centerY == CharacterAction.Up) { yOffset -= GetModifiedValue(CharacterProperty.YMove); if (yOffset < 0) { yOffset = 0; //move to center Y } } if (action == CharacterAction.Down || action == CharacterAction.Fall) { var holdOnBar = 0; if (curToken == CellType.RopeBar) { if (yOffset < 0) { holdOnBar = 1; } else if (action == CharacterAction.Down && y < _cellModule.Bottom && _cellModule[x, y + 1].Type != CellType.Ladder) { action = CharacterAction.Fall; //shape fixed: 2014/03/27 } } yOffset += GetModifiedValue(CharacterProperty.YMove); if (holdOnBar == 1 && yOffset >= 0) { yOffset = 0; //fall and hold on bar action = CharacterAction.FallBar; } if (stayCurrPos && yOffset > 0) { yOffset = 0; //stay on current position } else if (yOffset > _cellModule.H2) { //move to y+1 position //if (curToken == CubePlatformType.Block || curToken == CubePlatformType.HLadr) curToken = CubePlatformType.Empty; //in hole or hide laddr //map[x][y].Act = curToken; //runner move to [x][y+1], so set [x][y].act to previous state y++; yOffset = yOffset - _cellModule.TileH; if (_guardModule.IsGuardAlive(x, y)) { Dead(); //collision } } if (action == CharacterAction.Down) { //newShape = "RunUpDn"; _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.RunUpDn)); } else { //ACT_FALL or ACT_FALL_BAR if (y < _cellModule.Bottom && _guardModule.IsGuardAt(x, y + 1)) { //over guard //don't collision var guard = _guardModule.GetGuardAt(x, y + 1); //AI.Guard.getGuardId(x, y + 1); if (yOffset > guard.YOffset) { yOffset = guard.YOffset; } } if (action == CharacterAction.FallBar) { if (LastMoveAction == CharacterAction.Left) { _eventDispatcher.DispatchEvent( new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.BarLeft)); //newShape = "BarLeft"); } else { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.BarRight)); //newShape = "BarRight"; } } else { if (LastMoveAction == CharacterAction.Left) { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.FallLeft)); //newShape = "FallLeft"; } else { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.FallRight)); } //else newShape = "FallRight"; } } } if (centerY == CharacterAction.Down) { yOffset += GetModifiedValue(CharacterProperty.YMove); if (yOffset > 0) { yOffset = 0; //move to center Y } } if (action == CharacterAction.Left) { xOffset -= GetModifiedValue(CharacterProperty.XMove); if (stayCurrPos && xOffset < 0) { xOffset = 0; //stay on current position } else if (xOffset < -_cellModule.W2) { //move to x-1 position //if (curToken == CubePlatformType.Block || curToken == CubePlatformType.HLadr) curToken = CubePlatformType.Empty; //in hole or hide laddr //map[x][y].Act = curToken; //runner move to [x-1][y], so set [x][y].act to previous state x--; xOffset = _cellModule.TileW + xOffset; if (_guardModule.IsGuardAlive(x, y)) { Dead(); //collision } } if (curToken == CellType.RopeBar) { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.BarLeft)); //newShape = "BarLeft"; } else { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.RunLeft)); //else newShape = "RunLeft"; } } if (centerX == CharacterAction.Left) { xOffset -= GetModifiedValue(CharacterProperty.XMove); if (xOffset < 0) { xOffset = 0; //move to center X } } if (action == CharacterAction.Right) { xOffset += GetModifiedValue(CharacterProperty.XMove); if (stayCurrPos && xOffset > 0) { xOffset = 0; //stay on current position } else if (xOffset > _cellModule.W2) { //move to x+1 position //if (curToken == CubePlatformType.Block || curToken == CubePlatformType.HLadr) curToken = CubePlatformType.Empty; //in hole or hide laddr //map[x][y].Act = curToken; //runner move to [x+1][y], so set [x][y].act to previous state x++; xOffset = xOffset - _cellModule.TileW; if (_guardModule.IsGuardAlive(x, y)) { Dead(); //collision } } if (curToken == CellType.RopeBar) { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.BarRight)); //newShape = "BarRight"; } else { _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.RunRight)); //else newShape = "runRight"; } } if (centerX == CharacterAction.Right) { xOffset += GetModifiedValue(CharacterProperty.XMove); if (xOffset > 0) { xOffset = 0; //move to center X } } if (action == CharacterAction.Stop) { if (Action == CharacterAction.Fall) { _soundModule.StopFall(); _soundModule.PlayDown(); } if (Action != CharacterAction.Stop) { //_runner.sprite.stop(); _eventDispatcher.DispatchEvent(new PlayerAnimationEvent(PlayerAnimationEvent.AnimationEvent.Stop)); Action = CharacterAction.Stop; } } else { //_runner.sprite.x = (x + xOffset); //_runner.sprite.y = (y + yOffset); SetPosition(x, y, xOffset, yOffset); //if (curShape != newShape) //{ //_runner.sprite.gotoAndPlay(newShape); //_runner.shape = newShape; //} if (action != Action) { if (Action == CharacterAction.Fall) { _soundModule.StopFall(); _soundModule.PlayDown(); } else if (action == CharacterAction.Fall) { _soundModule.PlayFall(); } //_runner.sprite.play(); } if (action == CharacterAction.Left || action == CharacterAction.Right) { LastMoveAction = action; } Action = action; } //map[x][y].Act = CubePlatformType.Runner; // Check runner to get gold (MAX MOVE MUST < H4 & W4) if (_coinModule.IsCoin(x, y) && ((xOffset == 0f && yOffset >= 0 && yOffset < _cellModule.H4) || (yOffset == 0f && xOffset >= 0 && xOffset < _cellModule.W4) || (y < _cellModule.Bottom && _cellModule.Get(x, y + 1).Type == CellType.Ladder && yOffset < _cellModule.H4) // gold above laddr ) ) { _coinModule.RemoveAt(x, y); _soundModule.PlayGetGold(); //debug("gold = " + goldCount); //if (playMode == PLAY_CLASSIC || playMode == PLAY_AUTO || playMode == PLAY_DEMO) //{ // drawScore(SCORE_GET_GOLD); //} //else //{ //for modern mode , edit mode //AI.drawGold(1); //get gold //} } if (_coinModule.IsEmpty && !_coinModule.IsCompleted) { _cellModule.ShowHiddenLadder(); } //check collision with guard ! СheckCollision(x, y); }