Other Units of RandomPlatformScroller

Code of units UE, UGameText, UGlobals, UGlobalsNoUserTypes, UOptionsButton, KeyCodeToKeyName and UAi (stub) of RandomPlatformScroller by George Wright

unit UE;      //E = Exit/Entrance
{
    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;

type
  TE = class(TObject)
    X, Y : integer;
    Won : boolean;
    constructor create(newX, newY : integer);
    //Checks if the player is over the door, so it has won
    function isDone(Cord1, Cord3, Cord4 : float) : boolean;
  end;

const
  HEIGHT = 60;
  WIDTH = 30;

implementation

constructor TE.create(newX, newY : integer);
begin
  X := newX;
  Y := newY;
end;

function TE.isDone(cord1, cord3, cord4 : float) : boolean;
begin
  if (cord1 <= X + WIDTH) and (cord3 >= X) and (cord4 = Y + HEIGHT) then
    begin
      Exit(true);
    end
  else
    begin
      Exit(false);
    end;
end;

end.



unit UGameText;
{
    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;

type
  TText = class(TObject)
    text, colour : string;
    x, y : integer;
    constructor create(newText, newColour : string; newX, newY : integer);
  end;

implementation

constructor TText.create(newText, newColour : string; newX, newY : integer);
begin
  text := newText;
  x := newX;
  y := newY;
  colour := newColour;
end;

end.


unit UGlobals;
{
    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/
}
//Variables of user made types e.g. the door which uses the TE type.
//This is hard to reference as units with types in are referenced by this unit.
interface

uses
  w3system, UPlat, UGameText, UE, UPlayer, UBullet, UAi, UTurret, ULevelSelector, UOptionsButton, UGlobalsNoUserTypes;

//All arrays here are dynamic, so they can be as big or small as they like
//and can change size at will.
var
  Player : TPlayer; //The player
  Ai : array of TAi; //the array of Ai Units
  EntranceDoor : TE; //The entrance Door
  ExitDoor : TE; //The Exit door
  FPlats : array of TPlat; //The array of Fixed Plats
  RandPlats : array of TPlat; //The array of random Plats
  Bullets : array of TBullet; //The array of bullets
  gameText : array of TText; //The array of Game Text
  Options : array of TOptionsButton; //An array of the option buttons
  ControlButtons : array of TOptionsButton; //An array of buttons that will move the player
                                            //This is the mobile support as it can be click
  Controls : array of TText; //A list of the controls as text elements
  Turrets : array of TTurret; //The array of Turrets
  Selector : ULevelSelector.TSelect; //The level selector

implementation

end.




unit UGlobalsNoUserTypes;
{
    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/
}
//This unit is for constants and variables that may be needed in several units,
//but this one doesn't reference any meaning all units can access this one

interface

uses
  W3System;

//This is the list of moving controls for the player, stored as a Enumerator
type
  MoveCommands = (right, left, null);

//The types of gamemodes or menus available
type
  GameModes = (maingame, levelselector, settings);

const
  PLAYERHEALTH = 45; //The health of the player
  AIHEALTH = 30; //The health of an AI Unit
  PLAYERHEAD = 15; //Player Width
  PLAYERHEIGHT = 45; //Player Height
  DEFAULT_HORIZONTAL_HEIGHT = 10; //The default horizontal height of a rand platform
  DEFAULT_VERTICAL_WIDTH = 10; //the default vertical width of a rand platform
  TURRET_WIDTH = 20;
  TURRET_HEIGHT = 30;

var
  UnlockedDoors : integer; //The amount of doors unlocked
  MouseX, MouseY : float; //The Mouse's X and Y co-ordinates
  screenWidth : float; //the width of the viewport
  screenHeight : float; //the height of the viewport
  gamemode : GameModes; //Holds what gamemode we are in
  maxX : integer; //The maximum X for a level
  maxY : integer; //The Maximum Y for a level
  AIS : integer; //The number of Ai Units
  offsetX : float; //The offset X to draw a element at
  offsetY : float; //The offset Y to draw a element at
  RANDOMPLATFORMS : float; //The percetage of the screen that will be random platforms
  RANDOMVERTICALPLATFORMS : float; //The percentage of platforms that will be vertical
  RANDOMJUMPTHROUGHPLATFORMS : float; //The percentage of platforms that you can jump through
  RANDOMNOFALLPLATFORMS : float; //The percentage of platforms that you cannot fall through
  RANDOMNOWALLJUMPPLATFORMS : float; //The percentage of platforms that you cannot wall jump off of
  RANDOMCRUMBLEPLATFORMS : float; //The percentage of platforms that will crumble
  RANDOMMOVINGPLATFORMS : float; //the percentage of platforms that will move
  RANDOMMOVINGRIGHTTOLEFT : float; //the percentage of moving platforms that will move left to right
  RANDOMMAXMOVE : integer; //the maximum move speed for moving platforms
  RANDOMTURRETLEFTTOP : float; //The percent of random platforms that will have a turret on the top or left side
  RANDOMTURRETRIGHTBOTTOM : float; //The percent of random platforms that will have a turret on the bottom or right side
  RightKey : integer; //The key code for the Move Right Key
  LeftKey : integer; //The key code for the Move Left Key
  JumpKey : integer; //The key code for the Jumping Key
  FallKey : integer; //The key code for the Fall Key
  ShootKey : integer; //The key code for the Shoot key
  EnterKey : integer; //The key code for the Enter Door Key
  EscapeKey : integer; //The key code for the Excape Key
  Level : integer; //The level we are on

implementation

end.



unit UOptionsButton;
{
    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;

type
  TOptionsButton = class(TObject)
  X : float; //The x position of the button
  Y : float; //the y position of the button
  Width : float; //the width of the button
  Height : float; //the height of the button
  Text : string; //the text in the button
  TextX : float; //the X of the text in the button
  TextY : float; //the Y of the text in the button
  constructor create(newX, newY, newWidth, newHeight : float; newText : string; newTextX,newTextY : float);
   //If the x and y are in the button, it will return true as it has been clicked
  function clicked(clickX, clickY : float) : boolean;
end;

implementation

constructor TOptionsButton.create(newX,newY,newWidth,newHeight : float; newText : string; newTextX,newTextY : float);
begin
  X := newX;
  Y := newY;
  Width := newWidth;
  Height := newHeight;
  Text := newText;
  TextX := newTextX;
  TextY := newTextY;
end;

function TOptionsButton.clicked(clickX,clickY : float) : boolean;
begin
  if (clickX >= X) and (clickX <= X + Width) then //if the x is in the x range
    begin
      if (clickY >= Y) and (clickY <= Y + Height) then //if the y is in the y range
        begin
          Exit(true); //return true if both passed
        end;
    end;

  Exit(false); //otherwise return false
end;

end.




unit KeyCodeToKeyName;
{
    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;

function CodeToKeyName(KeyCode : integer) : string;

implementation

//Used to get key name from a key code, meaning it will show you your controls
//with proper key names, not just the numbered key codes
function CodeToKeyName(KeyCode : integer) : string;
begin
  case KeyCode of
    8 : Exit("Backspace");
    9 : Exit("Tab");
    13 : Exit("Enter");
    16 : Exit("Shift");
    17 : Exit("Ctrl");
    18 : Exit("Alt");
    19 : Exit("Pause/Break");
    20 : Exit("Caps Lock");
    27 : Exit("Escape");
    32 : Exit("Space");
    33 : Exit("Page Up");
    34 : Exit("Page Down");
    35 : Exit("End");
    36 : Exit("Home");
    37 : Exit("Left Arrow");
    38 : Exit("Up Arrow");
    39 : Exit("Right Arrow");
    40 : Exit("Down Arrow");
    45 : Exit("Insert");
    46 : Exit("Delete");
    48 : Exit("0");
    49 : Exit("1");
    50 : Exit("2");
    51 : Exit("3");
    52 : Exit("4");
    53 : Exit("5");
    54 : Exit("6");
    55 : Exit("7");
    56 : Exit("8");
    57 : Exit("9");
    65 : Exit("A");
    66 : Exit("B");
    67 : Exit("C");
    68 : Exit("D");
    69 : Exit("E");
    70 : Exit("F");
    71 : Exit("G");
    72 : Exit("H");
    73 : Exit("I");
    74 : Exit("J");
    75 : Exit("K");
    76 : Exit("L");
    77 : Exit("M");
    78 : Exit("N");
    79 : Exit("O");
    80 : Exit("P");
    81 : Exit("Q");
    82 : Exit("R");
    83 : Exit("S");
    84 : Exit("T");
    85 : Exit("U");
    86 : Exit("V");
    87 : Exit("W");
    88 : Exit("X");
    89 : Exit("Y");
    90 : Exit("Z");
    91 : Exit("Left Window Key");
    92 : Exit("Right Window Key");
    93 : Exit("Select Key");
    96 : Exit("Numpad 0");
    97 : Exit("Numpad 1");
    98 : Exit("Numpad 2");
    99 : Exit("Numpad 3");
    100 : Exit("Numpad 4");
    101 : Exit("Numpad 5");
    102 : Exit("Numpad 6");
    103 : Exit("Numpad 7");
    104 : Exit("Numpad 8");
    105 : Exit("Numpad 9");
    106 : Exit("Multiply");
    107 : Exit("Add");
    109 : Exit("Subtract");
    110 : Exit("Decimal Point");
    111 : Exit("Divide");
    112 : Exit("F1");
    113 : Exit("F2");
    114 : Exit("F3");
    115 : Exit("F4");
    116 : Exit("F5");
    117 : Exit("F6");
    118 : Exit("F7");
    119 : Exit("F8");
    120 : Exit("F9");
    121 : Exit("F10");
    122 : Exit("F11");
    123 : Exit("F12");
    144 : Exit("Num Lock");
    145 : Exit("Scroll Lock");
    186 : Exit("Semi-Colon");
    187 : Exit("Equal Sign");
    188 : Exit("Comma");
    189 : Exit("Dash");
    190 : Exit("Full Stop");
    191 : Exit("Forward Slash");
    192 : Exit("Apostrophe");
    219 : Exit("Open Bracket");
    220 : Exit("Back Slash");
    221 : Exit("Close Braket");
    222 : Exit("Hash Tag");
    else
      Exit(IntToStr(KeyCode)); //If it could not find it, send back the number
  end;
end;


end.




unit UAi;
{
    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, UPlayer, UBullet, UPlat, UGlobalsNoUserTypes;

type TAi = class(UPlayer.TPlayer)
  OnPlat, OnRand : boolean;
  PlatID : integer;
  LOSXMin, LOSXMax, LOSYMin, LOSYMax : float; //LOS = Line Of Shot
  PX, PY : float; //P = Player
  TargRunBefore : boolean;
  TargRand1 : boolean;
  TargID1 : integer;
  procedure WorkOutMoves(player : UPlayer.TPlayer; Bullets : array of TBullet; FixedPlats, RandPlats : Array of TPlat; screenwidth, screenheight : integer);
  procedure WorkOutJumpTargs(TargNO : integer; FixedPlats, RandPlats : array of TPlat; X, Y : float);
  function CanJumpTo(FixedPlats, RandPlats : array of TPlat; X, Y : float; TargetID : integer; isTargetRand : boolean = true) : boolean;
  procedure PlayerInfo(player : TPlayer; FixedPlats, RandPlats : Array of TPlat; screenwidth : integer);
  function SimulateBullet(FixedPlats, RandPlats : array of TPlat; testLeft : boolean) : float;
  procedure OnPlatform(FixedPlats, RandPlats : Array of TPlat);
  procedure OnPlatform(FixedPlats, RandPlats : Array of TPlat; x, y : float); overload;
  procedure Shoot(Bullets : array of TBullet);
  procedure MoveOnPlat(targPlats, playerPlats : array of TPlat);
  procedure MoveInAir(targPlats : array of TPlat);
end;

implementation
var
LastX, LastY : float;
counter : integer;

procedure TAi.WorkOutMoves(player : UPlayer.TPlayer; Bullets : array of TBullet; FixedPlats, RandPlats : Array of TPlat; screenwidth, screenheight : integer);
begin

end;

procedure TAi.WorkOutJumpTargs(TargNO : integer; FixedPlats, RandPlats : array of TPlat; X, Y : float);
begin
 
end;

function TAi.CanJumpTo(FixedPlats, RandPlats : array of TPlat; X, Y : float; TargetID : integer; isTargetRand : boolean = true) : boolean;
begin
 
end;

procedure TAi.PlayerInfo(player : TPlayer; FixedPlats, RandPlats : Array of TPlat; screenwidth : integer);
begin
 
end;

function TAi.SimulateBullet(FixedPlats, RandPlats : array of TPlat; testLeft : boolean) : float;
begin
 
end;

procedure TAi.OnPlatform(FixedPlats, RandPlats : Array of TPlat);
begin
 
end;

procedure TAi.OnPlatform(FixedPlats, RandPlats : Array of TPlat; x, y : float);
begin
  
end;

procedure TAi.shoot(Bullets : array of TBullet);
begin
  
end;

procedure TAi.MoveOnPlat(targPlats, playerPlats : array of TPlat);
begin
  
end;

procedure TAi.MoveInAir(targPlats : array of TPlat);
begin
  
end;

end.

Programming - a skill for life!

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