Sign in to follow this  
Followers 0
forever

Locking on a moving object

2 posts in this topic

#1 ·  Posted (edited)

Hi there,

no, this is not about cheating in a flash game, i just choose the game because i think its a good environment for learning purposes...

As you see in that game you can build a "tower", moving block on block.

The aim of this script is to find the tower and wait for the new block until its on a good position to drop on the tower. The intention behind this is how to lock on moving objects and waiting for certain circumstances.

Here's the link to the flash game:

http://www.mindjolt.com/games/tower-blocks

This is what i have so far:

while 1
    $locked = 0;
    $mpos = MouseGetPos();
    $coord = PixelSearch( $mpos[0]-40, $mpos[1]+120, $mpos[0]+40, $mpos[1]+160, 0xFAD606, 2)
    If Not @error Then
        MouseMove($coord[0]+8, $coord[1]-150, 0);
        $locked = 1;
    Else
        $locked = 0;
        $coord = PixelSearch( $mpos[0]-40, $mpos[1]+120, $mpos[0]+40, $mpos[1]+160, 0xC6D7A4, 1)
        If Not @error Then
            $locked = 1;
            MouseMove($coord[0]+8, $coord[1]-150, 0);
        EndIf
    EndIf
    if $locked = 1 Then
        $mpos = MouseGetPos();
        $coord = PixelSearch( $mpos[0]-11, $mpos[1]-75, $mpos[0]-7, $mpos[1]+45, 0xC6D7A4, 1)
        If Not @error Then
            ToolTip("Gotcha! xD", $mpos[0]+40, $mpos[1]-5, "Scanning...");
            MouseClick("left");
            sleep(750)
            ;MouseMove($mpos[0], $mpos[1]-15);
        Else
            ToolTip(":[", $mpos[0]+40, $mpos[1]-5, "Scanning...");
        EndIf
    Else
        ToolTip("No Tower Lock...", $mpos[0]+40, $mpos[1]-5, "Scanning...");
    EndIf
WEnd

If you are going to try out: start the game, build a tower with atleast 5-10 blocks, start the script and move ahead of the tower. It will lock and try to "play".

Questions:

- how to get it more precisely? (if i go for a thinner rect its not able to handle the movement speed)

- If it looses the "tower-lock", how to scan to find its way back to it ?

(Thought of slowly going down (from the top ofcourse) scanning for the "lock-pixel", any better/other ideas? <-problem with that: it shouldn't lock on the moving one (the one hanging from the top))

Thank you in advance and please excuse my bad english.

p.s.: just to prevent the question "why on a moving object.. the tower in that game doesnt move", if you build the tower up some blocks the screen will start moving ("wind effect")

Edited by forever

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Without playing the game, isn't it better to approach it from bottom up (I know, you have reasons not to do so...)?

(This is a complete theoretical approach):

1. Determining where the tower stands when there is no moving screen.

2. Calculate the heart of the tower (or first brick), draw an imaginary line upwards to the sky.

3. Determine the width of each brick to put on top of the previous one

4. If each new brick has crossed the line halfway, drop the brick.

5. Analyze the pixels to the left and the right of the first dropped brick (bottom of tower)

6. If one or both of them have changed we know

  • the moving of the screen has started.
  • in what direction the move is.
  • how many pixels have changed (and so knowing the speed)
7. Use the in 6 mentioned knowledge to recalculate the position of the imaginary line and also the drop zone.

Sounds fantastic, I truly doubt it will work this way, but that's the fun of not knowing everything.

In your mind a lot can be achieved. >_<

Edited by Scriptonize

If you learn from It, it's not a mistake

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