Jump to content

Recommended Posts

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 :/ )

#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
Link to comment
Share on other sites

  • Moderators

 

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!

Link to comment
Share on other sites

  • Moderators

JLogan3o13,

This script is the embryo of a game written in AutoIt by the OP and as such is entirely legal. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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 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!

Link to comment
Share on other sites

You can try to use _GDIPlus_BitmapGetPixel():

#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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...