组装20 人物动画的简单实现 角色的地图坐标的走跑

Pic011
function TActor.Move(step: Integer): Boolean;
var
  prv, curstep, maxstep: Integer;

begin
  Result := False;

  prv := m_nCurrentFrame;

  if (m_nCurrentAction = ActWalk) or
    (m_nCurrentAction = ActRun) or
    (m_nCurrentAction = ActRushLeft) or
    (m_nCurrentAction = ActRushRight) then
  begin
    if (m_nCurrentFrame < m_nStartFrame) or (m_nCurrentFrame > m_nEndFrame) then
      m_nCurrentFrame := m_nStartFrame - 1;
    if m_nCurrentFrame < m_nEndFrame then
    begin
      Inc(m_nCurrentFrame);
      curstep := m_nCurrentFrame - m_nStartFrame + 1;
      maxstep := m_nEndFrame - m_nStartFrame + 1;
      Shift(m_btDir, m_nMoveStep, curstep, maxstep);
    end;

    if m_nCurrentFrame >= m_nEndFrame then
    begin
      m_boLockEndFrame := True;
      m_nCurrentAction := ActStand;

    end;
    Result := True;
  end;

  if prv <> m_nCurrentFrame then
  begin
    LoadSurface;
  end;

end;
procedure TActor.Shift(dir, step, cur, max: Integer);
var
  unx, uny, ss, v: Integer;
begin
  unx := UNITX * step;
  uny := UNITY * step;
  if cur > max then
    cur := max;
  m_nRx := m_nCurrX;
  m_nRy := m_nCurrY;
  ss := Round((max - cur - 1) / max) * step;
  case dir of
    DR_UP:
      begin
        ss := Round((max - cur) / max) * step;
        m_nShiftX := 0;
        m_nRy := m_nCurrY + ss;
        if ss = step then
          m_nShiftY := -Round(uny / max * cur)
        else
          m_nShiftY := Round(uny / max * (max - cur));
      end;

    DR_DOWN:
      begin
        if max >= 6 then
          v := 1
        else
          v := 0;
        ss := Round((max - cur - v) / max) * step;
        m_nShiftX := 0;
        m_nRy := m_nCurrY - ss;
        if ss = step then
          m_nShiftY := Round(uny / max * cur)
        else
          m_nShiftY := -Round(uny / max * (max - cur));
      end;

    DR_RIGHT:
      begin
        ss := Round((max - cur) / max) * step;
        m_nRx := m_nCurrX - ss; //实际地图坐标
        if ss = step then
          m_nShiftX := Round(unx / max * cur)
        else
          m_nShiftX := -Round(unx / max * (max - cur));
        m_nShiftY := 0;
      end;

    DR_LEFT:
      begin
        ss := Round((max - cur) / max) * step;
        m_nRx := m_nCurrX + ss;
        if ss = step then
          m_nShiftX := -Round(unx / max * cur)
        else
          m_nShiftX := Round(unx / max * (max - cur));
        m_nShiftY := 0;
      end;

    DR_UPRIGHT:
      begin
        if max >= 6 then //这里应该是对图像帧数微调
          v := 2
        else
          v := 0;
        ss := Round((max - cur + v) / max) * step;
        m_nRx := m_nCurrX - ss;
        m_nRy := m_nCurrY + ss;
        if ss = step then
        begin
          m_nShiftX := Round(unx / max * cur);
          m_nShiftY := -Round(uny / max * cur);
        end
        else
        begin
          m_nShiftX := -Round(unx / max * (max - cur));
          m_nShiftY := Round(uny / max * (max - cur));
        end;
      end;

    DR_DOWNRIGHT:
      begin
        if max >= 6 then
          v := 2
        else
          v := 0;
        ss := Round((max - cur - v) / max) * step;
        m_nRx := m_nCurrX - ss;
        m_nRy := m_nCurrY - ss;
        if ss = step then
        begin
          m_nShiftX := Round(unx / max * cur);
          m_nShiftY := Round(uny / max * cur);
        end
        else
        begin
          m_nShiftX := -Round(unx / max * (max - cur));
          m_nShiftY := -Round(uny / max * (max - cur));
        end;
      end;

    DR_DOWNLEFT:
      begin
        if max >= 6 then
          v := 2
        else
          v := 0;
        ss := Round((max - cur - v) / max) * step;
        m_nRx := m_nCurrX + ss;
        m_nRy := m_nCurrY - ss;
        if ss = step then
        begin
          m_nShiftX := -Round(unx / max * cur);
          m_nShiftY := Round(uny / max * cur);
        end
        else
        begin
          m_nShiftX := Round(unx / max * (max - cur));
          m_nShiftY := -Round(uny / max * (max - cur));
        end;
      end;

    DR_UPLEFT:
      begin
        if max >= 6 then
          v := 2
        else
          v := 0;
        ss := Round((max - cur + v) / max) * step;
        m_nRx := m_nCurrX + ss;
        m_nRy := m_nCurrY + ss;
        if ss = step then
        begin
          m_nShiftX := -Round(unx / max * cur);
          m_nShiftY := -Round(uny / max * cur);
        end
        else
        begin
          m_nShiftX := Round(unx / max * (max - cur));
          m_nShiftY := Round(uny / max * (max - cur));
        end;
      end;

  end;

end;


procedure TPlayScene.PlayScene(MSurface: TDirectDrawSurface);
var
  movetick: Boolean;
begin

  movetick := False;
  if GetTickCount - m_dwMoveTime >= 120 then
  begin
    m_dwMoveTime := GetTickCount;
    movetick := True;
  end;

  if movetick then
  begin
    with Actor1 do
    begin
      if not Move(1) then
        Run;
    end;

  end;

  with Actor1 do
  DrawChr(MSurface,
        m_nRx * UNITX + m_nShiftX,
        m_nRy * UNITY + m_nShiftY);


  if MagicEff1 <> nil then
  begin
    MagicEff1.Run;
    MagicEff1.DrawEff(MSurface);
  end;
end;

 

 

问题:

1,好像间隔都给固定到120 了, 有什么办法解决吗?

2,DEBUG没有用上,

3,下一步,满格角色,做个角色列表,学习DEBUG

4,这个程序很占CPU

posted @ 2025-08-15 22:20  D7mir  阅读(8)  评论(0)    收藏  举报