Jump to content

Controls blinking.


Recommended Posts

I know that the _WinAPI_RedrawWindow() function is making everything blink but it's the only thing I could find to draw a line and keep all the controls.

Is there something I'm missing so it won't blink so much?

#include<misc.au3>
#include<guiconstants.au3>
#include<gdiplus.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
$gui = GUICreate(@HOUR&":"&@MIN&":"&@SEC,640,480,-1,-1)
GUISetBkColor(0x000000)
Opt("GUIOnEventMode",1)
GUISetOnEvent(-3,"_Exit")
Local $sec = @SEC
$xc = Random(1,590)
$yc = Random(1,430)
$xt = Random(1,590)
$yt = Random(1,430)
$random_x = Round(Random(1,590),0)
$random_y = Round(Random(1,430),0)
$box = GUICtrlCreateButton("",$xc,$yc,50,50)
$target = GUICtrlCreateButton("",$xt,$yt,50,50)
GUICtrlSetBkColor($box,0x0000FF)
GUICtrlSetBkColor($target,0xFF0000)
$hits = 0
$hit = GUICtrlCreateLabel("Hits: "&$hits,5,5,100,15)
GUICtrlSetFont($hit,12,700)
GUICtrlSetColor($hit,0xFFFFFF)
$move = True
$i = 0
$stopped = False
$t_pos_x = $random_x
$t_pos_y = $random_y
$t_pos = GUICtrlCreateLabel("Target Pos: "&$t_pos_x&","&$t_pos_y,0,25,150,20)
GUICtrlSetColor($t_pos,0xFFFFFF)
GUICtrlSetFont($t_pos,12,700)
GUISetState()
_GDIPlus_Startup()
$hwnd = _GDIPlus_GraphicsCreateFromHWND($gui)
$pen = _GDIPlus_PenCreate(0xFFFFFFFF, 2)
$tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", 0)
    DllStructSetData($tRect, "Top", 0)
    DllStructSetData($tRect, "Right", 640)
    DllStructSetData($tRect, "Bottom", 480)
While 1
   $mp = GUIGetCursorInfo($gui)
   $s = @SEC
   If $s <> $sec Then
      If $i >= 15 Then
      $random_x = Round(Random(1,590),0)
   $random_y = Round(Random(1,430),0)
   $i = 0
   $stopped = False
   GUICtrlSetData($t_pos,"Target Pos: "&$random_x&","&$random_y)
   EndIf
      $i += 1
      WinSetTitle($gui,"",@HOUR&":"&@MIN&":"&@SEC)
      $sec = $s
   EndIf
   attack()
   If $move = False Then
      test()
   EndIf
    If _IsPressed("01") Then
       test()
    EndIf
    $cp = ControlGetPos($gui,"",$target)
   $cp2 = ControlGetPos($gui,"",$box)
    _WinAPI_RedrawWindow($GUI,$tRect,0,BitOR($RDW_ERASE,$RDW_INVALIDATE))
    $line = _GDIPlus_GraphicsDrawLine($hwnd,$cp[0]+25,$cp[1]+25,$cp2[0]+25,$cp2[1]+25,$pen)
   Sleep(10)
WEnd

Func _Exit()
   _GDIPlus_PenDispose($Pen)
   _GDIPlus_GraphicsDispose($hwnd)
    _GDIPlus_Shutdown()
   Exit
EndFunc

Func attack()
   $cp = ControlGetPos($gui,"",$target)
   $cp2 = ControlGetPos($gui,"",$box)
   If $move = True Then
;~
   If $cp2[0] > $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]-1,$cp2[1])
   EndIf
   If $cp2[1] > $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]-1)
   EndIf
   If $cp2[0] < $cp[0] Then
      ControlMove($gui,"",$box,$cp2[0]+1,$cp2[1])
   EndIf
   If $cp2[1] < $cp[1] Then
      ControlMove($gui,"",$box,$cp2[0],$cp2[1]+1)
   EndIf
;~
If $stopped = False Then
   If $cp[0] > $random_x Then
      ControlMove($gui,"",$target,$cp[0]-1,$cp[1])
   EndIf
   If $cp[1] > $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]-1)
   EndIf
   If $cp[0] < $random_x Then
      ControlMove($gui,"",$target,$cp[0]+1,$cp[1])
   EndIf
   If $cp[1] < $random_y Then
      ControlMove($gui,"",$target,$cp[0],$cp[1]+1)
   EndIf
   If $cp[0] = $random_x And $cp[1] = $random_y Then
      $stopped = True
      EndIf
   EndIf
;~
     If $cp2[0] <= $cp[0]+$cp[2] And $cp2[1] <= $cp[1]+$cp[3] And $cp2[0]+$cp2[2] >= $cp[0] And $cp2[1]+$cp2[3] >= $cp[1] Then
        ControlMove($gui,"",$target,9999,-9999)
        ControlMove($gui,"",$target,Random(1,590),Random(1,430))
        $hits = $hits + 1
        GUICtrlSetData($hit,"Hits: "&$hits)
        $random_x = Round(Random(1,590),0)
   $random_y = Round(Random(1,430),0)
   $i = 0
   GUICtrlSetData($t_pos,"Target Pos: "&$random_x&","&$random_y)
   $stopped = False
     EndIf
     EndIf
  EndFunc

  Func test()
     $cp = ControlGetPos($gui,"",$box)
     $mp = GUIGetCursorInfo($gui)
     If $mp[0] >= $cp[0] And $mp[1] >= $cp[1] And $mp[0] <= $cp[0]+$cp[2] And $mp[1] <= $cp[1]+$cp[3] Then
     ControlMove($gui,"",$box,$mp[0]-25,$mp[1]-25)
     EndIf
  EndFunc

Thanks in advance.

Link to comment
Share on other sites

Looks like game automation

It is a game you made! My apologies :sweating:

EDIT: pretty cool, but what OS are you using?

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

MikahS,

How can this be game automation when it is an entirely self-contained script with no link to any third party app? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Exactly why I corrected myself ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

How did you fix it? Please post your solution so that if others have the same problem, they can see what you did to solve it. :D

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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