Advertisement
RaZgRiZ

CS Tetris WIP2

Sep 6th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. tetris = [showgui tetris]
  2. append = [$arg1 = (concat (getalias $arg1) $arg2)]
  3. rndo = [at $arg1 (rnd (listlen $arg1))]
  4.  
  5. _tetris_clearrows = [loop i 20 [[_tetris_row@i] = ""]]
  6.  
  7. _tetris_genrows = [
  8.     _tetris_clearrows
  9.     looplist i $_tetris_static [
  10.         cond (< $i 10) [
  11.             append _tetris_row0 $i
  12.         ] (< $i 100) [
  13.             append _tetris_row@(substr $i 0 1) (substr $i 1 1)
  14.         ] (< $i 200) [
  15.             append _tetris_row@(substr $i 0 2) (substr $i 2 1)
  16.         ]
  17.     ]
  18. ]
  19.  
  20. _tetris_spawnblock = [
  21.     _tetris_curblock = $_tetris_nextblock
  22.     _tetris_active = $[_tetris_@_tetris_curblock]
  23.     _tetris_nextblock = (rndo "i j l o s t z")
  24. ]
  25.  
  26. _tetris_moveblock = [
  27.     if (listlen $_tetris_active) [
  28.         local newpos valid tmp
  29.         valid = 1
  30.         looplist p $_tetris_active [
  31.             tmp = (+ $p $arg2)
  32.             if (|| arg1 [> (indexof $_tetris_static $tmp) -1]) [valid = 0] [append newpos $tmp]
  33.         ]
  34.         if $valid [_tetris_active = $newpos] arg3
  35.     ]
  36. ]
  37.  
  38. _tetris_i = "-4 -5 -6 -7"
  39. _tetris_j = "-14 -15 -16 -6"
  40. _tetris_l = "-13 -14 -15 -3"
  41. _tetris_o = "-15 -16 -5 -6"
  42. _tetris_s = "-15 -16 -4 -5"
  43. _tetris_t = "-15 -16 -17 -6"
  44. _tetris_z = "-15 -16 -6 -7"
  45.  
  46. _tetris_static = "" // settled blocks
  47. _tetris_active = "" // moving block
  48. _tetris_colors = "" // colors of settled blocks
  49.  
  50. _tetris_cleared   = 0
  51. _tetris_score     = 0
  52. _tetris_curblock = (rndo "i j l o s t z")
  53. _tetris_nextblock = $_tetris_curblock
  54.  
  55. _tetris_clearrows
  56.  
  57. newgui tetris [
  58.     guistayopen [
  59.         guilist [
  60.             guilist [
  61.                 loop i 20 [
  62.                     guilist [
  63.                         loop p 10 [
  64.                             tmp = (concatword $i $p)
  65.                             guitext "" (concatword "tetris/" (
  66.                                 ? (> (listfind z $_tetris_active [= $z $tmp]) -1) $_tetris_curblock (
  67.                                     ? (> (indexof $_tetris_row@i $p) -1) (
  68.                                         at $_tetris_colors (listfind z $_tetris_colors [= (at $z 0) $tmp]) 1
  69.                                     ) "_"
  70.                                 )
  71.                             ) ".png")
  72.                         ]
  73.                     ]
  74.                 ]
  75.             ]
  76.             guibar
  77.             guilist [
  78.                 guibutton "Spawn Block" _tetris_spawnblock
  79.                 guibutton "Move Down" [
  80.                     _tetris_moveblock [> $tmp 199] 10 [
  81.                         append _tetris_static $_tetris_active // move block coords to static
  82.                         looplist i $_tetris_active [
  83.                             append _tetris_colors [[@@(concat $i $_tetris_curblock)]]
  84.                         ]
  85.                         _tetris_active = ""              // clear active block
  86.                         _tetris_genrows                  // generate row hits
  87.                         loop i 20 [
  88.                             if (= (listlen $[_tetris_row@i]) 10) [
  89.                                 _tetris_cleared = (+ $_tetris_cleared 1) // compute rows cleared
  90.                                 _tetris_row@i = ""                       // clear full row
  91.                             ]
  92.                         ]
  93.                         // continue with moving STATIC above a cleared row, below. work on scoring tech.
  94.                     ]
  95.                 ]
  96.                 guibutton "Move Left" [
  97.                     _tetris_moveblock [< (div $tmp 10) (div $p 10)] -1
  98.                 ]
  99.                 guibutton "Move Right" [
  100.                     _tetris_moveblock [> (div $tmp 10) (div $p 10)] 1
  101.                 ]
  102.                
  103.                
  104.             ]
  105.         ]
  106.     ]
  107. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement