void Game_Character::Move(int dir) { int dx = (dir == Right || dir == UpRight || dir == DownRight) - (dir == Left || dir == DownLeft || dir == UpLeft); int dy = (dir == Down || dir == DownRight || dir == DownLeft) - (dir == Up || dir == UpRight || dir == UpLeft); SetDirection(dir); if (!(IsDirectionFixed() || IsFacingLocked())) { if (dir > 3) // Diagonal SetSpriteDirection(GetSpriteDirection() % 2 ? -dx + 2 : dy + 1); else SetSpriteDirection(dir); } if (jumping) { jump_plus_x += dx; jump_plus_y += dy; return; } move_failed = !IsPassable(GetX(), GetY(), dir); if (move_failed) { if (!CheckEventTriggerTouch(Game_Map::RoundX(GetX() + dx), Game_Map::RoundY(GetY() + dy))) return; } else { SetX(Game_Map::RoundX(GetX() + dx)); SetY(Game_Map::RoundY(GetY() + dy)); remaining_step = SCREEN_TILE_WIDTH; BeginMove(); } stop_count = 0; max_stop_count = (GetMoveFrequency() > 7) ? 0 : pow(2.0, 9 - GetMoveFrequency()); }
void Game_Character::MoveUpRight() { if (!IsDirectionFixed()) { if (GetDirection() % 2) { TurnRight(); } else { TurnUp(); } } if (jumping) { jump_plus_x++; jump_plus_y--; return; } if ((IsPassable(GetX(), GetY(), RPG::EventPage::Direction_right) && IsPassable(GetX() + 1, GetY(), RPG::EventPage::Direction_up)) || (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_up) && IsPassable(GetX(), GetY() - 1, RPG::EventPage::Direction_right))) { SetX(GetX() + 1); SetY(GetY() - 1); BeginMove(); stop_count = 0; move_failed = false; } }
void Game_Character::MoveDownLeft() { if (!IsDirectionFixed()) { if (GetDirection() % 2) { TurnLeft(); } else { TurnDown(); } } if (jumping) { jump_plus_x--; jump_plus_y++; return; } if ((IsPassable(GetX(), GetY(), RPG::EventPage::Direction_left) && IsPassable(GetX() - 1, GetY(), RPG::EventPage::Direction_down)) || (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_down) && IsPassable(GetX(), GetY() + 1, RPG::EventPage::Direction_left))) { SetX(GetX() - 1); SetY(GetY() + 1); BeginMove(); stop_count = 0; move_failed = false; } }
Edge::Edge() { m_anim.setTargetObject(this); m_anim.setPropertyName("pos"); connect(&m_anim,SIGNAL(finished()),this,SLOT(BeginMove())); }
Barrier::Barrier() { m_anim.setTargetObject(this); m_anim.setPropertyName("pos"); isMain = false; connect(&m_anim,SIGNAL(finished()),this,SLOT(BeginMove())); }
void StepperMotor::Start (Direction direction) { this->direction = direction; accelerationSteps = (uint32_t) (0.5f * (maxFrequency * accelerationTime)); decelerationLimit = -1; stepLimit = -1; BeginMove (); }
void StepperMotor::Move (Direction direction, uint32_t steps) { if (steps == 0) { if (MoveCompleted != nullptr) { EventArgs args; MoveCompleted (this, args); } return; // TODO fire move completed event. } uint32_t accelerationLimit; accelerationSteps = (uint32_t) (0.5f * (maxFrequency * accelerationTime)); uint32_t decelerationSteps = (uint32_t) (0.5f * (maxFrequency * decelerationTime)); if (accelerationGradient == fabs (decelerationGradient)) { accelerationLimit = steps / 2; } else { accelerationLimit = (uint32_t) ((steps * fabs (decelerationGradient)) / (accelerationGradient + fabs (decelerationGradient))); } if (accelerationSteps <= accelerationLimit) { fullSpeed = true; decelerationLimit = steps - decelerationSteps; } else { fullSpeed = false; // check this. decelerationLimit = steps + -(steps - accelerationLimit); } stepLimit = steps; this->direction = direction; BeginMove (); }
void Game_Character::MoveUp() { if (!IsDirectionFixed()) TurnUp(); if (jumping) { jump_plus_y--; return; } if (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_up)) { SetY(GetY() - 1); BeginMove(); stop_count = 0; move_failed = false; } else { CheckEventTriggerTouch(GetX(), GetY() - 1); move_failed = true; } }