Debian Codegraph @

examples/deprecated_to_upgrade/isometric_game/code/gamewindow.pas

raw
1 {
2 Copyright 2011-2018 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Game state and window. }
17 unit GameWindow;
18
19 interface
20
21 uses CastleWindow,
22 GameMap;
23
24 const
25 BaseWidth = 70;
26 BaseHeight = 36;
27
28 var
29 Window: TCastleWindow;
30
31 { Game time, in seconds. Updated in Update. }
32 GameTime: Single;
33
34 Map: TMap;
35
36 { Calculate values suitable for ViewMoveX and ViewMoveY to
37 see the map point MapX, MapY exactly in the middle.
38 MapX, Y don't have to be in the range 0...Map.Width/Height - 1. }
39 procedure ViewMoveToCenterPosition(const MapX, MapY: Integer;
40 var MoveX, MoveY: Integer);
41
42 implementation
43
44 procedure ViewMoveToCenterPosition(const MapX, MapY: Integer;
45 var MoveX, MoveY: Integer);
46 begin
47 { Set MoveX/Y such that point (0, 0) is in the middle. }
48 MoveX := (Window.Width div 2) - BaseWidth div 2;
49 MoveY := (Window.Height div 2) - BaseHeight div 2;
50 { Now translate such that MapX, MapY is in the middle. }
51 MoveX := MoveX - MapX * BaseWidth;
52 MoveY := MoveY - MapY * (BaseHeight div 2);
53 if Odd(MapY) then
54 MoveX := MoveX - (BaseWidth div 2);
55 end;
56
57 end.