#SingleInstance Force #Persistent #NoEnv SetWorkingDir %A_ScriptDir% Process, Priority, , High SetBatchLines, -1 OnExit, ExitSub /* 'Sound Engine',sounds coool doesn't it.... yeahhh / parentPid := DllCall("GetCurrentProcessId") / Sound quite simply needs to be run separately,even from one another,unless multiple threads are used, which is sort of a mess in ahk even using autohotkey.dll or with ahk_h. */ pseudoThread_soundEngine_cannon= ( ~Space:
: SoundPlay, cannon.wav while GetKeyState("Space") { Sleep, 55 ;corresponds to the length in ms of the cannon fire sound effect SoundPlay, cannon.wav } SoundPlay, stopPlayback.wav return ) _pseudoThread_soundEngine_engine = ( ~Up:: ElapsedTime(1, true) SoundPlay, engine.wav while GetKeyState("Up") { x := ElapsedTime() if ( x > 4750) ;corresponds to the length in ms of the engine sound effect { ElapsedTime(1, true)
SoundPlay, engine.wav } } SoundPlay, stopPlayback.wav return ElapsedTime(p_Timer=1,p_Start=false) { static timer_1,timer_2,timer_3,timer_4,timer_5,timer_6,timer_7,timer_8,timer_9 static timer_CheckFiles ;-- Example of meaningful timer nameif p_Start { timer_%p_Timer%:=A_TickCount l_ElapsedTime=0 } else l_ElapsedTime:=A_TickCount-timer_%p_Timer% return l_ElapsedTime }
)
_pseudoThread_begin(_pseudoThread_soundEngine_cannon,"_pseudoThread_soundEngine_cannon")
_pseudoThread_begin(_pseudoThread_soundEngine_engine,"_pseudoThread_soundEngine_engine")
_pseudoThread_begin(pseudoThreadName, pseudoThreadVarName) {
Global
/*
pseudoThreadActual sole purpose is a work around to retrieve the actual name of a variable while also retriving it's
contents,i don't quite think there is a way to do that. Will remove it if i happen to find a way.
*/;when parent process stops all child processes also die
/*
When creating pseudoThreads make sure any variable refrences like '%i%' are nullified with '' ,as in '
%i`%'
to retain variable refrence for in-"thread" use.
*/
parentPid := DllCall("GetCurrentProcessId")/*
TO TERMINATE A SPECIFIC THREAD...
A 'FileAppend, , pseudoThreadName.end_pThread' Command followed by 'Reload' should reload script without the
specified thread,other approaches could be taken here but,it is the simplest method.
*/
IfExist, %pseudoThreadName%.end_pThread ;rediculous but simplest way of terminating specific thread
{
FileDelete %pseudoThreadName%.end_pThread
Return ;functions exits here
};Create,Run then Destroy File
FileDelete, %pseudoThreadVarName%.ahk ;just in case deletion did not occur at end of thread start,like incase of a power outage
FileAppend,
(
;-------------------INIT----------------------;
#SingleInstance, force
#NoTrayIcon
Loop
{
Process, Exist, %parentPid% ;to terminate child instance when parent instance dies....how tragic:(
if (ErrorLevel = 0)
{
ExitApp
}
}
;-------------------INIT----------------------;
%pseudoThreadName%
), %pseudoThreadVarName%.ahk
;A_AhkPath
;For non-compiled scripts: The full path and name of the EXE file that is actually running the current script. For example: C:\Program Files\AutoHotkey\AutoHotkey.exe
Run, %A_AhkPath% %pseudoThreadVarName%.ahk ;incase for some reason ahk is not installed,or portable ahk is being used.
; FileDelete, %pseudoThreadName%.ahk
}Left:="Left" ; turn left
Right:="Right" ; turn right
Up:="Up" ; move forward
Down:="Down" ; move backward
Space:="Space" ; use weaponVarSetCapacity(ptWin, 16, 0)
NumPut(W:=512, ptWin, 8) , NumPut(H:=384, ptWin, 12)
Gui, Show, w%W% h%H%, AHKroid
hdcWin := DllCall("GetDC", "UInt", hwnd:=WinExist("A"))
hdcMem := DllCall("CreateCompatibleDC", "UInt", hdcWin)
hbm := DllCall("CreateCompatibleBitmap", "uint", hdcWin, "int", W, "int", H)
DllCall("SelectObject", "uint", hdcMem, "uint", hbm)X:=W/2 , Y:=H/2 , Vx:=Vy:=Va:=cd:=score:=0 , shield:="||||||||||" , nRoid:=6
formS1:="0,0,10,5,0,-15,-10,5,0,0"
formS2:="0,10,10,5,0,-15,-10,5,0,10"
VarSetCapacity(ptShip, 40)formB1:="-1,0,0,-1,1,0,0,1,-1,0"
VarSetCapacity(ptBall, 40)formR1:="-12,-28,0,-20,16,-28,28,-16,16,-8,28,8,12,28,-8,20,-16,28,-28,16,-20,0,-28,-16,-12,-28"
formR2:="-6,-14,0,-10,8,-14,14,-8,8,-4,14,4,6,14,-4,10,-8,14,-14,8,-10,0,-14,-8,-6,-14"
formR3:="-3,-7,-0,-5,4,-7,7,-4,4,-2,7,2,3,7,-2,5,-4,7,-7,4,-5,0,-7,-4,-3,-7"
VarSetCapacity(ptRoid, 104)
loop %nRoid%
listRoid .= "|1," rand(0, W, X) "," rand(0, H, Y) "," rand(0.0, 6)-3 "," rand(0.0, 6)-3SetTimer, Update, 25
return; --------------------------------
Update:
CriticalDllCall("FillRect", "uint", hdcMem, "uint", &ptWin, "uint", 0)
DllCall("TextOut", "uint", hdcMem, "uint", 16, "uint", 8, "uint", &score, "uint", StrLen(score))
DllCall("TextOut", "uint", hdcMem, "uint", 16, "uint", 24, "uint", &shield, "uint", StrLen(shield)); ----
Va += GetKeyState(Left) ? -0.1 : GetKeyState(Right) ? 0.1 : 0
formS0:="" , form := GetKeyState(Up) ? formS2 : formS1
loop, parse, form, `,
a_index & 1 ? i1:=a_loopfield : formS0 .= i1cos(Va)-a_loopfieldsin(Va) "," i1sin(Va)+a_loopfieldcos(Va) ","Vs := GetKeyState(Up) ? 0.4 : GetKeyState(Down) ? -0.2 : 0
Vx:=Vx0.95+sin(Va)Vs , Vy:=Vy0.95-cos(Va)Vs
X:= XW ? 0 : X+Vx , Y:= YH ? 0 : Y+VyDllCall("DeleteObject", "UInt", hShip)
loop, parse, formS0, `,
NumPut(a_loopfield+(a_index & 1 ? X : Y), ptShip, a_index*4-4)
DllCall("Polyline", "uint", hdcMem, "uint", &ptShip, "int", 5)
hShip := DllCall("CreatePolygonRgn", "uint", &ptShip, "int", 4, "int", 1); ----
cd-= cd>0 ? 1 : 0
if ( GetKeyState(Space) && cd=0 )
cd:=5 , listBall .= "|" a_tickcount "," X+sin(Va)10 "," Y-cos(Va)10 "," Valoop, parse, listBall, |
{
if a_index=1
continue
loop, parse, a_loopfield,,
,
i%a_index%:=a_loopfield
if (i1+1000 < a_tickcount) {
StringReplace, listBall, listBall, % "|" i1 "," i2 "," i3 "," i4 ,
continue
}
iX:=i2+sin(i4)*8 , iY:=i3-cos(i4)*8
iX:= iX<0 ? W : iX>W ? 0 : iX , iY:= iY<0 ? H : iY>H ? 0 : iY
StringReplace, listBall, listBall, % "|" i1 "," i2 "," i3 "," i4 , % "|" i1 "," iX "," iY "," i4
loop, parse, formB1,
NumPut(a_loopfield+(a_index & 1 ? iX : iY), ptBall, a_index*4-4)
DllCall("Polyline", "uint", hdcMem, "uint", &ptBall, "int", 5)
}; ----
loop, parse, listRoid, |
{
id:=a_index-1
if a_index=1
continue
loop, parse, a_loopfield,,
,
i%a_index%:=a_loopfield
iX:= i2+i4<0 ? W : i2+i4>W ? 0 : i2+i4 , iY:= i3+i5<0 ? H : i3+i5>H ? 0 : i3+i5
StringReplace, listRoid, listRoid, % "|" i1 "," i2 "," i3 "," i4 "," i5 , % "|" i1 "," iX "," iY "," i4 "," i5
loop, parse, formR%i1%,
NumPut(a_loopfield+(a_index & 1 ? iX : iY), ptRoid, a_index*4-4)
DllCall("Polyline", "uint", hdcMem, "uint", &ptRoid, "int", 13)
hRoid := DllCall("CreatePolygonRgn", "uint", &ptRoid, "int", 12, "int", 1)loop, parse, listBall, |
{
if a_index=1
continue
loop, parse, a_loopfield, `,
t%a_index%:=a_loopfield
if ( DllCall("PtInRegion", "uint", hRoid, "uint", t2, "uint", t3) <> 0 )
{
StringReplace, listBall, listBall, % "|" t1 "," t2 "," t3 "," t4 ,
StringReplace, listRoid, listRoid, % "|" i1 "," iX "," iY "," i4 "," i5 ,
score+=i1*5
if (i1<3) {
i1++
loop 2
listRoid .= "|" i1 "," iX "," iY "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
}
}
}if ( DllCall("CombineRgn", "uint", hRoid, "uint", hRoid, "uint", hShip, "int", 1) <> 1 ) {
Vx:=i4 , Vy:=i5
shield := SubStr(shield, 1, -1)
if (shield="") {
SoundPlay, explosion.wav, wait
msgbox %score% points
Reload
}
StringReplace, listRoid, listRoid, % "|" i1 "," iX "," iY "," i4 "," i5 ,
if (i1<3) {
i1++
loop 2
listRoid .= "|" i1 "," iX "," iY "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
}
}DllCall("DeleteObject", "UInt", hRoid)
}; -----
if (id<nRoid-1) {
nRoid++ , shield.="|"
loop %nRoid%
listRoid .= "|1," rand(0, W, X) "," rand(0, H, Y) "," rand(0.0, 6)-3 "," rand(0.0, 6)-3
}DllCall("BitBlt", "uint", hdcWin, "int", 0, "int", 0, "int", W, "int", H, "uint", hdcMem, "int", 0, "int", 0, "uint", 0xCC0020)
return; --------------------------------
Rand(min=0, max=1, mask="") {
loop {
Random, result, min, max
if ( mask="" || resultmask+100 )
return result
}
}ExitSub:
guiclose:
DllCall("DeleteObject", "UInt", hShip)
DllCall("DeleteObject", "UInt", hRoid)
DllCall("DeleteObject", "UInt", hbm)
DllCall("DeleteDC", "UInt", hdcMem)
DllCall("ReleaseDC", "UInt", hwnd, "UInt", hdcWin)
exitapp