Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tetris = [showgui tetris]
- append = [$arg1 = (concat (getalias $arg1) $arg2)]
- rndo = [at $arg1 (rnd (listlen $arg1))]
- _tetris_clearrows = [
- loop i 20 [
- [_tetris_row@i] = ""
- ]
- ]
- _tetris_genrows = [
- _tetris_clearrows
- looplist i $_tetris_static [
- cond (< $i 10) [
- append _tetris_row0 $i
- ] (< $i 100) [
- append _tetris_row@(substr $i 0 1) (substr $i 1 1)
- ] (< $i 200) [
- append _tetris_row@(substr $i 0 2) (substr $i 2 1)
- ]
- ]
- ]
- _tetris_scorerows = [
- local tmp1 tmp2
- loop i 20 [
- if (= (listlen $[_tetris_row@i]) 10) [
- _tetris_cleared = (+ $_tetris_cleared 1) // compute rows cleared
- _tetris_row@i = "" // clear full row
- ]
- ]
- looplist z $_tetris_static [
- //if (! (>< $z
- ]
- ]
- _tetris_spawnblock = [
- _tetris_curblock = $_tetris_nextblock
- _tetris_active = (at $[_tetris_@_tetris_curblock] 0)
- _tetris_rotation = $_tetris_active
- _tetris_nextblock = (? (rnd 100) (rndo "i j l o s t z") "b")
- ]
- _tetris_moveblock = [
- if (listlen $arg3) [
- local newpos valid tmp
- valid = 1
- looplist p $arg3 [
- tmp = (+ $p $arg2)
- if (|| arg1 [> (indexof $_tetris_static $tmp) -1]) [valid = 0] [append newpos $tmp]
- ]
- if $valid [_tetris_active = $newpos] arg4
- ]
- ]
- _tetris_i = ["-6 -7 -5 -4" "-5 -15 5 15" "5 7 6 4" "4 -16 -6 14"]
- _tetris_j = ["-16 -27 -17 -15" "-16 -26 -25 -6" "-16 -17 -15 -5" "-16 -26 -7 -6"]
- _tetris_l = ["-16 -17 -15 -7" "-16 -27 -26 -6" "-16 -25 -17 -15" "-16 -26 -6 -5"]
- _tetris_o = ["-15 -16 -5 -6"]
- _tetris_s = ["-16 -15 -7 -6" "-16 -26 -15 -5"]
- _tetris_t = ["-16 -26 -17 -15" " -16 -26 -15 -6" "-16 -17 -15 -6" "-16 -26 -17 -6"]
- _tetris_z = ["-16 -17 -6 -5" "-16 -26 -17 -7"]
- _tetris_b = ["-1 -2 -3 -4 -5 -6 -7 -8 -9 -10"]
- _tetris_static = "" // settled blocks
- _tetris_active = "" // moving block
- _tetris_colors = "" // colors of settled blocks
- _tetris_rotation = ""
- _tetris_cleared = 0
- _tetris_score = 0
- _tetris_curblock = (rndo "i j l o s t z")
- _tetris_nextblock = $_tetris_curblock
- _tetris_clearrows
- newgui tetris [
- guistayopen [
- guilist [
- guilist [
- loop i 20 [
- guilist [
- loop p 10 [
- tmp = (concatword $i $p)
- guitext "" (concatword "tetris/" (
- ? (> (listfind z $_tetris_active [= $z $tmp]) -1) $_tetris_curblock (
- ? (> (indexof $_tetris_row@i $p) -1) (substr (
- at $_tetris_colors (listfind z $_tetris_colors [= (substr $z 1) $tmp])
- ) 0 1) "_"
- )
- ) ".png")
- ]
- ]
- ]
- ]
- guibar
- guilist [
- guibutton "Spawn Block" _tetris_spawnblock
- guibutton "Move Down" [
- _tetris_moveblock [> $tmp 199] 10 $_tetris_active [
- append _tetris_static $_tetris_active // move block coords to static
- looplist i $_tetris_active [
- append _tetris_colors (concatword $_tetris_curblock $i)
- ]
- _tetris_active = "" // clear active block
- _tetris_genrows // generate row hits
- _tetris_scorerows // clear scored rows and move blocks down
- ]
- ]
- guibutton "Move Left" [
- _tetris_moveblock [< (div $tmp 10) (div $p 10)] -1 $_tetris_active
- ]
- guibutton "Move Right" [
- _tetris_moveblock [> (div $tmp 10) (div $p 10)] 1 $_tetris_active
- ]
- guibutton "Rotate Right" [
- cur = $_tetris_@_tetris_curblock
- _tetris_rotation = (at $cur (mod (+ (indexof $cur $_tetris_rotation) 1) (listlen $cur)))
- _tetris_moveblock [] (- (at $_tetris_active 0) (at $cur $_tetris_rotation 0)) $_tetris_rotation
- ]
- //
- ]
- ]
- ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement