Advertisement
RaZgRiZ

Tetris WIP v.2

Jan 6th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.84 KB | None | 0 0
  1. _tetris_spawnblock = [
  2.     _tetris_curblock = $_tetris_nextblock
  3.     _tetris_rotation = 1
  4.     _tetris_calcpos 1
  5.     _tetris_nextblock = (rnd 8 1)
  6. ]
  7.  
  8. // _tetris_moveblock [ condition ] <offset> [ do-if-invalid ]
  9. _tetris_moveblock = [
  10.     local invalid
  11.     _tetris_calcpos 0 $arg2
  12.     looplist p $_tetris_active [
  13.         if (|| arg1 [at $_tetris_static $p]) [ invalid = 1 ]
  14.     ]
  15.     if $invalid [
  16.         _tetris_calcpos 0 (- 0 $arg2)
  17.         arg3
  18.     ]
  19. ]
  20.  
  21.  
  22. _tetris_testmove = [
  23.     looplist p $_tetris_active [
  24.         if (|| arg1 [at $_tetris_static $p]) [ invalid = 1 ]
  25.     ]
  26. ]
  27.  
  28. // _tetris_calcpos <NEW BLOCK 0|1> <OFFSET> [ condition ] [ do-if-invalid ]
  29. _tetris_calcpos = [
  30.     local newpos b w n z row
  31.     b = $[_tetris_@[_tetris_curblock]]
  32.     n = (pow 2 (abs $_tetris_rotation))
  33.     z = 3
  34.     if $arg1 [ _tetris_offset = (div (- 10 (listlen $b)) 2) ]
  35.     if $arg2 [ _tetris_offset = (+ $_tetris_offset $arg2) ]
  36.     loop y (listlen $b) [
  37.         row = (at $b $y)
  38.         //w = (max $w (listlen (listfilter i $row [> (& $i $n) 0])))
  39.         loop x (listlen $row) [
  40.             if (& (at $row $x) $n) [
  41.                 z = (min $z $x)
  42.                 newpos = (concat $newpos (+ $_tetris_offset $x (* $y 10)))
  43.                 //echo "^f3Tetris^f2:" [Y=@y] [X=@x] "^f7||^f2" (at $row $x) "^f7||^f2" "^f0PASS"
  44.             ]// [ echo "^f3Tetris^f2:" [Y=@y] [X=@x] "^f7||^f2" (at $row $x) "^f7||^f2" "^f3FAIL" ]
  45.         ]
  46.     ]
  47.     //_tetris_width = $w
  48.     _tetris_topleft = $z
  49.     _tetris_active = $newpos
  50. ]
  51.  
  52. // ----------------------------------------- //
  53. // ---------------- CELL ID ---------------- //
  54. // ----------------------------------------- //
  55. // 0 = no cell
  56. // 1 = i tetromino
  57. // 2 = j
  58. // 3 = l
  59. // 4 = o
  60. // 5 = s
  61. // 6 = t
  62. // 7 = z
  63.  
  64. _tetris_1 = [ [  0  8  2  0 ] [  1  9  3  1 ] [  4 12  6  4 ] [  0  8  2  0 ] ]
  65. _tetris_2 = [ [  1 10  2 ] [  5 15  5 ] [  8 10  4 ] ]
  66. _tetris_3 = [ [  8 10  1 ] [  5 15  5 ] [  4 10  2 ] ]
  67. _tetris_4 = [ [ 15 15 ] [ 15 15 ] ]
  68. _tetris_5 = [ [  8  3  1 ] [  9 15  6 ] [  4 12  2 ] ]
  69. _tetris_6 = [ [  0 11  0 ] [ 13 15  7 ] [  0 14  0 ] ]
  70. _tetris_7 = [ [  1  9  2 ] [ 12 15  3 ] [  8  6  4 ] ]
  71.  
  72. _tetris_static = (loopconcat i 200 0) // settled blocks
  73. _tetris_active = "" // moving block
  74.  
  75. _tetris_rotation  = 0 // 0-3 tetromino rotation
  76. _tetris_cleared   = 0 // amount of rows cleared
  77. _tetris_score     = 0 // current score
  78. _tetris_curblock  = (rnd 8 1)
  79. _tetris_nextblock = $_tetris_curblock
  80.  
  81.  
  82. ui_menu "tetris" [
  83.     uihlist 0.01 [
  84.         uicolor 0 0.32 0.64 [
  85.             uihlist 0 [
  86.                 uigrid 10 0 [
  87.                     loop N 200 [
  88.                         posy = (div $N 10)
  89.                         posx = (mod $N 10)
  90.                         draw = (>= (indexof $_tetris_active $N) 0)
  91.                         if (|| $draw [at $_tetris_static $N]) [
  92.                             uiimage [media/texture/tetris/@(
  93.                                 if $draw [ result $_tetris_curblock ] [ at $_tetris_static $N ]
  94.                             ).png] 0.032 0.032
  95.                         ] [ uiimage "media/texture/tetris/0.png" 0.032 0.032 ]
  96.                     ]
  97.                 ]
  98.             ]
  99.             uioutline $_c_line
  100.             uiclamp- 1 1 1 1
  101.         ]
  102.         uivlist 0 [
  103.             uifill 0.2
  104.             uialign 0 -1
  105.             ui_button "hold2" [ uitext "Spawn Block" 0.6 ] 0 0.04 [ _tetris_spawnblock ]
  106.             uispace 0 0.01 [ ui_bar 1 ]
  107.             ui_button "hold2" [ uitext "Move Down" 0.6 ] 0 0.04 [
  108.                 _tetris_moveblock [> $p 199] 10 [
  109.                     looplist i $_tetris_active [                // add active cells to static
  110.                         _tetris_static = (listsplice $_tetris_static $_tetris_curblock $i 1)
  111.                     ]
  112.                     _tetris_spawnblock                            // spawn a new tetromino
  113.                     //_tetris_genrows                             // generate row hits
  114.                     //_tetris_scorerows                           // clear scored rows and move blocks down
  115.                 ]
  116.             ]
  117.             ui_button "hold2" [ uitext "Move Left" 0.6 ] 0 0.04 [
  118.                 _tetris_moveblock [] -1
  119.             ]
  120.             ui_button "hold2" [ uitext "Move Right" 0.6 ] 0 0.04 [
  121.                 _tetris_moveblock [] 1
  122.             ]
  123.             uispace 0 0.01 [ ui_bar 1 ]
  124.             ui_button "hold2" [ uitext "Rotate Left" 0.6 ] 0 0.04 [
  125.                 _tetris_rotation = (mod (- $_tetris_rotation 1) 4)
  126.                 _tetris_calcpos
  127.             ]
  128.             ui_button "hold2" [ uitext "Rotate Right" 0.6 ] 0 0.04 [
  129.                 _tetris_rotation = (mod (+ $_tetris_rotation 1) 4)
  130.                 _tetris_calcpos
  131.             ]
  132.             uiclamp* 1 1
  133.         ]
  134.     ]
  135. ] [ _tetris_spawnblock ]
  136.  
  137. tetris = [ exec scripts/tetris.cfg ; showui "tetris" ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement