Skip to content

Instantly share code, notes, and snippets.

@Powersaurus
Last active May 1, 2020 15:23
Show Gist options
  • Save Powersaurus/cafe1bd96ecaa4e4b8b2daf484aadaf0 to your computer and use it in GitHub Desktop.
Save Powersaurus/cafe1bd96ecaa4e4b8b2daf484aadaf0 to your computer and use it in GitHub Desktop.
Hello World Pascal Program + A bit of a roguelike
program helloPascal;
uses crt;
type
Room = record
x: Integer;
y: Integer;
w: Integer;
h: Integer;
end;
function isIn(r: Room; x: Integer; y: Integer): Boolean;
begin
isIn := ((x>=r.x) and (x<=(r.x+r.w)) and (y>=r.y) and (y<=(r.y+r.h)));
end;
Var
x: Integer;
y: Integer;
cx,cy: Integer;
cmd: char;
room1: Room;
Begin
TextBackground(White);
TextColor(Black);
x:=5;
y:=5;
vy:=0;
vx:=0;
room1.x:=5;
room1.y:=5;
room1.w:=10;
room1.h:=10;
while true do
begin
clrscr;
TextBackground(Black);
TextColor(DarkGray);
for cy:=room1.y to room1.y+room1.h do
begin
for cx:=room1.x to room1.x+room1.w do
begin
gotoxy(cx,cy);
write('.');
end;
end;
TextBackground(White);
TextColor(Black);
gotoxy(x, y);
write('@');
gotoxy(2,20);
if isIn(room1,x,y) then
write('in room');
delay(16);
cmd :=readkey;
case cmd of
#27: break;
#119: if isIn(room1,x,y-1) then y:=y-1;
#115: if isIn(room1,x,y+1) then y:=y+1;
#97: if isIn(room1,x-1,y) then x:=x-1;
#100: if isIn(room1,x+1,y) then x:=x+1;
end;
end;
writeln('done');
readln;
End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment