Here it is all fixed up with some extras.
Type MyItems
ItemID as integer
ItemName as string
ItemImage as integer
ItemValue as float
ItemDescription as String
`ItemOwned as Integer Not really necessary... IMHO
EndType
`*******************Main Source File*************************
global dim InventoryItems(0) as MyItems
global dim ShopItems(0) as MyItems
#constant IMG_CROWBAR 1
#constant IMG_BREAD 2
SetupProgram()
LoadMedia()
AddItemToShop( 1, "Crowbar", IMG_CROWBAR, 13.00, "Simple, yet effective" )
AddItemToShop( 2, "Bread", IMG_BREAD, 19.99, "Fills your stomach" )
do
cls
` Draw the Items at 32 pixels per picture. change it to the picture size of your items.
Item = ShowShopItems( 32 )
if Item <> -1
ink rgb(255,0,128), 0
text mousex()+16, mousey(), ShopItems(Item).ItemName + " Price: " + str$( ShopItems(Item).ItemValue )
endif
sync
loop
end
function SetupProgram()
sync on
sync rate 60
autocam off
set window on
set window size 800,600
set window title "Project Merchant Trader"
endfunction
function LoadMedia()
`set dir "Media"
if file exist("Media\Textures\crowbar.bmp") then load image "Media\Textures\crowbar.bmp", IMG_CROWBAR
if file exist("Media\Textures\bread.bmp") then load image "Media\Textures\bread.bmp", IMG_BREAD
endfunction
function PrintShopItems()
ink rgb(255,255,255), 0
for i = 0 to array count( ShopItems(0))
text 20, 20 + 15*i, ShopItems(i).ItemName
next i
endfunction
`This function will display all the items in the list and return the ItemID of the Item the mouse is over.
function ShowShopItems( TileSize as integer )
` Set the initial value for the return variable. -1 means nothing is selected.
ovr = -1
ac = array count( ShopItems(0) )
for im = 1 to ac
i = ShopItems(im).ItemImage
x = 100 + TileSize
y = 20 + (TileSize + 2) * im
` If the mouse is over this item
if mousex() > x and mousex() < x + TileSize and mousey() > y and mousey() < y + TileSize
ovr = ShopItems(im).ItemID
endif
` If the image is loaded, show it here, otherwise draw a white box.
if image exist(i)
paste image i, x, y, 1
else
ink rgb(255,255,255), 0
box x, y, x + TileSize, y + TileSize
endif
next im
endfunction ovr
function AddItemToShop( ItemID as integer, ItemName as string, ItemImage as integer, ItemValue as float, ItemDescription as string )
array insert at bottom ShopItems(0)
ac = array count( ShopItems(0) )
ShopItems(ac).ItemID = ItemID
ShopItems(ac).ItemName = ItemName
ShopItems(ac).ItemImage = ItemImage
ShopItems(ac).ItemValue = ItemValue
ShopItems(ac).ItemDescription = ItemDescription
endfunction
function AddItemToInventory( ItemID as integer, ItemName as string, ItemImage as integer, ItemValue as float, ItemDescription as string )
array insert at bottom InventoryItems(0)
ac = array count( InventoryItems(0) )
InventoryItems(ac).ItemID = ItemID
InventoryItems(ac).ItemName = ItemName
InventoryItems(ac).ItemImage = ItemImage
InventoryItems(ac).ItemValue = ItemValue
InventoryItems(ac).ItemDescription = ItemDescription
endfunction