From 0a2c7d3ccb5621150d827643bc2c196f7f8db664 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 10 Sep 2015 19:57:06 +0200 Subject: More tetris wip --- tetris/blocks.prn | 22 +++++++--------------- tetris/engine.prn | 23 +++++++++++++++++++++++ tetris/io.prn | 25 ++++++++++++++++++------- tetris/tetris.prn | 7 +++---- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 tetris/engine.prn (limited to 'tetris') diff --git a/tetris/blocks.prn b/tetris/blocks.prn index 021a9b5..0eb91f5 100644 --- a/tetris/blocks.prn +++ b/tetris/blocks.prn @@ -1,26 +1,18 @@ -@includeonce "io.prn" - 7 "b_nblocks" store 15 23 71 51 54 99 114 b_nblocks mkarrayp "b_blocks" store -6 3 4 7 2 1 5 + 6 3 4 7 2 1 5 b_nblocks mkarrayp "b_blockclrs" store -@defun "b_getblock" { #arg: block idx [1..7] - "b_blocks" - swapoutvar - swap - arridx - swap - "b_blocks" - gstore +@defun "b_getblock" { #arg: block idx [0..(b_nblocks-1)] + "b_blocks" swapoutvar swap arridx swap "b_blocks" gstore } @defun "b_drawblock" { #args: x y blockidx - b_getblock - "blockbits" store + dup "blockidx" store + b_getblock "blockbits" store "y" store "x" store @@ -30,7 +22,7 @@ b_nblocks mkarrayp "b_blockclrs" store x "xx" store row1 while row1 2 % if - xx y io_gsquare + xx y blockidx io_gsquare end xx 1 + "xx" store row1 2 / "row1" store @@ -41,7 +33,7 @@ b_nblocks mkarrayp "b_blockclrs" store x "xx" store row2 while row2 2 % if - xx y io_gsquare + xx y blockidx io_gsquare end xx 1 + "xx" store row2 2 / "row2" store diff --git a/tetris/engine.prn b/tetris/engine.prn new file mode 100644 index 0000000..ebfb0c7 --- /dev/null +++ b/tetris/engine.prn @@ -0,0 +1,23 @@ +mkarray "e_blockqueue" store + +@defun "e_nextblock" { + "e_blockqueue" swapoutvar + arrlen 1 < if + "ERROR: blockqueue empty while requesting nextblock" print + error + end + 0 arridx + swap + arrpopf "e_blockqueue" store +} + +@defun "e_peekblock" { + "e_blockqueue" swapoutvar + arrlen 2 < if + 0 + else + 1 arridx + end + swap + "e_blockqueue" store +} diff --git a/tetris/io.prn b/tetris/io.prn index 8c6a320..539cbee 100644 --- a/tetris/io.prn +++ b/tetris/io.prn @@ -59,6 +59,7 @@ "-" print 1 + dup w < end + pop "+" print #1000000 sleep @@ -71,6 +72,7 @@ "|\x1B[D\x1B[B" print #bar, left, down 1 + dup h 1 - < end + pop #1000000 sleep x w + 1 + y 1 + io_goto @@ -79,6 +81,7 @@ "|\x1B[D\x1B[B" print #bar, left, down 1 + dup h 1 - < end + pop #1000000 sleep } @@ -86,15 +89,16 @@ io_pos_windowstart io_pos_windowend io_pos_windowstart diff2 io_box } -@defun "io_square" { #args: x y (equivalent to x y 3 2 io_box) +@defun "io_square" { #args: x y "y" store "x" store x y io_goto - "+--+" print - x y 1 + io_goto - "| |" print - x y 2 + io_goto - "+--+" print + #"+--+" print + #x y 1 + io_goto + #"| |" print + #x y 2 + io_goto + #"+--+" print + "xxx\x1B[3D\x1B[Bxxx" print } @defun "io_pos_square" { #args: x y @@ -104,11 +108,18 @@ tile_sizey * padding_y + } -@defun "io_gsquare" { #args: x y +@defun "io_gsquare" { #args: x y blockidx + "b_blockclrs" swapoutvar swap arridx swap "b_blockclrs" gstore + io_setcolour io_pos_square io_square + io_resetcolour } @defun "io_setcolour" { #args: coloridx [0..7] "\x1B[3" swap + "m" + print } + +@defun "io_resetcolour" { + "\x1B[0m" print +} diff --git a/tetris/tetris.prn b/tetris/tetris.prn index ef56158..3f021b9 100644 --- a/tetris/tetris.prn +++ b/tetris/tetris.prn @@ -2,13 +2,12 @@ @includeonce "utility.prn" @includeonce "blocks.prn" -1 "i" store -i 8 < while +0 "i" store +i b_nblocks < while io_clearscreen io_windowbox - stackdump 0 0 i b_drawblock 1000000 sleep i 1 + "i" store -i 8 < end +i b_nblocks < end io_pos_after io_goto -- cgit v1.2.3-70-g09d2