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