AlmarM Posted February 12, 2009 Share Posted February 12, 2009 (edited) Hi, This is my second game Still a bit buggy. expandcollapse popup#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 February 12, 2009 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 More sharing options...
BrettF Posted February 12, 2009 Share Posted February 12, 2009 Crap this is hard! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
yehia Posted February 12, 2009 Share Posted February 12, 2009 u can always cheat having the source code nice idea AlmarM really nice but i didnt see that count bug My Scripts:IE New UDFsElastic images moving under mouse (with a happy valentine's example)_FileRemoveLine Link to comment Share on other sites More sharing options...
jvanegmond Posted February 12, 2009 Share Posted February 12, 2009 (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..expandcollapse popup#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 February 12, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
AlmarM Posted February 12, 2009 Author Share Posted February 12, 2009 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. Link to comment Share on other sites More sharing options...
FireFox Posted February 12, 2009 Share Posted February 12, 2009 @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 More sharing options...
corgano Posted February 12, 2009 Share Posted February 12, 2009 the box can move off the screen. try something like expandcollapse popup#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 More sharing options...
FireFox Posted February 12, 2009 Share Posted February 12, 2009 @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 expandcollapse popup#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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now