Lord_Doominik Posted March 5, 2006 Share Posted March 5, 2006 ok, i rewrote my game - with wingetpostion because controlgetposition always says strange coordinates or 0 - because i don't want to have the old buggy shooting system...now i have the problem, that the shoot isn't created in front of the tank...Source Code + Graphicsif you want to test it you'll need the rar package and need to run the "robot wars.au3"expandcollapse popup;Name: Battle.au3 ;Author: Lord_Doominik ;Status: In Progress (5%) ;Version: 0 Dim $bullet1[10000] Dim $bullet2[10000] $i = 0 $reloadtime = TimerInit() $Arena = GUICtrlCreatePic("Battlefields/Arena1.map", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Roboter1 = GUICreate("Roboter1", 32, 32, 330, 175, $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, 203, 550, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic("Vehicles/Roboter2.gif", 0, 0, 11, 21) GUISetState() ControlFocus("Robot Wars", "", $mainGUI) While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect Action() Shot() WEnd Func Action() $pos1 = WinGetPos("Roboter1") $x1 = 0 $y1 = 0 If _IsPressed("25") Then If Hex(PixelGetColor($pos1[0]+4, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+4, $pos1[1]+27), 6) <> "000000" Then $x1 -= 1 EndIf EndIf If _IsPressed("27") Then If Hex(PixelGetColor($pos1[0]+27, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+27, $pos1[1]+27), 6) <> "000000" Then $x1 += 1 EndIf EndIf If _IsPressed("26") Then If Hex(PixelGetColor($pos1[0]+16, $pos1[1]-1), 6) <> "000000" Or Hex(PixelGetColor($pos1[0]+17, $pos1[1]-1), 6) <> "000000" Or Hex(PixelGetColor($pos1[0]+18, $pos1[1]-1), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+5, $pos1[1]+2), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+26, $pos1[1]+2), 6) <> "000000" Then $y1 -= 1 EndIf EndIf If _IsPressed("28") Then If Hex(PixelGetColor($pos1[0]+5, $pos1[1]+29), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+26, $pos1[1]+29), 6) <> "000000" Then $y1 += 1 EndIf EndIf If _IsPressed("20") And TimerDiff($reloadtime) >= 1000 Then GUISwitch($mainGUI) $i += 1 $bullet1[$i] = GUICtrlCreateLabel("", $pos1[0]+11, $pos1[1]-27, 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() EndIf ControlMove("Roboter1", "", $Roboter1, $pos1[0]+$x1, $pos1[1]+$y1) EndFunc Func Shot() EndFunc Link to comment Share on other sites More sharing options...
Stumpii Posted March 5, 2006 Share Posted March 5, 2006 (edited) That is fun. I fixed up a couple of things that weren't working, like the E,W,S animation and the firing, so here is the code: CODE ;Name: Battle.au3 ;Author: Lord_Doominik ;Status: In Progress (5%) ;Version: 0 Dim $bullet1[10000] Dim $bullet2[10000] $i = 0 $reloadtime = TimerInit() $ShootDir = "N" $ShootPosX = 0 $ShootPosY = 0 $Arena = GUICtrlCreatePic("Battlefields/Arena1.map", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Roboter1 = GUICreate("Roboter1", 32, 32, 330, 175, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) $Roboter1Pic = GUICtrlCreatePic("Vehicles/Panzer1 N.gif", 0, 0, 32, 32) GUISetState() $Roboter2 = GUICreate("Roboter2", 11, 21, 203, 550, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic("Vehicles/Roboter2.gif", 0, 0, 11, 21) GUISetState() ControlFocus("Robot Wars", "", $mainGUI) While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect $WinPos = WinGetPos("Robot Wars") Action() Shot() WEnd Func Action() $pos1 = WinGetPos("Roboter1") $x1 = 0 $y1 = 0 If _IsPressed("25") Then ;Left GUICtrlSetImage ( $Roboter1Pic, "Vehicles/Panzer1 W.gif" ) If Hex(PixelGetColor($pos1[0]+4, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+4, $pos1[1]+27), 6) <> "000000" Then $x1 -= 1 EndIf $ShootDir = "E" EndIf If _IsPressed("27") Then ;Right GUICtrlSetImage ( $Roboter1Pic, "Vehicles/Panzer1 O.gif" ) If Hex(PixelGetColor($pos1[0]+27, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+27, $pos1[1]+27), 6) <> "000000" Then $x1 += 1 EndIf $ShootDir = "W" EndIf If _IsPressed("26") Then ;Up GUICtrlSetImage ( $Roboter1Pic, "Vehicles/Panzer1 N.gif" ) If Hex(PixelGetColor($pos1[0]+16, $pos1[1]-1), 6) <> "000000" Or Hex(PixelGetColor($pos1[0]+17, $pos1[1]-1), 6) <> "000000" Or Hex(PixelGetColor($pos1[0]+18, $pos1[1]-1), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+5, $pos1[1]+2), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+26, $pos1[1]+2), 6) <> "000000" Then $y1 -= 1 EndIf $ShootDir = "N" EndIf If _IsPressed("28") Then ;Down GUICtrlSetImage ( $Roboter1Pic, "Vehicles/Panzer1 S.gif" ) If Hex(PixelGetColor($pos1[0]+5, $pos1[1]+29), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+26, $pos1[1]+29), 6) <> "000000" Then $y1 += 1 EndIf $ShootDir = "S" EndIf If (_IsPressed("20")) And (TimerDiff($reloadtime) >= 1000) Then GUISwitch($mainGUI) $i += 1 Switch $ShootDir Case "N" $ShootPosX = $pos1[0] - $WinPos[0] + 15 $ShootPosY = $pos1[1] - $WinPos[1] - 50 Case "S" $ShootPosX = $pos1[0] - $WinPos[0] + 15 $ShootPosY = $pos1[1] - $WinPos[1] + 50 Case "E" $ShootPosX = $pos1[0] - $WinPos[0] - 50 $ShootPosY = $pos1[1] - $WinPos[1] - 15 Case "W" $ShootPosX = $pos1[0] - $WinPos[0] + 50 $ShootPosY = $pos1[1] - $WinPos[1] - 15 ENDswitch $bullet1[$i] = GUICtrlCreateLabel("", $ShootPosX, $ShootPosY, 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() EndIf ControlMove("Roboter1", "", $Roboter1, $pos1[0]+$x1, $pos1[1]+$y1) EndFunc Func Shot() EndFunc Another thing you might want to look at is using a mask for the areas that cannot be travelled. I mean us the battle ground that you have as the mask that is not displayed to the user and use a nice picture for the screen. When moving the tank, check the colour of the pixel on the mask, not the background. There are APIs that can do this, don't know if anyone has written an AutoIt wrapper for them. Good work! Edited March 5, 2006 by Stumpii Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 5, 2006 Author Share Posted March 5, 2006 (edited) hm, why should i use a mask isntead of the bg??? what are the pros in this??? o.O and thx... i'll try your code... EDIT: ok, your script rotated the tank while moving but not places the bullet at the right point o.O Edited March 5, 2006 by Lord_Doominik Link to comment Share on other sites More sharing options...
Stumpii Posted March 5, 2006 Share Posted March 5, 2006 hm, why should i use a mask isntead of the bg??? what are the pros in this??? o.O and thx... i'll try your code...Wouldn't you rather have a background of rolling hills, a stream/river with bridge and farm houses, etc? And not be able to drive over the river, or on top of the houses!Looked at the GetPixel Win API and you need a device context that AutoIt does not provide for the graphic or pic GUI objects. The PictureBox does provide the hDC, so you could try and add a real PictureBox on the screen, load the mask, make it invisible, and use the GetPixel API to determine the obstactles.Alternativly, you could setup an array of triangular obstacles and do collision detection using them. Most 3D modelling program will let you create a layout of objects (triangles) and export them as .obj files. The .obj file contains the points that make up each triangle. You just need to read the data in as the program starts.Sounds a bit complex? You may not want to put that much work into it. It is up to you. Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
Stumpii Posted March 5, 2006 Share Posted March 5, 2006 hm, why should i use a mask isntead of the bg??? what are the pros in this??? o.O and thx... i'll try your code...EDIT: ok, your script rotated the tank while moving but not places the bullet at the right point o.OHmm, it does in mine. You had the bullet draw in co-ordinates relative to the screen, where as the tank is draw in screen coordinates. This meant that the bullet was always off (unless you have the screen in the top left of the desktop). I recalculated the bullet coordinates based on the position of the window also. Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity. Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 5, 2006 Author Share Posted March 5, 2006 (edited) evtl. you tried to, but it don't works with your code... EDIT: ahhh, ok, you done it... i was jsut confused about the position of the bullet, because it don't appears at the tank pipe ^^... THX vry much! Edited March 5, 2006 by Lord_Doominik 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