author | Xeli |
Wed, 14 Sep 2011 18:43:16 +0200 | |
branch | hedgeroid |
changeset 5826 | 2a2cce052b4d |
parent 5733 | 5ab22736bdb6 |
child 5828 | 667fb58d7f18 |
permissions | -rw-r--r-- |
5621 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program 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. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
19 |
{$INCLUDE "options.inc"} |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
20 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
21 |
unit uTouch; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
22 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
23 |
interface |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
24 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
25 |
uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit, uCommandHandlers; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
26 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
27 |
type |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
28 |
PTouch_Finger = ^Touch_Finger; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
29 |
Touch_Finger = record |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
30 |
id : SDL_FingerId; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
31 |
x,y : LongInt; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
32 |
historicalX, historicalY : LongInt; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
33 |
timeSinceDown : Longword; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
34 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
35 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
36 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
37 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
38 |
procedure ProcessTouch; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
39 |
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
40 |
procedure onTouchMotion(x,y: Longword; dx,dy: LongInt; pointerId: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
41 |
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
42 |
function convertToCursor(scale: LongInt; xy: LongInt): LongInt; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
43 |
function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
44 |
procedure deleteFinger(id: SDL_FingerId); |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
45 |
procedure onTouchClick(finger: Touch_Finger); |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
46 |
procedure onTouchDoubleClick(finger: Touch_Finger); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
47 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
48 |
function findFinger(id: SDL_FingerId): PTouch_Finger; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
49 |
procedure aim(finger: Touch_Finger); |
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
50 |
function isOnCrosshair(finger: Touch_Finger): boolean; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
51 |
function isOnCurrentHog(finger: Touch_Finger): boolean; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
52 |
function isOnFireButton(finger: Touch_Finger): boolean; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
53 |
procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
54 |
function fingerHasMoved(finger: Touch_Finger): boolean; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
55 |
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
56 |
function getSecondFinger(finger: Touch_Finger): PTouch_Finger; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
57 |
procedure printFinger(finger: Touch_Finger); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
58 |
implementation |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
59 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
60 |
const |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
61 |
clicktime = 200; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
62 |
nilFingerId = High(SDL_FingerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
63 |
var |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
64 |
leftButtonBoundary : LongInt; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
65 |
rightButtonBoundary : LongInt; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
66 |
topButtonBoundary : LongInt; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
67 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
68 |
pointerCount : Longword; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
69 |
fingers: array of Touch_Finger; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
70 |
moveCursor : boolean; |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
71 |
invertCursor : boolean; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
72 |
|
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
73 |
xTouchClick,yTouchClick : LongInt; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
74 |
timeSinceClick : Longword; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
75 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
76 |
//Pinch to zoom |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
77 |
pinchSize : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
78 |
baseZoomValue: GLFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
79 |
|
5589 | 80 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
81 |
//aiming |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
82 |
aiming, movingCrosshair: boolean; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
83 |
crosshairCommand: ShortString; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
84 |
targetAngle: LongInt; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
85 |
stopFiring: boolean; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
86 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
87 |
//moving |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
88 |
stopLeft, stopRight, walkingLeft, walkingRight : boolean; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
89 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
90 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
91 |
procedure onTouchDown(x,y: Longword; pointerId: SDL_FingerId); |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
92 |
var |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
93 |
finger: PTouch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
94 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
95 |
finger := addFinger(x,y,pointerId); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
96 |
case pointerCount of |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
97 |
1: |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
98 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
99 |
moveCursor:= false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
100 |
if bShowAmmoMenu then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
101 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
102 |
moveCursor := true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
103 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
104 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
105 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
106 |
if isOnCrosshair(finger^) then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
107 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
108 |
aiming:= true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
109 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
110 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
111 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
112 |
if isOnFireButton(finger^) then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
113 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
114 |
stopFiring:= false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
115 |
ParseCommand('+attack', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
116 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
117 |
end; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
118 |
if (finger^.x < leftButtonBoundary) and (finger^.y < 390) then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
119 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
120 |
ParseCommand('+left', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
121 |
walkingLeft := true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
122 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
123 |
end; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
124 |
if finger^.x > rightButtonBoundary then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
125 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
126 |
ParseCommand('+right', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
127 |
walkingRight:= true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
128 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
129 |
end; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
130 |
if finger^.y < topButtonBoundary then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
131 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
132 |
ParseCommand('hjump', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
133 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
134 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
135 |
moveCursor:= true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
136 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
137 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
138 |
begin |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
139 |
aiming:= false; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
140 |
stopFiring:= true; |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
141 |
pinchSize := calculateDelta(finger^, getSecondFinger(finger^)^); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
142 |
baseZoomValue := ZoomValue |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
143 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
144 |
end;//end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
145 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
146 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
147 |
procedure onTouchMotion(x,y: Longword;dx,dy: LongInt; pointerId: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
148 |
var |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
149 |
finger, secondFinger: PTouch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
150 |
currentPinchDelta, zoom : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
151 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
152 |
finger:= findFinger(pointerId); |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
153 |
|
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
154 |
finger^.x := convertToCursor(cScreenWidth, x); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
155 |
finger^.y := convertToCursor(cScreenHeight, y); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
156 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
157 |
case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
158 |
1: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
159 |
begin |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
160 |
if aiming then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
161 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
162 |
aim(finger^); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
163 |
exit |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
164 |
end; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
165 |
if moveCursor then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
166 |
if invertCursor then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
167 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
168 |
CursorPoint.X := CursorPoint.X - convertToCursor(cScreenWidth,dx); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
169 |
CursorPoint.Y := CursorPoint.Y + convertToCursor(cScreenWidth,dy); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
170 |
end |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
171 |
else |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
172 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
173 |
CursorPoint.X := CursorPoint.X + convertToCursor(cScreenWidth,dx); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
174 |
CursorPoint.Y := CursorPoint.Y - convertToCursor(cScreenWidth,dy); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
175 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
176 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
177 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
178 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
179 |
secondFinger := getSecondFinger(finger^); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
180 |
currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
181 |
zoom := currentPinchDelta/cScreenWidth; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
182 |
ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta)); |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
183 |
if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
184 |
if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
185 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
186 |
end; //end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
187 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
188 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
189 |
procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
190 |
begin |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
191 |
aiming:= false; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
192 |
stopFiring:= true; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
193 |
deleteFinger(pointerId); |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
194 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
195 |
if walkingLeft then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
196 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
197 |
ParseCommand('-left', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
198 |
walkingLeft := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
199 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
200 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
201 |
if walkingRight then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
202 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
203 |
ParseCommand('-right', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
204 |
walkingRight := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
205 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
206 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
207 |
|
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
208 |
procedure onTouchDoubleClick(finger: Touch_Finger); |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
209 |
begin |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
210 |
ParseCommand('ljump', true); |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
211 |
end; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
212 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
213 |
procedure onTouchClick(finger: Touch_Finger); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
214 |
begin |
5617
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
215 |
if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
216 |
begin |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
217 |
onTouchDoubleClick(finger); |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
218 |
exit; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
219 |
end |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
220 |
else |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
221 |
begin |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
222 |
xTouchClick := finger.x; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
223 |
yTouchClick := finger.y; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
224 |
timeSinceClick := SDL_GetTicks; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
225 |
end; |
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
226 |
|
5589 | 227 |
if bShowAmmoMenu then |
228 |
begin |
|
229 |
doPut(CursorPoint.X, CursorPoint.Y, false); |
|
230 |
exit |
|
231 |
end; |
|
232 |
||
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
233 |
if isOnCurrentHog(finger) then |
5595 | 234 |
begin |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
235 |
bShowAmmoMenu := true; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
236 |
exit; |
5595 | 237 |
end; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
238 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
239 |
if finger.y < topButtonBoundary then |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
240 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
241 |
ParseCommand('hjump', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
242 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
243 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
244 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
245 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
246 |
function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
247 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
248 |
xCursor, yCursor, index : LongInt; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
249 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
250 |
//Check array sizes |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
251 |
if length(fingers) < pointerCount then |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
252 |
begin |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
253 |
setLength(fingers, length(fingers)*2); |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
254 |
for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId; |
5589 | 255 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
256 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
257 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
258 |
xCursor := convertToCursor(cScreenWidth, x); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
259 |
yCursor := convertToCursor(cScreenHeight, y); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
260 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
261 |
//on removing fingers, all fingers are moved to the left |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
262 |
//with dynamic arrays being zero based, the new position of the finger is the old pointerCount |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
263 |
fingers[pointerCount].id := id; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
264 |
fingers[pointerCount].historicalX := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
265 |
fingers[pointerCount].historicalY := yCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
266 |
fingers[pointerCount].x := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
267 |
fingers[pointerCount].y := yCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
268 |
fingers[pointerCount].timeSinceDown:= SDL_GetTicks; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
269 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
270 |
addFinger:= @fingers[pointerCount]; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
271 |
inc(pointerCount); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
272 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
273 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
274 |
procedure deleteFinger(id: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
275 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
276 |
index : Longint; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
277 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
278 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
279 |
dec(pointerCount); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
280 |
for index := 0 to pointerCount do |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
281 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
282 |
if fingers[index].id = id then |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
283 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
284 |
//Check for onTouchClick event |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
285 |
if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
286 |
not(fingerHasMoved(fingers[index])) then onTouchClick(fingers[index]); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
287 |
|
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
288 |
//put the last finger into the spot of the finger to be removed, |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
289 |
//so that all fingers are packed to the far left |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
290 |
if pointerCount <> index then |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
291 |
begin |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
292 |
fingers[index].id := fingers[pointerCount].id; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
293 |
fingers[index].x := fingers[pointerCount].x; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
294 |
fingers[index].y := fingers[pointerCount].y; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
295 |
fingers[index].historicalX := fingers[pointerCount].historicalX; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
296 |
fingers[index].historicalY := fingers[pointerCount].historicalY; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
297 |
fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
298 |
|
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
299 |
fingers[pointerCount].id := nilFingerId; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
300 |
end |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
301 |
else fingers[index].id := nilFingerId; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
302 |
break; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
303 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
304 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
305 |
|
5589 | 306 |
end; |
307 |
||
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
308 |
procedure ProcessTouch; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
309 |
var |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
310 |
deltaAngle: LongInt; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
311 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
312 |
invertCursor := not(bShowAmmoMenu); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
313 |
if aiming then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
314 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
315 |
if CurrentHedgehog^.Gear <> nil then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
316 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
317 |
deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
318 |
if (deltaAngle <> 0) and not(movingCrosshair) then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
319 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
320 |
ParseCommand('+' + crosshairCommand, true); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
321 |
movingCrosshair := true; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
322 |
end |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
323 |
else |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
324 |
if movingCrosshair then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
325 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
326 |
ParseCommand('-' + crosshairCommand, true); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
327 |
movingCrosshair:= false; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
328 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
329 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
330 |
end |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
331 |
else if movingCrosshair then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
332 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
333 |
ParseCommand('-' + crosshairCommand, true); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
334 |
movingCrosshair := false; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
335 |
end; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
336 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
337 |
if stopFiring then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
338 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
339 |
ParseCommand('-attack', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
340 |
stopFiring:= false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
341 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
342 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
343 |
if stopRight then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
344 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
345 |
stopRight := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
346 |
ParseCommand('-right', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
347 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
348 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
349 |
if stopLeft then |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
350 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
351 |
stopLeft := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
352 |
ParseCommand('-left', true); |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
353 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
354 |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
355 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
356 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
357 |
function findFinger(id: SDL_FingerId): PTouch_Finger; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
358 |
var |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
359 |
index: LongWord; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
360 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
361 |
for index := 0 to High(fingers) do |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
362 |
if fingers[index].id = id then |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
363 |
begin |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
364 |
findFinger := @fingers[index]; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
365 |
break; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
366 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
367 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
368 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
369 |
procedure aim(finger: Touch_Finger); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
370 |
var |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
371 |
hogX, hogY, touchX, touchY, deltaX, deltaY, tmpAngle: hwFloat; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
372 |
tmp: ShortString; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
373 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
374 |
if CurrentHedgehog^.Gear <> nil then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
375 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
376 |
hogX := CurrentHedgehog^.Gear^.X; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
377 |
hogY := CurrentHedgehog^.Gear^.Y; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
378 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
379 |
convertToWorldCoord(touchX, touchY, finger); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
380 |
deltaX := hwAbs(TouchX-HogX); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
381 |
deltaY := (TouchY-HogY); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
382 |
|
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
383 |
tmpAngle:= DeltaY / Distance(deltaX, deltaY) *_2048; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
384 |
targetAngle:= (hwRound(tmpAngle) + 2048) div 2; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
385 |
|
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
386 |
tmp := crosshairCommand; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
387 |
if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then crosshairCommand := 'down' |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
388 |
else crosshairCommand:= 'up'; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
389 |
if movingCrosshair and (tmp <> crosshairCommand) then |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
390 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
391 |
ParseCommand('-' + tmp, true); |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
392 |
movingCrosshair := false; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
393 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
394 |
|
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
395 |
end; //if CurrentHedgehog^.Gear <> nil |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
396 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
397 |
|
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
398 |
function convertToCursor(scale: LongInt; xy: LongInt): LongInt; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
399 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
400 |
convertToCursor := round(xy/32768*scale) |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
401 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
402 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
403 |
function isOnFireButton(finger: Touch_Finger): boolean; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
404 |
begin |
5619
2ec22ebeb6f5
added a visual fire button, isOnFireButton check needs to be fixed though it only works on 800x480 screens
Xeli
parents:
5617
diff
changeset
|
405 |
printFinger(finger); |
2ec22ebeb6f5
added a visual fire button, isOnFireButton check needs to be fixed though it only works on 800x480 screens
Xeli
parents:
5617
diff
changeset
|
406 |
WriteToConsole(Format('%d %d ',[round((-cScreenWidth+20)/0.8), round((cScreenHeight+55)/0.8)])); |
2ec22ebeb6f5
added a visual fire button, isOnFireButton check needs to be fixed though it only works on 800x480 screens
Xeli
parents:
5617
diff
changeset
|
407 |
WriteToConsole(Format('%d, %d',[cScreenWidth, cScreenHeight])); |
2ec22ebeb6f5
added a visual fire button, isOnFireButton check needs to be fixed though it only works on 800x480 screens
Xeli
parents:
5617
diff
changeset
|
408 |
isOnFireButton:= (finger.x < 205) and (finger.y > 420); |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
409 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
410 |
|
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
411 |
function isOnCrosshair(finger: Touch_Finger): boolean; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
412 |
var |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
413 |
x,y,fingerX, fingerY : hwFloat; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
414 |
begin |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
415 |
x := int2hwFloat(CrosshairX); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
416 |
y := int2hwFloat(CrosshairY); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
417 |
|
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
418 |
convertToWorldCoord(fingerX, fingerY, finger); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
419 |
isOnCrosshair:= Distance(fingerX-x, fingerY-y) < _20; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
420 |
end; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
421 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
422 |
function isOnCurrentHog(finger: Touch_Finger): boolean; |
5595 | 423 |
var |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
424 |
x,y, fingerX, fingerY : hwFloat; |
5595 | 425 |
begin |
426 |
x := CurrentHedgehog^.Gear^.X; |
|
427 |
y := CurrentHedgehog^.Gear^.Y; |
|
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
428 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
429 |
convertToWorldCoord(fingerX, fingerY, finger); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
430 |
isOnCurrentHog := Distance(fingerX-x, fingerY-y) < _20; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
431 |
end; |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
432 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
433 |
procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
434 |
begin |
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
435 |
//if x <> nil then |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
436 |
x := int2hwFloat((finger.x-WorldDx) - (cScreenWidth div 2)); |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
437 |
//if y <> nil then |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
438 |
y := int2hwFloat(finger.y-WorldDy); |
5595 | 439 |
end; |
440 |
||
5589 | 441 |
//Method to calculate the distance this finger has moved since the downEvent |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
442 |
function fingerHasMoved(finger: Touch_Finger): boolean; |
5589 | 443 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
444 |
fingerHasMoved := trunc(sqrt(Power(finger.X-finger.historicalX,2) + Power(finger.y-finger.historicalY, 2))) > 330; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
445 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
446 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
447 |
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; inline; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
448 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
449 |
calculateDelta := DistanceI(finger2.x-finger1.x, finger2.y-finger1.y); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
450 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
451 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
452 |
// Under the premise that all pointer ids in pointerIds:SDL_FingerId are packed to the far left. |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
453 |
// If the pointer to be ignored is not pointerIds[0] the second must be there |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
454 |
function getSecondFinger(finger: Touch_Finger): PTouch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
455 |
begin |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
456 |
if fingers[0].id = finger.id then getSecondFinger := @fingers[1] |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
457 |
else getSecondFinger := @fingers[0]; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
458 |
end; |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
459 |
|
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
460 |
procedure printFinger(finger: Touch_Finger); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
461 |
begin |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
462 |
WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown])); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
463 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
464 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
465 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
466 |
var |
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
467 |
index: Longword; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
468 |
begin |
5599
2e4b90f33a83
aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents:
5595
diff
changeset
|
469 |
movingCrosshair := false; |
5605
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
470 |
stopFiring:= false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
471 |
walkingLeft := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
472 |
walkingRight := false; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
473 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
474 |
leftButtonBoundary := cScreenWidth div 4; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
475 |
rightButtonBoundary := cScreenWidth div 4*3; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
476 |
topButtonBoundary := cScreenHeight div 6; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
477 |
|
5733
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
478 |
setLength(fingers, 4); |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
479 |
for index := 0 to High(fingers) do |
5ab22736bdb6
Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents:
5621
diff
changeset
|
480 |
fingers[index].id := nilFingerId; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
481 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
482 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
483 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
484 |
end. |