UnderwareDESIGN

PlayBASIC => Show Case => Topic started by: thefrog on December 15, 2007, 05:52:01 AM

Title: Lunar lander type game
Post by: thefrog on December 15, 2007, 05:52:01 AM
Hi,

Here is Level one of 'Lunar caves'. It's a Lunar Lander type game.
It's far from finished but level 1 is playable

http://labarette.free.fr/LunarCaves.zip (http://labarette.free.fr/LunarCaves.zip)

I've been playing with PB for 1 month now and I'm really impressed by it's functionnalities and professionalism.

I should be completing the next levels and adding power ups soon.

You can tweak video settings by editing config.ini (Fullscreen,vsync and MaxFPs)

Use arrow keys to rotate ship
Up key, left CTRL for normal thrust
Left shift for Emergency thrust

Use landing pads to refuel (land gently)
pick up the 4 gems

See ya

Bob
Title: Re: Lunar lander type game
Post by: kevin on December 15, 2007, 10:04:48 PM

  Well done,  that's already looking and feeling excellent! 
Title: Re: Lunar lander type game
Post by: thefrog on December 17, 2007, 10:56:45 AM
Hello,

Here is an updated version with 2 more playable levels.
http://labarette.free.fr/lunarcaves (http://labarette.free.fr/lunarcaves)

you now return to the previous base when you die

I had a problem using setFps on some computers (movement wasn't smooth), so I use a Timer function to
update the screen instead, which works much better.

Also the program crashes on my laptop when openscreen is called, I don't know why yet.


Press and hold F key during a few seconds to see FPS
You should be getting between 60 and 70 Frames per second.
If it's not the case, could you please tell me ?

Thanks


Title: Re: Lunar lander type game
Post by: basil99 on December 18, 2007, 01:51:57 AM
Crash on my home PC ( WinXPsp2 ) and on another machine in office with Win98
Title: Re: Lunar lander type game
Post by: esper on December 18, 2007, 01:54:09 AM
I can't even download it. I get some message in French which probably is telling me that I suck at the internet.
Title: Re: Lunar lander type game
Post by: thefrog on December 19, 2007, 09:08:04 AM
Hi

I made a few changes in this version, should work better

http://labarette.free.fr/lunarcaves/ (http://labarette.free.fr/lunarcaves/)

To get it running on my laptop with ATI radeon Xpress 200M I had to:
- De-activate Catalyst AI
- Put vsync mode to AUTO (let the application select vsync mode)




Title: Re: Lunar lander type game
Post by: thefrog on February 26, 2009, 09:16:02 AM
Hi,

I've corrected a few problems and recompiled with PB 1.64
It should now run on all computers (I hope) Please tell me if it doesn't
Thanks


http://labarette.free.fr/lunarcaves (http://labarette.free.fr/lunarcaves)

(http://labarette.free.fr/lunarcaves/screenshots/1s.jpg)
Menu (http://labarette.free.fr/lunarcaves/screenshots/1.jpg)

(http://labarette.free.fr/lunarcaves/screenshots/2s.jpg)
Ingame (http://labarette.free.fr/lunarcaves/screenshots/2.jpg)

(http://labarette.free.fr/lunarcaves/screenshots/3s.jpg)
Ingame (http://labarette.free.fr/lunarcaves/screenshots/3.jpg)
Title: Re: Lunar lander type game
Post by: kevin on February 26, 2009, 09:32:58 AM

  Screen shots would be nice.
Title: Re: Lunar lander type game
Post by: kevin on February 26, 2009, 12:16:48 PM
  Tested on both machines here, runs fine as far as I can tell.  Although the menu has 3 options on the old duron box and 4 options on this machine.  It seems the player starts level 1 in completely different location also.   
Title: Re: Lunar lander type game
Post by: kevin on February 27, 2009, 01:03:41 AM

    On the point of compatibility,  as far as I tell the program buffers all images into video memory.     Given the number and size of these frames  (20 * (1024*768*4) )  this means the host system requires at least 62 meg of free video memory to play a level.     This will fail on systems with less. 

    The solution is rather than load the frames into video, load them as FX images, then draw current room frame to the screen size video buffer.  With this approach you could get the memory consumption down around the  8->12 meg mark.   Allowing much broader compatibility.

Title: Re: Lunar lander type game
Post by: thefrog on February 27, 2009, 07:24:11 AM
Ok thanks, I did the modifications concerning fxImage..

Strange about the location of first level changing, works here....


Here is a link to download the source code for anyone interested.

[plink]http://labarette.free.fr/lunarcaves/Lunarcavessources.zip (http://labarette.free.fr/lunarcaves/Lunarcavessources.zip)[/plink]



Title: Re: Lunar lander type game
Post by: kevin on February 28, 2009, 11:39:44 AM
 Thanks for posting the source.  Seems to be pretty well put together.  There's a few bits that can be improved.  One that comes to mind is your usage of FlushKeys within an input loop.  This can make the loop unresponsive to key input.   As often it's flushing keys before the scan code is read.  In other words it only needs flushing, if a valid input has been pressed.  


[pbcode]

psub Level(p_aLevelLock())
   local key=0
   local nLevelSelected=0

   
   repeat
      cls 0
;      flushkeys
      showstars(xStars#(),yStars#())
      drawimage nMenuImg,0,0,1   
 
      setfont 11
      centertext nResX/2,50,"LUNAR CAVES"
       setfont 10
      text nResX/2-100,200,"1 LEVEL 1"

      //Level 2
      if p_aLevelLock(2)=1
         setfont 10
         text nResX/2-100,230,"2 LEVEL 2"
      else
          setfont 12
           text nResX/2-100,230,"2 LEVEL 2 Locked"
      endif

      //Level 3
      if p_aLevelLock(3)=1
         setfont 10
         text nResX/2-100,260,"3 LEVEL 3"
      else
          setfont 12
          text nResX/2-100,260,"3 LEVEL 3 Locked"
      endif

      sync  

      key=scancode()
     
     ;select level
      if key>1 and key<10  
         ;play level if unlocked
         if  p_aLevelLock(key-1)<>0
                nLevelSelected=key-1
               NLives=3
               nScore=0
               nRotateSpeed=4
               LevelLoop (nLevelSelected,aRooms(),aMap(),aMapBg(),aPowerUp(),aPad(),aGem(),ship.shipdata,p_aLevelLock(),aShipLoc())
               flushkeys
               initstars(xStars#(),yStars#())
               key=0
          endif
     endif


   until esckey()

flushkeys

endpsub

[/pbcode]


  Also, the changes to FX images have certainly dropped the video consumption dramatically,  but from what I can tell your rendering the current room constantly in the main loop.   Given the size of the images, this will effect performance. In particular on slower, old clunkers.

  What I was getting at previously, is that you should use a single screen sized video image as a backdrop cache.   So when a room is changed, the FX buffers are drawn onto the video image once.   Then we just draw the Video version each update.    This costs a little extra video memory, but is best all round solution for performance  and compatibility .


 a bit like this..


[pbcode]

      path$="D:\LunarCaves\data\"

      openscreen 1024,768,32,2

   
      Dim Rooms(1)
   
      Level$="Level1\"

      LoadRooms(path$+Level$,Rooms())

      print "loading"

      // Backdrop IMage
      BackdropIMage=LoadNewFXIMage(Path$+Level$+"Backrock.jpg")

      // This (video) image, will hold the current room being displayed
      RoomImage=NewImage(1024,768)


      // Pick a random starting room, and reqrest a backdrop refresh
      CurrentRoom=NewRoom()   
      CurrentRoomRefresh=true



      // Calc Amount of video memory used
      VideoMemory      =CalcUsedImageMemory(1)
      SystemMemory   =CalcUsedImageMemory(2)
      

;      Setfps 60      

      Do

         // DRaw

         // Check for a change of rooms ?
         if CurrentRoomRefresh=true
            // if there was, we copy/draw the FX version of the room image
            // to the video version.
            CurrentRoomRefresh=false
            RenderToImage RoomImage
            DrawImage BackdropIMage,0,0,false
            DrawImage Rooms(CurrentRoom),0,0,true         
            rendertoscreen
         endif               

   
         // Draw the backdrop (solid) as there's no need for a CLS.
         DrawImage RoomImage,0,0,false


         // Press Space to simulate changing rooms
         if Spacekey()
               CurrentRoom=NewRoom()   

               // request the backdrop image be refreshed
               CurrentRoomRefresh=true
         endif

         // Dump some info to the screen
         Text 0,0,  " Current Room:"+str$(CurrentRoom)
         text 0,20, "          fps:"+str$(fps())
         Text 0,40, " Video Memory:"+str$(VideoMemory)
         Text 0,60, "System Memory:"+str$(SystemMemory)

         Sync
      loop



Function NewRoom()
   repeat
      ThisRoom=rnd(Getarrayelements(rooms(),1))
      text 100,100,thisroom
   until ThisRoom>0 and Rooms(ThisRoom)<>0

EndFunction ThisRoom
      


Function LoadRooms(path$,Rooms())
   Size=GetArrayElements(rooms(),1)
   For lp=1 to 100
      file$=path$+str$(lp)+".png"
      if Fileexist(file$)=true
            if lp>size then redim Rooms(lp)
            Rooms(lp)=loadNewFXIMage(file$)
            RgbMaskImage rooms(lp),$00ffffff
            Size=lp
            cls 0   
            centertext 400,400,"Loading.."+str$(lp)
            Sync
      endif
   next
EndFunction



Function DeleteRooms(Rooms())

   For lp=1 to GetArrayElements(rooms(),1)
      img=Rooms(lp)
      if img>0
         if GetImageStatus(img)
            deleteimage img
         endif
      endif
      Rooms(lp)=0
   next

EndFunction







; **=------------------------------------------------------------------=*
;              >> Calc Used Image Memory <<
; **=------------------------------------------------------------------=*
;
;  This _debug_ function runs through the PB image list and returns the
; total number of bytes images are using. Due to the buffer locking it's
; not going to be fast, so don't call it every frame !
;
; **=------------------------------------------------------------------=*


Function CalcUsedImageMemory(IMageType)

   local OldSurface=GetSurface()
   local img
   For Img=1 to GetImageQuantity()
      If Img=1 or GetImageStatus(Img)=true
         #print GetImageType(img)
         if ImageType=GetImageType(img)            
            
            Rendertoimage Img
            Lockbuffer
               local  ImgSize= GetImagePitch(Img)*GetIMageHeight(img)
            unlockbuffer
            // Check for screen. If so, add the second buffer
            Memory=Memory+ImgSize
         endif
      Endif
   next
   
   if ImageType=1
      img=0
      Rendertoimage Img
      Lockbuffer
            local  ImgSize= GetImagePitch(Img)*GetIMageHeight(img)
         unlockbuffer
      if Img=0 then   ImgSize=ImgSize*2                                       
      Memory=Memory+ImgSize
   endif
   
   RenderToImage OldSurface
EndFunction Memory

[/pbcode]


    Another option is to let the player choose the screen 'depth' they want to play in.   Many older video cards, have limited 32bit support.  Many of the really old one's don't support it at all.     So running the game 16bit will not only  1/2 the memory consumption, it'd make it viable on really really old machines.  

    You could even take this further if you wanted, and make the refresh resize the  scene to the 640,480  or 800,600.  
Title: Re: Lunar lander type game
Post by: thefrog on March 06, 2009, 08:19:40 AM
Ok thanks, I'll do this...
Title: Re: Lunar lander type game
Post by: micky4fun on March 06, 2009, 08:49:40 AM
Hi thefrog ,,

thanks for posting code , will look through later ,

nice game this is another favourite of mine ..
once again great collision tip

mick :)

Title: Re: Lunar lander type game
Post by: OldNESJunkie on March 13, 2009, 10:26:28 PM
Won't run for me on my laptop, gives a generic winblows error and then CTD.

Vista 64-bit home premium
4 GB DDR3 (yes, 3) RAM
1024MB GeForce 9800GTS
2.26 GHz Intel Core 2 Duo

Tried setting to XP SP2 compatibility but it does nothing, doesn't even load. lunar.exe takes up 52% CPU but nothing ever comes up.   ???
Title: Re: Lunar lander type game
Post by: thefrog on March 15, 2009, 04:53:39 PM
OH !

Have you tried running it from PlayBasic Editor, to see if it works ?
Maybe it would give us a error message
Thanks