author | Xeli |
Sun, 21 Aug 2011 18:14:49 +0200 | |
branch | hedgeroid |
changeset 5625 | 9add7b92c5f0 |
parent 5621 | ea796c83ea47 |
child 5733 | 5ab22736bdb6 |
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 |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
28 |
Touch_Finger = record |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
29 |
id : SDL_FingerId; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
30 |
x,y : LongInt; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
31 |
historicalX, historicalY : LongInt; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
32 |
timeSinceDown : Longword; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
33 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
34 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
35 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
36 |
|
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
|
37 |
procedure ProcessTouch; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
function convertToCursor(scale: LongInt; xy: LongInt): LongInt; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
42 |
function addFinger(x,y: Longword; id: SDL_FingerId): Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
47 |
function findFinger(id: SDL_FingerId): Touch_Finger; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
48 |
procedure aim(finger: Touch_Finger); |
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
55 |
function getSecondFinger(finger: Touch_Finger): Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
56 |
implementation |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
57 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
58 |
const |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
59 |
clicktime = 200; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
65 |
pointerCount : Longword; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
|
88f43becefe3
added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents:
5615
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
73 |
//Pinch to zoom |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
74 |
pinchSize : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
75 |
baseZoomValue: GLFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
76 |
|
5589 | 77 |
|
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
|
78 |
//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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
84 |
//moving |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
85 |
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
|
86 |
procedure printFinger(finger: Touch_Finger); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
87 |
begin |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
88 |
WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown])); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
89 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
90 |
|
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
|
91 |
|
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
92 |
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
|
93 |
var |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
94 |
finger: Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
95 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
96 |
finger:= addFinger(x,y,pointerId); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
97 |
finger.x := convertToCursor(cScreenWidth,x); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
98 |
finger.y := convertToCursor(cScreenHeight,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
|
99 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
100 |
printFinger(finger); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
107 |
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
|
108 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
109 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
110 |
|
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
111 |
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
|
112 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
113 |
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
|
114 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
115 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
116 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
117 |
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
|
118 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
122 |
end; |
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
|
123 |
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
|
124 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
128 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
129 |
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
|
130 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
131 |
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
|
132 |
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
|
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; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
135 |
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
|
136 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
137 |
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
|
138 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
139 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
140 |
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
|
141 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
142 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
stopFiring:= true; |
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
|
146 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
147 |
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
|
148 |
baseZoomValue := ZoomValue |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
149 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
150 |
end;//end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
151 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
152 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
153 |
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
|
154 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
155 |
finger, secondFinger: Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
156 |
currentPinchDelta, zoom : hwFloat; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
157 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
158 |
finger:= findFinger(pointerId); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
159 |
finger.x := convertToCursor(cScreenWidth, x); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
160 |
finger.y := convertToCursor(cScreenHeight, y); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
161 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
162 |
case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
163 |
1: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
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 |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
176 |
else |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
177 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
181 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
182 |
2: |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
183 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
184 |
secondFinger := getSecondFinger(finger); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
185 |
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
|
186 |
zoom := currentPinchDelta/cScreenWidth; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
191 |
end; //end case pointerCount of |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
192 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
193 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
stopFiring:= true; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
198 |
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
|
199 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
200 |
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
|
201 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
205 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
206 |
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
|
207 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
208 |
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
|
209 |
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
|
210 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
211 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
212 |
|
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
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
|
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 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
|
5589 | 232 |
if bShowAmmoMenu then |
233 |
begin |
|
234 |
doPut(CursorPoint.X, CursorPoint.Y, false); |
|
235 |
exit |
|
236 |
end; |
|
237 |
||
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
238 |
if isOnCurrentHog(finger) then |
5595 | 239 |
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
|
240 |
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
|
241 |
exit; |
5595 | 242 |
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
|
243 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
244 |
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
|
245 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
246 |
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
|
247 |
exit; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
248 |
end; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
249 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
250 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
251 |
function addFinger(x,y: Longword; id: SDL_FingerId): Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
252 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
253 |
xCursor, yCursor, index : LongInt; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
254 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
255 |
//Check array sizes |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
256 |
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
|
257 |
begin |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
258 |
setLength(fingers, length(fingers)*2); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
259 |
for index := length(fingers) div 2 to length(fingers) do fingers[index].id := -1; |
5589 | 260 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
261 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
262 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
263 |
xCursor := convertToCursor(cScreenWidth, x); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
264 |
yCursor := convertToCursor(cScreenHeight, y); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
265 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
266 |
//on removing fingers all fingers are moved to the left, thus new fingers will be to the far right |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
267 |
//with dynamic arrays being zero based, 'far right' is the old pointerCount |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
268 |
fingers[pointerCount].id := id; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
269 |
fingers[pointerCount].historicalX := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
270 |
fingers[pointerCount].historicalY := yCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
271 |
fingers[pointerCount].x := xCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
272 |
fingers[pointerCount].y := yCursor; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
273 |
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
|
274 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
275 |
inc(pointerCount); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
276 |
addFinger:= fingers[pointerCount]; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
277 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
278 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
279 |
procedure deleteFinger(id: SDL_FingerId); |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
280 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
281 |
index : Longint; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
282 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
283 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
284 |
dec(pointerCount); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
285 |
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
|
286 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
287 |
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
|
288 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
289 |
//Check for onTouchevent |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
290 |
if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND not(fingerHasMoved(fingers[index])) then |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
291 |
onTouchClick(fingers[index]); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
292 |
fingers[index].id := -1; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
293 |
break; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
294 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
295 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
296 |
//put the last finger into the spot of the finger to be removed, so that all fingers are packed to the far left |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
297 |
if fingers[pointerCount].id = -1 then |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
298 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
299 |
fingers[index] := fingers[pointerCount]; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
300 |
fingers[pointerCount].id := -1; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
301 |
end; |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
302 |
|
5589 | 303 |
end; |
304 |
||
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
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 |
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
|
313 |
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
|
314 |
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
|
315 |
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
|
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 |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
334 |
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
|
335 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
336 |
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
|
337 |
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
|
338 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
339 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
340 |
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
|
341 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
342 |
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
|
343 |
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
|
344 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
345 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
346 |
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
|
347 |
begin |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
348 |
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
|
349 |
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
|
350 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
351 |
|
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
|
352 |
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
|
353 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
354 |
function findFinger(id: SDL_FingerId): Touch_Finger; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
355 |
begin |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
356 |
for findFinger in fingers do |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
357 |
if (findFinger.id = -1) and (findFinger.id = id) then break; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
358 |
end; |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
359 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
|
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 |
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
|
375 |
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
|
376 |
|
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 |
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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
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 |
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
|
387 |
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
|
388 |
|
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 |
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
|
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 |
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
|
392 |
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
|
393 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
end; |
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
401 |
|
5615
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
402 |
function isOnCrosshair(finger: Touch_Finger): boolean; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
403 |
var |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
404 |
x,y,fingerX, fingerY : hwFloat; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
405 |
begin |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
406 |
x := int2hwFloat(CrosshairX); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
407 |
y := int2hwFloat(CrosshairY); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
408 |
|
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
409 |
convertToWorldCoord(fingerX, fingerY, finger); |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
410 |
isOnCrosshair:= Distance(fingerX-x, fingerY-y) < _20; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
411 |
end; |
104f69e798bb
changed aiming to be triggered when touching the crosshair
Xeli
parents:
5609
diff
changeset
|
412 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
413 |
function isOnCurrentHog(finger: Touch_Finger): boolean; |
5595 | 414 |
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
|
415 |
x,y, fingerX, fingerY : hwFloat; |
5595 | 416 |
begin |
417 |
x := CurrentHedgehog^.Gear^.X; |
|
418 |
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
|
419 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
424 |
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
|
425 |
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
|
426 |
//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
|
427 |
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
|
428 |
//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
|
429 |
y := int2hwFloat(finger.y-WorldDy); |
5595 | 430 |
end; |
431 |
||
5589 | 432 |
//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
|
433 |
function fingerHasMoved(finger: Touch_Finger): boolean; |
5589 | 434 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
435 |
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
|
436 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
437 |
|
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
438 |
function calculateDelta(finger1, finger2: Touch_Finger): hwFloat; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
439 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
440 |
// calculateDelta := Distance(xyCoord[id2*2] - xyCoord[id1*2], xyCoord[id2*2+1] - xyCoord[id1*2+1]); |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
441 |
calculateDelta := int2hwFloat(trunc(sqrt(Power(finger2.x-finger1.x, 2) + Power(finger2.y-finger1.y, 2)))); |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
442 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
443 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
444 |
// Under the premise that all pointer ids in pointerIds:SDL_FingerId are pack to the far left. |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
445 |
// If the pointer to be ignored is not pointerIds[0] the second must be there |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
446 |
function getSecondFinger(finger: Touch_Finger): Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
447 |
begin |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
448 |
if fingers[0].id = finger.id then getSecondFinger := fingers[0] |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
449 |
else getSecondFinger := fingers[1]; |
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 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
452 |
procedure initModule; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
453 |
var |
5609
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
454 |
finger: Touch_Finger; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
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
|
459 |
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
|
460 |
|
31bd6e30df02
Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents:
5599
diff
changeset
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
|
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
465 |
setLength(fingers, 5); |
9d66611e4d0a
Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents:
5605
diff
changeset
|
466 |
for finger in fingers do finger.id := -1; |
5579
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
467 |
end; |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
468 |
|
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
469 |
begin |
3176ee8a9d94
uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff
changeset
|
470 |
end. |