unit uGame;

interface

uses
  ElysionKronos,
  SysUtils,
  BasicGame,
  uBasic,
  uGlobal,
  uConfig,
  uMainMenu,
  uGameScreen;

type
  TGame = class(TBasicGame)
  private
    fMainMenu: TMainMenu;
    fGameScreen: TGameScreen;
  public
    constructor Create(); Override;
    destructor Destroy; Override;
    
    procedure Initialize(); Override;

    procedure Render(); Override;
    procedure Update(dt: Double); Override;
  published
    property MainMenu: TMainMenu read fMainMenu write fMainMenu;
    property GameScreen: TGameScreen read fGameScreen write fGameScreen;
  end;

implementation

constructor TGame.Create;
begin
  GameState := gsMainMenu;
  
  // Super
  inherited Create(AppConfig.Width, AppConfig.Height, AppConfig.Bits, false);
end;

destructor TGame.Destroy;
begin
  inherited;

  MainMenu.Destroy;
  GameScreen.Destroy;
end;

procedure TGame.Initialize;
begin  
  ActiveWindow.Caption := 'Ludum Dare #17';
  ActiveWindow.ShowCursor();

  MainMenu := TMainMenu.Create;
  GameScreen := TGameScreen.Create;
end;

procedure TGame.Render;
begin

  case GameState of
    gsMainMenu:
    begin
      MainMenu.Render;
	  
     
    end;
    gsInstructions:
    begin
      
    end;
    gsOptions:
    begin
      
    end;
	gsIntro:
	begin
	  
	end;
    gsGame:
    begin
      GameScreen.Render;
	 
    end;
  end;
  
end;

procedure TGame.Update(dt: Double);
var
  i: Integer;
begin  
  case GameState of
    gsMainMenu:
    begin
      MainMenu.Update;
      MainMenu.HandleEvents;
    end;
    gsGame:
    begin
      GameScreen.Update;
      GameScreen.HandleEvents;
    end;
  end;
	
  // Keyboard Inputs
  if GameState <> gsMainMenu then
  begin
    if Input.Keyboard.isKeyUp(K_ESCAPE) then GameState := gsMainMenu;
  end;
  
  // Fullscreen not working at the moment, needs fixing
  //if Input.Keyboard.isKeyUp(K_W) then ActiveWindow.ToggleFullscreen;
  
end;

end.
