;==================================
; Script Name: EasyUO Tetris
; Author: Kal In Ex
; Version: 2.02
; Client Tested with: n/a
; EUO version tested with: 1.5.95
; Shard OSI / FS: OSI
; Revision Date: November 16, 2006
; Public Release: June 11, 2005
; Global Variables Used:
; Purpose: a "challenge" that wasn't :P
; Copyright 2005, 2006 Kal In Ex
;==================================
set #lpc 1000
set !gameXPos 10
set !gameYPos 10
set !gameWidth 10
set !gameHeight 20
set !blockSize 15
set !blockDrop 20 ; 50ms * !blockDrop = block speed
; set window size and window title
menu show
menu clear
menu window title Tetris
set !x ( !gameXPos * 2 ) + ( !gameWidth * !blockSize ) + 75
set !y ( !gameYPos * 2 ) + ( !gameHeight * !blockSize )
menu window size !x !y
; create a new game and display it in the menu
gosub tetris game1 create !gameWidth !gameHeight
if ! #true
{
gosub tetris game1 setscan 1 ..........
gosub tetris game1 setscan 2 ..........
gosub tetris game1 setscan 3 ..........
gosub tetris game1 setscan 4 ..........
gosub tetris game1 setscan 5 ..........
gosub tetris game1 setscan 6 ..........
gosub tetris game1 setscan 7 .........3
gosub tetris game1 setscan 8 .........3
gosub tetris game1 setscan 9 .........3
gosub tetris game1 setscan 10 ..........
gosub tetris game1 setscan 11 ..........
gosub tetris game1 setscan 12 ..........
gosub tetris game1 setscan 13 ...22.....
gosub tetris game1 setscan 14 ...22.....
gosub tetris game1 setscan 15 .5.22.444.
gosub tetris game1 setscan 16 55.222243.
gosub tetris game1 setscan 17 553222203.
gosub tetris game1 setscan 18 553220003.
gosub tetris game1 setscan 19 543221111.
gosub tetris game1 setscan 20 444221111.
;gosub tetris game1 display !gameXPos !gameYPos !blockSize
}
gosub tetris game1 display !gameXPos !gameYPos !blockSize
; place tetris game controls for game
set !x ( !gameXPos * 2 ) + ( !gameWidth * !blockSize )
set !y !gameYPos
gosub tetris game1 placeControls !x !y #true
;halt
; set the current state for the game
gosub tetris game1 nextblock
gosub tetris game1 state !blockDrop
set #menubutton n/a
mainloop:
wait 1
if #menubutton = closed
{
halt
}
gosub tetris game1 automate
goto mainloop
; callables
; <gamename> create [<width> <height>] - creates a new tetris "playing field"
; <gamename> setscan <scanline#> <scandata> - sets the data for a scanline
; <gamename> display <xpos> <ypos> <size> - draws the game view in easyuo menu
; <gamename> delviews - removes the game view(s) drawn by "display"
; <gamename> nextblock [blocknumber] - prepares a new block for dropping
; <gamename> up - moves the current block up
; <gamename> down - moves the current block down (will cement upon collision)
; <gamename> right - moves the current block right
; <gamename> left - moves the current block left
; <gamename> rotate <right|left> - rotates the block to the right or left
; <gamename> placecontrols <xpos> <ypos> - places game controls in menu
; <gamename> deletecontrols - removes game controls from menu
; <gamename> state <speed> - sets the block dropping speed (in number of calls to automate)
; <gamename> automate - "automates" the game
; <gamename> drop - drops a block until it collides
; uncallables
; <gamename> cement - fixes current blocks, removes lines, prepares nextblock
; <gamename> removelines - removes
; <gamename> detectcollision - detects collisions of the current block
sub tetris
namespace push
namespace local tetris_ , %1
if !tetris = n/a
{
set !tetris
set !blockCount 7
set !blockColor0 red
set !blockColor1 green
set !blockColor2 blue
set !blockColor3 yellow
set !blockColor4 aqua
set !blockColor5 purple
set !blockColor6 gray
set !gamescore 0
set !linecount 0
set !dropcount 0
}
for !_ 0 %0
{
set ! . !_ % . !_
}
if !2 = create
{
gosub tetrisCreate !3 !4
}
if !2 = setscan
{
set !gamescan . !3 !4
}
if !2 = display
{
gosub tetrisDisplay !3 !4 !5
}
if !2 = delview
{
gosub tetrisDelView
}
if !2 = nextblock
{
if !0 = 2
{
gosub tetrisNextBlock
}
if !0 > 2
{
gosub tetrisNextBlock !3
}
}
if !2 = up
{
gosub tetrisUp
}
if !2 = left
{
gosub tetrisLeft
}
if !2 = right
{
gosub tetrisRight
}
if !2 = down
{
gosub tetrisDown
}
if !2 = rotate
{
gosub tetrisRotate !3
}
if !2 = placeControls
{
if !0 = 4
{
set !5 #false
}
gosub tetrisPlaceControls !3 !4 !5
}
if !2 = deleteControls
{
gosub tetrisDeleteControls
}
if !2 = menubutton
{
gosub tetrisMenuButton !3
}
if !2 = state
{
gosub tetrisState !3
}
if !2 = automate
{
gosub tetrisAutomate
}
if !2 = drop
{
gosub tetrisDrop
}
namespace pop
return
sub tetrisAutomate
if !gameOver = #false
{
if !blockDropIndex = ( !blockDropSpeed - 1 )
{
gosub tetrisDown
}
set !blockDropIndex ( 1 + !blockDropIndex ) % !blockDropSpeed
}
if tetris_ , !1 , _ in #menubutton
{
set !menubutton #menubutton
set #menubutton n/a
if tetris_ , !1 , _ in !menubutton
{
if !gameOver = #false
{
gosub tetrisMenuButton !menubutton
}
if !gameOver = #true && tetris_ , !1 , _reset = !menubutton
{
gosub tetrisMenuButton !menubutton
}
}
}
return
sub tetrisState
set !blockDropSpeed %1
set !blockDropIndex 1
return
sub tetrisCreate
if %0 = 0
{
set %1 10 ; default width
set %2 20 ; default height
}
set !gamewidth %1
set !gameheight %2
set !_
for !x 1 !gamewidth
{
set !_ !_ , #dot
}
for !y 0 !gameheight
{
set !gamescan . !y !_
}
gosub tetrisDelView
if !gameView = #true
{
gosub tetrisDisplay !gameMenuX !gameMenuY !gameBlockSize
}
set !gameOver #false
return
sub tetrisDisplay
set !gameMenuX %1
set !gameMenuY %2
set !gameBlockSize %3
set !gameBlockDrawSize %3 + 1
menu delete gameview , !1
set !x !gamewidth * !gameBlockSize + 1
set !y !gameheight * !gameBlockSize + 1
menu shape gameview , !1 !gameMenuX !gameMenuY !x !y 3 7 1 black 2 blue
for !y !gameHeight 1
{
for !x 1 !gameWidth
{
str mid !gameScan . !y !x 1
if #strres <> #dot
{
set !xpos !gameMenuX + ( ( !x - 1 ) * !gameBlockSize )
set !ypos !gameMenuY + ( ( !y - 1 ) * !gameBlockSize )
menu shape gameview , !1 !xpos !ypos !gameBlockDrawSize !gameBlockDrawSize 3 7 1 black 7 !blockColor . #strres
}
}
}
set !gameView #true
return
sub tetrisDelView
menu delete gameview , !1
menu delete gameblock , !1
set !gameView #false
return
sub tetrisDrawBlock
if !gameView = #true
{
menu delete gameblock , !1
for !y !blockHeight 1
{
for !x 1 !blockWidth
{
str mid !blockScan . !y !x 1
if #strres <> #dot
{
set !xpos !gameMenuX + ( ( !x + !blockX - 2 ) * !gameblocksize )
set !ypos !gameMenuY + ( ( !y + !blockY - 2 ) * !gameblocksize )
menu shape gameblock , !1 !xpos !ypos !gameblockdrawsize !gameblockdrawsize 3 7 1 black 7 !blockColor . !blockNumber
}
}
}
}
return
sub tetrisNextBlock
set !nextBlock %1
if %0 = 0
{
set !nextBlock #random % !blockCount
}
gosub tetrisBlock !nextBlock
set !blockX ( !gameWidth / 2 ) - ( !blockWidth / 2 )
set !blockY 1
gosub tetrisDrawBlock
gosub tetrisDetectCollision
if #result = #true
{
set !gameOver #true
return #true
}
set !dropcount 1 + !dropcount
menu set tetris_ , !1 , _dropcount cubes: , !dropcount
return #false
sub tetrisRotate
if %1 = right
{
set !blockPosition ( 1 + !blockPosition ) % 4
gosub tetrisBlock !blockNumber !blockPosition
gosub tetrisDetectCollision
if #result = #true
{
set !blockPosition ( 3 + !blockPosition ) % 4
gosub tetrisBlock !blockNumber !blockPosition
return #true
}
gosub tetrisDrawBlock
return #false
}
if %1 = left
{
set !blockPosition ( 3 + !blockPosition ) % 4
gosub tetrisBlock !blockNumber !blockPosition
gosub tetrisDetectCollision
if #result = #true
{
set !blockPosition ( 3 - !blockPosition ) % 4
gosub tetrisBlock !blockNumber !blockPosition
return #true
}
gosub tetrisDrawBlock
return #false
}
return
sub tetrisLeft
set !blockX !blockX - 1
gosub tetrisDetectCollision
if #result = #true
{
set !blockX !blockX + 1
return #true
}
gosub tetrisDrawBlock
return #false
sub tetrisRight
set !blockX !blockX + 1
gosub tetrisDetectCollision
if #result = #true
{
set !blockX !blockX - 1
return #true
}
gosub tetrisDrawBlock
return #false
sub tetrisUp
set !blockY !blockY - 1
gosub tetrisDetectCollision
if #result = #true
{
set !blockY !blockY + 1
return #true
}
gosub tetrisDrawBlock
return #false
sub tetrisDown
set !blockY !blockY + 1
gosub tetrisDetectCollision
if #result = #true
{
set !blockY !blockY - 1
gosub tetrisCement
return #true
}
gosub tetrisDrawBlock
set !blockDropIndex 1
return #false
sub tetrisDrop
for !tetrisDrop 1 1
{
wait 1
gosub tetrisDown
if #result = #false
{
set !tetrisDrop 0
}
}
return
sub tetrisDetectCollision
for !y 1 !blockHeight
{
for !x 1 !blockWidth
{
str mid !blockScan . !y !x 1
if #strres <> #dot
{
set !xpos ( !x + !blockX ) - 1
set !ypos ( !y + !blockY ) - 1
if !xpos < 1 || !xpos > !gameWidth
return #true
if !ypos < 1 || !ypos > !gameHeight
return #true
str mid !gameScan . !ypos !xpos 1
if #strres <> #dot
{
return #true
}
}
}
}
return #false
sub tetrisRemoveLines
set !linesRemoved 0
for !y 1 !gameHeight
{
str pos !gameScan . !y #dot
if #strres = 0
{
set !linesRemoved 1 + !linesRemoved
for !z !y 1
{
set !_ !z - 1
set !gameScan . !z !gameScan . !_
}
}
}
if !linesRemoved > 0
{
set !linecount !lineCount + !linesremoved
if !linesremoved = 1
{
set !gamescore !gamescore + 1
gosub tetrisScoreMsg !linesremoved single
}
if !linesremoved = 2
{
set !gamescore !gamescore + 10
gosub tetrisScoreMsg 10 double
}
if !linesremoved = 3
{
set !gamescore !gamescore + 30
gosub tetrisScoreMsg 30 triple
}
if !linesremoved = 4
{
set !gamescore !gamescore + 100
gosub tetrisScoreMsg 100 quad
}
if !gameView = #true
{
gosub tetrisDisplay !gameMenuX !gameMenuY !gameBlockSize
menu set tetris_ , !1 , _gamescore score: , !gamescore
menu set tetris_ , !1 , _linecount lines: , !linecount
}
}
return
sub tetrisScoreMsg
if !gameView = #true
{
set !x !gameMenuX + 10
set !y !gameMenuY + 10
menu font size !gameBlockSize
menu font name lucida console
menu text scoremsg !x !y %1 %2 , !
wait 20
menu delete scoremsg
}
return
sub tetrisCement
for !y 1 !blockHeight
{
for !x 1 !blockWidth
{
str mid !blockScan . !y !x 1
if #strres <> #dot
{
set !xpos ( !x + !blockX ) - 1
set !ypos ( !y + !blockY ) - 1
str del !gameScan . !ypos !xpos 1
str ins #strres !blockNumber !xpos
set !gameScan . !ypos #strres
if !gameView = #true
{
set !xpos !gameMenuX + ( ( !x + !blockX - 2 ) * !gameblocksize )
set !ypos !gameMenuY + ( ( !y + !blockY - 2 ) * !gameblocksize )
menu shape gameview , !1 !xpos !ypos !gameblockdrawsize !gameblockdrawsize 3 7 1 black 7 !blockColor . !blockNumber
}
}
}
}
gosub tetrisRemoveLines
gosub tetrisNextBlock
return #result
sub tetrisBlock
if %0 = 1
{
set %2 0
}
gosub tetrisBlock , %1 %2
str len !blockScan1
set !blockWidth #strres
set !blockHeight !blockScans
return
sub tetrisBlock0
if %1 = 0
{
set !blockNumber 0
set !blockPosition %1
set !blockScans 2
set !blockScan1 xxx
set !blockScan2 x..
}
if %1 = 1
{
set !blockNumber 0
set !blockPosition %1
set !blockScans 3
set !blockScan1 xx
set !blockScan2 .x
set !blockScan3 .x
}
if %1 = 2
{
set !blockNumber 0
set !blockPosition %1
set !blockScans 2
set !blockScan1 ..x
set !blockScan2 xxx
}
if %1 = 3
{
set !blockNumber 0
set !blockPosition %1
set !blockScans 3
set !blockScan1 x.
set !blockScan2 x.
set !blockScan3 xx
}
return
sub tetrisBlock1
if %1 = 0
{
set !blockNumber 1
set !blockPosition %1
set !blockScans 2
set !blockScan1 xxx
set !blockScan2 ..x
}
if %1 = 1
{
set !blockNumber 1
set !blockPosition %1
set !blockScans 3
set !blockScan1 .x
set !blockScan2 .x
set !blockScan3 xx
}
if %1 = 2
{
set !blockNumber 1
set !blockPosition %1
set !blockScans 2
set !blockScan1 x..
set !blockScan2 xxx
}
if %1 = 3
{
set !blockNumber 1
set !blockPosition %1
set !blockScans 3
set !blockScan1 xx
set !blockScan2 x.
set !blockScan3 x.
}
return
sub tetrisBlock2
if %1 = 0 || %1 = 1 || %1 = 2 || %1 = 3
{
set !blockNumber 2
set !blockPosition %1
set !blockScans 2
set !blockScan1 xx
set !blockScan2 xx
}
return
sub tetrisBlock3
if %1 = 0 || %1 = 2
{
set !blockNumber 3
set !blockPosition %1
set !blockScans 1
set !blockScan1 xxxx
}
if %1 = 1 || %1 = 3
{
set !blockNumber 3
set !blockPosition %1
set !blockScans 4
set !blockScan1 x
set !blockScan2 x
set !blockScan3 x
set !blockScan4 x
}
return
sub tetrisBlock4
if %1 = 0
{
set !blockNumber 4
set !blockPosition %1
set !blockScans 2
set !blockScan1 xxx
set !blockScan2 .x.
}
if %1 = 1
{
set !blockNumber 4
set !blockPosition %1
set !blockScans 3
set !blockScan1 .x
set !blockScan2 xx
set !blockScan3 .x
}
if %1 = 2
{
set !blockNumber 4
set !blockPosition %1
set !blockScans 2
set !blockScan1 .x.
set !blockScan2 xxx
}
if %1 = 3
{
set !blockNumber 4
set !blockPosition %1
set !blockScans 3
set !blockScan1 x.
set !blockScan2 xx
set !blockScan3 x.
}
return
sub tetrisBlock5
if %1 = 0 || %1 = 2
{
set !blockNumber 5
set !blockPosition %1
set !blockScans 2
set !blockScan1 xx.
set !blockScan2 .xx
}
if %1 = 1 || %1 = 3
{
set !blockNumber 5
set !blockPosition %1
set !blockScans 3
set !blockScan1 .x
set !blockScan2 xx
set !blockScan3 x.
}
return
sub tetrisBlock6
if %1 = 0 || %1 = 2
{
set !blockNumber 6
set !blockPosition %1
set !blockScans 2
set !blockScan1 .xx
set !blockScan2 xx.
}
if %1 = 1 || %1 = 3
{
set !blockNumber 6
set !blockPosition %1
set !blockScans 3
set !blockScan1 x.
set !blockScan2 xx
set !blockScan3 .x
}
return
sub tetrisMenuButton
set !menubutton %1
if !menubutton = tetris_ , !1 , _rotate_left
{
gosub tetrisRotate left
}
if !menubutton = tetris_ , !1 , _move_up
{
gosub tetrisUp
}
if !menubutton = tetris_ , !1 , _rotate_right
{
gosub tetrisRotate right
}
if !menubutton = tetris_ , !1 , _move_left
{
gosub tetrisLeft
}
if !menubutton = tetris_ , !1 , _move_down
{
gosub tetrisDown
}
if !menubutton = tetris_ , !1 , _move_right
{
gosub tetrisRight
}
if !menubutton = tetris_ , !1 , _drop_block
{
gosub tetrisDrop
}
if !menubutton = tetris_ , !1 , _reset
{
set !gamescore 0
set !linecount 0
set !dropcount 0
menu set tetris_ , !1 , _gamescore score: , !gamescore
menu set tetris_ , !1 , _linecount lines: , !linecount
menu set tetris_ , !1 , _dropcount cubes: , !dropcount
gosub tetrisCreate !gameWidth !gameHeight
gosub tetrisDisplay !gameMenuX !gameMenuY !gameBlockSize
gosub tetrisNextBlock
}
if !menubutton = tetris_ , !1 , _cheat
{
set !_ !blockNumber
if !_ = 0
{
set !blockNumber 1
}
if !_ = 1
{
set !blockNumber 0
}
if !_ = 5
{
set !blockNumber 6
}
if !_ = 6
{
set !blockNumber 5
}
gosub tetrisBlock !blockNumber !blockPosition
gosub tetrisDrawBlock
}
return
sub tetrisDeleteControls
menu delete text tetris_ , !1 , _gamescore
menu delete text tetris_ , !1 , _linecount
menu delete text tetris_ , !1 , _dropcount
menu delete button tetris_ , !1 , _rotate_left
menu delete button tetris_ , !1 , _move_up
menu delete button tetris_ , !1 , _rotate_right
menu delete button tetris_ , !1 , _move_left
menu delete button tetris_ , !1 , _move_down
menu delete button tetris_ , !1 , _move_right
menu delete button tetris_ , !1 , _drop_block
menu delete button tetris_ , !1 , _reset
menu delete button tetris_ , !1 , _cheat
return
sub tetrisPlaceControls
set !x %1
set !y %2
menu font size 10
menu font name lucida console
menu text tetris_ , !1 , _gamescore !x !y score: , !gamescore
set !x !x + 0
set !y !y + 12
menu text tetris_ , !1 , _linecount !x !y lines: , !linecount
set !x !x + 0
set !y !y + 12
menu text tetris_ , !1 , _dropcount !x !y cubes: , !dropcount
menu font name wingdings
set !x !x + 0
set !y !y + 20
menu button tetris_ , !1 , _rotate_left !x !y 20 20 ã
set !x !x + 20
set !y !y + 0
menu button tetris_ , !1 , _move_up !x !y 20 20 á
set !x !x + 20
set !y !y + 0
menu button tetris_ , !1 , _rotate_right !x !y 20 20 ä
set !x !x - 40
set !y !y + 20
menu button tetris_ , !1 , _move_left !x !y 20 20 ß
set !x !x + 20
set !y !y + 0
menu button tetris_ , !1 , _move_down !x !y 20 20 â
set !x !x + 20
set !y !y + 0
menu button tetris_ , !1 , _move_right !x !y 20 20 à
set !x !x - 20
set !y !y + 20
menu button tetris_ , !1 , _drop_block !x !y 20 20 Þ
set !x !x - 20
set !y !y + 20
menu font name lucida console
menu button tetris_ , !1 , _reset !x !y 60 20 restart
if !5 = #true
{
set !x !x + 0
set !y !y + 20
menu button tetris_ , !1 , _cheat !x !y 60 20 cheat
}
return