From 0ad45225f7ecb1a8a5ee6751e8f682d5966c2fd8 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 23 Dec 2016 21:42:49 +0100 Subject: Some changes that were lying around --- tetris/engine.prn | 79 ++++++++++++++++++++++++++++++++++++++++++++++++------- tetris/io.prn | 6 ++--- tetris/tetris.prn | 5 ++-- 3 files changed, 76 insertions(+), 14 deletions(-) (limited to 'tetris') diff --git a/tetris/engine.prn b/tetris/engine.prn index bd00433..390e1d2 100644 --- a/tetris/engine.prn +++ b/tetris/engine.prn @@ -14,6 +14,12 @@ mkarray "e_blockqueue" store #(rot<<3) + idx e_pushnewblock e_newcblock #initialises cblock vars + + sys_rawmode +} + +@defun "e_teardown" { + sys_unrawmode } @defun "e_test" { @@ -94,13 +100,6 @@ mkarray "e_blockqueue" store #(rot<<3) + idx ntiles_x 3 + 1 e_peekblock dup 8 % swap 8 / b_drawblock - - e_cblockpos dup ntiles_x % swap ntiles_x / - e_cblock dup 8 % swap 8 / - dup4 - b_drawblock - sleep_time sleep - b_undrawblock } @defun "e_validcbp" { #args: cblock cblockpos (compares purely to e_boardfilled) @@ -162,9 +161,64 @@ mkarray "e_blockqueue" store #(rot<<3) + idx "e_boardfilled" gstore } -@defun "e_runloop" { +@defun "e_getuserinput" { + getc + dup "h" = if + e_cblockpos 1 - "newcbp" store + e_cblockpos ntiles_x % 0 > e_cblock newcbp e_validcbp & if + newcbp "e_cblockpos" gstore + end + end + dup "l" = if + e_cblockpos 1 + "newcbp" store + e_cblockpos ntiles_x % ntiles_x 1 - < e_cblock newcbp e_validcbp & if + newcbp "e_cblockpos" gstore + end + end + dup "j" = if + e_cblock 8 % e_cblock 8 / 3 + 4 % 8 * + "newcb" store + newcb e_cblockpos e_validcbp if + newcb "e_cblock" gstore + end + end + dup "j" = if + e_cblock 8 % e_cblock 8 / 1 + 4 % 8 * + "newcb" store + newcb e_cblockpos e_validcbp if + newcb "e_cblock" gstore + end + end + pop +} + +@defun "e_sleep_userinput" { + sleep_time "timeout" store 1 while + 0 1 mkarrayp mkarray mkarray timeout sys_select + "timeout" store + pop pop + arrlen if + e_getuserinput + stackdump + end + pop + timeout end +} + +@defun "e_runloop" { + 0 "exitrunloop" store + exitrunloop ! while e_fullrender + + e_cblockpos dup ntiles_x % swap ntiles_x / + e_cblock dup 8 % swap 8 / + dup4 + b_drawblock + io_pos_after io_goto + #sleep_time sleep + e_sleep_userinput + b_undrawblock + + e_cblockpos ntiles_x + #new cblockpos dup e_cblock swap e_validcbp if "e_cblockpos" gstore @@ -172,6 +226,13 @@ mkarray "e_blockqueue" store #(rot<<3) + idx pop e_cblock e_cblockpos e_applyblock e_newcblock + e_cblock e_cblockpos e_validcbp ! if + 1 "exitrunloop" store + e_blockqueue e_cblock arrpushf "e_blockqueue" gstore + e_fullrender + io_pos_after io_goto + "GAME OVER!\n" print + end end - 1 end + exitrunloop ! end } diff --git a/tetris/io.prn b/tetris/io.prn index d749150..24fb4bb 100644 --- a/tetris/io.prn +++ b/tetris/io.prn @@ -5,13 +5,13 @@ } @defun "io_pos_windowend" { #puts: x y - ntiles_x tile_sizex * padding_x 2 * + origin_x + - ntiles_y tile_sizey * padding_y 2 * + origin_y + + ntiles_x padding_x 2 * + tile_sizex * origin_x + + ntiles_y padding_y 2 * + tile_sizey * origin_y + } @defun "io_pos_after" { #puts: x y 0 - ntiles_y tile_sizey * padding_y 2 * + 1 + + ntiles_y padding_y 2 * + tile_sizey * origin_y + } @defun "io_clearscreen" { diff --git a/tetris/tetris.prn b/tetris/tetris.prn index c11ec57..c324a10 100644 --- a/tetris/tetris.prn +++ b/tetris/tetris.prn @@ -7,7 +7,7 @@ #PARAMETERS 0 "origin_x" store 5 "origin_y" store -3 "padding_x" store +2 "padding_x" store 2 "padding_y" store 11 "ntiles_x" store 13 "ntiles_y" store @@ -21,4 +21,5 @@ e_init #e_test e_runloop -io_pos_after io_goto +e_teardown +#io_pos_after io_goto -- cgit v1.2.3-70-g09d2