Qbasicnews.com
May 26, 2020, 06:04:16 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Arrays of sprites and pp256  (Read 2259 times)
annunaki10
New Member

Posts: 23



« on: June 17, 2004, 11:45:40 AM »

i've asked about this before but was told it's not possible. However, i was looking over some code, relsoft's scroll.bas and noticed that it does use this concept. Looking more into it, it's from pp256. i don't really want to use that for several reasons but also i'd prefer to use as little of other people's code as possible.

i can see that 'InitImageData' loads the data that pp256 creates (which on a side note, i don't understand those numbers at all  :-? ) and it looks like 'MakeImageIndex' basically creates the array. If i'm wrong on anything, please correct me.

So would it be possible to use this method of the arrays with an index but to GET images off the screen?
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #1 on: June 17, 2004, 12:14:03 PM »

I don't really understand your question.
If what  you want to do is load a multi-frame image file made with PP256, then just do this:
Code:
DIM ImageArray(WidthOfImages * HeightOfImages * NumImages) AS INTEGER
DEF SEG=VARSEG(ImageArray(0))
BLOAD "Imagefilename",VARSEG(ImageArray(0))
DEF SEG
Offset=WidthOfImages * HeightOfImages / 2 + 2

Then to access the first image, you do this:
Code:
PUT (X,Y),ImageArray(Offset * 0)

And the next:
Code:
PUT (X,Y),ImageArray(Offset * 1)

And the next:
Code:
PUT (X,Y),ImageArray(Offset * 2)

And so on. This is cool because if you have an animation, you can display all the frames in quick succession just by multiplying the Offset variable by an incremental variable.

Adosorken taught me this method.  Smiley
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
annunaki10
New Member

Posts: 23



« Reply #2 on: June 17, 2004, 12:32:07 PM »

Ok what you described is exactly what i want. Each direction has 2 frames for animation. So the character has 8 possible frames, 8 arrays, pain in the ass.

i don't want to load a file made with pp256 because i'd like to stay away from it.

What i'm doing is taking a sprite sheet and placing it on the screen and then looping through and GETting each image.

Is it possible to create this ImageArray using my method or no?

On a side note, i see this used a lot.
Code:
DEF SEG=VARSEG(ImageArray(0))


i more or less understand what's happening when DEF SEG is being called but i wouldn't know how to use it on my own or really know exactly what it does. Are there any tutorials or something that can explain it more thoroughly so i can fully understand it.
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #3 on: June 17, 2004, 12:59:18 PM »

I believe so. Just replace that PUT I gave you with:
Code:
GET (spritex1,spritey1)-(spritex2,spritey2),ImageArray(Offset * ImageNum

Get it?

About that DEF SEG question. It just sets the default segment that QB loads into, so your sprite gets loaded from the file into the proper segment of your ImageArray, see? And a plain "DEF SEG" just resets the segment to whatever QB prefers as a default.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
barok
Na_th_an
*****
Posts: 1727


How about a tasty lead sandwich?


« Reply #4 on: June 17, 2004, 01:07:19 PM »

to put it bluntly, yes.  however, it takes some work.  


1.  get the size of the sprites

are they 20x20? 16x16?

2. how many sprites?  howmany sprites are you using?  

3. dimension your array

take your sprites array and times it by the sprite width by sprite height.

dim shared sprites(wid * height) as integer

next, divide it in half.

dim shared sprites((wid * height) \ 2) as integer

add one to the result

dim shared sprites((wid * height) \ 2 + 1) as integer

finally times the result by the number of sprites.

dim shared sprites(((wid * height) \ 2 + 1) * numsprites) as integer

next, create your index.  the index should be dimmed the number of sprites.  

dim shared spritearray(numsprites) as integer

start a for...next loop from 0 to the number of sprites.

for i = 0 to numsprites

next

in the code have this.

spritearray(i) = (((wid * height) \ 2 + 1) * i)

now start another for..next loop.


for i = 0 to numsprites

next

now we put some math in the loop so we can get the sprites properly..

for i = 0 to numsprites
x = x + wid
if x > 319 then
x = 0
y = y + height
endif


next


then we get the sprites.

get (x,y)-(x + wid,y + height),sprite(wid *height)\2 + 1)  numsprites)

all together it should look something like this....
Code:

dim shared sprites(((wid * height) \ 2 + 1) * numsprites) as integer
dim shared spritearray(numsprites) as integer

for i = 0 to numsprites
spritearray(i) = (((wid * height) \ 2 + 1) * i)
next

for i = 0 to numsprites
x = x + wid
if x > 319 then
x = 0
y = y + height
endif
get (x,y)-(x + wid,y + height),sprite(wid *height)\2 + 1) * numsprites)
next


i think it should go something like this.  it may work and it may not... i made this off the top of my head.
Logged

Jumping Jahoolipers!
annunaki10
New Member

Posts: 23



« Reply #5 on: June 17, 2004, 01:07:39 PM »

Ok i hope that works cause that'll definitely make life easier. i'm going to try that GET statement tonight. Damn work really gets in the way of recreation. :wink:
Logged
annunaki10
New Member

Posts: 23



« Reply #6 on: June 18, 2004, 10:43:23 AM »

Ok i tried it out and it works perfectly as i wanted. Thanks a lot. :bounce:  :bounce:

Althought for whatever reason the offset had to be width * height / 2 + 2 instead of width * height / 2 + 1. Oh well
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #7 on: June 18, 2004, 11:55:05 AM »

"+ 2"...just like I said... :roll:
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
annunaki10
New Member

Posts: 23



« Reply #8 on: June 18, 2004, 12:12:22 PM »

True true. i actually tried both 1 and 2 because i read on previous posts that it only needs to be 1 when the height * width / 2 is an even number. Mine is 16*16=256/2 = 128. Anyway, it works like i wanted. Thanks Zack. Tongue
Logged
barok
Na_th_an
*****
Posts: 1727


How about a tasty lead sandwich?


« Reply #9 on: June 18, 2004, 09:35:10 PM »

when your dimming a put array +1 should work.  why?  because qbasic starts counting at 0, not 1.  however, when your getting the offset you need +2.
Logged

Jumping Jahoolipers!
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #10 on: June 19, 2004, 10:10:33 AM »

As I wrote recently, that depends on whether the resulting number of multiplying width by height is odd or even.

If it is odd, say for example "7", you have 7\2 = 3, but with 3 integers you can only store 6 bytes. You need an extra integer.

The correct expression would be:

Code:
Dimmension% = CEIL(( Width% * Height%) / 2) + 1


But the CEIL (round up) command doesn't exist in QB, so the golden rule is add 1 if w*h is even or 2 if w*h is odd.

Anyhow, if you use sprites with sizes that are powers of two, the result is always even.

I've said this tons of times: use sizes that are powers of two: the calculations are faster.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!