Lord_Doominik Posted February 28, 2006 Posted February 28, 2006 (edited) hi,i've done a litle tank-game... everytime, when you shoot, the bullet should disappear, if it collides with the walls... the walls are black, so i made a condition, if the pixel in front of the bullet is black, the bullet should disappear, but the bulletcoordinates don't fit and i don't know why o.O...expandcollapse popup;Name: Battle.au3 ;Author: Lord_Doominik ;Status: In Progress (50%) ;Version: 0 $gui = WinGetPos("Robot Wars") $x1 = 330 $xmove1 = $gui[0] + $x1 $y1 = 180 $ymove1 = $gui[1] + $y1 Dim $bullet1[1000] $bullet1[0] = 0 Dim $bulletx1[1000] Dim $bullety1[1000] $x2 = 203 $xmove2 = $gui[0] + $x1 $y2 = 550 $ymove2 = $gui[1] + $y1 Dim $bullet2[1000] $bullet2[0] = 0 Dim $bulletx2[1000] Dim $bullety2[1000] $i = 0 $reloadtime = TimerInit() $Arena = GUICtrlCreatePic("Battlefields/Arena1.map", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Roboter1 = GUICreate("Roboter1", 32, 32, $x1, $y1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic("Vehicles/Panzer1 N.gif", 0, 0, 32, 32) GUISetState() $Roboter2 = GUICreate("Roboter2", 11, 21, $x2, $y2, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic("Vehicles/Roboter2.gif", 0, 0, 11, 21) GUISetState() While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect Action1() Shot1() WEnd Func Action1() $gui = WinGetPos("Robot Wars") $xmove1 = $gui[0] + $x1 $ymove1 = $gui[1] + $y1 If _IsPressed("25") Then If Hex(PixelGetColor($xmove1+4, $ymove1), 6) <> "000000" And Hex(PixelGetColor($xmove1+4, $ymove1+27), 6) <> "000000" Then $xmove1 = $xmove1 - 1 $x1 = $x1 - 1 EndIf EndIf If _IsPressed("27") Then If Hex(PixelGetColor($xmove1+27, $ymove1), 6) <> "000000" And Hex(PixelGetColor($xmove1+27, $ymove1+27), 6) <> "000000" Then $xmove1 = $xmove1 + 1 $x1 = $x1 + 1 EndIf EndIf If _IsPressed("26") Then If Hex(PixelGetColor($xmove1+16, $ymove1-1), 6) <> "000000" Or Hex(PixelGetColor($xmove1+17, $ymove1-1), 6) <> "000000" Or Hex(PixelGetColor($xmove1+18, $ymove1-1), 6) <> "000000" And Hex(PixelGetColor($xmove1+5, $ymove1+2), 6) <> "000000" And Hex(PixelGetColor($xmove1+26, $ymove1+2), 6) <> "000000" Then $ymove1 = $ymove1 - 1 $y1 = $y1 - 1 EndIf EndIf If _IsPressed("28") Then If Hex(PixelGetColor($xmove1+5, $ymove1+29), 6) <> "000000" And Hex(PixelGetColor($xmove1+26, $ymove1+29), 6) <> "000000" Then $ymove1 = $ymove1 + 1 $y1 = $y1 + 1 EndIf EndIf If _IsPressed("20") Then If TimerDiff($reloadtime) >= 750 Then GUISwitch($mainGUI) $bullet1[0] = $bullet1[0] + 1 $i = $bullet1[0] $bulletx1[$i] = $x1 + 11 $bullety1[$i] = $y1 - 27 $bullet1[$i] = GUICtrlCreateLabel("", $bulletx1[$i], $bullety1[$i], 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() EndIf EndIf WinMove("Roboter1", "", $xmove1, $ymove1) EndFunc Func Shot1() For $j = 1 To $i If Hex(PixelGetColor($bulletx1[$j], $bullety1[$j]-1), 6) = "000000" Then GUICtrlDelete($bullet1[$j]) EndIf $bullety1[$j] = $bullety1[$j] - 2 GUICtrlSetPos($bullet1[$j], $bulletx1[$j], $bullety1[$j]) Next EndFuncRobot Wars Source Code + Graphics Edited March 2, 2006 by Lord_Doominik
Moderators SmOke_N Posted February 28, 2006 Moderators Posted February 28, 2006 Try just: (PixelGetColor($bulletx1[$j], $bullety1[$j]-1) == 0x000000) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Lord_Doominik Posted February 28, 2006 Author Posted February 28, 2006 don't works... already tryed it... the problem is sth. with the coordinates... the bullet disappears, but not, at a wall... but i don't know where the problem is...
Moderators SmOke_N Posted March 1, 2006 Moderators Posted March 1, 2006 Well, actually it's quite confusing... Is there a reason your not supplying the whole code for debugging? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Lord_Doominik Posted March 1, 2006 Author Posted March 1, 2006 (edited) that's the WHOLE code for debugging the other script is running well... Edited March 1, 2006 by Lord_Doominik
Cloudsx Posted March 1, 2006 Posted March 1, 2006 heej when its ready could you please give me a copier of that game i think i like it
Lord_Doominik Posted March 1, 2006 Author Posted March 1, 2006 i could, but first i need to fix the bug... xD
Moderators SmOke_N Posted March 1, 2006 Moderators Posted March 1, 2006 that's the WHOLE code for debugging the other script is running well...I can't run the script to try and help, so it's not the whole script, I have errors when I try to figure stuff out that the main GUI is missing. If you can't provide it all, then there's not much that anyone can do but take guesses and hope that their educated guesses are correct.Help yourself here! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Lord_Doominik Posted March 1, 2006 Author Posted March 1, 2006 lol, theres just another little script, but everything is fine with it... and if you see its jsut the guy... not more -.-* ;Name: RobotWars.au3 ;Author: Lord_Doominik ;Status: In Progress (15%) ;Version: 0 #include <GUIConstants.au3> #include <Misc.au3> $mainGUI = GUICreate("Robot Wars", 800, 625, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2, $WS_MINIMIZEBOX + $WS_SYSMENU) $Label = GUICtrlCreateLabel("Press Enter to Start", 0, (@DesktopHeight-200)/2, 800, -1, $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case _IsPressed("0D") ExitLoop EndSelect WEnd GUICtrlDelete($Label) #include <Battle.au3>
Moderators SmOke_N Posted March 1, 2006 Moderators Posted March 1, 2006 lol, theres just another little script, but everything is fine with it... and if you see its jsut the guy... not more -.-* ;Name: RobotWars.au3 ;Author: Lord_Doominik ;Status: In Progress (15%) ;Version: 0 #include <GUIConstants.au3> #include <Misc.au3> $mainGUI = GUICreate("Robot Wars", 800, 625, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2, $WS_MINIMIZEBOX + $WS_SYSMENU) $Label = GUICtrlCreateLabel("Press Enter to Start", 0, (@DesktopHeight-200)/2, 800, -1, $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case _IsPressed("0D") ExitLoop EndSelect WEnd GUICtrlDelete($Label) #include <Battle.au3>Just a Blank GUI ... (not included: #include <Battle.au3>)... I hope you get it working. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Lord_Doominik Posted March 1, 2006 Author Posted March 1, 2006 hugh??? look at the filenames... the game is splitted into 2 files... the game.au3 file, which later gets the menu and this stuff and the battle.au3, which has got the game... it's jsut included there, it doesn't matter if i copy it there or include??? don't know what exactly you mean...
Moderators SmOke_N Posted March 1, 2006 Moderators Posted March 1, 2006 Just hard to help doom, if I don't have anything but a 'blank' gui to look at... I can't replicate anything. I mean personally, looking at the code, I would have written it differently for the pixelgetcolor options, but nothing is commented or anything, on what it does, you leave it up to us to try and debug a problem that your having that only you can replicate, and we have to go off of variable names to try and understand what could be happening. I'll leave you alone, maybe someone else has a clue... but as I said... I personally need to be able to recreate a situation to be able to debug one. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Lord_Doominik Posted March 1, 2006 Author Posted March 1, 2006 (edited) oh, yeah, sry i forgot the pic... theres a background pic... hm, i thought you could get it from the code... but i can upload a zip package for you...Robot Wars Source Code + Graphics Edited March 1, 2006 by Lord_Doominik
GrungeRocker Posted March 1, 2006 Posted March 1, 2006 heej when its ready could you please give me a copier of that game i think i like ithmmmwelllthanks for supporting our game [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]
nfwu Posted March 3, 2006 Posted March 3, 2006 (edited) Hmmm... game idea? I think you should try using some simple collision detection like: (Assuming your battle arena is a rectangle) If $bullet_X < $arena_leftwall_x Or $bullet_X > $arena_rightwall_x Or $bullet_Y < $arena_topwall_y Or $bullet_Y > $arena_bottomwall_y Then ;;; $bullet has collided with a wall EndIf #) EDIT: code tags Edited March 3, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
GrungeRocker Posted March 3, 2006 Posted March 3, 2006 no that won't work, because the arene is an *.bmp file, and it should be working with different arenas [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]
Moderators SmOke_N Posted March 3, 2006 Moderators Posted March 3, 2006 I didn't even know this was still an open issue, so I downloaded the file... Well to be honest, you guys really make it too much of a pain in the rear to even try to help debug. I mean, I don't know about your computers, but when I am using a file path, don't work so good with a forward slash (Battlefields/Arena1.map)... I tend to use a back slash. Pic's were in the wrong place to even make the background show... I mean, if this was a edit job to try and hide any trade secrets... you did a good job on that, but hacked up the rest... I mean ya'll didn't even comment anything. Anyway, the problem your having... (After Debuging, is that the window you are wanting to get the 0x000000 color from doesn't have focus for PixelGetColor() to work... Just run my example below (change the file locations for the pictures of course) and you'll see what I'm talking about, the mouse will move where ever PixelGetColor() is searching:expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> $mainGUI = GUICreate("Robot Wars", 800, 625, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2, $WS_MINIMIZEBOX + $WS_SYSMENU) $Label = GUICtrlCreateLabel("Press Enter to Start", 0, (@DesktopHeight-200)/2, 800, -1, $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case _IsPressed("0D") ExitLoop EndSelect WEnd GUICtrlDelete($Label) $Arena = GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Battlefields\Arena2.bmp", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $gui = WinGetPos("Robot Wars") $x1 = 330 $xmove1 = $gui[0] + $x1 $y1 = 180 $ymove1 = $gui[1] + $y1 Dim $bullet1[1000] $bullet1[0] = 0 Dim $bulletx1[1000] Dim $bullety1[1000] $x2 = 203 $xmove2 = $gui[0] + $x1 $y2 = 550 $ymove2 = $gui[1] + $y1 Dim $bullet2[1000] $bullet2[0] = 0 Dim $bulletx2[1000] Dim $bullety2[1000] $i = 0 $reloadtime = TimerInit() $Roboter1 = GUICreate("Roboter1", 32, 32, $x1, $y1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Vehicles\Panzer1 N.gif", 0, 0, 32, 32) GUISetState() $Roboter2 = GUICreate("Roboter2", 11, 21, $x2, $y2, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Vehicles\Roboter2.gif", 0, 0, 11, 21) GUISetState() While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect Action1() Shot1() WEnd Func Action1() $gui = WinGetPos("Robot Wars") $xmove1 = $gui[0] + $x1 $ymove1 = $gui[1] + $y1 If _IsPressed("25") Then If (PixelGetColor($xmove1+4, $ymove1) <> 0x000000) And (PixelGetColor($xmove1+4, $ymove1+27) <> 0x000000) Then $xmove1 = $xmove1 - 1 $x1 = $x1 - 1 EndIf EndIf If _IsPressed("27") Then If (PixelGetColor($xmove1+27, $ymove1) <> 0x000000) And (PixelGetColor($xmove1+27, $ymove1+27) <> 0x000000) Then $xmove1 = $xmove1 + 1 $x1 = $x1 + 1 EndIf EndIf If _IsPressed("26") Then If (PixelGetColor($xmove1+16, $ymove1-1) <> 0x000000) Or (PixelGetColor($xmove1+17, $ymove1-1) <> 0x000000) Or (PixelGetColor($xmove1+18, $ymove1-1) <> 0x000000) And (PixelGetColor($xmove1+5, $ymove1+2) <> 0x000000) And (PixelGetColor($xmove1+26, $ymove1+2) <> 0x000000) Then $ymove1 = $ymove1 - 1 $y1 = $y1 - 1 EndIf EndIf If _IsPressed("28") Then If (PixelGetColor($xmove1+5, $ymove1+29) <> 0x000000) And (PixelGetColor($xmove1+26, $ymove1+29) <> 0x000000) Then $ymove1 = $ymove1 + 1 $y1 = $y1 + 1 EndIf EndIf If _IsPressed("20") Then If TimerDiff($reloadtime) >= 750 Then GUISwitch($mainGUI) $bullet1[0] = $bullet1[0] + 1 $i = $bullet1[0] $bulletx1[$i] = $x1 + 11 $bullety1[$i] = $y1 - 27 $bullet1[$i] = GUICtrlCreateLabel("", $bulletx1[$i], $bullety1[$i], 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() EndIf EndIf WinMove("Roboter1", "", $xmove1, $ymove1) EndFunc Func Shot1() For $j = 1 To $i Local $PixColor = PixelGetColor($bulletx1[$j], $bullety1[$j]-1) If ($PixColor == 0x000000) Then GUICtrlDelete($bullet1[$j]) EndIf If ($PixColor <> 0xFFFFFF) Then ConsoleWrite('0x' & Hex(PixelGetColor($bulletx1[$j], $bullety1[$j]-1), 6)) MouseMove($bulletx1[$j], $bullety1[$j]-1) EndIf $bullety1[$j] = $bullety1[$j] - 2 GUICtrlSetPos($bullet1[$j], $bulletx1[$j], $bullety1[$j]) Next EndFuncNot the exact answer your looking for I'm sure, but further than what has been explained so far as far as I know. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Moderators SmOke_N Posted March 3, 2006 Moderators Posted March 3, 2006 This is sloppy, but a works a bit... I think nfwu is on the right path, doesn't matter if the arena is a 'bitmap' file, you gave it a specific size (lol). C'mon now... You might think of using ControlGetPos() your lives may be alot easier.expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> Opt('PixelCoordMode', 2) $mainGUI = GUICreate("Robot Wars", 800, 625, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2, $WS_MINIMIZEBOX + $WS_SYSMENU) $Label = GUICtrlCreateLabel("Press Enter to Start", 0, (@DesktopHeight-200)/2, 800, -1, $SS_CENTER) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case _IsPressed("0D") ExitLoop EndSelect WEnd GUICtrlDelete($Label) $Arena = GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Battlefields\Arena2.bmp", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $gui = WinGetPos("Robot Wars") $x1 = 330 $xmove1 = $gui[0] + $x1 $y1 = 180 $ymove1 = $gui[1] + $y1 Dim $bullet1[1000] $bullet1[0] = 0 Dim $bulletx1[1000] Dim $bullety1[1000] $x2 = 203 $xmove2 = $gui[0] + $x1 $y2 = 550 $ymove2 = $gui[1] + $y1 Dim $bullet2[1000] $bullet2[0] = 0 Dim $bulletx2[1000] Dim $bullety2[1000] $i = 0 $reloadtime = TimerInit() $Roboter1 = GUICreate("Roboter1", 32, 32, $x1, $y1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Vehicles\Panzer1 N.gif", 0, 0, 32, 32) GUISetState() $Roboter2 = GUICreate("Roboter2", 11, 21, $x2, $y2, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic(@DesktopDir & "\Test_Folder\Robot_Wars\Vehicles\Roboter2.gif", 0, 0, 11, 21) GUISetState() While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect Action1() Shot1() WEnd Func Action1() $gui = WinGetPos("Robot Wars") $xmove1 = $gui[0] + $x1 $ymove1 = $gui[1] + $y1 If _IsPressed("25") Then If (PixelGetColor($xmove1+4, $ymove1) <> 0x000000) And (PixelGetColor($xmove1+4, $ymove1+27) <> 0x000000) Then $xmove1 = $xmove1 - 1 $x1 = $x1 - 1 EndIf EndIf If _IsPressed("27") Then If (PixelGetColor($xmove1+27, $ymove1) <> 0x000000) And (PixelGetColor($xmove1+27, $ymove1+27) <> 0x000000) Then $xmove1 = $xmove1 + 1 $x1 = $x1 + 1 EndIf EndIf If _IsPressed("26") Then If (PixelGetColor($xmove1+16, $ymove1-1) <> 0x000000) Or (PixelGetColor($xmove1+17, $ymove1-1) <> 0x000000) Or (PixelGetColor($xmove1+18, $ymove1-1) <> 0x000000) And (PixelGetColor($xmove1+5, $ymove1+2) <> 0x000000) And (PixelGetColor($xmove1+26, $ymove1+2) <> 0x000000) Then $ymove1 = $ymove1 - 1 $y1 = $y1 - 1 EndIf EndIf If _IsPressed("28") Then If (PixelGetColor($xmove1+5, $ymove1+29) <> 0x000000) And (PixelGetColor($xmove1+26, $ymove1+29) <> 0x000000) Then $ymove1 = $ymove1 + 1 $y1 = $y1 + 1 EndIf EndIf If _IsPressed("20") Then If TimerDiff($reloadtime) >= 750 Then GUISwitch($mainGUI) $bullet1[0] = $bullet1[0] + 1 $i = $bullet1[0] $bulletx1[$i] = $x1 + 11 $bullety1[$i] = $y1 - 27 $bullet1[$i] = GUICtrlCreateLabel("", $bulletx1[$i], $bullety1[$i], 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() EndIf EndIf WinMove("Roboter1", "", $xmove1, $ymove1) EndFunc Func Shot1() For $j = 1 To $i ControlFocus($mainGUI, '', '') Local $PixColor = PixelGetColor($bulletx1[$j], $bullety1[$j]-1) If ($PixColor == 0x000000) Then GUICtrlDelete($bullet1[$j]) $ShotsFired = 0 EndIf $bullety1[$j] = $bullety1[$j] - 2 GUICtrlSetPos($bullet1[$j], $bulletx1[$j], $bullety1[$j]) Next ControlFocus($Roboter1, '', '') EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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