Monday, 23 April 2012

End of Week 2 (ish)

I took a break after week one, so allowing for that, this is the end of the second week of posts.

The Blog is closer to three weeks old, but either way, it's come a long way.

We now have object loaded from a data file, but to see them in the game, needs an updated icon sheet.

Here is the source, without transparency - to go in the artwork folder with the name standard source.png.
Here, I filled the magenta bits in orange to help me line up the new graphics.  Filling the orange grid with magenta when all the objects have been added will put this back to normal.

And this is the transparent one for the media folder with the name standard.png.
They have both been optimised to keep the sizes down.

And here's a complete code check  - Just over 900 lines - to keep everything in sync.

// 23 April 2012 - Tabs converted to 3 spaces
// Constants must go at start of program

#constant PANEL_ROWS   3
#constant PANEL_COLS   4

#constant DEPTH_MENU   10
#constant DEPTH_SCORE   20
#constant DEPTH_PANEL   30
#constant DEPTH_WORK   40

#constant MAX_WORKOBJECTS   100

#constant FRAME_HIGHLIGHT   251
#constant FRAME_TRASHCAN      252

#constant STATE_SETUP   0
#constant STATE_INTRO   1
#constant STATE_DEMO   2
#constant STATE_MENU   3
#constant STATE_RUNNING   4
#constant STATE_EXIT   99

#constant MENU_FADE      1.0
#constant MENU_ITEMS      2

#constant MENU_DIVTOP   0.25
#constant MENU_DIVSIZE   0.10

#constant MENU_RED      255
#constant MENU_GREEN   165
#constant MENU_BLUE      0
#constant MENU_REDHI   255
#constant MENU_GREENHI   255
#constant MENU_BLUEHI   0

#constant TRANS_NONE   0
#constant TRANS_FADEIN   1
#constant TRANS_FADEOUT   2

// User Defined Types - custom data structures

type displayType
   physWidth#
   physHeight#
   virtWidth#
   virtHeight#
   iconSize#
   textHeight#
   lastFPS#
   iconImage
   highSprite
   transType
   transCount#
   transStep#
endtype

type touchType
   pointDX#
   pointDY#
   pointWX#
   pointWY#
   spritePicked
   objectPicked
   menuPicked
   pickOffsetX#
   pickOffsetY#
endtype

type panelType
   height#
   speed#
   isOpen
   image
   sprite
   text
   sound
   iconMax
endtype

type WorkObjectType
   isFree
   objectID
   sprite
endtype

type GameType
   state
   level
   topObject
endtype

type MainObjectType
   name$
   detail$
   icon
   isKnown
   isGroup
endtype

// I must remember to put this somewhere

global numWorkObjects = 0

Initialise()

// Temporary Objects

imageRef = SafeloadImage( "finger.png" )
spriteRef = createSprite( imageRef )

// Main Loop
do
   LoopStart()
   select GameState()
      case STATE_SETUP
         // Setup Code
         testNum = LoadObjectData( "standard" )
         setGameState( STATE_INTRO )
         // Workaround to ensure frame rate ok before menu is called
         // if timer() > 2.0 then setGameState( STATE_MENU )
      endcase
      case STATE_INTRO
         // Intro Code
         print(" Objects : " + str( TopObject() ) )
         for i=1 to TopObject()
            printc( str(i) + " : " + ObjectName( i ) + " : " + str( ObjectIcon( i) ) )
            if ObjectIsGroup( i ) > 0
               printc( ", Group: ")
               thisString$ = ObjectDetail( i )
               thisNum = len( thisString$ ) / 2
               for j = 1 to thisNum
                  thisCode$ = mid( thisString$ , j*2 - 1 , 2)
                  thisObject = Base96Decode( thisCode$ )
                  printc( ObjectName( thisObject ) )
                  if j < thisNum then printc( ", " )
               next j
               print( "." )
            else
               print( ", " + chr(34) + ObjectDetail( i ) + chr( 34 ))
            endif
         next i
         print( " ----- ")
      endcase
      case STATE_DEMO
         // Demo Code
      endcase
      case STATE_MENU
         // Menu Code
         if getTextVisible( menuText[ 1 ]) = 0
            // Menu starting - Activate Transition
            StartTransition( TRANS_FADEIN , MENU_FADE )
            thisX# = VirtWidth() / 2.0
            thisY# = VirtHeight() * MENU_DIVTOP
            thisSize# = VirtHeight() * MENU_DIVSIZE
            for i=1 to MENU_ITEMS
               setTextSize( menuText[ i ] , thisSize# )
               setTextAlignment( menuText[ i ] , 1 )
               setTextDepth( menuText[ i ] , DEPTH_MENU )
               setTextPosition( menuText[ i ] , thisX# , thisY# )
               setTextVisible( menuText[ i ] , 1 )
               setTextColor( menuText[ i ] , MENU_RED , MENU_GREEN, MENU_BLUE , 0 )
               thisY# = thisY# + getTextTotalHeight( menuText[ i ] ) * 2.0
            next i
         elseif (Transition() = TRANS_FADEIN) or (Transition() = TRANS_FADEOUT)
            thisAlpha = 255.0 * TransitionCount()
            if Transition() = TRANS_FADEOUT then thisAlpha = 255 - thisAlpha
            for i=1 to MENU_ITEMS
               setTextColorAlpha( menuText[ i ] , thisAlpha )
            next i
            if TransitionCount() = 1.0
               if Transition() = TRANS_FADEOUT
                  // Menu Exiting
                  for i=1 to MENU_ITEMS
                     setTextVisible( menuText[ i ] , 0 )
                  next i
                  select MenuPicked()
                     case 1
                        // Menu Option 1
                        setGameState( STATE_RUNNING )
                     endcase
                     case 2
                        // Menu Option 2
                        setGameState( STATE_EXIT )
                     endcase
                  endselect
               endif
               StopTransition()
            endif
         endif
         checkMenuPointer()
      endcase
      case STATE_RUNNING
         // Running Code
         checkGamePointer()
      endcase
      case default
         // Picks up unknown states - including STATE_EXIT
         exit
      endcase
   endselect

   // Position temporary finger sprite
   setSpritePosition( spriteRef , PointDX() , PointDY() )

   PrintDiagnostics()
   sync()
loop

end

// Loop Functions

function LoopStart()
   display.lastFPS# = screenFPS()
   panel.speed# = panelHeight() / (lastFPS() * 1.25)
   touch.pointDX# = getPointerX()
   touch.pointDY# = getPointerY()
   touch.pointWX# = ScreentoWorldX(PointDX())
   touch.pointWY# = ScreentoWorldY(PointDY())
   if Transition() > TRANS_NONE then UpdateTransition()
endfunction

// Game Functions

function checkGamePointer()
   if getPointerPressed() > 0
      if PointDY() >= getTextY( panelText() ) and PointDY() < getSpriteY( panelSprite() )
         ToggleTrayOpen()
      elseif PointDY() < getTextY( panelText() )
         touch.spritePicked = getSpriteHit( PointWX() , pointWY() )
         if SpritePicked() > 0
            touch.objectPicked = FindWorkObjectBySprite( SpritePicked() )
            if ObjectPicked() > 0
             touch.pickOffsetX# = PointWX() - getSpriteXByOffset( SpritePicked() )
             touch.pickOffsetY# = PointWY() - getSpriteYByOffset( SpritePicked() )
            endif
         endif
      endif
   elseif getPointerReleased() > 0
      if thisObjectPicked > 0
         thisX# = PointWX() - PickOffsetX()
         thisY# = PointWY() - PickOffsetY()
         HideHighLight()
         if WorldToScreenY( thisY#) >= getTextY( panelText() )
            DelWorkObject( ObjectPicked() )
         else
            setSpritePositionByOffset( SpritePicked() , thisX# , thisY# )
            setSpriteDepth( SpritePicked() , DEPTH_WORK - 1 )
            thisObjectUnder = WorkObjectIsOver( ObjectPicked() )
            if thisObjectUnder > 0
               // This is where the merge objects code goes
            endif
         endif
      endif
      touch.spritePicked = 0
      touch.objectPicked = 0
      touch.pickOffsetX# = 0.0
      touch.pickOffsetY# = 0.0
   elseif getPointerState() > 0
      if ObjectPicked() > 0
         thisX# = PointWX() - PickOffsetX()
         thisY# = PointWY() - PickOffsetY()
         setSpritePositionByOffset( SpritePicked() , thisX# , thisY# )
         setSpriteDepth( SpritePicked() , DEPTH_PANEL - 5 )
         if WorldToScreenY( thisY#) >= getTextY( panelText() )
            HighlightSprite( SpritePicked() , FRAME_TRASHCAN )
         else
            thisObjectUnder = WorkObjectIsOver( ObjectPicked() )
            if thisObjectUnder > 0
               HighlightSprite( WorkObjectSprite( thisObjectUnder ) , FRAME_HIGHLIGHT )
            else
               HideHighLight()
            endif
         endif
      endif
   endif

   if panelIsOpen() = 1
      if getSpriteY( panelSprite() ) > ( PhysHeight() - panelHeight() )
         MovePanel( -panelSpeed() )
      endif
   else
      if getSpriteY( panelSprite() ) < PhysHeight()
         MovePanel( panelSpeed() )
      endif
   endif
endfunction

// Menu Functions

function checkMenuPointer()
   thisMenuSelected = 0
   for i=1 to MENU_ITEMS
      if getTextHitTest( menuText[ i ] , PointDX() , PointDY() ) > 0
         thisMenuSelected = i
         exit
      endif
   next i
   if getPointerPressed() > 0
      // Pointer Pressed
      touch.menuPicked = thisMenuSelected
   elseif getPointerReleased() > 0
      // Pointer Released
      if thisMenuSelected > 0 and thisMenuSelected = MenuPicked() then StartTransition( TRANS_FADEOUT , MENU_FADE )
   elseif getPointerState() > 0
      // PointerHeld
      if MenuPicked() > 0
         if thisMenuSelected = MenuPicked()
            setTextColorRed( menuText[ MenuPicked() ] , MENU_REDHI )
            setTextColorGreen( menuText[ MenuPicked() ] , MENU_GREENHI )
            setTextColorBlue( menuText[ MenuPicked() ] , MENU_BLUENHI )
         else
            setTextColorRed( menuText[ MenuPicked() ] , MENU_RED )
            setTextColorGreen( menuText[ MenuPicked() ] , MENU_GREEN )
            setTextColorBlue( menuText[ MenuPicked() ] , MENU_BLUE )
         endif
      endif
   endif
endfunction

// Transition Functions

function StartTransition( thisType , thisTime# )
   display.transType = thisType
   display.transCount# = 0.0
   display.transStep# = 1.0 / ( lastFPS() * thisTime# )
endfunction

function StopTransition()
   display.transType = TRANS_NONE
endfunction

function UpdateTransition()
   if TransitionCount() < 1.0 then display.transCount# = TransitionCount() + TransitionStep()
   if TransitionCount() > 1.0 then display.transCount# = 1.0
endfunction

// Diagnostic Functions

function PrintDiagnostics()
   printc( "Phy: " + str( PhysWidth() , 0) + " x " + str( PhysHeight() , 0 ))
   printc( ", Vir: " + str( VirtWidth() , 1) + " x " + str( VirtHeight() , 1 ))
   print( ", @ " + str ( lastFPS() , 2 ) + " fps" + chr(10) )
   printc("Transition Type : " + str( Transition() ) )
   printc(", Count: " + str( TransitionCount() , 3 ) )
   print(", Step: " + str( TransitionStep() , 3 ) + chr(10))
   print("Game State : " + str( GameState() ) + chr(10))
   print("Objects : " + str( TopObject() ) + chr(10) )

   printc( "Pointer (Display): " )
   print( str( PointDX() ) + " x " + str( PointDY() ) )
   printc( "Pointer (World): " )
   print( str( PointWX() ) + " x " + str( PointWY() ) )
   printc( "Sprite: ")
   print( str( getSpriteHit( PointDX() , PointDY() )))
   printc( "Sprite Picked: ")
   printc( str( SpritePicked() ))
   printc( ", Object Picked: ")
   printc( str( ObjectPicked() ))
   printc( ", Over : " )
   print( str( WorkObjectIsOver( ObjectPicked() ) ))
endfunction

// Panel Functions

function ToggleTrayOpen()
   panel.isOpen = 1 - panelIsOpen()
   if panelSound() > 0 then playSound( panelSound() )
endfunction

function MovePanel( distance# )
   setSpriteY( panelSprite() , getSpriteY( panelSprite() ) + distance# )
   setTextY( panelText() , getTextY( panelText() ) + distance# )
   PositionPanelIcons()
endfunction

function PositionPanelIcons()
   iconDepth = getSpriteDepth( PanelSprite() ) - 1
   for icon = 1 to panelIconMax()
      offset = icon - 1
      col = offset mod PANEL_COLS
      row = offset / PANEL_COLS
      x = col * IconSize() + 2
      y = row * IconSize() + getSpriteY( PanelSprite() ) + 2
      setSpritePosition( panelIconSprite[ icon ] , x , y )
      setSpriteDepth( panelIconSprite[ icon ] , iconDepth )
   next icon
endfunction

// Load Functions

function SafeLoadImage( thisFileName$ )
   if getFileExists( thisFileName$ )
      thisImageRef = loadImage( thisFileName$ )
   else
      thisImageRef = 0
   endif
endfunction thisImageRef

function SafeLoadSound( thisFileName$ )
   if getFileExists( thisFileName$ )
      thisSoundRef = loadSound( thisFileName$ )
   else
      thisSoundRef = 0
   endif
endfunction thisSoundRef

// Base 96 Functions

function Base96Encode( thisValue )
   lowValue = thisValue mod 96
   highValue = ( thisValue / 96 ) mod 96
   thisString$ = chr( highValue + 32 ) + chr( lowValue + 32 )
endfunction thisString$

function Base96Decode( thisString$ )
   thisLen = len(thisString$)
   if thisLen = 0
      thisValue = 0
   else
      if thisLen = 1 then thisString$ = " " + thisString$
      highValue = asc( left( thisString$ , 1 ) ) - 32
      lowValue = asc( mid( thisString$ , 2, 1 ) ) - 32
      thisValue = highValue * 96 + lowValue
   endif
endfunction thisValue

function Base96Sort( thisString$ )
   thisLen = len(thisString$)
   if thisLen > 2 and (thisLen && 1) = 0
      thisArraySize = thisLen / 2
      dim tempArray[ thisArraySize ] as string
      for i=1 to thisArraySize
         tempArray[ i ] = mid( thisString$ , i*2 - 1 , 2)
      next i
      SortTempArray( thisArraySize )
      thisString$ = ""
      for i=1 to thisArraySize
         thisString$ = thisString$ + tempArray[ i ]
      next i
   endif
endfunction thisString$

function SortTempArray( thisSize )
   for i=1 to thisSize - 1
      thisLow = i
      for j = i + 1 to thisSize
         if tempArray[j] < tempArray[thisLow] then thisLow = j
      next j
      if thisLowest <> i
         temp$ = tempArray[i]
         tempArray[i] = tempArray[thisLow]
         tempArray[thisLow] = temp$
      endif
   next i
endfunction

// Main Object Functions

function ObjectValid( thisObject )
   thisBool = ( thisObject > 0 and thisObject <= TopObject() )
endfunction thisBool

function FindObjectByName( thisName$ )
   thisName$ = upper( thisName$ )
   for thisObject = 1 to TopObject()
      if upper( ObjectName( thisObject )) = thisName$ then exit
   next thisObject
   if thisObject > TopObject() then thisObject = 0
endfunction thisObject

// Work Object Functions

function TopWorkObject()
endfunction numWorkObjects

function WorkObjectValid( thisObject )
   thisBool = ( thisObject > 0 and thisObject <= TopWorkObject() )
endfunction thisBool

function FirstFreeWorkObject()
   for thisObject = 1 to TopWorkObject()
      if WorkObjectIsFree( thisObject ) > 0 then exit
   next thisObject
   if thisObject > MAX_WORKOBJECTS then thisObject = 0
endfunction thisObject

function AddWorkObject( thisObjectID, thisSprite )
   thisObject = FirstFreeWorkObject()
   if thisObject > TopWorkObject() then numWorkObjects = thisObject
   if WorkObjectValid( thisObject )
      workObject[ thisObject ].isFree = 0
      workObject[ thisObject ].objectID = thisObjectID
      workObject[ thisObject ].sprite = thisSprite
   endif
endfunction thisObject

function DelWorkObject( thisObject )
   if WorkObjectValid( thisObject )
      workObject[ thisObject ].isFree = 1
      if WorkObjectSprite( thisObject ) > 0
         thisSprite = WorkObjectSprite( thisObject )
         workObject[ thisObject ].sprite = 0
         if getSpriteExists( thisSprite ) then deleteSprite( thisSprite )
      endif
      while WorkObjectIsFree( TopWorkObject() ) = 1 and TopWorkObject() >= 0
         dec numWorkObjects , 1
      endwhile
   endif
endfunction

function CreateWorkObjectSprite( thisObject , thisX , thisY )
   if WorkObjectIsFree( thisObject ) = 0
      if WorkObjectSprite( thisObject ) = 0 then workObject[ thisObject ].sprite = createSprite( IconImage() )
      thisSprite = WorkObjectSprite( thisObject )
      fixSpriteToScreen( thisSprite , 0 )
      setSpriteSize( thisSprite , IconSize() , - 1)
      setSpriteOffset( thisSprite , iconSize() / 2.0 , iconSize() / 2.0 )
      setSpritePositionByOffset( thisSprite , thisX , thisY )
      setSpriteDepth( thisSprite , DEPTH_WORK - 1 )
      setSpriteAnimation( thisSprite , 64 , 64 , 252 )
      setSpriteFrame( thisSprite , WorkObjectID( thisObject ) )
   endif
endfunction

function WorkObjectIsOver( thisWorkObject )
   thisSprite = WorkObjectSprite( thisWorkObject )
   if thisSprite > 0
      thisX# = getSpriteXByOffset( thisSprite )
      thisY# = getSpriteYByOffset( thisSprite )
      for thisObject = 1 to TopWorkObject()
         if thisObject <> thisWorkObject
            thisSprite = WorkObjectSprite( thisObject )
            if thisSprite > 0
               diffX# = abs( getSpriteXByOffset( thisSprite ) - thisX# )
               diffY# = abs( getSpriteYByOffset( thisSprite ) - thisY# )
               if diffX# < iconSize() and diffY# < iconSize() then exit
            endif
         endif
      next thisObject
      if thisObject > TopWorkObject() then thisObject = 0
   else
      thisObject = -1
   endif
endfunction thisObject

function FindWorkObjectBySprite( thisSprite )
   for thisObject = 1 to TopWorkObject()
      if WorkObjectSprite( thisObject ) = thisSprite then exit
   next thisObject
   if thisObject > TopWorkObject() then thisObject = 0
endfunction thisObject

function HideHighLight()
   if HighSprite() > 0
      if getSpriteExists( HighSprite() ) then deleteSprite( HighSprite() )
      display.highSprite = 0
   endif
endfunction

function HighlightSprite( thisSprite , thisFrame )
   if thisSprite > 0 and thisFrame > 0 and thisFrame < 253
      if getSpriteExists( thisSprite )
         HideHighLight()
         display.highSprite = cloneSprite( thisSprite )
         setSpriteFrame( HighSprite() , thisFrame )
         setSpriteDepth( HighSprite() , getSpriteDepth( HighSprite() ) - 1)
      endif
   endif
endfunction

// Game State Functions

function SetGameState( thisState )
   game.state = thisState
endfunction

// Data Load Functions

function LoadObjectData( thisName$ )
   // Pass the name without extension
   thisTextName$ = thisName$ + ".txt"
   thisImageName$ = FindImageFile( thisName$ )
   if getFileExists( thisTextName$ ) and thisImageName$ <> ""
      // Both data files exist
      dim tempArray[ 1000 ] as string
      thisArraySize = 0
      thisFile = openToRead( thisTextName$ )
      thisString$ = readLine( thisFile )
      repeat
         if thisString$ <> ""
            inc thisArraySize , 1
            tempArray[ thisArraySize ]  = thisString$
         endif
         thisString$ = readLine( thisFile )
      until fileEof( thisFile ) > 0
      closefile( thisFile )
      // Convert Data to Array
      game.topObject = thisArraySize
      dim MainObject[ topObject() ] as MainObjectType
      for i=1 to topObject()
         thisString$ = tempArray[ i ]
         thisLen = len( thisString$ )
         thisComma = FindSubString( thisString$ , "," , 1 )
         thisColon = FindSubString( thisString$ , ":" , thisComma + 1 )
         if thisComma > 0
            MainObject[ i ].name$ = left( thisString$ , thisComma - 1)
            if thisColon > 0
               MainObject[ i ].detail$ = right( thisString$ , thisLen - thisColon )
               thisLen = thisColon - 1
               thisString$ = left( thisString$ , thisLen)
            else
               MainObject[ i ].detail$ = ""
            endif
            thisString$ = right( thisString$ , thisLen - thisComma )
            thisValue = val( thisString$ )
            MainObject[ i ].icon = abs( thisValue )
            MainObject[ i ].isKnown = 0
            if thisValue < 0
               MainObject[ i ].isGroup = 1
            else
               MainObject[ i ].isGroup = 0
            endif
         endif
      next i
      // Recipes Go Here
      for i=topObject() + 1 to thisArraySize

      next i
      // Clear Temp Array
      dim tempArray[ 0 ]
      // Group Memberships
      for i=1 to topObject()
         if ObjectIsGroup( i ) > 0 and ObjectDetail( i ) <> ""
            thisString$ = ObjectDetail( i )
            thisLen = len( thisString$ )
            thisStart = 1
            thisCoded$ = ""
            while thisStart < thisLen
               thisComma = FindSubString( thisString$ , "," , thisStart )
               if thisComma = 0 then thisComma = thisLen + 1
               thisObject$ = mid( thisString$ , thisStart , thisComma - thisStart )
               // convert to base96
               thisObject = FindObjectByName( thisObject$ )
               if thisObject > 0 then thisCoded$ = thisCoded$ + Base96Encode( thisObject )
               thisStart = thisComma + 1
            endwhile
            MainObject[ i ].detail$ = Base96Sort( thisCoded$ )
         endif
      next i
   endif
endfunction thisArraySize

function FindImageFile( thisName$ )
   thisString$ = ""
   if getFileExists( thisName$ + ".png" )
      thisString$ = thisName$ + ".png"
   elseif getFileExists( thisName$ + ".jpg" )
      thisString$ = thisName$ + ".jpg"
   elseif getFileExists( thisName$ + ".bmp" )
      thisString$ = thisName$ + ".bmp"
   endif
endfunction thisString$

// String Functions

function FindSubString( thisString$ , thisSearch$ , thisStart )
   thisLen = len( thisSearch$ )
   thisSearch$ = upper( thisSearch$ )
   thisString$ = upper( thisString$ )
   thisEnd = len( thisString$ ) - thisLen + 1
   for thisPos = thisStart to thisEnd
      if mid( thisString$ , thisPos , thisLen ) = thisSearch$ then exit
   next i
   if thisPos > thisEnd then thisPos = 0
endfunction thisPos


// Initialisation Functions

function Initialise()
   // Prepare Globals
   global game as gameType
      game.level = 0
      game.state = STATE_SETUP
      game.topObject = 0

   global touch as touchType
      touch.pointDX# = 0.0
      touch.pointDY# = 0.0
      touch.pointWX# = 0.0
      touch.pointWY# = 0.0
      touch.spritePicked = 0
      touch.objectPicked = 0
      touch.menuPicked = 0
      touch.pickOffsetX# = 0.0
      touch.pickOffsetY# = 0.0

   global display as displayType
      display.physWidth# = getDeviceWidth()
      display.physHeight# = getDeviceHeight()
      display.virtWidth# = PhysWidth()
      display.virtHeight# = PhysHeight()
      display.iconSize# = PhysWidth() / PANEL_COLS
      display.textHeight# = PhysHeight() / 20.0
      display.highSprite = 0
      display.iconImage = SafeloadImage( "objects.png" )
      display.transType = TRANS_NONE
      display.transCount# = 0.0
      display.transStep# = 0.0

   global panel as panelType
      panel.iconMax = PANEL_ROWS * PANEL_COLS
      panel.height# = IconSize() * PANEL_ROWS
      panel.speed# = 0.0
      panel.isOpen = 0
      panel.Image = SafeloadImage( "panel.jpg" )
      panel.sprite = createSprite( PanelImage() )
      panel.text = createText( "Objects" )
      panel.sound = SafeLoadSound("panel.wav")

   setImageWrapU( PanelImage() , 1 )
   setImageWrapV( PanelImage() , 1 )

   uScale# = getImageWidth( PanelImage() ) / PhysWidth()
   vScale# = getImageHeight( PanelImage() ) / PanelHeight()
   setSpriteUVScale( PanelSprite() , uScale# , vScale# )
   setSpriteSize( PanelSprite() , PhysWidth() , PanelHeight() )
   setSpritePosition( PanelSprite() , 0 , PhysHeight() )
   setSpriteDepth( PanelSprite() , DEPTH_PANEL)

   setTextSize( panelText() , textHeight() )
   setTextAlignMent( panelText() , 1)
   setTextPosition( panelText() , PhysWidth() / 2.0 , PhysHeight() - TextHeight() )
   setTextDepth( panelText() , DEPTH_PANEL - 1 )

   // Prepare Arrays

   dim panelIconSprite[ panelIconMax() ]
      for icon = 1 to panelIconMax()
         panelIconSprite[ icon ] = createSprite( 0 )
         setSpriteSize( panelIconSprite[ icon ] , IconSize() - 4, IconSize() - 4)
         setSpriteColor( panelIconSprite[ icon ] , 255 , 255 , 255 , 127 )
      next icon

   dim workObject[ MAX_WORKOBJECTS ] as WorkObjectType
      for thisObject = 1 to MAX_WORKOBJECTS
         workObject[ thisObject ].isFree = 1
         workObject[ thisObject ].objectID = 0
         workObject[ thisObject ].sprite = 0
      next thisObject
   setVirtualResolution( VirtWidth(), VirtHeight() )
   PositionPanelIcons()

   dim menuString[ 5 ] as string = [ "" , "Start Game" , "Exit", "Option 4" , "Option 5" , "Option 6" ]
   dim menuText[ MENU_ITEMS ]
      for i=1 to MENU_ITEMS
         menuText[ i ] = createText( menuString[i] )
         setTextVisible( menuText[ i ] , 0 )
      next i

   dim MainObject[0] as MainObjectType

endfunction

// Return Functions - Game

function GameLevel()
endfunction game.level
function GameState()
endfunction game.state
function TopObject()
endfunction game.topObject

// Return Functions - Display

function PhysWidth()
endfunction display.physWidth#
function PhysHeight()
endfunction display.physHeight#
function VirtWidth()
endfunction display.virtWidth#
function VirtHeight()
endfunction display.virtHeight#
function IconSize()
endfunction display.iconSize#
function TextHeight()
endfunction display.textHeight#
function LastFPS()
endfunction display.lastFPS#
function IconImage()
endfunction display.iconImage
function HighSprite()
endfunction display.highSprite
function Transition()
endfunction display.transType
function TransitionCount()
endfunction display.transCount#
function TransitionStep()
endfunction display.transStep#

// Return Functions - Touch

function PointDX()
endfunction touch.pointDX#
function PointDY()
endfunction touch.pointDY#
function PointWX()
endfunction touch.pointWX#
function PointWY()
endfunction touch.pointWY#
function SpritePicked()
endfunction touch.spritePicked
function ObjectPicked()
endfunction touch.objectPicked
function MenuPicked()
endfunction touch.menuPicked
function PickOffsetX()
endfunction touch.pickOffsetX#
function PickOffsetY()
endfunction touch.pickOffsetY#

// Return Functions - Panel

function PanelHeight()
endfunction panel.height#
function PanelSpeed()
endfunction panel.speed#
function PanelIsOpen()
endfunction panel.isOpen
function PanelImage()
endfunction panel.image
function PanelSprite()
endfunction panel.sprite
function PanelText()
endfunction panel.text
function PanelSound()
endfunction panel.sound
function PanelIconMax()
endfunction panel.iconMax

// Return Functions - WorkObject Array

function WorkObjectIsFree( thisObject )
   if WorkObjectValid( thisObject )
      thisIsFree = workObject[ thisObject ].isFree
   else
      thisIsFree = -1
   endif
endfunction thisIsFree

function WorkObjectID( thisObject )
   if WorkObjectValid( thisObject )
      thisObjectID = workObject[ thisObject ].objectID
   else
      thisObjectID = -1
   endif
endfunction thisObjectID

function WorkObjectSprite( thisObject )
   if WorkObjectValid( thisObject )
      thisSprite = workObject[ thisObject ].sprite
   else
      thisSprite = -1
   endif
endfunction thisSprite

// Return Functions - Main Object

function ObjectName( thisObject )
   if ObjectValid( thisObject )
      thisString$ = MainObject [ thisObject ].name$
   else
      thisString$ = ""
   endif
endfunction thisString$

function ObjectDetail( thisObject )
   if ObjectValid( thisObject )
      thisString$ = MainObject [ thisObject ].detail$
   else
      thisString$ = ""
   endif
endfunction thisString$


function ObjectIcon( thisObject )
   if ObjectValid( thisObject )
      thisIcon = MainObject [ thisObject ].icon
   else
      thisIcon = -1
   endif
endfunction thisIcon

function ObjectIsKnown( thisObject )
   if ObjectValid( thisObject )
      thisBool = MainObject [ thisObject ].isKnown
   else
      thisBool = -1
   endif
endfunction thisBool

function ObjectIsGroup( thisObject )
   if ObjectValid( thisObject )
      thisBool = MainObject [ thisObject ].isGroup
   else
      thisBool = -1
   endif
endfunction thisBool
//

No comments:

Post a Comment