#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile_type=a3x #AutoIt3Wrapper_outfile=C:\Dokumente und Einstellungen\Administrator\Desktop\Stick\MicroSnake\Snake.a3x #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt('GUICloseOnESC', 0) Opt('GUIOnEventMode', 0) Opt('MustDeclareVars', 1) Global Const $WS_EX_LAYERED = 0x00080000 ; Style Global Const $WS_POPUP = 0x80000000 ; Style Global Const $WM_NCHITTEST = 0x0084 ; Fenster "Anfassen" Global Const $HTCAPTION = 2 ; Fenster "Anfassen" Global Const $COPY = 0x00CC0020 ; Blitten Global Const $BLACK = 0x00000042 ; Blitten Global $h_GDI32_DLL = DllOpen('gdi32.dll') Global $h_USER32_DLL = DllOpen('user32.dll') Global Const $Version = '1.00' Global Const $Name = 'Micro Snake' Global $Titel = $Name & ' ' & $Version Global Const $Breite = 30, $Hoehe = 30 If Not FileExists('settings.ini') Then IniWrite('settings.ini', 'Settings', 'Zoom', '12') Global $Zoom = Int(IniRead('settings.ini', 'Settings', 'Zoom', 12)) Global $Tempo = 20 Global $hGUI = GUICreate($Titel, $Breite * $Zoom, $Hoehe * $Zoom, Center($Breite * $Zoom, 1), Center($Hoehe * $Zoom), $WS_POPUP, $WS_EX_LAYERED) ; Fenster ohne Alles GUISetBkColor(0x0000FF, $hGUI) ; Damit kann man sehen ob iwo was transparent ist, oder nicht gezeichnet wird. WinSetTrans($hGUI, '', 255) ; Bei XP gibt es manchmal Probleme mit der Geschwindigkeit ohne 255 Trans GUISetOnEvent(-3, '__Exit', $hGUI) GUISetState(@SW_SHOW, $hGUI) Global $Buffer = _CreateImage($Breite, $Hoehe) Global $sBuffer = DllStructCreate('int['&$Breite*$Hoehe&']', DllStructGetData($Buffer, 1, 4)) Global $hDC_Gui = _WinAPI_GetDC($hGUI) OnAutoItExitRegister('_Exit') GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") While 1 _Start() WEnd Func _Start() _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 0, 0, $Breite, $Hoehe, 0, 0, 0, $BLACK) For $i = 0 To 1000 Step 1 invertpx(Random(1, 28, 1), Random(11, 28, 1)) Next While Sleep(20) And Not _IsPressed('0D') muster4x4(1+2,1,nr('s')) muster4x4(6+2,1,nr('n')) muster4x4(11+2,1,nr('a')) muster4x4(16+2,1,nr('k')) muster4x4(21+2,1,nr('e')) For $i = 0 To 9 Step 1 invertpx(Random(1, 28, 1), Random(11, 28, 1)) Next _WinAPI_StretchBlt($hDC_Gui, 0, 0, $Breite*$Zoom, $Hoehe*$Zoom, DllStructGetData($Buffer, 1, 1), 0 , 0, $Breite, $Hoehe,$COPY) WEnd _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 11, 6, 8, 6, 0, 0, 0, $BLACK) ;Platz machen um die Zahl in der Mitte Local Static $TempoTmp = 1 Local $Press = True Local $PressTmp = True While Sleep(20) For $i = 0 To 9 Step 1 invertpx(Random(1, 28, 1), Random(11, 28, 1)) Next _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 11, 6, 8, 6, 0, 0, 0, $BLACK) muster4x4(3,1,nr('s')) muster4x4(8,1,nr('p')) muster4x4(13,1,nr('e')) muster4x4(18,1,nr('e')) muster4x4(23,1,nr('d')) If _IsPressed('26') Then $TempoTmp += 1 If _IsPressed('28') Then $TempoTmp -= 1 If $TempoTmp < 10 Then $TempoTmp = 10 If $TempoTmp > 40 Then $TempoTmp = 40 muster4x4(13,6,nr(String(Int($TempoTmp/10)))) _WinAPI_StretchBlt($hDC_Gui, 0, 0, $Breite*$Zoom, $Hoehe*$Zoom, DllStructGetData($Buffer, 1, 1), 0 , 0, $Breite, $Hoehe,$COPY) $PressTmp = _IsPressed('0D') If Not $PressTmp Then $Press = False If $Press = False And $PressTmp Then ExitLoop WEnd Switch Int($TempoTmp/10) Case 1 $Tempo = 40 Case 2 $Tempo = 30 Case 3 $Tempo = 20 Case 4 $Tempo = 10 EndSwitch Local $Punkte = _Spiel($Tempo), $len $Punkte = Int($Punkte * (99/$Tempo)) For $i = 0 To 1000 Step 1 invertpx(Random(1, 28, 1), Random(11, 28, 1)) Next While Sleep(20) $len = StringLen($Punkte) * 5 For $i = 0 To 9 Step 1 invertpx(Random(1, 28, 1), Random(11, 28, 1)) Next _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), Int(15 - $len/2) - 1, 6, $len + 3, 6, 0, 0, 0, $BLACK) muster4x4(3,1,nr('s')) muster4x4(8,1,nr('c')) muster4x4(13,1,nr('0')) muster4x4(18,1,nr('r')) muster4x4(23,1,nr('e')) Zahl(1, 6, $Punkte) _WinAPI_StretchBlt($hDC_Gui, 0, 0, $Breite*$Zoom, $Hoehe*$Zoom, DllStructGetData($Buffer, 1, 1), 0 , 0, $Breite, $Hoehe,$COPY) $PressTmp = _IsPressed('0D') If Not $PressTmp Then $Press = False If $Press = False And $PressTmp Then ExitLoop WEnd EndFunc Func Zahl($x, $y, $a) Local $len = StringLen($a) For $i = 1 To $len Step 1 muster4x4($x + ($i-1) * 5 + ($Breite/2 - ($len*5)/2), $y, nr(StringMid($a, $i, 1))) Next EndFunc Func muster4x4($x, $y, $s) ; 4x4px Schrift Local $a $y -= 1 For $i = 1 To 4 Step 1 For $o = 1 To 4 Step 1 Switch Int(StringMid($s, $i + ($o-1)*4, 1)) Case 0 $a = 0xFF000000 Case Else $a = 0xFFFFFFFF EndSwitch DllStructSetData($sBuffer, 1, $a, $x + $i + $o * $Breite+ $y * $Breite) Next Next EndFunc Func nr($a) Switch $a Case 'a' Return '1111100111111001' Case 's' Return '1111110000111111' Case 'n' Return '1101110110111011' Case 'k' Return '1001101011101001' Case 'e' Return '1111100011101111' Case 'p' Return '1111100111111000' Case 'd' Return '1110100110011110' Case 'c' Return '1111100010001111' Case 'r' Return '1110100111101001' Case '0' Return '1111100110011111' Case '1' Return '1110001000101111' Case '2' Return '1111001111001111' Case '3' Return '1111000101111111' Case '4' Return '1000101011110010' Case '5' Return '1111110000111111' Case '6' Return '1000111110011111' Case '7' Return '1111000100110001' Case '8' Return '1111100111111111' Case '9' Return '1111100111110001' Case Else Return '1010010110100101' EndSwitch EndFunc Func px($x, $y, $col) $x += 1 Switch $col Case 0 DllStructSetData($sBuffer, 1, 0xFF000000, $x + $y*$Breite) Case 1 DllStructSetData($sBuffer, 1, 0xFFFFFFFF, $x + $y*$Breite) Case Else DllStructSetData($sBuffer, 1, 0xFFFF0000, $x + $y*$Breite) EndSwitch EndFunc Func invertpx($x, $y) $x += 1 Switch DllStructGetData($sBuffer, 1, $x + $y*$Breite) Case 0xFF000000 DllStructSetData($sBuffer, 1, 0xFFFFFFFF, $x + $y*$Breite) Case Else DllStructSetData($sBuffer, 1, 0xFF000000, $x + $y*$Breite) EndSwitch EndFunc Func getcol($x, $y) $x += 1 Return DllStructGetData($sBuffer, 1, $x + $y*$Breite) EndFunc Func _trifftSchlange($a, $Punkt) For $i = 0 To UBound($a, 1) - 1 Step 1 If $a[$i][0] = $Punkt[0] And $a[$i][1] = $Punkt[1] Then Return 1 Next EndFunc Func _Spiel($Tempo) _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 0, 0, $Breite, $Hoehe, 0, 0, 0, $BLACK) Local $Schlange[2][2] = [[Random(0, 29, 1), Random(0, 29, 1)], [0,0]] Local $Richtung = Random(0, 3,1), $RichtungReell = $Richtung ;Reelle Richtung ist das wohin sich die Schlange bewegt. Die $Richtung ist nur als Tmp Local $Punkt[2] = [Random(0, 29, 1), Random(0, 29, 1)] ; Links, Rechts, Oben, Unten Local $Frames = 0, $o Local $Punktzahl = 0 While Sleep($Tempo) $Frames += 1 If _IsPressed('25') Then $Richtung = 0 If _IsPressed('27') Then $Richtung = 1 If _IsPressed('26') Then $Richtung = 2 If _IsPressed('28') Then $Richtung = 3 If $Frames = 3 Then $Frames = 0 Switch $RichtungReell Case 0 If $Richtung <> 1 Then $RichtungReell = $Richtung Case 1 If $Richtung <> 0 Then $RichtungReell = $Richtung Case 2 If $Richtung <> 3 Then $RichtungReell = $Richtung Case 3 If $Richtung <> 2 Then $RichtungReell = $Richtung EndSwitch If $Schlange[0][0] = $Punkt[0] And $Schlange[0][1] = $Punkt[1] Then Do $Punkt[0] = Random(0, 29, 1) $Punkt[1] = Random(0, 29, 1) Until Not _trifftSchlange($Schlange, $Punkt) _GliedDazu($Schlange, -1, -1) ;Noch unausgerichtet $Punktzahl += 1 EndIf Switch $RichtungReell Case 0 $Schlange[0][0] -= 1 If $Schlange[0][0] < 0 Then $Schlange[0][0] = $Breite - 1 Case 1 $Schlange[0][0] += 1 If $Schlange[0][0] > $Breite - 1 Then $Schlange[0][0] = 0 Case 2 $Schlange[0][1] -= 1 If $Schlange[0][1] < 0 Then $Schlange[0][1] = $Hoehe-1 Case 3 $Schlange[0][1] += 1 If $Schlange[0][1] > $Hoehe-1 Then $Schlange[0][1] = 0 EndSwitch For $i = UBound($Schlange, 1) - 1 To 1 Step -1 $Schlange[$i][0] = $Schlange[$i-1][0] $Schlange[$i][1] = $Schlange[$i-1][1] If getcol($Schlange[$i][0], $Schlange[$i][1]) = 0xFFFFFFFF Then ExitLoop 2 EndIf px($Schlange[$i][0], $Schlange[$i][1], 1) Next px($Schlange[0][0], $Schlange[0][1], 2) px($Punkt[0], $Punkt[1], 2) _WinAPI_StretchBlt($hDC_Gui, 0, 0, $Breite*$Zoom, $Hoehe*$Zoom, DllStructGetData($Buffer, 1, 1), 0 , 0, $Breite, $Hoehe,$COPY) _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 0, 0, $Breite, $Hoehe, 0, 0, 0, $BLACK) EndIf WEnd _WinAPI_BitBlt(DllStructGetData($Buffer, 1, 1), 0, 0, $Breite, $Hoehe, 0, 0, 0, $BLACK) Return $Punktzahl EndFunc Func _GliedDazu(ByRef $a, $x, $y) Local $Anzahl = UBound($a, 1) ReDim $a[$Anzahl + 1][2] $a[$Anzahl][0] = $x $a[$Anzahl][1] = $y EndFunc Func _WinAPI_GetDC($hWnd) Local $aResult = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd) Return $aResult[0] EndFunc ;==>_WinAPI_GetDC Func _WinAPI_BitBlt($hDestDC, $iXDest, $iYDest, $iWidth, $iHeight, $hSrcDC, $iXSrc, $iYSrc, $iROP) DllCall("gdi32.dll", "bool", "BitBlt", "handle", $hDestDC, "int", $iXDest, "int", $iYDest, "int", $iWidth, "int", $iHeight, "handle", $hSrcDC, "int", $iXSrc, "int", $iYSrc, "dword", $iROP) EndFunc ;==>_WinAPI_BitBlt Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop) DllCall($h_GDI32_DLL, 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop) EndFunc ;==>_WinAPI_StretchBlt Func _WinAPI_CreateCompatibleDC($hDC) Local $aResult = DllCall("gdi32.dll", "handle", "CreateCompatibleDC", "handle", $hDC) Return $aResult[0] EndFunc ;==>_WinAPI_CreateCompatibleDC Func _WinAPI_DeleteDC($hDC) DllCall("gdi32.dll", "bool", "DeleteDC", "handle", $hDC) EndFunc ;==>_WinAPI_DeleteDC Func _WinAPI_DeleteObject($hObject) DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hObject) EndFunc Func _WinAPI_SelectObject($hDC, $hGDIObj) DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj) EndFunc ;==>_WinAPI_SelectObject Func _IsPressed($a) Local $b = DllCall($h_USER32_DLL, "short", "GetAsyncKeyState", "int", '0x' & $a) Return BitAND($b[0], 0x8000) <> 0 EndFunc ;==>_IsPressed Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func __Exit() _Exit() EndFunc Func _Exit() ToolTip('Blubb') _DeleteImage($Buffer) _WinAPI_DeleteDC($hDC_Gui) $sBuffer = 0 DllClose($h_GDI32_DLL) DllClose($h_USER32_DLL) Exit EndFunc Func _CreateImage($b, $h) Local $ptr, $hdc, $hbmp $hdc = _CreateNewBmp32($b, $h, $ptr, $hbmp) Local $struct = DllStructCreate('int[5]') DllStructSetData($struct, 1, $hdc, 1) DllStructSetData($struct, 1, $b, 2) DllStructSetData($struct, 1, $h, 3) DllStructSetData($struct, 1, $ptr, 4) DllStructSetData($struct, 1, $hbmp, 5) Return $struct EndFunc ;==>_CreateImage Func _DeleteImage(ByRef $struct) _WinAPI_DeleteObject(DllStructGetData($struct, 1, 5)) _WinAPI_DeleteDC(DllStructGetData($struct, 1, 1)) $struct = 0 EndFunc ;==>_DeleteImage Func _CreateNewBmp32($iWidth, $iHeight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe DC und ptr und handle auf die Bitmapdaten Local $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen Local $tBMI = DllStructCreate("dword Size;long Width;long Height;word Planes;word BitCount;dword Compression;dword SizeImage;long XPelsPerMeter;long YPelsPerMeter;dword ClrUsed;dword ClrImportant;dword RGBQuad") ;Struktur der Bitmapinfo erstellen und Daten eintragen DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette DllStructSetData($tBMI, "Width", $iWidth) DllStructSetData($tBMI, "Height", -$iHeight) ;minus =standard = bottomup DllStructSetData($tBMI, "Planes", 1) DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR Local $adib = DllCall($h_GDI32_DLL, 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0) $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC Return $hcdc ;DC der Bitmap zurückgeben EndFunc ;==>_CreateNewBmp32 Func Center($a, $b = 0) ;Gibt x/y Koords für ein Fenster damit es zentriert ist. If $b Then Return @DesktopWidth / 2 - $a / 2 ; Wenn b dann x Return @DesktopHeight / 2 - $a / 2 ; Sonst y EndFunc ;==>_C