Actually, you're not far off. Hand positioning is always a bad idea, as you'll hardcode in the values and if you ever make a change you have to recalculate everything (been there, done that, it was an absolute nightmare...)
Your current code is good, though, but I get the feeling it's not placing your grass images where you want them? I'll try and explain how 2D positioning works.
Say your program runs in a 1024x768 window - that means you have a bitmap of 1024xx768 pixels to draw on. (0,0) is in the top left, (1024,768) is in the bottom right. Now suppose your grass.png texture is a 256x256 pixel image. If you call
Sprite SpriteID, 0, 0, ImageID
then you'll paste the grass image in the top left corner (g = grass in the diagram below):
__ __
|g_|__|
|__|__|
Now, say we want another grass image to make a pathway, well, just paste it at (256, 0) for this:
__ __
|g_|g_|
|__|__|
And finally (256,256) for this:
__ __
|g_|g_|
|__|g_|
So, your for-loop currently puts a horizontal strip of grass across the screen. All you need to do is modify it slightly to adjust for the width/height of the original image. You can either write:
for x = 0 to 9
sprite terrain(x).id, x+256, 450, terrain(x).id
next x
where I've used 256 as the pixel width of the grass image
or
for x = 0 to 9
sprite terrain(x).id, x+Image Width(terrain(x).id), 450, terrain(x).id
next x
which is more general and won't break if you move to a different size of image.
A few things to note, though - even though you're creating a 2D backdrop to represent the "landscape" your player moves through, don't call it a terrain. A terrain in DBPro is a 3D landscape and obeys a whole different set of rules. Also, don't call your player an "object" - object implies 3D as well!
You might be better off trying a few different data types in your code. Maybe use "entity" for your player, and landscape for what you currently call "terrain":
type entity
x as integer
y as integer
id as integer
r as integer `For rotation later in the game. To allow you to shoot arrows anywhere.
h as integer `Sprite Height. For offseting.
w as integer `Sprite wdith. For offseting.
endtype
// Note - a landscape should not rotate in a 2D game
//(if it does, you need 3D!)
type landscape
x as integer
y as integer
id as integer
endtype
global player as entity
//global background as object
global dim terrain(10) as landscape `I really don't know what else to do with this lol.
load image "Media\GUI\BG.png", background.id
load image "Media\Mobs\HunterStatic.png", player.id `I might make a Load_Images() function later. But for now its like this.
// I've cclosed off this for-loop with "next x"
// always, always close your loops properly!
for x = 0 to 9
load image "Media\Terrain\Grass.png", terrain(x).id
next x
remstart
// You could also get away with just loading one image
// and use multiple sprites to reference it!
load image "Media\Terrain\Grass.png", terrainImageNumber
// then below (in Place_Objects), use
sprite terrain(x).id, x+2, 450, terrainImageNumber
remend
function Place_Objects()
sprite background.id, 0, 0, player.id
sprite player.id, 0, 0, player.id
for x = 0 to 9
sprite terrain(x).id, x+2, 450, terrain(x).id
next x
endfunction Place_Objects()
Lastly, your background appears to be a single image that's always there - there's no need to log all the other items in your data type with it, just give it an image number and let it go at that. The whole point of types is that it links together relevant variables - logging the rotation of your backdrop is a waste of memory, because it will never rotate.
Hope this helps!
We spend our lives chasing dreams. Dark Basic lets us catch some of them.