unit Sprites;

interface

uses DXSprite,DXCLass,DXDraws,Windows,DirectX ;

type

//This is the new class
TSpriteMan = class(TImageSprite)
  public
    VelocityX : Integer;
    VelocityY : Integer;
    Angle: Integer;

    ButtonUp: Boolean;
    ButtonDown: Boolean;

    function Anglechange();
    procedure DoMove(MoveCount: Integer); override;
    procedure DoDraw(); override;
    procedure Buttons();

end;

implementation

procedure TSpriteMan.Buttons();
begin
  if isleft in gameform.input.states then    
    anglechange(left);
  if isright in gameform.input.states then
    anglechange(right);
  if isup in gameform.input.states then
    ButtonUp := true;
  is isDown in gameform.input.states then
    ButtonDown := true;
end;

procedure TSpriteMan.DoMove(MoveCount: Integer);
begin
  Buttons;
  if ButtonUp then
  begin
    x := x + VelocityX;
    y := y + VelocityY;
  end;
  if ButtonDown then
  begin
    x := x - VelocityX;
    y := y - VelocityY;
  end;
end;

procedure TSpriteMan.DoDraw();
var
  TempX: Integer;
  TempY: Integer;
begin
  TempX := Round(X);
  TempY := Round(Y);
  Image.DrawRotate(GameForm.DXDraw.Surface, x, y, Width, Height, 0, 0.5, 0.5, angle);      
end;

function TSpriteMan.Anglechange(side: string);
begin
  case side of
    left:
    case Angle of
      0..63 :
        Velocityx := Velocityx - change;
        Velocityy := Velocityy + change;
      64..127 :
        Velocityx := Velocityx + change;
        Velocityy := Velocityy + change;
      128..194 :
        Velocityx := Velocityx + change;
        Velocityy := Velocityy - change;
      195..256 :
        Velocityx := Velocityx - change;
        Velocityy := Velocityy - change;
    end;
    right:
    case Angle of
      0..63 :
        Velocityx := Velocityx + change;
        Velocityy := Velocityy - change;
      64..127 :
        Velocityx := Velocityx - change;
        Velocityy := Velocityy - change;
      128..194 :
        Velocityx := Velocityx - change;
        Velocityy := Velocityy + change;
      195..256 :
        Velocityx := Velocityx + change;
        Velocityy := Velocityy + change;
    end;
  end;
  if angle = 0 then
  begin
    Velocityx := 0;
    Velocityy := Velocitymax;
  end;
  if angle = 64 then
  begin
    Velocityx := Velocitymax;
    Velocityy := 0;
  end;
  if angle = 128 then
  begin
    Velocityx := 0;
    Velocityy := Velocitymin;
  end;
  if angle = 192 then
  begin
    Velocityx := Velocitymin;
    Velocityy := 0;
  end;
end;


end.