hedgewars/uTouch.pas
author Xeli
Fri, 16 Sep 2011 17:36:05 +0200
branchhedgeroid
changeset 5828 667fb58d7f18
parent 5733 5ab22736bdb6
child 5938 c186c454779d
permissions -rw-r--r--
Changed firebutton, parameters in uTouch might need to be tweaked some more
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     1
(*
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     2
 * Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    17
 *)
ea796c83ea47 added licenses
Xeli
parents: 5619
diff changeset
    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);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    63
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    64
var
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    65
    fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    66
        
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    67
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
    68
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    69
    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
    70
    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
    71
    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
    72
    
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    73
    pointerCount : Longword;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
    74
    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
    75
    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
    76
    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
    77
88f43becefe3 added low jump, you can low-jump by double tapping the right or left side of the screen
Xeli
parents: 5615
diff changeset
    78
    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
    79
    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
    80
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    81
    //Pinch to zoom 
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    82
    pinchSize : hwFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    83
    baseZoomValue: GLFloat;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    84
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
    85
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
    86
    //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
    87
    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
    88
    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
    89
    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
    90
    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
    91
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    92
    //moving
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    93
    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
    94
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
    95
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    96
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
    97
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
    98
    finger: PTouch_Finger;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
    99
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
   100
    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
   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
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   146
            moveCursor:= false;
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
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
5733
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, secondFinger: PTouch_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;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   157
    tmpX, tmpY: LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   158
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   159
    finger:= findFinger(pointerId);
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   160
    tmpX := convertToCursor(cScreenWidth, x);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   161
    tmpY := convertToCursor(cScreenHeight, y);
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
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   163
    if moveCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   164
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   165
        if invertCursor then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   166
        begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   167
            CursorPoint.X := CursorPoint.X + (finger^.x - tmpX);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   168
            CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   169
        end
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   170
        else
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   171
        begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   172
            CursorPoint.X := CursorPoint.X - (finger^.x - tmpX);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   173
            CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   174
        end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   175
        finger^.x := tmpX;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   176
        finger^.y := tmpY;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   177
        exit //todo change into switch rather than ugly ifs
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   178
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   179
    
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   180
    finger^.x := tmpX;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   181
    finger^.y := tmpY;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   182
    
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   183
    if aiming then 
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   184
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   185
        aim(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   186
        exit
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   187
    end;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   188
    if pointerCount = 2 then
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   189
    begin
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   190
       secondFinger := getSecondFinger(finger^);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   191
       currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   192
       zoom := currentPinchDelta/cScreenWidth;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   193
       ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   194
       if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   195
       if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   196
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   197
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   198
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   199
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
   200
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
   201
    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
   202
    stopFiring:= true;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   203
    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
   204
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   205
    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
   206
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   207
        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
   208
        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
   209
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   210
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   211
    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
   212
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   213
        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
   214
        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
   215
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   216
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   217
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
   218
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
   219
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
   220
    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
   221
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
   222
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   223
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
   224
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
   225
    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
   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
    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
   228
    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
   229
    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
   230
    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
   231
    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
   232
        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
   233
        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
   234
        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
   235
    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
   236
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   237
    if bShowAmmoMenu then 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   238
    begin
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   239
        doPut(CursorPoint.X, CursorPoint.Y, false); 
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   240
        exit
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   241
    end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   242
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   243
    if isOnCurrentHog(finger) then
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   244
    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
   245
        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
   246
        exit;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   247
    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
   248
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   249
    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
   250
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   251
        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
   252
        exit;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   253
    end;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   254
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   255
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   256
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
   257
var 
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   258
    xCursor, yCursor, index : LongInt;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   259
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   260
    //Check array sizes
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   261
    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
   262
    begin
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   263
        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
   264
        for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   265
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   266
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   267
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   268
    xCursor := convertToCursor(cScreenWidth, x);
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   269
    yCursor := convertToCursor(cScreenHeight, y);
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   270
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   271
    //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
   272
    //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
   273
    fingers[pointerCount].id := id;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   274
    fingers[pointerCount].historicalX := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   275
    fingers[pointerCount].historicalY := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   276
    fingers[pointerCount].x := xCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   277
    fingers[pointerCount].y := yCursor;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   278
    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
   279
 
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   280
    addFinger:= @fingers[pointerCount];
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   281
    inc(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   282
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   283
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   284
procedure deleteFinger(id: SDL_FingerId);
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   285
var
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   286
    index : Longint;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   287
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   288
    
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   289
    dec(pointerCount);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   290
    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
   291
    begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   292
         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
   293
         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
   294
             //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
   295
             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
   296
                 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
   297
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   298
             //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
   299
             //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
   300
             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
   301
             begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   302
                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
   303
                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
   304
                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
   305
                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
   306
                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
   307
                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
   308
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   309
                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
   310
             end
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   311
             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
   312
             break;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   313
         end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   314
    end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   315
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   316
end;
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   317
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
   318
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
   319
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
   320
    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
   321
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
   322
    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
   323
    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
   324
    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
   325
        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
   326
        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
   327
            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
   328
            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
   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 := 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
   332
            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
   333
            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
   334
                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
   335
                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
   336
                    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
   337
                    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
   338
                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
   339
        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
   340
    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
   341
    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
   342
    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
   343
        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
   344
        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
   345
    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
   346
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   347
    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
   348
    begin
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('-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
   350
        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
   351
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   352
    
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   353
    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
   354
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   355
        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
   356
        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
   357
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   358
 
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   359
    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
   360
    begin
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   361
        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
   362
        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
   363
    end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   364
    
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
   365
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
   366
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   367
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
   368
var
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   369
    index: LongWord;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   370
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
   371
   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
   372
       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
   373
       begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   374
           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
   375
           break;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   376
       end;
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   377
end;
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   378
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   379
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
   380
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
   381
    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
   382
    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
   383
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
   384
    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
   385
    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
   386
        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
   387
        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
   388
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   389
        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
   390
        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
   391
        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
   392
        
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
        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
   394
        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
   395
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
        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
   397
        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
   398
        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
   399
        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
   400
        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
   401
            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
   402
            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
   403
        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
   404
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
   405
    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
   406
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
   407
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
   408
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
   409
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
   410
    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
   411
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
   412
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   413
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
   414
begin
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   415
    isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop);
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   416
end;
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   417
5615
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   418
function isOnCrosshair(finger: Touch_Finger): boolean;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   419
var
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   420
    x,y,fingerX, fingerY : hwFloat;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   421
begin
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   422
    x := int2hwFloat(CrosshairX);
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   423
    y := int2hwFloat(CrosshairY);
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   424
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   425
    convertToWorldCoord(fingerX, fingerY, finger);
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   426
    isOnCrosshair:= Distance(fingerX-x, fingerY-y) < _20;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
diff changeset
   427
end;
104f69e798bb changed aiming to be triggered when touching the crosshair
Xeli
parents: 5609
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
function isOnCurrentHog(finger: Touch_Finger): boolean;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   430
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
   431
    x,y, fingerX, fingerY : hwFloat;
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   432
begin
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   433
    x := CurrentHedgehog^.Gear^.X;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   434
    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
   435
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   436
    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
   437
    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
   438
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
   439
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   440
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
   441
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
   442
//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
   443
    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
   444
//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
   445
    y := int2hwFloat(finger.y-WorldDy);
5595
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   446
end;
480d451152a5 open ammo when clicking the current hog
Xeli
parents: 5589
diff changeset
   447
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   448
//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
   449
function fingerHasMoved(finger: Touch_Finger): boolean;
5589
b95d10c82f7f Now able to select a weapon
Xeli
parents: 5579
diff changeset
   450
begin
5609
9d66611e4d0a Introduced a Touch_Finger type to replace the arrays with coords, makes cleaner code
Xeli
parents: 5605
diff changeset
   451
    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
   452
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   453
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 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
   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
    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
   457
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   458
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   459
// 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
   460
// 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
   461
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
   462
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
   463
    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
   464
    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
   465
end;
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   466
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   467
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
   468
begin
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   469
    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
   470
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   471
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   472
procedure initModule;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   473
var
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   474
    index, uRenderCoordScaleX, uRenderCoordScaleY: Longword;
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   475
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
   476
    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
   477
    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
   478
    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
   479
    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
   480
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
   481
    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
   482
    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
   483
    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
   484
    
5733
5ab22736bdb6 Fixed a major bug (related to pointers) which also solves the stuttering when zooming in and out
Xeli
parents: 5621
diff changeset
   485
    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
   486
    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
   487
        fingers[index].id := nilFingerId;
5828
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   488
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   489
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   490
    uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   491
    fireButtonLeft := Round(cScreenWidth*0.01);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   492
    fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4));
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   493
    fireButtonBottom := Round(cScreenHeight*0.99);
667fb58d7f18 Changed firebutton, parameters in uTouch might need to be tweaked some more
Xeli
parents: 5733
diff changeset
   494
    fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4);
5579
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   495
end;
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   496
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   497
begin
3176ee8a9d94 uTouch, has cursor move, zoom and click or tap to open the ammo menu
Xeli
parents:
diff changeset
   498
end.