Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _tetris_spawnblock = [
- _tetris_curblock = $_tetris_nextblock
- _tetris_rotation = 1
- _tetris_calcpos 1
- _tetris_nextblock = (rnd 8 1)
- ]
- // _tetris_moveblock [ condition ] <offset> [ do-if-invalid ]
- _tetris_moveblock = [
- local invalid
- _tetris_calcpos 0 $arg2
- looplist p $_tetris_active [
- if (|| arg1 [at $_tetris_static $p]) [ invalid = 1 ]
- ]
- if $invalid [
- _tetris_calcpos 0 (- 0 $arg2)
- arg3
- ]
- ]
- _tetris_testmove = [
- looplist p $_tetris_active [
- if (|| arg1 [at $_tetris_static $p]) [ invalid = 1 ]
- ]
- ]
- // _tetris_calcpos <NEW BLOCK 0|1> <OFFSET> [ condition ] [ do-if-invalid ]
- _tetris_calcpos = [
- local newpos b w n z row
- b = $[_tetris_@[_tetris_curblock]]
- n = (pow 2 (abs $_tetris_rotation))
- z = 3
- if $arg1 [ _tetris_offset = (div (- 10 (listlen $b)) 2) ]
- if $arg2 [ _tetris_offset = (+ $_tetris_offset $arg2) ]
- loop y (listlen $b) [
- row = (at $b $y)
- //w = (max $w (listlen (listfilter i $row [> (& $i $n) 0])))
- loop x (listlen $row) [
- if (& (at $row $x) $n) [
- z = (min $z $x)
- newpos = (concat $newpos (+ $_tetris_offset $x (* $y 10)))
- //echo "^f3Tetris^f2:" [Y=@y] [X=@x] "^f7||^f2" (at $row $x) "^f7||^f2" "^f0PASS"
- ]// [ echo "^f3Tetris^f2:" [Y=@y] [X=@x] "^f7||^f2" (at $row $x) "^f7||^f2" "^f3FAIL" ]
- ]
- ]
- //_tetris_width = $w
- _tetris_topleft = $z
- _tetris_active = $newpos
- ]
- // ----------------------------------------- //
- // ---------------- CELL ID ---------------- //
- // ----------------------------------------- //
- // 0 = no cell
- // 1 = i tetromino
- // 2 = j
- // 3 = l
- // 4 = o
- // 5 = s
- // 6 = t
- // 7 = z
- _tetris_1 = [ [ 0 8 2 0 ] [ 1 9 3 1 ] [ 4 12 6 4 ] [ 0 8 2 0 ] ]
- _tetris_2 = [ [ 1 10 2 ] [ 5 15 5 ] [ 8 10 4 ] ]
- _tetris_3 = [ [ 8 10 1 ] [ 5 15 5 ] [ 4 10 2 ] ]
- _tetris_4 = [ [ 15 15 ] [ 15 15 ] ]
- _tetris_5 = [ [ 8 3 1 ] [ 9 15 6 ] [ 4 12 2 ] ]
- _tetris_6 = [ [ 0 11 0 ] [ 13 15 7 ] [ 0 14 0 ] ]
- _tetris_7 = [ [ 1 9 2 ] [ 12 15 3 ] [ 8 6 4 ] ]
- _tetris_static = (loopconcat i 200 0) // settled blocks
- _tetris_active = "" // moving block
- _tetris_rotation = 0 // 0-3 tetromino rotation
- _tetris_cleared = 0 // amount of rows cleared
- _tetris_score = 0 // current score
- _tetris_curblock = (rnd 8 1)
- _tetris_nextblock = $_tetris_curblock
- ui_menu "tetris" [
- uihlist 0.01 [
- uicolor 0 0.32 0.64 [
- uihlist 0 [
- uigrid 10 0 [
- loop N 200 [
- posy = (div $N 10)
- posx = (mod $N 10)
- draw = (>= (indexof $_tetris_active $N) 0)
- if (|| $draw [at $_tetris_static $N]) [
- uiimage [media/texture/tetris/@(
- if $draw [ result $_tetris_curblock ] [ at $_tetris_static $N ]
- ).png] 0.032 0.032
- ] [ uiimage "media/texture/tetris/0.png" 0.032 0.032 ]
- ]
- ]
- ]
- uioutline $_c_line
- uiclamp- 1 1 1 1
- ]
- uivlist 0 [
- uifill 0.2
- uialign 0 -1
- ui_button "hold2" [ uitext "Spawn Block" 0.6 ] 0 0.04 [ _tetris_spawnblock ]
- uispace 0 0.01 [ ui_bar 1 ]
- ui_button "hold2" [ uitext "Move Down" 0.6 ] 0 0.04 [
- _tetris_moveblock [> $p 199] 10 [
- looplist i $_tetris_active [ // add active cells to static
- _tetris_static = (listsplice $_tetris_static $_tetris_curblock $i 1)
- ]
- _tetris_spawnblock // spawn a new tetromino
- //_tetris_genrows // generate row hits
- //_tetris_scorerows // clear scored rows and move blocks down
- ]
- ]
- ui_button "hold2" [ uitext "Move Left" 0.6 ] 0 0.04 [
- _tetris_moveblock [] -1
- ]
- ui_button "hold2" [ uitext "Move Right" 0.6 ] 0 0.04 [
- _tetris_moveblock [] 1
- ]
- uispace 0 0.01 [ ui_bar 1 ]
- ui_button "hold2" [ uitext "Rotate Left" 0.6 ] 0 0.04 [
- _tetris_rotation = (mod (- $_tetris_rotation 1) 4)
- _tetris_calcpos
- ]
- ui_button "hold2" [ uitext "Rotate Right" 0.6 ] 0 0.04 [
- _tetris_rotation = (mod (+ $_tetris_rotation 1) 4)
- _tetris_calcpos
- ]
- uiclamp* 1 1
- ]
- ]
- ] [ _tetris_spawnblock ]
- tetris = [ exec scripts/tetris.cfg ; showui "tetris" ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement