Qbasicnews.com

Full Version: read/data statements
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
i'm trying to make a sprite, and a sprite mask. i made the sprite in PP256 and saved it as the first set of data statements below. then i copied those, and made a mask with the second set of data statements. i am trying to read them into an array, but i get the error "out of data" immediately when i run the program below.. what's wrong with it? thanks.



Code:
CLS

DIM octo(31, 19)
DIM octom(31, 19)

FOR y = 1 TO 19
FOR x = 1 TO 31
  READ octo(x, y)
NEXT
NEXT

x = 0
y = 0

FOR y = 1 TO 19
FOR x = 1 TO 31
  READ octom(x, y)
NEXT
NEXT


'the octopus



DATA 297
DATA 248,19,0,0,0,0,0,0,-15678,-15678,-15678,-15678,0,0,0,0,0,0,0,0
DATA 0,0,-15678,-15678,-15678,-15678,-15678,-15678,-15678,0,0,0,0,0,0,0,0,-15678,-15678,-15678
DATA -15678,-15678,-15678,-15678,-15678,0,0,0,0,0,0,0,-15678,-15678,10178,-15833,-15678,10178,-15833,-15678
DATA -15678,0,0,0,0,0,0,-15678,-15678,-15678,39,-15833,10178,9984,-15678,-15678,-15678,0,0,0
DATA 0,0,-15872,-15678,-15678,-15678,10023,-15678,10023,-15678,-15678,-15678,194,0,0,0,0,0,-15678,-15678
DATA -15678,-15678,-15678,-15678,-15678,-15678,-15678,-15678,0,0,0,0,0,-15872,-15678,-15678,-15678,-15678,-15678,-15678
DATA -15678,-15678,-15678,194,0,0,0,0,0,-15872,-15678,-15678,-15837,-15678,-15678,9154,-15678,-15678,194,0
DATA 0,0,0,0,0,-15872,-15678,-15678,8995,8995,8995,-15678,-15678,194,0,0,0,0,0,0
DATA 0,-15872,-15678,-15678,-15678,-15678,-15678,-15678,194,0,0,0,0,0,0,0,0,-15678,-15872,-15678
DATA -15678,-15678,194,-15872,0,0,0,0,0,0,0,0,-15678,0,-15872,194,0,194,0,-15678
DATA 0,0,0,0,0,0,0,-15872,0,-15872,194,0,-15872,0,0,194,0,0,0,0
DATA 0,0,0,-15678,0,194,0,0,194,0,-15872,0,0,0,0,0,0,0,0,-15678
DATA -15872,194,0,-15678,0,0,194,0,0,0,0,0,0,0,0,194,0,194,-15872,0
DATA -15872,-15678,0,0,0,0,0,0,0,0,-15872,0,-15872,194,-15678,194,194,0,0,0
DATA 0,0,0,0,0,-15872,194,0,194,0,-15872,-15872,0,0,0,0,0

'the mask for the octopus
DATA 297
DATA 248,19,255,255,255,255,255,255,15678,15678,15678,15678,255,255,255,255,255,255,255,255
DATA 255,255,15678,15678,-15678,-15678,-15678,-15678,-15678,255,255,255,255,255,255,255,255,15678,15678,15678
DATA 15678,-15678,-15678,-15678,-15678,255,255,255,255,255,255,255,-15678,-15678,10178,-15833,15678,10178,15833,15678
DATA -15678,255,255,255,255,255,255,-15678,-15678,-15678,39,-15833,10178,9984,-15678,-15678,-15678,255,255,255
DATA 255,255,-15872,-15678,-15678,-15678,10023,-15678,10023,-15678,-15678,-15678,194,255,255,255,255,255,15678,15678
DATA -15678,-15678,-15678,-15678,-15678,-15678,-15678,-15678,255,255,255,255,255,-15872,-15678,-15678,-15678,-15678,-15678,
DATA 15678
DATA -15678,-15678,-15678,194,255,255,255,255,255,-15872,-15678,-15678,-15837,-15678,-15678,9154,-15678,-15678,194,255
DATA 255,255,255,255,255,-15872,-15678,-15678,8995,8995,8995,-15678,-15678,194,255,255,255,255,255,255
DATA 255,-15872,-15678,-15678,-15678,-15678,-15678,-15678,194,255,255,255,255,255,255,255,255,-15678,-15872,-15678
DATA -15678,-15678,194,-15872,255,255,255,255,255,255,255,255,-15678,255,-15872,194,255,194,255,-15678
DATA 255,255,255,255,255,255,255,-15872,255,-15872,194,255,-15872,255,255,194,255,255,255,255
DATA 255,255,255,-15678,255,194,255,255,194,255,-15872,255,255,255,255,255,255,255,255,-15678
DATA -15872,194,255,-15678,255,255,194,255,255,255,255,255,255,255,255,194,255,194,-15872,255
DATA -15872,-15678,255,255,255,255,255,255,255,255,-15872,255,-15872,194,-15678,194,194,255,255,255
DATA 255,255,255,255,255,-15872,194,255,194,255,-15872,-15872,255,255,255,255,255
Well, the simple problem is that you are READing too many times for the amount of data you have...I don't have too much have expirience with it, but I can give you a quick hint:
Rather than saving your pictures as Data, save them plainly "as". Then you can load em' like this:
Code:
DIM yourpic(width*height)
DEF SEG=VARSEG(yourpic(0))
BLOAD "yourpic.pic",VARPTR(yourpic(0))
Where width and height are, obviously the width and height of your picture, in pixels, and yourpic.pic is the filename.
yeah zack, i was doing that originally, but the problem was, when i was loading the .put files and putting them on the screen, it was putting the black part of the picture on the screen too- i was trying to make the black part 'see-through' so you only saw the colored part of the sprite, in front of the background

thanks for the help, though.
In SCREEN 13, what I said about SCREEN 7 applies, but the colours change:

* Transparent pixels: 255 in the mask, 0 in the sprite.
* Solid pixels: 0 in the mask, any colour (including 0) in the sprite.

Being transparent or not does not depend on how you are loading your sprites.

Remember the pair:

Code:
PUT (x%, y%), mask%(0), AND
PUT (x%, y%), sprite%(0), XOR
oh. that would explain some stuff. thanks again nathan.

now i just need to figure out why my read/data stuff won't work...
weird..

maybe i should just make my sprites in mspaint and just write out data based on that.

what do you use to make sprites, na_th_an?
I use the same thing for all my pixel art: Deluxe Paint IIe v.3 ( http://usuarios.lycos.es/qbsux/utils.html )

[Image: shoop.gif]

DPIIe3 is great Smile
you made that graphic in that image editor? WOW.

i thought of something else. in the data statements from my first post, there are numbers like -15678 - i thought colors were all positive numbers... in that case, the 'save as data' thing under export is flawed.
That number is two pixels combined. A pixel takes 1 byte in mode 13h. QB does not have a byte data type, the smallest is the INTEGER data type that takes 2 bytes. INTEGERs rank from -32768 to 32767, the binary representation is out of scope here Tongue
oh, okay. thanks, yet again, na_th_an. i think in a half an hour or so i might have this movement system worked out.

the read and data statements should work even with the negative numbers, right?
THe problem is with your array definition and with your loops. Sprite arrays must be 1D. The way to calculate the correct size is found in the QB help. Anyhow, PP256 calculates it for you: it is the number in the first data (the one which is left alone).

Code:
READ dimmension%
DIM sprite%(dimmension%)
FOR i%=0 TO dimmension%
   READ sprite%(i%)
NEXT i%

PUT (160,100), Sprite%(0), PSET
Pages: 1 2