Membuat Snake Lewat Turbo Pascal 7.0


Ternyata untuk menjadi programmer game gampang lho!!!

Kita mulai dari yang sederhana dulu ya, yakni dengan menggunakan aplikasi pengolah program TURBO PASCAL seri terbaru, yakni 7.0

Pada postingan kemarin kita telah mencoba untuk membuat game tetris, kali ini kita akan mencoba untuk membuat game yang lebih sedikit rumit lagi, yakni snake atau yang biasa kita kenal game ular-ularan.

Oke langsung dicoba (silahkan di copy-paste) skrip di bawah ini:

program SNAKE;
uses crt;
type

TWORM=record
L:byte;
W:array [1..46,1..2]of integer;
EOG:boolean;
D:INTEGER;
end;
var
N:integer;
S:byte;
K:byte;
MW:TWORM;
C:char;
F:boolean;
I, J:integer;
SCREEN:array[1..25,1..80] of word absolute $B800:0000;

{This instruction will read your key}
function FUN_KEY (var C:char):boolean;
begin
FUN_KEY:=FALSE;
F:=FALSE;
C:=Readkey;
if C=#0 then begin
FUN_KEY:=true;
F:=TRUE;
C:=readkey;
end;
end;

procedure INIT;
var
X,Y:integer;
I:integer;
begin
for I:=1 to 23 do
for J:=1 to 73 do
SCREEN[I,J]:=15*256+219;
for I:=1 to 25 do
for J:=74 to 80 do
SCREEN[I,J]:=0;
for I:=24 to 25 do
for J:=1 to 80 do
SCREEN[I,J]:=0;
end;

{****************************************************************
{******************************************************************}
procedure SETSEED(S:byte);
var
X,Y:byte;
begin
randomize;
X:=random(23)+1;
Y:=random(73)+1;
while SCREEN[X,Y]15*256+219 do
begin
X:=random(23)+1;
Y:=random(73)+1;
end;
SCREEN[X,Y]:=4*256+(48+S);
end;

procedure NGAME;
begin
randomize;
INIT;
MW.L:=1;
MW.W[1,1]:=22;
MW.W[1,2]:=40;
K:=0;
S:=1;
MW.D:=1;
SETSEED(S);
N:=N div 2;
end;

{*******************************************************************}
procedure MOVE;
begin
SCREEN[MW.W[MW.L,1],MW.W[MW.L,2]]:=15*256+219;
if K>0 then
begin
MW.L:=MW.L+1;
dec(K);
end;

for J:=MW.L downto 2 do
begin
MW.W[J,1]:=MW.W[J-1,1];
MW.W[J,2]:=MW.W[J-1,2];
SCREEN[MW.W[J,1],MW.W[J,2]]:=11*256+7;
end;

if MW.D= 1 then begin
if MW.W[1,1]=1 then MW.W[1,1]:=24;
MW.W[1,1]:=MW.W[1,1]-1;
end
else if MW.D= 2 then begin
if MW.W[1,1]=23 then MW.W[1,1]:=0;
MW.W[1,1]:=MW.W[1,1]+1;
end
else if MW.D= 3 then begin
if MW.W[1,2]=73 then MW.W[1,2]:=0;
MW.W[1,2]:=MW.W[1,2]+1;
end
else if MW.D= 4 then begin
if MW.W[1,2]=1 then MW.W[1,2]:=74;
MW.W[1,2]:=MW.W[1,2]-1;
end;
if SCREEN[MW.W[1,1],MW.W[1,2]]=11*256+7 then
begin
gotoxy(1,24);
textcolor(green);
write(‘Game Over…’);
delay(100);
MW.EOG:=false;
end;
if SCREEN[MW.W[1,1],MW.W[1,2]]=4*256+(48+S) then
begin
MW.L:=MW.L+1;
K:=S-1+K;
inc(S);
MW.W[MW.L,1]:=MW.W[MW.L-1,1];
MW.W[MW.L,2]:=MW.W[MW.L-1,2];
if S=10 then NGAME
else SETSEED(S);
end
else SCREEN[MW.W[1,1],MW.W[1,2]]:=3*256+42;
end;

{****************************************************************}
procedure EVENT(C:char;F:boolean);
begin
if F and (C=#72) then
if MW.D2 then MW.D:=1;
if F and (C=#80) then
if MW.D1 then MW.D:=2;
if F and (C=#77) then
if MW.D4 then MW.D:=3;
if F and (C=#75) then
if MW.D3 then MW.D:=4;
end;

{***************************************************************}
begin
Randomize;
INIT;

FOR I:=2 to 46 do
begin
MW.W[I,1]:=1;
MW.W[I,2]:=1;
end;

MW.L:=1;
MW.W[1,1]:=22;
MW.W[1,2]:=40;
MW.D:=1;
MW.EOG:=true;
S:=1;
SETSEED(S);
N:=60;

while (MW.EOG and not((not F) and (C=#27))) do
begin
MOVE;
if keypressed then F:=FUN_KEY(C);
EVENT(C,F);
mem[$40:$1C]:=mem[$40:$1A];
delay(N);
end;
end.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s