Code of Globals Unit

Code of Globals.pas

unit Globals;
{
    Copyright (c) 2014 Steven Binns

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
interface

uses
  CRT, INIFiles, SDL, SDL_GFX, SDL_IMAGE, SDL_MIXER, SDL_TTF, SYSUTILS;

procedure FILLEDRECTCOLOUR(x, y, w, h: integer; colour: int64);
procedure RECTCOLOUR(x, y, w, h: integer; colour: int64);
procedure Options();
procedure Store();
procedure TrainingHalls();
procedure RougeGear();
procedure DrawHats();
function dist_to_point(x1, y1, x2, y2: integer): integer;

type
  tMyRect = class(TObject)
  public
    x, y, Width, Height: integer;
    constructor Create(newx, newy, newwidth, newheight: integer);
    function getSDLRect(): pSDL_RECT;
  end;

var
  screen, fontface, surface: pSDL_SURFACE;
  test_event: pSDL_EVENT;
  font: pointer;
  playerpos: array [0..1] of integer;
  blinkpoints: array [0..4, 0..1] of integer;
  xspeed, yspeed, mousex, mousey, gamespeed, maxenrg, enrg, enrgcost,
    maxhp, hp, score, xp, pClass: integer;
  warping: boolean = False;
  begun: boolean = False;
  totalhalt: boolean = False;
  fullscreen: boolean = False;
  music: array [0..2] of pMIX_MUSIC;
  stats: array [0..2, 0..5] of integer;
  savefile: TINIFile;
  neww, newh: longint;
  hatinv, hatimg: array [0..20] of ansistring;

implementation

constructor tMyRect.Create(newx, newy, newwidth, newheight: integer);
begin
  x := newx;
  y := newy;
  Width := newwidth;
  Height := newheight;
end;

function tMyRect.getSDLRect(): pSDL_RECT; //Converts a tMyRect to a pSDL_RECT
var
  temp: pSDL_RECT;
begin
  new(temp);
  temp^.x := x;
  temp^.y := y;
  temp^.w := Width;
  temp^.h := Height;

  Result := temp;
end;

procedure FILLEDRECTCOLOUR(x, y, w, h: integer; colour: int64);
begin //Draws a coloured, filled rectangle
  SDL_FILLRECT(screen, tMyRect.Create(x, y, w, h).getSDLRECT(), colour);
end;

procedure RECTCOLOUR(x, y, w, h: integer; colour: int64);
begin //Draws a coloured empty rectangle
  SDL_FILLRECT(screen, tMyRect.Create(x, y, w, h).getSDLRECT(), colour);
  SDL_FILLRECT(screen, tMyRect.Create(x + 1, y + 1, w - 2, h - 2).getSDLRECT(), $00000000);
end;

procedure Options(); //Draws the menu and does the workings for the options menu
var
  exit: boolean = False;
  fontcolour: pSDL_COLOR;
  local_event: pSDL_EVENT;
  lmousex, lmousey, sliderx: integer;
  volumechanging: boolean = False;
begin
  new(fontcolour);
  new(local_event);
  sliderx := savefile.readInteger('GENERAL', 'volume', 365);
  fontcolour^.r := 0;
  fontcolour^.g := 255;
  fontcolour^.b := 0;
  while exit = False do
  begin
    if SDL_POLLEVENT(local_event) = 1 then
      case local_event^.type_ of
        SDL_MOUSEMOTION:
        begin
          lmousex := local_event^.motion.x;
          lmousey := local_event^.motion.y;
          if (lmousex < 230) or (lmousex > 560) or (lmousey < 375) or
            (lmousey > 405) then
            volumechanging := False;
          if volumechanging = True then
          begin
            sliderx := lmousex;
            if sliderx > 545 then
              sliderx := 545;
            if sliderx < 245 then
              sliderx := 245;
            MIX_VOLUMEMUSIC(round((sliderx - 245) / 3));
          end;
        end;
        SDL_MOUSEBUTTONUP: if (lmousex > 277) and (lmousex < 526) then
          begin
            if (lmousey > 245) and (lmousey < 290) then
              if fullscreen = True then
              begin
                screen := SDL_SETVIDEOMODE(800, 600, 32, SDL_SWSURFACE);
                fullscreen := False;
              end
              else
              begin
                screen := SDL_SETVIDEOMODE(800, 600, 32, SDL_FULLSCREEN);
                fullscreen := True;
              end;
            volumechanging := False;
            if (lmousey > 455) and (lmousey < 495) then
            begin
              exit := True;
              savefile.WriteInteger('GENERAL', 'volume', sliderx);
            end;
          end;
        SDL_MOUSEBUTTONDOWN: if (lmousex > 230) and (lmousex < 560) and
            (lmousey > 375) and (lmousey < 405) then
          begin
            volumechanging := True;
            sliderx := lmousex;
            if sliderx > 545 then
              sliderx := 545;
            if sliderx < 245 then
              sliderx := 245;
            MIX_VOLUMEMUSIC(round((sliderx - 245) / 3));
          end;
        SDL_KEYUP: if local_event^.key.keysym.sym = 27 then
          begin
            exit := True;
            savefile.WriteInteger('GENERAL', 'volume', sliderx);
          end;
      end;
    font := TTF_OPENFONT('Aethv2.ttf', 50);
    fontface := TTF_RENDERTEXT_SOLID(font, 'Options', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(275, 100, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 30);
    if (lmousex > 277) and (lmousex < 526) and (lmousey > 245) and (lmousey < 290) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Fullscreen', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(277, 250, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Fullscreen', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(277, 250, 200, 100).getSDLRect());
    end;

    fontface := TTF_RENDERTEXT_SOLID(font, 'Volume', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(325, 340, 200, 100).getSDLRect);

    if (lmousex > 277) and (lmousex < 526) and (lmousey > 455) and (lmousey < 495) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 460, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 460, 200, 100).getSDLRect());
    end;
    FILLEDRECTCOLOUR(230, 395, 330, 1, $00FF00);
    RECTCOLOUR(sliderx - 15, 375, 30, 40, $00FF00);
    FILLEDRECTCOLOUR(230, 375, 1, 40, $00FF00);
    FILLEDRECTCOLOUR(559, 375, 1, 40, $00FF00);
    SDL_FLIP(screen);
    FILLEDRECTCOLOUR(0, 0, 800, 600, $000000);
    SDL_DELAY(10);
  end;
end;

procedure Store(); //Draws the menu and deals with the workings of the store
var
  exit: boolean = False;
  fontcolour: pSDL_COLOR;
  local_event: pSDL_EVENT;
  lmousex, lmousey: integer;
begin
  new(fontcolour);
  new(local_event);
  fontcolour^.r := 0;
  fontcolour^.g := 255;
  fontcolour^.b := 0;
  while exit = False do
  begin
    if SDL_POLLEVENT(local_event) = 1 then
      case local_event^.type_ of
        SDL_MOUSEMOTION:
        begin
          lmousex := local_event^.motion.x;
          lmousey := local_event^.motion.y;
        end;
        SDL_MOUSEBUTTONUP:
        begin
          if (lmousex > 290) and (lmousex < 504) and (lmousey > 200) and
            (lmousey < 245) then ;//Hatshop();
          if (lmousex > 277) and (lmousex > 518) and (lmousey > 250) and
            (lmousey < 295) then ;//Perkshop();
          if (lmousex > 243) and (lmousex < 544) and (lmousey > 300) and (lmousey < 345) then
            TrainingHalls();
          if (lmousex > 350) and (lmousex < 450) and (lmousey > 350) and (lmousey < 395) then
            exit := True;
        end;
        SDL_KEYUP: if local_event^.key.keysym.sym = 27 then
                     exit := True;
      end;
    font := TTF_OPENFONT('Aethv2.ttf', 50);
    fontface := TTF_RENDERTEXT_SOLID(font, 'Store', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(295, 50, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 20);
    fontface := TTF_RENDERTEXT_SOLID(font, 'XP:', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 120, 200, 100).getSDLRect());
    fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(xp)), fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(55, 120, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 30);
    fontcolour^.g := 55;
    fontface := TTF_RENDERTEXT_SOLID(font, 'Hat Store', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(290, 200, 200, 100).getSDLRect());
    fontcolour^.g := 55;
    fontface := TTF_RENDERTEXT_SOLID(font, 'Perk Store', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(277, 250, 200, 100).getSDLRect());
    fontcolour^.g := 255;

    if (lmousex > 243) and (lmousex < 544) and (lmousey > 300) and (lmousey < 345) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Training Halls', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(243, 300, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Training Halls', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(243, 300, 200, 100).getSDLRect());
    end;
    if (lmousex > 290) and (lmousex < 504) and (lmousey > 350) and (lmousey < 395) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 350, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 350, 200, 100).getSDLRect());
    end;
    SDL_FLIP(screen);
    FILLEDRECTCOLOUR(0, 0, 800, 600, $000000);
    SDL_DELAY(10);
  end;
end;

procedure TrainingHalls();
//Draws the menu and deals with the workings of the upgrades menu
var
  exit: boolean = False;
  fontcolour: pSDL_COLOR;
  local_event: pSDL_EVENT;
  lmousex, lmousey: integer;
begin
  new(fontcolour);
  new(local_event);
  fontcolour^.r := 0;
  fontcolour^.g := 255;
  fontcolour^.b := 0;
  while exit = False do
  begin
    if SDL_POLLEVENT(local_event) = 1 then
      case local_event^.type_ of
        SDL_MOUSEMOTION:
        begin
          lmousex := local_event^.motion.x;
          lmousey := local_event^.motion.y;
        end;
        SDL_MOUSEBUTTONUP:
        begin
          if (lmousex > 290) and (lmousex < 504) and (lmousey > 200) and
            (lmousey < 245) then
            RougeGear();
          if (lmousex > 277) and (lmousex > 518) and (lmousey > 250) and
            (lmousey < 295) then ;//MageGear();
          if (lmousex > 243) and (lmousex > 544) and (lmousey > 300) and
            (lmousey < 345) then ;//WarriorGear();
          if (lmousex > 350) and (lmousex < 450) and (lmousey > 350) and (lmousey < 395) then
            exit := True;
        end;
        SDL_KEYUP: if local_event^.key.keysym.sym = 27 then
            exit := True;
      end;
    font := TTF_OPENFONT('Aethv2.ttf', 50);
    fontface := TTF_RENDERTEXT_SOLID(font, 'Training Halls', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(155, 50, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 20);
    fontface := TTF_RENDERTEXT_SOLID(font, 'XP:', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 120, 200, 100).getSDLRect());
    fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(xp)), fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(55, 120, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 30);
    if (lmousex > 290) and (lmousex < 504) and (lmousey > 200) and (lmousey < 245) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Halls of Shadows', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(215, 200, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Halls of Shadows', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(215, 200, 200, 100).getSDLRect());
    end;

    fontcolour^.g := 55;
    fontface := TTF_RENDERTEXT_SOLID(font, 'Halls of the Arcane', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(
      183, 250, 200, 100).getSDLRect());

    fontcolour^.g := 55;
    fontface := TTF_RENDERTEXT_SOLID(font, 'Halls of Strength', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(198, 300, 200, 100).getSDLRect());
    fontcolour^.g := 255;

    if (lmousex > 290) and (lmousex < 504) and (lmousey > 350) and (lmousey < 395) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 350, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 350, 200, 100).getSDLRect());
    end;
    SDL_FLIP(screen);
    FILLEDRECTCOLOUR(0, 0, 800, 600, $000000);
    SDL_DELAY(10);
  end;
end;

procedure RougeGear();
//Draws the UI and deals with the workings of the rouge upgrade panel
var
  lmousex, lmousey, i: integer;
  exit: boolean = False;
  local_event: pSDL_EVENT;
  fontcolour: pSDL_COLOR;
begin
  new(fontcolour);
  new(local_event);
  fontcolour^.r := 0;
  fontcolour^.g := 255;
  fontcolour^.b := 0;
  while exit = False do
  begin
    FILLEDRECTCOLOUR(0, 0, 800, 600, $000000);
    if SDL_POLLEVENT(local_event) = 1 then
      case local_event^.type_ of
        SDL_MOUSEMOTION:
        begin
          lmousex := local_event^.motion.x;
          lmousey := local_event^.motion.y;
        end;
        SDL_MOUSEBUTTONUP:
        begin
          //Back out of the Halls
          if (lmousex > 345) and (lmousex < 453) and (lmousey > 545) and (lmousey < 585) then
          begin
            savefile.WriteInteger('ROUGE', 'reach', stats[0, 0]);
            savefile.WriteInteger('ROUGE', 'agility', stats[0, 1]);
            exit := True;
          end;
          //Level up Reach
          if (lmousex > 10) and (lmousex < 250) and (lmousey > 250) and (lmousey < 270) then
            if stats[0, 0] < 10 then
              if xp >= 1000 * (sqr(stats[0, 0] + 1)) then
              begin
                xp -= 1000 * (sqr(stats[0, 0] + 1));
                stats[0, 0] += 1;
              end;
          //Level up Agility
          if (lmousex > 10) and (lmousex < 220) and (lmousey > 280) and (lmousey < 300) then
            if stats[0, 1] < 3 then
              if xp >= 2500 * (sqr(stats[0, 1] + 1)) then
              begin
                xp -= 2500 * (sqr(stats[0, 1] + 1));
                stats[0, 1] += 1;
              end;
          //Equip Hat Slot 0 (Unequip Hat)
          if (lmousex > 220) and (lmousex < 335) and (lmousey > 345) and (lmousey < 495) then
            savefile.WriteInteger('ROUGE', 'hat', 0);
          //Equip Hat Slot 1
          if (lmousex > 335) and (lmousex < 450) and (lmousey > 345) and (lmousey < 495) then
            case hatinv[0] of
              'sombrero': savefile.WriteInteger('ROUGE', 'hat', 1);
              'tophat': savefile.WriteInteger('ROUGE', 'hat', 2);
            end;
          //Equip Hat Slot 2
          if (lmousex > 450) and (lmousex < 565) and (lmousey > 345) and (lmousey < 495) then
            case hatinv[1] of
              'sombrero': savefile.WriteInteger('ROUGE', 'hat', 1);
              'tophat': savefile.WriteInteger('ROUGE', 'hat', 2);
            end;
        end;
        SDL_KEYUP: if local_event^.key.keysym.sym = 27 then
          begin
            savefile.WriteInteger('ROUGE', 'reach', stats[0, 0]);
            savefile.WriteInteger('ROUGE', 'agility', stats[0, 1]);
            exit := True;
          end;
      end;
    font := TTF_OPENFONT('Aethv2.ttf', 50);
    fontface := TTF_RENDERTEXT_SOLID(font, 'Halls of Shadows', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(100, 50, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 20);
    fontface := TTF_RENDERTEXT_SOLID(font, 'XP:', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 120, 200, 100).getSDLRect());
    fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(xp)), fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(55, 120, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 30);
    if (lmousex > 345) and (lmousex < 453) and (lmousey > 545) and (lmousey < 585) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 550, 200, 100).getSDLRect);
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Back', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(350, 550, 200, 100).getSDLRect);
    end;
    font := TTF_OPENFONT('Aethv2.ttf', 25);
    RECTCOLOUR(5, 195, 210, 300, $00FF00); //Draw Stats Box
    RECTCOLOUR(220, 195, 575, 145, $00FF00); //Draw Perks Box
    //Begin Drawing Hat Box
    RECTCOLOUR(220, 345, 575, 150, $00FF00);
    for i := 1 to 4 do
      vlineColor(screen, 220 + (i * 115), 345, 495, $00FF00FF);
    hlineColor(screen, 220, 795, 420, $00FF00FF);
    for i := 0 to 4 do
    begin
      surface := IMG_LOAD(PChar(hatinv[i] + ansistring('.png')));
      if savefile.ReadInteger('ROUGE', 'hat', 0) = 0 then
        RECTCOLOUR(220, 345, 116, 76, $FFFFFFFF);
      case hatinv[i] of
        'sombrero':
        begin
          if savefile.ReadInteger('ROUGE', 'hat', 0) = 1 then
            RECTCOLOUR(220 + ((i + 1) * 115), 345, 116, 76, $FFFFFFFF);
          ZOOMSURFACESIZE(54, 16, 2, 2, neww, newh);
          surface := ZOOMSURFACE(surface, 2, 2, 0);
          SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(226 +
            ((i + 1) * 115), 345 + (round(newh / 2)), 115, 75).getSDLRect());
        end;
        'tophat':
        begin
          if savefile.ReadInteger('ROUGE', 'hat', 0) = 2 then
            RECTCOLOUR(220 + ((i + 1) * 115), 345, 116, 76, $FFFFFFFF);
          ZOOMSURFACESIZE(32, 32, 2.3, 2.3, neww, newh);
          surface := ZOOMSURFACE(surface, 2.3, 2.3, 0);
          SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(226 +
            ((i + 1) * 115) + (round(neww / 4)), 345, 115, 75).getSDLRect());
        end;
      end;
      if hatinv[i] = '' then
      begin
        surface := IMG_LOAD('Lock.png');
        ZOOMSURFACESIZE(256, 256, 0.3, 0.3, neww, newh);
        surface := ZOOMSURFACE(surface, 0.3, 0.3, 0);
        SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(221 +
          ((i + 1) * 115) + round(neww / 4), 346, 115, 75).getSDLRect());
      end;
    end;
    //Stop drawing Hat Box

    fontface := TTF_RENDERTEXT_SOLID(font, 'Stats', fontcolour^);
    SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(55, 200, 200, 100).getSDLRect());
    font := TTF_OPENFONT('Aethv2.ttf', 15);
    if (lmousex > 10) and (lmousex < 195) and (lmousey > 250) and (lmousey < 270) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Reach:', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 250, 200, 100).getSDLRect());
      if stats[0, 0] < 10 then
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 0]) +
                   ' (XP: ' + IntToStr(1000 * (sqr(stats[0, 0] + 1))) + ')'), fontcolour^)
      else
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 0]) + ' (MAX)'),
                                         fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(82, 250, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Reach:', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 250, 200, 100).getSDLRect());
      if stats[0, 0] < 10 then
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 0]) +
                   ' (XP: ' + IntToStr(1000 *  (sqr(stats[0, 0] + 1))) + ')'), fontcolour^)
      else
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 0]) + ' (MAX)'),
          fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(82, 250, 200, 100).getSDLRect());
    end;
    if (lmousex > 10) and (lmousex < 220) and (lmousey > 280) and (lmousey < 300) then
    begin
      fontcolour^.r := 255;
      fontcolour^.g := 255;
      fontcolour^.b := 255;
      fontface := TTF_RENDERTEXT_SOLID(font, 'Agility:', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 280, 200, 100).getSDLRect());
      if stats[0, 1] < 3 then
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 1]) +
                    ' (XP: ' + IntToStr(2500 * (sqr(stats[0, 1] + 1))) + ')'), fontcolour^)
      else
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 1]) + ' (MAX)'),
                                         fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(88, 280, 200, 100).getSDLRect());
      fontcolour^.r := 0;
      fontcolour^.g := 255;
      fontcolour^.b := 0;
    end
    else
    begin
      fontface := TTF_RENDERTEXT_SOLID(font, 'Agility:', fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(10, 280, 200, 100).getSDLRect());
      if stats[0, 1] < 3 then
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 1]) +
                    ' (XP: ' + IntToStr(2500 * (sqr(stats[0, 1] + 1))) + ')'), fontcolour^)
      else
        fontface := TTF_RENDERTEXT_SOLID(font, PChar(IntToStr(stats[0, 1]) + ' (MAX)'),
          fontcolour^);
      SDL_BLITSURFACE(fontface, nil, screen, tMyRect.Create(88, 280, 200, 100).getSDLRect());
    end;
    SDL_FLIP(screen);
    SDL_DELAY(10);
  end;
end;

procedure DrawHats();
begin  //Draws the currently equipped hat stop the players head
  if savefile.ReadInteger('ROUGE', 'hat', 0) = 1 then
    if warping = False then
    begin
      surface := IMG_LOAD('sombrero.png');
      ZOOMSURFACESIZE(54, 16, 1.5, 1.2, neww, newh);
      surface := ZOOMSURFACE(surface, 1.5, 1.2, 0);
      SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(
        playerpos[0] - 42, playerpos[1] - 31, 90, 72).getSDLRect());
    end
    else
    begin
      surface := IMG_LOAD('sombrerob.png');
      ZOOMSURFACESIZE(54, 16, 1.5, 1.2, neww, newh);
      surface := ZOOMSURFACE(surface, 1.5, 1.2, 0);
      SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(
        playerpos[0] - 42, playerpos[1] - 31, 90, 72).getSDLRect());
    end;
  if savefile.ReadInteger('ROUGE', 'hat', 0) = 2 then
    if warping = False then
    begin
      surface := IMG_LOAD('tophat.png');
      ZOOMSURFACESIZE(32, 32, 1.5, 1.5, neww, newh);
      surface := ZOOMSURFACE(surface, 1.5, 1.2, 0);
      SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(
        playerpos[0] - 24, playerpos[1] - 38, 48, 38).getSDLRect());
    end
    else
    begin
      surface := IMG_LOAD('tophatb.png');
      ZOOMSURFACESIZE(32, 32, 1.5, 1.5, neww, newh);
      surface := ZOOMSURFACE(surface, 1.5, 1.2, 0);
      SDL_BLITSURFACE(surface, nil, screen, tMyRect.Create(
        playerpos[0] - 24, playerpos[1] - 38, 48, 38).getSDLRect());
    end;
end;

function dist_to_point(x1, y1, x2, y2: integer): integer;
  //Works out the distance between two points
var
  a, d1, d2: integer;
begin
  d1 := sqr(x1 - x2);
  d2 := sqr(y1 - y2);
  a := Round(sqrt(d1 + d2));
  dist_to_point := round(a / 10);
end;

end.
Programming - a skill for life!

by Steven Binns: Y13 Age ~18