Merge pull request 'feat/TD-011-add-scenes-screens' (#10) from dev into main
Reviewed-on: #10
This commit is contained in:
commit
6c4c204a07
@ -8,7 +8,7 @@ const
|
||||
BorderSize = 1;
|
||||
CellSize = 2;
|
||||
LifeBarX = 33;
|
||||
ScreenW = (ArenaW - 1) * CellSize + BorderSize * 2; { 79 }
|
||||
ScreenW = (ArenaW - 1) * CellSize + BorderSize * 2; { 82 }
|
||||
InterfaceBarH = ScreenW - ArenaH * CellSize - BorderSize * 2; { 14 }
|
||||
InterfaceCellW = ScreenW div 3;
|
||||
InterfaceH = 6;
|
||||
@ -20,6 +20,7 @@ procedure DrawArenaCell(arenaX, arenaY: integer; symbol: char);
|
||||
procedure DrawArenaEdges;
|
||||
procedure DrawEdge(x, y: integer; var a: arena);
|
||||
procedure DrawLevel;
|
||||
procedure DrawRectangle(x0, y0, h, w: integer);
|
||||
|
||||
implementation
|
||||
|
||||
@ -157,6 +158,7 @@ end;
|
||||
|
||||
procedure DrawLevel;
|
||||
begin
|
||||
clrscr;
|
||||
DrawRectangle(1, 1, ScreenH, ScreenW * WidthCoefficient);
|
||||
DrawInterface
|
||||
end;
|
||||
|
||||
@ -207,10 +207,11 @@ end;
|
||||
|
||||
procedure SetArenaBorder(var t: tracePtr; var a: arena);
|
||||
begin
|
||||
if t = nil then
|
||||
exit;
|
||||
if t <> nil then
|
||||
begin
|
||||
a.borders[t^.x][t^.y] := true;
|
||||
SetArenaBorder(t^.prev, a)
|
||||
end
|
||||
end;
|
||||
|
||||
function IsOnEdge(var cr: creature): boolean;
|
||||
@ -395,7 +396,6 @@ begin
|
||||
a.borders[x + 1][y] and a.borders[x][y - 1]
|
||||
end;
|
||||
|
||||
|
||||
function IsConvexCorner(var cr: creature; var a: arena): boolean;
|
||||
var
|
||||
x, y, nextX, nextY: integer;
|
||||
|
||||
178
src/ascii_arts_m.pas
Normal file
178
src/ascii_arts_m.pas
Normal file
@ -0,0 +1,178 @@
|
||||
unit ascii_arts_m;
|
||||
|
||||
interface
|
||||
|
||||
const
|
||||
DigitHeight = 5;
|
||||
DigitWidth = 5;
|
||||
DigitsAscii: array[0..9] of array[1..DigitHeight] of string = (
|
||||
|
||||
(
|
||||
'@@@@@',
|
||||
'@ @',
|
||||
'@ @',
|
||||
'@ @',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
' @ ',
|
||||
' @@ ',
|
||||
'@ @ ',
|
||||
' @ ',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
' @',
|
||||
'@@@@@',
|
||||
'@ ',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
' @',
|
||||
'@@@@@',
|
||||
' @',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@ @',
|
||||
'@ @',
|
||||
'@@@@@',
|
||||
' @',
|
||||
' @'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
'@ ',
|
||||
'@@@@@',
|
||||
' @',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
'@ ',
|
||||
'@@@@@',
|
||||
'@ @',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
' @',
|
||||
' @',
|
||||
' @',
|
||||
' @'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
'@ @',
|
||||
'@@@@@',
|
||||
'@ @',
|
||||
'@@@@@'
|
||||
),
|
||||
(
|
||||
'@@@@@',
|
||||
'@ @',
|
||||
'@@@@@',
|
||||
' @',
|
||||
'@@@@@'
|
||||
)
|
||||
);
|
||||
GameNameHeight = 6;
|
||||
GameNameWidth = 58;
|
||||
GameNameAscii: array[1..GameNameHeight] of string = (
|
||||
' _____ _ _ _ _',
|
||||
' / ____| | | | | | | | |',
|
||||
'| | __ ___ | | | |__| | __ _ _ __ ___ ___| |_ ___ _ __',
|
||||
'| | |_ |/ _ \| | | __ |/ _` | ''_ ` _ \/ __| __/ _ \ ''__|',
|
||||
'| |__| | (_) |_| | | | | (_| | | | | | \__ \ || __/ |',
|
||||
' \_____|\___/(_) |_| |_|\__,_|_| |_| |_|___/\__\___|_|'
|
||||
);
|
||||
NewGameHeight = 6;
|
||||
NewGameAscii: array[1..NewGameHeight] of string = (
|
||||
' _ _ _____',
|
||||
'| \ | | / ____|',
|
||||
'| \| | _____ __ | | __ __ _ _ __ ___ ___',
|
||||
'| . ` |/ _ \ \ /\ / / | | |_ |/ _` | ''_ ` _ \ / _ \',
|
||||
'| |\ | __/\ V V / | |__| | (_| | | | | | | __/',
|
||||
'|_| \_|\___| \_/\_/ \_____|\__,_|_| |_| |_|\___|'
|
||||
);
|
||||
HighScoreHeight = 8;
|
||||
HighScoreAscii: array[1..HighScoreHeight] of string = (
|
||||
' _ _ _ _ _____',
|
||||
'| | | (_) | | / ____|',
|
||||
'| |__| |_ __ _| |__ | (___ ___ ___ _ __ ___',
|
||||
'| __ | |/ _` | ''_ \ \___ \ / __/ _ \| ''__/ _ \',
|
||||
'| | | | | (_| | | | | ____) | (_| (_) | | | __/',
|
||||
'|_| |_|_|\__, |_| |_| |_____/ \___\___/|_| \___|',
|
||||
' __/ |',
|
||||
' |___/'
|
||||
);
|
||||
|
||||
KeyInfoHeight = 8;
|
||||
KeyInfoAscii: array[1..KeyInfoHeight] of string = (
|
||||
' _ __ _____ __',
|
||||
'| |/ / |_ _| / _|',
|
||||
'| '' / ___ _ _ | | _ __ | |_ ___',
|
||||
'| < / _ \ | | | | | | ''_ \| _/ _ \',
|
||||
'| . \ __/ |_| | _| |_| | | | || (_) |',
|
||||
'|_|\_\___|\__, | |_____|_| |_|_| \___/',
|
||||
' __/ |',
|
||||
' |___/'
|
||||
);
|
||||
|
||||
ContinueHeight = 6;
|
||||
ContinueAscii: array[1..ContinueHeight] of string = (
|
||||
' _____ _ _ ',
|
||||
' / ____| | | (_) ',
|
||||
'| | ___ _ __ | |_ _ _ __ _ _ ___ ',
|
||||
'| | / _ \| ''_ \| __| | ''_ \| | | |/ _ \',
|
||||
'| |___| (_) | | | | |_| | | | | |_| | __/',
|
||||
' \_____\___/|_| |_|\__|_|_| |_|\__,_|\___|'
|
||||
);
|
||||
|
||||
ExitHeight = 8;
|
||||
ExitWidth = 70;
|
||||
ExitAscii: array[1..ExitHeight] of string = (
|
||||
' ______ _ _ _ _ ___',
|
||||
'| ____| (_) | | | | | |__ \',
|
||||
'| |__ __ ___| |_ | |_| |__ ___ __ _ __ _ _ __ ___ ___ ) |',
|
||||
'| __| \ \/ / | __| | __| ''_ \ / _ \ / _` |/ _` | ''_ ` _ \ / _ \/ /',
|
||||
'| |____ > <| | |_ | |_| | | | __/ | (_| | (_| | | | | | | __/_|',
|
||||
'|______/_/\_\_|\__| \__|_| |_|\___| \__, |\__,_|_| |_| |_|\___(_)',
|
||||
' __/ |',
|
||||
' |___/'
|
||||
);
|
||||
|
||||
YesHeight = 6;
|
||||
YesAscii: array[1..YesHeight] of string = (
|
||||
' _ _ ___ ___',
|
||||
'| | | |/ _ \/ __|',
|
||||
'| |_| | __/\__ \',
|
||||
' \__, |\___||___/',
|
||||
' __/ |',
|
||||
' |___/'
|
||||
);
|
||||
|
||||
NoHeight = 4;
|
||||
NoWidth = 13;
|
||||
NoAscii: array[1..NoHeight] of string = (
|
||||
' _ __ ___',
|
||||
'| ''_ \ / _ \',
|
||||
'| | | | (_) |',
|
||||
'|_| |_|\___/'
|
||||
);
|
||||
|
||||
HamsterHeight = 5;
|
||||
HamsterWidth = 7;
|
||||
HamsterStayAscii: array[1..HamsterHeight] of string = (
|
||||
' (\_/)',
|
||||
'( o_o )',
|
||||
'/-----\',
|
||||
' |___|',
|
||||
' / \'
|
||||
);
|
||||
|
||||
implementation
|
||||
end.
|
||||
|
||||
@ -3,18 +3,32 @@ unit game_m;
|
||||
interface
|
||||
|
||||
type
|
||||
state = (gameExit, gameMenu, gamePause, gameLevel);
|
||||
menuState = (menuNewGame, menuHighScore, menuKeyInfo, menuContinue);
|
||||
exitState = (exitYes, exitNo);
|
||||
|
||||
gameState = record
|
||||
curExit: exitState;
|
||||
curMenu: menuState;
|
||||
curState: state;
|
||||
hamsterAlive: boolean;
|
||||
score, life, speedBonus, slowBonus: integer;
|
||||
paused, level, hamsterAlive: boolean;
|
||||
shutdown: boolean
|
||||
end;
|
||||
|
||||
procedure DecreaseLife(var g: gameState);
|
||||
procedure GameOver(var g: gameState);
|
||||
procedure InitGame(var g: gameState);
|
||||
procedure NextExitState(var g: gameState);
|
||||
procedure NextMenuState(var g: gameState);
|
||||
procedure PreviousExitState(var g: gameState);
|
||||
procedure PreviousMenuState(var g: gameState);
|
||||
procedure RunExit(var g: gameState);
|
||||
procedure RunMenu(var g: gameState);
|
||||
|
||||
implementation
|
||||
|
||||
uses graphics_m;
|
||||
uses crt, arena_graphics_m, graphics_m, keys_m;
|
||||
|
||||
const
|
||||
StartScore = 0;
|
||||
@ -22,6 +36,7 @@ const
|
||||
BonusTurns = 45;
|
||||
StartSpeedBonus = 0;
|
||||
StartSlowBonus = 0;
|
||||
KeyDelayMs = 25;
|
||||
|
||||
procedure InitGame(var g: gameState);
|
||||
begin
|
||||
@ -29,7 +44,10 @@ begin
|
||||
g.life := StartLifes;
|
||||
g.speedBonus := StartSpeedBonus;
|
||||
g.slowBonus := StartSlowBonus;
|
||||
g.hamsterAlive := true
|
||||
g.hamsterAlive := true;
|
||||
g.curState := gameMenu;
|
||||
g.curMenu := menuNewGame;
|
||||
g.shutdown := false
|
||||
end;
|
||||
|
||||
procedure DecreaseLife(var g: gameState);
|
||||
@ -38,6 +56,72 @@ begin
|
||||
DrawLifes(g)
|
||||
end;
|
||||
|
||||
procedure RunMenu(var g: gameState);
|
||||
begin
|
||||
g.curState := gameMenu;
|
||||
DrawMenu(g);
|
||||
while g.curState = gameMenu do
|
||||
begin
|
||||
delay(KeyDelayMs);
|
||||
if keypressed then
|
||||
HandleMenuKey(g);
|
||||
if g.shutdown then
|
||||
break;
|
||||
if g.curState = gameExit then
|
||||
begin
|
||||
g.curState := gameMenu;
|
||||
DrawMenu(g)
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
procedure RunExit(var g: gameState);
|
||||
var
|
||||
keep: boolean = true;
|
||||
begin
|
||||
g.curState := gameExit;
|
||||
DrawExit(g);
|
||||
while keep do
|
||||
begin
|
||||
delay(KeyDelayMs);
|
||||
if keypressed then
|
||||
HandleExitKey(keep, g)
|
||||
end;
|
||||
EraseExit
|
||||
end;
|
||||
|
||||
procedure PreviousMenuState(var g: gameState);
|
||||
begin
|
||||
if g.curMenu = menuNewGame then
|
||||
g.curMenu := menuContinue
|
||||
else
|
||||
g.curMenu := pred(g.curMenu)
|
||||
end;
|
||||
|
||||
procedure NextMenuState(var g: gameState);
|
||||
begin
|
||||
if g.curMenu = menuContinue then
|
||||
g.curMenu := menuNewGame
|
||||
else
|
||||
g.curMenu := succ(g.curMenu)
|
||||
end;
|
||||
|
||||
procedure NextExitState(var g: gameState);
|
||||
begin
|
||||
if g.curExit = exitNo then
|
||||
g.curExit := exitYes
|
||||
else
|
||||
g.curExit := succ(g.curExit)
|
||||
end;
|
||||
|
||||
procedure PreviousExitState(var g: gameState);
|
||||
begin
|
||||
if g.curExit = exitYes then
|
||||
g.curExit := exitNo
|
||||
else
|
||||
g.curExit := pred(g.curExit)
|
||||
end;
|
||||
|
||||
procedure GameOver(var g: gameState);
|
||||
begin
|
||||
end;
|
||||
|
||||
@ -5,18 +5,16 @@ uses crt, arena_m, arena_graphics_m, trace_m, creature_m, graphics_m,
|
||||
const
|
||||
DelaySizeMs = 100;
|
||||
|
||||
procedure RunLevel;
|
||||
procedure RunLevel(var game: gameState);
|
||||
var
|
||||
h, g: creature;
|
||||
a: arena;
|
||||
t: tracePtr = nil;
|
||||
continueLevel: boolean = true;
|
||||
game: gameState;
|
||||
begin
|
||||
InitArena(a);
|
||||
InitHamster(h);
|
||||
InitGhost(g);
|
||||
InitGame(game);
|
||||
DrawCreature(h);
|
||||
DrawCreature(g);
|
||||
DrawScore(game);
|
||||
@ -58,15 +56,18 @@ begin
|
||||
end
|
||||
end;
|
||||
|
||||
var
|
||||
g: gameState;
|
||||
begin
|
||||
if not IsTerminalValid then
|
||||
begin
|
||||
PrintTerminalHelp;
|
||||
exit
|
||||
end;
|
||||
InitGame(g);
|
||||
{RunLevel(g);}
|
||||
clrscr;
|
||||
DrawLevel;
|
||||
RunLevel;
|
||||
RunMenu(g);
|
||||
clrscr
|
||||
end.
|
||||
|
||||
|
||||
@ -8,22 +8,52 @@ function IsTerminalValid: boolean;
|
||||
procedure DrawAfterStep(var cr: creature; var a: arena);
|
||||
procedure DrawAfterStep(var hamster: creature; var t: tracePtr; var a: arena);
|
||||
procedure DrawCreature(var cr: creature);
|
||||
procedure DrawLifes(var game: GameState);
|
||||
procedure DrawScore(var game: GameState);
|
||||
procedure DrawExitState(s: exitState);
|
||||
procedure DrawExit(var g: gameState);
|
||||
procedure DrawLifes(var g: GameState);
|
||||
procedure DrawMenuState(s: menuState);
|
||||
procedure DrawMenu(var g: gameState);
|
||||
procedure DrawScore(var g: GameState);
|
||||
procedure EraseExit;
|
||||
procedure EraseExitState(s: exitState);
|
||||
procedure EraseMenu;
|
||||
procedure EraseMenuState(s: menuState);
|
||||
procedure EraseStepTrace(var hamster: creature; t: tracePtr);
|
||||
procedure EraseTrace(t: tracePtr; var a: arena);
|
||||
procedure PrintTerminalHelp;
|
||||
|
||||
implementation
|
||||
|
||||
uses crt, math_m;
|
||||
uses crt, math_m, ascii_arts_m;
|
||||
|
||||
const
|
||||
LetterWidth = 6;
|
||||
Notation = 10;
|
||||
DigitSpaceSize = 1;
|
||||
InterfaceMarginY = InterfaceBarH div 4 + BorderSize + 1;
|
||||
BigLetterWidth = 8;
|
||||
DigitWidth = 6;
|
||||
GameNameX = ScreenW * WidthCoefficient div 3 + 4;
|
||||
GameNameY = 12;
|
||||
NameHeightPadding = 8;
|
||||
MenuHeightPadding = 2;
|
||||
MenuWidthPadding = 4;
|
||||
MenuHamsterX = GameNameX - HamsterWidth - MenuWidthPadding;
|
||||
NewGameY = GameNameY + GameNameHeight + NameHeightPadding;
|
||||
HighScoreY = NewGameY + NewGameHeight + MenuHeightPadding;
|
||||
KeyInfoY = HighScoreY + HighScoreHeight;
|
||||
ContinueY = KeyInfoY + KeyInfoHeight;
|
||||
InterfaceMarginX = InterfaceCellW div 4;
|
||||
InterfaceMarginY = InterfaceBarH div 4 + BorderSize + 1;
|
||||
LetterWidth = 5;
|
||||
Notation = 10;
|
||||
PunctuationWidth = 3;
|
||||
SpaceWidth = 3;
|
||||
ExitGameY = ScreenH div 2 - ExitHeight - MenuHeightPadding;
|
||||
ExitYesX = MenuHamsterX;
|
||||
ExitYesY = ExitGameY + ExitHeight + MenuHeightPadding;
|
||||
ExitNoX = ScreenW * WidthCoefficient - ExitYesX - NoWidth;
|
||||
ExitHamsterY = ExitYesY;
|
||||
HamsterYesX = ExitYesX - HamsterWidth - MenuWidthPadding;
|
||||
HamsterNoX = ExitNoX - HamsterWidth - MenuWidthPadding;
|
||||
var
|
||||
firstMenuDraw: boolean = true;
|
||||
|
||||
function IsTerminalValid: boolean;
|
||||
begin
|
||||
@ -139,161 +169,11 @@ begin
|
||||
DrawCreature(cr)
|
||||
end;
|
||||
|
||||
procedure DrawZero(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 3);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawOne(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write(' @ ');
|
||||
GotoXY(x, y + 1);
|
||||
write(' @@ ');
|
||||
GotoXY(x, y + 2);
|
||||
write('@ @ ');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @ ');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawTwo(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write(' @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write('@ ');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawThree(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write(' @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawFour(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @');
|
||||
GotoXY(x, y + 4);
|
||||
write(' @');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawFive(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ ');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawSix(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ ');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawSeven(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write(' @');
|
||||
GotoXY(x, y + 2);
|
||||
write(' @');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @');
|
||||
GotoXY(x, y + 4);
|
||||
write(' @');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawEight(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure DrawNine(x, y: integer);
|
||||
begin
|
||||
GotoXY(x, y);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 1);
|
||||
write('@ @');
|
||||
GotoXY(x, y + 2);
|
||||
write('@@@@@');
|
||||
GotoXY(x, y + 3);
|
||||
write(' @');
|
||||
GotoXY(x, y + 4);
|
||||
write('@@@@@');
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure FillRectangle(x, y, w, h: integer; ch: char);
|
||||
var
|
||||
i, j: integer;
|
||||
begin
|
||||
for i := 0 to h do
|
||||
for i := 0 to h - 1 do
|
||||
begin
|
||||
GotoXY(x, y + i);
|
||||
for j := 0 to w do
|
||||
@ -338,30 +218,26 @@ begin
|
||||
dispose(tmp)
|
||||
end;
|
||||
|
||||
procedure DrawAscii(x, y, h: integer; var a: array of string);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := 1 to h do
|
||||
begin
|
||||
GotoXY(x, y + i - 1);
|
||||
write(a[i - 1])
|
||||
end;
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
|
||||
procedure EraseRectangle(x, y, w, h: integer);
|
||||
begin
|
||||
FillRectangle(x, y, w, h, ' ')
|
||||
end;
|
||||
|
||||
procedure DrawDigit(x, y, digit: integer);
|
||||
begin
|
||||
case digit of
|
||||
0:
|
||||
DrawZero(x, y);
|
||||
1:
|
||||
DrawOne(x, y);
|
||||
2:
|
||||
DrawTwo(x, y);
|
||||
3:
|
||||
DrawThree(x, y);
|
||||
4:
|
||||
DrawFour(x, y);
|
||||
5:
|
||||
DrawFive(x, y);
|
||||
6:
|
||||
DrawSix(x, y);
|
||||
7:
|
||||
DrawSeven(x, y);
|
||||
8:
|
||||
DrawEight(x, y);
|
||||
9:
|
||||
DrawNine(x, y)
|
||||
end
|
||||
DrawAscii(x, y, DigitHeight, DigitsAscii[digit])
|
||||
end;
|
||||
|
||||
procedure DrawNumber(interfaceX: integer; s: longint);
|
||||
@ -382,22 +258,128 @@ begin
|
||||
y := InterfaceMarginY;
|
||||
while st.top <> nil do
|
||||
begin
|
||||
DrawDigit(x + (LetterWidth + DigitSpaceSize) * i, y, st.top^.val);
|
||||
DrawDigit(x + (DigitWidth + SpaceWidth) * i, y, st.top^.val);
|
||||
StackPop(st);
|
||||
i := i + 1
|
||||
end
|
||||
end;
|
||||
|
||||
procedure DrawLifes(var game: GameState);
|
||||
procedure DrawLifes(var g: GameState);
|
||||
begin
|
||||
DrawNumber(LifeBarX, game.life)
|
||||
DrawNumber(LifeBarX, g.life)
|
||||
end;
|
||||
|
||||
procedure DrawScore(var game: GameState);
|
||||
procedure DrawScore(var g: GameState);
|
||||
var
|
||||
killBarX: integer = InterfaceCellW * 2 * WidthCoefficient + BorderSize;
|
||||
begin
|
||||
DrawNumber(killBarX, game.score)
|
||||
DrawNumber(killBarX, g.score)
|
||||
end;
|
||||
|
||||
procedure EraseAll;
|
||||
begin
|
||||
FillRectangle(2, 2, (ScreenW - 2) * WidthCoefficient, ScreenH - 2, ' ')
|
||||
end;
|
||||
|
||||
procedure DrawMenuState(s: menuState);
|
||||
begin
|
||||
case s of
|
||||
menuNewGame:
|
||||
DrawAscii(MenuHamsterX, NewGameY + 1,
|
||||
HamsterHeight, HamsterStayAscii);
|
||||
menuHighScore:
|
||||
DrawAscii(MenuHamsterX, HighScoreY + 1,
|
||||
HamsterHeight, HamsterStayAscii);
|
||||
menuKeyInfo:
|
||||
DrawAscii(MenuHamsterX, KeyInfoY + 1,
|
||||
HamsterHeight, HamsterStayAscii);
|
||||
menuContinue:
|
||||
DrawAscii(MenuHamsterX, ContinueY + 1,
|
||||
HamsterHeight, HamsterStayAscii)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure DrawMenu(var g: gameState);
|
||||
var
|
||||
y: integer = GameNameY;
|
||||
begin
|
||||
if firstMenuDraw then
|
||||
begin
|
||||
DrawRectangle(1, 1, ScreenH, ScreenW * WidthCoefficient);
|
||||
firstMenuDraw := not firstMenuDraw
|
||||
end;
|
||||
DrawAscii(GameNameX, y, GameNameHeight, GameNameAscii);
|
||||
DrawAscii(GameNameX, NewGameY, NewGameHeight, NewGameAscii);
|
||||
DrawAscii(GameNameX, HighScoreY, HighScoreHeight, HighScoreAscii);
|
||||
DrawAscii(GameNameX, KeyInfoY, KeyInfoHeight, KeyInfoAscii);
|
||||
DrawAscii(GameNameX, ContinueY, ContinueHeight, ContinueAscii);
|
||||
DrawMenuState(g.curMenu)
|
||||
end;
|
||||
|
||||
procedure EraseMenuState(s: menuState);
|
||||
begin
|
||||
case s of
|
||||
menuNewGame:
|
||||
EraseRectangle(MenuHamsterX, NewGameY + 1,
|
||||
HamsterWidth, HamsterHeight);
|
||||
menuHighScore:
|
||||
EraseRectangle(MenuHamsterX, HighScoreY + 1,
|
||||
HamsterWidth, HamsterHeight);
|
||||
menuKeyInfo:
|
||||
EraseRectangle(MenuHamsterX, KeyInfoY + 1,
|
||||
HamsterWidth, HamsterHeight);
|
||||
menuContinue:
|
||||
EraseRectangle(MenuHamsterX, ContinueY + 1,
|
||||
HamsterWidth, HamsterHeight)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure EraseMenu;
|
||||
begin
|
||||
EraseRectangle(MenuHamsterX, GameNameY,
|
||||
GameNameWidth + HamsterWidth + MenuWidthPadding,
|
||||
ScreenH - GameNameY * 2)
|
||||
end;
|
||||
|
||||
procedure DrawExitState(s: exitState);
|
||||
begin
|
||||
case s of
|
||||
exitYes:
|
||||
DrawAscii(HamsterYesX, ExitHamsterY,
|
||||
HamsterHeight, HamsterStayAscii);
|
||||
exitNo:
|
||||
DrawAscii(HamsterNoX, ExitHamsterY,
|
||||
HamsterHeight, HamsterStayAscii)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure DrawExit(var g: gameState);
|
||||
var
|
||||
realX: integer = ScreenW * WidthCoefficient;
|
||||
begin
|
||||
DrawAscii((realX - ExitWidth) div 2, ExitGameY, ExitHeight, ExitAscii);
|
||||
DrawAscii(ExitYesX, ExitYesY, YesHeight, YesAscii);
|
||||
DrawAscii(ExitNoX, ExitYesY, NoHeight, NoAscii);
|
||||
DrawExitState(g.curExit)
|
||||
end;
|
||||
|
||||
procedure EraseExitState(s: exitState);
|
||||
begin
|
||||
case s of
|
||||
exitYes:
|
||||
EraseRectangle(HamsterYesX, ExitHamsterY,
|
||||
HamsterWidth, HamsterHeight);
|
||||
exitNo:
|
||||
EraseRectangle(HamsterNoX, ExitHamsterY,
|
||||
HamsterWidth, HamsterHeight)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure EraseExit;
|
||||
begin
|
||||
EraseRectangle(HamsterYesX, ExitGameY,
|
||||
ExitWidth + HamsterWidth + MenuWidthPadding,
|
||||
ExitHeight + MenuHeightPadding + YesHeight)
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
108
src/keys_m.pas
108
src/keys_m.pas
@ -2,16 +2,21 @@ unit keys_m;
|
||||
|
||||
interface
|
||||
|
||||
uses crt, creature_m, arena_m, trace_m, hamster_m, debug_m;
|
||||
uses crt, creature_m, arena_m, game_m, trace_m, hamster_m, debug_m;
|
||||
|
||||
const
|
||||
SpaceOrd = 32;
|
||||
EscOrd = 27;
|
||||
CtrlCOrd = 3;
|
||||
ArrowDownOrd = -80;
|
||||
ArrowLeftOrd = -75;
|
||||
ArrowRightOrd = -77;
|
||||
ArrowDownOrd = -80;
|
||||
ArrowUpOrd = -72;
|
||||
CtrlCOrd = 3;
|
||||
EnterOrd = 13;
|
||||
EscOrd = 27;
|
||||
LowerNOrd = 110;
|
||||
LowerYOrd = 121;
|
||||
SpaceOrd = 32;
|
||||
UpperNOrd = 78;
|
||||
UpperYOrd = 89;
|
||||
{ Debug }
|
||||
BOrd = 98;
|
||||
COrd = 99;
|
||||
@ -19,11 +24,15 @@ const
|
||||
{ Debug }
|
||||
|
||||
procedure GetKey(var keyCode: integer);
|
||||
procedure HandleExitKey(var keep: boolean; var g: gameState);
|
||||
procedure HandleKey(var h: creature; var continueLevel: boolean;
|
||||
var a: arena; var t: tracePtr);
|
||||
procedure HandleMenuKey(var g: gameState);
|
||||
|
||||
implementation
|
||||
|
||||
uses graphics_m;
|
||||
|
||||
procedure GetKey(var keyCode: integer);
|
||||
var
|
||||
c: char;
|
||||
@ -40,11 +49,11 @@ begin
|
||||
end
|
||||
end;
|
||||
|
||||
procedure ChangeHamsterDelta(keyCode: integer; var h: creature);
|
||||
procedure ChangeHamsterDelta(k: integer; var h: creature);
|
||||
begin
|
||||
h.dX := 0;
|
||||
h.dY := 0;
|
||||
case keyCode of
|
||||
case k of
|
||||
ArrowLeftOrd:
|
||||
h.dX := -h.movespeed;
|
||||
ArrowRightOrd:
|
||||
@ -61,15 +70,15 @@ end;
|
||||
procedure HandleKey(var h: creature; var continueLevel: boolean;
|
||||
var a: arena; var t: tracePtr);
|
||||
var
|
||||
keyCode: integer;
|
||||
k: integer;
|
||||
begin
|
||||
GetKey(keyCode);
|
||||
GetKey(k);
|
||||
{DEBUG}
|
||||
if keyCode = BOrd then
|
||||
if k = BOrd then
|
||||
Print(a.borders);
|
||||
if keyCode = COrd then
|
||||
if k = COrd then
|
||||
Print(a.captured);
|
||||
if keyCode = LOrd then
|
||||
if k = LOrd then
|
||||
begin
|
||||
GotoXY(2, 60);
|
||||
write(' ');
|
||||
@ -78,14 +87,79 @@ begin
|
||||
GotoXY(1, 1)
|
||||
end;
|
||||
{DEBUG}
|
||||
if (keyCode = ArrowLeftOrd) or (keyCode = ArrowRightOrd) or
|
||||
(keyCode = ArrowUpOrd) or (keyCode = ArrowDownOrd) or
|
||||
(keyCode = SpaceOrd) then
|
||||
if (k = ArrowLeftOrd) or (k = ArrowRightOrd) or (k = ArrowUpOrd) or
|
||||
(k = ArrowDownOrd) or (k = SpaceOrd) then
|
||||
begin
|
||||
ChangeHamsterDelta(keyCode, h)
|
||||
ChangeHamsterDelta(k, h)
|
||||
end;
|
||||
if (keyCode = EscOrd) or (keyCode = CtrlCOrd) then
|
||||
if (k = EscOrd) or (k = CtrlCOrd) then
|
||||
continueLevel := false
|
||||
end;
|
||||
|
||||
procedure ChangeMenuState(k: integer; var g: gameState);
|
||||
begin
|
||||
case k of
|
||||
ArrowUpOrd:
|
||||
PreviousMenuState(g);
|
||||
ArrowDownOrd:
|
||||
NextMenuState(g)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure HandleMenuKey(var g: gameState);
|
||||
var
|
||||
k: integer;
|
||||
begin
|
||||
GetKey(k);
|
||||
if (k = ArrowUpOrd) or (k = ArrowDownOrd) then
|
||||
begin
|
||||
EraseMenuState(g.curMenu);
|
||||
ChangeMenuState(k, g);
|
||||
DrawMenuState(g.curMenu)
|
||||
end
|
||||
else
|
||||
if k = EscOrd then
|
||||
begin
|
||||
g.curState := gameExit;
|
||||
EraseMenu;
|
||||
RunExit(g)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure ChangeExitState(k: integer; var g: gameState);
|
||||
begin
|
||||
case k of
|
||||
ArrowRightOrd:
|
||||
NextExitState(g);
|
||||
ArrowLeftOrd:
|
||||
PreviousExitState(g)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure HandleExitKey(var keep: boolean; var g: gameState);
|
||||
var
|
||||
k: integer;
|
||||
begin
|
||||
GetKey(k);
|
||||
if (k = ArrowLeftOrd) or (k = ArrowRightOrd) then
|
||||
begin
|
||||
EraseExitState(g.curExit);
|
||||
ChangeExitState(k, g);
|
||||
DrawExitState(g.curExit);
|
||||
exit
|
||||
end;
|
||||
if k = EnterOrd then
|
||||
begin
|
||||
if g.curExit = exitYes then
|
||||
g.shutdown := true
|
||||
else
|
||||
g.curExit := exitYes;
|
||||
end;
|
||||
if (k = UpperYOrd) or (k = LowerYOrd) then
|
||||
g.shutdown := true;
|
||||
if (k = UpperNOrd) or (k = LowerNOrd) or (k = EscOrd) then
|
||||
g.curExit := exitYes;
|
||||
keep := false
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user