unit MP;

interface

uses
  objet,
  essai_map,
  gameplay,
  System.Drawing,
  System.Windows.Forms,
  Microsoft.DirectX,
  Microsoft.DirectX.DirectInput,
  Microsoft.DirectX.Direct3D;

type
  TSurface = record
    hd, bd, hg, bg : char;
  end;

  TV_vitesse = record
    angle, norme : real;
  end;
  TMP = class
    private
      surface : TSurface;
      i : real;
    public
      vv : TV_vitesse;
      constructor create;
      procedure new_coordonee(  var move : TMove ;  var Touches:TTouches ; vecteur: array of string);
      procedure get_surface ( move : TMove ; vecteur: array of string);
      procedure deplacement(var move : TMove ; touches : TTouches);
      procedure saut(var move : TMove);

  end;

implementation

constructor TMP.create;
begin
  inherited;
end;

procedure TMP.new_coordonee(var  move : TMove ; var Touches:TTouches ; vecteur: array of string );
begin
  if (move.x <= 0.5) or (move.x >= TMap.taille-0.5 ) or (move.z <= 0.5) or (move.z >= TMap.taille-0.5 )or (move.y < 0) then
        move.y := move.y-0.2
  else
  begin

  get_surface(move , vecteur);
  if move.saut or touches.saut then
    saut(move)
  else
  if  (surface.hd >= '1') or (surface.bd >= '1') or (surface.hg >= '1') or (surface.bg >= '1') then
    deplacement(move , touches)


  else
    move.y := move.y-0.2;
  end;

  if Touches.R then
  begin
    move.angle := 1.57;
    move.x := 3;
    move.y := 0;
    move.z := 3;
    move.saut := false;
  end;

end;

procedure TMP.get_surface ( move : TMove ; vecteur: array of string);
begin
  surface.hd := vecteur[trunc(move.z+0.5)][trunc(1+move.x+0.5)];
  surface.bd := vecteur[trunc(move.z+0.5)][trunc(1+move.x-0.5)];
  surface.hg := vecteur[trunc(move.z-0.5)][trunc(1+move.x+0.5)];
  surface.bg := vecteur[trunc(move.z-0.5)][trunc(1+move.x-0.5)];
end;

procedure TMP.deplacement(var move : TMove ; touches : TTouches);
begin
    if Touches.Dr then
      move.angle := move.angle - 0.1;
    if Touches.Ga then
      move.angle := move.angle + 0.1;

    if Touches.Ha then
    begin

      move.x := move.x - 0.1*cos(move.angle);
      move.z := move.z - 0.1*sin(move.angle);

    end;

    if Touches.Ba then
    begin
      move.x := move.x + 0.1*cos(move.angle);
      move.z := move.z + 0.1*sin(move.angle);
    end;
  end;

procedure TMP.saut(var move : TMove);
begin
  move.saut := true;
  move.x := move.x - 0.1*cos(move.angle);
  move.z := move.z - 0.1*sin(move.angle);
  move.y := 3*sin(0.5*i);
  i:= i+0.1;
  if move.y < 0 then
  begin
    move.saut := false;
    move.y := 0;
    self.i := 0;
    if  (surface.hd = '0') and (surface.bd >= '0') and (surface.hg >= '0') and (surface.bg >= '0') then
      move.y := move.y-0.2;
    
  end;
end;
end.
