if absX<4 then begin l:=false; r:=false; end; if absY<4 then begin u:=false; d:=false; end; {如果绝对距离已经小于四个象素,则认为已经到达目的地}
if u and l and not d and not r then MoveTo(MoveCount,DrUpLeft); if u and r and not l and not d then MoveTo(MoveCount,DrUpRight); if d and l and not r and not u then MoveTo(MoveCount,DrDownLeft); if d and r and not u and not l then MoveTo(MoveCount,DrDownRight); if d and not l and not r and not u then MoveTo(MoveCount,DrDown); if u and not l and not r and not d then MoveTo(MoveCount,DrUp); if l and not u and not r and not d then MoveTo(MoveCount,DrLeft); if r and not l and not u and not d then MoveTo(MoveCount,DrRight); {根据目的地来判断运动的方向,从而播放相应方向运动的动画}
Collision; {检测碰撞} Engine.X := -X+Engine.Width div 2 - Width div 2; Engine.Y := -Y+Engine.Height div 2 - Height div 2; {移动引擎,从而是游戏人物处于舞台的正中央} end;
procedure TMainForm.DXTimerTimer(Sender: TObject; LagCount: Integer); begin if not DXDraw.CanDraw then exit; {检测DXDraw是否可以画,否则退出} DXInput.Update; {捕捉各类设备输入,这里我们用来检测鼠标的输入}
LagCount := 1000 div 60; {用来控制整个游戏运行速度的参数} DXSpriteEngine.Move(LagCount); DXSpriteEngine.Dead;