Help with masking and code layout. Please and thanks.

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Help with masking and code layout. Please and thanks.

Post by Super Mario »

Hey everybody. I just started programing this yesterday. I got this far by myself, checking tutorials when I got stuck. Now, however, I've hit some snags. I think I have been focusing to much on getting graphics on screen than the actual game itself.

First and foremost, I'm having trouble with the masking tecnique. If somebody could explain the concept and how to implement it, I would be really thankful. I've read some tutorials relating to it, but I still don't understand.

Second, I'm concerned about the coding in general. If I want to have a sprite move around a map and have more maps when he moves off the screen, how should I place all the code. Where should everything go?

Again, thanks a lot. I self-taught myself QBasic last summer, but this is the first graphic intensive thing I've done. Any other comments or suggestions would be appreciated.

Code: Select all

DIM grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)

SCREEN 13

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 1 THEN PSET (x, y), 10
IF clr = 0 THEN PSET (x, y), 2
NEXT
NEXT

GET (1, 1)-(10, 10), grass

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 14
NEXT
NEXT

GET (1, 1)-(10, 10), path

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 3
IF clr = 1 THEN PSET (x, y), 11
NEXT
NEXT

GET (1, 1)-(10, 10), water

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 6
IF clr = 1 THEN PSET (x, y), 8
IF clr = 2 THEN PSET (x, y), 0
NEXT
NEXT

GET (1, 1)-(10, 10), tent

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 0
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scout

FOR y = 1 TO 10
FOR x = 1 TO 10
READ clr
IF clr = 0 THEN PSET (x, y), 255
IF clr = 1 THEN PSET (x, y), 2
IF clr = 2 THEN PSET (x, y), 8
IF clr = 3 THEN PSET (x, y), 14
IF clr = 4 THEN PSET (x, y), 4
NEXT
NEXT

GET (1, 1)-(10, 10), scoutmask

CLS
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
IF tilenumber = 5 THEN PUT (x * 10, y * 10), scout, PSET
IF tilenumber = 5 THEN PUT (x * 10, y * 10), scoutmask, PSET

NEXT
NEXT

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,1,0,0,0
DATA 0,1,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,1,0,0
DATA 0,0,0,0,0,0,0,0,0,0

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

DATA 0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,0,0,0,0,0,0
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1,1,1,1,1,1,3,3
DATA 1,1,1,1,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,2,4,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,4,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,4,1,1,1,1,3,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Good job.

On masking:
The idea is for a certain color that causes a to-draw pixel to be ignored, so the background is used instead. Like that sprite. There should be some color that when the computer sees it, it simply just uses the background (the tile in this case).

[edit] I'm working on some pictures.

[edit] Here we go:

The tile: http://www.skepticalcommunity.com/phpbb ... le1alt.bmp

The sprite: http://www.skepticalcommunity.com/phpbb ... /labf1.bmp

Drawing a the masked sprite onto the tile: http://www.skepticalcommunity.com/phpbb ... ask_1j.jpg

In this case, the masking color is the pinkish background.

Hm. I'm having trouble hot linking. Oh well, they're small.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

Okay, but do you need to have two sprites like I have in my code? Or do you just have the one sprite with the invisable background? Also, how do you get the " invisable color"?
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Super Mario wrote:Okay, but do you need to have two sprites like I have in my code? Or do you just have the one sprite with the invisable background? Also, how do you get the " invisable color"?
I used FB for the example, since I learned about sprites after I adjusted to FreeBASIC. So I've forgotten how to specifically do it in QB. The way I put sprites (TRANS, as opposed to PSET or AND), the mask color is pinkish.
I don't remember the method for QB. I'll have to look into it some more.

So first you draw you're whole background as if the sprite isn't there. Then you draw the sprites (characters & moving stuff).
For any grievances posted above, I blame whoever is in charge . . .
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Go here

Post by burger2227 »

Talk to Bob about this at his Graphics Studio:

http://www.network54.com/Forum/613143/

Ted

LOL@FB
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Ah, I did a little checking. In QB, I think there needs to be an extra image for the mask.

FB has pampered me. I'm used to opening up in Paint then flood filling the mask color.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

So you need to put down the tile with PSET. Then you need to put down the mask with AND. What the mask will do is cut out the image by ANDing 0 to where you would draw the sprite's pixels. I think it depends on the screen mode, but in &h13 I used 0 as the sprite's pixels for the mask, and 255 for the tile.

So a sprite like this:

DATA 0,0,0,0,1,1,0,0,0,0
DATA 0,0,0,1,1,1,1,1,0,0
DATA 0,0,0,3,3,3,3,0,0,0
DATA 0,2,2,2,2,4,2,2,2,0
DATA 0,2,2,2,2,4,2,2,2,0
DATA 0,3,2,2,2,2,2,2,3,0
DATA 0,0,2,2,2,2,2,2,0,0
DATA 0,0,1,1,1,1,1,1,0,0
DATA 0,0,1,1,1,1,1,1,0,0
DATA 0,0,1,1,1,1,1,1,0,0

should have a mask like this:

DATA 1,1,1,1,0,0,1,1,1,1
DATA 1,1,1,0,0,0,0,0,1,1
DATA 1,1,1,0,0,0,0,1,1,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,1,0,0,0,0,0,0,1,1
DATA 1,1,0,0,0,0,0,0,1,1
DATA 1,1,0,0,0,0,0,0,1,1
DATA 1,1,0,0,0,0,0,0,1,1

where the 1s are color 255 and 0s are color 0.

Then OR the sprite.

I got your example to work. Here:

Code: Select all

DIM as integer grass(10, 10), path(10, 10), water(10, 10), tent(10, 10), scout(10, 10), scoutmask(10, 10)

SCREEN 13

dim y as integer
dim x as integer
dim clr as integer
dim tileNumber as integer

FOR y = 1 TO 10
    FOR x = 1 TO 10
    READ clr
    IF clr = 1 THEN PSET (x, y), 10
    IF clr = 0 THEN PSET (x, y), 2
    NEXT
NEXT

GET (1, 1)-(10, 10), grass

FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 6
        IF clr = 1 THEN PSET (x, y), 14
    NEXT
NEXT

GET (1, 1)-(10, 10), path

FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 3
        IF clr = 1 THEN PSET (x, y), 11
    NEXT
NEXT

GET (1, 1)-(10, 10), water

FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 6
        IF clr = 1 THEN PSET (x, y), 8
        IF clr = 2 THEN PSET (x, y), 0
    NEXT
NEXT

GET (1, 1)-(10, 10), tent

FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 0
        IF clr = 1 THEN PSET (x, y), 2
        IF clr = 2 THEN PSET (x, y), 8
        IF clr = 3 THEN PSET (x, y), 14
        IF clr = 4 THEN PSET (x, y), 4
    NEXT
NEXT

GET (1, 1)-(10, 10), scout

FOR y = 1 TO 10
    FOR x = 1 TO 10
        READ clr
        IF clr = 0 THEN PSET (x, y), 0
        IF clr = 1 THEN PSET (x, y), 255
        IF clr = 2 THEN PSET (x, y), 8
        IF clr = 3 THEN PSET (x, y), 14
        IF clr = 4 THEN PSET (x, y), 4
    NEXT
NEXT

GET (1, 1)-(10, 10), scoutmask

CLS
FOR y = 1 TO 15
    FOR x = 1 TO 30
        READ tileNumber
        
        IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, Pset
        IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, Pset
        IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, Pset
        IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, Pset
        IF tilenumber = 5 THEN PUT (x * 10, y * 10), path, Pset
        IF tilenumber = 5 THEN PUT (x * 10, y * 10), scoutMask, AND
        IF tilenumber = 5 THEN PUT (x * 10, y * 10), scout, OR
    
    NEXT
NEXT

sleep

'grass
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,0,0,0,0,0,0,0
DATA 0,0,0,0,0,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,1,0,0,0
DAT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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3
DATA 2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3
DATA 1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

Okay. I got the mask to work. Looks great! Now, how would I go about adding movement?
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

When you want things to move, you don't put it/him/her in the data array. You give them coordinates and then move the coordinates.

So you're guy has the coordinates 5, 1 according to the map. Instead of putting the number 5 in the map, you put the path, then draw him at his coordinates.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

Okay, I changed it. I now have the map down, with the guy placed afterwards using its own coordinates. Any tips on moving him?
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Code: Select all

...
'get keyboard button pressed
key$ = inkey$

'left
if key$ = chr$(0) + chr$(75) then scoutX = scoutX - 1

'Right
if key$ = chr$(0) + chr$(77) then scoutX = scoutX + 1

...
chr$(0) + chr$(75) is the left arrow
chr$(0) + chr$(77) is right arrow
chr$(0) + chr$(80) and chr$(0) + chr$(72) are up and down arrows, but I forgot which is which.

Moving is adding the direction to the coordinate. v = dx / dt.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

Here's what I have right now.

Code: Select all

DO
p$ = INKEY$
oldscoutx = scoutx
oldscouty = scouty

PUT (oldscoutx * 10, oldscouty * 10), scoutmask, AND
PUT (oldscoutx * 10, oldscouty * 10), scout, OR

IF p$ = "w" THEN scouty = oldscouty - 1
IF p$ = "s" THEN scouty = oldscouty + 1
IF p$ = "a" THEN scoutx = oldscoutx - 1
IF p$ = "d" THEN scoutx = oldscoutx + 1

LOOP UNTIL p$ = CHR$(27)
How do I change this so it erases the old guy, replaces the tile underneath, and moves it with out creating a new guy each time?
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Clear the whole screen, and redraw the whole spill. Or just redraw the tiles and sprite again.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

Is that the best way? Or is there a more proper way?

Once again, thanks a TON for all of your help!
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

I'm getting an "Out of Data" error. What does this mean?

Code: Select all

DO
p$ = INKEY$
oldscoutx = scoutx
oldscouty = scouty

PUT (oldscoutx * 10, oldscouty * 10), scoutmask, AND
PUT (oldscoutx * 10, oldscouty * 10), scout, OR

IF p$ = "w" THEN scouty = oldscouty - 1
IF p$ = "s" THEN scouty = oldscouty + 1
IF p$ = "a" THEN scoutx = oldscoutx - 1
IF p$ = "d" THEN scoutx = oldscoutx + 1

CLS
FOR y = 1 TO 15
FOR x = 1 TO 30
READ tilenumber

IF tilenumber = 1 THEN PUT (x * 10, y * 10), grass, PSET
IF tilenumber = 2 THEN PUT (x * 10, y * 10), path, PSET
IF tilenumber = 3 THEN PUT (x * 10, y * 10), water, PSET
IF tilenumber = 4 THEN PUT (x * 10, y * 10), tent, PSET
                                          
NEXT
NEXT

LOOP UNTIL p$ = CHR$(27)
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Let's see ... you can draw to one frame not shown, then pCopy it to the current frame. Or lock it, draw, unlock briefly then relock, draw, etc. Burger might know something else. Again, I'm used to FB lib methods not available in QB. My favorite is start-unlock-lock-cls-draw-loop.

Different ways, different flavors. I don't know which one is the most proper.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Out of data means you're asking to read a data statement, but you've gone through all of them.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

How can i go back through to the one I want?
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

With "RESTORE". It's used like GOTO, but with data.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Super Mario
Coder
Posts: 21
Joined: Mon Jul 21, 2008 8:34 am
Location: My computer

Post by Super Mario »

So just instead of READ, use RESTORE?
Post Reply