Created
March 29, 2013 11:56
-
-
Save tluyben/5270420 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{TRON-LASERBIKES by (c) T.Luyben && J.Straaten 1988, revised for TP7.0 VGA, | |
THIS GAME IS FREEWARE AND MAY BE COPIED... DO NOT ALTER THIS FILE OR THE | |
ZIP FILE YOU COPY... | |
IF YOU CHANGE ANYTHING THEN PLEASE LET ME KNOW! NO PROFIT SHALL BE MADE FROM | |
THIS LITTLE PROJECT | |
} | |
uses crt,dos; | |
const cdlevel=3; {here you can change the difficulty level; there is a} | |
pdlevel=3; {bug here, but that's no real problem...} | |
del=10; {the speed... Try making it 0} | |
pl=1; {how many players; 1 is you against the computer, 0 is | |
the computer against itself} | |
var bios9:procedure; {save the computers original keybios} | |
a:byte; {current key} | |
xp,yp, | |
xe,ye : word; {players coordinates} | |
dxp,dxe, | |
dyp,dye : shortint; {direction} | |
death:byte; {who died?} | |
{$F+} | |
procedure mybios9;interrupt; {takeover keyboard interrupt} | |
begin a:=port[$60]; port[$20]:=$20; end; | |
{$F-} | |
procedure screen_open;assembler; {open vga 320*200 8 bits} | |
asm mov ax,$13; int $10; end; | |
procedure screen_close;assembler; {goto textmode} | |
asm mov ax,3; int $10; end; | |
procedure pset(const x,y:word;const col:byte);assembler; {fast pixelput} | |
asm push ds; mov ax,y; mov bx,ax; shl ax,8; shl bx,6; add ax,bx; add ax,x; | |
mov ds,SEGA000; mov di,ax; mov al,col;mov [ds:di],al; pop ds; end; | |
function pget(const x,y:word):byte; {fast pixelget, gives back color} | |
var temp:byte; | |
begin | |
asm push ds; mov ax,y; mov bx,ax; shl ax,8; shl bx,6; add ax,bx; add ax,x; | |
mov ds,SEGA000; mov di,ax; mov al, [ds:di]; mov temp,al; pop ds; end; | |
pget:=temp; | |
end; | |
procedure swap(var w1,w2:word); {swap to vars, could be faster, this is the | |
easy way out} | |
var w3:word; | |
begin | |
w3:=w1; w1:=w2; w2:=w3; | |
end; | |
procedure hline(x1,x2,y:word;const col:byte); {draw a horizontal line} | |
var i:word; | |
begin | |
if x1>x2 then swap(x1,x2); | |
for i:=x1 to x2 do | |
pset(i,y,col); | |
end; | |
procedure vline(y1,y2,x:word;const col:byte); {draw a vertical line} | |
var i:word; | |
begin | |
if y1>y2 then swap(y1,y2); | |
for i:=y1 to y2 do | |
pset(x,i,col); | |
end; | |
procedure setpal(const col,r,g,b:byte);assembler; {set the palette for game} | |
asm mov dx,3c8h;mov al,[col];out dx,al;inc dx;mov al,[r]; | |
out dx,al;mov al,[g];out dx,al;mov al,[b];out dx,al; end; | |
function check_col(const x,y:word;const dx,dy:shortint;const howfar:word):word; | |
{check for collision} | |
var vx,vy,ho:integer; | |
begin | |
vx:=x; vy:=y; | |
repeat | |
vx:=vx+dx; | |
vy:=vy+dy; | |
if (x-vx)<>0 | |
then ho:=abs(vx-x) | |
else ho:=abs(vy-y); | |
until (pget(vx,vy)<>0) or (ho>=howfar); | |
check_col:=ho; | |
end; | |
procedure enemy_move(const x,y:word;var dx,dy:shortint;const dl:byte); | |
{VERY simple enemy move calculator} | |
var dist:word; | |
begin | |
dist:=check_col(x,y,dx,dy,dl); | |
if dist<dl | |
then if dx=0 | |
then case dy of | |
-1 : begin | |
dx:=1; dy:=0; | |
if check_col(x,y-dist,dx,dy,dl)<dl | |
then dx:=-1; | |
end; | |
1 : begin | |
dx:=-1; dy:=0; | |
if check_col(x,y+dist,dx,dy,dl)<dl | |
then dx:=1; | |
end; | |
end | |
else case dx of | |
-1 : begin | |
dx:=0; dy:=-1; | |
if check_col(x-dist,y,dx,dy,dl)<dl | |
then dy:=1; | |
end; | |
1 : begin | |
dx:=0; dy:=1; | |
if check_col(x+dist,y,dx,dy,dl)<dl | |
then dy:=-1; | |
end; | |
end; | |
end; | |
procedure play_screen; {init the playscreen} | |
begin | |
setpal(1,0,0,$ff); | |
setpal(2,$ff,0,0); | |
setpal(3,0,$ff,0); | |
hline(0,319,0,1); | |
hline(0,319,199,1); | |
vline(0,199,0,1); | |
vline(0,199,319,1); | |
end; | |
begin {main} | |
screen_open; | |
getintvec(9,@bios9); {hold bios} | |
setintvec(9,addr(mybios9)); {put mine in} | |
play_screen; a:=0; | |
xp:=215; yp:=100; dxp:=-1; dyp:=0; death:=0; {init vars, you can play} | |
xe:=107; ye:=100; dxe:=1; dye:=0; {with these } | |
repeat | |
xp:=xp+dxp; yp:=yp+dyp; | |
xe:=xe+dxe; ye:=ye+dye; | |
if (pget(xp,yp)<>0) then death:=1 | |
else if (pget(xe,ye)<>0) then death:=2; | |
pset(xp,yp,2); pset(xe,ye,3); | |
enemy_move(xe,ye,dxe,dye,cdlevel); | |
if pl=1 then | |
case a of | |
72 : begin dxp:=0; dyp:=-1 end; | |
77 : begin dxp:=1; dyp:=0 end; | |
80 : begin dxp:=0; dyp:=1 end; | |
75 : begin dxp:=-1; dyp:=0 end; | |
end else enemy_move(xp,yp,dxp,dyp,pdlevel); | |
delay(del); | |
until (a=1) or (death>0); {Death or escape was pressed} | |
setintvec(9,@bios9); | |
screen_close; | |
case death of | |
0 : writeln('Escape was pressed!'); | |
1 : writeln('Player 2 won!'); | |
2 : writeln('Player 1 won!'); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment