📄 allegro_main.dpr
字号:
{*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program demonstrates how to use fixed point numbers, which
* are signed 32-bit integers storing the integer part in the
* upper 16 bits and the decimal part in the 16 lower bits. This
* example also uses the unusual approach of communicating with
* the user exclusively via the allegro_message() function.
*}
program Allegro_Main;
uses
SysUtils, Allegro;
procedure allegro_message(msg: string; args: array of const);
begin
allegro.allegro_message(PChar(Format(msg, args)));
end;
var
// declare three 32 bit (16.16) fixed point variables
x, y, z: fixed;
begin
if allegro_init() <> 0 then
Exit;
// convert integers to fixed point like this
x := itofix(10);
// convert floating point to fixed point like this
y := ftofix(3.14);
{* fixed point variables can be assigned, added, subtracted, negated,
* and compared just like integers, eg:
*}
z := fixadd(x, y); //x + y;
allegro_message('%f + %f = %f', [fixtof(x), fixtof(y), fixtof(z)]);
{* you can't add integers or floating point to fixed point, though:
* z = x + 3;
* would give the wrong result.
*}
{* fixed point variables can be multiplied or divided by integers or
* floating point numbers, eg:
*}
z := y * 2; //y * 2;
allegro_message('%f * 2 = %f', [fixtof(y), fixtof(z)]);
{* you can't multiply or divide two fixed point numbers, though:
* z = x * y;
* would give the wrong result. Use fixmul() and fixdiv() instead, eg:
*}
z := fixmul(x, y);
allegro_message('%f * %f = %f', [fixtof(x), fixtof(y), fixtof(z)]);
// fixed point trig and square root are also available, eg:
z := fixsqrt(x);
allegro_message('fixsqrt(%f) = %f', [fixtof(x), fixtof(z)]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -