20 |
20 |
21 unit uTouch; |
21 unit uTouch; |
22 |
22 |
23 interface |
23 interface |
24 |
24 |
25 uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit; |
25 uses sysutils, math, uConsole, uVariables, SDLh, uFloat, uConsts, uIO, GLUnit; |
26 |
26 |
27 // TODO: this type should be Int64 |
27 // TODO: this type should be Int64 |
28 // TODO: this type should be named TSDL_FingerId |
28 // TODO: this type should be named TSDL_FingerId |
29 type SDL_FingerId = LongInt; |
29 type SDL_FingerId = LongInt; |
30 |
30 |
112 end; |
112 end; |
113 |
113 |
114 if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, finger^) then |
114 if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, finger^) then |
115 begin |
115 begin |
116 stopFiring:= false; |
116 stopFiring:= false; |
117 ParseCommand('+attack', true); |
117 spaceKey:= true; |
118 exit; |
118 exit; |
119 end; |
119 end; |
120 if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, finger^) then |
120 if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, finger^) then |
121 begin |
121 begin |
122 ParseCommand('+left', true); |
122 leftKey:= true; |
123 walkingLeft := true; |
123 walkingLeft := true; |
124 exit; |
124 exit; |
125 end; |
125 end; |
126 if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, finger^) then |
126 if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, finger^) then |
127 begin |
127 begin |
128 ParseCommand('+right', true); |
128 rightKey:= true; |
129 walkingRight:= true; |
129 walkingRight:= true; |
130 exit; |
130 exit; |
131 end; |
131 end; |
132 if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then |
132 if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then |
133 begin |
133 begin |
134 ParseCommand('+up', true); |
134 upKey:= true; |
135 aimingUp:= true; |
135 aimingUp:= true; |
136 exit; |
136 exit; |
137 end; |
137 end; |
138 if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then |
138 if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then |
139 begin |
139 begin |
140 ParseCommand('+down', true); |
140 downKey:= true; |
141 aimingDown:= true; |
141 aimingDown:= true; |
142 exit; |
142 exit; |
143 end; |
143 end; |
144 |
144 |
145 if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, finger^) then |
145 if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, finger^) then |
146 begin |
146 begin |
147 ParseCommand('hjump', true); |
147 enterKey:= true; |
148 exit; |
148 exit; |
149 end; |
149 end; |
150 if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then |
150 if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then |
151 begin |
151 begin |
152 ParseCommand('ljump', true); |
152 backspaceKey:= true; |
153 exit; |
153 exit; |
154 end; |
154 end; |
155 moveCursor:= not bShowAmmoMenu; |
155 moveCursor:= not bShowAmmoMenu; |
156 end; |
156 end; |
157 2: |
157 2: |
222 |
222 |
223 deleteFinger(pointerId); |
223 deleteFinger(pointerId); |
224 |
224 |
225 if walkingLeft then |
225 if walkingLeft then |
226 begin |
226 begin |
227 ParseCommand('-left', true); |
227 leftKey:= false; |
228 walkingLeft := false; |
228 walkingLeft := false; |
229 end; |
229 end; |
230 |
230 |
231 if walkingRight then |
231 if walkingRight then |
232 begin |
232 begin |
233 ParseCommand('-right', true); |
233 rightKey:= false; |
234 walkingRight := false; |
234 walkingRight := false; |
235 end; |
235 end; |
236 |
236 |
237 if aimingUp then |
237 if aimingUp then |
238 begin |
238 begin |
239 ParseCommand('-up', true); |
239 upKey:= false; |
240 aimingUp:= false; |
240 aimingUp:= false; |
241 end; |
241 end; |
242 if aimingDown then |
242 if aimingDown then |
243 begin |
243 begin |
244 ParseCommand('-down', true); |
244 downKey:= false; |
245 aimingDown:= false; |
245 aimingDown:= false; |
246 end; |
246 end; |
247 end; |
247 end; |
248 |
248 |
249 procedure onTouchDoubleClick(finger: Touch_Finger); |
249 procedure onTouchDoubleClick(finger: Touch_Finger); |
250 begin |
250 begin |
251 finger := finger;//avoid compiler hint |
251 finger := finger;//avoid compiler hint |
252 //ParseCommand('ljump', true); |
|
253 end; |
252 end; |
254 |
253 |
255 procedure onTouchClick(finger: Touch_Finger); |
254 procedure onTouchClick(finger: Touch_Finger); |
256 begin |
255 begin |
257 if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then |
256 if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then |
258 begin |
257 begin |
259 onTouchDoubleClick(finger); |
258 onTouchDoubleClick(finger); |
260 timeSinceClick:= -1; |
259 timeSinceClick:= 0;//we make an assumption there won't be an 'click' in the first 300 ticks(milliseconds) |
261 exit; |
260 exit; |
262 end; |
261 end; |
263 |
262 |
264 xTouchClick:= finger.x; |
263 xTouchClick:= finger.x; |
265 yTouchClick:= finger.y; |
264 yTouchClick:= finger.y; |
282 if isOnCurrentHog(finger) then |
281 if isOnCurrentHog(finger) then |
283 begin |
282 begin |
284 bShowAmmoMenu := true; |
283 bShowAmmoMenu := true; |
285 exit; |
284 exit; |
286 end; |
285 end; |
287 |
|
288 {if finger.y < topButtonBoundary then |
|
289 begin |
|
290 ParseCommand('hjump', true); |
|
291 exit; |
|
292 end;} |
|
293 end; |
286 end; |
294 |
287 |
295 function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; |
288 function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger; |
296 var |
289 var |
297 xCursor, yCursor, index : LongInt; |
290 xCursor, yCursor, index : LongInt; |
375 deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; |
368 deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; |
376 if (deltaAngle = 0) then |
369 if (deltaAngle = 0) then |
377 begin |
370 begin |
378 if aimingUp then |
371 if aimingUp then |
379 begin |
372 begin |
380 ParseCommand('-up', true); |
373 upKey:= false; |
381 aimingUp:= false; |
374 aimingUp:= false; |
382 end; |
375 end; |
383 if aimingDown then |
376 if aimingDown then |
384 begin |
377 begin |
385 ParseCommand('-down', true); |
378 downKey:= false; |
386 aimingDown:= false; |
379 aimingDown:= false; |
387 end |
380 end |
388 end |
381 end |
389 else |
382 else |
390 begin |
383 begin |
391 if (deltaAngle < 0) then |
384 if (deltaAngle < 0) then |
392 begin |
385 begin |
393 if aimingUp then |
386 if aimingUp then |
394 begin |
387 begin |
395 ParseCommand('-up', true); |
388 upKey:= false; |
396 aimingUp:= false; |
389 aimingUp:= false; |
397 end; |
390 end; |
398 ParseCommand('+down', true); |
391 downKey:= true; |
399 aimingDown:= true; |
392 aimingDown:= true; |
400 end |
393 end |
401 else |
394 else |
402 begin |
395 begin |
403 if aimingDown then |
396 if aimingDown then |
404 begin |
397 begin |
405 ParseCommand('-down', true); |
398 downKey:= false; |
406 aimingDown:= false; |
399 aimingDown:= false; |
407 end; |
400 end; |
408 ParseCommand('+up', true); |
401 upKey:= true; |
409 aimingUp:= true; |
402 aimingUp:= true; |
410 end; |
403 end; |
411 end; |
404 end; |
412 end |
405 end |
413 else |
406 else |
414 begin |
407 begin |
415 if aimingUp then |
408 if aimingUp then |
416 begin |
409 begin |
417 ParseCommand('-up', true); |
410 upKey:= false; |
418 aimingUp:= false; |
411 aimingUp:= false; |
419 end; |
412 end; |
420 if aimingDown then |
413 if aimingDown then |
421 begin |
414 begin |
422 ParseCommand('-down', true); |
415 upKey:= false; |
423 aimingDown:= false; |
416 aimingDown:= false; |
424 end; |
417 end; |
425 end; |
418 end; |
426 |
419 |
427 if stopFiring then |
420 if stopFiring then |
428 begin |
421 begin |
429 ParseCommand('-attack', true); |
422 spaceKey:= false; |
430 stopFiring:= false; |
423 stopFiring:= false; |
431 end; |
424 end; |
432 |
425 |
433 if stopRight then |
426 if stopRight then |
434 begin |
427 begin |
435 stopRight := false; |
428 stopRight := false; |
436 ParseCommand('-right', true); |
429 rightKey:= false; |
437 end; |
430 end; |
438 |
431 |
439 if stopLeft then |
432 if stopLeft then |
440 begin |
433 begin |
441 stopLeft := false; |
434 stopLeft := false; |
442 ParseCommand('-left', true); |
435 leftKey:= false; |
443 end; |
436 end; |
444 |
437 |
445 end; |
438 end; |
446 |
439 |
447 function findFinger(id: SDL_FingerId): PTouch_Finger; |
440 function findFinger(id: SDL_FingerId): PTouch_Finger; |