Jump to content

Lots of questions inside :P


Recommended Posts

Hello everyone!

I'm not really experienced with autoit, and I don't know why I decided to make a game in autoit, but after I thought about it I couldnt get it out of my head.

So, I spent like 10 minutes on this code, and it seems I have problems ^_^

First, the code:

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Misc.au3>

#include <Timers.au3>

Global $Enemy[9], $ScoreNow, $BulletPosX, $BulletPosY

Global $EnemyPosX[5]

Global $EnemyPosY[5]

Opt("GUIoneventmode", 1)

Opt("mousecoordmode", 2)

$dll = DllOpen("user32.dll")

HotKeySet("{esc}", "Esc")

$GUI = GUICreate('Game', 700, 340, -1, -1, -2138570616)

$Player = GUICtrlCreateRadio("", 0, 0, 15, 15)

$Score = GUICtrlCreateLabel("Score: ", 300, 0, 100, 15)

For $I = 1 To 4

$Enemy[$I] = GUICtrlCreateButton("What?", -30, -15, 40, 15)

Next

GUISetCursor(16, 1)

GUISetState(@SW_SHOW)

$Time_Go = _Timer_Init()

While 1

GUICtrlSetState($Player, $GUI_CHECKED)

Sleep(15)

$Follow = MouseGetPos()

GUICtrlSetPos($Player, $Follow[0], $Follow[1])

If _IsPressed("01", $dll) And _Timer_Diff($Time_Go) > 200 Then

Shoot()

$Time_Go = _Timer_Init()

EndIf

$Random = Random(1, 90, 1)

If $Random = 90 Then

Enemy()

EndIf

WEnd

Func Shoot()

$Shoot = GUICtrlCreateLabel("<=-", $Follow[0], $Follow[1], 15, 15)

For $I = 0 To 70

Sleep(1)

$BulletPosX = $Follow[0] - $I * 10

$BulletPosY = $Follow[1]

GUICtrlSetPos($Shoot, $BulletPosX, $BulletPosY, 15, 15)

If $BulletPosX > $EnemyPosX[1] And $BulletPosX < $EnemyPosX[1] + 40 And $BulletPosY > $EnemyPosY[1] And $BulletPosY < $EnemyPosY[1] + 15 Then

$ScoreNow += $ScoreNow + 1

GUICtrlSetData($Score, "Score: " & $ScoreNow)

EndIf

Next

EndFunc ;==>Shoot

Func Enemy()

For $I = 1 To 4

$EnemyPosX[$I] = Random(0, 650, 1)

$EnemyPosY[$I] = Random(0, 340, 1)

GUICtrlSetPos($Enemy[$I], $EnemyPosX[$I], $EnemyPosY[$I])

GUICtrlSetBkColor($Enemy[1], 0xff0000)

Next

EndFunc ;==>Enemy

Func Esc()

Exit 0

EndFunc ;==>Esc

You can just copypaste that into autoit, compile and see whats going on to understand my questions better xD

Basically you control a GuiCtrlCreateRadio thing, shoot labels "<=-" and your goal is to hit the red "What?" box.

#1

$ScoreNow += $ScoreNow+ 1
and
GUICtrlSetData($Score, "Score: " & $ScoreNow)
are supposed to increase your score. For some reason it increases exponentially, it should be like 15 points for each correct shot, but it gives 15,250,1000,4000 etc. Howcome?

#2 When you shoot, the game freezes because its calculating the shot movement:

For $I = 0 To 70
        Sleep(1)
        $BulletPosX = $Follow[0] - $I * 10

How do you make autoit calculate the shot movement without freezing the whole game?

#3 Is it possible to change the whole GUI into a semi-transparant picture? Like a GIF with transparant background or jpg with opacity.

#4 Is there some kind of range macro in autoit? e.g. @Range(1,100) would mean any number from 1 to 100.

I know you can use For $Var = 1 to 100, but thats not exactly what I'm looking for. I need something like:

If $Var1=@Range(1,100) Then....;If $Var is any number from 1 to 100 then...

Thanks in advance! I hope my questions will be answered ;)

Edited by Qousio
Link to comment
Share on other sites

#1

Your using the Incremental operater "+=" which will add whatever ever value is right of the operater to the variable on the left.

Your problem is that your telling Autoit to increment the variable by 1+its current value.

So just "$ScoreNow += 15" should work OK.

#2

The player node stops moving when you shoot because AutoIt is incapable of doing two loops at once. If i were you id make a function that moves the player node by itself then use it with the AdlibEnable() function.

#3

i think theres an example of someone doing this with Png images. Try doing a quick search for it ^_^

#4

If $Var <= 100 And $var >= 1 Then

;Var is witin number range

endif

hope i helped.

*EDIT*

Fixed the error in the number range bit

Edited by Marlo
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

#1

Your using the Incremental operater "+=" which will add whatever ever value is right of the operater to the variable on the left.

Your problem is that your telling Autoit to increment the variable by 1+its current value.

So just "$ScoreNow += 15" should work OK.

#2

The player node stops moving when you shoot because AutoIt is incapable of doing two loops at once. If i were you id make a function that moves the player node by itself then use it with the AdlibEnable() function.

#3

i think theres an example of someone doing this with Png images. Try doing a quick search for it ^_^

#4

If $Var <= 100 And >= 1 Then

;Var is witin number range

endif

hope i helped.

Thanks for your answers! I will search the .png example and some adlib examples right now and see what I can do with them ;)

Link to comment
Share on other sites

#1

Wow, did a Forum database upgrade cause this funky code corruption?

;$ScoreNow += $ScoreNow + 1
$ScoreNow += 15oÝ÷ Ûf(»¥è­êçyçm¢ÊeÛazèqë,{h¶ÞiÛª®¢Ún¨º¸Zº.´ojwvËn}ú®¢×+^h:½éí±û§rبڭ椢ëh~Ø^jwç$jw¯z{j¹ë¢z-²"^ºÇ¶)­Æ¥¶Ú-®( z¶¬µêbØ^jx¦jب·¦¢÷­æ§f­ÚÚ'+!£
®¢Øb¶«¨¶êºfË*ºZêí²H§u©bæÚ¶Ù^²©¢Ø^®g­l!ƧßÛkyÆ¥«m+-g·N«yªÞr§¶W¬±ìZ^²í+"Ø^~îÇhj«¢rKj·!jwr¢ì"WâÖ{âÚgÚÚÊZ­éÜÉ©Ý2>á«­¢+Øí%ÀÌØíYÈÄõI¹ Ä°ÄÀÀ¤Q¡¸¸¸¸¸í%ÀÌØíYȥ̹ä¹ÕµÈɽ´ÄѼÄÀÀÑ¡¸¸¸¸)M±Ð(%

ÍÄQ¼ÄÀÀ($$ì!¥Ð(%

ͱÍ($$ì5¥ÍÌ)¹M±
Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

I fixed pretty much everything I wanted to fix... Except calculating the shot movement ;)

I tried using AdLib but it just doesnt work as intended :(

...use a timer callback to trigger a step in the animation.

Thanks for the reply Zinthose!

But how would I do this? ^_^

Link to comment
Share on other sites

I fixed pretty much everything I wanted to fix... Except calculating the shot movement ;)

I tried using AdLib but it just doesnt work as intended :(

Thanks for the reply Zinthose!

But how would I do this? ^_^

I threw this together, it's not very clean but works and is kinda cool. :D

#include 'timers.au3'
#include 'GUIConstantsEx.au3'
#include 'WindowsConstants.au3'
#include 'array.au3'

#include 'debug.au3'
;_DebugSetup(@ScriptName)

Global $Bullets[1] = [0]

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

$hGUI = GUICreate("Timers Using CallBack Function(s)", 400, 320, -1, -1, BitOR($WS_POPUP,$WS_CLIPSIBLINGS), 0)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,   "_ShootLeft",   $hGUI)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_ShootRight",  $hGUI)
GUISetState(@SW_SHOW)

Global $Timer = _Timer_SetTimer($hGUI, 20, "_AnimationCycle")

Func _AnimationCycle($hWnd, $Msg, $iIDTimer, $dwTime)
    Local $i, $pos, $direction, $speed, $handle, $deleted[1] = [0]
    
    ;## Animate Bullets
        For $i = 1 To $Bullets[0]
            If $Bullets[$i] = -1 Then ContinueLoop
            
            $handle = GUICtrlGetHandle($Bullets[$i])
            $pos = WinGetPos($handle)
            
            $direction = GUICtrlRead($Bullets[$i])

            If $direction = "<==" Then
                $speed = -5
            Else
                $speed = 5
            EndIf
            
            $winPos = WinGetPos($hGUI)
            $pos[0] = $pos[0] - $winPos[0]
            $pos[1] = $pos[1] - $winPos[1]
            
            If $pos[0] < 0 Or $pos[0] > $winPos[2] Then
                GUICtrlDelete($Bullets[$i])
                $Bullets[$i] = -1
                _ArrayAdd($deleted, $i)
                ContinueLoop
            EndIf
            
            GUICtrlSetPos($Bullets[$i], $pos[0] + $speed, $pos[1])

            $pos = WinGetPos($handle)
            _DebugOut("$pos[0] = " & $pos[0])
            _DebugOut("$pos[1] = " & $pos[1])
        Next
    
        ;## Clean up removed bullets
            For $i = 1 To $deleted[0]
                _ArrayDelete($Bullets, $i)
            Next
    
EndFunc

Sleep(30000)
_Timer_KillAllTimers($hGUI)

Func _ShootLeft()
    Local $pos, $newBullet
    
    $pos = MouseGetPos()
    
    ;## Create Bullet
        $newBullet = GUICtrlCreateLabel("<==", $pos[0], $pos[1], 15, 15)
        
    ;## Add Bullet to the Active Bullents Array
        _ArrayAdd($Bullets, $newBullet)
        $Bullets[0] += 1
EndFunc

Func _ShootRight()
    Local $pos, $newBullet
    
    $pos = MouseGetPos()
    
    ;## Create Bullet
        $newBullet = GUICtrlCreateLabel("==>", $pos[0], $pos[1], 15, 15)
        
    ;## Add Bullet to the Active Bullents Array
        _ArrayAdd($Bullets, $newBullet)
        $Bullets[0] += 1
EndFunc

EDIT: Added a garbage collector to clean up all the empty bullet shells :D

Edited by Zinthose

--- TTFN

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...