Jump to content

webcam pingpong


7h331337
 Share

Recommended Posts

This was my first script and i thout i would share it

the webcam udf is attached

CODE

#include <GUIConstantsEx.au3>

#include <Webcam.au3>

HotKeySet("{esc}","stop")

$Main = GUICreate("",@desktopwidth,@DesktopHeight,0,0,$WS_POPUPWINDOW)

_WebcamInit()

sleep(400)

$open = _Webcam($main,@desktopwidth,@DesktopHeight,0, 0)

global $x

global $y

$x = 6

$y = 6

$count = 1

$Ball = GUICtrlCreateLabel ( "", $x, $y, 10, 10 )

GUICtrlSetBkColor ( -1, 0x120000 )

$user1 = GUICtrlCreateLabel("",10,10)

$user2 = GUICtrlCreateLabel("",10,10)

guisetstate()

sleep(2000)

Do

$ran1 = Random(5,15)

$ran2 = Random(5,15)

if guictrlread($user1) = "" then

MsgBox(0,"colour","please select coluor")

$p = MouseGetPos()

$col1 = PixelGetColor($p[0],$p[1])

GUICtrlSetData($user1,$col1)

endif

if GUICtrlRead($user2) = "" Then

MsgBox(0,"colour","please select coluor 2")

$t = MouseGetPos()

$col2 = PixelGetColor($t[0],$t[1])

GUICtrlSetData($user2,$col2)

EndIf

$play1 = PixelSearch($x - 5,$y - 5 ,$x + 15,$y + 15,guictrlread($user1),5,5)

If Not @error Then

MouseMove($play1[0], $play1[1], 0)

ToolTip("Player1 Found", 0, 0)

beep(250, 100)

$count = 5

EndIf

$play2 = PixelSearch($x - 5,$y - 5 ,$x + 15,$y + 15,guictrlread($user2),5,5)

If Not @error Then

MouseMove($play2[0], $play2[1], 0)

ToolTip("Player2 Found", 0, 0)

beep(150, 100)

$count = 6

EndIf

if $count = 1 Then

$y = $y + $ran1

$x = $x + $ran1

sleep(2)

EndIf

if $count = 2 Then

$y = $y - $ran1

$x = $x + $ran1

beep(100,100)

sleep(1)

EndIf

if $count = 3 Then

$y = $y - $ran1

$x = $x - $ran1

sleep(1)

EndIf

if $count = 4 Then

$y = $y + $ran1

$x = $x - $ran2

sleep(1)

EndIf

if $count = 5 Then

$y = $y - $ran1

$x = $x - $ran2

sleep(1)

EndIf

if $count = 6 Then

$y = $y + $ran1

$x = $x + $ran2

sleep(1)

EndIf

if $y >= @DesktopHeight Then

$count = 2

EndIf

if $x >= @DesktopWidth Then

$count = 3

EndIf

if $x <= 2 Then

$count = 1

EndIf

if $y <= 2 Then

$count = 4

EndIf

GUICtrlSetPos($ball,$x,$y)

GUICtrlSetPos($play1,$x - 5,$y - 5)

GUICtrlSetPos($play2,$x - 5,$y - 5)

until 1 = 2

func stop()

_WebcamStop()

sleep(2000)

Exit

EndFunc

webcam.au3

Edited by 7h331337
Link to comment
Share on other sites

  • Developers

It normally helps when you explain what it is supposed to do.

I for one never check out any of these examples unless they sound useful.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...