Hi, here is a tetris game with source.
Im mainly looking for feedback on the control (mobiles and pc). how is the game play ?
No media used, so just copy/paste and play.
* 5 modes.
* In arcade mode, speed increase.
* Highscore on all modes.
* Display next block.
rem
rem AGK Application 3Tris: Preben Eriksen, gameplay test.
rem
global score = 0
SetVirtualResolution ( 320 , 480 )
SetOrientationAllowed ( 1, 1, 0, 0 )
SetSyncRate( 30, 0 )
SetPhysicsGravity ( 0, 100 )
SetClearColor( 24 , 47 , 80 )
dim highscore[5,2] as string
if GetFileExists( "3trishighscore.txt" ) = 1
OpenToRead ( 1, "3trishighscore.txt" )
for fl = 1 to 5
highscore[fl,1] = ReadString ( 1 )
highscore[fl,2] = ReadString ( 1 )
next fl
CloseFile ( 1 )
else
for fl = 1 to 5
highscore[fl,1] = "0"
highscore[fl,2] = "na"
next fl
endif
// split screen into a grid.
global gridx = 10
global gridy = 24
global yhidden = 4
global gridxstart = -4
global gridystart = 20
global gridxsize = 22
global gridysize = 20
global speed# = 0.05
global dropspeed# = 0.60
global newblock = 1
global moving = 1
global nextblock = 1
global gamemode = 1
dim ttis[ gridx , gridy ] as integer
dim tsprite[ gridx , gridy ]
dim tnext[ 3 , 3 ] as integer
dim tnsprite[ 3 , 3 ]
// setup sprites.
for y = yhidden to gridy
for x = 1 to gridx
tsprite[ x , y ] = createSprite ( 0 )
setSpriteSize ( tsprite[ x , y ] , gridxsize-1 , gridysize-1 )
SetSpriteColor ( tsprite[ x , y ] , 0 , 0 , 0 , 255 )
SetSpritePosition( tsprite[ x , y ] , gridxstart + ( gridxsize * x ) , gridystart + ( gridysize * (y-yhidden) ) )
next x
next y
// setup next block sprites.
for y = 1 to 3
for x = 1 to 3
tnsprite[ x , y ] = createSprite ( 0 )
setSpriteSize ( tnsprite[ x , y ] , gridxsize-1 , gridysize-1 )
SetSpriteColor ( tnsprite[ x , y ] , 0 , 0 , 0 , 255 )
SetSpritePosition( tnsprite[ x , y ] , gridxstart + ( gridxsize * gridx ) + 4 , gridystart )
next x
next y
CreateText ( 1, "SCORE" )
SetTextSize ( 1, 18 )
SetTextPosition ( 1, 250, 155 )
SetTextColor ( 1, 0, 0, 0, 255 )
CreateText ( 2, "" )
SetTextSize ( 2, 18 )
SetTextPosition ( 2, 250, 175 )
SetTextColor ( 2, 250, 250, 250, 255 )
//rem
drawblocks()
ending()
rem A Wizard Did It!
lastFrame# = Timer ( )
ClastFrame# = Timer ( )
// main loop
do
thisFrame# = Timer ( )
difference# = thisFrame# - lastFrame#
if difference# > dropspeed#
lastFrame# = thisFrame#
blockhit()
if newblock = 0
moveblocks()
endif
if newblock = 1
// create new block
createblock()
blockhit()
// hit just after create end game. ending
if newblock = 1
moveblocks()
drawblocks()
ending()
// goto main menu
endif
endif
drawblocks()
endif
if newblock = 0 // and Cdifference# > speed#
CthisFrame# = Timer ( )
// keyboard input with delayed repeat
if GetRawKeyPressed(38) or GetVirtualButtonReleased( 10 ) = 1 // Up
ClastFrame# = CthisFrame#
rotateblock()
drawblocks()
endif
if GetRawKeyPressed(40) or GetVirtualButtonReleased( 11 ) = 1 // Down
ClastFrame# = CthisFrame#
while newblock = 0
moveblocks()
blockhit()
drawblocks()
Sync()
endwhile
endif
if GetRawKeyPressed(37) // Left
ClastFrame# = CthisFrame#
moveleft()
drawblocks()
endif
if GetRawKeyPressed(39) // Right
ClastFrame# = CthisFrame#
moveright()
drawblocks()
endif
if GetPointerPressed() = 1
ClastFrame# = CthisFrame#
x# = GetPointerX ( )
if x# < 130
moveleft()
elseif x# > 200
moveright()
drawblocks()
else
rotateblock()
drawblocks()
endif
endif
Cdifference# = CthisFrame# - ClastFrame#
// emulate delayed key repeat with a max speed
if GetRawKeyState(38) and Cdifference# > .5 // Up
ClastFrame# = CthisFrame# - .40
rotateblock()
drawblocks()
endif
if GetRawKeyState(37) and Cdifference# > .5 // Left
ClastFrame# = CthisFrame# - .40
moveleft()
drawblocks()
endif
if GetRawKeyState(39) and Cdifference# > .5 // Right
ClastFrame# = CthisFrame# - .40
moveright()
drawblocks()
endif
// pointer input
if ( GetPointerState ( ) = 1 and Cdifference# > .5 )
ClastFrame# = CthisFrame# - .40
x# = GetPointerX ( )
if x# < 130
moveleft()
drawblocks()
elseif x# > 200
moveright()
drawblocks()
else
rotateblock()
drawblocks()
endif
endif
endif
SetTextString ( 2, Str( score ) )
Sync()
loop
//####
function rotateblock()
for y = 2 to gridy-2
for x = 2 to gridx-1
if ttis[ x , y ] < 20
if ( ttis[ x , y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y+2 ] > 0 and ttis[ x+1 , y+2 ] > 0 ) and (ttis[ x , y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y+2 ] < 20 and ttis[ x+1 , y+2 ] < 20)
// L
if ttis[ x+1 , y+1 ] = 0 and ttis[ x-1 , y+1 ] = 0 and ttis[ x+1 , y ] = 0
ttis[ x-1 , y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x+1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0; ttis[ x+1 , y ] = ttis[ x+1 , y+2 ]; ttis[ x+1 , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x-1 , y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x+1 , y ] > 0 ) AND ( ttis[ x-1 , y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x+1 , y ] < 20 )
// 001
// 111
if ttis[ x-1 , y ] = 0 and ttis[ x , y+2 ] = 0 and ttis[ x , y ] = 0
ttis[ x , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0; ttis[ x , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0; ttis[ x-1 , y ] = ttis[ x+1 , y ]; ttis[ x+1 , y ] = 0;
return
endif
endif
//
if ( ttis[ x-1 , y ] > 0 and ttis[ x , y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y +2 ] > 0 ) AND ( ttis[ x-1 , y ] < 20 and ttis[ x , y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y +2 ] < 20 )
// 110
// 010
// 010
if ttis[ x-1 , y+2 ] = 0 and ttis[ x-1 , y+1 ] = 0 and ttis[ x+1 , y+1 ] = 0
ttis[ x+1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0; ttis[ x-1 , y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x-1 , y+2 ] = ttis[ x-1 , y ]; ttis[ x-1 , y ] = 0;
return
endif
endif
//
if ( ttis[ x-1 , y+1 ] > 0 and ttis[ x-1 , y+2 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y +1 ] > 0 ) AND ( ttis[ x-1 , y+1 ] < 20 and ttis[ x-1 , y+2 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y +1 ] < 20 )
// 111
// 100
if ttis[ x , y ] = 0 and ttis[ x , y+2 ] = 0 and ttis[ x+1 , y+2 ] = 0;
ttis[ x , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0; ttis[ x+1 , y+2 ] = ttis[ x-1 , y+2 ]; ttis[ x-1 , y+2 ] = 0; ttis[ x , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x , y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y+2 ] > 0 and ttis[ x-1 , y +1 ] > 0 ) AND ( ttis[ x , y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y+2 ] < 20 and ttis[ x-1 , y +1 ] < 20 )
// -|
if ttis[ x+1 , y+1 ] = 0
ttis[ x +1, y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x , y +2 ] > 0 ) AND ( ttis[ x-1, y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x , y +2 ] < 20 )
// 000
// 111
// 010
if ttis[ x , y ] = 0
ttis[ x , y ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y+2 ] > 0 and ttis[ x+1 , y + 1 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y+2 ] < 20 and ttis[ x+1 , y + 1 ] < 20 )
// |-
if ttis[ x-1 , y+1 ] = 0
ttis[ x-1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x , y ] > 0 ) AND ( ttis[ x-1, y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x , y ] < 20 )
// _|_
if ttis[ x , y+2 ] = 0
ttis[ x , y+2 ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x+1 , y ] > 0 and ttis[ x-1 , y+1 ] > 0 and ttis[ x, y+1 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x+1 , y ] < 20 and ttis[ x-1 , y+1 ] < 20 and ttis[ x, y+1 ] < 20 )
// 011
// 110
if ttis[ x + 1 , y+1 ] = 0 and ttis[ x+1 , y+2 ] = 0
ttis[ x+1 , y+1 ] = ttis[ x+1 , y ]; ttis[ x+1 , y ] = 0; ttis[ x+1 , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x+1, y+2 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x+1, y+2 ] < 20 )
// 011
// 110
if ttis[ x + 1 , y ] = 0 and ttis[ x-1 , y+1 ] = 0
ttis[ x+1 , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0; ttis[ x-1 , y+1 ] = ttis[ x+1 , y+2 ]; ttis[ x+1 , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y ] > 0 and ttis[ x , y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1, y+1 ] > 0 ) AND ( ttis[ x-1, y ] < 20 and ttis[ x , y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1, y+1 ] < 20 )
// 110
// 011
if ttis[ x + 1 , y ] = 0 and ttis[ x , y+2 ] = 0
ttis[ x+1 , y ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x , y+2 ] = ttis[ x-1 , y ]; ttis[ x-1 , y ] = 0;
return
endif
endif
//
if ( ttis[ x+1, y ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x, y+2 ] > 0 ) AND ( ttis[ x+1, y ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x, y+2 ] < 20 )
// 001
// 011
// 010
if ttis[ x - 1 , y ] = 0 and ttis[ x , y ] = 0
ttis[ x-1 , y ] = ttis[ x+1 , y ]; ttis[ x+1 , y ] = 0; ttis[ x , y ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y+2 ] > 0 and ttis[ x-1, y+2 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y+2 ] < 20 and ttis[ x-1, y+2 ] < 20 )
// 010
// 010
// 110
if ttis[ x - 1 , y+1 ] = 0 and ttis[ x+1 , y+1 ] = 0 and ttis[ x+1 , y+2 ] = 0
ttis[ x-1 , y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x+1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0; ttis[ x+1 , y+2 ] = ttis[ x-1 , y+2 ]; ttis[ x-1 , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 and ttis[ x+1, y+2 ] > 0 ) AND ( ttis[ x-1, y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 and ttis[ x+1, y+2 ] < 20 )
// 000
// 111
// 001
if ttis[ x , y+2 ] = 0 and ttis[ x , y ] = 0 and ttis[ x+1 , y ] = 0
ttis[ x , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0; ttis[ x+1 , y ] = ttis[ x+1 , y+2 ]; ttis[ x+1 , y+2 ] = 0; ttis[ x , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x+1 , y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x, y+2 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x+1 , y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x, y+2 ] < 20 )
// 011
// 010
// 010
if ttis[ x-1 , y ] = 0 and ttis[ x-1 , y+1 ] = 0 and ttis[ x+1 , y+1 ] = 0
ttis[ x-1 , y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x-1 , y ] = ttis[ x+1 , y ]; ttis[ x+1 , y ] = 0; ttis[ x+1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y ] > 0 and ttis[ x-1 , y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1, y+1 ] > 0 ) AND ( ttis[ x-1, y ] < 20 and ttis[ x-1 , y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1, y+1 ] < 20 )
// |__
if ttis[ x , y ] = 0 and ttis[ x-1 , y+2 ] = 0 and ttis[ x , y+2 ] = 0
ttis[ x , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0; ttis[ x-1 , y+2 ] = ttis[ x-1 , y ]; ttis[ x-1 , y ] = 0; ttis[ x , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x-1, y+1 ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x+1 , y+1 ] > 0 ) AND ( ttis[ x-1, y+1 ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x+1 , y+1 ] < 20 )
// -
if ttis[ x , y ] = 0 and ttis[ x , y+2 ] = 0
ttis[ x , y+2 ] = ttis[ x-1 , y+1 ]; ttis[ x-1 , y+1 ] = 0; ttis[ x , y ] = ttis[ x+1 , y+1 ]; ttis[ x+1 , y+1 ] = 0;
return
endif
endif
//
if ( ttis[ x, y ] > 0 and ttis[ x , y+1 ] > 0 and ttis[ x , y+2 ] > 0 ) AND ( ttis[ x, y ] < 20 and ttis[ x , y+1 ] < 20 and ttis[ x , y+2 ] < 20 )
// |
if ttis[ x -1 , y+1 ] = 0 and ttis[ x+1 , y+1 ] = 0
ttis[ x-1 , y+1 ] = ttis[ x , y ]; ttis[ x , y ] = 0; ttis[ x+1 , y+1 ] = ttis[ x , y+2 ]; ttis[ x , y+2 ] = 0;
return
endif
endif
endif
next x
next y
endfunction
//####
function moveleft()
for y = 1 to gridy
for x = 1 to gridx
if ttis[ x , y ] > 0 and ttis[ x , y ] < 20 and ( ttis[ x-1 , y ] > 20 or x = 1 )
// hit
return
endif
next x
next y
for y = 1 to gridy
for x = 2 to gridx
if ttis[ x , y ] > 0 and ttis[ x , y ] < 20 and ttis[ x-1 , y ] = 0
ttis[ x - 1 , y ] = ttis[ x , y ]
ttis[ x , y ] = 0
endif
next x
next y
endfunction
//####
function moveright()
for y = 1 to gridy
if ttis[ gridx , y ] > 0 and ttis[ gridx , y ] < 20
return
endif
for x = gridx to 2 step -1
if (ttis[ x -1 , y ] > 0 and ttis[ x - 1 , y ] < 20) and ( ttis[ x , y ] > 20 )
//hit
return
endif
next x
next y
for y = 1 to gridy
for x = gridx to 2 step -1
if ttis[ x - 1 , y ] > 0 and ttis[ x - 1 , y ] < 20 and ttis[ x , y ] = 0
ttis[ x , y ] = ttis[ x - 1 , y ]
ttis[ x - 1, y ] = 0
endif
next x
next y
endfunction
//####
function moveblocks()
moving = 0
for y = gridy to 1 step -1
for x = 1 to gridx
// check if we have a block that need to be moved.
if ttis[ x , y ] = 0
if ttis[ x , y - 1 ] > 0 and ttis[ x , y - 1 ] < 20
// move block.
ttis[ x , y ] = ttis[ x , y - 1 ]
ttis[ x , y - 1 ] = 0
moving = 1
endif
endif
next x
next y
endfunction
//####
function blockhit()
for x = 1 to gridx
if ttis[ x , gridy ] > 0 and ttis[ x , gridy ] < 20
newblock = 1
return
endif
next x
for y = gridy to 1 step -1
for x = 1 to gridx
// check for a hit after move
if ( ttis[ x , y - 1 ] > 0 and ttis[ x , y - 1 ] < 20 ) and ( ttis[ x , y ] > 20 )
// freeze current clocks.
newblock = 1
return
endif
next x
next y
endfunction
//####
function drawblocks()
for y = yhidden to gridy
for x = 1 to gridx
if ttis[ x , y ] = 1 or ttis[ x , y ] = 21
SetSpriteColor ( tsprite[ x , y ] , 0 , 0 , 247 , 255 )
elseif ttis[ x , y ] = 2 or ttis[ x , y ] = 22
SetSpriteColor ( tsprite[ x , y ] , 250 , 250 , 0 , 255 )
elseif ttis[ x , y ] = 3 or ttis[ x , y ] = 23
SetSpriteColor ( tsprite[ x , y ] , 250 ,100 , 0 , 255 )
elseif ttis[ x , y ] = 4 or ttis[ x , y ] = 24
SetSpriteColor ( tsprite[ x , y ] , 250 ,0 , 0 , 255 )
elseif ttis[ x , y ] = 5 or ttis[ x , y ] = 25
SetSpriteColor ( tsprite[ x , y ] , 100 , 200 , 255 , 255 )
elseif ttis[ x , y ] = 6 or ttis[ x , y ] = 26
SetSpriteColor ( tsprite[ x , y ] , 200 , 0 , 255 , 255 )
elseif ttis[ x , y ] = 7 or ttis[ x , y ] = 27
SetSpriteColor ( tsprite[ x , y ] , 0 , 200 , 0 , 255 )
else
//SetSpriteColor ( tsprite[ x , y ] , 45 , 94 , 163 , 255 )
SetSpriteColor ( tsprite[ x , y ] , y*1.6 , 0 , 0 , 255 )
endif
SetSpritePosition( tsprite[ x , y ] , gridxstart + ( gridxsize * x ) , gridystart + ( gridysize * (y-yhidden) ) )
next x
next y
// draw next block.
for y = 1 to 3
for x = 1 to 3
if tnext[ x , y ] > 0
SetSpriteColor ( tnsprite[ x , y ] , 150 , 150 , 150 , 255 )
else
SetSpriteColor ( tnsprite[ x , y ] , 24 , 47 , 80 , 255 )
endif
SetSpritePosition( tnsprite[ x , y ] , gridxstart + ( gridxsize * (gridx+x) ) + 4 , gridystart + ( gridysize * y-1 ) )
next x
next y
endfunction
//####
function createblock()
// freeze all current blocks.
for y = yhidden to gridy
for x = 1 to gridx
if ttis[x,y] < 20 and ttis[x,y] > 0
ttis[x,y] = ttis[x,y] + 20
endif
next x
next y
for i = 1 to 3
tnext[1,i] = 0
tnext[2,i] = 0
tnext[3,i] = 0
next i
// check if we need to remove any lines.
anotherremove:
for y = 1 to gridy
countx = 1
for x = 1 to gridx
if ttis[x,y] >= 20
countx = countx + 1
endif
next x
if countx > gridx
// display delete line.
drawblocks()
sync()
for x = 1 to gridx
score = score + 1 // score for line
SetSpriteColor ( tsprite[ x , y ] , 200 , 200 , 200 , 255 )
sync()
next x
//delete line y
ycopy = gridy
for yy = gridy to 1 step -1
if ycopy = y
ycopy = ycopy - 1
endif
for xx = 1 to gridx
ttis[xx,yy] = ttis[xx,ycopy]
next xx
ycopy = ycopy - 1
next yy
endif
next y
newblock = 0
if nextblock = 1
ttis[5,1] = 1; ttis[5,2] = 1; ttis[5,3] = 1; ttis[6,3] = 1;
elseif nextblock = 2
ttis[4,1] = 2; ttis[5,1] = 2; ttis[6,1] = 2; ttis[5,2] = 2;
elseif nextblock = 3
ttis[4,1] = 3; ttis[5,1] = 3; ttis[6,1] = 3;
elseif nextblock = 4
ttis[5,1] = 4; ttis[5,2] = 4; ttis[6,1] = 4; ttis[6,2] = 4;
elseif nextblock = 5
ttis[5,1] = 5; ttis[6,1] = 5; ttis[4,2] = 5; ttis[5,2] = 5;
elseif nextblock = 6
ttis[5,1] = 6; ttis[5,2] = 6; ttis[5,3] = 6; ttis[4,3] = 6;
elseif nextblock = 7
ttis[4,1] = 7; ttis[5,1] = 7; ttis[5,2] = 7; ttis[6,2] = 7;
endif
nextblock = random(1,7)
if nextblock = 1
tnext[2,1] = 1; tnext[2,2] = 1; tnext[2,3] = 1; tnext[3,3] = 1;
elseif nextblock = 2
tnext[1,1] = 2; tnext[2,1] = 2; tnext[3,1] = 2; tnext[2,2] = 2;
elseif nextblock = 3
tnext[1,1] = 3; tnext[2,1] = 3; tnext[3,1] = 3;
elseif nextblock = 4
tnext[2,1] = 4; tnext[2,2] = 4; tnext[3,1] = 4; tnext[3,2] = 4;
elseif nextblock = 5
tnext[2,1] = 5; tnext[3,1] = 5; tnext[1,2] = 5; tnext[2,2] = 5;
elseif nextblock = 6
tnext[2,1] = 6; tnext[2,2] = 6; tnext[2,3] = 6; tnext[1,3] = 6;
elseif nextblock = 7
tnext[1,1] = 7; tnext[2,1] = 7; tnext[2,2] = 7; tnext[3,2] = 7;
endif
// 10 points for a new block
score = score + 10
if gamemode = 1
dropspeed# = dropspeed# - 0.003
if dropspeed# < 0.14
dropspeed# = 0.14
endif
elseif gamemode = 2 // relax
dropspeed# = 0.70
elseif gamemode = 3 // normal
dropspeed# = 0.50
elseif gamemode = 4 // hard
dropspeed# = 0.20
elseif gamemode = 5 // insane
dropspeed# = 0.10
endif
endfunction
//####
function ending()
oldgamemode = gamemode
if score > 0 and score > Val( highscore[oldgamemode,1] )
submitactive = 1
else
submitactive = 0
endif
if submitactive = 1
AddVirtualButton( 8, 130, 304, 110 )
SetVirtualButtonColor( 8, 100 , 100 , 100 )
SetVirtualButtonText( 8, " SUBMIT " )
SetVirtualButtonAlpha( 8, 90 )
endif
CreateText ( 5, "" )
SetTextSize ( 5, 30 )
SetTextColor ( 5, 255, 255, 255, 255 )
scrollpos = 600
CreateText ( 7, "" ) // scroll
SetTextSize ( 7, 30 )
SetTextColor ( 7, 43, 91, 159, 255 )
SetTextString ( 7, " Select mode and press PLAY To move block point anywhere on the left side of the screen to move left, right to move right, center to rotate. " )
SetTextPosition ( 7, scrollpos , 446 )
CreateText ( 8, "" ) // scroll
SetTextSize ( 8, 14 )
SetTextColor ( 8, 118, 163, 226, 255 )
hscrollstr = 0; hscrollpos = -350
if score > 0
DeleteVirtualButton( 10 )
DeleteVirtualButton( 11 )
CreateText ( 3, "GAME OVER" )
if submitactive = 1
CreateText ( 4, "HIGH SCORE" )
else
CreateText ( 4, "YOUR SCORE" )
endif
SetTextString ( 5, Str( score ) )
SetTextPosition ( 5, 128-GetTextTotalWidth( 5 )/2 , 255 )
else
CreateText ( 3, " WELCOME " )
CreateText ( 4, " TO 3TRIS" )
SetTextString ( 5, "" )
endif
SetTextSize ( 3, 38 )
SetTextPosition ( 3, 22, 155 )
SetTextColor ( 3, 255, 255, 255, 255 )
SetTextSize ( 4, 30 )
SetTextPosition ( 4, 36, 205 )
SetTextColor ( 4, 255, 255, 255, 255 )
for y = 1 to 3
for x = 1 to 3
SetSpritePosition( tnsprite[ x , y ] , gridxstart + ( gridxsize * (gridx+x) ) + 4 + 400 , gridystart + ( gridysize * y-1 ) )
next x
next y
SetTextPosition ( 1, 1250, 155 ) // score text
SetTextPosition ( 2, 1250, 175 ) // score
AddVirtualButton( 1, 90, 398, 60 )
SetVirtualButtonColor( 1, 0, 255, 0 )
SetVirtualButtonText( 1, " PLAY " )
SetVirtualButtonAlpha( 1, 200 )
AddVirtualButton( 2, 170, 398, 60 )
SetVirtualButtonColor( 2, 250 , 0, 0 )
SetVirtualButtonText( 2, " EXIT " )
SetVirtualButtonAlpha( 2, 200 )
CreateText ( 6, "MODE" )
SetTextSize ( 6, 24 )
SetTextPosition ( 6, 250 , 20 )
SetTextColor ( 6, 255, 255, 255, 255 )
gamemode = 1
AddVirtualButton( 3, 280, 80, 70 )
SetVirtualButtonColor( 3, 100, 255, 100 )
SetVirtualButtonText( 3, "ARCADE" )
SetVirtualButtonAlpha( 3, 200 )
AddVirtualButton( 4, 280, 80+(1*72), 70 )
SetVirtualButtonColor( 4, 100, 100, 100 )
SetVirtualButtonText( 4, "RELAX" )
SetVirtualButtonAlpha( 4, 200 )
AddVirtualButton( 5, 280, 80+(2*72), 70 )
SetVirtualButtonColor( 5, 100 , 100 , 100 )
SetVirtualButtonText( 5, "NORMAL" )
SetVirtualButtonAlpha( 5, 200 )
AddVirtualButton( 6, 280, 80+(3*72), 70 )
SetVirtualButtonColor( 6, 100 , 100 , 100 )
SetVirtualButtonText( 6, "HARD" )
SetVirtualButtonAlpha( 6, 200 )
AddVirtualButton( 7, 280, 80+(4*72), 70 )
SetVirtualButtonColor( 7, 100 , 100 , 100 )
SetVirtualButtonText( 7, "INSANE" )
SetVirtualButtonAlpha( 7, 200 )
myexit = 0
aniloop# = 0
// sync loop
while myexit = 0
if submitactive = 1
if GetTextInputCompleted ( ) = 1
text$ = GetTextInput ( )
highscore[oldgamemode,2] = text$
highscore[oldgamemode,1] = Str( score )
//save score
fileid = OpenToWrite ( "3trishighscore.txt", 0 )
for fl = 1 to 5
WriteString ( fileid, highscore[fl,1] )
WriteString ( fileid, highscore[fl,2] )
next fl
CloseFile ( fileid )
SetVirtualButtonText( 8, "" )
SetVirtualButtonAlpha( 8, 1 )
SetVirtualButtonVisible( 8, 0 )
SetVirtualButtonActive( 8, 0 )
endif
if ( GetVirtualButtonReleased( 8 ) = 1)
StartTextInput ( )
text$ = ""
endif
endif
if ( GetVirtualButtonReleased( 1 ) = 1)
myexit = 1
endif
if ( GetVirtualButtonReleased( 2 ) = 1)
goto endprogram
endif
if ( GetVirtualButtonReleased( 3 ) = 1)
gamemode = 1
setbutcol()
SetVirtualButtonColor( 3, 100, 255, 100 );
hscrollstr = 0; hscrollpos = -400
endif
if ( GetVirtualButtonReleased( 4 ) = 1)
gamemode = 2
setbutcol()
SetVirtualButtonColor( 4, 100, 255, 100 )
hscrollstr = 1; hscrollpos = -400
endif
if ( GetVirtualButtonReleased( 5 ) = 1)
gamemode = 3
setbutcol()
SetVirtualButtonColor( 5, 100, 255, 100 )
hscrollstr = 2; hscrollpos = -400
endif
if ( GetVirtualButtonReleased( 6 ) = 1)
gamemode = 4
setbutcol()
SetVirtualButtonColor( 6, 100, 255, 100 )
hscrollstr = 3; hscrollpos = -400
endif
if ( GetVirtualButtonReleased( 7 ) = 1)
gamemode = 5
setbutcol()
SetVirtualButtonColor( 7, 100, 255, 100 )
hscrollstr = 4; hscrollpos = -400
endif
SetTextPosition ( 7, scrollpos , 446 )
scrollpos = scrollpos - 2
if scrollpos < -3000
scrollpos = 1000
endif
SetTextPosition ( 8, hscrollpos , 3 )
if hscrollpos > -350
hscrollpos = hscrollpos - 2
endif
if hscrollpos < -360
hscrollstr = hscrollstr + 1
if hscrollstr > 5
hscrollstr = 1
endif
if hscrollstr = 1
highstr$ = "HIGHSCORE Arcade: " + highscore[1,2] + " - " + highscore[1,1]
elseif hscrollstr = 2
highstr$ = "HIGHSCORE Relax: " + highscore[2,2] + " - " + highscore[2,1]
elseif hscrollstr = 3
highstr$ = "HIGHSCORE Normal: " + highscore[3,2] + " - " + highscore[3,1]
elseif hscrollstr = 4
highstr$ = "HIGHSCORE Hard: " + highscore[4,2] + " - " + highscore[4,1]
else
highstr$ = "HIGHSCORE Insane: " + highscore[5,2] + " - " + highscore[5,1]
endif
SetTextString ( 8, highstr$ )
hscrollpos = 400
endif
if aniloop# <= 800
for y = yhidden to gridy
for x = 1 to gridx
SetSpritePosition( tsprite[ x , y ] , gridxstart + ( gridxsize * x ) + (sin(x*aniloop#)*3), gridystart + ( gridysize * (y-yhidden) ) + (cos(y*aniloop#)*3) )
next x
next y
endif
aniloop# = aniloop# + 1.5
if aniloop# > 500
for y = yhidden to gridy
for x = 1 to gridx
SetSpriteShape ( tsprite[ x , y ] , 2 )
SetSpritePhysicsOn ( tsprite[ x , y ] , 2 )
SetSpritePhysicsRestitution( tsprite[ x , y ] , 0 ) // 0 bounce to prevent physics agk bug
next x
next y
endif
sync()
endwhile
SetTextPosition ( 1, 250, 155 ) // score text
SetTextPosition ( 2, 250, 175 ) // score
for y = yhidden to gridy
for x = 1 to gridx
SetSpritePhysicsOff ( tsprite[ x , y ] )
setSpriteAngle ( tsprite[ x , y ] , 0 )
next x
next y
DeleteVirtualButton( 1 )
DeleteVirtualButton( 2 )
DeleteVirtualButton( 3 )
DeleteVirtualButton( 4 )
DeleteVirtualButton( 5 )
DeleteVirtualButton( 6 )
DeleteVirtualButton( 7 )
if submitactive = 1
DeleteVirtualButton( 8 )
endif
DeleteText( 3 )
DeleteText( 4 )
DeleteText( 5 )
DeleteText( 6 )
DeleteText( 7 )
DeleteText( 8 )
// start speed.
global dropspeed# = 0.60
// clear level.
for y = 1 to gridy
for x = 1 to gridx
ttis[x,y] = 0
next x
next y
score = 0
// game button
AddVirtualButton( 10, 279, 118+(4*72), 70 )
SetVirtualButtonColor( 10, 100 , 100 , 100 )
SetVirtualButtonText( 10, "ROTATE" )
SetVirtualButtonAlpha( 10, 200 )
AddVirtualButton( 11, 279, 118+(3*72), 70 )
SetVirtualButtonColor( 11, 100 , 100 , 100 )
SetVirtualButtonText( 11, "DROP" )
SetVirtualButtonAlpha( 11, 200 )
endfunction
function setbutcol()
SetVirtualButtonColor( 3, 100, 100, 100 );
SetVirtualButtonColor( 4, 100, 100, 100 );
SetVirtualButtonColor( 5, 100, 100, 100 );
SetVirtualButtonColor( 6, 100, 100, 100 );
SetVirtualButtonColor( 7, 100, 100, 100 );
endfunction
endprogram:
Code 900 lines, style get the job done.
Edit: made video that show highscore submit.
best regards Preben Eriksen,