Sign in to follow this  
Followers 0
pixartist

How To create simple graphical effects

3 posts in this topic

Let's say i wanted to create Tetris with autoit, a very simple game which is 2d only, and i want to embedd it into a normal windows GUI. How would i do that? is there any libary to embed visuals like that into the winapi with autoit ?

Share this post


Link to post
Share on other sites



_GDIPlus Functions

or just use a graphic control :)

btw... if you want to do a game... you'll need to double buffer the _GDIPlus graphic... or it will flicker


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites

great...i tried gdi+ and the first 10 lines of code already showed how AWESOME it is:

AWESOME!!

Hey now, don't get put off just because it didn't work right off the bat, there's a lot of examples/discussion of GDI+ on the forums...

For something along the lines of what you want to do, here's an example from this post that I corrected so it didn't need a UDF that I don't have.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>

Local $p_1p = 40, $p_2p = 40, $direction = True, $boundaries = True, $xball = 1, $yball = 1, $gf = 2, $win = 1
Dim $points[2] = [0, 0]

Opt("GuiOnEventMode", 1)

#Region GUI
$GUI = GUICreate("GDI+", 700, 500, -1, -1, $WS_POPUP + $WS_BORDER)
GUISetBkColor(0x000000, $GUI)
GUISetState(@SW_SHOW, $GUI)

$p_1 = GUICtrlCreateGraphic(0, 0, 700, 500) ;draw p_1
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFFFF, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 15, 216, 10, 60)
;~ GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE)
GUICtrlSetPos($p_1, 10, $p_1p) ;place p_1

$p_2 = GUICtrlCreateGraphic(0, 0, 700, 500) ;draw p_2
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFFFF, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 500, 216, 10, 60)
;~ GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE)
GUICtrlSetPos($p_2, 165, $p_2p) ;place p_2

$ball = GUICtrlCreateGraphic(0, 0, 700, 500) ;draw ball
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFFFF, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 300, 100, 15, 15)
GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
;~ GUICtrlSetGraphic(-1, $GUI_GR_CLOSE)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE)

;scores
_Graphicdraw(300, 5, 5, 40) ;draw right line
_Graphicdraw(390, 5, 5, 40) ;draw left line
_Graphicdraw(300, 45, 95, 5) ;draw bottom line
$p_1s = GUICtrlCreateLabel("0",310,7,35,35)
GUICtrlSetColor($p_1s,0xFFFFFF)
GUICtrlSetFont($p_1s,20,400,0,'Comic Sans MS')
$p_2s = GUICtrlCreateLabel("0",355,7,35,35)
GUICtrlSetColor($p_2s,0xFFFFFF)
GUICtrlSetFont($p_2s,20,400,0,'Comic Sans MS')

;outline
_Graphicdraw(345, 0, 5, 500) ;draw center line
_Graphicdraw(0, 0, 5, 500) ;draw left line
_Graphicdraw(0, 0, 700, 5) ;draw top line
_Graphicdraw(695, 0, 5, 500) ;draw right line
_Graphicdraw(0, 495, 700, 5) ;draw bottom line
#EndRegion GUI

HotKeySet("{ESC}", "_Exit")


Func _Graphicdraw($left, $top, $width, $height)
    GUICtrlCreateGraphic(0, 0, 700, 500)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFFFF, 0xFFFFFF)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, $left, $top, $width, $height)
;~  GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE)
EndFunc   ;==>_Graphicdraw

Func _Exit()
    Exit
EndFunc   ;==>_Exit


While 1
    Sleep(40)
    If ($direction) Then ;move ball to right
        $xball += $gf * 2
        GUICtrlSetPos($ball, $xball, $yball)
        GUICtrlSetGraphic($ball, $GUI_GR_REFRESH)
    Else
        $xball -= $gf * 2 ;move ball to left
        GUICtrlSetPos($ball, $xball, $yball)
        GUICtrlSetGraphic($ball, $GUI_GR_REFRESH)
    EndIf
    If ($boundaries) Then ;move ball to top
        $yball += $gf * 3
        GUICtrlSetPos($ball, $xball, $yball)
        GUICtrlSetGraphic($ball, $GUI_GR_REFRESH)
    Else
        $yball -= $gf * 3 ;move ball to bottom
        GUICtrlSetPos($ball, $xball, $yball)
        GUICtrlSetGraphic($ball, $GUI_GR_REFRESH)
    EndIf
    If ($yball > 350) Then $boundaries = False ;the ball hit the bottom
    If ($yball < -70) Then $boundaries = True ;the ball hit the top
    If (($xball >= 350) And ($direction)) Then ;the ball is in the line of right player
        $contact = $yball - $p_2p ;calculate contact
        ConsoleWrite('$contact p_2 >> $yball : ' & $yball & ' //  $p_2p : ' & $p_2p & ' //  $contact : ' & $contact & @CRLF)
        If (($contact > 88) And ($contact < 180)) Then ;check if there is contact
            $direction = False ;move the ball to left
        Else ;no contact, right player lost
            $points[1] += 1 ;+1 pt for player 2
            GUICtrlSetData($p_2s,$points[1]) ;update score
            $gf = 0 ;stop ball move
            $xball = 345 ;replace xball
            $yball = 130 ;replace yball
            $direction = False ;move the ball to left
            $win = 3 ;active restart ball
            ConsoleWrite('win p_2 >> $points[0] : ' & $points[0] & ' //  $points[1] : ' & $points[1] & @CRLF)
        EndIf
    EndIf
    If (($xball <= -268) And (Not ($direction))) Then ;the ball is in the line of left player
        $contact = $yball - $p_1p ;calculate contact
        ConsoleWrite('$contact p_1 >> $yball : ' & $yball & ' //  $p_1p : ' & $p_1p & ' //  $contact : ' & $contact & @CRLF)
        If (($contact > 100) And ($contact < 180)) Then ;check if there is contact
            $direction = True ;move the ball to right
        Else
            $points[0] += 1 ;+1 pt for player 1
            GUICtrlSetData($p_1s,$points[0]) ;update score
            $gf = 0 ;stop ball move
            $xball = -258 ;replace xball
            $yball = 130 ;replace yball
            $direction = True ;move the ball to right
            $win = 2 ;active restart ball
            ConsoleWrite('win p_1 >> $points[0] : ' & $points[0] & ' //  $points[1] : ' & $points[1] & @CRLF)
        EndIf
    EndIf

    ;Keys for move players
    If _IsPressed ("26") And _IsPressed("5A") Then
        If $p_2p >= -190 Then
            $p_2p -= 10
            GUICtrlSetPos($p_2, 165, $p_2p)
        EndIf
        If $p_1p >= -190 Then
            $p_1p -= 10
            GUICtrlSetPos($p_1, 10, $p_1p)
        EndIf
    ElseIf _IsPressed ("26") And _IsPressed("53") Then
        If $p_2p >= -190 Then
            $p_2p -= 10
            GUICtrlSetPos($p_2, 165, $p_2p)
        EndIf
        If $p_1p <= 200 Then
            $p_1p += 10
            GUICtrlSetPos($p_1, 10, $p_1p)
        EndIf
    ElseIf _IsPressed ("28") And _IsPressed("5A") Then
        If $p_2p <= 200 Then
            $p_2p += 10
            GUICtrlSetPos($p_2, 165, $p_2p)
        EndIf
        If $p_1p >= -190 Then
            $p_1p -= 10
            GUICtrlSetPos($p_1, 10, $p_1p)
        EndIf
    ElseIf _IsPressed ("28") And _IsPressed("53") Then
        If $p_2p <= 200 Then
            $p_2p += 10
            GUICtrlSetPos($p_2, 165, $p_2p)
        EndIf
        If $p_1p <= 200 Then
            $p_1p += 10
            GUICtrlSetPos($p_1, 10, $p_1p)
        EndIf
    ElseIf (_IsPressed("26") And $p_2p >= -190) Then
        $p_2p -= 10
        GUICtrlSetPos($p_2, 165, $p_2p)
    ElseIf (_IsPressed("28") And $p_2p <= 200) Then
        $p_2p += 10
        GUICtrlSetPos($p_2, 165, $p_2p)
    ElseIf (_IsPressed("5A") And $p_1p >= -190) Then
        $p_1p -= 10
        GUICtrlSetPos($p_1, 10, $p_1p)
    ElseIf (_IsPressed("53") And $p_1p <= 200) Then
        $p_1p += 10
        GUICtrlSetPos($p_1, 10, $p_1p)
    ElseIf (_IsPressed("25") And $win = 3) Then
        $win = 1
        $gf = 2
    ElseIf (_IsPressed("20") And $win = 2) Then
        $win = 1
        $gf = 2
    EndIf
WEnd


Func _OnAutoItExit()
    Exit
EndFunc   ;==>_OnAutoItExit

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