Array - Image Mapping

BlitzPlus Forums/BlitzPlus Beginners Area/Array - Image Mapping

Jono(Posted 2005) [#1]
AppTitle "Zelda"
Graphics 224,176,32

SetBuffer BackBuffer()

Dim TileSet(1)
TileSet(0) = LoadImage("Floor.bmp")
TileSet(1) = LoadImage("Tree Stump.bmp")

Dim Apple_Tree_Inn(2,2)
Apple_Tree_Inn(0,0) = 0 : Apple_Tree_Inn(0,1) = 0 : Apple_Tree_Inn(0,2) = 0
Apple_Tree_Inn(1,0) = 0 : Apple_Tree_Inn(1,1) = 1 : Apple_Tree_Inn(1,2) = 0
Apple_Tree_Inn(2,0) = 0 : Apple_Tree_Inn(2,1) = 0 : Apple_Tree_Inn(2,2) = 0

While Not KeyHit(1)

Cls

For Y = 0 To 2
For X = 0 To 2
If Apple_Tree_Inn(Y,X) = 0 Then DrawImage TileSet(0),X*ImageWidth(TileSet(0)),Y*ImageHeight(TileSet(0))
If Apple_Tree_Inn(Y,X) = 1 Then DrawImage TileSet(1),X*ImageWidth(TileSet(1)),Y*ImageHeight(TileSet(1))
Next
Next

Flip

Wend

Ok, I've just written this and it works. But I was wondering if you guys knew of a better way, or a more simplistic way of writing this source code. Seems a bit long winded and maybe could be cut down. The tiles are 16x16 and Apple_Tree_Inn is the name of the area.

Looking forward to hearing from ya! ^.^


CS_TBL(Posted 2005) [#2]
http://www.blitzbasic.co.nz/Community/posts.php?topic=51100


Jono(Posted 2005) [#3]
;# Array #
0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,3

0,0 = 0
0,1 = 1
0,2 = 0
1,0 = 0
1,1 = 1
1,2 = 0
2,0 = 0
2,1 = 1
2,2 = 0

;# Source #

For Y = 0 To 2
For X = 0 To 2

Next
Next

;# Processer #
Y = 0, X = 0
Y = 0, X = 1
Y = 0, X = 2
Y = 1, X = 0
Y = 1, X = 1
Y = 1, X = 2
Y = 2, X = 0
Y = 2, X = 1
Y = 2, X = 2

Is this how it works during the program execution, I can't seem to step through the source code like I can in Visual Basic.


CS_TBL(Posted 2005) [#4]
obviously that's how it works... why? What's your *real* question?


Jono(Posted 2005) [#5]
Nothing to do with a question, you're assuming instead of reading. I'm talking about high optimization, not debugging.

"Optimization - The procedure or procedures used to make a system or design as effective or functional as possible, especially the mathematical techniques involved."


WolRon(Posted 2005) [#6]
AppTitle "Zelda"
Graphics 224,176,32

SetBuffer BackBuffer()

Dim TileSet(1, 2)
TileSet(0, 0) = LoadImage("Floor.bmp")
TileSet(1, 0) = LoadImage("Tree Stump.bmp")
For tile = 0 to 1
  TileSet(tile, 1) = ImageWidth(TileSet(tile, 0))
  TileSet(tile, 2) = ImageHeight(TileSet(tile, 0))
Next

Dim Apple_Tree_Inn(2,2)
Apple_Tree_Inn(0,0) = 0 : Apple_Tree_Inn(0,1) = 0 : Apple_Tree_Inn(0,2) = 0
Apple_Tree_Inn(1,0) = 0 : Apple_Tree_Inn(1,1) = 1 : Apple_Tree_Inn(1,2) = 0
Apple_Tree_Inn(2,0) = 0 : Apple_Tree_Inn(2,1) = 0 : Apple_Tree_Inn(2,2) = 0

While Not KeyHit(1)

Cls

For Y = 0 To 2
  For X = 0 To 2
    tile = Apple_Tree_Inn(X,Y)
    DrawImage TileSet(tile,0), X*TileSet(tile,1), Y*TileSet(tile,2)
  Next
Next

Flip

Wend

I can't seem to step through the source code like I can in Visual Basic.
Why not? Aren't you using the debugging tools?
Set a "Stop" in the beginning of your program (or whereever it is that you want to start debugging) and then press any of the line-by-line debugging buttons in the debbugger window to step, skip, stop, run, whatever.
If you mean that you can't see the values of array indices, then you are correct. But for debugging purposes, you can cheat by setting a temp value to equal each one in order to view them, something like this:
For Y = 0 to 2:For X = 0 to 2
  temp = Apple_Tree_Inn(X, Y)
Next:Next