Sunday, October 3, 2010

BB, part 4, loading a 2d map


A very simple example, the important thing is how to create those maps, there is a silly tool called editor.exe in the demos that should help you.

uses
  BB.Input.Keys, BB.Screen.Types, BB.Screen.D3D, BB.Math, BB.Screen.Maps,
  BB.Colors;

procedure TForm1.FormActivate(Sender: TObject);
var
  m: TMap;
  gd: TGraphicDriver;

begin
  gd := TD3DDriver.Create;
  try
    gd.WindowHandle := WindowHandle;
    gd.Width := Width;
    gd.Height := Height;
    gd.BPP := 32;
    gd.ScreenFlags := [sfWait, sfClear];
    gd.Initialize;

    m := TMap.Create;
    m.FileName := 'test';
    m.LoadFile;
    m.Layers[0].SpeedX := 1;
    m.Layers[0].SpeedY := 1;
    m.Layers[0].X := 0;

    repeat
      gd.BeginRender;
      m.Layers[0].X := 1024 + (512 * Cos(gd.TotalFrames * Rad));
      m.Layers[0].Y := 512 + (256 * Sin(gd.TotalFrames * Rad));
      m.Render;

      gd.Rectangle(0, 16, gd.CurrentFPS, 16, TRGB.White);
      gd.EndRender;

      Application.ProcessMessages;
    until Inkey(VK_ESCAPE);

  finally
    gd.Free;
  end;

  Close;
end;




No comments:

Post a Comment