Units ULevelSelector and Levels of RandomPlatformScroller

Code of the ULevelSelector and 17 levels of RandomPlatformScroller by George Wright

unit ULevelSelector;
{
    Copyright (c) 2014 George Wright

    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
  w3system, UE, UPlat, UGameText, UPlayer, UAi, KeyCodeToKeyName, UGlobalsNoUserTypes;

type
  TSelect = class(TObject)
    screenwidth : integer; //The width of the selector
    screenheight : integer; //The height of the selector
    Doors : array of UE.TE; //An array of the possible level doors
    Plats : array of UPlat.TPlat; //Array of platforms so you can walk to doors
    Text : array of UGameText.TText; //array of text (instructions)
    Ai : array of TAi; //So that the game doesn't get confused as it needs the ai array
    maxX : integer; //The maxX (for the player update methods)
    maxY : integer; //The maxY (for the player update methods)
    constructor create();
    function selected(x1, y1, x2, y2 : float) : integer;
  end;

const
  //This is the amount of doors that spawn on the level selector.
  //It is reduced by 1 so it starts at the 0 index properly.
  DOORSAMOUNT = 18 - 1;

implementation

constructor TSelect.create();
var
  x, y, n, i, ii: integer; //Iteration variables, but x and y are for spawning of doors
  iidone : boolean; //iteration purposes
begin
  Text[0] := UGameText.TText.create('Use ' + CodeToKeyName(EnterKey) + ' to go through the door.', 'blue', 100, 60);
  Text[1] := UGameText.TText.create('Use ' + CodeToKeyName(LeftKey) + ' and ' + CodeToKeyName(RightKey) + ' to move left and right', 'blue', 100, 80);
  Text[2] := UGameText.TText.create('or you can use the buttons in the top and bottom left corners', 'blue', 100, 100);
  i := 0;
  ii := 0;
  iidone := False;
  x := 65;
  maxX := 965;
  y := 200 - UE.HEIGHT;
  n := 200;
  maxY := 200;
  while i <= DOORSAMOUNT do //Creates all the needed doors
    begin
      Doors[i] := UE.TE.create(x, y); //Spawns a new door
      if iidone = False then
        begin
          if n mod 400 = 0 then //Spawns platforms if new line of doors is created on new a line
            begin
              Plats[ii] := UPlat.TPlat.createF(50, y + UE.HEIGHT,maxX - 50, 10, True);
            end
          else //Spawns platforms if new line of doors is created on new a line
            begin
              Plats[ii] := UPlat.TPlat.createF(0,y + UE.HEIGHT,maxX - 50, 10, True);
            end;
          ii += 1;
          iidone := True;
        end;
      if i + 1 <= 9 then //Displays numbers on doors
        begin
          Text[i + 3] := UGameText.TText.create(IntToStr(i + 1), 'red',x +
                                                (UE.WIDTH div 2) - 5, y + (UE.HEIGHT div 4));
        end
      else //Displays numbers on doors
        begin
          Text[i + 3] := UGameText.TText.create(IntToStr(i + 1), 'red', x +
                                                (UE.WIDTH div 2) - 9, y + (UE.HEIGHT div 4));
        end;
      i += 1;
      if (n mod 400 = 0) and (n <> 200) then //Moves the x co-ord
        begin                                //if the platform is in an even row
          x -= 100; //Make the X of the door go left
          if x <= 49 then //If no more doors will be spawned after this one
            begin
              y += 200; //Increase it to the next row
              maxY += 200; //Increase the maxY for player purposes
              n += 200; //Increase it to the next row
              iidone := False;
            end;
        end
      else //Moves the x co-ord if the platform is a odd row
        begin
          x += 100; //Make the X of the door go right
          if x >= maxX then //If the door is over the maxX it wants to go down and left
            begin
              x -= 100; //Put the X of the door back on screen
              y += 200; //Increase it to the next row
              maxY += 200; //Increase the maxY for player purposes
              n += 200; //Increase it to the next row
              iidone := False;
            end;
        end;
    end;
  maxY += 100;
  Ai[0] := TAi.start();
  Ai[0].Dead := True;
end;

function TSelect.selected(x1, y1, x2, y2 : float) : integer;  //x2 = right hand side, x1 = left hand side
                                                             //y2 = bottom, y1 = top
var
  i : integer;
begin
  while i <= High(Doors) do //Iterates through the Doors
    begin
      if (y1 + y2 = Doors[i].y + UE.HEIGHT) then  //Checks if the bottoms are equal
        begin
          //Checks x overlap so if the door is selected properly
          if (x1 <= Doors[i].X + UE.WIDTH) and (x2 >= Doors[i].x) then
            begin
              Exit(i + 1); //Says the level that was selected, so the door + 1
                           //(as the door starts at 0, the levels start at 1)
            end;
        end;
      i += 1; //Adds one to i so that it selects the next door
    end;
  Exit(0); //No level was picked
end;

end.



unit lvl1;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('Use ' + CodeToKeyName(LeftKey) + ' and ' + CodeToKeyName(RightKey) +
       ' to move left and right', 'blue', 10, 60);
  Text('Use ' + CodeToKeyName(EnterKey) + ' to go through the door', 'blue', 500, 60);
  Text('or you can use the buttons in the bottom left corner to move.', 'blue', 10, 80);
  Text('or the enter button in the top left corner.', 'blue', 500, 80);
  InDoor(10, 100);
  OutDoor(600, 100);
  FixPlats(10, 100 + UE.HEIGHT, 590 + UE.WIDTH, 10);
  SideScrollSize(800, 200);
  StartLvl(0);
end;

end.



unit lvl2;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('Use ' + CodeToKeyName(JumpKey) + ' to jump', 'blue', 90, 60);
  Text('or the button labelled "Jump" in the bottom left corner.', 'blue', 10, 80);
  InDoor(10, 100);
  OutDoor(300, 100);
  FixPlats(10, 100 + UE.HEIGHT, 100, 10);
  FixPlats(200, 100 + UE.HEIGHT, 100 + UE.WIDTH, 10);
  SideScrollSize(500, 500);
  PercentofRands(0);
  StartLvl(0);
end;

end.




unit lvl3;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('You are able to do one air jump.', 'blue', 90, 60);
  Text('_____', 'blue', 180, 200);
  Text('TIP: Jump here >>>', 'blue', 30, 200);
  InDoor(10, 100);
  OutDoor(450, 100);
  FixPlats(10, 100 + UE.HEIGHT,UE.WIDTH + 20, 10);
  FixPlats(280, 100 + UE.HEIGHT,UE.WIDTH + 170, 10);
  SideScrollSize(500, 500);
  PercentofRands(0);
  StartLvl(0);
end;

end.



unit lvl4;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
	clearvars();
	text('Use ' + CodeToKeyName(FallKey) + ' to fall through the platform', 'blue', 10, 230);
  text('or the button called "Fall" in the bottom right corner.', 'blue', 10, 250);
	indoor(10, 100);
	outdoor(100, 400);
	fixplats(10, 100 + ue.height,ue.width + 10, 10);
	fixplats(10, 90, ue.width + 10, 10);
	fixplats(10, 100, 10, ue.height);
	fixplats(10 + ue.width, 100, 10, ue.height);
	fixplats(10, 400 + ue.height, 100 + ue.width, 10);
	sidescrollsize(500, 600);
	percentofrands(0);
	startlvl();
end;

end.



unit lvl5;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('You can wall jump,  try it', 'blue', 10, 900);
  Text('on the walls in front to get to the top.', 'blue', 10, 920);
  Text('You can do this off any platform type', 'blue', 10, 940);
  Text("and it won't make crumbling platforms fall", 'blue', 10, 960);
  Text('You can also wall jump off one', 'blue', 500, 970);
  Text('wall repeatedly to climb it.', 'blue', 500, 990);
  Text('Do this by moving into it and jumping when touching the wall.', 'blue', 400, 1100);
  InDoor(10, 1000);
  OutDoor(700, 100);
  FixPlats(0, 1000 + UE.HEIGHT, 800, 10);
  FixPlats(0, 100 + UE.HEIGHT, 700 + UE.WIDTH, 10);
  FixPlats(300, 250, 10, 750);
  FixPlats(350, 250, 10, 750 + UE.HEIGHT);
  FixPlats(350, 250, 200, 10);
  FixPlats(700 + UE.WIDTH, 100 + UE.HEIGHT, 10, 850 - UE.HEIGHT);
  SideScrollSize(900,  1200);
  StartLvl();
end;

end.


unit lvl6;

interface

uses
  w3system, UE, UCreates;

var
  i : float;
  n : integer;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text("There are 9 types", "blue", 10, 550);
  Text("of platform", "blue", 10, 570);
  Text("Go test and play on them", "blue", 150, 620);
  Text("TIP: Try things you know,  like falls and jumps", "blue", 170, 640);
  Text("Giveaways on what the platforms do are above", "blue", 650, 630);
  Text("^", "blue", 850, 610);
  Text("Giveaways on what the platforms do are right >>>", "blue", 550, 235);
  Text("Pink: Vertical and you can't fall through it or wall jump off it",  'rgba(250,  100,  190,  0.9)', 900, 160);
  Text("Purple: Vertical and you can fall through it,  but not wall jump off it",  'rgba(190,  10,  120,  0.9)', 900, 210);
  Text("Grey: Vertical and you can fall through it and wall jump off it", "rgb(100, 100, 100)", 900, 260);
  Text("Orange: Vertical and you can wall jump off it but can't fall through it", 'rgba(255, 80, 0, 0.9)', 900, 310);
  Text("Green: Horizontal and you can jump and fall through it", 'rgb(0, 50, 0)', 900, 360);
  Text("Black: Horizontal and you can't jump through it but can fall", 'rgb(0, 0, 0)', 900, 410);
  Text("Red: Horizontal and you can jump through it,  but not fall", 'rgb(100, 0, 0)', 900, 460);
  Text("Blue: Horizontal and you can't jump or fall through it", 'rgb(0, 0, 100)', 900, 510);
  Text("Brown: Can have any properties but will fall after you jump on it", 'rgb(90, 65, 35)', 900, 560);
  Text("NOTE: All horizontal platforms can be wall jumped off of and all vertical ones can't be jumped through",  'blue', 680, 110);
  InDoor(10, 600);
  OutDoor(1000, 600);
  FixPlats(0, 600 + UE.HEIGHT, 1400, 10);
  FixPlats(140, 250, 10, 300);
  FixPlats(200, 500, 200, 10, true);
  FixPlats(200, 300, 200, 10);
  FixPlats(450, 250, 10, 300, true);
  FixPlats(500, 250, 10, 300, true, true);
  FixPlats(375, 200, 200, 10);
  FixPlats(550, 500, 200, 10, true, true);
  FixPlats(550, 300, 200, 10, false, true);
  FixPlats(800, 250, 10, 300, false, true);
  FixPlats(880, 190, 10, 30, true);
  FixPlats(880, 140, 10, 30, true, true);
  FixPlats(880, 240, 10, 30);
  FixPlats(880, 290, 10, 30, false, true);
  FixPlats(1150, 370, 200, 10, true);
  FixPlats(850, 420, 200, 10);
  FixPlats(1150, 470, 200, 10, true, true);
  FixPlats(850, 520, 200, 10, false, true);
  FixPlats(1150, 570, 200, 10, false, false, true);
  SideScrollSize(1400, 900);
  PercentofRands(0);
  PercentofVerticals(0);
  PercentofNoFalls(0);
  PercentofJumpThoughs(0);
  SpawnRands();
  StartLvl();
end;

end.



unit lvl7;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('Crumbling Platforms:',  'blue',  90,  70);
  Text('With speed you can jump from one to another', 'blue', 90, 180);
  Text('Crumbles can have any property so its always worth checking', 'blue', 1000, 550);
  Text('Use ' + CodeToKeyName(ShootKey) + ' to shoot stright', 'blue', 700, 40);
  Text('or you can aim with the mouse,  and click to shoot towards it', 'blue', 550, 80);
  Text('or you can click the shoot button on screen to shoot stright',  'blue',  625,  60);
  Text('Bullets will make crumble platforms fall', 'blue', 750, 100);
  InDoor(10,  30);
  OutDoor(610,  500 - UE.HEIGHT);
  FixPlats(0,  30 + UE.HEIGHT,  UE.WIDTH + 20,  10);
  FixPlats(150, 200, 100, 10, false, false, true);
  FixPlats(400, 200, 100, 10, false, false, true);
  FixPlats(650, 200, 100, 10, false, false, true);
  FixPlats(900, 200, 400, 10);
  FixPlats(600, 400, 500, 10, false, true);
  FixPlats(1100, 200, 10, 310);
  FixPlats(600, 400, 10, 110);
  FixPlats(600, 500, 350, 10, false, true);
  FixPlats(950, 500, 150, 10, true, false, true);
  FixPlats(1100, 0, 10, 510, false, true, true);
  FixPlats(800, 600, 800, 10, false, true);
  FixPlats(3000,  100 + UE.HEIGHT, 100 + UE.WIDTH,  10);
  SideScrollSize(4000, 1500);
  StartLvl();
end;

end.



unit lvl8;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('All Platforms can move.', 'blue', 90, 100);
  InDoor(50, 50);
  OutDoor(500, 100);
  FixPlats(40, 50 + UE.HEIGHT, UE.WIDTH + 10, 10);
  FixPlats(490, 100 + UE.HEIGHT, UE.WIDTH + 10, 10);
  FixPlats(150, 150, 150, 10, false, false, false, true, false, 300);
  FixPlats(150, 250, 150, 10, true, false, false, true, false, 300);
  FixPlats(150, 350, 150, 10, true, true, false, true, false, 300);
  FixPlats(150, 450, 150, 10, false, true, false, true, false, 300);
  FixPlats(600, 0, 10, 200, false, false, true, true, true, 400);
  FixPlats(150, 550, 150, 10, false, false, true, true, false, 300);
  SideScrollSize(700, 700);
  StartLvl();
end;

end.



unit lvl9;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('Enjoy the sidescrolling!', 'blue', 90, 500);
  InDoor(10, 500);
  OutDoor(3000, 500);
  FixPlats(0 ,500 + UE.HEIGHT, 4000, 10);
  FixPlats(3000, 100 + UE.HEIGHT, 100 + UE.WIDTH, 10);
  SideScrollSize(4000, 700);
  PercentofRands(3.1);
  PercentofVerticals(10);
  PercentofNoFalls(30);
  PercentofJumpThoughs(30);
  PercentofCrumble(20);
  PercentofMovings(10);
  PercentofMovesThatMoveX(70);
  MaxMoveForMoves(500);
  SpawnRands();
  StartLvl(0);
end;

end.



unit lvl10;

interface
//Designed by Alex Karet.
//05/05/2014
//Showcasing the non fall through platforms, Will probably require tutorial to explain this.

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text('This game also scrolls up and down; try to find the door!', 'blue', 90, 70);
  Text('Note how you cannot fall through most of the platforms, maybe the door is downwards then?', 'black', 100, 90);
  InDoor(50, 50);
  OutDoor(100, 1030);
  FixPlats(50, 50 + UE.HEIGHT, 50, 10);
  FixPlats(100, 1030 + UE.HEIGHT, 30 + UE.WIDTH, 10);
  SideScrollSize(1200, 1500);
  PercentofRands(65);
  PercentofNoFalls(80);//High percent to showcase feature
  PercentofJumpThoughs(5);
  SpawnRands();
  StartLvl(0);
end;

end.



unit lvl11;

interface
//Designed by Alex Karet.
//05/05/2014
//Find your way to the top, showcasing the jump through platforms.

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  InDoor(1050, 1050);
  OutDoor(50, 500);
  FixPlats(50, 500 + UE.HEIGHT, 50, 10);
  FixPlats(1050, 1050 + UE.HEIGHT, 30 + UE.WIDTH, 10);
  SideScrollSize(1500, 1500);
  PercentofRands(45);
  PercentofNoFalls(20);
  PercentofJumpThoughs(70);//high percent in order to showcase the platforms
  SpawnRands();
  StartLvl();
end;

end.



unit lvl12;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  InDoor(750, 1050);
  OutDoor(1050, 500);
  FixPlats(1050, 500 + UE.HEIGHT, 50, 10);
  FixPlats(750, 1050 + UE.HEIGHT, 30 + UE.WIDTH, 10);
  SideScrollSize(2000, 2000);
  PercentofRands(45);
  PercentofNoFalls(70);
  PercentofJumpThoughs(30);
  PercentofCrumble(90);
  SpawnRands();
  StartLvl();
end;

end.



unit lvl13;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  InDoor(50, 50);
  OutDoor(1050, 1500);
  FixPlats(50, 50 + UE.HEIGHT, 50, 10);
  FixPlats(1050 - 10, 1500 + UE.HEIGHT, 20 + UE.WIDTH, 10);
  SideScrollSize(2000, 2000);
  PercentofRands(60);
  PercentofNoFalls(20);
  PercentofJumpThoughs(20);
  PercentofMovings(55);
  PercentofMovesThatMoveX(30);
  MaxMoveForMoves(500);
  SpawnRands();
  StartLvl();
end;

end.



unit lvl14;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  InDoor(750, 1300);
  OutDoor(100, 200);
  FixPlats(750, 1300 + UE.HEIGHT, 50, 10);
  FixPlats(100, 200 + UE.HEIGHT, 30 + UE.WIDTH, 10);
  SideScrollSize(1500, 1500);
  PercentofRands(55);
  PercentofVerticals(50);
  PercentofNoFalls(70);
  PercentofJumpThoughs(30);
  PercentofCrumble(40);
  SpawnRands();
  StartLvl();
end;

end.



unit lvl15;

interface

uses
  w3system, UE, UCreates;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text("Now try without wall jumps!", "blue", 750, 1260);
  InDoor(750, 1300);
  OutDoor(100, 200);
  FixPlats(750, 1300 + UE.HEIGHT, 50, 10);
  FixPlats(100, 200 + UE.HEIGHT, 30 + UE.WIDTH, 10);
  SideScrollSize(1500, 1500);
  PercentofRands(55);
  PercentofVerticals(50);
  PercentofNoFalls(70);
  PercentofJumpThoughs(30);
  PercentofCrumble(40);
  PercentofNoWallJumps(100);
  SpawnRands();
  StartLvl();
end;

end.



unit lvl16;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  Text("This is a turret. It will aim and shoot", "blue", 10, 80);
  Text("at you. Two shots will kill it!", "blue", 10, 100);
  Text("If it is on a crumbling platform, shoot the platform to make it fall with it.", "blue", 10, 120);
  InDoor(10, 150);
  OutDoor(600, 150);
  FixPlats(10, 150 + UE.HEIGHT, 590 + UE.WIDTH, 10);
  FixPlats(550, 50, 100, 10, false, false, false, false, false, 0, false, true);
  FixPlats(650, 50, 10, 100, false, false, true, false, false, 0, true, false);
  SideScrollSize(800, 300);
  StartLvl();
end;

end.



unit lvl17;

interface

uses
  w3system, UE, UCreates, KeyCodeToKeyName, UGlobalsNoUserTypes;

procedure Initialize();

implementation

procedure Initialize();
begin
  ClearVARS();
  InDoor(10, 150);
  OutDoor(1350, 1300);
  FixPlats(0, 150 + UE.HEIGHT, UE.WIDTH + 20, 10);
  FixPlats(1340, 1300 + UE.HEIGHT, UE.WIDTH + 20, 10);
  SideScrollSize(1500, 1500);
  PercentofRands(75.391);
  PercentofVerticals(15);
  PercentofNoFalls(15);
  PercentofNoWallJumps(15);
  PercentofJumpThoughs(30);
  PercentofCrumble(20);
  PercentofMovings(5);
  PercentofMovesThatMoveX(50);
  MaxMoveForMoves(500);
  PercentofTurretsOnLeftorTop(0.55);
  PercentofTurretsOnRightorBottom(0.55);
  SpawnRands();
  StartLvl();
end;

end.




Programming - a skill for life!

Smart Mobile Studio game by George Wright: Y9 Age ~14