|
////////////////////////////////////////////////////////////////////////////////
// //
// !Yeakisen's Snake! //
// Yeakisen Productions (2007) //
// Console Graphics Unit //
// Written by Matthew Gianfrancesco //
// December 11, 2007 //
// Completed December 27, 2007 //
// //
////////////////////////////////////////////////////////////////////////////////
UNIT YSCG;
INTERFACE
TYPE
YSImage=ARRAY[0..30,0..25]OF Byte;
CONST
ColBlack=0;
ColDarkBlue=1;
ColDarkGreen=2;
ColDarkCyan=3;
ColDarkRed=4;
ColDarkViolet=5;
ColDarkYellow=6;
ColGray=7;
ColDarkGray=8;
ColBlue=9;
ColGreen=10;
ColCyan=11;
ColRed=12;
ColViolet=13;
ColYellow=14;
ColWhite=15;
Transparent=16;
PROCEDURE InitYSCG;
PROCEDURE ClearScreen;
PROCEDURE DrawColor(Text:Boolean;Color:Byte);
PROCEDURE DrawPixel(X,Y:Smallint);
PROCEDURE DrawImage(X,Y:Smallint;Image:YSImage);
FUNCTION LoadImage(Filename:String):YSImage;
PROCEDURE Pause(Milliseconds:Smallint);
PROCEDURE SetXY(X,Y:Smallint);
IMPLEMENTATION
USES
Windows;
VAR
OutputHandle:THandle;
InputHandle:THandle;
DrawCol:Byte;
PROCEDURE InitYSCG;
VAR
WindowSize:TCoord;
WindowDraw:Small_Rect;
InputData:TInputRecord;
EventsRead:Cardinal;
CursorInfo:Console_Cursor_Info;
BEGIN
WindowSize.X:=90;
WindowSize.Y:=50;
WindowDraw.Left:=0;
WindowDraw.Top:=0;
WindowDraw.Right:=89;
WindowDraw.Bottom:=49;
OutputHandle:=GetStdHandle(STD_OUTPUT_HANDLE);
InputHandle:=GetStdHandle(STD_INPUT_HANDLE);
GetConsoleCursorInfo(OutputHandle,CursorInfo);
CursorInfo.bVisible:=FALSE;
SetConsoleCursorInfo(OutputHandle,CursorInfo);
SetConsoleScreenBufferSize(OutputHandle,WindowSize);
SetConsoleWindowInfo(OutputHandle,TRUE,WindowDraw);
SetConsoleTitle('Yeakisen`s Snake');
ReadConsoleInput(InputHandle,InputData,1,EventsRead);
DrawCol:=0;
END;
PROCEDURE ClearScreen;
VAR
Coordinates:TCoord;
CellsWritten:Cardinal;
BEGIN
Coordinates.X:=0;
Coordinates.Y:=0;
FillConsoleOutputAttribute(OutputHandle,DrawCol,4500,Coordinates,CellsWritten);
END;
PROCEDURE DrawColor(Text:Boolean;Color:Byte);
BEGIN
IF(Text=FALSE)
THEN
DrawCol:=(Color*16)+Color
ELSE
SetConsoleTextAttribute(OutputHandle,Color);
END;
PROCEDURE DrawPixel(X,Y:Smallint);
VAR
XCounter,YCounter:Smallint;
Coordinates:TCoord;
CellsWritten:Cardinal;
BEGIN
FOR XCounter:=0 TO 2 DO
BEGIN
FOR YCounter:=0 TO 1 DO
BEGIN
Coordinates.X:=X*3+XCounter;
Coordinates.Y:=Y*2+YCounter;
FillConsoleOutputAttribute(OutputHandle,DrawCol,1,Coordinates,CellsWritten);
END;
END;
END;
PROCEDURE DrawImage(X,Y:Smallint;Image:YSImage);
VAR
XCounter,YCounter:Integer;
OldColor:Byte;
BEGIN
OldColor:=DrawCol;
FOR XCounter:=0 TO Image[30,0] DO
BEGIN
FOR YCounter:=0 TO Image[0,25] DO
BEGIN
IF NOT(Image[XCounter,YCounter]=Transparent)THEN
BEGIN
DrawColor(FALSE,Image[XCounter,YCounter]);
DrawPixel(X+XCounter,Y+YCounter);
END;
END;
END;
DrawCol:=OldColor;
END;
FUNCTION LoadImage(Filename:String):YSImage;
VAR
Return:YSImage;
InFile:Text;
XCounter,YCounter:Integer;
BEGIN
Assign(InFile,Filename);
Reset(InFile);
Readln(InFile,Return[30,0]);
Readln(InFile,Return[0,25]);
FOR XCounter:=0 TO Return[30,0] DO
BEGIN
FOR YCounter:=0 TO Return[0,25] DO
BEGIN
Readln(InFile,Return[XCounter,YCounter]);
END;
END;
Close(InFile);
Result:=Return;
END;
PROCEDURE Pause(Milliseconds:Smallint);
BEGIN
Sleep(Milliseconds);
END;
PROCEDURE SetXY(X,Y:Smallint);
VAR
CursorPos:TCoord;
BEGIN
CursorPos.X:=X;
CursorPos.Y:=Y;
SetConsoleCursorPosition(OutputHandle,CursorPos);
END;
END.
|