Hi Enrico !

Post Reply
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Hi Enrico !

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Hi Enrico !

Post 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
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post 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
Rossine
Posts: 343
Joined: Tue Oct 11, 2005 11:33 am

Post 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.
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

And if I want move the sprite with cursor key How I can make it ?
Best Regards, Saludos

Falconi Silvio
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

thanks Enrico !!!
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post 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....
Best Regards, Saludos

Falconi Silvio
Rossine
Posts: 343
Joined: Tue Oct 11, 2005 11:33 am

Post 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:
areang
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Post 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
Post Reply