unit Resources;

interface

uses
  QuadEngine, GameModeManager, Vec2f, Bass;

type
  TContent = class
  public
    class procedure Initialize; virtual; abstract;
    class procedure Finalize; virtual; abstract;
  end;

  TGlobals = class sealed(TContent)
  public
    const ScreenWidth = 1280;
    const ScreenHeight = 720;
    class var QuadDevice: IQuadDevice;
    class var QuadWindow: IQuadWindow;
    class var QuadRender: IQuadRender;
    class var QuadTimer: IQuadTimer;
    class var GameModeManager: TGameModeManager;
    class var music: HSAMPLE;
    class var sfx: HSAMPLE;
    class procedure Initialize; override;
    class procedure Finalize; override;
  end;

  TTextures = class sealed(TContent)
  public
    class var GameOverlay: IQuadTexture;
    class var Blocks: IQuadTexture;
    class var Dance: array[0..24] of IQuadTexture;
    class var DanceFloor: array[0..4] of IQuadTexture;
    class var Line: IQuadTexture;
    class var Fog: IQuadTexture;
    class var Fog2: IQuadTexture;
    class var Font: IQuadFont;
    class procedure Initialize; override;
    class procedure Finalize; override;
  end;

implementation

Uses
  Main;

class procedure TTextures.Initialize;
var
  i: Integer;
begin
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'gfx\overlay.png', GameOverlay);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'gfx\Blocks.png', Blocks, 43, 43);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'gfx\line.png', Line);

  TGlobals.QuadDevice.CreateAndLoadFont('fonts\quad.png', 'fonts\quad.qef', Font);

  for i := 0 to 24 do
    TGlobals.QuadDevice.CreateTexture(Dance[i]);

  Dance[0].LoadFromFile(0, 'gfx\dance\1.png');
  Dance[1].LoadFromFile(0, 'gfx\dance\2.png');
  Dance[2].LoadFromFile(0, 'gfx\dance\3.png');
  Dance[3].LoadFromFile(0, 'gfx\dance\4.png');
  Dance[4].LoadFromFile(0, 'gfx\dance\5.png');
  Dance[5].LoadFromFile(0, 'gfx\dance\6.png');
  Dance[6].LoadFromFile(0, 'gfx\dance\7.png');
  Dance[7].LoadFromFile(0, 'gfx\dance\8.png');
  Dance[8].LoadFromFile(0, 'gfx\dance\9.png');
  Dance[9].LoadFromFile(0, 'gfx\dance\10.png');
  Dance[10].LoadFromFile(0, 'gfx\dance\11.png');
  Dance[11].LoadFromFile(0, 'gfx\dance\12.png');
  Dance[12].LoadFromFile(0, 'gfx\dance\13.png');
  Dance[13].LoadFromFile(0, 'gfx\dance\14.png');
  Dance[14].LoadFromFile(0, 'gfx\dance\15.png');
  Dance[15].LoadFromFile(0, 'gfx\dance\16.png');
  Dance[16].LoadFromFile(0, 'gfx\dance\17.png');
  Dance[17].LoadFromFile(0, 'gfx\dance\18.png');
  Dance[18].LoadFromFile(0, 'gfx\dance\19.png');
  Dance[19].LoadFromFile(0, 'gfx\dance\20.png');
  Dance[20].LoadFromFile(0, 'gfx\dance\21.png');
  Dance[21].LoadFromFile(0, 'gfx\dance\22.png');
  Dance[22].LoadFromFile(0, 'gfx\dance\23.png');
  Dance[23].LoadFromFile(0, 'gfx\dance\24.png');
  Dance[24].LoadFromFile(0, 'gfx\dance\25.png');

  for i := 0 to 4 do
    TGlobals.QuadDevice.CreateTexture(DanceFloor[i]);

  DanceFloor[0].LoadFromFile(0, 'gfx\dancefloor\1.png');
  DanceFloor[1].LoadFromFile(0, 'gfx\dancefloor\2.png');
  DanceFloor[2].LoadFromFile(0, 'gfx\dancefloor\3.png');
  DanceFloor[3].LoadFromFile(0, 'gfx\dancefloor\4.png');
  DanceFloor[4].LoadFromFile(0, 'gfx\dancefloor\5.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'gfx\dancefloor\fog.png', Fog);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'gfx\dancefloor\fog2.png', Fog2);
end;

class procedure TTextures.Finalize;
begin

end;

class procedure TGlobals.Initialize;
begin
  QuadDevice := CreateQuadDevice;

  QuadDevice.CreateWindow(QuadWindow);
  QuadWindow.SetCaption('Quad-engine Tetris');
  QuadWindow.SetSize(ScreenWidth, ScreenHeight);
  QuadWindow.SetPosition(48, 48);
  QuadWindow.SetOnKeyDown(OnKeyDown);
  QuadWindow.SetOnKeyUp(OnKeyUp);

  QuadDevice.CreateRender(QuadRender);
  QuadRender.Initialize(QuadWindow.GetHandle, ScreenWidth, ScreenHeight, False);

  TTextures.Initialize;

  BASS_Init(1, 44100, 0, QuadWindow.GetHandle, nil);
  BASS_Start;
  music := BASS_StreamCreateFile(FALSE, PAnsiChar('./music/1.ogg'), 0, 0, 0);
  BASS_ChannelPlay(music, True);

  sfx := BASS_SampleGetChannel(BASS_SampleLoad(False, PAnsiChar('./music/m0x.mp3'), 0, 0, 32, 0), False);
  GameModeManager := TGameModeManager.Create;

  QuadDevice.CreateTimerEx(QuadTimer, OnTimer, 16, True);
  QuadWindow.Start;
end;

class procedure TGlobals.Finalize;
begin

end;


end.
