Author Topic: Monster Shooting?  (Read 3718 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Monster Shooting?
« on: January 25, 2009 »
Hiya all,

I got the Code from my Old space invader game that work in for blitzbasic but I hoping it will work for freebasic.
Could people point out why it the monster shooting doesnt work?

Code: [Select]
  #INCLUDE "TINYPTC_EXT.BI"
    #INCLUDE "WINDOWS.BI"
   
    #INCLUDE "Spritespal.bas"
    #INCLUDE "Spritesraw.bas"

    OPTION STATIC
    OPTION EXPLICIT

    CONST XRES = 800
    CONST YRES = 600
   
    CONST HALFX = XRES/2
    CONST HALFY = YRES/2
    Const Speed = 5
   
    'CONST PCLIP  = 0
   
    DIM SHARED AS INTEGER IMGX,IMGY
    IMGX=512:' WIDTH
    IMGY=172:' HEIGHT

    DIM SHARED AS INTEGER IMG_COLOURS(256)
    DIM SHARED AS INTEGER IMG_RAW(IMGX * IMGY)
   
    DIM SHARED BUFFER ( XRES * YRES ) AS UINTEGER
    DIM SHARED AS DOUBLE OLDTIME,GADD,DELTAVALUE,NEWTIME
   
    Declare Function KeyDown( ByVal KeyChar As Integer ) As Integer   
    DECLARE SUB LOAD_IMAGE()
    DECLARE SUB DRAW_IMAGE(BYVAL X1 AS INTEGER , BYVAL Y1 AS INTEGER, BYVAL W AS INTEGER, BYVAL H AS INTEGER, BYVAL SX AS INTEGER , BYVAL SY AS INTEGER )
     
    LOAD_IMAGE()
   
'-------------------------------------------------------------------------
' Open Screen.
'-------------------------------------------------------------------------

    PTC_ALLOWCLOSE(0)
    PTC_SETDIALOG(1,"Simple Game"+CHR$(13)+"FULL SCREEN?",0,1)               
    IF (PTC_OPEN("Framework code by Shockwave",XRES,YRES)=0) THEN
       END-1
    END IF   

    DELTAVALUE=.1
   
DIM shared  y,BX as integer
DIM shared  k as string
DIM shared  rateoffire as integer
Dim Shared  MonsterChoice as integer

' the higher you make this, the less Monster will fire at you. you could lower this value when
' going to a higher level, so that the Monster will fire at you more often.
rateoffire=1000

WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<> -32767 and PTC_GETLEFTBUTTON=FALSE)
   
    ' Keyboard Input from the User
    IF GETASYNCKEYSTATE(VK_UP)   = -32767 then y=y-Speed
    IF GETASYNCKEYSTATE(VK_Down) = -32767 then y=y+Speed
   
    ' DRAW_IMAGE ( STARTLEFT, STARTTOP, WIDTH,HEIGHT , SCREEN X , SCREEN Y)
   
    ' Monster - Enemys
    DRAW_IMAGE (300,0,20,170,0,10)
   
    ' The Dragon - The Player   
    DRAW_IMAGE (230,0,140,170,0,10+y)
   
    ' The DEMONS
    DRAW_IMAGE (80,0,150,170,0,0)
   
    ' make the monster to fire
    if Rnd(0,rateoffire)=False
       MonsterChoice=rnd(1)
       
       ' Monster to Choose which one to Fire
       select case MonsterChoice
     
            case 0
                  BX=BX-1
                  ' The DEMONS
                  DRAW_IMAGE (80,0,150,170,BX,0)
         
            case 1
                  BX=BX-1
                 ' Baby
                 DRAW_IMAGE (0,0,200,50,BX,y)
       end select
   
    endif
       
    NEWTIME=TIMER

    PTC_UPDATE@BUFFER(0)   
    ERASE BUFFER
    SLEEP 1
    DELTAVALUE=(TIMER-NEWTIME)*15
   
WEND
ptc_close()


'-------------------------------------------------------------------------------
'USAGE :  DRAWIMAGE ( X1 , Y1 , WIDTH , HEIGHT , SCREENX , SCREENY )
'-------------------------------------------------------------------------------

SUB DRAW_IMAGE(BYVAL X1 AS INTEGER , BYVAL Y1 AS INTEGER, BYVAL W AS INTEGER, BYVAL H AS INTEGER, BYVAL SX AS INTEGER , BYVAL SY AS INTEGER )
    DIM AS INTEGER X,Y,XX,YY,PIXEL
    YY=SY
    FOR Y=Y1 TO Y1+H
        XX=SX
        FOR X=X1 TO X1+W
           
        ' MAKE SURE POINT IS ON THE SCREEN;
       
        IF XX>1 AND XX<XRES AND YY>1 AND YY<YRES-1 THEN
            PIXEL=IMG_RAW(X+(Y*IMGX))
           
            'MAKE SURE IT'S NOT THE BACKGROUND COLOUR;
            IF PIXEL>0 THEN BUFFER (XX+(YY*XRES))=IMG_COLOURS(PIXEL)
           
        END IF
        XX=XX+1
        NEXT
        YY=YY+1
    NEXT
   
END SUB


SUB LOAD_IMAGE()
DIM AS INTEGER L,RR,GG,BB
'
' PALETTE FIRST..
'
    RR=0
    GG=1
    BB=2
   
    FOR L=0 TO 255       
        IMG_COLOURS(L)=RGB(Sprites.bmp.pal(RR),Sprites.bmp.pal(GG),Sprites.bmp.pal(BB))
        RR=RR+3
        GG=GG+3
        BB=BB+3
    NEXT
'
' RAW DATA NEXT..
'
    FOR L=0 TO (IMGX*IMGY)-1
        IMG_RAW(L)=Sprites.bmp.raw(L)
    NEXT
   
END SUB

' Credits to Clyde for this code.
Function KeyDown( ByVal KeyChar As Integer ) As Integer

    If GetAsyncKeyState(KeyChar) Then
        Return TRUE
    Else
        Return FALSE
    End if

End Function


'===============================================================================
'                                     ***END***
'===============================================================================
« Last Edit: January 25, 2009 by Hotshot »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Monster Shooting?
« Reply #1 on: January 25, 2009 »
Well this is would stop it working for a start;

Code: [Select]
    ' make the monster to fire
    if Rnd(0,rateoffire)=False
       MonsterChoice=rnd(1)

Code: [Select]
x=rnd(1)

Returns a random number between 0 and 1, you cant specify a range as you would in Blitz.

I cant run it though as the raw graphics files are not attached.

The other thing that sticks out to me is that you have declared speed as a constant.

While it wont cause it to crash I wouldn't declare a variable for the game like that.
Const is better used for things like screen resolutions and storing things that would be expensive to keep clculating in real time like the value of pi for instance, but you already know that because I mentioned it before.

You should probably use dim shared in this case.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Monster Shooting?
« Reply #2 on: January 27, 2009 »
Also, why are you using TPTC for games?  TPTC is designed for demos and FreeBasic has a really good built-in GFX library.

Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Monster Shooting?
« Reply #3 on: January 28, 2009 »
I dont know much about GFX library( does they have Document?) as I only know in TPTC  :)

Offline relsoft

  • DBF Aficionado
  • ******
  • Posts: 3303
  • Karma: 47
    • View Profile
Re: Monster Shooting?
« Reply #4 on: January 29, 2009 »
The FreeBasic help file (CHM) offers a lot of great examples.

Or use the wiki:

http://www.freebasic.net/wiki/wikka.php?wakka=TutHowToProgGame1
Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Monster Shooting?
« Reply #5 on: January 29, 2009 »
thank you for link  relsoft  :)