Code of Settings and Input Units

Code of Settings and Input Units of Josh Blake's SpaceInvaders

unit Settings;
{
    Copyright (c) 2014 Josh Blake

    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

const
  ENEMY_CREATION_SPEED = 0.07;     //start creation speed
  ENEMY_CREATION_MULTIPLIER = 1000;  //speed of increase

  BACKGROUND_COLOR = 'black';
  PLAYER_COLOR = 'blue';
  ENEMY_COLOR = 'red';
  BULLET_COLOR = 'white';

  ENEMY_SPEED = 3;
  PLAYER_SPEED = 2;
  BULLET_SPEED = 5;

  BULLET_INTERVAL = 0.00001;

  DEBUG = False;

procedure Log(aMessage: String);

implementation

procedure Log(aMessage: String);
begin
  if DEBUG then begin
    asm
      console.log((@aMessage));
    end;
  end;
end;

end.

Code of Input Unit

unit Input;

interface

uses 
  W3System, Settings;

type
  TCallback = procedure(mCode: Integer);

procedure AddKeyDown(Callback: TCallback);
procedure KeyDownEvent(mCode: Integer);
procedure AddKeyUp(Callback: TCallback);
procedure KeyUpEvent(mCode: Integer);

var
  KeyDownCallbacks, KeyUpCallbacks: Array of TCallback;

implementation

procedure AddKeyDown(Callback: TCallback);
begin
  KeyDownCallbacks.Add(Callback);
end;

procedure KeyDownEvent(mCode: Integer);
var
  I: Integer;
begin
  Log(IntToStr(mCode) + ' down');
  for I := Low(KeyDownCallbacks) to High(KeyDownCallbacks) do begin
    Log('Call ' + IntToStr(I));
    KeyDownCallbacks[I](mCode);
  end;
end;

procedure AddKeyUp(Callback: TCallback);
begin
  KeyUpCallbacks.Add(Callback);
end;

procedure KeyUpEvent(mCode: Integer);
var
  I: Integer;
begin
  Log(IntToStr(mCode) + ' up');
  for I := Low(KeyUpCallbacks) to High(KeyUpCallbacks) do begin
    KeyUpCallbacks[I](mCode);
  end;
end;

end.
Programming - a skill for life!

Smart Mobile Studio game by Josh Blake: Y12 Age ~17