hedgewars/uStore.pas
author unc0rr
Sat, 31 Dec 2005 13:45:09 +0000
changeset 35 9367f246fb5f
parent 30 794e98e11b66
child 37 2b7f2a43b999
permissions -rw-r--r--
- New rope - Increased speed in windowed mode - Surfaces with alpha channel blit poperly in windowed mode - +1 land template
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     2
 * Hedgewars, a worms-like game
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     3
 * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     6
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     9
 * with the Software without restriction, including without limitation the
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    12
 * furnished to do so, subject to the following conditions:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    15
 *    this list of conditions and the following disclaimer.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
 *    and/or other materials provided with the distribution.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
 *    derived from this software without specific prior written permission.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
unit uStore;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
interface
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    36
uses uConsts, uTeams, SDLh;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    37
{$INCLUDE options.inc}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    38
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
type PRangeArray = ^TRangeArray;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
     TRangeArray = array[byte] of record
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
                                  Left, Right: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    42
                                  end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
procedure StoreInit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
procedure StoreLoad;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
procedure StoreRelease;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    48
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    49
procedure DrawSprite (Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    50
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    51
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    53
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    54
procedure DrawExplosion(X, Y, Radius: integer);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
procedure DrawLineExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
procedure RenderHealth(var Hedgehog: THedgehog);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    57
function  RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    58
procedure AddProgress;
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
    59
function  LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    60
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
var PixelFormat: PSDL_PixelFormat;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
 SDLPrimSurface: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
implementation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
uses uMisc, uIO, uConsole, uLand;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    66
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
var StoreSurface,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    68
     TempSurface,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    69
       HHSurface: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    70
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
procedure DrawExplosion(X, Y, Radius: integer);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    72
var ty, tx: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    73
    p: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    75
for ty:= max(-Radius, -y) to min(radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
    for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
        Land[ty + y, tx]:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    78
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
if SDL_MustLock(LandSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
   SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    81
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    82
p:= Longword(LandSurface.pixels);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    83
case LandSurface.format.BytesPerPixel of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    84
     1: ;// not supported
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    85
     2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    86
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    87
                PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    88
     3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    89
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    90
                begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    91
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    92
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    93
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    94
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    95
     4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    96
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    97
                PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    98
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    99
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   100
inc(Radius, 4);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   101
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   102
case LandSurface.format.BytesPerPixel of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   103
     1: ;// not supported
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
     2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   105
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   106
               if PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^ <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   107
                  PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   108
     3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   109
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   110
                if (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   111
                or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   112
                or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   113
                then begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   115
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   116
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   117
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   118
     4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   119
            for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
                if PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^ <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   121
                   PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   122
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   123
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   124
if SDL_MustLock(LandSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   125
   SDL_UnlockSurface(LandSurface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   127
SDL_UpdateRect(LandSurface, X - Radius, Y - Radius, Radius * 2, Radius * 2)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   128
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   129
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   130
procedure DrawLineExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   131
var tx, ty, i, p: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   132
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   133
if SDL_MustLock(LandSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   134
   SDL_LockSurface(LandSurface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   135
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   136
p:= Longword(LandSurface.pixels);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   137
for i:= 0 to Pred(Count) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   138
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   139
    case LandSurface.format.BytesPerPixel of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   140
     1: ;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   141
     2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   142
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   143
                PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   144
     3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   145
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
                begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   147
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   148
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   149
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   150
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   151
     4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   152
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   153
                PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
    inc(y, dY)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
inc(Radius, 4);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   159
dec(y, Count*dY);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   160
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   161
for i:= 0 to Pred(Count) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   162
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   163
    case LandSurface.format.BytesPerPixel of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   164
     1: ;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   165
     2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   166
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
               if PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^ <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   168
                  PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   169
     3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   170
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   171
                if (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   172
                or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   173
                or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^ <> 0)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   174
                then begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   175
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   176
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   177
                PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   178
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   179
     4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   180
            for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   181
                if PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^ <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   182
                   PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   183
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   184
    inc(y, dY)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   185
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   186
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   187
if SDL_MustLock(LandSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
   SDL_UnlockSurface(LandSurface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   189
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   190
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
procedure StoreInit;
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   192
var r: TSDL_Rect;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   193
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   194
StoreSurface  := SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   195
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true);
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   196
r.x:= 0;
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   197
r.y:= 0;
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   198
r.w:= 576;
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   199
r.h:= 1024;
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   200
SDL_FillRect(StoreSurface, @r, 0);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   201
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   202
TempSurface   := SDL_CreateRGBSurface(SDL_HWSURFACE, 724, 320, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   203
TryDo(  TempSurface <> nil, errmsgCreateSurface + ': temp'  , true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   204
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   205
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   206
//TryDo(SDL_SetColorKey(SpriteSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   207
TryDo(SDL_SetColorKey(  TempSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   208
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   209
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   210
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   211
var tmpsurf: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   212
    rr: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   213
begin
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   214
  tmpsurf:= LoadImage(Filename, false);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   215
  rr.x:= X;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   216
  rr.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   217
  SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   218
  SDL_FreeSurface(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   219
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   220
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   221
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   222
var w, h: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   223
    tmpsurf: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   224
    clr: TSDL_Color;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   225
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   226
TTF_SizeText(Fontz[Font].Handle, PChar(s), w, h);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   227
Result.x:= X;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   228
Result.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   229
Result.w:= w + 6;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   230
Result.h:= h + 6;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   231
SDL_FillRect(Surface, @Result, 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   232
Result.w:= 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   233
Result.y:= Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   234
Result.h:= h + 4;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   235
SDL_FillRect(Surface, @Result, cWhiteColor);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   236
Result.x:= X + w + 5;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   237
SDL_FillRect(Surface, @Result, cWhiteColor);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   238
Result.x:= X + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   239
Result.w:= w + 4;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   240
Result.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   241
Result.h:= 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   242
SDL_FillRect(Surface, @Result, cWhiteColor);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   243
Result.y:= Y + h + 5;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   244
SDL_FillRect(Surface, @Result, cWhiteColor);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   245
Result.x:= X + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   246
Result.y:= Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   247
Result.h:= h + 4;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   248
SDL_FillRect(Surface, @Result, cColorNearBlack);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   249
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   250
tmpsurf:= TTF_RenderText_Blended(Fontz[Font].Handle, PChar(s), clr);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   251
Result.x:= X + 3;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   252
Result.y:= Y + 3;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   253
SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   254
SDL_FreeSurface(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   255
Result.x:= X;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   256
Result.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   257
Result.w:= w + 6;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   258
Result.h:= h + 6
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   259
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   260
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   261
procedure StoreLoad;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   262
var i: TStuff;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   263
    ii: TSprite;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   264
    fi: THWFont;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   265
    s: string;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   266
    tmpsurf: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   267
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   268
    procedure WriteNames(Font: THWFont);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   269
    var Team: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   270
        i: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   271
        r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   272
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   273
    r.x:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   274
    r.y:= 272;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   275
    Team:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   276
    while Team<>nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   277
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   278
      r.w:= 1968;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   279
      r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.TeamName);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   280
      Team.NameRect:= r;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   281
      inc(r.y, r.h);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   282
      for i:= 0 to 7 do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   283
          if Team.Hedgehogs[i].Gear<>nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   284
             begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   285
             r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.Hedgehogs[i].Name);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   286
             Team.Hedgehogs[i].NameRect:= r;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   287
             inc(r.y, r.h)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   288
             end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   289
      Team:= Team.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   290
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   291
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   292
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   293
    procedure MakeCrossHairs;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   294
    var Team: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   295
        r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   296
        tmpsurf: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   297
        s: string;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   298
        TransColor: Longword;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   299
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   300
    r.x:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   301
    r.y:= 256;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   302
    r.w:= 16;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   303
    r.h:= 16;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   304
    s:= Pathz[ptGraphics] + cCHFileName;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   305
    WriteToConsole(msgLoading + s + ' ');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   306
    tmpsurf:= IMG_Load(PChar(s));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   307
    TryDo(tmpsurf <> nil, msgFailed, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   308
    WriteLnToConsole(msgOK);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   309
    TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   310
    TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   311
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   312
    Team:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   313
    while Team<>nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   314
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   315
      SDL_FillRect(StoreSurface, @r, Team.Color);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   316
      SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   317
      Team.CrossHairRect:= r;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   318
      inc(r.x, 16);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   319
      Team:= Team.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   320
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   321
      
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   322
    SDL_FreeSurface(tmpsurf)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   323
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   324
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   325
    procedure InitHealth;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   326
    var p: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   327
        i, t: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   328
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   329
    p:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   330
    t:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   331
    while p <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   332
          begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   333
          for i:= 0 to cMaxHHIndex do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   334
              if p.Hedgehogs[i].Gear <> nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   335
                 begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   336
                 p.Hedgehogs[i].HealthRect.y:= t;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   337
                 RenderHealth(p.Hedgehogs[i]);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   338
                 inc(t, p.Hedgehogs[i].HealthRect.h)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   339
                 end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   340
          p:= p.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   341
          end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   342
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   343
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   344
    procedure LoadGraves;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   345
    var p: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   346
        l: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   347
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   348
    p:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   349
    l:= 512;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   350
    while p <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   351
          begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   352
          dec(l, 32);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   353
          if p.GraveName = '' then p.GraveName:= 'Simple';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   354
          LoadToSurface(Pathz[ptGraves] + p.GraveName + '.png', StoreSurface, l, 512);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   355
          p.GraveRect.x:= l;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   356
          p.GraveRect.y:= 512;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   357
          p.GraveRect.w:= 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   358
          p.GraveRect.h:= 256;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   359
          p:= p.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   360
          end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   361
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   362
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   363
    procedure GetSkyColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   364
    var p: Longword;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   365
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   366
    if SDL_MustLock(StoreSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   367
       SDLTry(SDL_LockSurface(StoreSurface) >= 0, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   368
    p:= Longword(StoreSurface.pixels) + Word(StuffPoz[sSky].x) * StoreSurface.format.BytesPerPixel;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   369
    case StoreSurface.format.BytesPerPixel of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   370
         1: cSkyColor:= PByte(p)^;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   371
         2: cSkyColor:= PWord(p)^;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   372
         3: cSkyColor:= (PByte(p)^) or (PByte(p + 1)^ shl 8) or (PByte(p + 2)^ shl 16);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   373
         4: cSkyColor:= PLongword(p)^;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   374
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   375
    if SDL_MustLock(StoreSurface) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   376
       SDL_UnlockSurface(StoreSurface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   377
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   378
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   379
    procedure GetExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   380
    var f: textfile;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   381
        c: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   382
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   383
    s:= Pathz[ptThemeCurrent] + cThemeCFGFilename;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   384
    WriteToConsole(msgLoading + s + ' ');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   385
    AssignFile(f, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   386
    {$I-}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   387
    Reset(f);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   388
    Readln(f, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   389
    Closefile(f);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   390
    {$I+}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   391
    TryDo(IOResult = 0, msgFailed, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   392
    WriteLnToConsole(msgOK);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   393
    val(s, cExplosionBorderColor, c);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   394
    if cFullScreen then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   395
    cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   396
                                                    (cExplosionBorderColor shr 8) and $FF,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   397
                                                     cExplosionBorderColor and $FF)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   398
    else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   399
    cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   400
                                                           (cExplosionBorderColor shr 8) and $FF,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   401
                                                            cExplosionBorderColor and $FF)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   402
    end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   403
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   404
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   405
for fi:= Low(THWFont) to High(THWFont) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   406
    with Fontz[fi] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   407
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   408
         s:= Pathz[ptFonts] + Name;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   409
         WriteToConsole(msgLoading + s + ' ');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   410
         Handle:= TTF_OpenFont(PChar(s), Height);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   411
         TryDo(Handle <> nil, msgFailed, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   412
         WriteLnToConsole(msgOK)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   413
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   414
AddProgress;
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   415
//s:= Pathz[ptMapCurrent] + cLandFileName;
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   416
//WriteToConsole(msgLoading + s + ' ');         
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   417
//tmpsurf:= IMG_Load(PChar(s));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   418
tmpsurf:= LandSurface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   419
TryDo(tmpsurf <> nil, msgFailed, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   420
if cFullScreen then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   421
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   422
   LandSurface:= SDL_DisplayFormat(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   423
   SDL_FreeSurface(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   424
   end else LandSurface:= tmpsurf;
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   425
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   426
WriteLnToConsole(msgOK);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   427
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   428
GetExplosionBorderColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   429
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   430
AddProgress;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   431
for i:= Low(TStuff) to High(TStuff) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   432
    LoadToSurface(Pathz[StuffLoadData[i].Path] + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   433
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   434
AddProgress;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   435
WriteNames(fnt16);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   436
MakeCrosshairs;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   437
LoadGraves;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   438
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   439
GetSkyColor;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   440
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   441
AddProgress;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   442
for ii:= Low(TSprite) to High(TSprite) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   443
    with SpritesData[ii] do
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   444
         Surface:= LoadImage(Pathz[Path] + FileName, hasAlpha);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   445
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   446
AddProgress;
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   447
tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName, false);
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   448
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   449
HHSurface:= SDL_DisplayFormat(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   450
SDL_FreeSurface(tmpsurf);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   451
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   452
InitHealth;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   453
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   454
{$IFDEF DUMP}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   455
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   456
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   457
SDL_SaveBMP_RW(TempSurface, SDL_RWFromFile('TempSurface.bmp', 'wb'), 1);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   458
{$ENDIF}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   459
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   460
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   461
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   462
var rr: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   463
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   464
rr.x:= X;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   465
rr.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   466
rr.w:= r.w;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   467
rr.h:= r.h;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   468
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   469
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   470
   Writeln('Blit: ', SDL_GetError);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   471
   exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   472
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   473
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   474
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   475
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   476
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   477
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   478
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   479
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   480
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   481
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   482
r.y:= r.y + Height * Position;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   483
r.h:= Height;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   484
DrawFromRect(X, Y, @r, StoreSurface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   485
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   486
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   487
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   488
var r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   489
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   490
r.x:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   491
r.w:= SpritesData[Sprite].Width;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   492
r.y:= Position * SpritesData[Sprite].Height;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   493
r.h:= SpritesData[Sprite].Height;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   494
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   495
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   496
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   497
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   498
var clr: TSDL_Color;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   499
    tmpsurf: PSDL_Surface;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   500
    r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   501
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   502
r.x:= X;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   503
r.y:= Y;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   504
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   505
tmpsurf:= TTF_RenderText_Solid(Fontz[Font].Handle, PChar(s), clr);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   506
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   507
SDL_FreeSurface(tmpsurf)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   508
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   509
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   510
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   511
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   512
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   513
DrawFromRect(X, Y, @r, LandSurface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   514
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   515
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   516
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   517
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   518
if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface,  Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   519
                else DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   520
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   521
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   522
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   523
var r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   524
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   525
r.x:= Step * 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   526
r.y:= Pos * 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   527
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   528
r.w:= 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   529
r.h:= 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   530
DrawFromRect(X, Y, @r, HHSurface, Surface)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   531
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   532
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   533
procedure StoreRelease;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   534
var ii: TSprite;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   535
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   536
for ii:= Low(TSprite) to High(TSprite) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   537
    SDL_FreeSurface(SpritesData[ii].Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   538
SDL_FreeSurface(  HHSurface  );
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   539
SDL_FreeSurface(TempSurface  );
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   540
SDL_FreeSurface(LandSurface  );
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   541
SDL_FreeSurface(StoreSurface )
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   542
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   543
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   544
procedure RenderHealth(var Hedgehog: THedgehog);
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   545
var s: string[15];
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   546
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   547
str(Hedgehog.Gear.Health, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   548
Hedgehog.HealthRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   549
if Hedgehog.Gear.Damage > 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   550
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   551
   str(Hedgehog.Gear.Damage, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   552
   Hedgehog.HealthTagRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x + Hedgehog.HealthRect.w, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   553
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   554
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   555
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   556
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   557
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   558
Result:= WriteInRoundRect(TempSurface, 64, Pos * Fontz[fntBig].Height, Color, fntBig, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   559
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   560
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   561
procedure AddProgress;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   562
const Step: Longword = 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   563
      ProgrSurf: PSDL_Surface = nil;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   564
      MaxCalls = 10; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   565
var r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   566
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   567
if Step = 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   568
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   569
   WriteToConsole(msgLoading + 'progress sprite... ');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   570
   ProgrSurf:= IMG_Load(PChar(string('Data/Graphics/BigDigits.png')));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   571
   SDLTry(ProgrSurf <> nil, true);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   572
   WriteLnToConsole(msgOK)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   573
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   574
SDL_FillRect(SDLPrimSurface, nil, 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   575
r.x:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   576
r.w:= 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   577
r.h:= 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   578
r.y:= Step * 32;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   579
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   580
SDL_Flip(SDLPrimSurface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   581
inc(Step);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   582
if Step = MaxCalls then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   583
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   584
   WriteLnToConsole('Freeing progress surface... ');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   585
   SDL_FreeSurface(ProgrSurf)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   586
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   587
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   588
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   589
function  LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   590
var tmpsurf: PSDL_Surface;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   591
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   592
WriteToConsole(msgLoading + filename + '... ');
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   593
tmpsurf:= IMG_Load(PChar(filename));
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   594
TryDo(tmpsurf <> nil, msgFailed, true);
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   595
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   596
if cFullScreen then
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   597
   begin
35
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   598
   if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
9367f246fb5f - New rope
unc0rr
parents: 30
diff changeset
   599
               else Result:= SDL_DisplayFormat(tmpsurf);
30
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   600
   SDL_FreeSurface(tmpsurf);
794e98e11b66 - Fixed slow sprite blt
unc0rr
parents: 4
diff changeset
   601
   end else Result:= tmpsurf;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   602
WriteLnToConsole(msgOK)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   603
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   604
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   605
end.