FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Hi Enrico !
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
Hi Enrico !
Posted: Mon Oct 30, 2006 03:07 AM

How to create games with xHarbour

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

:lol::lol:

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Hi Enrico !
Posted: Mon Oct 30, 2006 09:12 AM
This is a working sample:

#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
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
Hi Enrico !
Posted: Tue Oct 31, 2006 06:35 AM

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

Posts: 344
Joined: Tue Oct 11, 2005 11:33 AM
Hi Enrico !
Posted: Fri Nov 10, 2006 07:15 PM
Hi Areang,

Try this:

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



Rossine.



Harbour and Harbour++
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Hi Enrico !
Posted: Sat Nov 11, 2006 01:36 AM

And if I want move the sprite with cursor key How I can make it ?

Best Regards, Saludos



Falconi Silvio
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Hi Enrico !
Posted: Sat Nov 11, 2006 08:01 AM
#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
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Hi Enrico !
Posted: Sat Nov 11, 2006 01:34 PM

thanks Enrico !!!

Best Regards, Saludos



Falconi Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Hi Enrico !
Posted: Sat Nov 11, 2006 01:49 PM

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
Posts: 344
Joined: Tue Oct 11, 2005 11:33 AM
Hi Enrico !
Posted: Sat Nov 11, 2006 06:54 PM

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:

Obrigado, Regards, Saludos



Rossine.



Harbour and Harbour++
Posts: 128
Joined: Mon Jul 31, 2006 03:23 PM
Hi Enrico !
Posted: Sun Nov 12, 2006 08:07 AM

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

Continue the discussion