Qbasicnews.com
Starting a fighting game - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Starting a fighting game (/thread-671.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16


Starting a fighting game - na_th_an - 05-19-2003

In fact, the problems you'll find trying to use pure QB in your project is that you'll only have space for 8 or 9 sprites that size in conventional memory.You need EMS or XMS, or your GFX data won't fin in memory.


Starting a fighting game - Kofman - 05-19-2003

Your saying I wont survive without libarie.

Alright I'll try again. If you can, please get the tutorial on masking. I'm going to see what I can do with libaries one more time. Your recomnding Direct QB I assume?

Wait a sec for Dircect QB I have to edit the CONFIG file. I'm not going to be able to do that at the school computers. !!

I'l try to stick with masking


Starting a fighting game - wizardlife - 05-20-2003

I go away on a canoe trip for three days and we spiral out of control again. What happened to the simplicity talk of a week ago?

Mr. Anderson...

Okay, forget the backdrops, forget the transparency. Forget using a lib. You don't have the time for that nonsense. Get the game happening on a black background first... and if it works there (a massive achievement) it will be easy to port to Rel or DQB.


Starting a fighting game - na_th_an - 05-20-2003

I was only fearing that sprites of that size wouldn't fit in memory. Anyways, here's the tut on masking:

As you may have noticed, the PUT function has those parameters:

Code:
PUT (x%, y%), array%(index%)[, mode]

where mode can be either PSET, AND, XOR among others. That final parameters especifies a logical operation between the pixel data in the array and the pixel data on screen.

What is a logical operation? Well, I guess you have heard of AND and OR, and that:

Code:
1 OR x = 1
0 OR 0 = 0
0 AND x = 0
1 AND 1 = 1

where x can be either 1 or 0. You also have XOR:

Code:
x XOR x = 0
x XOR y = 1 if x<>y

Those binary operations can be applied to byte numbers, for example, 127 AND 255 will compare each bit of 127 with its correspondent bit in 255, and will build a new byte with the results:

Code:
127 = 0 1 1 1 1 1 1 1
AND
    255 = 1 1 1 1 1 1 1 1
______________________
          0 1 1 1 1 1 1 1 = 127

This is very useful when trying to avoid the ugly black bounding box around our GFX. With masking techniques, you can get rid of it.

First we need to create a mask. Imagine we want a ball. We think on which pixels will be transparent and draw it with colour #ZERO:

Code:
00 00 01 02 02 01 00 00
00 01 02 03 03 02 01 00
01 02 03 03 03 03 02 01
01 02 03 03 03 03 02 01
01 02 03 03 03 03 02 01
01 02 03 03 03 03 02 01
00 01 02 03 03 02 01 00
00 00 01 02 02 01 00 00

Now, we create the mask. We need a similar drawing, but the transparent zones have to be drawn with colour #FFh (255, the last colour, in binary 11111111b). The non-transparent zones have to be drawn with colour #00h, that is:

Code:
FF FF 00 00 00 00 FF FF
FF 00 00 00 00 00 00 FF
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
FF 00 00 00 00 00 00 FF
FF FF 00 00 00 00 FF FF

what for? well, let me explain:

To do masking, we first need to prepare screen. If we PUT the mask using "AND", the blitter will AND each pixel in our mask with its correspondent on screen. That will make that every pixel on screen that corresponds with a FF in our mask (transparent zone) will remain as it is, 'cause x AND FF = x. It will also make that every pixel on screen that corresponds with a 00 in our mask (solid zones) will be cleared to ZERO, 'cause x AND 0 = 0.

Note that this will create a black zone with the shape of our sprite on screen.

Now we PUT the sprite using "XOR". Note that x XOR 0 = x and 0 XOR x = x, so the pixels in your sprite that equal 0 (transparent zones) won't have no effect on screen (and those pixels on screen will still have the background, after the AND operation), and the pixels in your sprite different from 0 will be XORed with pixels on screen that equal zero (after the AND operation, if your mask was correctly done).

Code:
' Transparent blit using masks:
PUT (x%, y%), myMask%(0), AND
PUT (x%, y%), mySprite%(0), XOR

I can't post examples 'cause my webspace can not be accessed tonight, so I can't upload pics to show you Sad.

LATER:

I've written this piece of code as an example:

Code:
' Masking demo by Na Than Assh Antti 2003

'$DYNAMIC
DIM MySprite%(33)
DIM MyMask%(33)

SCREEN 13

' Colour #255 is by default BLACK. Let's turn it into WHITE so we can
' see the mask (for educational purposes):

OUT &H3C8, 255: OUT &H3C9, 63: OUT &H3C9, 63: OUT &H3C9, 63

' Get the sprites: [I am using ugly and stupid DATA sprites :P]

RESTORE
FOR i% = 0 TO 1

   FOR y% = 0 TO 7
      FOR x% = 0 TO 7
         READ a$
         PSET (i% * 8 + x%, y%), VAL("&H" + a$)
      NEXT x%
   NEXT y%

NEXT i%
GET (0, 0)-(7, 7), MySprite%(0)
GET (8, 0)-(15, 7), MyMask%(0)

CLS
PAINT (0, 0), 34

LOCATE 3, 5: PRINT "THIS IS THE SPRITE:"
PUT (220, 16), MySprite%(0), PSET
LOCATE 5, 5: PRINT "THIS IS THE MASK:"
PUT (220, 32), MyMask%(0), PSET
LOCATE 7, 5: PRINT "Let's see what happens if we PUT"
LOCATE 8, 5: PRINT "our mask using AND:"
PUT (156, 72), MyMask%(0), AND
LOCATE 12, 5: PRINT "Now we PUT the mask with AND and "
LOCATE 13, 5: PRINT "then the sprite with XOR:"

' Transparency:
PUT (156, 112), MyMask%(0), AND
PUT (156, 112), MySprite%(0), XOR

' DONE :D

END

' Sprite:
DATA 00,00,01,01,01,01,00,00
DATA 00,01,02,02,02,02,01,00
DATA 01,02,02,03,03,02,02,01
DATA 01,02,02,03,03,02,02,01
DATA 01,02,02,03,03,02,02,01
DATA 01,02,02,03,03,02,02,01
DATA 00,01,02,02,02,02,01,00
DATA 00,00,01,01,01,01,00,00

' Mask:
DATA FF,FF,00,00,00,00,FF,FF
DATA FF,00,00,00,00,00,00,FF
DATA 00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00
DATA FF,00,00,00,00,00,00,FF
DATA FF,FF,00,00,00,00,FF,FF



Starting a fighting game - Kofman - 05-22-2003

I get it, it's very creative. And very simple too I think. Thanks allot.
Before you said this takes allot of memory and is slow. How about this.

I. Using wiz's spriter and rendering code get the masks and sprites onto memory.
II. Next use masking to create transparency.
III. Clear Memory
IV. Make new sprites from those on the screen and save them into memory.
V. Clear the screen and start playing with them

The only problem I see here is I don't know how to clear memory. I mean destroy an array or something like that.

This might take some time to load. But just make a little bar that loads everything and without the use of libaries I'm sure it will be very acceptable to wait a few seconds till everything is loaded, unloaded, and reloaded.

So tell me if this could work and if so how do you clear an array or clear memory?


Starting a fighting game - Kofman - 05-22-2003

I just did that masking thing and all my colors got a little screwy.
Really screwy.

I'm waiting for the chance to upload it, becuase it's really impossible to describe it.

If you know the problem off hand please tell me. Here is my long abstract code collected from what you guys have given me.

Code:
SCREEN 13
CLS
PAINT (0, 0), 1

DIM sprite(65, 66 + 66) AS INTEGER

OPEN "NARUTO.TIL" FOR BINARY AS #1

length = LOF(1) - 768

FOR sprt% = 0 TO (length / 66) - 1

   sprite%(0, sprt%) = 64
   sprite%(1, sprt%) = 8

   FOR byte% = 2 TO 33
      GET #1, (sprt% * 66) + 3 + ((byte% - 2) * 2), temp%
      'PRINT temp%
      sprite%(byte%, sprt%) = temp%
   NEXT
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

DIM mask(65, 66 + 66) AS INTEGER

OPEN "MASK.TIL" FOR BINARY AS #2

length = LOF(2) - 768

FOR sprt% = 0 TO (length / 66) - 1

   mask%(0, sprt%) = 64
   mask%(1, sprt%) = 8

   FOR byte% = 2 TO 33
      GET #2, (sprt% * 66) + 3 + ((byte% - 2) * 2), temp%
      'PRINT temp%
      mask%(byte%, sprt%) = temp%
   NEXT
NEXT

FOR drawx = 0 TO 22
     FOR drawy = 0 TO 2
          PUT (drawx * 8, drawy * 8), mask(0, masknum), AND
          masknum = masknum + 1
     NEXT
NEXT
FOR drawx = 0 TO 22
     FOR drawy = 0 TO 2
          PUT (drawx * 8, drawy * 8), sprite(0, spritenum), XOR
          spritenum = spritenum + 1
     NEXT
NEXT

DO: LOOP UNTIL INKEY$ <> ""


CLOSE #1, #2



Starting a fighting game - Kofman - 05-22-2003

I know I already have a bunch of posts going here, with different things to discuss but since I haven't been replied to yet I'll keep going : P. Is their a way to take a color from the pallate directly and either manipulate it by changing it, or better yet deleting it from the pallate. Thus making something trasparent. Food for Thought or just my stupidity acting up again. :king:


You can read the RGB data for attribute A from the ... - Glenn - 05-22-2003

palette registers via

OUT &H3C7, A
R = INP(&H3C9)
G = INP(&H3C9)
B =INP(&H3C9)

But changing them and rewriting them to the palette registers, via

OUT &H3C8, A
OUT &H3C9, R
OUT &H3C9, G
OUT &H3C9, B

won't make anything "transparent." That's not a property of the RGB data. That's a property of how the attribute you're plotting interacts with the attribute of the pixel already on the screen at that location.


Starting a fighting game - Kofman - 05-22-2003

oh I know it's not really possible to create a transparent swatch in the pallate. But when you load a program onto the screen in QBASIC the background isn't really black. It's empty theirs nothing their. So what I'm saying is couldn't you take a certain swatch and tell the pallate never to actually draw it. Or something like that. I mean I'm expreminting with ideas that have probably been thought of already but It's worth a try to maybe inspire one you genious to come up with a solution.

Also I've bad at understanding what INP(&H3C9) means. Where can I get definitions for all these sybmols : ?


Starting a fighting game - wizardlife - 05-22-2003

It's called a transparent PUT routine. It's 50% of the reason to switch to a lib. (the other 50% being a fast double buffer, of course)

But like I said, I think you should screw that and just work on a black background.