As always unformatted for copy / paste
// April 9 2012 - Tabs converted to 3 spaces
#constant PANEL_ROWS 3
#constant PANEL_COLS 4
#constant DEPTH_SCORE 20
#constant DEPTH_PANEL 30
#constant DEPTH_WORK 40
#constant MAX_WORKOBJECTS 100
type displayType
physWidth#
physHeight#
virtWidth#
virtHeight#
iconSize#
textHeight#
lastFPS#
iconImage
endtype
global display as displayType
display.physWidth# = getDeviceWidth()
display.physHeight# = getDeviceHeight()
display.iconSize# = PhysWidth() / PANEL_COLS
display.textHeight# = PhysHeight() / 20.0
setVirtualResolution( PhysWidth() , PhysHeight() )
display.virtWidth# = getVirtualWidth()
display.virtHeight# = getVirtualHeight()
display.iconImage = SafeloadImage( "objects.png" )
type panelType
height#
speed#
isOpen
image
sprite
text
sound
iconMax
endtype
global panel as panelType
panel.height# = IconSize() * PANEL_ROWS
panel.speed# = 0.0
panel.isOpen = 0
panel.iconMax = PANEL_ROWS * PANEL_COLS
panel.Image = SafeloadImage( "panel.jpg" )
setImageWrapU( PanelImage() , 1 )
setImageWrapV( PanelImage() , 1 )
panel.sprite = createSprite( PanelImage() )
uScale# = getImageWidth( PanelImage() ) / PhysWidth()
vScale# = getImageHeight( PanelImage() ) / PanelHeight()
setSpriteUVScale( PanelSprite() , uScale# , vScale# )
setSpriteSize( PanelSprite() , PhysWidth() , PanelHeight() )
setSpritePosition( PanelSprite() , 0 , PhysHeight() )
setSpriteDepth( PanelSprite() , DEPTH_PANEL)
panel.text = createText( "Objects" )
setTextSize( panelText() , textHeight() )
setTextAlignMent( panelText() , 1)
setTextPosition( panelText() , PhysWidth() / 2.0 , PhysHeight() - TextHeight() )
setTextDepth( panelText() , DEPTH_PANEL - 1 )
panel.sound = SafeLoadSound("panel.wav")
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
type WorkObjectType
isFree
objectID
sprite
endtype
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
global numWorkObjects = 0
imageRef = SafeloadImage( "finger.png" )
spriteRef = createSprite( imageRef )
PositionPanelIcons()
testSprite = createSprite( IconImage() )
setSpriteSize( testSprite , IconSize() , - 1)
setSpritePosition( testSprite , 100 , 100 )
setSpriteDepth( testSprite , DEPTH_WORK )
setSpriteAnimation( testSprite , 64 , 64 , 252 )
do
testFrame = testFrame + 1
if testFrame = 253 then testFrame = 1
setSpriteFrame( testSprite , testFrame )
LoopStart()
print( "FPS: " + str ( lastFPS() ) )
if getPointerPressed() > 0
if getPointerY() >= getTextY( panelText() ) and getPointerY() < getSpriteY( panelSprite() )
ToggleTrayOpen()
endif
endif
if panelIsOpen() = 1
if getSpriteY( panelSprite() ) > ( PhysHeight() - panelHeight() )
MovePanel( -panelSpeed() )
endif
else
if getSpriteY( panelSprite() ) < PhysHeight()
MovePanel( panelSpeed() )
endif
endif
setSpritePosition( spriteRef , getPointerX() , getPointerY() )
printc( "Physical: " )
print( str( PhysWidth() ) + " x " + str( PhysHeight() ) )
printc( "Pointer: " )
print( str( getPointerX() ) + " x " + str( getPointerY() ) )
sync()
loop
function LoopStart()
display.lastFPS# = screenFPS()
panel.speed# = panelHeight() / (lastFPS() * 1.25)
endfunction
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
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
// 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
// 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 - 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
// 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
//
No comments:
Post a Comment