TheNorwegianUser Posted February 11, 2015 Posted February 11, 2015 I'm having some difficulties with a game. It's kinda like CurveFever (Achtung Die Kurve), but I just want it for personal 1P usage. The problem is just that I can't figure out a way to check if the line is colliding with any point of where it has been before. I know there are lots of ways to do it, but I always end up with the game running slow because of bad methods such as searching for pixels etc. Any suggestions on a faster method? (You would probably have to test the code yourself to know what I'm saying if you want to help :/ ) expandcollapse popup#include <misc.au3> #include <GDIPlus.au3> HotKeySet("{ESC}", "Terminate") #Region Win $WinWidth=895 $WinHeight=895 $hGUI=GUICreate("", $WinWidth, $WinHeight, -1, -1) GUISetBkColor(0x000000, $hGUI) GUISetState() #EndRegion #Region GDIPLUS _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) $hPen = _GDIPlus_PenCreate(0x9900FF00, 5) $hPenBorder = _GDIPlus_PenCreate(0xFFFFFFFF, 5) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $WinWidth-1, $WinHeight-1, $hPenBorder) #EndRegion #Region Vars $Width=56 $SpeedTime=100 $Switch=1 $x=5 $y=5 $VektorX=0 $VektorY=Sqrt($Width^2-($VektorX^2)) $Hole_Count=1 $Hole_MakeHole=Random(10, 1000, 1) Global $SpeedTime _GDIPlus_GraphicsDrawEllipse($hGraphic, $x, $y, 2.4, 2.4, $hPen) #EndRegion Sleep(1000) $Timer=TimerInit() While 1 If _IsPressed(25) Then TurnLeft() EndIf If _IsPressed(27) Then TurnRight() EndIf $x+=$VektorX/30 $y+=$VektorY/30 DrawLine() While TimerDiff($Timer)<$SpeedTime/6 WEnd $Timer=TimerInit() WEnd Func DrawLine() ;~ $Hole_Count+=1 If $Hole_Count>$Hole_MakeHole Then If $Hole_Count>$Hole_MakeHole+15 Then $Hole_Count=0 $Hole_MakeHole=Random(10, 1000, 1) EndIf Else _GDIPlus_GraphicsDrawEllipse($hGraphic, $x, $y, 2.4, 2.4, $hPen) EndIf EndFunc Func TurnLeft() If $Switch>0 Then $VektorX+=(2.5*$VektorY*$Switch)/$Width+0.0005 If $Switch<0 Then $VektorX-=(2.5*$VektorY*$Switch)/$Width+0.0005 If $VektorX>=$Width Then $Switch*=-1 $VektorX=$Width EndIf If $VektorX<=-$Width Then $Switch*=-1 $VektorX=-$Width EndIf $VektorY=Sqrt($Width^2-($VektorX^2))*$Switch EndFunc Func TurnRight() If $Switch>0 Then $VektorX-=(2.5*$VektorY*$Switch)/$Width+0.0005 If $Switch<0 Then $VektorX+=(2.5*$VektorY*$Switch)/$Width+0.0005 If $VektorX>=$Width Then $Switch*=-1 $VektorX=$Width EndIf If $VektorX<=-$Width Then $Switch*=-1 $VektorX=-$Width EndIf $VektorY=Sqrt($Width^2-($VektorX^2))*$Switch EndFunc Func Terminate() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_PenDispose($hPen) _GDIPlus_Shutdown() Exit EndFunc
Moderators JLogan3o13 Posted February 11, 2015 Moderators Posted February 11, 2015 On 2/11/2015 at 3:30 PM, TheNorwegianUser said: I'm having some difficulties with a game. It's kinda like CurveFever (Achtung Die Kurve), but I just want it for personal 1P usage. The problem is just that I can't figure out a way to check if the line is colliding with any point of where it has been before. I know there are lots of ways to do it, but I always end up with the game running slow because of bad methods such as searching for pixels etc. Any suggestions on a faster method? (You would probably have to test the code yourself to know what I'm saying if you want to help :/ ) TheNorwegianUser, you have been around long enough now that you should have read the Forum Rules (bottom right of every page). I would highly suggest you read them now, especially the part regarding Game Automation and Interaction (mainly because it's lame). "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators Melba23 Posted February 11, 2015 Moderators Posted February 11, 2015 JLogan3o13,This script is the embryo of a game written in AutoIt by the OP and as such is entirely legal. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators JLogan3o13 Posted February 11, 2015 Moderators Posted February 11, 2015 (edited) Sorry, I was apparently too hasty. I thought we'd backed off on even AutoIt-developed games (the "regardless of the game" segment in the rules). My apologies to the OP. Edited February 11, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
UEZ Posted February 12, 2015 Posted February 12, 2015 You can try to use _GDIPlus_BitmapGetPixel(): expandcollapse popup#include <misc.au3> #include <GDIPlus.au3> HotKeySet("{ESC}", "Terminate") #Region Win $WinWidth = 895 $WinHeight = 895 $hGUI = GUICreate("", $WinWidth, $WinHeight, -1, -1) GUISetBkColor(0x000000, $hGUI) GUISetState() #EndRegion Win #Region GDIPLUS _GDIPlus_Startup() $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($WinWidth, $WinHeight, $hGfx) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) $hPen = _GDIPlus_PenCreate(0x9900FF00, 5) $hPen2 = _GDIPlus_PenCreate(0xFFFFFF00, 1) $hPenBorder = _GDIPlus_PenCreate(0xFFFFFFFF, 5) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $WinWidth - 1, $WinHeight - 1, $hPenBorder) _GDIPlus_GraphicsDrawImage($hGfx, $hBitmap, 0, 0) #EndRegion GDIPLUS #Region Vars $Width = 56 $SpeedTime = 30 $Switch = 1 $x = 5 $y = 5 $VektorX = 0 $VektorY = Sqrt($Width ^ 2 - ($VektorX ^ 2)) $Hole_Count = 1 $Hole_MakeHole = Random(10, 1000, 1) Global $SpeedTime _GDIPlus_GraphicsDrawEllipse($hGraphic, $x, $y, 2.4, 2.4, $hPen) #EndRegion Vars Sleep(1000) $Timer = TimerInit() While 1 If _IsPressed(25) Then TurnLeft() EndIf If _IsPressed(27) Then TurnRight() EndIf $x += $VektorX / 30 $y += $VektorY / 30 DrawLine() While TimerDiff($Timer) < $SpeedTime WEnd $Timer = TimerInit() WEnd Func DrawLine() ;~ $Hole_Count+=1 If $Hole_Count > $Hole_MakeHole Then If $Hole_Count > $Hole_MakeHole + 15 Then $Hole_Count = 0 $Hole_MakeHole = Random(10, 1000, 1) EndIf Else If _GDIPlus_BitmapGetPixel($hBitmap, $x + $VektorX * 0.1025, $y + $VektorY * 0.1025) Then MsgBox(0, "Test", "Collision") _GDIPlus_GraphicsDrawEllipse($hGraphic, $x, $y, 2.4, 2.4, $hPen) _GDIPlus_GraphicsDrawImage($hGfx, $hBitmap, 0, 0) EndIf EndFunc ;==>DrawLine Func TurnLeft() If $Switch > 0 Then $VektorX += (2.5 * $VektorY * $Switch) / $Width + 0.0005 If $Switch < 0 Then $VektorX -= (2.5 * $VektorY * $Switch) / $Width + 0.0005 If $VektorX >= $Width Then $Switch *= -1 $VektorX = $Width EndIf If $VektorX <= -$Width Then $Switch *= -1 $VektorX = -$Width EndIf $VektorY = Sqrt($Width ^ 2 - ($VektorX ^ 2)) * $Switch EndFunc ;==>TurnLeft Func TurnRight() If $Switch > 0 Then $VektorX -= (2.5 * $VektorY * $Switch) / $Width + 0.0005 If $Switch < 0 Then $VektorX += (2.5 * $VektorY * $Switch) / $Width + 0.0005 If $VektorX >= $Width Then $Switch *= -1 $VektorX = $Width EndIf If $VektorX <= -$Width Then $Switch *= -1 $VektorX = -$Width EndIf $VektorY = Sqrt($Width ^ 2 - ($VektorX ^ 2)) * $Switch EndFunc ;==>TurnRight Func Terminate() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_Shutdown() Exit EndFunc ;==>Terminate Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Luigi Posted February 12, 2015 Posted February 12, 2015 I like! That is cool! Crazy! 8D Visit my repository
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