Page 1 of 1

Hi Enrico !

Posted: Mon Oct 30, 2006 3:07 am
by areang
:lol: How to create games with xHarbour :lol:

I used FWH and xHB.


function Games()
local oBmpBackGround, oBmpSprite1, oBmpSprite2

DEFINE WINDOW oWnd

@0,0 bitmap oBmpBackGround FILE "room.bmp" pixel of oWnd

@20,10 bitmap oBmpSprite1 FILE "ball.bmp" pixel of oWnd

oBmpSprite1:lTransparent := .t.

?????????????????????????????
// But Not Transparent //
?????????????????????????????


ACTIVATE WINDOW oWnd

return nil

Thank's

Best Regard
Areang

Re: Hi Enrico !

Posted: Mon Oct 30, 2006 9:12 am
by Enrico Maria Giordano
This is a working sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    local oWnd, oBrush, oSprite, oTimer

    DEFINE BRUSH oBrush;
           FILE "c:\fwharbour\bitmaps\backgrnd\beach.bmp"

    DEFINE WINDOW oWnd;
           BRUSH oBrush

    @ 0, 0 BITMAP oSprite;
           FILE "c:\fwharbour\bitmaps\fdem5.bmp";
           PIXEL NOBORDER

    oSprite:lTransparent = .T.

    DEFINE TIMER oTimer OF oWnd;
           INTERVAL 10;
           ACTION MOVESPRITE( oWnd, oSprite )

    ACTIVATE WINDOW oWnd;
             ON INIT oTimer:Activate()

    RELEASE TIMER oTimer

    RETURN NIL


STATIC FUNCTION MOVESPRITE( oWnd, oSprite )

    LOCAL aWndRect := GETCLIENTRECT( oWnd:hWnd )

    LOCAL nWndWidth  := aWndRect[ 4 ] - aWndRect[ 2 ]
    LOCAL nWndHeight := aWndRect[ 3 ] - aWndRect[ 1 ]

    LOCAL nXPos, nYPos

    STATIC nXStep := 5
    STATIC nYStep := 5

    nXPos = oSprite:nLeft + nXStep
    nYPos = oSprite:nTop + nYStep

    IF nXPos < 0
        nXPos = 0
        nXStep = -nXStep
    ENDIF

    IF nYPos < 0
        nYPos = 0
        nYStep = -nYStep
    ENDIF

    IF nXPos + oSprite:nWidth >= nWndWidth
        nXPos = nWndWidth - oSprite:nWidth - 1
        nXStep = -nXStep
    ENDIF

    IF nYPos + oSprite:nHeight > nWndHeight
        nYPos = nWndHeight - oSprite:nHeight
        nYStep = -nYStep
    ENDIF

    oSprite:Move( nYPos, nXPos, , , .T. )

    RETURN NIL
EMG

Posted: Tue Oct 31, 2006 6:35 am
by areang
Thank's Enrico,

but the BMP size must fixed with window size.
when it not fixed the brush makes tiles on window surfaces.


Best Regard
Areang

Posted: Fri Nov 10, 2006 7:15 pm
by Rossine
Hi Areang,

Try this:

Code: Select all


...
  IF nYPos + oSprite:nHeight > nWndHeight
        nYPos = nWndHeight - oSprite:nHeight
        nYStep = -nYStep
    ENDIF

    oSprite:refresh()  &&<<<--- Inside This 

    oSprite:Move( nYPos, nXPos, , , .T. )

    RETURN NIL
Regards,

Rossine.

Posted: Fri Nov 10, 2006 7:39 pm
by Enrico Maria Giordano
Great!

EMG

Posted: Sat Nov 11, 2006 1:36 am
by Silvio
And if I want move the sprite with cursor key How I can make it ?

Posted: Sat Nov 11, 2006 8:01 am
by Enrico Maria Giordano

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    local oWnd, oBrush, oSprite

    DEFINE BRUSH oBrush;
           FILE "c:\fwharbour\bitmaps\backgrnd\beach.bmp"

    DEFINE WINDOW oWnd;
           BRUSH oBrush

    oWnd:bKeyDown = { | nKey | MoveSprite( oWnd, oSprite, nKey ) }

    @ 0, 0 BITMAP oSprite;
           FILE "c:\fwharbour\bitmaps\fdem5.bmp";
           PIXEL NOBORDER

    oSprite:lTransparent = .T.

    ACTIVATE WINDOW oWnd

    RETURN NIL


STATIC FUNCTION MOVESPRITE( oWnd, oSprite, nKey )

    LOCAL aWndRect := GETCLIENTRECT( oWnd:hWnd )

    LOCAL nWndWidth  := aWndRect[ 4 ] - aWndRect[ 2 ]
    LOCAL nWndHeight := aWndRect[ 3 ] - aWndRect[ 1 ]

    LOCAL nXPos, nYPos

    LOCAL nXStep := 0
    LOCAL nYStep := 0

    IF nKey = VK_RIGHT; nXStep = 5; ENDIF
    IF nKey = VK_LEFT; nXStep = -5; ENDIF

    IF nKey = VK_DOWN; nYStep = 5; ENDIF
    IF nKey = VK_UP; nYStep = -5; ENDIF

    nXPos = oSprite:nLeft + nXStep
    nYPos = oSprite:nTop + nYStep

    IF nXPos < 0
        nXPos = 0
        nXStep = -nXStep
    ENDIF

    IF nYPos < 0
        nYPos = 0
        nYStep = -nYStep
    ENDIF

    IF nXPos + oSprite:nWidth >= nWndWidth
        nXPos = nWndWidth - oSprite:nWidth - 1
        nXStep = -nXStep
    ENDIF

    IF nYPos + oSprite:nHeight > nWndHeight
        nYPos = nWndHeight - oSprite:nHeight
        nYStep = -nYStep
    ENDIF

    oSprite:Refresh()

    oSprite:Move( nYPos, nXPos, , , .T. )

    RETURN NIL
EMG

Posted: Sat Nov 11, 2006 1:34 pm
by Silvio
thanks Enrico !!!

Posted: Sat Nov 11, 2006 1:49 pm
by Silvio
And if I want press space key and fire another small sprite ?
and ihow I make if I want make collision on another sprite
think about space invaders....

Posted: Sat Nov 11, 2006 6:54 pm
by Rossine
Hi Enrico,

It is possible, using FREEIMAGE.DLL capture the image that this in a determined window (dialog/window) and record-her in the format. JPG?

Excuse me. I am using a translator :lol:

Posted: Sun Nov 12, 2006 8:07 am
by areang
Hi Enrico.

For the future the game is the good way for all clipper needed.
Just move the image object, click object, show object, hide object, rotate, scale and more. Play the sound and video file.

Think's the object are : image, sound and video

Can you make the lib for this ?

And I will buy the lib from you.

Thank's
Best Regard
Areang