diff --git a/src/Makefile b/src/Makefile index 46be871..7d6a8b2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ FPC = fpc GAME_SRC = gohamster.pas arena_m.pas cell_m.pas creature_m.pas debug_m.pas \ ghost_m.pas graphics_m.pas hamster_m.pas keys_m.pas math_m.pas \ - trace_m.pas + trace_m.pas _banners_m.pas all: gohamster @@ -14,3 +14,4 @@ gohamster: $(GAME_SRC) clean: rm *.o *.ppu gohamster + diff --git a/src/_banners_m.pas b/src/_banners_m.pas new file mode 100644 index 0000000..afd9f41 --- /dev/null +++ b/src/_banners_m.pas @@ -0,0 +1,358 @@ +{ ************************************************** } +{ ************************************************** } +{ *** *** } +{ *** *** } +{ *** AUTOMATICALLY GENERATED FILE. DO NOT EDIT. *** } +{ *** *** } +{ *** *** } +{ ************************************************** } +{ ************************************************** } +unit _banners_m; + +interface +const +KeyInfoHeight = 42; +KeyInfoWidth = 98; +MaxBannerHeight = KeyInfoHeight; +MaxBannerWidth = KeyInfoWidth; +type +BannerImage = array[1..MaxBannerHeight] of string[MaxBannerWidth]; +const +KeyInfoScreen: BannerImage = ( +' _', +' | |', +' _ __ ___ _____ _____ | | _____ _ _ ___ _', +' | ''_ ` _ \ / _ \ \ / / _ \ | |/ / _ \ | | / __| (_)', +' | | | | | | (_) \ V / __/ | < __/ |_| \__ \ _', +' |_| |_| |_|\___/ \_/ \___| |_|\_\___|\__, |___/ (_)', +' __/ |', +' _ |___/', +' / \', +' / . \', +' / / \ \', +' /_/| |\_\', +' | |', +' |_|', +' __ ========= __', +' / / (\_/) \ \', +' / /_____ ( 0_0 ) ______\ \ ', +' { ______| /-----\ |_______ }', +' \ \ |___| / /', +' \_\ / \ /_/', +' ========== _ ===========', +' | |', +' _ | | _ ', +' \ \| |/ /', +' \ \ / / ', +' \ ` / ', +' \_/', +' =========', +' _ _ _', +' | | | | | |', +' ___ _ __ __ _ ___ ___ ___| |_ ___ _ __ | |__ __ _ _ __ ___ ___| |_ ___ _ __', +' / __| ''_ \ / _` |/ __/ _ \ ______ / __| __/ _ \| ''_ \ | ''_ \ / _` | ''_ ` _ \/ __| __/ _ \ ''__|', +' \__ \ |_) | (_| | (_| __/ |______| \__ \ || (_) | |_) | | | | | (_| | | | | | \__ \ || __/ |', +' |___/ .__/ \__,_|\___\___| |___/\__\___/| .__/ |_| |_|\__,_|_| |_| |_|___/\__\___|_|', +' ====| |=================== | |', +' |_| |_|', +' ___ ___ ___ _ __ __ _ _ _ ___ ___', +' / _ \/ __|/ __| ______ | ''_ \ / _` | | | / __|/ _ \', +'| __/\__ \ (__ |______| | |_) | (_| | |_| \__ \ __/', +' \___||___/\___| | .__/ \__,_|\__,_|___/\___|', +'================ | |', +' |_|' +); + +ExitScreenHeight = 16; +ExitWidth = 70; +ExitHeight = 8; +ExitScreen: BannerImage = ( +' ______ _ _ _ _ ___', +'| ____| (_) | | | | | |__ \', +'| |__ __ ___| |_ | |_| |__ ___ __ _ __ _ _ __ ___ ___ ) |', +'| __| \ \/ / | __| | __| ''_ \ / _ \ / _` |/ _` | ''_ ` _ \ / _ \/ /', +'| |____ > <| | |_ | |_| | | | __/ | (_| | (_| | | | | | | __/_|', +'|______/_/\_\_|\__| \__|_| |_|\___| \__, |\__,_|_| |_| |_|\___(_)', +' __/ |', +' |___/', +'', +'', +' _ _ ___ ___ _ __ ___', +'| | | |/ _ \/ __| | ''_ \ / _ \', +'| |_| | __/\__ \ | | | | (_) |', +' \__, |\___||___/ |_| |_|\___/', +' __/ |', +' |___/', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'' +); + +PauseHeight = 22; +PauseWidth = 76; +PauseAscii: BannerImage = ( +' _', +' | |', +' _ __ __ _ _ _ ___ ___ __| |', +' | ''_ \ / _` | | | / __|/ _ \/ _` |', +' | |_) | (_| | |_| \__ \ __/ (_| |', +' | .__/ \__,_|\__,_|___/\___|\__,_| ', +' | | ', +' |_| _ _', +' | | (_)', +' ___ _ __ __ _ __ ___ ___ ___ _ __ | |_ _ _ __ _ _ ___', +'/ __| ''_ \ / _` |/ __/ _ \ ______ / __/ _ \| ''_ \| __| | ''_ \| | | |/ _ \', +'\__ \ |_) | (_| | (_| __/ |______| | (_| (_) | | | | |_| | | | | |_| | __/', +'|___/ .__/ \__,_|\___\___| \___\___/|_| |_|\__|_|_| |_|\__,_|\___|', +'====| |===================', +' |_| _ _ _', +' (_) | | |', +' __ _ __ _ _ _ _| |_ | |_ ___ _ __ ___ ___ _ __ _ _', +' / _` | ______ / _` | | | | | __| | __/ _ \ | ''_ ` _ \ / _ \ ''_ \| | | |', +'| (_| | |______| | (_| | |_| | | |_ | || (_) | | | | | | | __/ | | | |_| |', +' \__, | \__, |\__,_|_|\__| \__\___/ |_| |_| |_|\___|_| '' |_|\__,_|', +'====| |= | |', +' |_| |_|', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'' +); + +GameCompleteHeight = 14; +GameCompleteWidth = 74; +GameCompleteScoreWidth = 50; +GameComplete: BannerImage = ( +' _____ _ _ _ ', +' / ____| | | | | | |', +'| | __ __ _ _ __ ___ ___ ___ ___ _ __ ___ _ __ | | ___| |_ ___| |', +'| | |_ |/ _` | ''_ ` _ \ / _ \ / __/ _ \| ''_ ` _ \| ''_ \| |/ _ \ __/ _ \ |', +'| |__| | (_| | | | | | | __/ | (_| (_) | | | | | | |_) | | __/ || __/_|', +' \_____|\__,_|_| |_| |_|\___| \___\___/|_| |_| |_| .__/|_|\___|\__\___(_)', +' | |', +' |_|', +'__ __', +'\ \ / / _ ', +' \ \_/ /__ _ _ _ __ ___ ___ ___ _ __ ___(_)', +' \ / _ \| | | | ''__| / __|/ __/ _ \| ''__/ _ \', +' | | (_) | |_| | | \__ \ (_| (_) | | | __/_ ', +' |_|\___/ \__,_|_| |___/\___\___/|_| \___(_)', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'' +); + +GameMenuHeight = 36; +GameNameHeight = 6; +GameNameWidth = 58; +NewGameHeight = 6; +HighScoreHeight = 8; +MenuInfoHeight = 8; +ContinueHeight = 6; +ContinueWidth = 41; +GameMenuScreen: BannerImage = ( +' _____ _ _ _ _', +' / ____| | | | | | | | |', +'| | __ ___ | | | |__| | __ _ _ __ ___ ___| |_ ___ _ __', +'| | |_ |/ _ \| | | __ |/ _` | ''_ ` _ \/ __| __/ _ \ ''__|', +'| |__| | (_) |_| | | | | (_| | | | | | \__ \ || __/ |', +' \_____|\___/(_) |_| |_|\__,_|_| |_| |_|___/\__\___|_|', +'', +'', +'', +'', +'', +'', +'', +'', +' _ _ _____', +'| \ | | / ____|', +'| \| | _____ __ | | __ __ _ _ __ ___ ___', +'| . ` |/ _ \ \ /\ / / | | |_ |/ _` | ''_ ` _ \ / _ \', +'| |\ | __/\ V V / | |__| | (_| | | | | | | __/', +'|_| \_|\___| \_/\_/ \_____|\__,_|_| |_| |_|\___|', +'', +'', +' _ __ _____ __', +'| |/ / |_ _| / _|', +'| '' / ___ _ _ | | _ __ | |_ ___', +'| < / _ \ | | | | | | ''_ \| _/ _ \', +'| . \ __/ |_| | _| |_| | | | || (_) |', +'|_|\_\___|\__, | |_____|_| |_|_| \___/', +' __/ |', +' |___/', +' _____ _ _ ', +' / ____| | | (_) ', +'| | ___ _ __ | |_ _ _ __ _ _ ___ ', +'| | / _ \| ''_ \| __| | ''_ \| | | |/ _ \', +'| |___| (_) | | | | |_| | | | | |_| | __/', +' \_____\___/|_| |_|\__|_|_| |_|\__,_|\___|', +'', +'', +'', +'', +'', +'' +); + +GameOverHeight = 40; +GameOverWidth = 63; +GameOverScreen: BannerImage = ( +' _____ __ __ ______ ', +' / ____| /\ | \/ | ____|', +' | | __ / \ | \ / | |__ ', +' | | |_ | / /\ \ | |\/| | __|', +' | |__| |/ ____ \| | | | |____', +' \_____/_/ \_\_| |_|______|', +' ______ ________ _____', +' / __ \ \ / / ____| __ \', +' | | | \ \ / /| |__ | |__) |', +' | | | |\ \/ / | __| | _ /', +' | |__| | \ / | |____| | \ \', +' \____/ \/ |______|_| \_\', +'', +' ____ ____', +' / o@@\ /@@o \', +' / /``\@\ __,-==-,__ /@/``\ \', +' / /` `||//\______/ \||` `\ \', +' | |` // __ __ \\ `| |', +' \ \` (/ /;g\ /g;\ \) `/ |', +' \_\__(( " .. " )____/_/', +' \ " __ " / ', +' @@@@@@(||)@@@@`@@`@@@@(||)@@@@@@@', +' @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@', +' @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@', +' @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@', +' ', +' _ _ ___', +' | | (_) |__ \', +' ___ ___ _ __ | |_ _ _ __ _ _ ___ ) |', +' / __/ _ \| ''_ \| __| | ''_ \| | | |/ _ \ / /', +' | (_| (_) | | | | |_| | | | | |_| | __/ |_|', +' \___\___/|_| |_|\__|_|_| |_|\__,_|\___| (_)', +' ___ ___ __ ___ ___', +'| _| |_ | \ \ | _| |_ |', +'| | _ _ | | ___ ___ \ \ | | _ __ | | ___', +'| | | | | | | |/ _ \/ __| \ \ | | | ''_ \ | |/ _ \', +'| | | |_| | | | __/\__ \ \ \ | | | | | | | | (_) |', +'| |_ \__, | _| |\___||___/ \ \ | |_ |_| |_| _| |\___/', +'|___|=====/ |=|___| \_\ |___|=========|___|', +' |___/', +'', +'' +); + +LevelAnnounceHeight = 6; +LevelAnnounceWidth = 24; +LevelAnnounce: BannerImage = ( +' _ _ ', +'| | | |', +'| | _____ _____| |', +'| | / _ \ \ / / _ \ |', +'| |___| __/\ V / __/ |', +'|______\___| \_/ \___|_|', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'', +'' +); + +implementation +end. + diff --git a/src/arena_m.pas b/src/arena_m.pas index 4e9cd6e..5f5a134 100644 --- a/src/arena_m.pas +++ b/src/arena_m.pas @@ -2,7 +2,7 @@ unit arena_m; interface -uses creature_m, trace_m, hamster_m, debug_m; +uses creature_m, trace_m, hamster_m; const ArenaH = 33; @@ -12,10 +12,10 @@ const ArenaSymbol = ' '; type - arenaBooleanMatrix = array [1..ArenaW, 1..ArenaH] of boolean; + arenaMatrix = array [1..ArenaW, 1..ArenaH] of boolean; arena = record - captured, borders: arenaBooleanMatrix; + captured, borders: arenaMatrix; end; function ArenaSplited(var h: creature; var t: tracePtr; var a: arena): boolean; @@ -36,7 +36,7 @@ implementation uses cell_m, graphics_m, math_m; -procedure Fill(var m: arenaBooleanMatrix; val: boolean); +procedure Fill(var m: arenaMatrix; val: boolean); var i, j: integer; begin diff --git a/src/debug_m.pas b/src/debug_m.pas index 3029f8f..2a0652b 100644 --- a/src/debug_m.pas +++ b/src/debug_m.pas @@ -2,11 +2,11 @@ unit debug_m; interface -uses {arena_m,} cell_m, creature_m; +uses arena_m, cell_m, creature_m; procedure Debug; procedure DebugCell(cell: cellItemPtr); -{procedure Print(var m: arenaBooleanMatrix);} +procedure Print(var m: arenaMatrix); procedure PrintCreatureDebug(var cr: creature); @@ -34,8 +34,7 @@ begin DebugTmp := DebugTmp + 1 end; -{ -procedure Print(var m: arenaBooleanMatrix); +procedure Print(var m: arenaMatrix); var i, j: integer; begin @@ -50,7 +49,6 @@ begin end; GotoXY(1, 1) end; -} procedure PrintCreatureDebug(var cr: creature); var diff --git a/src/gohamster.pas b/src/gohamster.pas index 113f2a4..5e4274c 100644 --- a/src/gohamster.pas +++ b/src/gohamster.pas @@ -1,9 +1,9 @@ program go_hamster; -uses crt, arena_m, trace_m, creature_m, graphics_m, hamster_m, keys_m, ghost_m, - debug_m; +uses crt, arena_m, trace_m, creature_m, graphics_m, hamster_m, keys_m, + ghost_m, debug_m; const - DelaySizeMs = 75; + DelaySizeMs = 100; procedure RunLevel; var @@ -17,6 +17,7 @@ begin InitGhost(g); DrawCreature(h); DrawCreature(g); + DrawScore(12345); while continueLevel do begin delay(DelaySizeMs); @@ -48,3 +49,4 @@ begin RunLevel; clrscr end. + diff --git a/src/graphics_m.pas b/src/graphics_m.pas index 2cd6aea..6307153 100644 --- a/src/graphics_m.pas +++ b/src/graphics_m.pas @@ -4,15 +4,17 @@ interface uses arena_m, creature_m, hamster_m, trace_m; -procedure DrawAfterStep(var hamster: creature; var t: tracePtr; var a: arena); +function IsTerminalValid: boolean; procedure DrawAfterStep(var cr: creature; var a: arena); +procedure DrawAfterStep(var hamster: creature; var t: tracePtr; var a: arena); procedure DrawArenaBorders(var a: arena); procedure DrawArenaCell(arenaX, arenaY: integer; symbol: char); procedure DrawArenaEdges; procedure DrawCreature(var cr: creature); +{procedure DrawKills(killCounter: integer);} +procedure DrawScore(s: integer); procedure DrawLevel; procedure EraseTrace(var hamster: creature; t: tracePtr); -function IsTerminalValid: boolean; procedure PrintTerminalHelp; implementation @@ -25,8 +27,10 @@ const BorderSize = 1; ScreenW = (ArenaW - 1) * CellSize + BorderSize * 2; { 79 } ScreenH = (ArenaH + InterfaceH) * CellSize + BorderSize; + InterfaceCellW = ScreenW div 3; WidthCoefficient = 2; InterfaceBarH = ScreenW - ArenaH * CellSize - BorderSize * 2; { 14 } + LetterWidth = 6; function IsTerminalValid: boolean; begin @@ -88,12 +92,10 @@ end; procedure DrawInterface; -var - cellW: integer = ScreenW div 3; begin DrawLineX(1, InterfaceBarH, ScreenW * WidthCoefficient); - DrawLineY(cellW * WidthCoefficient, 1, InterfaceBarH); - DrawLineY(cellW * 2 * WidthCoefficient + 1, 1, InterfaceBarH) + DrawLineY(InterfaceCellW * WidthCoefficient, 1, InterfaceBarH); + DrawLineY(InterfaceCellW * 2 * WidthCoefficient + 1, 1, InterfaceBarH) end; procedure DrawLevel; @@ -274,4 +276,267 @@ begin DrawCreature(cr) end; +{ +procedure DrawKills(killCounter: integer); +begin + GotoXY(1, 81); + while killCounter <> 0 do + begin + write(killCounter mod 10); + killCounter := killCounter div 10 + end; + GotoXY(1, 1) +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 + begin + GotoXY(x, y + i); + for j := 0 to w do + write(ch) + end; + GotoXY(1, 1) +end; + +type + stackIntPtr = ^stackIntItem; + + stackIntItem = record + val: integer; + next: stackIntPtr + end; + + StackInt = record + top: stackIntPtr + end; + +procedure StackIntInit(var s: StackInt); +begin + s.top := nil +end; + +procedure StackPush(var st: StackInt; val: integer); +var + tmp: stackIntPtr; +begin + new(tmp); + tmp^.val := val; + tmp^.next := st.top; + st.top := tmp +end; + +procedure StackPop(var st: StackInt); +var + tmp: stackIntPtr; +begin + tmp := st.top; + st.top := st.top^.next; + dispose(tmp) +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 +end; + +procedure DrawScore(s: integer); +var + killBar: integer = InterfaceCellW * 2 * WidthCoefficient + 1; + x, y: integer; + i: integer = 0; + st: StackInt; +begin + StackIntInit(st); + if s = 0 then + StackPush(st, 0); + while s <> 0 do + begin + StackPush(st, s mod 10); + s := s div 10 + end; + x := killBar + InterfaceCellW div 4; + y := InterfaceBarH div 4 + BorderSize + 1; + while st.top <> nil do + begin + DrawDigit(x + (LetterWidth + 1) * i, y, st.top^.val); + StackPop(st); + i := i + 1 + end +end; + end. diff --git a/src/keys_m.pas b/src/keys_m.pas index d84cf12..932c66a 100644 --- a/src/keys_m.pas +++ b/src/keys_m.pas @@ -64,7 +64,7 @@ var keyCode: integer; begin GetKey(keyCode); - { + {DEBUG} if keyCode = BOrd then Print(a.borders); if keyCode = COrd then @@ -77,7 +77,7 @@ begin writeln(GetLength(t)); GotoXY(1, 1) end; - } + {DEBUG} if (keyCode = ArrowLeftOrd) or (keyCode = ArrowRightOrd) or (keyCode = ArrowUpOrd) or (keyCode = ArrowDownOrd) or (keyCode = SpaceOrd) then