Что нового

Столкновение 2 объектов

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
К примеру у меня есть код:

Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{UP}", "UP")
HotKeySet("{Down}", "Down")
HotKeySet("{Left}", "Left")
HotKeySet("{Right}", "Right")

$Form1 = GUICreate("Form1", 422, 335, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 72, 128, 73, 65, BitOR($BS_FLAT,$WS_GROUP))
$Button2 = GUICtrlCreateButton("Button2", 232, 80, 73, 65, BitOR($BS_FLAT,$WS_GROUP))
GUISetState(@SW_SHOW)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd

Func Up()
	$B1pos = ControlGetPos($Form1,"",$Button1)
	ControlMove($Form1,"",$Button1,$B1pos[0],$B1pos[1] - 5)
EndFunc

Func Down()
	$B1pos = ControlGetPos($Form1,"",$Button1)
	ControlMove($Form1,"",$Button1,$B1pos[0],$B1pos[1] + 5)
EndFunc

Func Left()
	$B1pos = ControlGetPos($Form1,"",$Button1)
	ControlMove($Form1,"",$Button1,$B1pos[0] - 5,$B1pos[1])
EndFunc

Func Right()
	$B1pos = ControlGetPos($Form1,"",$Button1)
	ControlMove($Form1,"",$Button1,$B1pos[0] + 5,$B1pos[1])
EndFunc


Вопрос, как зделать так чтобы Button1 не проходил через Button2 ???
 

dwerf

Использует ArchLinux
Сообщения
478
Репутация
219
К примеру проверять координаты:

Код:
Func Up()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	$B2pos = ControlGetPos($Form1,"",$Button2)
	If Abs($B2pos[1]+$B2pos[3]-$B1pos[1]) >= 5 Or $B1pos[0] <= $B2pos[0]-$B1pos[2] Or $B1pos[0] > $B2pos[0]+$B2pos[2] Then ControlMove($Form1,"",$Button1,$B1pos[0],$B1pos[1] - 5)
EndFunc
 

gregaz

AutoIT Гуру
Сообщения
1,166
Репутация
299
Так : ?
Код:
Func Right()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	$B2pos = ControlGetPos($Form1,"",$Button2)
	
	If $B1pos[0]  +73 >= $B2pos[0] Then Return
	ControlMove($Form1,"",$Button1,$B1pos[0] + 5,$B1pos[1])
EndFunc



Добавлено:
Сообщение автоматически объединено:

Или лучше так :
Код:
If $B1pos[0]  + $B1pos[2] +5 >= $B2pos[0] Then Return
 
Автор
Zaramot

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
dwerf сказал(а):
К примеру проверять координаты:

У меня не как не получается написать функцию для Left,Right и Down.
Ладно хоть за Up спасибо.

gregaz, спасибо, но у меня так и получается, а мне надо как написал dwerf.
 

gregaz

AutoIT Гуру
Сообщения
1,166
Репутация
299
Zaramot [?]
У меня не как не получается написать функцию для Left,Right и Down.
Ладно хоть за Up спасибо.
gregaz, спасибо, но у меня так и получается, а мне надо как написал dwerf.

Значит я не понял условие задачи.
Тогда так можно :
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{UP}", "UP")
HotKeySet("{Down}", "Down")
HotKeySet("{Left}", "Left")
HotKeySet("{Right}", "Right")

$Form1 = GUICreate("Form1", 422, 335, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 72, 128, 73, 65, BitOR($BS_FLAT,$WS_GROUP))
$Button2 = GUICtrlCreateButton("Button2", 232, 80, 73, 65, BitOR($BS_FLAT,$WS_GROUP))

$B2pos = ControlGetPos($Form1,"",$Button2)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func Up()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	If Abs($B1pos[1] - $B2pos[1]-5) <= $B1pos[3] And $B1pos[0] + $B1pos[2] >=  $B2pos[0] And $B1pos[0] <=  $B2pos[0] +  $B2pos[2] Then Return
	ControlMove($Form1,"",$Button1,$B1pos[0],$B1pos[1] - 5)
EndFunc

Func Down()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	If Abs($B1pos[1] - $B2pos[1]+5) <= $B1pos[3] And $B1pos[0] + $B1pos[2] >=  $B2pos[0] And $B1pos[0] <=  $B2pos[0] +  $B2pos[2] Then Return
	ControlMove($Form1,"",$Button1,$B1pos[0],$B1pos[1] + 5)
EndFunc

Func Left()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	If Abs($B1pos[0] - $B2pos[0] -5 )  <= $B1pos[2] And  $B1pos[1] <=  $B2pos[1]+ $B2pos[3] And $B1pos[1] + $B1pos[3] >=  $B2pos[1]  Then Return
	ControlMove($Form1,"",$Button1,$B1pos[0] - 5,$B1pos[1])
EndFunc

Func Right()
    $B1pos = ControlGetPos($Form1,"",$Button1)
	If Abs($B1pos[0] - $B2pos[0]+5) <= $B1pos[2] And $B1pos[1] <=  $B2pos[1]+ $B2pos[3] And $B1pos[1] + $B1pos[3] >=  $B2pos[1] Then Return
	ControlMove($Form1,"",$Button1,$B1pos[0] + 5,$B1pos[1])
EndFunc
 
Автор
Zaramot

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
УЛЬТРА, прям то что нужно!!!! СПС :laugh: :laugh: :laugh:

ТЕМА ЗАКРЫТА
 
Верх