Achilles Posted January 2, 2009 Share Posted January 2, 2009 (edited) TETRISThe music for Tetris is not attached here to due size. Click here to download it. (Try this if the previous doesn't work)Once you have it downloaded just place the three theme songs inside the same directory as Tetris - Pic.au3Options menu is not supposed to be functional yet.ControlsMove piece left - Left ArrowMove piece right - Right ArrowMove piece down - Down ArrowRotate Left - ARotate Right - SDrop - SpaceNew Game - F2Pause - F3UpdatesJanuary 12, 2009]Now uses pictures instead of labelsThe bug with pieces getting stuck should be gone (hopefully)High scoresSound is now functional (Music is attached in a seperate file)All pieces are redrawn in more efficient way that saves time and processingHotkeys get disabled when window loses focusPreview is now shown for where a piece will dropPreview for the next piece is now shownJanuary 2, 2009Added drop (Space bar), drop gives points depending on how far it dropsAdded menu (basic game operations and a currently non functional sound part)New Game function (F2)Pause function (F3)High Scores with decent GUIAbility to restart gameLevels are slightly easier (higher levels were going too fast)To DoCustomizable hotkeys - almost thereCustomizable colorsTetris.zipPrevious Downloads: 113 Edited January 13, 2009 by Ichigo My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 2, 2009 Share Posted January 2, 2009 Cool but there are a few bugs, I once made it crash by holding the "down arrow" for a few secs, and I don't think that green block was supposed to stop in mid-air...... .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
AlmarM Posted January 2, 2009 Share Posted January 2, 2009 Wow nicely done I like it @ AdmiralAlkex How the hell did you do that ;p? AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 @Ichigo Nice job, keep it up ! Cheers, FireFox. Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 (edited) @Ichigo After few hours of game Ive only one beug : the same as AdmiralAlkex It would be great that you add : -pause button -IsPressed instead of HotkeySet because with hotkeyset I can't tape 2keys in one time for example down and turn. So with IsPressed you can do if IsPressed down and turn then etc... -Store high score in a file Cheers, FireFox. Edited January 2, 2009 by FireFox Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 (edited) @IchigoAdded pause button and IsPressed functions : (Include Is_Pressed_UDF)Edit : Added help buttonEdit2 : Added restart button when loseEdit3 : Added highscores and sounds[autoit]#Region sound$snd = "http://d3monautoit.free.fr/sound/"If Not FileExists(@TempDir & "\move.mp3") Then InetGet($snd & "move.mp3", @TempDir & "\move.mp3", 1, 0) InetGet($snd & "down.mp3", @TempDir & "\down.mp3", 1, 0) InetGet($snd & "start.mp3", @TempDir & "\start.mp3", 1, 0) InetGet($snd & "gameover.mp3", @TempDir & "\gameover.mp3", 1, 0)EndIf#EndRegion sound#Region Include#include <Grid.au3>#include <File.au3>#include <Array.au3>#include <IsPressed_UDF.au3>#include <StaticConstants.au3>#include <GUIConstantsEx.au3>#include <WindowsConstants.au3>#EndRegion Include#Region GlobalGlobal Const $SINGLE = 40, $DOUBLE = 100, $TRIPLE = 300, $TETRIS = 1200Global Const $PIECE_FLAT = 0, $PIECE_SQUARE = 1, $PIECE_L = 2, $PIECE_BKL = 3, $PIECE_STEP = 4, $PIECE_BKSTEP = 5, $PIECE_MID = 6Global Const $COLORS[7] = [0xFF0000, 0xFFFF00, 0xFF8000, 0x0000FF, 0xFF00FF, 0x00FF00, 0x00FFFF]Global Const $WIDTH = 10, $HEIGHT = 20Global Const $SIZE = 20Global Const $BK_COLOR = 0x000000Global Const $GUI_L_W = 70Global $level = 0Global $score = 0Global $time = 800Global $lines = 0Global $idle = True ; set to false when redrawing or movingGlobal $currentPieceType ; 0-6Global $currentPieceOrien ; 0 = 12 o'clock, 1 = 3 0'clock...Global $currentPiece[4] ; An array of four coords#EndRegion Global#Region GUI$gui = GUICreate('Tetris', $SIZE * ($WIDTH + 1.5) + $GUI_L_W, $SIZE + 20 * ($HEIGHT + 1), -1, -1, $WS_SYSMENU, $WS_EX_CONTEXTHELP)GUIRegisterMsg($WM_SYSCOMMAND, "_help");~ GUICtrlCreateLabel('-- Preview --', 220, 200, 70, 20, $SS_CENTER);~ _Grid_Create(4, 5, 18, $BK_COLOR, 220, 220, $gui)_Grid_Create($WIDTH, $HEIGHT, $SIZE, $BK_COLOR, $SIZE / 2, $SIZE / 2, $gui)GUICtrlCreateLabel('-- Score --', $SIZE * ($WIDTH + 1), $SIZE / 2, $GUI_L_W, 20, $SS_CENTER)$lblScore = GUICtrlCreateLabel('', $SIZE * ($WIDTH + 1), $SIZE / 2 + 25, $GUI_L_W, 21, BitOR($SS_RIGHT, $SS_SUNKEN))GUICtrlSetData(-1, $score)GUICtrlCreateLabel('-- Level --', $SIZE * ($WIDTH + 1), $SIZE / 2 + 60, $GUI_L_W, 20, $SS_CENTER)$lblLevel = GUICtrlCreateLabel('', $SIZE * ($WIDTH + 1), $SIZE / 2 + 85, $GUI_L_W, 21, BitOR($SS_RIGHT, $SS_SUNKEN))GUICtrlSetData(-1, $level)GUICtrlCreateLabel('-- Lines --', $SIZE * ($WIDTH + 1), $SIZE / 2 + 120, $GUI_L_W, 20, $SS_CENTER)$lblLines = GUICtrlCreateLabel('', $SIZE * ($WIDTH + 1), $SIZE / 2 + 145, $GUI_L_W, 21, BitOR($SS_RIGHT, $SS_SUNKEN))GUICtrlSetData(-1, $level)GUISetFont(11)GUISetState(@SW_SHOW, $gui)#EndRegion GUI#Region StartSoundPlay(@TempDir & "\start.mp3")MsgBox(0, "Tetris", "Welcome to Tetris !")_GeneratePiece()AdlibEnable('_Down', $time)_EnableHotkeys()#EndRegion StartWhile 1 Sleep(75) If _IsAndKeyPressed("25|27") Then _Left() _Right() ElseIf _IsAndKeyPressed("25|28") Then _Left() _Down() ElseIf _IsAndKeyPressed("25|41") Then _Left() _RotateLeft() ElseIf _IsAndKeyPressed("25|53") Then _Left() _RotateRight() EndIf If _IsAndKeyPressed("27|28") Then _Right() _Down() ElseIf _IsAndKeyPressed("27|41") Then _Right() _RotateLeft() ElseIf _IsAndKeyPressed("27|53") Then _Right() _RotateRight() ElseIf _IsAndKeyPressed("41|53") Then _RotateLeft() _RotateRight() EndIf If _IsPressed("25") Then _Left() ElseIf _IsPressed("27") Then _Right() ElseIf _IsPressed("28") Then _Down() ElseIf _IsPressed("41") Then _RotateLeft() ElseIf _IsPressed("53") Then _RotateRight() ElseIf _IsPressed("26") Then _Bottom() EndIfWEnd#Region *** GAME ***Func _GeneratePiece() $currentPieceType = Random(0, 6, 1) $currentPieceOrien = 0 $posCurrentPiece = $currentPiece Switch $currentPieceType Case $PIECE_FLAT For $i = 0 To 3 Dim $temp[2] = [5, $i] $posCurrentPiece[$i] = $temp Next Case $PIECE_SQUARE For $i = 0 To 3 If $i < 2 Then Dim $temp[2] = [4 + $i, 0] Else Dim $temp[2] = [4 + ($i - 2), 1] EndIf $posCurrentPiece[$i] = $temp Next Case $PIECE_L For $i = 0 To 2 Dim $temp[2] = [4, $i] ; 1 is the rotation point $posCurrentPiece[$i] = $temp Next Dim $temp[2] = [5, 2] $posCurrentPiece[3] = $temp Case $PIECE_BKL ; 1 is the rotation point For $i = 0 To 2 Dim $temp[2] = [5, $i] $posCurrentPiece[$i] = $temp Next Dim $temp[2] = [4, 2] $posCurrentPiece[3] = $temp Case $PIECE_STEP Dim $temp[2] = [5, 0] $posCurrentPiece[0] = $temp Dim $temp[2] = [4, 1] $posCurrentPiece[1] = $temp Dim $temp[2] = [5, 1] $posCurrentPiece[2] = $temp ; 2 is the rotation point Dim $temp[2] = [4, 2] $posCurrentPiece[3] = $temp Case $PIECE_BKSTEP Dim $temp[2] = [4, 0] $posCurrentPiece[0] = $temp Dim $temp[2] = [4, 1] $posCurrentPiece[1] = $temp ; 2 is the rotation point Dim $temp[2] = [5, 1] $posCurrentPiece[2] = $temp Dim $temp[2] = [5, 2] $posCurrentPiece[3] = $temp Case $PIECE_MID For $i = 0 To 2 Dim $temp[2] = [4 + $i, 0] ; 1 is the rotation point $posCurrentPiece[$i] = $temp Next Dim $temp[2] = [5, 1] $posCurrentPiece[3] = $temp EndSwitch If Not _AreaIsClear($posCurrentPiece) Then _GameOver() Else $currentPiece = $posCurrentPiece _DrawPiece() EndIfEndFunc ;==>_GeneratePieceFunc _Land() _CheckGrid() _GeneratePiece()EndFunc ;==>_LandFunc _CheckGrid() Local $tempErase[4] = [-1, -1, -1, -1] $rowDrop = 0 For $i = $HEIGHT - 1 To 0 Step -1 $possible = True For $j = 0 To $WIDTH - 1;~ Msgbox(0, '', _Grid_GetColor($j, $i)) If _Grid_GetColor($j, $i) = 0 Then $possible = False ExitLoop EndIf Next If $possible Then $tempErase[$rowDrop] = $i $rowDrop += 1 EndIf Next If $tempErase[0] = -1 Then Return AdlibDisable() _DisableHotkeys() For $i = 0 To $rowDrop - 1 _Grid_SetRowColor($tempErase[$i], 0xFFFFFF) Next Sleep(500) $tempGrid = $colorGrid ; $colorGrid is taken from Grid.au3 $passed = 0 ; How many rows to bring down the everything (varies as the loop progresses) $row = $tempErase[0] $consec = 0 ; Number of consecutive Do While _ArraySearch($tempErase, $row - $passed) <> -1 $passed += 1 $consec += 1 WEnd If $consec > 0 Then Switch $consec Case 1 $score += ($level * $SINGLE) + $SINGLE $lines += 1 Case 2 $score += ($level * $DOUBLE) + $DOUBLE $lines += 2 Case 3 $score += ($level * $TRIPLE) + $TRIPLE $lines += 3 Case 4 $score += ($level * $TETRIS) + $TETRIS $lines += 4 EndSwitch GUICtrlSetData($lblScore, $score) GUICtrlSetData($lblLines, $lines) If $lines >= (($level + 1) * 10) Then $level += 1 GUICtrlSetData($lblLevel, $level) $time *= .8 EndIf $consec = 0 EndIf ;~ ConsoleWrite('> $row = ' & $row & @TAB & '$passed = ' & $passed & @CRLF) For $j = 0 To $WIDTH - 1 If $row - $passed < 0 Then $tempGrid[$row][$j] = $BK_COLOR Else $tempGrid[$row][$j] = $tempGrid[$row - $passed][$j] EndIf Next $row -= 1 Until $row - $passed < -1 ; Redraw the grid For $i = 0 To $HEIGHT - 1 For $j = 0 To $WIDTH - 1 _Grid_SetColor($tempGrid[$i][$j], $j, $i) Next Next AdlibEnable('_Down', $time) _EnableHotkeys();~ Msgbox(0, '', 'Any good?')EndFunc ;==>_CheckGrid#Region ModifiedFunc _DisableHotkeys() ;None HotKeySet("{PAUSE}", "_Pause") HotKeySet("a", "_None") HotKeySet("s", "_None")EndFunc ;==>_DisableHotkeysFunc _EnableHotkeys() ;None HotKeySet("{PAUSE}", "_Pause") HotKeySet("a", "_none") HotKeySet("s", "_none")EndFunc ;==>_EnableHotkeysFunc _None() ;Function for disable sound ; when enter a or sEndFunc ;==>_NoneFunc _Pause() TrayTip("Tetris", "Game paused !", 0, 1) HotKeySet("{PAUSE}", "_Unpause") Global $idle = False While 1 Sleep(100) If $idle = True Then ExitLoop WEndEndFunc ;==>_PauseFunc _Unpause() TrayTip('Tetris', 'Game restarted !', 0, 1) HotKeySet("{PAUSE}", "_Pause") Global $idle = TrueEndFunc ;==>_UnpauseFunc _Restart() _Grid_Destroy() _Grid_Create($WIDTH, $HEIGHT, $SIZE, $BK_COLOR, $SIZE / 2, $SIZE / 2, $gui) GUICtrlSetData($lblLevel, 0) GUICtrlSetData($lblScore, 0) GUICtrlSetData($lblLines, 0) AdlibEnable('_Down', $time)EndFunc ;==>_RestartFunc _help($hWnd, $Msg, $wParam, $lParam) If $wParam = 0x0000F180 Then ;HELP BUTTON MsgBox(64, "Tetris help/About...", "Author(s) : Edited January 2, 2009 by FireFox Link to comment Share on other sites More sharing options...
fmen Posted January 2, 2009 Share Posted January 2, 2009 @Firefox I get the following error as soon as the first piece hits the bottom: " Line 220==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $tempErase[$rowDrop] = $i ^ ERROR" Link to comment Share on other sites More sharing options...
FireFox Posted January 2, 2009 Share Posted January 2, 2009 @fmen Dont know why you've got this error .... Updated highscore + sounds ! Cheers, FireFox. Link to comment Share on other sites More sharing options...
Achilles Posted January 3, 2009 Author Share Posted January 3, 2009 Cool but there are a few bugs, I once made it crash by holding the "down arrow" for a few secs, and I don't think that green block was supposed to stop in mid-air......I've had that happen a few times. I'll try adding a bit more checks for making sure it's idle when you press down. It use to be way worse, but I added an $idle variable that stops it from redrawing in the middle of it's drawing, but I guess it isn't covering everything yet. Wow nicely done I like it AlmarMThanks! Thanks for all your input. Most of those suggestions were what I was thinking of doing. I'll probably use some of what you added if you don't mind. I personally don't like the sound effects much, but I'll try to find something that works to my liking more. I'll probably add a GUI instead of using a message box at the end though... I'm not sure if the _IsPressed udf is an improvement. It seems to make the pieces move/rotate too fast. I know you said that you could do both at once, but when you try it seems kind of buggy, like it only works sometime. @fmen: Does that happen with my version? The error you described happens when an item is trying to be drawn outside the grid (causes an array error, as I have experienced many times in testing). I thought I got all possibilities of that happening blocked... @everyone: I'll be adding some of firefox's updates and some of my own soon... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Zedna Posted January 3, 2009 Share Posted January 3, 2009 Looks nice.There are another Tetris game AutoIt's implementations.You can take some ideas from therehttp://www.autoitscript.com/forum/index.ph...1&hl=tetrishttp://www.autoitscript.com/forum/index.ph...9&hl=tetrishttp://www.autoitscript.com/forum/index.ph...9&hl=tetris Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Achilles Posted January 3, 2009 Author Share Posted January 3, 2009 Looks nice.There are another Tetris game AutoIt's implementations.You can take some ideas from therehttp://www.autoitscript.com/forum/index.ph...1&hl=tetrishttp://www.autoitscript.com/forum/index.ph...9&hl=tetrishttp://www.autoitscript.com/forum/index.ph...9&hl=tetrisThanks... Those other ones you listed don't have too much to more than mine. As soon as I get back to my desktop I'll be making some decent graphics and adding a few other things. I'm getting sick of programming on my laptop without a real mouse... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Achilles Posted January 3, 2009 Author Share Posted January 3, 2009 Updated My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
BrettF Posted January 3, 2009 Share Posted January 3, 2009 Pause allows you to still move pieces. And I believe _IsPressed is better... But I like the concept. Thank you for sharing it. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
FireFox Posted January 3, 2009 Share Posted January 3, 2009 @Ichigo BrettF is right, Is_Pressed is better, you have just to change as you like sleep in the while and sleep after IsPressed Cheers, FireFox. Link to comment Share on other sites More sharing options...
FireFox Posted January 3, 2009 Share Posted January 3, 2009 (edited) @Ichigo Menu for sound but no sound... Edit : I saw that you say its normal... First time I play when I click on highscore there is array variable error (you should write in highscore file like me with 0 score) Do you preffer to get more score only when you erase line ? (in my version +20 when you put a piece) Cheers, FireFox. Edited January 3, 2009 by FireFox Link to comment Share on other sites More sharing options...
rasim Posted January 3, 2009 Share Posted January 3, 2009 IchigoCool! 4 stars! Link to comment Share on other sites More sharing options...
Achilles Posted January 3, 2009 Author Share Posted January 3, 2009 Pause allows you to still move pieces. And I believe _IsPressed is better... But I like the concept. Thank you for sharing it.Cheers,BrettOk, I'll try changing it to _IsPressed with a slightly longer sleep time. Lol, I forgot to fix pause all the way.. I'll change that too.@IchigoMenu for sound but no sound... Edit : I saw that you say its normal...First time I play when I click on highscore there is array variable error (you should write in highscore file like me with 0 score)Do you preffer to get more score only when you erase line ? (in my version +20 when you put a piece)Cheers, FireFox.Yeah, I was just getting sound ready to add. I'll check the high score error.IchigoCool! 4 stars! Thanks! My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
FireFox Posted January 3, 2009 Share Posted January 3, 2009 @Ichigo Can you add my function "bottom" when you press up arrow then piece go to bottom Cheers, FireFox. Link to comment Share on other sites More sharing options...
Achilles Posted January 3, 2009 Author Share Posted January 3, 2009 @IchigoCan you add my function "bottom" when you press up arrow then piece go to bottom Cheers, FireFox.I didn't realize you had added it... However, I did add it... Push space bar. It seems to unlogical to have a piece drop when you press up so I think I'm going to leave it with space bar..I'll be adding customizable hotkeys soon so you'll be able to pick whatever keys you want. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
FireFox Posted January 3, 2009 Share Posted January 3, 2009 @Ichigo Its perhaps unlogicable but its better to play with arrows because when you turn piece with a or z you have to search space bar... Cheers, FireFox. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now