hedgewars/uGearsHandlers.pas
author sheepluva
Fri, 17 Jan 2014 01:06:54 +0100
changeset 9998 736015b847e3
parent 9969 f27921b31b61
child 10015 4feced261c68
permissions -rw-r--r--
update copyright to 2014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     1
(*
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9969
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     4
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     8
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    13
 *
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    17
 *)
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    18
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    20
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    21
unit uGearsHandlers;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    22
interface
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    23
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    24
uses uTypes;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    25
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    26
function cakeStep(Gear: PGear): boolean;
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    27
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    28
implementation
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    29
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    30
uses SDLh, uFloat, uCollisions;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    31
7398
2b7b939014b5 Start TestCake
unc0rr
parents: 7370
diff changeset
    32
2b7b939014b5 Start TestCake
unc0rr
parents: 7370
diff changeset
    33
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    34
const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    35
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    36
procedure PrevAngle(Gear: PGear; dA: LongInt); inline;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    37
begin
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    38
    inc(Gear^.WDTimer);
7721
2b1ad418ba39 - Fix warnings and hints
unc0rr
parents: 7671
diff changeset
    39
    Gear^.Angle := (LongInt(Gear^.Angle) - dA) and 3
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    40
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    41
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    42
procedure NextAngle(Gear: PGear; dA: LongInt); inline;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    43
begin
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    44
    inc(Gear^.WDTimer);
7721
2b1ad418ba39 - Fix warnings and hints
unc0rr
parents: 7671
diff changeset
    45
    Gear^.Angle := (LongInt(Gear^.Angle) + dA) and 3
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    46
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    47
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    48
function cakeStep(Gear: PGear): boolean;
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    49
var
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    50
    xx, yy, xxn, yyn: LongInt;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    51
    dA: LongInt;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    52
begin
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    53
    dA := hwSign(Gear^.dX);
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    54
    xx := dirs[Gear^.Angle].x;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    55
    yy := dirs[Gear^.Angle].y;
7721
2b1ad418ba39 - Fix warnings and hints
unc0rr
parents: 7671
diff changeset
    56
    xxn := dirs[(LongInt(Gear^.Angle) + dA) and 3].x;
2b1ad418ba39 - Fix warnings and hints
unc0rr
parents: 7671
diff changeset
    57
    yyn := dirs[(LongInt(Gear^.Angle) + dA) and 3].y;
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    58
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    59
    if (xx = 0) then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    60
        if TestCollisionYwithGear(Gear, yy) <> 0 then
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    61
            PrevAngle(Gear, dA)
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    62
        else
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    63
            begin
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    64
            Gear^.Tag := 0;
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    65
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    66
            if TestCollisionXwithGear(Gear, xxn) <> 0 then
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    67
                Gear^.WDTimer:= 0;
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    68
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    69
            Gear^.Y := Gear^.Y + int2hwFloat(yy);
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    70
            if TestCollisionXwithGear(Gear, xxn) = 0 then
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    71
                begin
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    72
                Gear^.X := Gear^.X + int2hwFloat(xxn);
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    73
                NextAngle(Gear, dA)
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    74
                end
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    75
            end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    76
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    77
    if (yy = 0) then
9706
5178d2263521 return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents: 9080
diff changeset
    78
        if TestCollisionXwithGear(Gear, xx) <> 0 then
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    79
            PrevAngle(Gear, dA)
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    80
        else
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    81
            begin
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    82
            Gear^.Tag := 0;
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    83
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    84
            if TestCollisionYwithGear(Gear, yyn) <> 0 then
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    85
                Gear^.WDTimer:= 0;
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    86
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    87
            Gear^.X := Gear^.X + int2hwFloat(xx);
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    88
            if TestCollisionYwithGear(Gear, yyn) = 0 then
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    89
                begin
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    90
                Gear^.Y := Gear^.Y + int2hwFloat(yyn);
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    91
                NextAngle(Gear, dA)
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    92
                end
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    93
            end;
9969
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    94
f27921b31b61 Cake falls when loses ground
unc0rr
parents: 9706
diff changeset
    95
    cakeStep:= Gear^.WDTimer < 4
7370
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    96
end;
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    97
d50b874e7ee8 Introduce uGearsHandlers.pas, for now only part of cake handlers is moved there
unc0rr
parents:
diff changeset
    98
end.