It uses line intersects to detect collisions rather than using the more traditional distance between two points method.
The game is in a very basic form.
Spoiler
Code: Select all
;********************************************************************************************************************************************************************************************
#Include, <My Altered GDIP LIB> ;GDIP.AHK
;********************************************************************************************************************************************************************************************
#SingleInstance, Force
SetBatchlines, -1
CoordMode, Mouse, Screen
Gdip_Startup()
Main := {}
Main.Gui1 := New PopUpWindow( { X: A_ScreenWidth / 2 - 400 , Y: A_ScreenHeight - 500 , W: 800 , H: 400 , Options: " -DPIScale +AlwaysOnTop " , AutoShow: 1 } )
Main.Pen1 := Gdip_CreatePen( "0xFF000000" , 3 )
Main.Pen2 := Gdip_CreatePen( "0xFF0066FF" , 3 )
Main.Pen3 := Gdip_CreatePen( "0xFF0000FF" , 3 )
Main.Pen4 := Gdip_CreatePen( "0xFFFF0000" , 3 )
Main.Brush1 := Gdip_BrushCreateSolid( "0xFFff0000" )
Main.Brush2 := Gdip_BrushCreateSolid( "0xFF0000FF" )
Main.Gui2 := New PopUpWindow( { X: A_ScreenWidth / 2 - 400 , Y: A_ScreenHeight - 500 , W: 800 , H: 400 , Options: " -DPIScale +AlwaysOnTop " , AutoShow: 1 } )
Main.Gui2.DrawBitmap( HB_BITMAP_MAKER() , { X: 0 , Y: Main.Gui2.H / 3 * 2 , W: Main.Gui2.W , H: Main.Gui2.H / 3 } , dispose := 1 )
Main.Gui2.UpdateWindow()
Bob := New Missile( Main )
Score := 0
Health := 10
Lasers := []
SetTimer, GameLoop, 30
return
GuiContextMenu:
*ESC::ExitApp
Numpad3::PopUpWindow.Helper()
GameLoop:
Main.Gui1.ClearWindow()
Bob.Update(Main)
Loop, % Lasers.Length() {
Lasers[ Lasers.Length() - A_Index + 1 ].Update( Main )
if ( Lasers[ Lasers.Length() - A_Index + 1 ].CheckWalls() )
Lasers.RemoveAt( Lasers.Length() - A_Index + 1 )
else
Lasers[ Lasers.Length() - A_Index + 1 ].Draw( Main )
if( Lasers[ Lasers.Length() - A_Index + 1 ].CheckHit( Bob ) ){
Bob := New Missile( Main )
Hit := New HB_Vector( Lasers[ Lasers.Length() - A_Index + 1 ].Hit.X , Lasers[ Lasers.Length() - A_Index + 1 ].Hit.Y )
Lasers.RemoveAt( Lasers.Length() - A_Index + 1 )
cc := 1 , rad := 10 , ++Score
}
}
if( cc && ++cc < 20 ){
Gdip_FillEllipse( Main.Gui1.G , Main.Brush1 , Hit.X - rad , Hit.Y - rad , rad * 2 , rad * 2 )
rad += 5
}
( cc > 20 && ! cc := 0)
if( --Bob.Life = 0 ){
Bob := New Missile( Main )
Health--
}
Gdip_TextToGraphics( Main.Gui1.G , "Score: " Score , "s26 Bold c" Main.Brush2 " x0 y0" , "Segoe ui" , 322 , 22 )
Gdip_TextToGraphics( Main.Gui1.G , "Health: " Health , "s26 Bold c" Main.Brush1 " x0 y45" , "Segoe ui" , 322 , 22 )
if( Health <= 0 ){
SetTimer, GameLoop, off
Gdip_TextToGraphics( Main.Gui1.G , "Game Over!" , "s44 Bold Center vCenter c" Main.Brush1 " x0 y0" , "Segoe ui" , 800 , 400 )
}
Main.Gui1.UpdateWindow()
return
^LButton::
CoordMode, Mouse, Client
Gui, % Main.Gui1.Hwnd ":Show",
if( Lasers.Length() > 0 )
return
MouseGetPos, x, y
Lasers.Push( New Laser( Main , Tog := !Tog , x , y ) )
return
Class Laser {
static Walls := [ { Start: New HB_Vector( 0 , 400 ) , End: New HB_Vector( 0 , 0 ) } , { Start: New HB_Vector( 0 , 0 ) , End: New HB_Vector( 800 , 0 ) } , { Start: New HB_Vector( 800 , 0 ) , End: New HB_Vector( 800 , 400 ) } ]
__New( Main , Station , x , y ){
This._SetDefaults( Station , x , y )
This.Draw( Main )
}
_SetDefaults( Station , x , y ){
This.Length := 50
This.Color := "0xFF00ff00"
This.Life := 30
This.StartPosition := New HB_Vector( ( ( Station = 1 ) ? ( 50 ) : ( 750 ) ) , 400 )
This.TargetPosition := New HB_Vector( x , y )
This.Vector := New HB_Vector( x , y )
This.Vector.Sub( This.StartPosition )
This.Vector.Norm()
This.Vector.SetMag( 30 )
This.BackVector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.BackVector.Sub( This.StartPosition )
This.BackVector.SetMag( -This.Length )
This.Back := New HB_Vector( This.StartPosition.X , This.StartPosition.Y )
This.Back.Add( This.BackVector )
}
LineIntercept( Line1 , Line2 ){
A1 := Line1.End.Y - Line1.Start.Y
B1 := Line1.Start.X - Line1.End.X
C1 := A1 * Line1.Start.X + B1 * Line1.Start.Y
A2 := Line2.End.Y - Line2.Start.Y
B2 := Line2.Start.X - Line2.End.X
C2 := A2 * Line2.Start.X + B2 * Line2.Start.Y
Denominator := A1 * B2 - A2 * B1
return New HB_Vector( ( ( B2 * C1 - B1 * C2 ) / Denominator ) , ( ( A1 * C2 - A2 * C1 ) / Denominator ) )
}
CheckHit( obj ){
inter := This.LineIntercept( { Start: This.StartPosition , End: This.Back } , { Start: obj.StartPosition , End: obj.Back } )
if( !( inter.X < min( This.StartPosition.X , This.Back.X ) || inter.X > max( This.StartPosition.X , This.Back.X ) || inter.X < min( obj.StartPosition.X , obj.Back.X ) || inter.X > max( obj.StartPosition.X , obj.Back.X ) ) ) {
This.Hit := inter
return 1
}else
return 0
}
CheckWalls(){
if( This.StartPosition.X < 0 || This.StartPosition.X > 800 || This.StartPosition.Y < - This.Length )
return 1
else
return 0
}
Update(){
This.StartPosition.Add( This.Vector )
This.Back.Add( This.Vector )
}
Draw( Main ){
Gdip_DrawLine( Main.Gui1.G , Main.Pen3 , This.StartPosition.X , This.StartPosition.Y , This.Back.X , This.Back.Y )
}
}
class Missile {
__New( Main ){
This._SetDefaults()
This.Draw( Main )
}
_SetDefaults(){
This.Length := 90
This.Color := "0xFFFF0000"
This.Life := Random( 75 , 150 )
This.StartPosition := New HB_Vector( Random( 0 , 800 ) , 0 )
This.TargetPosition := New HB_Vector( Random( 0 , 800 ) , 400 )
This.Vector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.Vector.Sub( This.StartPosition )
This.Vector.SetMag( This.Vector.Mag() / This.Life )
This.BackVector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.BackVector.Sub( This.StartPosition )
This.BackVector.SetMag( -This.Length )
This.Back := New HB_Vector( This.StartPosition.X , This.StartPosition.Y )
This.Back.Add( This.BackVector )
}
Update( main ){
This.StartPosition.Add( This.Vector )
This.Back.Add( This.Vector )
This.Draw( Main )
}
Draw( Main ){
Gdip_DrawLine( Main.Gui1.G , Main.Pen4 , This.StartPosition.X , This.StartPosition.Y , This.Back.X , This.Back.Y )
}
}
HB_BITMAP_MAKER(){
;Bitmap Created Using: HB Bitmap Maker
pBitmap := Gdip_CreateBitmap( 800 , 200 ) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 0 , 60 , 80 , 150 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 40 , 20 , 80 , 200 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 190 , 140 , 200 , 200 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 460 , 50 , 100 , 160 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 660 , 110 , 100 , 100 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 110 , 130 , 40 , 100 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 230 , 80 , 80 , 120 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 530 , 110 , 80 , 90 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 720 , 30 , 80 , 180 ) , Gdip_DeleteBrush( Brush )
Gdip_DeleteGraphics( G )
return pBitmap
}
Random( Min, Max ){
Random, Out, Min, Max
return out
}
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
class PopUpWindow {
;PopUpWindow v2
;Date Written: Oct 28th, 2021
;Written By: Hellbent aka CivReborn
;SpcThanks: teadrinker , malcev
static Index := 0 , Windows := [] , Handles := [] , EditHwnd , HelperHwnd
__New( obj := "" ){
This._SetDefaults()
This.UpdateSettings( obj )
This._CreateWindow()
This._CreateWindowGraphics()
if( This.AutoShow )
This.ShowWindow( This.Title )
}
_SetDefaults(){
This.X := 10
This.Y := 10
This.W := 10
This.H := 10
This.Smoothing := 2
This.Options := " -DPIScale +AlwaysOnTop "
This.AutoShow := 0
This.GdipStartUp := 0
This.Title := ""
This.Controls := []
This.Handles := []
This.Index := 0
}
AddTrigger( obj ){
local k , v , cc , bd
This.Controls[ ++This.Index ] := { X: 10
, Y: 10
, W: 10
, H: 10 }
for k, v in obj
This.Controls[ This.Index ][ k ] := obj[ k ]
cc := This.Controls[ This.Index ]
Gui, % This.Hwnd ":Add", Text, % "x" cc.X " y" cc.Y " w" cc.W " h" cc.H " hwndhwnd"
This.Handles[ hwnd ] := This.Index
This.Controls[ This.Index ].Hwnd := hwnd
return hwnd
}
DrawTriggers( color := "0xFFFF0000" , AutoUpdate := 0 ){
local brush , cc
Brush := Gdip_BrushCreateSolid( color )
Gdip_SetSmoothingMode( This.G , 3 )
loop, % This.Controls.Length() {
cc := This.Controls[ A_Index ]
Gdip_FillRectangle( This.G , Brush , cc.x , cc.y , cc.w , cc.h )
}
Gdip_DeleteBrush( Brush )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
if( AutoUpdate )
This.UpdateWindow()
}
UpdateSettings( obj := "" , UpdateGraphics := 0 ){
local k , v
if( IsObject( obj ) )
for k, v in obj
This[ k ] := obj[ k ]
( This.X = "Center" ) ? ( This.X := ( A_ScreenWidth - This.W ) / 2 )
( This.Y = "Center" ) ? ( This.Y := ( A_ScreenHeight - This.H ) / 2 )
if( UpdateGraphics ){
This._DestroyWindowsGraphics()
This._CreateWindowGraphics()
}
}
_CreateWindow(){
local hwnd
Gui , New, % " +LastFound +E0x80000 hwndhwnd -Caption " This.Options
PopUpWindow.Index++
This.Index := PopUpWindow.Index
PopUpWindow.Windows[ PopUpWindow.Index ] := This
This.Hwnd := hwnd
PopUpWindow.Handles[ hwnd ] := PopUpWindow.Index
if( This.GdipStartUp && !PopUpWindow.pToken )
PopUpWindow.pToken := GDIP_STARTUP()
}
_DestroyWindowsGraphics(){
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
}
_CreateWindowGraphics(){
This.hbm := CreateDIBSection( This.W , This.H )
This.hdc := CreateCompatibleDC()
This.obm := SelectObject( This.hdc , This.hbm )
This.G := Gdip_GraphicsFromHDC( This.hdc )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
}
ShowWindow( Title := "" ){
Gui , % This.Hwnd ":Show", % "x" This.X " y" This.Y " w" This.W " h" This.H " NA", % Title
}
HideWindow(){
Gui , % This.Hwnd ":Hide",
}
UpdateWindow(){
UpdateLayeredWindow( This.hwnd , This.hdc , This.X , This.Y , This.W , This.H )
}
ClearWindow( AutoUpdate := 0 ){
Gdip_GraphicsClear( This.G )
if( Autoupdate )
This.UpdateWindow()
}
DrawBitmap( pBitmap , obj , dispose := 1 , AutoUpdate := 0 ){
Gdip_DrawImage( This.G , pBitmap , obj.X , obj.Y , obj.W , obj.H )
if( dispose )
Gdip_DisposeImage( pBitmap )
if( Autoupdate )
This.UpdateWindow()
}
PaintBackground( color := "0xFF000000" , AutoUpdate := 0 ){
if( isObject( color ) ){
Brush := Gdip_BrushCreateSolid( ( color.HasKey( "Color" ) ) ? ( color.Color ) : ( "0xFF000000" ) )
if( color.Haskey( "Round" ) )
Gdip_FillRoundedRectangle( This.G , Brush , color.X , color.Y , color.W , color.H , color.Round )
else
Gdip_FillRectangle( This.G , Brush , color.X , color.Y , color.W , color.H )
}else{
Brush := Gdip_BrushCreateSolid( color )
Gdip_FillRectangle( This.G , Brush , -1 , -1 , This.W + 2 , This.H + 2 )
}
Gdip_DeleteBrush( Brush )
if( AutoUpdate )
This.UpdateWindow()
}
DeleteWindow( GDIPShutdown := 0 ){
Gui, % This.Hwnd ":Destroy"
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
Gdip_DeleteGraphics( This.G )
hwnd := This.Hwnd
for k, v in PopUpWindow.Windows[ Hwnd ]
This[k] := ""
PopUpWindow.Windows[ Hwnd ] := ""
if( GDIPShutdown ){
Gdip_Shutdown( PopUpWindow.pToken )
PopUpWindow.pToken := ""
}
}
_OnClose( wParam ){
if( wParam = 0xF060 ){ ;SC_CLOSE ;[ clicking on the gui close button ]
Try{
Gui, % PopUpWindow.HelperHwnd ":Destroy"
SoundBeep, 555
}
}
}
CreateCachedBitmap( pBitmap , Dispose := 0 ){
local pCachedBitmap
if( This.CachedBitmap )
This.DisposeCachedbitmap()
DllCall( "gdiplus\GdipCreateCachedBitmap" , "Ptr" , pBitmap , "Ptr" , this.G , "PtrP" , pCachedBitmap )
This.CachedBitmap := pCachedBitmap
if( Dispose )
Gdip_DisposeImage( pBitmap )
}
DrawCachedBitmap( AutoUpdate := 0 ){
DllCall( "gdiplus\GdipDrawCachedBitmap" , "Ptr" , this.G , "Ptr" , This.CachedBitmap , "Int" , 0 , "Int" , 0 )
if( AutoUpdate )
This.UpdateWindow()
}
DisposeCachedbitmap(){
DllCall( "gdiplus\GdipDeleteCachedBitmap" , "Ptr" , This.CachedBitmap )
}
Helper(){
local hwnd , MethodList := ["__New","UpdateSettings","ShowWindow","HideWindow","UpdateWindow","ClearWindow","DrawBitmap","PaintBackground","DeleteWindow" , "AddTrigger" , "DrawTriggers", "CreateCachedBitmap" , "DrawCachedBitmap" , "DisposeCachedbitmap" ]
Gui, New, +AlwaysOnTop +ToolWindow +HwndHwnd
PopUpWindow.HelperHwnd := hwnd
Gui, Add, Edit, xm ym w250 r1 Center hwndhwnd, Gui1
PopUpWindow.EditHwnd := hwnd
loop, % MethodList.Length()
Gui, Add, Button, xm y+1 w250 r1 gPopUpWindow._HelperClip, % MethodList[ A_Index ]
Gui, Show,,
OnMessage( 0x112 , This._OnClose.Bind( hwnd ) )
}
_HelperClip(){
local ClipList
GuiControlGet, out, % PopUpWindow.HelperHwnd ":", % PopUpWindow.EditHwnd
ClipList := { __New: " := New PopUpWindow( { X: 0 , Y: 0 , W: A_ScreenWidth , H: A_ScreenHeight , Options: "" -DPIScale +AlwaysOnTop "" } )"
, UpdateSettings: ".UpdateSettings( { X: """" , Y: """" , W: """" , H: """" } , UpdateGraphics := 0 )"
, ShowWindow: ".ShowWindow( Title := """" )"
, HideWindow: ".HideWindow()"
, UpdateWindow: ".UpdateWindow()"
, ClearWindow: ".ClearWindow( AutoUpdate := 0 )"
, DrawBitmap: ".DrawBitmap( pBitmap := """" , { X: 0 , Y: 0 , W: " Out ".W , H: " Out ".H } , dispose := 1 )"
, PaintBackground: ".PaintBackground( color := ""0xFF000000"" ) " ";{ Color: ""0xFF000000"" , X: 2 , Y: 2 , W: " Out ".W - 4 , H: " Out ".H - 4 , Round: 10 }"
, DeleteWindow: ".DeleteWindow( GDIPShutdown := 0 )"
, AddTrigger: ".AddTrigger( { X: """" , Y: """" , W: """" , H: """" , Value: """" , Label: """" , BoundClass: """" , BoundMethod: """" } )"
, DrawTriggers: ".DrawTriggers( color := ""0xFFFF0000"" , AutoUpdate := 0 )"
, CreateCachedBitmap: ".CreateCachedBitmap( pBitmap , Dispose := 0 )"
, DrawCachedBitmap: ".DrawCachedBitmap( AutoUpdate := 0 )"
, DisposeCachedbitmap: ".DisposeCachedbitmap()" }
clipboard := Out ClipList[ A_GuiControl ]
}
}
;****************************************************************
Class HB_Vector {
__New(x:=0,y:=0){
This.X:=x
This.Y:=y
}
Add(Other_HB_Vector){
This.X+=Other_HB_Vector.X
This.Y+=Other_HB_Vector.Y
}
Sub(Other_HB_Vector){
This.X-=Other_HB_Vector.X
This.Y-=Other_HB_Vector.Y
}
mag(){
return Sqrt(This.X*This.X + This.Y*This.Y)
}
magsq(){
return This.Mag()**2
}
setMag(in1){
m:=This.Mag()
This.X := This.X * in1/m
This.Y := This.Y * in1/m
return This
}
mult(in1,in2:="",in3:="",in4:="",in5:=""){
if(IsObject(in1)&&in2=""){
This.X*=In1.X
This.Y*=In1.Y
}else if(!IsObject(In1)&&In2=""){
This.X*=In1
This.Y*=In1
}else if(!IsObject(In1)&&IsObject(In2)){
This.X*=In1*In2.X
This.Y*=In1*In2.Y
}else if(IsObject(In1)&&IsObject(In2)){
This.X*=In1.X*In2.X
This.Y*=In1.Y*In2.Y
}
}
div(in1,in2:="",in3:="",in4:="",in5:=""){
if(IsObject(in1)&&in2=""){
This.X/=In1.X
This.Y/=In1.Y
}else if(!IsObject(In1)&&In2=""){
This.X/=In1
This.Y/=In1
}else if(!IsObject(In1)&&IsObject(In2)){
This.X/=In1/In2.X
This.Y/=In1/In2.Y
}else if(IsObject(In1)&&IsObject(In2)){
This.X/=In1.X/In2.X
This.Y/=In1.Y/In2.Y
}
}
dist(in1){
return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
}
dot(in1){
return (This.X*in1.X)+(This.Y*In1.Y)
}
cross(in1){
return This.X*In1.Y-This.Y*In1.X
}
Norm(){
m:=This.Mag()
This.X/=m
This.Y/=m
}
}
After tweaking the code a bit
Spoiler
- Temp (1).gif (525.99 KiB) Viewed 6363 times
Code: Select all
;********************************************************************************************************************************************************************************************
#Include, <My Altered GDIP LIB> ;GDIP.AHK
;********************************************************************************************************************************************************************************************
#SingleInstance, Force
SetBatchlines, -1
CoordMode, Mouse, Screen
Gdip_Startup()
Main := {}
Main.Gui1 := New PopUpWindow( { X: A_ScreenWidth / 2 - 400 , Y: A_ScreenHeight - 500 , W: 800 , H: 400 , Options: " -DPIScale +AlwaysOnTop " , AutoShow: 1 } )
Main.Pen1 := Gdip_CreatePen( "0xFF000000" , 3 )
Main.Pen2 := Gdip_CreatePen( "0xFF0066FF" , 3 )
Main.Pen3 := Gdip_CreatePen( "0xFF0000FF" , 3 )
Main.Pen4 := Gdip_CreatePen( "0xFFFF0000" , 3 )
Main.Brush1 := Gdip_BrushCreateSolid( "0xFFff0000" )
Main.Brush2 := Gdip_BrushCreateSolid( "0xFF0000FF" )
Main.Gui2 := New PopUpWindow( { X: A_ScreenWidth / 2 - 400 , Y: A_ScreenHeight - 500 , W: 800 , H: 400 , Options: " -DPIScale +AlwaysOnTop " , AutoShow: 1 } )
Main.Gui2.DrawBitmap( HB_BITMAP_MAKER() , { X: 0 , Y: Main.Gui2.H / 3 * 2 , W: Main.Gui2.W , H: Main.Gui2.H / 3 } , dispose := 1 )
Main.Gui2.UpdateWindow()
Bob := New Missile( Main )
index := 0
Score := 0
Health := 10
Lasers := []
MsgBox, Start
SetTimer, GameLoop, 30
return
GuiContextMenu:
*ESC::ExitApp
Numpad3::PopUpWindow.Helper()
GameLoop:
if( ++Index > 2 && !Index := 0)
if( GetKeyState("LButton" ) ){
CoordMode, Mouse, Client
Gui, % Main.Gui1.Hwnd ":Show",
MouseGetPos, x, y
Lasers.Push( New Laser( Main , Tog := !Tog , x , y ) )
}
Main.Gui1.ClearWindow()
Bob.Update(Main)
Loop, % Lasers.Length() {
Lasers[ Lasers.Length() - A_Index + 1 ].Update( Main )
if ( Lasers[ Lasers.Length() - A_Index + 1 ].CheckWalls() )
Lasers.RemoveAt( Lasers.Length() - A_Index + 1 )
else
Lasers[ Lasers.Length() - A_Index + 1 ].Draw( Main )
if( Lasers[ Lasers.Length() - A_Index + 1 ].CheckHit( Bob ) ){
Bob := New Missile( Main )
Hit := New HB_Vector( Lasers[ Lasers.Length() - A_Index + 1 ].Hit.X , Lasers[ Lasers.Length() - A_Index + 1 ].Hit.Y )
Lasers.RemoveAt( Lasers.Length() - A_Index + 1 )
cc := 1 , rad := 10 , ++Score
}
}
if( cc && ++cc < 20 ){
Gdip_FillEllipse( Main.Gui1.G , Main.Brush1 , Hit.X - rad , Hit.Y - rad , rad * 2 , rad * 2 )
rad += 5
}
( cc > 20 && ! cc := 0)
if( --Bob.Life = 0 ){
Bob := New Missile( Main )
Health--
}
Gdip_TextToGraphics( Main.Gui1.G , "Score: " Score , "s26 Bold c" Main.Brush2 " x0 y0" , "Segoe ui" , 322 , 22 )
Gdip_TextToGraphics( Main.Gui1.G , "Health: " Health , "s26 Bold c" Main.Brush1 " x0 y45" , "Segoe ui" , 322 , 22 )
if( Health <= 0 ){
SetTimer, GameLoop, off
Gdip_TextToGraphics( Main.Gui1.G , "Game Over!" , "s44 Bold Center vCenter c" Main.Brush1 " x0 y0" , "Segoe ui" , 800 , 400 )
}
Main.Gui1.UpdateWindow()
return
^LButton::
CoordMode, Mouse, Client
Gui, % Main.Gui1.Hwnd ":Show",
if( Lasers.Length() > 10 )
return
MouseGetPos, x, y
Lasers.Push( New Laser( Main , Tog := !Tog , x , y ) )
return
Class Laser {
static Walls := [ { Start: New HB_Vector( 0 , 400 ) , End: New HB_Vector( 0 , 0 ) } , { Start: New HB_Vector( 0 , 0 ) , End: New HB_Vector( 800 , 0 ) } , { Start: New HB_Vector( 800 , 0 ) , End: New HB_Vector( 800 , 400 ) } ]
__New( Main , Station , x , y ){
This._SetDefaults( Station , x , y )
This.Draw( Main )
}
_SetDefaults( Station , x , y ){
This.Length := 30
This.Color := "0xFF00ff00"
;~ This.Life := 30
This.Life := 10
This.StartPosition := New HB_Vector( ( ( Station = 1 ) ? ( 50 ) : ( 750 ) ) , 400 )
This.TargetPosition := New HB_Vector( x , y )
This.Vector := New HB_Vector( x , y )
This.Vector.Sub( This.StartPosition )
;~ This.Vector.Norm()
This.Vector.SetMag( This.Life )
This.BackVector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.BackVector.Sub( This.StartPosition )
This.BackVector.SetMag( -This.Length )
This.Back := New HB_Vector( This.StartPosition.X , This.StartPosition.Y )
This.Back.Add( This.BackVector )
}
LineIntercept( Line1 , Line2 ){
A1 := Line1.End.Y - Line1.Start.Y
B1 := Line1.Start.X - Line1.End.X
C1 := A1 * Line1.Start.X + B1 * Line1.Start.Y
A2 := Line2.End.Y - Line2.Start.Y
B2 := Line2.Start.X - Line2.End.X
C2 := A2 * Line2.Start.X + B2 * Line2.Start.Y
Denominator := A1 * B2 - A2 * B1
return New HB_Vector( ( ( B2 * C1 - B1 * C2 ) / Denominator ) , ( ( A1 * C2 - A2 * C1 ) / Denominator ) )
}
CheckHit( obj ){
inter := This.LineIntercept( { Start: This.StartPosition , End: This.Back } , { Start: obj.StartPosition , End: obj.Back } )
if( !( inter.X < min( This.StartPosition.X , This.Back.X ) || inter.X > max( This.StartPosition.X , This.Back.X ) || inter.X < min( obj.StartPosition.X , obj.Back.X ) || inter.X > max( obj.StartPosition.X , obj.Back.X ) ) ) {
This.Hit := inter
return 1
}else
return 0
}
CheckWalls(){
if( This.StartPosition.X < 0 || This.StartPosition.X > 800 || This.StartPosition.Y < - This.Length )
return 1
else
return 0
}
Update(){
This.StartPosition.Add( This.Vector )
This.Back.Add( This.Vector )
}
Draw( Main ){
Gdip_DrawLine( Main.Gui1.G , Main.Pen3 , This.StartPosition.X , This.StartPosition.Y , This.Back.X , This.Back.Y )
}
}
class Missile {
__New( Main ){
This._SetDefaults()
This.Draw( Main )
}
_SetDefaults(){
This.Length := 90
This.Color := "0xFFFF0000"
This.Life := Random( 75 , 150 )
This.StartPosition := New HB_Vector( Random( 0 , 800 ) , 0 )
This.TargetPosition := New HB_Vector( Random( 0 , 800 ) , 400 )
This.Vector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.Vector.Sub( This.StartPosition )
This.Vector.SetMag( This.Vector.Mag() / This.Life )
This.BackVector := New HB_Vector( This.TargetPosition.X , This.TargetPosition.Y )
This.BackVector.Sub( This.StartPosition )
This.BackVector.SetMag( -This.Length )
This.Back := New HB_Vector( This.StartPosition.X , This.StartPosition.Y )
This.Back.Add( This.BackVector )
}
Update( main ){
This.StartPosition.Add( This.Vector )
This.Back.Add( This.Vector )
This.Draw( Main )
}
Draw( Main ){
Gdip_DrawLine( Main.Gui1.G , Main.Pen4 , This.StartPosition.X , This.StartPosition.Y , This.Back.X , This.Back.Y )
}
}
HB_BITMAP_MAKER(){
;Bitmap Created Using: HB Bitmap Maker
pBitmap := Gdip_CreateBitmap( 800 , 200 ) , G := Gdip_GraphicsFromImage( pBitmap ) , Gdip_SetSmoothingMode( G , 2 )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 0 , 60 , 80 , 150 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 40 , 20 , 80 , 200 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 190 , 140 , 200 , 200 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 460 , 50 , 100 , 160 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF222222" ) , Gdip_FillRectangle( G , Brush , 660 , 110 , 100 , 100 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 110 , 130 , 40 , 100 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 230 , 80 , 80 , 120 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 530 , 110 , 80 , 90 ) , Gdip_DeleteBrush( Brush )
Brush := Gdip_BrushCreateSolid( "0xFF333333" ) , Gdip_FillRectangle( G , Brush , 720 , 30 , 80 , 180 ) , Gdip_DeleteBrush( Brush )
Gdip_DeleteGraphics( G )
return pBitmap
}
Random( Min, Max ){
Random, Out, Min, Max
return out
}
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
;####################################################################################################################################################################################
class PopUpWindow {
;PopUpWindow v2
;Date Written: Oct 28th, 2021
;Written By: Hellbent aka CivReborn
;SpcThanks: teadrinker , malcev
static Index := 0 , Windows := [] , Handles := [] , EditHwnd , HelperHwnd
__New( obj := "" ){
This._SetDefaults()
This.UpdateSettings( obj )
This._CreateWindow()
This._CreateWindowGraphics()
if( This.AutoShow )
This.ShowWindow( This.Title )
}
_SetDefaults(){
This.X := 10
This.Y := 10
This.W := 10
This.H := 10
This.Smoothing := 2
This.Options := " -DPIScale +AlwaysOnTop "
This.AutoShow := 0
This.GdipStartUp := 0
This.Title := ""
This.Controls := []
This.Handles := []
This.Index := 0
}
AddTrigger( obj ){
local k , v , cc , bd
This.Controls[ ++This.Index ] := { X: 10
, Y: 10
, W: 10
, H: 10 }
for k, v in obj
This.Controls[ This.Index ][ k ] := obj[ k ]
cc := This.Controls[ This.Index ]
Gui, % This.Hwnd ":Add", Text, % "x" cc.X " y" cc.Y " w" cc.W " h" cc.H " hwndhwnd"
This.Handles[ hwnd ] := This.Index
This.Controls[ This.Index ].Hwnd := hwnd
return hwnd
}
DrawTriggers( color := "0xFFFF0000" , AutoUpdate := 0 ){
local brush , cc
Brush := Gdip_BrushCreateSolid( color )
Gdip_SetSmoothingMode( This.G , 3 )
loop, % This.Controls.Length() {
cc := This.Controls[ A_Index ]
Gdip_FillRectangle( This.G , Brush , cc.x , cc.y , cc.w , cc.h )
}
Gdip_DeleteBrush( Brush )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
if( AutoUpdate )
This.UpdateWindow()
}
UpdateSettings( obj := "" , UpdateGraphics := 0 ){
local k , v
if( IsObject( obj ) )
for k, v in obj
This[ k ] := obj[ k ]
( This.X = "Center" ) ? ( This.X := ( A_ScreenWidth - This.W ) / 2 )
( This.Y = "Center" ) ? ( This.Y := ( A_ScreenHeight - This.H ) / 2 )
if( UpdateGraphics ){
This._DestroyWindowsGraphics()
This._CreateWindowGraphics()
}
}
_CreateWindow(){
local hwnd
Gui , New, % " +LastFound +E0x80000 hwndhwnd -Caption " This.Options
PopUpWindow.Index++
This.Index := PopUpWindow.Index
PopUpWindow.Windows[ PopUpWindow.Index ] := This
This.Hwnd := hwnd
PopUpWindow.Handles[ hwnd ] := PopUpWindow.Index
if( This.GdipStartUp && !PopUpWindow.pToken )
PopUpWindow.pToken := GDIP_STARTUP()
}
_DestroyWindowsGraphics(){
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
}
_CreateWindowGraphics(){
This.hbm := CreateDIBSection( This.W , This.H )
This.hdc := CreateCompatibleDC()
This.obm := SelectObject( This.hdc , This.hbm )
This.G := Gdip_GraphicsFromHDC( This.hdc )
Gdip_SetSmoothingMode( This.G , This.Smoothing )
}
ShowWindow( Title := "" ){
Gui , % This.Hwnd ":Show", % "x" This.X " y" This.Y " w" This.W " h" This.H " NA", % Title
}
HideWindow(){
Gui , % This.Hwnd ":Hide",
}
UpdateWindow(){
UpdateLayeredWindow( This.hwnd , This.hdc , This.X , This.Y , This.W , This.H )
}
ClearWindow( AutoUpdate := 0 ){
Gdip_GraphicsClear( This.G )
if( Autoupdate )
This.UpdateWindow()
}
DrawBitmap( pBitmap , obj , dispose := 1 , AutoUpdate := 0 ){
Gdip_DrawImage( This.G , pBitmap , obj.X , obj.Y , obj.W , obj.H )
if( dispose )
Gdip_DisposeImage( pBitmap )
if( Autoupdate )
This.UpdateWindow()
}
PaintBackground( color := "0xFF000000" , AutoUpdate := 0 ){
if( isObject( color ) ){
Brush := Gdip_BrushCreateSolid( ( color.HasKey( "Color" ) ) ? ( color.Color ) : ( "0xFF000000" ) )
if( color.Haskey( "Round" ) )
Gdip_FillRoundedRectangle( This.G , Brush , color.X , color.Y , color.W , color.H , color.Round )
else
Gdip_FillRectangle( This.G , Brush , color.X , color.Y , color.W , color.H )
}else{
Brush := Gdip_BrushCreateSolid( color )
Gdip_FillRectangle( This.G , Brush , -1 , -1 , This.W + 2 , This.H + 2 )
}
Gdip_DeleteBrush( Brush )
if( AutoUpdate )
This.UpdateWindow()
}
DeleteWindow( GDIPShutdown := 0 ){
Gui, % This.Hwnd ":Destroy"
SelectObject( This.hdc , This.obm )
DeleteObject( This.hbm )
DeleteDC( This.hdc )
Gdip_DeleteGraphics( This.G )
hwnd := This.Hwnd
for k, v in PopUpWindow.Windows[ Hwnd ]
This[k] := ""
PopUpWindow.Windows[ Hwnd ] := ""
if( GDIPShutdown ){
Gdip_Shutdown( PopUpWindow.pToken )
PopUpWindow.pToken := ""
}
}
_OnClose( wParam ){
if( wParam = 0xF060 ){ ;SC_CLOSE ;[ clicking on the gui close button ]
Try{
Gui, % PopUpWindow.HelperHwnd ":Destroy"
SoundBeep, 555
}
}
}
CreateCachedBitmap( pBitmap , Dispose := 0 ){
local pCachedBitmap
if( This.CachedBitmap )
This.DisposeCachedbitmap()
DllCall( "gdiplus\GdipCreateCachedBitmap" , "Ptr" , pBitmap , "Ptr" , this.G , "PtrP" , pCachedBitmap )
This.CachedBitmap := pCachedBitmap
if( Dispose )
Gdip_DisposeImage( pBitmap )
}
DrawCachedBitmap( AutoUpdate := 0 ){
DllCall( "gdiplus\GdipDrawCachedBitmap" , "Ptr" , this.G , "Ptr" , This.CachedBitmap , "Int" , 0 , "Int" , 0 )
if( AutoUpdate )
This.UpdateWindow()
}
DisposeCachedbitmap(){
DllCall( "gdiplus\GdipDeleteCachedBitmap" , "Ptr" , This.CachedBitmap )
}
Helper(){
local hwnd , MethodList := ["__New","UpdateSettings","ShowWindow","HideWindow","UpdateWindow","ClearWindow","DrawBitmap","PaintBackground","DeleteWindow" , "AddTrigger" , "DrawTriggers", "CreateCachedBitmap" , "DrawCachedBitmap" , "DisposeCachedbitmap" ]
Gui, New, +AlwaysOnTop +ToolWindow +HwndHwnd
PopUpWindow.HelperHwnd := hwnd
Gui, Add, Edit, xm ym w250 r1 Center hwndhwnd, Gui1
PopUpWindow.EditHwnd := hwnd
loop, % MethodList.Length()
Gui, Add, Button, xm y+1 w250 r1 gPopUpWindow._HelperClip, % MethodList[ A_Index ]
Gui, Show,,
OnMessage( 0x112 , This._OnClose.Bind( hwnd ) )
}
_HelperClip(){
local ClipList
GuiControlGet, out, % PopUpWindow.HelperHwnd ":", % PopUpWindow.EditHwnd
ClipList := { __New: " := New PopUpWindow( { X: 0 , Y: 0 , W: A_ScreenWidth , H: A_ScreenHeight , Options: "" -DPIScale +AlwaysOnTop "" } )"
, UpdateSettings: ".UpdateSettings( { X: """" , Y: """" , W: """" , H: """" } , UpdateGraphics := 0 )"
, ShowWindow: ".ShowWindow( Title := """" )"
, HideWindow: ".HideWindow()"
, UpdateWindow: ".UpdateWindow()"
, ClearWindow: ".ClearWindow( AutoUpdate := 0 )"
, DrawBitmap: ".DrawBitmap( pBitmap := """" , { X: 0 , Y: 0 , W: " Out ".W , H: " Out ".H } , dispose := 1 )"
, PaintBackground: ".PaintBackground( color := ""0xFF000000"" ) " ";{ Color: ""0xFF000000"" , X: 2 , Y: 2 , W: " Out ".W - 4 , H: " Out ".H - 4 , Round: 10 }"
, DeleteWindow: ".DeleteWindow( GDIPShutdown := 0 )"
, AddTrigger: ".AddTrigger( { X: """" , Y: """" , W: """" , H: """" , Value: """" , Label: """" , BoundClass: """" , BoundMethod: """" } )"
, DrawTriggers: ".DrawTriggers( color := ""0xFFFF0000"" , AutoUpdate := 0 )"
, CreateCachedBitmap: ".CreateCachedBitmap( pBitmap , Dispose := 0 )"
, DrawCachedBitmap: ".DrawCachedBitmap( AutoUpdate := 0 )"
, DisposeCachedbitmap: ".DisposeCachedbitmap()" }
clipboard := Out ClipList[ A_GuiControl ]
}
}
;****************************************************************
Class HB_Vector {
__New(x:=0,y:=0){
This.X:=x
This.Y:=y
}
Add(Other_HB_Vector){
This.X+=Other_HB_Vector.X
This.Y+=Other_HB_Vector.Y
}
Sub(Other_HB_Vector){
This.X-=Other_HB_Vector.X
This.Y-=Other_HB_Vector.Y
}
mag(){
return Sqrt(This.X*This.X + This.Y*This.Y)
}
magsq(){
return This.Mag()**2
}
setMag(in1){
m:=This.Mag()
This.X := This.X * in1/m
This.Y := This.Y * in1/m
return This
}
mult(in1,in2:="",in3:="",in4:="",in5:=""){
if(IsObject(in1)&&in2=""){
This.X*=In1.X
This.Y*=In1.Y
}else if(!IsObject(In1)&&In2=""){
This.X*=In1
This.Y*=In1
}else if(!IsObject(In1)&&IsObject(In2)){
This.X*=In1*In2.X
This.Y*=In1*In2.Y
}else if(IsObject(In1)&&IsObject(In2)){
This.X*=In1.X*In2.X
This.Y*=In1.Y*In2.Y
}
}
div(in1,in2:="",in3:="",in4:="",in5:=""){
if(IsObject(in1)&&in2=""){
This.X/=In1.X
This.Y/=In1.Y
}else if(!IsObject(In1)&&In2=""){
This.X/=In1
This.Y/=In1
}else if(!IsObject(In1)&&IsObject(In2)){
This.X/=In1/In2.X
This.Y/=In1/In2.Y
}else if(IsObject(In1)&&IsObject(In2)){
This.X/=In1.X/In2.X
This.Y/=In1.Y/In2.Y
}
}
dist(in1){
return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
}
dot(in1){
return (This.X*in1.X)+(This.Y*In1.Y)
}
cross(in1){
return This.X*In1.Y-This.Y*In1.X
}
Norm(){
m:=This.Mag()
This.X/=m
This.Y/=m
}
}