Jump to content

Catch!


AlmarM
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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

Link to comment
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.

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