Jump to content

Mouse follow game


Recommended Posts

i am trying to make a game with a box that moves around the screen and wants your mouse to stay in the box, and if it leaves, it says you lose.

Buy i am having three problems:

1. In the script below the box just moves left to right if i do the same thing with the Y coords, it moves in squares not like random diagonals like i want

2. The box is moving, but part of the background sort of overlaps the box It really glitchy, like its doesn't have time to do everything

3. The Box it too fast, how do i slow it down w/o actualy stopping it(might resolve #2)

Heres my current code

#include<GuiConstants.au3>
#cs
AdlibEnable("ChangeAndCheck")
#ce

Global $x, $y, $MenuPlay, $instructions, $MenuGame,$box, $x2, $y2

    $MenuGame = GuiCreate("", 500,600, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetBkColor(0x000000)
    $label1 = GuiCtrlCreateLabel("Follow the Box", 175, 0, 200, 100)
    GUICtrlSetFont($label1, 20, 500, 2, "Arial")
    GUICtrlSetColor($label1, 0xff0000)
    $instructions = GuiCtrlCreateLabel("Keep your mouse in the gray squares and avoid touching the black background", 25, 100, 500, 50)
    GUICtrlSetFont($instructions, 15, 500, 2, "Arial")
    GUICtrlSetColor($instructions, 0xCCCCCC)
    $menuPlay = GUICtrlCreateButton("Play", 225, 500, 50, 30)
    GuiSetState()

While 1
    $msg = GUIGETMSG()
    
    if $msg = $GUI_EVENT_CLOSE then ExitLoop
    if $msg = $menuPLAY then StartGame()
WEnd

Func StartGame()
    $x= 200
    $y= 475
        
    GuiDelete("$MenuGame")
    GuiCreate("", 500,600, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetBkColor(0x000000)
    $box = GUICtrlCreateLabel(" ", 200, 475, 100, 100)
    GUICtrlSetBkColor($box, 0xCCCCCC)
    GuiSetState()

While 1
    $msg = GUIGETMSG()
    if $msg = $GUI_EVENT_CLOSE then ExitLoop
    
    $x = Random(0, 400)
    $y = Random(0, 500)
    $currentpos = ControlGetPos("","", $box)
        
        
    if $x > $currentpos[0] then 
        For $x2 = $currentpos[0] to $x
            GUICtrlSetPos($box, $x2,475)
        Next
    Else
        For $x2 = $currentpos[0] to $x step -1
            GUICtrlSetPos($box, $x2,475)
        Next
    Endif

WEnd

EndFunc

Any way to help?

Link to comment
Share on other sites

While I dont have any comments on your current problems, an easy way to check to see if the mouse is still within the box is just do a GUIGetCursorInfo() and it will return a control ID of what the mouse is currently over. So just do a While loop for while the cursor is over the box (with its specific ID).

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

While I dont have any comments on your current problems, an easy way to check to see if the mouse is still within the box is just do a GUIGetCursorInfo() and it will return a control ID of what the mouse is currently over. So just do a While loop for while the cursor is over the box (with its specific ID).

Thanks for the help, and that will probably be how i'll check that, but i really need a way to incorporate vertical movement and slow things down a notch or 2
Link to comment
Share on other sites

Alright, I would first like to say that I dont do game programming very well... but this was my attempt at making it randomly move around your black area and detect if your mouse moved off the box.

I'm sure there are better ways, this is just what came to me while looking at it:

#include<GuiConstants.au3>
#cs
    
#ce

Global $x, $y, $MenuPlay, $instructions, $MenuGame, $box, $x2, $y2

$MenuGame = GUICreate("", 500, 600, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
$label1 = GUICtrlCreateLabel("Follow the Box", 175, 0, 200, 100)
GUICtrlSetFont($label1, 20, 500, 2, "Arial")
GUICtrlSetColor($label1, 0xff0000)
$instructions = GUICtrlCreateLabel("Keep your mouse in the gray squares and avoid touching the black background", 25, 100, 500, 50)
GUICtrlSetFont($instructions, 15, 500, 2, "Arial")
GUICtrlSetColor($instructions, 0xCCCCCC)
$MenuPlay = GUICtrlCreateButton("Play", 225, 500, 50, 30)
GUISetState()

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $MenuPlay Then StartGame()
WEnd

Func ChangeAndCheck()
    $s_Temp = 0
    $a_BoxPos = ControlGetPos("", "", $box)
    If IsArray($a_BoxPos) Then
    Do
        $i_Rand = Random(1, 4,1)
        Select
            Case $i_Rand = 1  ; Move Box UP
                If ($a_BoxPos[1] - 15) > 25 Then
                    GUICtrlSetPos($box, $a_BoxPos[0], $a_BoxPos[1] - 15)
                    $s_Temp = 1
                EndIf
            Case $i_Rand = 2  ; Move Box RIGHT
                If ($a_BoxPos[0] + 15) < 475 Then
                    GUICtrlSetPos($box, $a_BoxPos[0] + 15, $a_BoxPos[1])
                    $s_Temp = 1
                EndIf
            Case $i_Rand = 3  ; Move Box DOWN
                If ($a_BoxPos[1] + 15) < 475 Then
                    GUICtrlSetPos($box, $a_BoxPos[0], $a_BoxPos[1] + 15)
                    $s_Temp = 1
                EndIf
            Case $i_Rand = 4  ; Move Box LEFT
                If ($a_BoxPos[0] - 15) > 25 Then
                    GUICtrlSetPos($box, $a_BoxPos[0] - 15, $a_BoxPos[1])
                    $s_Temp = 1
                EndIf
        EndSelect
    Until $s_Temp = 1
    EndIf
EndFunc   ;==>ChangeAndCheck

Func StartGame()
    GUIDelete("$MenuGame")
    $h_Game = GUICreate("", 500, 500, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetBkColor(0x000000)
    $box = GUICtrlCreateLabel(" ", 250, 250, 100, 100)
    GUICtrlSetBkColor($box, 0xCCCCCC)
    MouseMove(270, 270, 0)
    GUISetState()
    Sleep(1000)
    AdlibEnable("ChangeAndCheck",50)
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        Sleep(100)
        $a_Info = GuiGetCursorInfo($h_Game)
        If $a_Info[4] <> $box Then ExitLoop
        WEnd
        GUIDelete($h_Game)
    MsgBox(0, "Whoops!", "Your mouse left the box!")
    Exit
EndFunc   ;==>StartGame
Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Alright, I would first like to say that I dont do game programming very well... but this was my attempt at making it randomly move around your black area and detect if your mouse moved off the box.

I'm sure there are better ways, this is just what came to me while looking at it:

Thanks man, i liked it,

made a few changes, added point system and centered it

Then I put in Scripts and Scraps so i can update it later to have a menu and selectable difficulties and speeds

Thanks again

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