Sign in to follow this  
Followers 0
AlmarM

Catch!

8 posts in this topic

#1 ·  Posted (edited)

Hi,

This is my second game :)

Still a bit buggy.

#include <Misc.au3>

AdlibEnable("SetTimer", 1000)

Global $vDll = "user32.dll"
Global $xP = 10, $yP = 25
Global $Point
Global $Score = 0
Global $RandomX, $RandomY
Global $Timer = 0

$GUI = GUICreate("Catch the Dot!", 700, 700)
$Player = GUICtrlCreateLabel("", $xP, $yP, 30, 30)
$ScoreLabel = GUICtrlCreateLabel("                              Score: " & $Score, 0, 0, 700, 15)

_Random_Dot()

GUICtrlSetBkColor($ScoreLabel, 0xFFFFFF)
GUICtrlSetBkColor($Player, 0x000000)
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(20)
    
    If _IsPressed(25, $vDll) Then ; Left
        $xP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(26, $vDll) Then ; Up
        $yP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(27, $vDll) Then ; Right
        $xP += 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(28, $vDll) Then ; Down
        $yP += 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If $xP > $RandomX - 4 And $xP < $RandomX + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                               Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $yP > $RandomY - 4 And $yP < $RandomY + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                               Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $Timer = 2 Then
        _Delete()
        _Random_Dot()
    EndIf
WEnd

Func _Random_Dot()
    $RandomX = Random(10, 680, 1)
    $RandomY = Random(15, 680, 1)
    $Point = GUICtrlCreateLabel("", $RandomX, $RandomY, 10, 10)
    GUICtrlSetBkColor($Point, 0xFF0000)
EndFunc

Func _Delete()
    GUICtrlDelete($Point)
EndFunc

Func SetTimer()
    $Timer += 1
EndFunc

The randomizing after the $Timer reaches 2 is not a bug.

Hope someone can get ride of the buggs and Hope you Enjoy :)

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

Could you explain what is the purpose? I don't get this one bit. I get it.

And there's really no need at all to use Adlib here..

#include <Misc.au3>

Global $vDll = "user32.dll"
Global $xP = 10, $yP = 25
Global $Point
Global $Score = 0
Global $RandomX, $RandomY
Global $Timer = TimerInit()

$GUI = GUICreate("Catch the Dot!", 700, 700)
$Player = GUICtrlCreateLabel("", $xP, $yP, 30, 30)
$ScoreLabel = GUICtrlCreateLabel("                Score: " & $Score, 0, 0, 700, 15)

_Random_Dot()

GUICtrlSetBkColor($ScoreLabel, 0xFFFFFF)
GUICtrlSetBkColor($Player, 0x000000)
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(20)
    
    If _IsPressed(25, $vDll) Then ; Left
        $xP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(26, $vDll) Then ; Up
        $yP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(27, $vDll) Then ; Right
        $xP += 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If _IsPressed(28, $vDll) Then ; Down
        $yP += 6
        GUICtrlSetPos($Player, $xP, $yP)
    EndIf
    
    If $xP > $RandomX - 4 And $xP < $RandomX + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                        Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = TimerInit()
    EndIf
    
    If $yP > $RandomY - 4 And $yP < $RandomY + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                        Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = TimerInit()
    EndIf
    
    If TimerDiff($Timer) >= 2000 Then
        _Delete()
        _Random_Dot()
    EndIf
WEnd

Func _Random_Dot()
    $RandomX = Random(10, 680, 1)
    $RandomY = Random(15, 680, 1)
    $Point = GUICtrlCreateLabel("", $RandomX, $RandomY, 10, 10)
    GUICtrlSetBkColor($Point, 0xFF0000)
EndFunc

Func _Delete()
    GUICtrlDelete($Point)
EndFunc
Edited by Manadar

Share this post


Link to post
Share on other sites

Ah, thx Manadar! :)

AlmarM


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

@AlmarM

Nice game, but little hard :)

I see that you use always _IsPressed in your while, so it would be better to Open user32.dll and close it on autoit exit,

just include IsPressed_UDF and it will do it...as you know it has a lot of functions :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

the box can move off the screen.

try something like

#include <Misc.au3>

AdlibEnable("SetTimer", 1000)

Global $vDll = "user32.dll"
Global $xP = 10, $yP = 25
Global $Point
Global $Score = 0
Global $RandomX, $RandomY
Global $Timer = 0

$GUI = GUICreate("Catch the Dot!", 700, 700)
$Player = GUICtrlCreateLabel("", $xP, $yP, 30, 30)
$ScoreLabel = GUICtrlCreateLabel("              Score: " & $Score, 0, 0, 700, 15)

_Random_Dot()

GUICtrlSetBkColor($ScoreLabel, 0xFFFFFF)
GUICtrlSetBkColor($Player, 0x000000)
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(20)
    
    If _IsPressed(25, $vDll) Then; Left
        if $xP > 0 Then 
        $xP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(26, $vDll) Then; Up
        If $yP > 16 Then
        $yP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(27, $vDll) Then; Right
        If $xP < 670 Then
        $xP += 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(28, $vDll) Then; Down
        If $yP < 700 Then
        $yP += 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If $xP > $RandomX - 4 And $xP < $RandomX + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                       Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $yP > $RandomY - 4 And $yP < $RandomY + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, "                       Score: " & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $Timer = 2 Then
        _Delete()
        _Random_Dot()
    EndIf
WEnd

Func _Random_Dot()
    $RandomX = Random(10, 680, 1)
    $RandomY = Random(15, 680, 1)
    $Point = GUICtrlCreateLabel("", $RandomX, $RandomY, 10, 10)
    GUICtrlSetBkColor($Point, 0xFF0000)
EndFunc

Func _Delete()
    GUICtrlDelete($Point)
EndFunc

Func SetTimer()
    $Timer += 1
EndFunc

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

@corgano

Have you tested your suggestion ? Because the down limit is out of bounds...

Here is my example with my IsPressed_UDF suggestion :

- Keys detection is faster

#include <IsPressed_UDF.au3>

AdlibEnable('SetTimer', 1000)

Global $xP = 10, $yP = 25
Global $Point
Global $Score = 0
Global $RandomX, $RandomY
Global $Timer = 0

$GUI = GUICreate('Catch the Dot!', 700, 700)
$Player = GUICtrlCreateLabel('', $xP, $yP, 30, 30)
$ScoreLabel = GUICtrlCreateLabel('                Score: ' & $Score, 0, 0, 700, 15)

_Random_Dot()

GUICtrlSetBkColor($ScoreLabel, 0xFFFFFF)
GUICtrlSetBkColor($Player, 0x000000)
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(20)
    
    If _IsPressed(25) Then; Left
        if $xP > 0 Then
        $xP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(26) Then; Up
        If $yP > 16 Then
        $yP -= 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(27) Then; Right
        If $xP < 670 Then
        $xP += 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If _IsPressed(28) Then; Down
        If $yP < 670 Then
        $yP += 6
        GUICtrlSetPos($Player, $xP, $yP)
        EndIf
    EndIf
    
    If $xP > $RandomX - 4 And $xP < $RandomX + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, '                        Score: ' & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $yP > $RandomY - 4 And $yP < $RandomY + 4 Then
        $Score += 1
        GUICtrlSetData($ScoreLabel, '                        Score: ' & $Score)
        _Delete()
        _Random_Dot()
        $Timer = 0
    EndIf
    
    If $Timer = 2 Then
        _Delete()
        _Random_Dot()
    EndIf
WEnd

Func _Random_Dot()
    $RandomX = Random(10, 680, 1)
    $RandomY = Random(15, 680, 1)
    $Point = GUICtrlCreateLabel('', $RandomX, $RandomY, 10, 10)
    GUICtrlSetBkColor($Point, 0xFF0000)
EndFunc

Func _Delete()
    GUICtrlDelete($Point)
EndFunc

Func SetTimer()
    $Timer += 1
EndFunc

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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