Sign in to follow this  
Followers 0
AlmarM

Graphic Help

8 posts in this topic

Hi,

How can I make the script react when 2 graphics hit each other.

I made this example:

#include <GUIConstants.au3>
#include <Misc.au3>

Global $vDll = "user32.dll"
Global $xP1 = 10, $yP1 = 10
Global $xP2 = 30, $yP1 = 30

$GUI = GUICreate("Example", 100, 100)

$Player = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player, $GUI_GR_COLOR, 0xFF0000, 0xFF0000)
GUICtrlSetGraphic($Player, $GUI_GR_PIE, 10, 10, 10, 10, 360)
GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player, $GUI_GR_CLOSE)

$Player2 = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player2, $GUI_GR_COLOR, 0x0000FF, 0x000FF)
GUICtrlSetGraphic($Player2, $GUI_GR_PIE, 30, 30, 10, 10, 360)
GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player2, $GUI_GR_CLOSE)

GUISetBkColor(0x000000)
GUISetState()
While 1
    Sleep(20)
    GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
    If GUIGetMsg() = -3 Then Exit
        
    If _IsPressed(25, $vDll) Then ; Left
        $xP1 -= 4
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(26, $vDll) Then ; Up
        $yP1 -= 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(27, $vDll) Then ; Right
        $xP1 += 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(28, $vDll) Then ; Down
        $yP1 += 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
WEnd

When you use the Arrow keys and your Red ball hits the Blue ball the script should do something.

But how can I build this into my script?

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.

Share this post


Link to post
Share on other sites



u can see if the coordinates of the graphics are same, as in when the two touch.. when that happens.. do something

say.. like if x,y of blue comes in +50 pixels range of x,y of red.. wham.. do something


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

u can see if the coordinates of the graphics are same, as in when the two touch.. when that happens.. do something

say.. like if x,y of blue comes in +50 pixels range of x,y of red.. wham.. do something

Ye, already tried something liek that, but I think im doing something wrong.

#include <GUIConstants.au3>
#include <Misc.au3>

Global $vDll = "user32.dll"
Global $xP1 = 10, $yP1 = 10
Global $xP2 = 30, $yP2 = 30

$GUI = GUICreate("Example", 100, 100)

$Player = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player, $GUI_GR_COLOR, 0xFF0000, 0xFF0000)
GUICtrlSetGraphic($Player, $GUI_GR_PIE, 10, 10, 10, 10, 360)
GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player, $GUI_GR_CLOSE)

$Player2 = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player2, $GUI_GR_COLOR, 0x0000FF, 0x000FF)
GUICtrlSetGraphic($Player2, $GUI_GR_PIE, 30, 30, 10, 10, 360)
GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player2, $GUI_GR_CLOSE)

GUISetBkColor(0x000000)
GUISetState()
While 1
    Sleep(20)
    GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
    If GUIGetMsg() = -3 Then Exit
        
    If _IsPressed(25, $vDll) Then ; Left
        $xP1 -= 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(26, $vDll) Then ; Up
        $yP1 -= 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(27, $vDll) Then ; Right
        $xP1 += 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(28, $vDll) Then ; Down
        $yP1 += 3
        GUICtrlSetPos($Player, $xP1, $yP1)
    EndIf
    
    If _IsPressed(01, $vDll) Then
        $yP2 += 3
        GUICtrlSetPos($Player2, $xP2, $yP2)
    EndIf
    
    If $xP1 = $xP2 + 10 And $yP1 = $yP2 + 10 Then
        MsgBox(0, "", "")
    EndIf
WEnd

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.

Share this post


Link to post
Share on other sites

if $xp1>$xP2-10 and $xP1<$xP2+10 then do something..

same for y co-ord..

we just want to accomplish a band of pixels within which we do something.. hope u get it


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

Ah, got it! Thanks :)

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.

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include <Misc.au3>

HotKeySet('{LEFT}', '_Left')
HotKeySet('{UP}', '_Up')
HotKeySet('{RIGHT}', '_Right')
HotKeySet('{DOWN}', '_Down')

Global $xP1 = 10, $yP1 = 10
Global $xP2 = 30, $yP2 = 30
Global $hUser32 = DllOpen('user32.dll')

$GUI = GUICreate("Example", 100, 100)

$Player = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player, $GUI_GR_COLOR, 0xFF0000, 0xFF0000)
GUICtrlSetGraphic($Player, $GUI_GR_PIE, 10, 10, 10, 10, 360)
GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player, $GUI_GR_CLOSE)

$Player2 = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player2, $GUI_GR_COLOR, 0x0000FF, 0x000FF)
GUICtrlSetGraphic($Player2, $GUI_GR_PIE, 30, 30, 10, 10, 360)
GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player2, $GUI_GR_CLOSE)

GUISetBkColor(0x000000)
GUISetState()
While 1
    GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
    
    If GUIGetMsg() = -3 Then ExitLoop
   
    If _IsPressed(01, $hUser32) And WinActive($GUI) Then
        $yP2 += 2
        GUICtrlSetPos($Player2, $xP2, $yP2)
    EndIf
   
    If $xP1 = $xP2 And $yP1 = $yP2 Then
        ToolTip('Text', 0, 0)
    EndIf
WEnd

DllClose($hUser32)
GUIDelete($GUI)
Exit


Func _Left()
    If Not WinActive($GUI) Then
        HotKeySet('{LEFT}')
        Send('{LEFT}')
        HotKeySet('{LEFT}', '_Left')
        Return
    EndIf
    
    $xP1 -= 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Up()
    If Not WinActive($GUI) Then
        HotKeySet('{UP}')
        Send('{UP}')
        HotKeySet('{UP}', '_Up')
        Return
    EndIf
    
    $yP1 -= 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Right()
    If Not WinActive($GUI) Then
        HotKeySet('{RIGHT}')
        Send('{RIGHT}')
        HotKeySet('{RIGHT}', '_Right')
        Return
    EndIf
    
    $xP1 += 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Down()
    If Not WinActive($GUI) Then
        HotKeySet('{DOWN}')
        Send('{DOWN}')
        HotKeySet('{DOWN}', '_Down')
        Return
    EndIf
    
    $yP1 += 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

lol, I couldn't stand still watching this script invoking the key state over and over... ;]

Share this post


Link to post
Share on other sites

works like a beauty..

#include <GUIConstants.au3>
#include <Misc.au3>

HotKeySet('{LEFT}', '_Left')
HotKeySet('{UP}', '_Up')
HotKeySet('{RIGHT}', '_Right')
HotKeySet('{DOWN}', '_Down')

Global $xP1 = 10, $yP1 = 10
Global $xP2 = 30, $yP2 = 30
Global $hUser32 = DllOpen('user32.dll')

$GUI = GUICreate("Example", 100, 100)

$Player = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player, $GUI_GR_COLOR, 0xFF0000, 0xFF0000)
GUICtrlSetGraphic($Player, $GUI_GR_PIE, 10, 10, 10, 10, 360)
GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player, $GUI_GR_CLOSE)

$Player2 = GUICtrlCreateGraphic(10, 10, 10, 10)
GUICtrlSetGraphic($Player2, $GUI_GR_COLOR, 0x0000FF, 0x000FF)
GUICtrlSetGraphic($Player2, $GUI_GR_PIE, 30, 30, 10, 10, 360)
GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Player2, $GUI_GR_CLOSE)

GUISetBkColor(0x000000)
GUISetState()
While 1
    GUICtrlSetGraphic($Player, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($Player2, $GUI_GR_REFRESH)
    
    If GUIGetMsg() = -3 Then ExitLoop
   
    If _IsPressed(01, $hUser32) And WinActive($GUI) Then
        $yP2 += 2
        GUICtrlSetPos($Player2, $xP2, $yP2)
    EndIf
   
    If $xP1>($xP2-10) And $xP1<($xP2+10) Then
        SplashTextOn("","hit")
        SplashOff()
    EndIf
    
    If $yP1>($yP2-10) And $yP1<($yP2+10) Then
        SplashTextOn("","hit")
    ;sleep(2000)
    EndIf
    SplashOff()
WEnd

DllClose($hUser32)
GUIDelete($GUI)
Exit


Func _Left()
    If Not WinActive($GUI) Then
        HotKeySet('{LEFT}')
        Send('{LEFT}')
        HotKeySet('{LEFT}', '_Left')
        Return
    EndIf
    
    $xP1 -= 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Up()
    If Not WinActive($GUI) Then
        HotKeySet('{UP}')
        Send('{UP}')
        HotKeySet('{UP}', '_Up')
        Return
    EndIf
    
    $yP1 -= 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Right()
    If Not WinActive($GUI) Then
        HotKeySet('{RIGHT}')
        Send('{RIGHT}')
        HotKeySet('{RIGHT}', '_Right')
        Return
    EndIf
    
    $xP1 += 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

Func _Down()
    If Not WinActive($GUI) Then
        HotKeySet('{DOWN}')
        Send('{DOWN}')
        HotKeySet('{DOWN}', '_Down')
        Return
    EndIf
    
    $yP1 += 2
    GUICtrlSetPos($Player, $xP1, $yP1)
EndFunc

But use something else in place of splashtexton()


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

Hmmm, the above code is pretty buggy for me. Collision detection activates even when they're far apart.

This is a little example of how I did some thing similar recently:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $iGraphCount = 0
Global $iMoveUnit = 4

HotKeySet("{UP}","_KeyPressed")
HotKeySet("{DOWN}","_KeyPressed")
HotKeySet("{LEFT}","_KeyPressed")
HotKeySet("{RIGHT}","_KeyPressed")

GUICreate("",600,600,Default,Default,Default,0x2000000)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Close")

$hGraphic = GUICtrlCreateGraphic(0,0,600,600)
GUICtrlSetBkColor(-1,0xFFFFFF)

$iRad = 40
Global $aPos[5] = ["",40,40,200,200]
GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[1],$aPos[2],$iRad*2,$iRad*2)
GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[3],$aPos[4],$iRad*2,$iRad*2)


GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd

Func _KeyPressed()
    
    Switch @HotKeyPressed
        Case "{UP}"
            $aPos[2] -= $iMoveUnit
        Case "{DOWN}"
            $aPos[2] += $iMoveUnit
        Case "{LEFT}"
            $aPos[1] -= $iMoveUnit
        Case "{RIGHT}"
            $aPos[1] += $iMoveUnit
    EndSwitch
    
    _Clear()
    
    If Sqrt((($aPos[3] - $aPos[1])^2) + (($aPos[4] - $aPos[2])^2)) < ($iRad * 2) - 1 Then
        Switch @HotKeyPressed
            Case "{UP}"
                $aPos[4] -= 1
            Case "{DOWN}"
                $aPos[4] += 1
            Case "{LEFT}"
                $aPos[3] -= 1
            Case "{RIGHT}"
                $aPos[3] += 1
        EndSwitch
    
        If $aPos[2] < $aPos[4] Then $aPos[4] += 1 * (($aPos[4] - $aPos[2]) / $iRad*2)
        If $aPos[2] > $aPos[4] Then $aPos[4] -= 1 * (($aPos[2] - $aPos[4]) / $iRad*2)
        If $aPos[1] < $aPos[3] Then $aPos[3] += 1 * (($aPos[3] - $aPos[1]) / $iRad*2)
        If $aPos[1] > $aPos[3] Then $aPos[3] -= 1 * (($aPos[1] - $aPos[3]) / $iRad*2)
    EndIf

    GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[1],$aPos[2],$iRad*2,$iRad*2)
    GUICtrlSetGraphic($hGraphic,$GUI_GR_ELLIPSE,$aPos[3],$aPos[4],$iRad*2,$iRad*2)
    
    GUICtrlSetGraphic($hGraphic,$GUI_GR_REFRESH)
    
EndFunc


Func _Clear()

    $iGraphCount += 1
    
    GUICtrlSetGraphic($hGraphic,$GUI_GR_COLOR,0xFFFFFF,0xFFFFFF)
    GUICtrlSetGraphic($hGraphic,$GUI_GR_RECT,0,0,600,600)
    GUICtrlSetGraphic($hGraphic,$GUI_GR_COLOR,0x000000,$GUI_GR_NOBKCOLOR)
    
    If $iGraphCount > 100 Then
        GUISetState(@SW_LOCK)
        GUICtrlDelete($hGraphic)
        $hGraphic = GUICtrlCreateGraphic(0,0,600,600)
        GUICtrlSetBkColor(-1,0xFFFFFF)
        GUISetState(@SW_UNLOCK)
        $iGraphCount = 0
    EndIf
    
EndFunc


Func _Close()
    Exit
EndFunc

Hope it helps


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
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
Sign in to follow this  
Followers 0