Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: andy on October 17, 2003, 08:49:18 AM



Title: darken
Post by: andy on October 17, 2003, 08:49:18 AM
Say I have a game, and when I pause it, I want the entire screen become darker, so the image is still there but darker. and in the middle I want a box with a message in to apperar in th normal brightness, how can I do this. Please help.


Title: darken
Post by: Agamemnus on October 17, 2003, 10:55:07 AM
If you're using all 256 colors on the screen at the same time, you can't do that. Otherwise you go through all the colors except those you want to use for the box and divide their rgb values by two... using PALETTE.............................

Otherwise................. you can use ugl's alpha blending thingo... if you're doing it in ugl.......

Sorry...... details are........ bad.......


Title: Like this:
Post by: Xyphos on October 17, 2003, 11:24:06 AM
I assume this is QB and you are using 256 colors?

Code:

DEFINT A-Z

Type PalType
   Red As Integer
   Green As Integer
   Blue As Integer
End Type

Dim Shared Pal(255) As PalType, I% As Integer

SUB Pause (BrightColor%)

   'Special Thanks to Xyphos for this routine.
   'He is the greatest programmer in the world!!!

   '   (^.^)

    For I% = 0 To 255 'Number Of Colors
       If I% <> BrightColor% Then 'Make sure we don't modify the Brighter Color.
            'Fetch current color attributes for this color
            Out &H3C7, I% 'Write VGA, The color to be read
            Pal(I%).Red = Inp(&H3C9) 'Get Red, Green and Blue
            Pal(I%).Green = Inp(&H3C9)
            Pal(I%).Blue = Inp(&H3C9)

            'Now write this color back as halved.
            Out &H3C8, I% 'Write VGA, The color to be written
            Out &H3C9,  Pal(I%).Red \ 2
            Out &H3C9,  Pal(I%).Green \ 2
            Out &H3C9,  Pal(I%).Blue \ 2
       END IF
   NEXT I%

   '   < YOUR MESSAGE CODE GOES HERE >
   ' < SOME TYPE OF CONTROLED LOOP GOES HERE >

   'Now restore everything

   For I% = 0 to 255
            Out &H3C8, I% 'Write VGA, The color to be written
            Out &H3C9,  Pal(I%).Red
            Out &H3C9,  Pal(I%).Green
            Out &H3C9,  Pal(I%).Blue
   NEXT

   ' Viola! such a masterpiece!
END SUB



' sorry if the code is a little buggy, but I do know the vast secreats of programming    :D


Title: darken
Post by: toonski84 on October 17, 2003, 03:52:35 PM
You're not limited to 256 color modes or even VGA modes to use a palette fade.  On a VGA card, using OUT to modify the palette is effect on colors 0-4 in text mode, and 0-7 in EGA modes.  In screen 12, a vga mode with 16 colors, you can modify every color on the pallete.

Here's a little something that should work on 256 color modes.  If you are using mode 12h or an EGA, find all the little "255"s and change them to the highest color you can modfiy.

Code:
DECLARE SUB fadein (pal() AS ANY, steps!)
DECLARE SUB fadeout (pal() AS ANY, steps AS INTEGER)
DECLARE SUB getpal (pal() AS ANY)

TYPE pal
 r AS INTEGER
 g AS INTEGER
 b AS INTEGER
END TYPE

SCREEN 13
DIM pal(0 TO 255) AS pal

FOR x = 0 TO 255
  LINE (x, 0)-(x, 199), x
NEXT x

getpal pal()
SLEEP
fadeout pal(), 200
SLEEP
fadein pal(), 200


SUB fadein (pal() AS pal, steps)
  FOR y = 1 TO steps
    OUT &H3C8, 0
    FOR x = 0 TO 255
      OUT &H3C9, (pal(x).r / steps) * y
      OUT &H3C9, (pal(x).g / steps) * y
      OUT &H3C9, (pal(x).b / steps) * y
    NEXT x
  NEXT y
END SUB

SUB fadeout (pal() AS pal, steps AS INTEGER)
  FOR y = 1 TO steps
    OUT &H3C8, 0
    FOR x = 0 TO 255
      OUT &H3C9, pal(x).r - (pal(x).r / steps) * y
      OUT &H3C9, pal(x).g - (pal(x).g / steps) * y
      OUT &H3C9, pal(x).b - (pal(x).b / steps) * y
    NEXT x
  NEXT y
END SUB

SUB getpal (pal() AS pal)
OUT &H3C7, 0
FOR x = 0 TO 255
  pal(x).r = INP(&H3C9)
  pal(x).g = INP(&H3C9)
  pal(x).b = INP(&H3C9)
NEXT x
END SUB


if you want help understanding it, or you want to modify it to suit your needs, just reply and I will tell.

on a side note, for those who care:  this is just a sad testament to how much perl has corrupted me.  I need to return multiple values, arrays and hashes in an inefficient manner, it's a sick, disgusting, perform-hogging trait of my programming of late, but I could never turn back.


Title: darken
Post by: Dav on October 17, 2003, 06:17:39 PM
Had this little snippet at my fingers.  This uses OUT as well.
Code:

'TRANSBOX.BAS
'Simple Transparent box routine

DEFINT A-Z
DECLARE SUB TRANSBOX (x1%, y1%, x2%, y2%, clr%)

SCREEN 13

'draw some lines
FOR i% = 1 TO 200
    LINE (RND * 319, RND * 199)-(RND * 319, RND * 199), RND * 255
NEXT

TRANSBOX 40, 40, 80, 80, 33

SUB TRANSBOX (x1%, y1%, x2%, y2%, clr%)

FOR i% = 239 TO 255: OUT 968, i%
    OUT 969, r%: r% = r% + clr% / 16
    OUT 969, g%: g% = g% + clr% / 16
    OUT 969, B%: B% = B% + clr% / 16
NEXT

REDIM TT(255) AS INTEGER
FOR i% = 0 TO 255: OUT 967, i%
  TT(i) = 239 + ((INP(969) + INP(969) + INP(969)) / 4) / 63 * 16
NEXT

DEF SEG = &HA000
offset& = y1% * 320&
FOR y% = y1% TO y2%
    FOR x% = x1% TO x2%
        POKE offset& + x%, TT(POINT(x%, y%))
    NEXT
    offset& = offset& + 320
NEXT
DEF SEG

LINE (x1%, y1%)-(x2%, y2%), 255, B

END SUB


Here's a little 'fake' trans box routine I have using PUT instead.  It's not that great looking, put it might be worth posting too:

Code:


DEFINT A-Z

SCREEN 13

FOR x% = 1 TO 320 STEP 2
  FOR y% = 20 TO 180 STEP 2
    PSET (x%, y%), RND * 22
  NEXT
NEXT
LOCATE 25, 15: PRINT "PRESS A KEY";
A$ = INPUT$(1)

'Translucent window
REDIM Image&(0 TO 6800)                 'Use 16000 for whole screen
GET (50, 50)-(270, 170), Image&         'Store Screen
LINE (50, 50)-(270, 170), 33, BF        'Fill in a dark area
PUT (50, 50), Image&, AND               'Merge or Impose Image (AND/OR)
                                        'AND makes darker windows
LINE (50, 50)-(270, 170), 22, B         'Give it a Border
LINE (51, 51)-(269, 169), 55, B        'Give it a Border
A$ = INPUT$(1)                          'Pause......
PUT (50, 50), Image&, PSET              'Restore Screen Image

SLEEP


- Dav


Title: darken
Post by: na_th_an on October 17, 2003, 06:19:40 PM
Quote from: "toonski84"
You're not limited to 256 color modes or even VGA modes to use a palette fade.  On a VGA card, using OUT to modify the palette is effect on colors 0-4 in text mode, and 0-7 in EGA modes.


(again) In fact, you can change every colour in every mode: http://faq.qbasicnews.com/?blast=DacRegistersInScreenNine

This applies to text mode and SCREEN 9.

In Screen 7 and Screen 8 you have to OUT &H3C8,0-7 for colours 0-7 and OUT &H3C8,16-23 for colours 8-15 (note : add 8 ).

Code:
' Palette in SCREEN 7 - 8
SUB SetDAC78 (reg%, r%, g%, b%)
   IF reg%>7 THEN reg%=reg%+8
   OUT &H3C8, reg%
   OUT &H3C9, r%
   OUT &H3C9, g%
   OUT &H3C9, b%
END SUB


Code:
' Palette in SCREEN 0, SCREEN 9
SUB SetDAC09 (reg%, r%, g%, b%)
   PALETTE reg%, reg%
   OUT &H3C8, reg%
   OUT &H3C9, r%
   OUT &H3C9, g%
   OUT &H3C9, b%
END SUB


(Toonsk, I think I explained this to you in a previous post... May I be mistaken)


Title: darken
Post by: toonski84 on October 17, 2003, 06:34:55 PM
Oh, wow.  I need to read mesages more closely.  You want to leave everything but area darker.  In that case, you have a few options:

1) Use an RGB table to find RGB matches closest to the palette's current selection (memory consuming).

2) Fake a 332 RGB palette, that is use 3 bytes for red, and 3 bytes for green and 2 for blue, and you can span the entire spectrum with only 256 colors (crummy quality).

3) use an overlapping palette (good if you're clever)

There really isnt a perfect way to do this, you just have to play with illusion tricks.  Number 3 works the best in my honest opinion, but it would be potentially slow.  

I dont know.

I'm confused, could you explain this in more detail?

EDIT: Yeah, nate, I didn't know you could go above 7 in EGA modes.  Thanks for enlightening me, I was going off previous experiences.


Title: darken
Post by: na_th_an on October 17, 2003, 09:38:36 PM
Well, I had the same prob. When I first coded "Jill" I did it with no libs and in SCREEN 7. I discovered that by mistake, but :P oh, most good discovers have been by mistake.

As for the topic, what I would do is something that is implied in some of the replies above: I'd pick up some colours that I'd only use for messages and GUI, and would not use them in any graphics so when I wanted to darken screen as explained I'd only darken the remaining colours, leaving the GUI colours untouched.

The best way would be using a hicolour or truecolour palette and overlay a translucent black box, but I guess you're using Mode 13h so don't mind.


Title: darken
Post by: relsoft on October 18, 2003, 04:10:23 AM
RelGammaBlock ;*)


Title: darken
Post by: andy on October 18, 2003, 01:22:09 PM
Thanks, I tred xyphos's first and it works fine. I had to change some things like I had to define the arays, and pal(i%).red etc, was not allowed I had to change it to palred(i%) as my version of qbasic will not allow "periods" or in english dots. Anyway thaks to everyone who posted.


Title: darken
Post by: TheBigBasicQ on October 19, 2003, 03:44:25 PM
Which version are you using? qb 1.1?


Title: darken
Post by: oracle on October 19, 2003, 07:33:53 PM
You can't use "."s in your arrays unless you define a TYPE for it. It's got nothing to do with the version...

Code:
TYPE PalType
  Red AS INTEGER
  Green AS INTEGER
  Blue AS INTEGER
END TYPE

DIM Pal(1 TO 64) AS PalType

' yada yada...

Pal(1).Red = 63
Pal(1).Green = 45
'......


Title: darken
Post by: andy on October 20, 2003, 04:34:46 AM
I think I'm using v1.1.
It came with windows 3.11 about nine years ago.


Title: darken
Post by: TheBigBasicQ on October 20, 2003, 02:56:22 PM
Ah, then try to download qb 4.5 or 7.1. It is a *lot* better than 1.1

http://www.qbcafe.net/english/dl_pages/compiler/qbasic.html


Title: darken
Post by: oracle on October 20, 2003, 04:45:45 PM
How about a nice, direct link: http://homepages.ihug.co.nz/~twotowers/software/qb45.zip ;)


Title: darken
Post by: andy on October 21, 2003, 04:40:52 AM
Thanks, I can confirm it, I have QB v1.1. I have v7.1 on my laptop, but that is off for repair. I should get it back soon.
By the way what differences are there between v1.1 and v7.1 in the coding, not the interface.


Title: darken
Post by: toonski84 on October 21, 2003, 07:15:27 AM
Well, the biggest, most important difference between 1.1 and any other version is that it can't compile .exes.  You see, 1.1 is really cripped shareware of an updated version of 4.5 that they distributed with dos (and consequently windows).  It can also do things like run .qlb libraries (asm extentions to the BASIC language) and execute interrupts from qb.  

7.1 has a few features over 4.5 as well.  You can use arrays in type definitions, and programs can be stored in EMS memory.  There also seems to be some new data types like CURRENCY.  It also has some cleaner code as well.

Microsoft also made a final version of QB, called Visual Basic for Dos.  It generates pretty much the cleanest, fastest code of any of the QBs, though it isnt used much for some reasons.


Title: darken
Post by: TheBigBasicQ on October 21, 2003, 10:13:52 AM
Quote from: "oracle"
How about a nice, direct link: http://homepages.ihug.co.nz/~twotowers/software/qb45.zip ;)


Oracle you are such a bully ;) That doesnt leave him any choice. He has to download Qb 4.5. My link will allow him to choose between qb 4.5 and 7.1.

Andy, I recommend Qb7.1 =)


Title: darken
Post by: oracle on October 21, 2003, 04:33:08 PM
Like I said, qb45=compatibility+most the features of 7.1. Sterling Christensen is always being caught out using QB7.1 commands and posting them here, where the vast majority of us can't use them.

Besides, he already has 7.1  :P


Title: darken
Post by: toonski84 on October 21, 2003, 07:13:17 PM
"can't use them?" - You can install more than one on your computer, silly.


Title: darken
Post by: seph on October 21, 2003, 08:39:31 PM
ORRRRRRRRRRR you can do it MY way, which is so much better than theirs ;)

HERE!

Code:
SCREEN 13

paintScreen
'SLEEP

gamePause 1
SLEEP

paintScreen
'SLEEP

gamePause 2
SLEEP

SUB gamePause (method%)
        SELECT CASE method%
        CASE 1
                FOR y% = 0 TO 99
                        FOR x% = 0 TO 159
                                PSET (x% * 2, y% * 2), 0
                        NEXT x%
                NEXT y%
        CASE 2
                FOR y% = 0 TO 99
                        FOR x% = 0 TO 159
                                PSET (x% * 2, y% * 2), 0
                                PSET (x% * 2 + 1, y% * 2 + 1), 0
                        NEXT x%
                NEXT y%
        END SELECT
END SUB

SUB paintScreen
        CLS
        PAINT (0, 0), 5
END SUB