Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "au3Irrlicht2.au3"
- #Include <Timers.au3>
- $title="Tetris Beta v_1.0 by CheapBrain"
- $x=@DesktopWidth/2-200
- $y=@DesktopHeight/2-200
- $gridx=120+$x
- $gridy=27+$y
- _IrrStart($IRR_EDT_SOFTWARE,@DesktopWidth,@DesktopHeight,$IRR_BITS_PER_PIXEL_16,$IRR_FULLSCREEN,$IRR_NO_SHADOWS,$IRR_CAPTURE_EVENTS,$IRR_VERTICAL_SYNC_OFF)
- _IrrSetWindowCaption($title)
- local $bitmapFont = _IrrGetFont ( @ScriptDir&"\font1.png" )
- local $logo = _IrrGetTexture(@ScriptDir&"\title.bmp")
- local $background = _IrrGetTexture(@ScriptDir&"\ingame.bmp")
- local $texture = _IrrGetTexture(@ScriptDir&"\texture.bmp")
- local $sprite[4][3], $tileset[10][24]
- _IrrBeginScene(0, 0, 0)
- _Irr2DFontDraw ( $BitmapFont, "Loading...", @DesktopWidth/2-30, @DesktopHeight/2-10, 10, 10 )
- _IrrEndScene()
- HotKeySet ( "{UP}" , "_up" )
- HotKeySet ( "{DOWN}" , "_down" )
- HotKeySet ( "{RIGHT}" , "_right" )
- HotKeySet ( "{LEFT}" , "_left" )
- HotKeySet ( "{ENTER}" , "_enter" )
- HotKeySet ( "{SPACE}" , "_space" )
- _menu()
- func _menu()
- Local $timer=TimerInit()
- local $count=0
- local $fps=0
- local $mouse=0
- local $mousex=0
- local $mousey=0
- global $enter=0
- global $up=0
- global $down=0
- global $right=0
- global $left=0
- global $space=0
- global $key=0
- While 1
- if not WinActive($title) then _sleep()
- _IrrBeginScene(18, 44, 77)
- _IrrDraw2DImage( $logo, $x, $y )
- _Irr2DFontDraw ( $BitmapFont, " x:"&$mousex&@CRLF&" y:"&$mousey&@CRLF&" click:"&$mouse&@CRLF&" FPS:"&$fps, 0, 0, 10, 10 )
- while _IrrMouseEventAvailable()
- $pMouseEvent = _IrrReadMouseEvent()
- $mousex=__getMouseEvt($pMouseEvent, $EVT_MOUSE_IX)-$x
- $mousey=__getMouseEvt($pMouseEvent, $EVT_MOUSE_IY)-$y
- if __getMouseEvt($pMouseEvent, $EVT_MOUSE_IACTION)=$IRR_EMIE_LMOUSE_PRESSED_DOWN then
- $mouse=1
- Else
- $mouse=0
- endif
- if $mouse=1 Then
- if $mousex>139 And $mousex<278 And $mousey>356 and $mousey<400 then
- _IrrEndScene()
- _stop()
- ElseIf $mousex>105 And $mousex<293 And $mousey>171 and $mousey<213 then
- _IrrEndScene()
- _game()
- ElseIf $mousex>105 And $mousex<293 And $mousey>238 and $mousey<280 then
- _IrrEndScene()
- _high()
- ElseIf $mousex>7 And $mousex<38 And $mousey>365 and $mousey<396 then
- _IrrEndScene()
- _help()
- ElseIf $mousex>46 And $mousex<76 And $mousey>365 and $mousey<396 then
- _IrrEndScene()
- _sett()
- endif
- EndIf
- wend
- _IrrEndScene()
- $count+=1
- if $count=20 Then
- $fps=Round(20000/TimerDiff($timer),0)
- $timer=TimerInit()
- $count=0
- EndIf
- WEnd
- endfunc
- func _game()
- local $binfo="10101010001010110001011100101110000111100010110100111100"
- Local $block[7][2][4]
- for $dh45=0 to 6
- for $dh50=0 to 3
- for $dh55=0 to 1
- $block[$dh45][$dh55][$dh50]=stringmid($binfo,8*$dh45+$dh50*2+$dh55+1,1)
- Next
- Next
- Next
- Local $sprite[3]
- Local $ran1=10
- Local $ran2=10
- for $dh45=0 to 2
- while $ran1=$ran2
- $ran2=Random(0,6,1)
- wend
- $ran1=$ran2
- $sprite[$dh45]=$ran1
- Next
- Local $tileset[11][24]
- For $dh45=0 to 10
- for $dh50=0 to 23
- $tileset[$dh45][$dh50]=0
- Next
- Next
- Local $timer=TimerInit()
- Local $autodown= TimerInit()
- Local $interr=1000
- Local $count=0
- Local $fps=0
- global $enter=0
- global $up=0
- global $down=0
- global $right=0
- global $left=0
- global $space=0
- global $key=0
- global $posx=64
- global $posy=-64
- Local $spritecoord[4][2]
- Local $spritecoord2[4][2]
- Local $rotate=0
- $count45=0
- for $dh45=0 to 3
- for $dh50=0 to 1
- if $block[$sprite[0]][$dh50][$dh45]=1 Then
- $spritecoord[$count45][0]=$dh50*16
- $spritecoord[$count45][1]=$dh45*16
- $count45+=1
- EndIf
- Next
- Next
- while 1
- _IrrBeginScene(18, 44, 77)
- _Irr2DFontDraw ( $BitmapFont, "game"&@CRLF&" FPS:"&$fps, 0, 0, 10, 10 )
- _IrrDraw2DImage($background,$x,$y)
- _IrrDraw2DImageElement($texture, $gridx+$posx+$spritecoord[0][0], $gridy+$posy+$spritecoord[0][1], $sprite[0]*16, 0, $sprite[0]*16+16, 16,$IRR_USE_ALPHA)
- _IrrDraw2DImageElement($texture, $gridx+$posx+$spritecoord[1][0], $gridy+$posy+$spritecoord[1][1], $sprite[0]*16, 0, $sprite[0]*16+16, 16,$IRR_USE_ALPHA)
- _IrrDraw2DImageElement($texture, $gridx+$posx+$spritecoord[2][0], $gridy+$posy+$spritecoord[2][1], $sprite[0]*16, 0, $sprite[0]*16+16, 16,$IRR_USE_ALPHA)
- _IrrDraw2DImageElement($texture, $gridx+$posx+$spritecoord[3][0], $gridy+$posy+$spritecoord[3][1], $sprite[0]*16, 0, $sprite[0]*16+16, 16,$IRR_USE_ALPHA)
- For $dh45=1 to 10
- For $dh50=4 to 23
- if $tileset[$dh45][$dh50]<>0 Then
- _IrrDraw2DImageElement($texture, $gridx+($dh45-1)*16, $gridy+($dh50-4)*16, ($tileset[$dh45][$dh50]-1)*16, 0, ($tileset[$dh45][$dh50]-1)*16+16, 16,$IRR_USE_ALPHA)
- EndIf
- Next
- Next
- If $key=1 Then
- $key=0
- if $enter=1 Then
- $enter=0
- _pause()
- ElseIf $left=1 then
- if $posx-16+$spritecoord[0][0]>-1 And $posx-16+$spritecoord[1][0]>-1 And $posx-16+$spritecoord[2][0]>-1 And $posx-16+$spritecoord[3][0]>-1 and $tileset[($posx+$spritecoord[0][0])/16][($posy+$spritecoord[0][1])/16+4]+$tileset[($posx+$spritecoord[1][0])/16][($posy+$spritecoord[1][1])/16+4]+$tileset[($posx+$spritecoord[2][0])/16][($posy+$spritecoord[2][1])/16+4]+$tileset[($posx+$spritecoord[3][0])/16][($posy+$spritecoord[3][1])/16+4]=0 then
- $posx-=16
- endif
- $left=0
- ElseIf $right=1 then
- if $posx+16+$spritecoord[0][0]<160 And $posx+16+$spritecoord[1][0]<160 And $posx+16+$spritecoord[2][0]<160 And $posx+16+$spritecoord[3][0]<160 and $tileset[($posx+$spritecoord[0][0])/16+2][($posy+$spritecoord[0][1])/16+4]+$tileset[($posx+$spritecoord[1][0])/16+2][($posy+$spritecoord[1][1])/16+4]+$tileset[($posx+$spritecoord[2][0])/16+2][($posy+$spritecoord[2][1])/16+4]+$tileset[($posx+$spritecoord[3][0])/16+2][($posy+$spritecoord[3][1])/16+4]=0 then
- $posx+=16
- endif
- $right=0
- ElseIf $up=1 then
- $up=0
- ElseIf $down=1 then
- if $posy+16+$spritecoord[0][1]<320 and $posy+16+$spritecoord[1][1]<320 and $posy+16+$spritecoord[2][1]<320 and $posy+16+$spritecoord[3][1]<320 and $tileset[($posx+$spritecoord[0][0])/16+1][($posy+$spritecoord[0][1])/16+5]+$tileset[($posx+$spritecoord[1][0])/16+1][($posy+$spritecoord[1][1])/16+5]+$tileset[($posx+$spritecoord[2][0])/16+1][($posy+$spritecoord[2][1])/16+5]+$tileset[($posx+$spritecoord[3][0])/16+1][($posy+$spritecoord[3][1])/16+5]=0 then
- $posy+=16
- endif
- $down=0
- elseif $space=1 Then
- $rotate+=1
- if $rotate=4 then $rotate=0
- $outgrid=0
- $tempx=0
- $tempy=0
- for $dh45=0 to 3
- for $dh50=0 to 1
- if $block[$sprite[0]][$dh50][$dh45]=1 Then
- if $rotate=0 Then
- $tempx=$dh50*16
- $tempy=$dh45*16
- elseif $rotate=1 Then
- $tempx=32-$dh45*16
- $tempy=$dh50*16+16
- elseif $rotate= 2 Then
- $tempx=16-$dh50*16
- $tempy=48-$dh45*16
- Elseif $rotate= 3 then
- $tempx=$dh45*16-16
- $tempy=32-$dh50*16
- EndIf
- if $posx+$tempx<0 or $posx+$tempx>159 or $posy+$tempy>319 then
- $outgrid=1
- $rotate-=1
- if $rotate=-1 then $rotate=3
- ElseIf $tileset[($posx+$tempx)/16+1][($posy+$tempy)/16+4]<>0 Then
- $outgrid=1
- $rotate-=1
- if $rotate=-1 then $rotate=3
- EndIf
- EndIf
- Next
- Next
- if $outgrid=0 then
- $count45=0
- for $dh45=0 to 3
- for $dh50=0 to 1
- if $block[$sprite[0]][$dh50][$dh45]=1 Then
- if $rotate=0 Then
- $spritecoord[$count45][0]=$dh50*16
- $spritecoord[$count45][1]=$dh45*16
- elseif $rotate=1 Then
- $spritecoord[$count45][0]=32-$dh45*16
- $spritecoord[$count45][1]=$dh50*16+16
- elseif $rotate= 2 Then
- $spritecoord[$count45][0]=16-$dh50*16
- $spritecoord[$count45][1]=48-$dh45*16
- Elseif $rotate= 3 then
- $spritecoord[$count45][0]=$dh45*16-16
- $spritecoord[$count45][1]=32-$dh50*16
- EndIf
- $count45+=1
- EndIf
- Next
- Next
- EndIf
- $space=0
- EndIf
- EndIf
- _IrrEndScene()
- $count+=1
- if $count=20 Then
- $fps=Round(20000/TimerDiff($timer),0)
- $timer=TimerInit()
- $count=0
- EndIf
- if TimerDiff($autodown)>$interr Then
- $autodown= TimerInit()
- if $posy+16+$spritecoord[0][1]<320 and $posy+16+$spritecoord[1][1]<320 and $posy+16+$spritecoord[2][1]<320 and $posy+16+$spritecoord[3][1]<320 and $tileset[($posx+$spritecoord[0][0])/16+1][($posy+$spritecoord[0][1])/16+5]+$tileset[($posx+$spritecoord[1][0])/16+1][($posy+$spritecoord[1][1])/16+5]+$tileset[($posx+$spritecoord[2][0])/16+1][($posy+$spritecoord[2][1])/16+5]+$tileset[($posx+$spritecoord[3][0])/16+1][($posy+$spritecoord[3][1])/16+5]=0 then
- $posy+=16
- Else
- $tileset[($posx+$spritecoord[0][0])/16+1][($posy+$spritecoord[0][1])/16+4]=$sprite[0]+1
- $tileset[($posx+$spritecoord[1][0])/16+1][($posy+$spritecoord[1][1])/16+4]=$sprite[0]+1
- $tileset[($posx+$spritecoord[2][0])/16+1][($posy+$spritecoord[2][1])/16+4]=$sprite[0]+1
- $tileset[($posx+$spritecoord[3][0])/16+1][($posy+$spritecoord[3][1])/16+4]=$sprite[0]+1
- $tileset[0][($posy+$spritecoord[0][1])/16+4]+=1
- $tileset[0][($posy+$spritecoord[1][1])/16+4]+=1
- $tileset[0][($posy+$spritecoord[2][1])/16+4]+=1
- $tileset[0][($posy+$spritecoord[3][1])/16+4]+=1
- for $dh55=4 to 23
- if $tileset[0][$dh55]=10 Then
- For $dh45=$dh55 to 1 step -1
- for $dh50=0 to 10
- $tileset[$dh50][$dh45]=$tileset[$dh50][$dh45-1]
- next
- Next
- EndIf
- next
- if $tileset[0][3]>0 or $tileset[0][2]>0 then _menu()
- $sprite[0]=$sprite[1]
- $sprite[1]=$sprite[2]
- while $ran1=$ran2
- $ran2=Random(0,6,1)
- wend
- $ran1=$ran2
- $sprite[2]=$ran1
- $count45=0
- for $dh45=0 to 3
- for $dh50=0 to 1
- if $block[$sprite[0]][$dh50][$dh45]=1 Then
- $spritecoord[$count45][0]=$dh50*16
- $spritecoord[$count45][1]=$dh45*16
- $count45+=1
- EndIf
- Next
- Next
- $posx=64
- $posy=-64
- $rotate=0
- EndIf
- EndIf
- wend
- endfunc
- func _high()
- while 1
- _IrrBeginScene(18, 44, 77)
- _Irr2DFontDraw ( $BitmapFont, "high", 0, 0, 10, 10 )
- _IrrEndScene()
- wend
- endfunc
- func _sett()
- while 1
- _IrrBeginScene(18, 44, 77)
- _Irr2DFontDraw ( $BitmapFont, "sett", 0, 0, 10, 10 )
- _IrrEndScene()
- wend
- endfunc
- func _help()
- while 1
- _IrrBeginScene(18, 44, 77)
- _Irr2DFontDraw ( $BitmapFont, "help", 0, 0, 10, 10 )
- _IrrEndScene()
- wend
- endfunc
- func _stop()
- _IrrStop()
- exit
- EndFunc
- func _sleep()
- while WinActive($title)<>true
- sleep(500)
- wend
- endfunc
- func _pause()
- $wait1=true
- while $wait1
- _IrrBeginScene(18, 44, 77)
- _Irr2DFontDraw ( $BitmapFont, "pause", 0,0, 10, 10 )
- _Irr2DFontDraw ( $BitmapFont, "Back", $x+180,$y+50, 10, 10 )
- _Irr2DFontDraw ( $BitmapFont, "Menu", $x+180,$y+100, 10, 10 )
- _Irr2DFontDraw ( $BitmapFont, "Exit", $x+180,$y+150, 10, 10 )
- while _IrrMouseEventAvailable()
- $pMouseEvent = _IrrReadMouseEvent()
- $mousex=__getMouseEvt($pMouseEvent, $EVT_MOUSE_IX)-$x
- $mousey=__getMouseEvt($pMouseEvent, $EVT_MOUSE_IY)-$y
- if __getMouseEvt($pMouseEvent, $EVT_MOUSE_IACTION)=$IRR_EMIE_LMOUSE_PRESSED_DOWN then
- $mouse=1
- Else
- $mouse=0
- endif
- if $mouse=1 Then
- if $mousex>180 And $mousex<280 And $mousey>50 and $mousey<75 then
- $wait1=false
- ElseIf $mousex>180 And $mousex<280 And $mousey>100 and $mousey<125 then
- _IrrEndScene()
- _menu()
- ElseIf $mousex>180 And $mousex<280 And $mousey>150 and $mousey<175 then
- _IrrEndScene()
- _stop()
- endif
- EndIf
- wend
- _IrrEndScene()
- wend
- endfunc
- func _up()
- $key=1
- $up=1
- endfunc
- func _down()
- $key=1
- $down=1
- endfunc
- func _right()
- $key=1
- $right=1
- endfunc
- func _left()
- $key=1
- $left=1
- endfunc
- func _space()
- $key=1
- $space=1
- endfunc
- func _enter()
- $key=1
- $enter=1
- endfunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement