Lord_Doominik Posted March 13, 2006 Share Posted March 13, 2006 (edited) Hm, I've got big performance problems with my game... If you shoot much bulelts in a row without waiting until all are expired the game becomes sooo laggy o.O... But I really don't know what to do... EDIT: oh, sry posted it in the wrong section, plz move it to v3support, thx!TPT_Tank_Wars.rar Edited March 13, 2006 by Lord_Doominik Link to comment Share on other sites More sharing options...
Valuater Posted March 13, 2006 Share Posted March 13, 2006 Maybe Raise the wait/reload timer or expandcollapse popup;Name: Battle.au3 ;Author: Lord_Doominik ;Status: In Progress (50%) ;Version: 0.5 Dim $bullet1[50] Dim $ShootDir1[50] Dim $ShootPosX1[50] Dim $ShootPosY1[50] Dim $bullet2[50] $Shot = 0 $i = 0 $l = 0 $reloadtime = TimerInit() $wallcheck = TimerInit() $Arena = GUICtrlCreatePic("Battlefields/Arena1.map", 0, 0, 800, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Tank1 = GUICreate("Tank1", 32, 32, 330, 175, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) $Tank1Pic = GUICtrlCreatePic("Vehicles/Panzer1 N.gif", 0, 0, 32, 32) GUISetState() $Tank2 = GUICreate("Tank2", 11, 21, 203, 550, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $mainGUI) GUICtrlCreatePic("Vehicles/Roboter2.gif", 0, 0, 11, 21) GUISetState() ControlFocus("Tank Wars", "", $mainGUI) While 1 $bmsg = GUIGetMsg() Select Case $bmsg = $GUI_EVENT_CLOSE Exit EndSelect $WinPos = WinGetPos("Tank Wars") Action() Shot() WEnd Func Action() $pos1 = WinGetPos("Tank1") $x1 = 0 $y1 = 0 If _IsPressed("25") Then;Left If Hex(PixelGetColor($pos1[0]+4, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+4, $pos1[1]+27), 6) <> "000000" Then GUICtrlSetImage($Tank1Pic, "Vehicles/Panzer1 W.gif") $ShootDir1[$i] = "E" $x1 -= 1 EndIf ElseIf _IsPressed("27") Then;Right If Hex(PixelGetColor($pos1[0]+27, $pos1[1]), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+27, $pos1[1]+27), 6) <> "000000" Then GUICtrlSetImage($Tank1Pic, "Vehicles/Panzer1 O.gif") $ShootDir1[$i] = "W" $x1 += 1 EndIf ElseIf _IsPressed("26") Then;Up 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 GUICtrlSetImage ($Tank1Pic, "Vehicles/Panzer1 N.gif") $ShootDir1[$i] = "N" $y1 -= 1 EndIf ElseIf _IsPressed("28") Then;Down If Hex(PixelGetColor($pos1[0]+5, $pos1[1]+29), 6) <> "000000" And Hex(PixelGetColor($pos1[0]+26, $pos1[1]+29), 6) <> "000000" Then GUICtrlSetImage($Tank1Pic, "Vehicles/Panzer1 S.gif") $ShootDir1[$i] = "S" $y1 += 1 EndIf EndIf If (_IsPressed("20")) And (TimerDiff($reloadtime) >= 2000) And $Shot = 0 Then GUISwitch($mainGUI) Switch $ShootDir1[$i] Case "N" $ShootPosX1[$i] = $pos1[0] - $WinPos[0] + 11.5 $ShootPosY1[$i] = $pos1[1] - $WinPos[1] - 24 Case "S" $ShootPosX1[$i] = $pos1[0] - $WinPos[0] + 11.5 $ShootPosY1[$i] = $pos1[1] - $WinPos[1] + 11 Case "E" $ShootPosX1[$i] = $pos1[0] - $WinPos[0] - 7 $ShootPosY1[$i] = $pos1[1] - $WinPos[1] - 7 Case "W" $ShootPosX1[$i] = $pos1[0] - $WinPos[0] + 29 $ShootPosY1[$i] = $pos1[1] - $WinPos[1] - 7 EndSwitch $bullet1[$i] = GUICtrlCreateLabel("", $ShootPosX1, $ShootPosY1, 3, 2) GUICtrlSetBkColor(-1, 0xFF0000) $reloadtime = TimerInit() $Shot = 1 $i += 1 $ShootDir1[$i] = $ShootDir1[$i-1] EndIf ControlMove("Tank1", "", $Tank1, $pos1[0]+$x1, $pos1[1]+$y1) EndFunc Func Shot() For $j = 0 To $i-1 Switch $ShootDir1[$j] Case "N" $ShootPosY1[$j] -= 4 Case "S" $ShootPosY1[$j] += 4 Case "E" $ShootPosX1[$j] -= 4 Case "W" $ShootPosX1[$j] += 4 EndSwitch GUICtrlSetPos($bullet1[$j], $ShootPosX1[$j], $ShootPosY1[$j]) If _CheckHitArenaWalls($ShootPosX1[$j], $ShootPosY1[$j], "Battlefields\Arena1") = 1 And $bullet1[$j] <> 0 Then GUICtrlDelete($bullet1[$j]) $bullet1[$j] = 0 $ShootDir1[$j] = 0 $ShootPosX1[$j] = 0 $ShootPosY1[$j] = 0 $Shot = 0 $l += 1 If $l = $i Then $ShootDir1[0] = $ShootDir1[$i] $i = 0 $l = 0 EndIf EndIf Next EndFunc Func _CheckHitArenaWalls($bullet_X, $bullet_Y, $arenaname) $number_of_blocks = IniRead($arenaname&".dat", "global", "number_of_blocks", 0) For $k = 1 to $number_of_blocks $arena_bottomwall_y = IniRead($arenaname&".dat", "block"&$k, "bottom", 0 ) $arena_leftwall_x = IniRead($arenaname&".dat", "block"&$k, "left", 0 ) $arena_rightwall_x = IniRead($arenaname&".dat", "block"&$k, "right", 0 ) $arena_topwall_y = IniRead($arenaname&".dat", "block"&$k, "top", 0 ) $arena_method = IniRead($arenaname&".dat", "block"&$k, "col_method", "in") If $arena_method = "out" Then 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 return 1 EndIf ElseIf $arena_method = "in" Then If $bullet_X >= $arena_leftwall_x And $bullet_X <= $arena_rightwall_x And $bullet_Y >= $arena_topwall_y And $bullet_Y <= $arena_bottomwall_y Then return 1 EndIf EndIf Next Return 0 EndFunc 8) Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 13, 2006 Author Share Posted March 13, 2006 (edited) hm, reload timer is at the moment at 2secs, i think that's high enaugh... can you plz jsut upload your change or say what did you changed??? i don't see a difference between my prog there o.O but thx for your answer... EDIT: ah, ok saw the difference, but i don't want to have jsut 1 shot at the same time at the display... later there should be 2 or more tanks fighting against and wit hjsut 1 shot at the display it would suxx... it is bad, too, because it also is slower with only 1 shot at the display... Edited March 13, 2006 by Lord_Doominik Link to comment Share on other sites More sharing options...
Valuater Posted March 13, 2006 Share Posted March 13, 2006 (edited) on the last one i helped you with... i could understand you taking out the sleep... but i sure thought tht explosion i made was really good! it looked alot better 8) Edited March 13, 2006 by Valuater Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 13, 2006 Author Share Posted March 13, 2006 lol, but that's not my problem... i'll make an explosion, but 1st a better one and 2nd i have first fix the performance problems... my problem isn't to get an explosion or something, my prob is the slower gamespeed while a shot is flying! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 13, 2006 Moderators Share Posted March 13, 2006 Come on Val, don't you know... he can't figure it out, so he's thankless for any and all efforts provided for him... I gave up trying to help him when he looked the gift horse in the mouth! 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. Link to comment Share on other sites More sharing options...
nfwu Posted March 14, 2006 Share Posted March 14, 2006 @Lord_Doominik: Ignore the PM i sent you... I gottit now... from here. did not realise that this topic exists! OK, so your problem is: Slow game speed while bullet is flying. 2 Solutions: 1) Check for collision once every 10 "loops" 2) Store the data in the arena's *.dat file in an array instead of calling INIREAD all the time. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 14, 2006 Author Share Posted March 14, 2006 @nfwu hm, i'll try this, looks helpfull... don't was aware about that it would be slow it much, when i always read the ini... i just tryed to run the loop every 10 times, but that doesn't made it better... but i can try it another time ^^. @smoke i just am tired of this "solutions" which aren't some hint for me... i could use the explosion later, but this is at the moment not my main problem... Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 14, 2006 Author Share Posted March 14, 2006 @nfwu whoaaa, big thanks, i've solved it... the problem was, that the it took so long to read the ini every time... now i've did a function which initialize the arena before the game and then just take the array for reading the values... Link to comment Share on other sites More sharing options...
nfwu Posted March 16, 2006 Share Posted March 16, 2006 For some reason, this: Func _CheckHitArenaWalls($bullet_X, $bullet_Y, $arenaname) $number_of_blocks = IniRead($arenaname&".dat", "global", "number_of_blocks", 0) For $k = 1 to $number_of_blocks $arena_bottomwall_y = IniRead($arenaname&".dat", "block"&$k, "bottom", 0 ) $arena_leftwall_x = IniRead($arenaname&".dat", "block"&$k, "left", 0 ) $arena_rightwall_x = IniRead($arenaname&".dat", "block"&$k, "right", 0 ) $arena_topwall_y = IniRead($arenaname&".dat", "block"&$k, "top", 0 ) $arena_method = IniRead($arenaname&".dat", "block"&$k, "col_method", "in") If $arena_method = "out" Then 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 return 1 EndIf ElseIf $arena_method = "in" Then If $bullet_X >= $arena_leftwall_x And $bullet_X <= $arena_rightwall_x And $bullet_Y >= $arena_topwall_y And $bullet_Y <= $arena_bottomwall_y Then return 1 EndIf EndIf Next Return 0 EndFunc looks very familiar.... ??? #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 17, 2006 Author Share Posted March 17, 2006 ye ... hm, i've done it this way: $arena = "Battlefields\Arena1" $number_of_blocks = 0 Dim $arena_bottomwall_y[100] Dim $arena_leftwall_x[100] Dim $arena_rightwall_x[100] Dim $arena_topwall_y[100] Dim $arena_method[100] Initialize($arena) Func Initialize($arenaname) $number_of_blocks = IniRead($arenaname&".dat", "global", "number_of_blocks", 0) For $k = 1 to $number_of_blocks $arena_bottomwall_y[$k] = IniRead($arenaname&".dat", "block"&$k, "bottom", 0) $arena_leftwall_x[$k] = IniRead($arenaname&".dat", "block"&$k, "left", 0 ) $arena_rightwall_x[$k] = IniRead($arenaname&".dat", "block"&$k, "right", 0) $arena_topwall_y[$k] = IniRead($arenaname&".dat", "block"&$k, "top", 0) $arena_method[$k] = IniRead($arenaname&".dat", "block"&$k, "col_method", "in") Next GUICtrlDelete($Start) GUICtrlDelete($Options) GUICtrlDelete($About) GUICtrlDelete($Exit) EndFunc and then just: Func _CheckHitArenaWalls($bullet_X, $bullet_Y) For $k = 1 to $number_of_blocks If $arena_method[$k] = "out" Then If $bullet_X <= $arena_leftwall_x[$k] Or $bullet_X >= $arena_rightwall_x[$k] Or $bullet_Y <= $arena_topwall_y[$k] Or $bullet_Y >= $arena_bottomwall_y[$k] Then return 1 EndIf ElseIf $arena_method[$k] = "in" Then If $bullet_X >= $arena_leftwall_x[$k] And $bullet_X <= $arena_rightwall_x[$k] And $bullet_Y >= $arena_topwall_y[$k] And $bullet_Y <= $arena_bottomwall_y[$k] Then return 1 EndIf EndIf Next Return 0 EndFunc Link to comment Share on other sites More sharing options...
nfwu Posted March 18, 2006 Share Posted March 18, 2006 OffTopic: Your first version on TankWars in the Support forum looks as if you have coded in the Allegro graphics library for C++ before. Because you used PixelGetColor(), AutoIt "close" equivelent of Allegro's getpixel function... Just wondering... #) p.s. the book I have on Allegro also has a sample game called Tank Wars. Are you making an AutoIt clone of that? TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Lord_Doominik Posted March 19, 2006 Author Share Posted March 19, 2006 no, it's jsut my idea... or a copy of these old dos tank war games, but i don't know allegro ^^... hm, ye, my first version was a big instable and buggy, cause autoit had problems with pixelgetcolor ^^... now it's better solved and i can paint the walls as i want ^^... 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