Sign in to follow this  
Followers 0
CodyBarrett

issues, collision, backbuffering.. ect.

5 posts in this topic

#1 ·  Posted (edited)

hello

Apologies to UEZ for Pming him before i came here.

i've come across some blockades when i was creating an original game

#1 (main issue) Collision detection

i've got a static gravity and as things are moving down they just pass through the ground. how would i use collision detection? i've read on these forums about _Winapi_ptinrect but i couldn't understand how to use that func, or about the structuring of the TAGS that the func uses.

does anyone have any pointers for how to use an effective collision detection system?

#2 Backbuffering

a while ago for my TRON remake i tried using multiple layers of Graphics Objects and that worked very well. I'm not sure how to do that in this instance, i need to clear the graphic and redraw something in a different position,(ie) a picture when it moves. in TRON i didn't need to change the Graphic until a player crashed, then i just deleted it object. Deleting the object then creating a new object every time i need to move some pixels is not efficient at all. For now, i've just got two buffers, a backbuffer that i draw to and the main object that the backbuffer draws to.

#3 Smooth movements in GDI+

i've looked at the Physik Engine i found here and its not in english, and even then its too advanced for me to understand, that script is soooo impressive! its SO FAST too! i'm not sure how to make anything i make that fast, do you guys have any pointers?

this is my current script, its messy i know and i'll be working on it for a while.

i'm kinda in uncharted territory here anything that would help me understand would be greatly appreciated.

#include <GDIPLUS.au3>
#include <WINAPI.au3>
#include <ARRAY.au3>
#include <WINDOWSCONSTANTS.au3>
#include <GUICONSTANTSEX.au3>

Opt('GUIONEVENTMODE', 1)

Global $buffer_speed = 45

Global $window_main
Global $window_parent = Default

Global $left_pos = Default
Global $right_pos = Default

Global $window_width = 800
Global $window_height = 600
Global $window_offset = 5

Global $window_style = Default
Global $window_style_ex = Default

Global $s[1]
Global $block_list[1][4]
Global $player_pos[4] = [100,100,75,75]

$window_main = GUICreate('', $window_width, $window_height, $left_pos, $right_pos, $window_style, $window_style_ex, $window_parent)
GUISetOnEvent(-3, 'quit', $window_main)
GUISetState(@SW_SHOW, $window_main)

_GDIPlus_Startup()

Global $graphic = _GDIPlus_GraphicsCreateFromHWND($window_main)
    Global $bb_bmp = _GDIPlus_BitmapCreateFromGraphics($window_width, $window_height, $graphic)
    Global $bb_graphic = _GDIPlus_ImageGetGraphicsContext($bb_bmp)


Global $background_brush = _GDIPlus_BrushCreateSolid ('0xFF' & '000099')
Global $ground_brush = _GDIPlus_BrushCreateSolid ('0xFF' & '202020')

_GDIPlus_GraphicsFillRect($bb_graphic, 0, 0, $window_width,$window_height,$ground_brush)
_GDIPlus_GraphicsFillRect($bb_graphic, $window_offset, $window_offset, $window_width-($window_offset*2),$window_height-($window_offset*10),$background_brush)



;~ $s[0] = _GDIPlus_ImageLoadFromFile (@ScriptDir & '\s0.png') you don't have this so just ignore it...



Global $objects[4][5]
$objects[0][1] = 0
$objects[0][2] = 0
$objects[0][3] = $window_width
$objects[0][4] = $window_offset

$objects[1][1] = 0
$objects[1][2] = 0
$objects[1][3] = $window_offset
$objects[1][4] = $window_height

$objects[2][1] = $window_width-$window_offset
$objects[2][2] = 0
$objects[2][3] = $window_offset
$objects[2][4] = $window_height

$objects[3][1] = 0
$objects[3][2] = $window_height-($window_offset*10)
$objects[3][3] = $window_width
$objects[3][4] = $window_offset*10

reset_block_list ()
For $n = 0 To UBound ($objects)-1
    $objects[$n][0] = _GDIPlus_BrushCreateSolid ('0xFF' & '202020')
    add_block ($objects[$n][1],$objects[$n][2],$objects[$n][3],$objects[$n][4])
Next

GUIRegisterMsg(0xF, 'MY_PAINT')
GUIRegisterMsg(0x85, 'MY_PAINT')
AdlibRegister('BUFFER', $buffer_speed)
While True
    $player_direction_x = 0
    $player_direction_y = $window_offset
    move_player ()
    draw ()
    Sleep(50)
WEnd
Func reset_block_list ()
    Global $block_list[1][4]
    $block_list[0][0] = '.'
    $block_list[0][1] = '.'
    $block_list[0][2] = '.'
    $block_list[0][3] = '.'
EndFunc
Func move_player ()
    $player_pos[0] += $player_direction_x
    $player_pos[1] += $player_direction_y
    If check_blocking ($player_pos[0],$player_pos[1],$player_pos[2],$player_pos[3]) = 'error' Then
        $player_pos[0] -= $player_direction_x
        $player_pos[1] -= $player_direction_y
    EndIf
EndFunc
Func add_block ($x,$y,$w,$h)
    Local $n
    Local $size = UBound ($block_list,1)
    For $n = 0 To $size-1
        If IsInt ($block_list[$n][0]) = 0 And  IsInt ($block_list[$n][1]) = 0 And IsInt ($block_list[$n][2]) = 0 And  IsInt ($block_list[$n][3]) = 0 Then
            $block_list[$n][0] = $x
            $block_list[$n][1] = $y
            $block_list[$n][2] = $w
            $block_list[$n][3] = $h
            Return
        EndIf
    Next
    ReDim $block_list[$size+1][4]
    $block_list[$size][0] = $x
    $block_list[$size][1] = $y
    $block_list[$size][2] = $w
    $block_list[$size][3] = $h
EndFunc
Func check_blocking ($x,$y,$w,$h)
    Local $n
    For $n = 0 To UBound ($block_list,1)-1

        If IsInt ($block_list[$n][0]) = 1 And  IsInt ($block_list[$n][1]) = 1 And IsInt ($block_list[$n][2]) = 1 And  IsInt ($block_list[$n][3]) = 1 Then
            $xx = $block_list[$n][0]
            $yy = $block_list[$n][1]
            $ww = $block_list[$n][2]
            $hh = $block_list[$n][3]



;~  THIS WORKS BUT IS SOOOOOOO SLOW!!!
            For $ny = $yy To $yy+$hh
                For $nx = $xx To $xx+$ww
                    If $x = $nx And $y = $ny Then
                        Return 'error'
                    EndIf
                    If $x+$w = $nx And $y+$h = $ny Then
                        Return 'error'
                    EndIf
                Next
            Next


        EndIf
    Next
    Return 'ok'
EndFunc










Func draw ()
;~  _GDIPlus_GraphicsClear ($bb_graphic,'0x60506070') ;<========= cool little fade effect (looks like it's speedy)
    _GDIPlus_GraphicsClear ($bb_graphic,'0xFF506070') ;<========= simple but it works
    For $n = 0 To UBound ($objects)-1
        _GDIPlus_GraphicsFillRect ($bb_graphic,$objects[$n][1],$objects[$n][2],$objects[$n][3], $objects[$n][4],$objects[$n][0])
    Next
;~  _GDIPlus_GraphicsDrawImageRect($bb_graphic, $s[0], $player_pos[0], $player_pos[1],$player_pos[2],$player_pos[3])
    _GDIPlus_GraphicsFillRect($bb_graphic, $player_pos[0], $player_pos[1],$player_pos[2],$player_pos[3],$ground_brush)

EndFunc
Func BUFFER()
    _GDIPlus_GraphicsDrawImage($graphic, $bb_bmp, 0, 0)
EndFunc   ;==>BUFFER
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hWnd, Default, Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT

Func quit()
    _GDIPlus_GraphicsDispose($graphic)
        _GDIPlus_GraphicsDispose($bb_graphic)
        _GDIPlus_ImageDispose($bb_bmp)
    For $n = 0 To UBound ($objects)-1
        _GDIPlus_BrushDispose ($objects[$n][0])
    Next
    _GDIPlus_BrushDispose ($background_brush)
    _GDIPlus_BrushDispose ($ground_brush)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>quit
Edited by CodyBarrett

Share this post


Link to post
Share on other sites



I don't know much about (actually not much more than the basics) of graphics programming, but wouldn't using sprites do what you're looking to do? Not sure how, or even if, you could program them in AutoIt, but might be something to look into.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

i have images yes, PNGs but... i have no room to upload them, the main problem is collision detection of the sprites, in the example i have a Block moving down and passing into the floor.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#1 collision detection is not trivial if you use complex objects! It is easier for rectangle and circle objects. Ask google for collision detection and you will find plenty of mathematical descriptions and examples.

#2 look to the example I made

#3 Physik Engine is really a tough mathematical approach which I cannot teach you with a few sentences and besides that my english is probably not good enough.

Here some links for Rigid body dynamics: http://en.wikipedia.org/wiki/Rigid_body_dynamics, http://graphics.cs.cmu.edu/courses/15-869-F08/lec/14/notesg.pdf

Here a very simple collision detection (not optimized) for rectangles:

;coded by UEZ 2011
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $i
Global Const $width = 800
Global Const $height = 600

Global Const $hGUI = GUICreate("GDI+", $width, $height)
GUISetState()

Global Const $window_offset = 5
Global Const $ground_x = $window_offset
Global Const $ground_y = $window_offset
Global Const $ground_w = $width - ($window_offset * 2)
Global Const $ground_h = $height - ($window_offset * 10)

_GDIPlus_Startup()
Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Global Const $hBackground_brush = _GDIPlus_BrushCreateSolid (0xFF000099)
Global Const $hGround_brush = _GDIPlus_BrushCreateSolid (0xFF202020)

Global Const $speed = 2
Global Const $blocks = 10
Global $aBlocks[$blocks][7] ;x, y, width, height, color, on/off, move

For $i = 0 To $blocks - 1
    $aBlocks[$i][0] = Random($ground_x, $ground_w - 110, 1)
    $aBlocks[$i][1] = Random(10, 20, 1)
    $aBlocks[$i][2] = Random(50, 100, 1)
    $aBlocks[$i][3] = Random(50, 100, 1)
    $aBlocks[$i][4] = _GDIPlus_BrushCreateSolid("0xFF" & Hex(Random(0x111111, 0xFFFFFF, 1), 6))
    $aBlocks[$i][5] = False
    $aBlocks[$i][6] = False
Next
$aBlocks[0][5]  = True
$aBlocks[0][6]  = True

GUISetOnEvent(-3, "_Exit")

$i = 0
While Sleep(30)
    If $i < $blocks Then
        _GDIPlus_GraphicsClear($hContext, 0xFF000000)
        Draw_Background()
        Draw_Block()
        Check_Collision()
        Move_Block()
        Next_Block()
    EndIf
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
WEnd

Func Draw_Background()
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $width, $height, $hGround_brush)
    _GDIPlus_GraphicsFillRect($hContext, $ground_x, $ground_x, $ground_w, $ground_h, $hBackground_brush)
EndFunc

Func Draw_Block()
        Local $j
        For $j = 0 To $blocks - 1
            If $aBlocks[$j][5] Then _GDIPlus_GraphicsFillRect($hContext, $aBlocks[$j][0], $aBlocks[$j][1], $aBlocks[$j][2], $aBlocks[$j][3], $aBlocks[$j][4])
        Next
EndFunc

Func Check_Collision()
    Local $k, $l, $c
    For $k = 0 To $blocks - 1
        For $l = $k + 1 To $blocks - 1
            If $aBlocks[$k][5] And $aBlocks[$l][5] Then
                If _RectCollision($aBlocks[$k][0], $aBlocks[$k][1], $aBlocks[$k][0] + $aBlocks[$k][2], $aBlocks[$k][1] + $aBlocks[$k][3], _
                                             $aBlocks[$l][0], $aBlocks[$l][1] + $speed, $aBlocks[$l][0] + $aBlocks[$l][2], $aBlocks[$l][1] + $aBlocks[$l][3] + $speed) Then
                    $aBlocks[$k][6] = False
                    $aBlocks[$l][6] = False
                EndIf
            EndIf
        Next
        If $aBlocks[$k][6] And _RectCollision($aBlocks[$k][0], $aBlocks[$k][1], $aBlocks[$k][0] + $aBlocks[$k][2], $aBlocks[$k][1] + $aBlocks[$k][3], _
                                                                                 $ground_x, $ground_h + $speed + 1, $ground_x + $ground_w, $ground_h + $speed + 5) Then $aBlocks[$k][6] = False
    Next
EndFunc

Func Move_Block()
        Local $j
        For $j = 0 To $blocks - 1
            If $aBlocks[$j][6] Then $aBlocks[$j][1] += $speed
        Next
EndFunc

Func Next_Block()
    If $i < $blocks - 1 Then
        If $aBlocks[$i][6] = False Then
            $aBlocks[$i + 1][5] = True
            $aBlocks[$i + 1][6] = True
            $i += 1
        EndIf
    EndIf
EndFunc

Func _RectCollision($Rect1X1, $Rect1Y1, $Rect1X2, $Rect1Y2, $Rect2X1, $Rect2Y1, $Rect2X2, $Rect2Y2) ;left, top, bottom, right
    ; Prog@ndy
    Local Const $tagRECT = "long;long;long;long"
    Local $1 = DllStructCreate($tagRECT)
    Local $2 = DllStructCreate($tagRECT)
    Local $3 = DllStructCreate($tagRECT)
    DllStructSetData($1, 1, $Rect1X1)
    DllStructSetData($1, 2, $Rect1Y1)
    DllStructSetData($1, 3, $Rect1X2)
    DllStructSetData($1, 4, $Rect1Y2)
    DllStructSetData($2, 1, $Rect2X1)
    DllStructSetData($2, 2, $Rect2Y1)
    DllStructSetData($2, 3, $Rect2X2)
    DllStructSetData($2, 4, $Rect2Y2)
    Local $r = DllCall("User32.dll", "int", "IntersectRect", "ptr", DllStructGetPtr($3), "ptr", DllStructGetPtr($1), "ptr", DllStructGetPtr($2))
    If @error Then Return SetError(1,0,0)
    Return $r[0] <> 0
EndFunc

Func _Exit()
    For $i = 0 To $blocks - 1
        _GDIPlus_BrushDispose($aBlocks[$i][4])
    Next
    _GDIPlus_BrushDispose($hBackground_brush)
    _GDIPlus_BrushDispose($hGround_brush)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

I hope it helps you a little bit.

Br,

UEZ

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

Share this post


Link to post
Share on other sites

AWESOME!!! thanks so much thats perfect! now, is this right? i mean it looks alright but i'm not sure if my gravity equation is right, or if my collision detection could be improved, i'm going to look into the rect dll structs later but for now i just copied, i really would like to learn more about it. :huh2:

#include <GDIPLUS.au3>
#include <WINAPI.au3>
#include <ARRAY.au3>
#include <WINDOWSCONSTANTS.au3>
#include <GUICONSTANTSEX.au3>

Opt('GUIONEVENTMODE', 1)

Global $buffer_speed = 45

Global $window_main
Global $window_parent = Default

Global $left_pos = Default
Global $right_pos = Default

Global $window_width = 800
Global $window_height = 600
Global $window_offset = 5

Global $window_style = Default
Global $window_style_ex = Default


$window_main = GUICreate('', $window_width, $window_height, $left_pos, $right_pos, $window_style, $window_style_ex, $window_parent)
GUISetOnEvent(-3, 'quit', $window_main)
GUISetState(@SW_SHOW, $window_main)

_GDIPlus_Startup()

Global $graphic = _GDIPlus_GraphicsCreateFromHWND($window_main)
    Global $bb_bmp = _GDIPlus_BitmapCreateFromGraphics($window_width, $window_height, $graphic)
    Global $bb_graphic = _GDIPlus_ImageGetGraphicsContext($bb_bmp)


Global $background_brush = _GDIPlus_BrushCreateSolid ('0xFF' & '000099')
Global $ground_brush = _GDIPlus_BrushCreateSolid ('0xFF' & '202020')



Global $s[1]
;~ $s[0] = _GDIPlus_ImageLoadFromFile (@ScriptDir & '\s0.png') ;you don't have this so just ignore it...


Global $object_count = 1
Global $object_status[$object_count]
Global $object_pos[$object_count][2]
Global $object_size[$object_count][2]
Global $object_brush[$object_count]
Global $object_img[$object_count]
Global $object_direction[$object_count][2]
Global $object_time[$object_count]

$object_status[0] = False

;------------------------
;($x,$y,$w,$h,$brush,$img,$direction_x,$direction_y,$time)
;------------------------
;player
add_object (100,100,75,75,$background_brush,False,0,$window_offset,1)
;~ add_object (100,100,75,75,$background_brush,$s[0],0,$window_offset,1) ;this is using the image that i can't upload

;top
add_object (0,0,$window_width,$window_offset,$ground_brush,False,0,0,-1)

;right
add_object ($window_width-$window_offset,$window_offset,$window_offset,$window_height-($window_offset*11),$ground_brush,False,0,0,-1)

;bottom
add_object (0,$window_height-($window_offset*10),$window_width,$window_offset*10,$ground_brush,False,0,0,-1)

;left
add_object (0,$window_offset,$window_offset,$window_height-($window_offset*11),$ground_brush,False,0,0,-1)



_GDIPlus_GraphicsClear($bb_graphic, 0x60FFFFFF)

GUIRegisterMsg(0xF, 'MY_PAINT')
GUIRegisterMsg(0x85, 'MY_PAINT')
AdlibRegister('BUFFER', $buffer_speed)
AdlibRegister('PHYSICS', $buffer_speed)


While True
    Sleep(100)
WEnd





Func add_object ($x,$y,$w,$h,$brush,$img,$direction_x,$direction_y,$time)
    For $n = 0 To $object_count-1
        If $object_status[$n] = False Then
            $object_status[$n] = True
            assign_object_elements ($n,$x,$y,$w,$h,$brush,$img,$direction_x,$direction_y,$time)
            Return
        EndIf
    Next
    $object_count += 1
    ReDim $object_status[$object_count]
    ReDim $object_pos[$object_count][2]
    ReDim $object_size[$object_count][2]
    ReDim $object_brush[$object_count]
    ReDim $object_img[$object_count]
    ReDim $object_direction[$object_count][2]
    ReDim $object_time[$object_count]
    $object_status[$object_count-1] = True
    assign_object_elements ($object_count-1,$x,$y,$w,$h,$brush,$img,$direction_x,$direction_y,$time)
EndFunc
Func assign_object_elements ($n,$x,$y,$w,$h,$brush,$img,$direction_x,$direction_y,$time)
    $object_pos[$n][0] = $x
    $object_pos[$n][1] = $y
    $object_size[$n][0] = $w
    $object_size[$n][1] = $h
    $object_brush[$n] = $brush
    $object_img[$n] = $img
    $object_direction[$n][0] = $direction_x
    $object_direction[$n][1] = $direction_y
    $object_time[$n] = $time
EndFunc







Func calculate_objects_x_y ()
    For $n = 0 To $object_count-1
        If $object_status[$n] = True Then
            If $object_time[$n] <> -1 Then
                $object_pos[$n][0] += $object_direction[$n][0]
                $object_pos[$n][1] += $object_direction[$n][1]
                If check_blocking ($n,$object_pos[$n][0],$object_pos[$n][1],$object_size[$n][0],$object_size[$n][1]) = 'error' Then
                    $object_pos[$n][0] -= $object_direction[$n][0]
                    $object_pos[$n][1] -= $object_direction[$n][1]
                    $object_direction[$n][1] = 1
                    $object_time[$n] = 0
                Else
                    ;GRAVITY!!! = 9.8m/s^2
                    $object_time[$n] += 0.01
                    $g = 9.8
                    $t = $object_time[$n]
                    $s = (1/2)*$g*($t^2)
                    $object_direction[$n][1] = $s
                EndIf
            EndIf
        EndIf
    Next
EndFunc









Func check_blocking ($index,$x,$y,$w,$h)
    Local $n
    Local $xx
    Local $yy
    Local $ww
    Local $hh
    For $n = 0 To $object_count-1
        If $object_status[$n] = True Then
            If $n <> $index Then
                $xx = $object_pos[$n][0]
                $yy = $object_pos[$n][1]
                $ww = $object_size[$n][0]
                $hh = $object_size[$n][1]
                If _RectCollision($x,$y,$x+$w,$y+$h, _
                                $xx,$yy,$xx+$ww,$yy+$hh) Then
                   Return 'error'
                EndIf
;~              ;================================================
;~              ;================================================
;~              ;================================================
;~              If $xx > $x And $yy+$hh > $y And $yy < $y And $xx < $x+$w Then Return 'error' ;looking for blocking up
;~              If $xx < $x And $yy < $y+$h And $y < $yy And $xx+$ww > $x+$w Then Return 'error' ;looking for blocking down
;~              ;Is this ^^^^^^^^^^^^^^^^^^ right???
;~              ;================================================
;~              ;================================================
;~              ;================================================
            EndIf
        EndIf
    Next
    If $x < 0 Or $y < 0 Or $x+$w > $window_width Or $y+$h > $window_height Then
        Return 'error'
    EndIf
    Return 'ok'
EndFunc




Func _RectCollision($Rect1X1, $Rect1Y1, $Rect1X2, $Rect1Y2, $Rect2X1, $Rect2Y1, $Rect2X2, $Rect2Y2) ;left, top, bottom, right
    ; Prog@ndy
    Local Const $tagRECT = "long;long;long;long"
    Local $1 = DllStructCreate($tagRECT)
    Local $2 = DllStructCreate($tagRECT)
    Local $3 = DllStructCreate($tagRECT)
    DllStructSetData($1, 1, $Rect1X1)
    DllStructSetData($1, 2, $Rect1Y1)
    DllStructSetData($1, 3, $Rect1X2)
    DllStructSetData($1, 4, $Rect1Y2)
    DllStructSetData($2, 1, $Rect2X1)
    DllStructSetData($2, 2, $Rect2Y1)
    DllStructSetData($2, 3, $Rect2X2)
    DllStructSetData($2, 4, $Rect2Y2)
    Local $r = DllCall("User32.dll", "int", "IntersectRect", "ptr", DllStructGetPtr($3), "ptr", DllStructGetPtr($1), "ptr", DllStructGetPtr($2))
    If @error Then Return SetError(1,0,0)
    Return $r[0] <> 0
EndFunc







; tried using these but couldn't make them work properly
;~ Func _tPoint($x, $y)
;~     Local $tPOINT = DllStructCreate($tagPOINT)
;~     DllStructSetData($tPOINT, 'X', $x)
;~     DllStructSetData($tPOINT, 'Y', $y)
;~     Return $tPOINT
;~ EndFunc
;~ Func _tRect($x, $y, $w, $h)
;~     Local $tRect = DllStructCreate($tagRECT)
;~     DllStructSetData($tRect, 'Left', $x)
;~     DllStructSetData($tRect, 'Top', $y)
;~     DllStructSetData($tRect, 'Right', $x + $w)
;~     DllStructSetData($tRect, 'Bottom', $y + $h)
;~     Return $tRect
;~ EndFunc













Func draw_objects ()
    _GDIPlus_GraphicsClear($bb_graphic, 0x60FFFFFF) ;<========= cool little fade effect (looks like it's speedy)
;~  _GDIPlus_GraphicsClear ($bb_graphic,'0xFFFFFFFF') ;<========= simple but it works well
    For $n = $object_count-1 To 0 Step -1
        If $object_status[$n] = True Then
            If $object_img[$n] <> False Then
                _GDIPlus_GraphicsDrawImageRect($bb_graphic, $object_img[$n],$object_pos[$n][0],$object_pos[$n][1],$object_size[$n][0], $object_size[$n][1])
            Else
                _GDIPlus_GraphicsFillRect ($bb_graphic,$object_pos[$n][0],$object_pos[$n][1],$object_size[$n][0], $object_size[$n][1],$object_brush[$n])
            EndIf
        EndIf
    Next
EndFunc
Func PHYSICS ()
    calculate_objects_x_y ()
EndFunc
Func BUFFER()
    draw_objects ()
    _GDIPlus_GraphicsDrawImage($graphic, $bb_bmp, 0, 0)
EndFunc   ;==>BUFFER
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hWnd, Default, Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT
Func quit()
    _GDIPlus_GraphicsDispose($graphic)
        _GDIPlus_GraphicsDispose($bb_graphic)
        _GDIPlus_ImageDispose($bb_bmp)
    For $n = 0 To $object_count-1
        If $object_status[$n] = True Then
            _GDIPlus_BrushDispose ($object_brush[$n])
        EndIf
    Next
    _GDIPlus_BrushDispose ($background_brush)
    _GDIPlus_BrushDispose ($ground_brush)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>quit

Share this post


Link to post
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
Sign in to follow this  
Followers 0