Jump to content

_GDIPlus question


Recommended Posts

Okay, so I want to make this script do the function new1, 2, or 3 every time either one of the "players" hit a line alredy created. How can I make it check if it tries to create a new line where there alredy is a line?

HotKeySet("{ESC}", "Terminate")
HotKeySet("{DOWN}", "Down")
HotKeySet("{RIGHT}", "Right")
HotKeySet("{LEFT}", "Left")
HotKeySet("{UP}", "Up")
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hurtighet=5
$P1=0
$P2=0
$P3=0
Local $hGUI, $iARGB, $nWidth
#region meg
$startx=Random(1, @DesktopWidth, 1)
$starty=Random(1, @DesktopHeight, 1)
$iA=$startx-1
$iB=$starty-1
$iC=$startx
$iD=$starty
$last="vannrett"
$way="right"
#endregion
#region Random2
$startx=Random(1, @DesktopWidth, 1)
$starty=Random(1, @DesktopHeight, 1)
$iA2=$startx-1
$iB2=$starty-1
$iC2=$startx
$iD2=$starty
$last2="vannrett"
$count=0
$r=1
$time=0
#endregion
#region Random3
$startx3=Random(1, @DesktopWidth, 1)
$starty3=Random(1, @DesktopHeight, 1)
$iA3=$startx3-1
$iB3=$starty3-1
$iC3=$startx3
$iD3=$starty3
$last3="vannrett"
$count3=0
$r3=1
$time3=0
#endregion
#region Gui+Graphics
$hGUI=GUICreate("", @DesktopWidth, @DesktopHeight,  0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
_GDIPlus_Startup()
$hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$hPen = _GDIPlus_PenCreate(0x990000FF)
$hPen2 = _GDIPlus_PenCreate(0x9900FF00)
$hPen3 = _GDIPlus_PenCreate(0x99FF0000)
_GDIPlus_GraphicsDrawLine($hGraphic, $iA, $iB, $iC, $iD, $hPen)
#endregion
While 1
#region Utenfor
If $iA> @DesktopWidth Or $iA < 0 or $iB < 0 Or $iB > @DesktopHeight Then
new1()
EndIf
If $iA2> @DesktopWidth Or $iA2 < 0 or $iB2 < 0 Or $iB2 > @DesktopHeight Then
new2()
EndIf
If $iA3> @DesktopWidth Or $iA3 < 0 or $iB3 < 0 Or $iB3 > @DesktopHeight Then
new3()
EndIf
#endregion
#region Random2
If $count>$time Then
  $time=Random(50, 1500)
  If $last2="loddrett" Then
   $r=Random(1, 2, 1)
  EndIf
  If $last2="vannrett" Then
   $r=Random(3, 4, 1)
  EndIf
  $count=0
EndIf
If $r=1 Then
  $iB2+=1/$hurtighet
  $iD2+=1/$hurtighet
  $last2="vannrett"
EndIf
If $r=3 Then
  $iA2+=1/$hurtighet
  $iC2+=1/$hurtighet
  $last2="loddrett"
EndIf
If $r=4 Then
  $iA2-=1/$hurtighet
  $iC2-=1/$hurtighet
  $last2="loddrett"
EndIf
If $r=2 Then
  $iB2-=1/$hurtighet
  $iD2-=1/$hurtighet
  $last2="vannrett"
EndIf
$count+=1
#endregion
#region Random3
If $count3>$time3 Then
  $time3=Random(50, 1500)
  If $last3="loddrett" Then
   $r3=Random(1, 2, 1)
  EndIf
  If $last3="vannrett" Then
   $r3=Random(3, 4, 1)
  EndIf
  $count3=0
EndIf
If $r3=1 Then
  $iB3+=1/$hurtighet
  $iD3+=1/$hurtighet
  $last3="vannrett"
EndIf
If $r3=3 Then
  $iA3+=1/$hurtighet
  $iC3+=1/$hurtighet
  $last3="loddrett"
EndIf
If $r3=4 Then
  $iA3-=1/$hurtighet
  $iC3-=1/$hurtighet
  $last3="loddrett"
EndIf
If $r3=2 Then
  $iB3-=1/$hurtighet
  $iD3-=1/$hurtighet
  $last3="vannrett"
EndIf
$count3+=1
#endregion
#region Meg
If $way="down" then
  $iB+=1/$hurtighet
  $iD+=1/$hurtighet
EndIf
If $way="right" then
  $iA+=1/$hurtighet
  $iC+=1/$hurtighet
EndIf
If $way="left" then
  $iA-=1/$hurtighet
  $iC-=1/$hurtighet
EndIf
If $way="up" then
  $iB-=1/$hurtighet
  $iD-=1/$hurtighet
EndIf
#endregion
#region DrawLine
_GDIPlus_GraphicsDrawLine($hGraphic, $iA, $iB, $iC, $iD, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $iA2, $iB2, $iC2, $iD2, $hPen2)
_GDIPlus_GraphicsDrawLine($hGraphic, $iA3, $iB3, $iC3, $iD3, $hPen3)
#endregion
WEnd
#region Meg
Func Down()
If $last="vannrett" Then
  $way="down"
  $last="loddrett"
EndIf
EndFunc
Func Right()
If $last="loddrett" Then
  $way="right"
  $last="vannrett"
EndIf
EndFunc
Func Left()
If $last="loddrett" Then
  $way="left"
  $last="vannrett"
EndIf
EndFunc
Func Up()
If $last="vannrett" Then
  $way="up"
  $last="loddrett"
EndIf
EndFunc
#endregion
Func new1()
$startx=Random(1, @DesktopWidth, 1)
$starty=Random(1, @DesktopHeight, 1)
$iA=$startx-1
$iB=$starty-1
$iC=$startx
$iD=$starty
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$P1+=1
EndFunc
Func new2()
$startx=Random(1, @DesktopWidth, 1)
$starty=Random(1, @DesktopHeight, 1)
$iA2=$startx-1
$iB2=$starty-1
$iC2=$startx
$iD2=$starty
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$P2+=1
EndFunc
Func new3()
$startx3=Random(1, @DesktopWidth, 1)
$starty3=Random(1, @DesktopHeight, 1)
$iA3=$startx3-1
$iB3=$starty3-1
$iC3=$startx3
$iD3=$starty3
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
$P3+=1
EndFunc
Func Terminate()
GUISetState(@SW_HIDE)
MsgBox(0, "Score:", "The score was:" & @CRLF & "Player 1: " & $P1 & " faults." & @CRLF & "Player 2: " & $P2 & " faults." & @CRLF & "Player 3: " & $P3 & " faults.")
Exit
EndFunc
Link to comment
Share on other sites

Try this here:

HotKeySet("{ESC}", "Terminate")
HotKeySet("{DOWN}", "Down")
HotKeySet("{RIGHT}", "Right")
HotKeySet("{LEFT}", "Left")
HotKeySet("{UP}", "Up")

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
$hurtighet = 1
$P1 = 0
$P2 = 0
$P3 = 0
Global $hGUI
#region meg
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA = $startx
$iB = $starty
$last = "vannrett"
$way = "right"
#endregion meg
#region Random2
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA2 = $startx
$iB2 = $starty
$last2 = "vannrett"
$count = 0
$r = 1
$time = 0
#endregion Random2
#region Random3
$startx3 = Random(1, $iWidth, 1)
$starty3 = Random(1, $iHeight, 1)
$iA3 = $startx3
$iB3 = $starty3
$last3 = "vannrett"
$count3 = 0
$r3 = 1
$time3 = 0
#endregion Random3
#region Gui+Graphics
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)

$hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
$hBrush2 = _GDIPlus_BrushCreateSolid(0xFF00FF00)
$hBrush3 = _GDIPlus_BrushCreateSolid(0xFFFF0000)

$hNTDll = DllOpen("ntdll.dll")
$hStruct = DllStructCreate("int64 time;")
$iMicroSeconds = 5000

#endregion Gui+Graphics
While 1
    DllStructSetData($hStruct,"time", -1 * ($iMicroSeconds * 10))
    DllCall($hNTDll,"dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))

    #region Utenfor
    If $iA > $iWidth Or $iA < 0 Or $iB < 0 Or $iB > $iHeight Then
        new1()
    EndIf
    If $iA2 > $iWidth Or $iA2 < 0 Or $iB2 < 0 Or $iB2 > $iHeight Then
        new2()
    EndIf
    If $iA3 > $iWidth Or $iA3 < 0 Or $iB3 < 0 Or $iB3 > $iHeight Then
        new3()
    EndIf
    #endregion Utenfor
    #region Random2
    If $count > $time Then
        $time = Random(50, 1500)
        If $last2 = "loddrett" Then
            $r = Random(1, 2, 1)
        EndIf
        If $last2 = "vannrett" Then
            $r = Random(3, 4, 1)
        EndIf
        $count = 0
    EndIf
    Switch $r
        Case 1
            $iB2 += 1
            $last2 = "vannrett"
        Case 3
            $iA2 += 1
            $last2 = "loddrett"
        Case 4
            $iA2 -= 1
            $last2 = "loddrett"
        Case 2
            $iB2 -= 1
            $last2 = "vannrett"
    EndSwitch
    $count += 1
    #endregion Random2
    #region Random3
    If $count3 > $time3 Then
        $time3 = Random(50, 1500)
        If $last3 = "loddrett" Then
            $r3 = Random(1, 2, 1)
        EndIf
        If $last3 = "vannrett" Then
            $r3 = Random(3, 4, 1)
        EndIf
        $count3 = 0
    EndIf
    Switch $r3
        Case 1
            $iB3 += 1
            $last3 = "vannrett"
        Case 3
            $iA3 += 1
            $last3 = "loddrett"
        Case 4
            $iA3 -= 1
            $last3 = "loddrett"
        Case 2
            $iB3 -= 1
            $last3 = "vannrett"
    EndSwitch
    $count3 += 1
    #endregion Random3
    #region Meg
    Switch $way
        Case "down"
            $iB += 1
        Case "right"
            $iA += 1
        Case "left"
            $iA -= 1
        Case $way = "up"
            $iB -= 1
    EndSwitch
    #endregion Meg
    #region DrawLine
    If Collides($hBitmap, $iA, $iB) Then
        MsgBox(262144, "Collision", "Collision detected (blue)")
        new1()
    EndIf
    If Collides($hBitmap, $iA2, $iB2) Then
        MsgBox(262144, "Collision", "Collision detected (green)")
        new2()
    EndIf
    If Collides($hBitmap, $iA3, $iB3) Then
        MsgBox(262144, "Collision", "Collision detected (red)")
        new3()
    EndIf
    _GDIPlus_GraphicsFillRect($hGraphic, $iA, $iB, 1, 1, $hBrush)
    _GDIPlus_GraphicsFillRect($hContext, $iA, $iB, 1, 1, $hBrush)
    _GDIPlus_GraphicsFillRect($hGraphic, $iA2, $iB2, 1, 1, $hBrush2)
    _GDIPlus_GraphicsFillRect($hContext, $iA2, $iB2, 1, 1, $hBrush2)
    _GDIPlus_GraphicsFillRect($hGraphic, $iA3, $iB3, 1, 1, $hBrush3)
    _GDIPlus_GraphicsFillRect($hContext, $iA3, $iB3, 1, 1, $hBrush3)
    #endregion DrawLine
WEnd

Func Collides($hBitmap, $iX, $iY, $iBgColor = 0xFFFFFFFF)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)
    If Hex($aResult[4], 8) = Hex($iBgColor, 8) Then Return False
    Return True
EndFunc

#region Meg
Func Down()
    If $last = "vannrett" Then
        $way = "down"
        $last = "loddrett"
    EndIf
EndFunc   ;==>Down

Func Right()
    If $last = "loddrett" Then
        $way = "right"
        $last = "vannrett"
    EndIf
EndFunc   ;==>Right

Func Left()
    If $last = "loddrett" Then
        $way = "left"
        $last = "vannrett"
    EndIf
EndFunc   ;==>Left

Func Up()
    If $last = "vannrett" Then
        $way = "up"
        $last = "loddrett"
    EndIf
EndFunc   ;==>Up
#endregion Meg
Func new1()
    $startx = Random(1, $iWidth, 1)
    $starty = Random(1, $iHeight, 1)
    $iA = $startx
    $iB = $starty
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P1 += 1
EndFunc   ;==>new1
Func new2()
    $startx = Random(1, $iWidth, 1)
    $starty = Random(1, $iHeight, 1)
    $iA2 = $startx
    $iB2 = $starty
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P2 += 1
EndFunc   ;==>new2
Func new3()
    $startx3 = Random(1, $iWidth, 1)
    $starty3 = Random(1, $iHeight, 1)
    $iA3 = $startx3
    $iB3 = $starty3
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P3 += 1
EndFunc   ;==>new3
Func Terminate()
    DllClose($hNTDll)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete()
    MsgBox(0, "Score:", "The score was:" & @CRLF & "Player 1: " & $P1 & " faults." & @CRLF & "Player 2: " & $P2 & " faults." & @CRLF & "Player 3: " & $P3 & " faults.")
    Exit
EndFunc   ;==>Terminate

I didn't change too much in the code...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try this here:

HotKeySet("{ESC}", "Terminate")
HotKeySet("{DOWN}", "Down")
HotKeySet("{RIGHT}", "Right")
HotKeySet("{LEFT}", "Left")
HotKeySet("{UP}", "Up")

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight
$hurtighet = 1
$P1 = 0
$P2 = 0
$P3 = 0
Global $hGUI
#region meg
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA = $startx
$iB = $starty
$last = "vannrett"
$way = "right"
#endregion meg
#region Random2
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA2 = $startx
$iB2 = $starty
$last2 = "vannrett"
$count = 0
$r = 1
$time = 0
#endregion Random2
#region Random3
$startx3 = Random(1, $iWidth, 1)
$starty3 = Random(1, $iHeight, 1)
$iA3 = $startx3
$iB3 = $starty3
$last3 = "vannrett"
$count3 = 0
$r3 = 1
$time3 = 0
#endregion Random3
#region Gui+Graphics
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)

$hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
$hBrush2 = _GDIPlus_BrushCreateSolid(0xFF00FF00)
$hBrush3 = _GDIPlus_BrushCreateSolid(0xFFFF0000)

$hNTDll = DllOpen("ntdll.dll")
$hStruct = DllStructCreate("int64 time;")
$iMicroSeconds = 5000

#endregion Gui+Graphics
While 1
DllStructSetData($hStruct,"time", -1 * ($iMicroSeconds * 10))
DllCall($hNTDll,"dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))

#region Utenfor
If $iA > $iWidth Or $iA < 0 Or $iB < 0 Or $iB > $iHeight Then
new1()
EndIf
If $iA2 > $iWidth Or $iA2 < 0 Or $iB2 < 0 Or $iB2 > $iHeight Then
new2()
EndIf
If $iA3 > $iWidth Or $iA3 < 0 Or $iB3 < 0 Or $iB3 > $iHeight Then
new3()
EndIf
#endregion Utenfor
#region Random2
If $count > $time Then
$time = Random(50, 1500)
If $last2 = "loddrett" Then
$r = Random(1, 2, 1)
EndIf
If $last2 = "vannrett" Then
$r = Random(3, 4, 1)
EndIf
$count = 0
EndIf
Switch $r
Case 1
$iB2 += 1
$last2 = "vannrett"
Case 3
$iA2 += 1
$last2 = "loddrett"
Case 4
$iA2 -= 1
$last2 = "loddrett"
Case 2
$iB2 -= 1
$last2 = "vannrett"
EndSwitch
$count += 1
#endregion Random2
#region Random3
If $count3 > $time3 Then
$time3 = Random(50, 1500)
If $last3 = "loddrett" Then
$r3 = Random(1, 2, 1)
EndIf
If $last3 = "vannrett" Then
$r3 = Random(3, 4, 1)
EndIf
$count3 = 0
EndIf
Switch $r3
Case 1
$iB3 += 1
$last3 = "vannrett"
Case 3
$iA3 += 1
$last3 = "loddrett"
Case 4
$iA3 -= 1
$last3 = "loddrett"
Case 2
$iB3 -= 1
$last3 = "vannrett"
EndSwitch
$count3 += 1
#endregion Random3
#region Meg
Switch $way
Case "down"
$iB += 1
Case "right"
$iA += 1
Case "left"
$iA -= 1
Case $way = "up"
$iB -= 1
EndSwitch
#endregion Meg
#region DrawLine
If Collides($hBitmap, $iA, $iB) Then
MsgBox(262144, "Collision", "Collision detected (blue)")
new1()
EndIf
If Collides($hBitmap, $iA2, $iB2) Then
MsgBox(262144, "Collision", "Collision detected (green)")
new2()
EndIf
If Collides($hBitmap, $iA3, $iB3) Then
MsgBox(262144, "Collision", "Collision detected (red)")
new3()
EndIf
_GDIPlus_GraphicsFillRect($hGraphic, $iA, $iB, 1, 1, $hBrush)
_GDIPlus_GraphicsFillRect($hContext, $iA, $iB, 1, 1, $hBrush)
_GDIPlus_GraphicsFillRect($hGraphic, $iA2, $iB2, 1, 1, $hBrush2)
_GDIPlus_GraphicsFillRect($hContext, $iA2, $iB2, 1, 1, $hBrush2)
_GDIPlus_GraphicsFillRect($hGraphic, $iA3, $iB3, 1, 1, $hBrush3)
_GDIPlus_GraphicsFillRect($hContext, $iA3, $iB3, 1, 1, $hBrush3)
#endregion DrawLine
WEnd

Func Collides($hBitmap, $iX, $iY, $iBgColor = 0xFFFFFFFF)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)
If Hex($aResult[4], 8) = Hex($iBgColor, 8) Then Return False
Return True
EndFunc

#region Meg
Func Down()
If $last = "vannrett" Then
$way = "down"
$last = "loddrett"
EndIf
EndFunc ;==>Down

Func Right()
If $last = "loddrett" Then
$way = "right"
$last = "vannrett"
EndIf
EndFunc ;==>Right

Func Left()
If $last = "loddrett" Then
$way = "left"
$last = "vannrett"
EndIf
EndFunc ;==>Left

Func Up()
If $last = "vannrett" Then
$way = "up"
$last = "loddrett"
EndIf
EndFunc ;==>Up
#endregion Meg
Func new1()
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA = $startx
$iB = $starty
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
$P1 += 1
EndFunc ;==>new1
Func new2()
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA2 = $startx
$iB2 = $starty
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
$P2 += 1
EndFunc ;==>new2
Func new3()
$startx3 = Random(1, $iWidth, 1)
$starty3 = Random(1, $iHeight, 1)
$iA3 = $startx3
$iB3 = $starty3
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
$P3 += 1
EndFunc ;==>new3
Func Terminate()
    DllClose($hNTDll)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete()
MsgBox(0, "Score:", "The score was:" & @CRLF & "Player 1: " & $P1 & " faults." & @CRLF & "Player 2: " & $P2 & " faults." & @CRLF & "Player 3: " & $P3 & " faults.")
Exit
EndFunc ;==>Terminate

I didn't change too much in the code...

Br,

UEZ

Thanks a lot! :)

Any way I can make the brushsize a bit bigger?

Link to comment
Share on other sites

Yes but the collision check needs to be adjusted appropriately.

Next try:

HotKeySet("{ESC}", "Terminate")
HotKeySet("{DOWN}", "Down")
HotKeySet("{RIGHT}", "Right")
HotKeySet("{LEFT}", "Left")
HotKeySet("{UP}", "Up")

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$iWidth = @DesktopWidth
$iHeight = @DesktopHeight

$P1 = 0
$P2 = 0
$P3 = 0
Global $hGUI
#region meg
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA = $startx
$iB = $starty
$last = "vannrett"
$way = "right"
#endregion meg
#region Random2
$startx = Random(1, $iWidth, 1)
$starty = Random(1, $iHeight, 1)
$iA2 = $startx
$iB2 = $starty
$last2 = "vannrett"
$count = 0
$r = 1
$time = 0
#endregion Random2
#region Random3
$startx3 = Random(1, $iWidth, 1)
$starty3 = Random(1, $iHeight, 1)
$iA3 = $startx3
$iB3 = $starty3
$last3 = "vannrett"
$count3 = 0
$r3 = 1
$time3 = 0
#endregion Random3
#region Gui+Graphics
$hGUI = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)

$hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
$hBrush2 = _GDIPlus_BrushCreateSolid(0xFF00FF00)
$hBrush3 = _GDIPlus_BrushCreateSolid(0xFFFF0000)

$hNTDll = DllOpen("ntdll.dll")
$tStruct = DllStructCreate("int64 time;")
$pStruct = DllStructGetPtr($tStruct)
$iMicroSeconds = 10000
$iBrushSize = 2
#endregion Gui+Graphics
While 1
    DllStructSetData($tStruct, "time", -1 * ($iMicroSeconds * 10 * $iBrushSize / 2))
    DllCall($hNTDll,"dword", "ZwDelayExecution", "int", 0, "ptr", $pStruct)

    #region Random2
    If $count > $time Then
        $time = Random(50, 1500)
        If $last2 = "loddrett" Then
            $r = Random(1, 2, 1)
        EndIf
        If $last2 = "vannrett" Then
            $r = Random(3, 4, 1)
        EndIf
        $count = 0
    EndIf
    Switch $r
        Case 1
            $iB2 += $iBrushSize
            $last2 = "vannrett"
        Case 3
            $iA2 += $iBrushSize
            $last2 = "loddrett"
        Case 4
            $iA2 -= $iBrushSize
            $last2 = "loddrett"
        Case 2
            $iB2 -= $iBrushSize
            $last2 = "vannrett"
    EndSwitch
    $count += 1
    #endregion Random2
    #region Random3
    If $count3 > $time3 Then
        $time3 = Random(50, 1500)
        If $last3 = "loddrett" Then
            $r3 = Random(1, 2, 1)
        EndIf
        If $last3 = "vannrett" Then
            $r3 = Random(3, 4, 1)
        EndIf
        $count3 = 0
    EndIf
    Switch $r3
        Case 1
            $iB3 += $iBrushSize
            $last3 = "vannrett"
        Case 3
            $iA3 += $iBrushSize
            $last3 = "loddrett"
        Case 4
            $iA3 -= $iBrushSize
            $last3 = "loddrett"
        Case 2
            $iB3 -= $iBrushSize
            $last3 = "vannrett"
    EndSwitch
    $count3 += 1
    #endregion Random3
    #region Meg
    Switch $way
        Case "down"
            $iB += $iBrushSize
        Case "right"
            $iA += $iBrushSize
        Case "left"
            $iA -= $iBrushSize
        Case $way = "up"
            $iB -= $iBrushSize
    EndSwitch
    #endregion Meg
    #region DrawLine
    $iCol = 0
    If Collides($hBitmap, $iA, $iB) Then $iCol = 1
    If Collides($hBitmap, $iA2, $iB2) Then $iCol = 2
    If Collides($hBitmap, $iA3, $iB3) Then $iCol = 3
    _GDIPlus_GraphicsFillRect($hGraphic, $iA, $iB, $iBrushSize, $iBrushSize, $hBrush)
    _GDIPlus_GraphicsFillRect($hContext, $iA, $iB, $iBrushSize, $iBrushSize, $hBrush)
    _GDIPlus_GraphicsFillRect($hGraphic, $iA2, $iB2, $iBrushSize, $iBrushSize, $hBrush2)
    _GDIPlus_GraphicsFillRect($hContext, $iA2, $iB2, $iBrushSize, $iBrushSize, $hBrush2)
    _GDIPlus_GraphicsFillRect($hGraphic, $iA3, $iB3, $iBrushSize, $iBrushSize, $hBrush3)
    _GDIPlus_GraphicsFillRect($hContext, $iA3, $iB3, $iBrushSize, $iBrushSize, $hBrush3)
    Switch $iCol
        Case 1
            MsgBox(262144, "Collision", "Collision detected (blue)")
            new1()
        Case 2
            MsgBox(262144, "Collision", "Collision detected (green)")
            new2()
        Case 3
            MsgBox(262144, "Collision", "Collision detected (red)")
            new3()
    EndSwitch
    #endregion DrawLine
WEnd

Func Collides($hBitmap, $iX, $iY, $iBgColor = 0xFFFFFFFF)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)
    If Hex($aResult[4], 8) = Hex($iBgColor, 8) Then Return False
    Return True
EndFunc

#region Meg
Func Down()
    If $last = "vannrett" Then
        $way = "down"
        $last = "loddrett"
    EndIf
EndFunc   ;==>Down

Func Right()
    If $last = "loddrett" Then
        $way = "right"
        $last = "vannrett"
    EndIf
EndFunc   ;==>Right

Func Left()
    If $last = "loddrett" Then
        $way = "left"
        $last = "vannrett"
    EndIf
EndFunc   ;==>Left

Func Up()
    If $last = "vannrett" Then
        $way = "up"
        $last = "loddrett"
    EndIf
EndFunc   ;==>Up
#endregion Meg

Func new1()
    $startx = Random(1, $iWidth, 1)
    $starty = Random(1, $iHeight, 1)
    $iA = $startx
    $iB = $starty
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P1 += 1
EndFunc   ;==>new1

Func new2()
    $startx = Random(1, $iWidth, 1)
    $starty = Random(1, $iHeight, 1)
    $iA2 = $startx
    $iB2 = $starty
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P2 += 1
EndFunc   ;==>new2

Func new3()
    $startx3 = Random(1, $iWidth, 1)
    $starty3 = Random(1, $iHeight, 1)
    $iA3 = $startx3
    $iB3 = $starty3
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)
    $P3 += 1
EndFunc   ;==>new3

Func Terminate()
    DllClose($hNTDll)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_BrushDispose($hBrush3)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete()
    MsgBox(0, "Score:", "The score was:" & @CRLF & "Player 1: " & $P1 & " faults." & @CRLF & "Player 2: " & $P2 & " faults." & @CRLF & "Player 3: " & $P3 & " faults.")
    Exit
EndFunc   ;==>Terminate

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...