0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
0	
1	{
1	}
3	var
3	var
3	var
3	var
3	var
3	var
3	var
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	end;
4	type
4	type
4	uses
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	begin
5	const
6	    );
6	  end;
6	  end;
6	public
6	public
7	  darg,
7	  dgui,
7	  dtga,
7	  end; 
7	  mapa,
7	{$ELSE}
8	    end;
8	  djson,
8	  dmath,
8	  uber2,
8	{$ENDIF}
8	{$ENDIF}
9	  {$ELSE}
9	  dflags,
9	  dscene;
9	  dtypes,
9	protected
9	protected
9	protected
10	  {$ENDIF}
10	  {$ENDIF}
10	  {$ENDIF}
10	  {$ENDIF}
10	  {$ENDIF}
10	  dcolors,
10	  drect2i,
10	  dresize,
10	  dstrnum,
10	  end else
10	  end else
10	  Eng.Run;
11	    D := 0;
11	  Gui.Done;
12	  D: Single;
12	  DGraphTex,
12	  dvector2f,
12	  dvector2i,
12	  dvector4f,
12	  P: TVec2i;
12	  ParseArgs;
12	public const
13	      // TODO
13	      D := 2;
13	  dintersect,
13	  dminkowski,
13	  Flags := 0;
13	  Gui.Render;
13	  Gui.Update;
13	  Obj: PJson;
13	  S: TString;
13	  World.Done;
14	  dstreamfile,
14	  Json := Obj;
14	  Json: PJson;
14	  Mapa: TMapa;
14	  Pos: TVec2f;
14	  SetupShapes;
14	  Vel: TVec2f;
14	{$MODE OBJFPC}
15	  Base : record
15	  Shape: PJson;
15	  World.Render;
15	  World.Update;
16	    Exit(False);
16	    Result := 0;
16	  Down := False;
16	  Down: Boolean;
16	  Rect: TRect2f;
16	  World: TWorld;
16	TGlobal = object
17	    Eng.StopLoop;
17	    if D > 2 then
17	  Color: TUInt32;
17	  GameScene.Done;
17	  MenuScene.Done;
17	  Radius: Double;
17	  Width: LongInt;
18	    Rect: TRect2f;
18	  Bounds: TRect2i;
18	  dgui_theme_text,
18	  Entity: PEntity;
18	  Flags: Cardinal;
18	  Global: TGlobal;
18	  Height: LongInt;
18	  Item: PJsonItem;
18	  MapSize: TVec2i;
18	  Result := False;
18	  Result := False;
18	  Result := False;
18	  Result := False;
18	  World.Init(Eng);
19	    P := Eng.Mouse;
19	  OnGround := True;
19	PEntity = ^TEntity;
20	  Circle: TCircle2f;
20	  DragDelta: TVec2f;
20	  LoadingScene.Done;
20	  Macro: PJsonArray;
20	  MapaName: TString;
20	  OnGround: Boolean;
20	{$IFDEF DEVELOPMENT}
20	{$IFDEF DEVELOPMENT}
21	  Eng.Draw.EndRender;
21	  PLAYER_Y_SHIFT = 2;
21	  Vel := Vec2f(0, 0);
21	{$I deng_app_end.inc}
22	    Circle: TCircle2f;
22	  //CheckForMapa(Eng);
22	  {$IFDEF DEVELOPMENT}
22	  {$IFDEF DEVELOPMENT}
22	  {$IFDEF DEVELOPMENT}
22	  {$IFDEF DEVELOPMENT}
22	  {$IFDEF DEVELOPMENT}
23	  Eng.Draw.BeginRender;
23	  GameScene.Init(@Eng);
23	  LastUpdated: LongInt;
23	  MenuScene.Init(@Eng);
23	  Tex, Tex2: TGraphTex;
23	{$I deng_app_begin.inc}
23	{$MODESWITCH AUTODEREF}
24	    World.Root^.ForEach(
24	  GameScene: TGameScene;
24	  LastCursorPos: TVec2f;
24	  MenuScene: TMenuScene;
24	  procedure SetupShapes;
24	  WorkSpace: TWorkSpace;
25	  DragStartedPos: TVec2f;
25	  SceneSwitch(GameScene);
26	  {$I deng_app_units.inc},
26	  HorizontalLock := False;
26	  HorizontalLock: Boolean;
26	  LoadingScene.Init(@Eng);
26	  NearlyCollided: LongInt;
26	procedure TEntity.OnClick;
26	procedure TEntity.OnSpawn;
27	  DragStartedMouse: TVec2i;
27	procedure TEntity.OnRender;
27	procedure TEntity.OnUpdate;
27	TGameScene = object(TScene)
27	TMenuScene = object(TScene)
28	  FLAG_ENEMY_STALKER    = 8;
28	  FLAG_PHYS_CIRCLE      = 2;
28	  FLAG_PHYS_POLYGON     = 1;
28	  FLAG_PHYS_RECT        = 4;
28	  Polygon: TConvexPolygon2f;
28	  procedure DoLoad; virtual;
28	  procedure DoLoad; virtual;
28	  procedure DoLoad; virtual;
28	procedure TGameScene.DoLoad;
28	procedure TMenuScene.DoLoad;
29	  FLAG_ENEMY_GARGOYLE   = 64;
29	  FLAG_ENEMY_GHOST      = 16;
29	  FLAG_ENEMY_LEPRECHAUN = 32;
29	  procedure OnClick; virtual;
29	  procedure OnSpawn; virtual;
29	{$MODESWITCH DUPLICATELOCALS}
29	TEntity = object(TBaseEntity)
30	    Polygon: TConvexPolygon2f;
30	  //procedure ComputeMovement;
30	  FLAG_EXPLORER         = 256;
30	  FLAG_SQUEAKY          = 512;
30	  FLAG_TREASURE         = 128;
30	  function GetFakeVel: TVec2f;
30	  LoadingScene: TLoadingScene;
30	  procedure DoRender; virtual;
30	  procedure DoRender; virtual;
30	  procedure DoRender; virtual;
30	  procedure DoUnload; virtual;
30	  procedure DoUnload; virtual;
30	  procedure DoUnload; virtual;
30	  procedure DoUpdate; virtual;
30	  procedure DoUpdate; virtual;
30	  procedure DoUpdate; virtual;
30	  procedure OnRender; virtual;
30	  procedure OnUpdate; virtual;
30	  procedure SetupShapesLinear;
30	{$MODESWITCH POINTERTOPROCVAR}
30	procedure TEntity.SetupShapes;
30	procedure TGameScene.DoRender;
30	procedure TGameScene.DoUnload;
30	procedure TGameScene.DoUpdate;
30	procedure TMenuScene.DoRender;
30	procedure TMenuScene.DoUnload;
30	procedure TMenuScene.DoUpdate;
30	TLoadingScene = object(TScene)
31	    Obj := Item.Get(EmptyJson);
31	  // here some global variables
31	  Eng.Draw.BlendMode(BM_ALPHA);
31	  MapaParseBounds(Obj, Bounds);
31	procedure TLoadingScene.DoLoad;
32	{$I deng_app.inc} onebuttonhunt;
33	procedure TLoadingScene.DoRender;
33	procedure TLoadingScene.DoUnload;
33	procedure TLoadingScene.DoUpdate;
34	  if Gui.OnWindowEvent(Event) then
34	  if not HorizontalLock then begin
35	    if Macro.Has('exit') then begin
35	    Rect.Translate(Base.Rect, Pos);
35	  if Flags.Has(FLAG_PHYS_RECT) then
35	  if Flags.Has(FLAG_PHYS_RECT) then
36	      @PEntity(World.Root).DoNothing
36	  Result := Vec2f(Vel.X, Vel.Y + 1);
36	function TEntity.GetFakeVel: TVec2f;
36	procedure TEntity.SetupShapesLinear;
37	    Flags := Flags or FLAG_PHYS_RECT;
37	  Global.Mapa.RenderJsonObject(Json);
37	  if Event.IsLeftClickDown then begin
37	  if Flags.Has(FLAG_PHYS_CIRCLE) then
37	  if Flags.Has(FLAG_PHYS_CIRCLE) then
37	  Radius := Shape^.Get('radius', 10);
38	  if Eng.Control.Pressed(KEY_ESC) then
38	  if Flags.Has(FLAG_PHYS_POLYGON) then
38	  if Flags.Has(FLAG_PHYS_POLYGON) then
39	    Circle.Translate(Base.Circle, Pos);
39	    Flags := Flags or FLAG_PHYS_CIRCLE;
39	  Arg('w', 'width', Global.Width, 800);
40	    Flags := Flags or FLAG_PHYS_POLYGON;
40	    Tex := Eng.Draw.UploadTex(Asset(S));
40	  Gui.Init(Eng, @dgui_theme_text.Theme);
40	  Shape := Obj^.Get('shape', EmptyJson);
41	    Polygon.Translate(Base.Polygon, Pos);
41	    Result := Other.GetOffset(Rect, Dir);
41	    Tex2 := Eng.Draw.UploadTex(Asset(S));
41	  Arg('h', 'height', Global.Height, 600);
41	  Global.Mapa.Init(Eng, Global.MapaName);
41	  Global.MapName := 'data/maps/map.json';
43	  end else if Event.IsCursorMove then begin
43	procedure TEntity.InitFromJson(Obj: PJson);
44	      @PEntity(World.Root).CollideWithMouse,
44	    D := (Eng.Time - LastUpdated)/Eng.Delta;
44	    Result := Other.GetOffset(Polygon, Dir);
44	  Eng.Draw.ClearScreen(Vec4f(0, 0, 0, 1.0));
44	  if Flags.Has(FLAG_PHYS_POLYGON) then begin
45	    end else if Macro.Has('ghost') then begin
45	  if MapaParseCircle(Shape, Base.Circle) then
45	procedure CheckForMapa(Eng: TEngine); inline;
46	    Macro := Obj.Get('macro', EmptyJsonArray);
46	  if MapaParseRect(Obj, Shape, Base.Rect) then
46	  procedure InitFromJson(Obj: PJson); virtual;
47	    end else if Macro.Has('squeaky') then begin
47	    end else if Macro.Has('stalker') then begin
47	  // TODO use these flags instead of 10 objects
47	  //function GetPostion(Time: LongInt): TVec2f;
47	  end else if Event.IsRightClickDown then begin
47	  Gui.SetGlobalEventHandler(@GlobalOnGuiEvent);
47	  if MapaParsePolygon(Shape, Base.Polygon) then
47	  if Obj^.Find('texture', S) and (S <> '') then
48	    end else if Macro.Has('explorer') then begin
48	    end else if Macro.Has('gargoyle') then begin
48	    end else if Macro.Has('treasure') then begin
48	  if Obj^.Find('texture2', S) and (S <> '') then
49	procedure TEntity.DoNothing(Entity: PBaseEntity);
50	    end else if Macro.Has('leprechaun') then begin
50	  end else if Flags.Has(FLAG_PHYS_RECT) then begin
50	  procedure CollideWithMouse(Entity: PBaseEntity);
50	function GlobalOnGuiEvent(Ev: PGuiEvent): Boolean;
51	  end else if Event.IsKeyDown(KEY_SPACE) then begin
51	  Obj := Global.Mapa.Json.Get('global', EmptyJson);
51	  Pos := Vec2f(Obj^.Get('x', 0), Obj^.Get('y', 0));
53	    Log('-----------------------------------------');
53	  Color := StrToColor(Obj^.Get('color', 'FFFFFFFF'));
53	  procedure DoNothing(Entity: PBaseEntity); overload;
55	  //function CheckOnGround(out Delta: TVec2f): Boolean;
56	procedure TEntity.CollideWithMouse(Entity: PBaseEntity);
57	    // TODO Refactor these horrible ForEach constructions
59	    Player^.Pos := Global.WorkSpace.CursorToWork(Vec2f(P));
59	    Rect.Translate(Base.Rect, Vec2f(Round2f(Pos + D*Vel)));
60	  function DoOnEvent(Event: PWindowEvent): Boolean; virtual;
60	  function DoOnEvent(Event: PWindowEvent): Boolean; virtual;
60	  function DoOnEvent(Event: PWindowEvent): Boolean; virtual;
60	function TGameScene.DoOnEvent(Event: PWindowEvent): Boolean;
60	function TMenuScene.DoOnEvent(Event: PWindowEvent): Boolean;
61	  TODO separate DEVELOPMENT to DEBUG and DEVELOPMENT switches
62	  Arg('m', 'mapaname', Global.MapaName, 'data/maps/map.json');
63	    Circle.Translate(Base.Circle, Vec2f(Round2f(Pos + D*Vel)));
63	function TLoadingScene.DoOnEvent(Event: PWindowEvent): Boolean;
64	  Eng.InitDisplayMode(Global.Width, Global.Height, 32, DENG_GL);
65	    Polygon.Translate(Base.Polygon, Vec2f(Round2f(Pos + D*Vel)));
65	  Eng.Draw.Start2D(Global.WorkSpace.Pos, Global.WorkSpace.Coeff);
65	  Global.WorkSpace.Setup(Global.MapSize, Eng.WinApi.Window.Size);
66	  Global.MapSize := Vec2i(Obj.Get('w', 1440), Obj.Get('h', 2560));
68	    LastCursorPos := Global.WorkSpace.CursorToWork(Event.GetCursor);
68	    LastCursorPos := Global.WorkSpace.CursorToWork(Event.GetCursor);
70	  //Eng.Draw.Color(Vec4f(1, 0, 0, 1)).CircleFilled(LastCursorPos, 10);
71	  for Item in Global.Mapa.Json.Get('objects', EmptyJsonArray)^ do begin
72	  Eng.InitTitle('One button hunt'{$IFDEF DEVELOPMENT}+' (dev)'{$ENDIF});
79	  function GetOffset(const Other: TConvexPolygon2f; const Dir: TVec2f): Double;
80	  TODO refactor Eng.Draw.* functions and reduce int<->float conversasions at all
85	function TEntity.GetOffset(const Other: TConvexPolygon2f; const Dir: TVec2f): Double;
