Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Starting a fighting game
#21
The structure of Pascal is that code blocks are enclosed in Begin...End. So the outermost Begin...End contain the entire procedure... same with the one after the while statement... that's the code inside the loop.

Sorry, I'm using untyped pointers to store the sprites. That way I can accomidate different sizes. Ignore that getmem statement. You just want to have a huge array, something like:

DIM mysprites(255, 16, 16);

That's the maximum size for a segment... but use the array with GET # statements and manually load in the individual bytes.

One other thing to consider: My sprite format is slightly different from QBs. In QB the header is three bytes... two for the width, one for the height. Mine is just two bytes. So you'll have to twiddle that a little.


Biggest problem you face is that QB doesn't have a data type for a single byte... So you have to load the bytes in pairs and then do an AND 255 to chop them down to the single byte. Example:

Code:
'Loads single bytes out of a file
OPEN "myfile.txt" FOR BINARY AS #1
temp% = 0
ctr% = 1
WHILE NOT EOF(1)
  GET #1, ctr%, temp%
  temp% = temp% AND 255
  PRINT temp% + "  ";
  ctr% = ctr% + 1
WEND
PRINT "Total bytes: " + ctr%
'untested
Reply
#22
I think I know how to cut up the tiles and store them in. How do you display the .til onto the screen to use the GET or would what you have work?
·····································LINEAR INC·····································
Ø-----------------------------------------------------------------------O
From Problem to Solution - We take the shortest distance
Reply
#23
Quote:I think I know how to cut up the tiles and store them in. How do you display the .til onto the screen to use the GET or would what you have work?

All that code shows you how to do is load individual bytes. You need to take those bytes and put them in them in an array, that then qb's PUT command can stick on the screen for you.
Reply
#24
I'll try to write you a code example that loads a few images and puts them on the screen.
Reply
#25
you'll do that for me. I love you :lol:
·····································LINEAR INC·····································
Ø-----------------------------------------------------------------------O
From Problem to Solution - We take the shortest distance
Reply
#26
Quote:you'll do that for me. I love you :lol:

I'm such a sucker. [Image: wtf.gif]

Run this in the same directory as the Water.TIL file I included with the Spriter program:
Code:
SCREEN 13
CLS

DIM sprite(129, 251) AS INTEGER 'load up to 252 sprites here


OPEN "water.til" FOR BINARY AS #1

'LOAD THE IMAGE DATA

length = LOF(1) - 768

FOR ctr = 0 TO length / 258 - 1
  
   'hardcoding the height and width of the sprites to be 16x16
   sprite%(0, ctr) = 128  '16*8 (for whatever reason)
   sprite%(1, ctr) = 16

   'Input the 256 bytes of data in pairs, thus only 128 loops
   FOR word = 2 TO 129
      GET #1, (ctr * 258) + (word * 2), temp%
      sprite%(word, ctr) = temp%
   NEXT
  
   'PUT the sprite on the screen (obviously remove this eventually)
   PUT (ctr * 18 + 1, 150), sprite(0, ctr), PSET
NEXT

'Just so we can see the palette
FOR a = 0 TO 255
PSET (a, 0), a
NEXT


'LOAD IN THE PALETTE

length = length + 1
DIM colorval AS LONG

FOR col = 0 TO 255
   GET #1, length + (col * 3), R%
   GET #1, length + (col * 3) + 1, G%
   GET #1, length + (col * 3) + 2, B%

   R% = R% AND 63
   G% = G% AND 63
   B% = B% AND 63

   colorval& = R% + (G% * 256) + (B% * 65536)

   PALETTE col, colorval&
NEXT

Folks will be quick to show you the superior way to change the palette and whatever, but this works for now. I imagine since you'll end up using 8x8 tiles, you'll need to change a few values... but it's not that hard to figure out.
Reply
#27
Well, the only advice I can give you is, MAKE SURE YOU HAVE A GOOD KEYHANDLER IF YOU DON'T ALREADY HAVE ONE!!! You won't beleive how much I had to go through because of that, and it was hard to go through the whole code and modify everything to fit the keyhandler, so yeah, make sure you do that.

I am however, interested in seeing how your game will turn out... I wish I knew about this sprite tiling stuff... ¬_¬
Reply
#28
What's wrong with Milo Sedlacek's? That worked fine for me. Any time you need to do input or whatever, you just temporarily turn it off.
Reply
#29
Quote:
Code:
1. SCREEN 13
2. CLS
3.
4. DIM sprite(129, 251) AS INTEGER 'load up to 252 sprites here
5.
6.
7. OPEN "water.til" FOR BINARY AS #1
8.
9. 'LOAD THE IMAGE DATA
10.
11. length = LOF(1) - 768
12.
13. FOR ctr = 0 TO length / 258 - 1
14.  
15.   'hardcoding the height and width of the sprites to be 16x16
16.    sprite%(0, ctr) = 128  '16*8 (for whatever reason)
17.   sprite%(1, ctr) = 16
18.
19.    'Input the 256 bytes of data in pairs, thus only 128 loops
20.    FOR word = 2 TO 129
21.       GET #1, (ctr * 258) + (word * 2), temp%
22.       sprite%(word, ctr) = temp%
23.    NEXT
24.  
25.   'PUT the sprite on the screen (obviously remove this eventually)
26.    PUT (ctr * 18 + 1, 150), sprite(0, ctr), PSET
27. NEXT
28.
29. 'Just so we can see the palette
30. FOR a = 0 TO 255
32. PSET (a, 0), a
33. NEXT
34.
35.
36. 'LOAD IN THE PALETTE
37.
38. length = length + 1
39. DIM colorval AS LONG
40.
41. FOR col = 0 TO 255
44.    GET #1, length + (col * 3), R%
45.    GET #1, length + (col * 3) + 1, G%
46.    GET #1, length + (col * 3) + 2, B%
47.
48.    R% = R% AND 63
49.    G% = G% AND 63
50.    B% = B% AND 63
51.
52.    colorval& = R% + (G% * 256) + (B% * 65536)
53.
54.    PALETTE col, colorval&
55. NEXT

I'd like to say thank you before I begin with my post. Wiz, your the best. I mean I can't believe you actually sat down and wrote code for me. Second I'd like to apoligize for not replying right away. Don't take it as insult. It turned out I had quite a few tests, and project due today. I've been trying very hard to get back to qb but simply didn't manage. So thank you all for understanding and don't take think your posts went to waste for my long silence at the forums.

Now for my reply. I've ran the code and it's working perfectly. Theirs a palate that stretches across the top, and the images appear fine.

Sadly I didn't understand all of it. So I decided to number all the lines in your code wiz and try to ask very specific questions.


Line 3 - The Dim Statement

I know how the dim statement is used in arrays, and I thought before I had a general understanding of it. It has become aparent to me that I need further understanding in order to use properly all the time. The dim statement sets dimentions and in this case to (I assume) an array called sprite? What are the values for exactly, and how do they work?

I've created a maze program previously to this and it had a DIM sprite(1000) setting in it. I assumed it was the amount of pixels the sprite could be. The program would than take a shot of the sprite I drew using the LINE command, and store it into sprite. Is the logic here simular. Please clarify it for me.

Line 7 - The OPEN Command

In a previous program, I used the OPEN command in order to load a .txt file and save information onto it. The normal way of using it I suppose. In this case I see the WORD binary and it's used to load an image. I have a few questions here.

Can you use the OPEN command to load in any graphic or other file format? For example a gif, jpg, or an avi? If so how exactly do you display it? Perticularly an AVI (I've read it was possible). Not that this is my number one focus at the moment it would be something I'd like to learn more on.

Line 11 - I guess I'm just dumb

Well I'm sorry but I really don't understand this part. I know what LOF(1) is. Your taking the size of the image loaded and subtracting 768. I don't get it. Why do you subtract 768?

Line 13-17 - I don't understand the logic here

Next you've launched a for loop which I assume takes the sprites and loads them into the sprite array, am I right? Simple enough I understand the Get command, is used to store everything into that little array you dimentionalized earlier and Put of coarse displays the sprite saved in umm sprite(num1 ,num2 ). Once again what does the num1, and num2 stand for?

Next your setting, according to your comments, the width and height. I don't quite follow this logic here. If it should be 16x16. Then why would you set the first one to 128 (16*8). Now besides that point I don't quite understand this. Your setting all 0s to be the width, and all heights to be 1s. Obviously it works becuase the program ran perfectly and your a genious but I miss the logic here. So your setting things to certain numbers, and playing around with width and height in a way I really don't understand.


Line 20-24 - The important loop I assume

Before I go on, I didn't get the translation for your variables. What does ctr stand for and what does word stand for and imply.

Now umm I assume this loop does the importand work becuase it actually stores the sprites. I'll keep this short and simple, I don't understand the proccess.

I'm not going to ask the same question on the PUT command which is further down becuase it will probably be answered in part with the rest of them.

---------------------------------------------------

Now I've never played around with pallets before. Ever. I need someone to explain to me how the proccess works. What are palletes used for? How are they implented? And how the code in the end works?

---------------------------------------------------


I have to apolize for this extremly long post and my stupidity in the subject. I'm simply not aware and a little in experienced. I'm more than willing to learn. I want to learn. I need to learn. But someone please talk, for me to listen.

I love this community and when I one day move onto the next language I so wish this community follows.
·····································LINEAR INC·····································
Ø-----------------------------------------------------------------------O
From Problem to Solution - We take the shortest distance
Reply
#30
My next step is ofcoarse movement, so I'll first try to experiement with an idea I have before coming for help. I do need to know how to use the code first in order to begin on part 2.
·····································LINEAR INC·····································
Ø-----------------------------------------------------------------------O
From Problem to Solution - We take the shortest distance
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)