Qbasicnews.com

Full Version: Palletes an rain
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey do any of u guys know how i would go about making rain?

It doesnt need to be transparent or anything, just rain diagonally or more helpful, downwards.

Also, what is a pallete, and why would i need one for a game? isnt 256 colours enuff?

thanks in advance.
Note the credit at the end...this is not my code.

Code:
SCREEN 13
CLS
DEFINT A-Z
'init the palette
FOR I = 1 TO 60
  OUT &H3C8, I
  OUT &H3C9, I / 2 + 33
  OUT &H3C9, I / 2 + 33
  OUT &H3C9, I / 2 + 33
NEXT I

NUMFLK = 1000      'Number of flakes

'Define the snow flake variable type
TYPE snfk
  X AS INTEGER
  Y AS INTEGER
  C AS INTEGER
END TYPE

'-                                         -
'Draw what you want the snow to fall on here
COLOR 64
LOCATE 15, 15: PRINT "ESC to exit"
LOCATE 16, 9: PRINT "Any key to clear screen"
'-                                         -

'Dimension the snow flake array
DIM FLK(NUMFLK) AS snfk

'Init the flakes pos and speed
FOR I = 1 TO NUMFLK
  FLK(I).X = RND * 320
  FLK(I).Y = -4000
  FLK(I).C = RND * 50 + 50
NEXT I

'Move the flakes a little so they're not so bunched up
FOR REP = 1 TO 80
  FOR I = 1 TO NUMFLK
    FLK(I).Y = FLK(I).Y + FLK(I).C
  NEXT I
NEXT REP

TIM! = TIMER
'Do the snow
DO
CNT = CNT + 1
RANDOMIZE TIMER
FOR I = 1 TO NUMFLK

  MVD = 0         'Set up the
  OY = FLK(I).Y '
  OX = FLK(I).X '
  OC = FLK(I).C 'temporary   (not array is faster)
  TC = OC         '
  TY = OY         '
  TX = OX         'variables
  TYH = TY \ 100  'Set another variable

  IF POINT(TX, TYH + 1) <> 0 AND TY > 2000 THEN 'Check if the current pixel is filled
    MVD = 2
    IF POINT(TX - 1, TYH + 1) = 0 THEN                       'how about the down & left pixel?
      IF POINT(TX - 1, TYH) = 0 THEN TX = TX - 1: MVD = 1    'no so move the pixel there
    ELSEIF POINT(TX + 1, TYH + 1) = 0 THEN                   'how about the down & right pixel?
      IF POINT(TX + 1, TYH) = 0 THEN TX = TX + 1: MVD = 1    'no so move the pixel there
    END IF
  END IF

  IF MVD = 2 THEN       'If the flake cant move then put it on the top
    FLK(I).X = RND * 320
    FLK(I).Y = 100
    FLK(I).C = RND * 50 + 50
    GOTO 1
  END IF

  TY = TY + TC    'Increment the flake vertically

  PSET (OX, TYH), 0                 'Erase the flake
  PSET (TX, TY \ 100), TC - 40         'Draw the flake

  FLK(I).X = TX                        ' Put the flake
  FLK(I).Y = TY                        '   where its
  FLK(I).C = TC                        'supposed to be
1
NEXT I
A$ = INKEY$
IF A$ = CHR$(27) THEN EXIT DO
IF A$ <> "" THEN CLS
LOOP
SCREEN 12
PRINT CNT / (TIMER - TIM!)
DO
LOOP UNTIL INKEY$ = ""
PRINT "FAST SNOW ROUTINE BY DANNY BEARDSLEY (made in QB4.5)"
PRINT "COMPILE ME! 2 TIMES FASTER"
PRINT "COMPILE ME! 2 TIMES FASTER"
PRINT "COMPILE ME! 2 TIMES FASTER"
PRINT "________________________________________________________"
PRINT "This is a fast snow routine in 320X200 with 1000 flakes!"
PRINT "    If you COMPILE it will be !!!2 times faster!!!!"
PRINT "    I think that every variablle here is an integer"
PRINT "  If you want more code for other amazing feats then>"
PRINT "--------------------------------------------------------"
PRINT "Email:       dsb@cyberdude.com"
PRINT "Homepage:    www.dnai.com/~beards"
PRINT "FREEWARE (just put my name in somewhere if you use it {:-)"
SLEEP

END
doesn't change the number of colors available. It just changes what the colors are (if I understood that part of your question right).
ok, thanks, but, how would i go about making my own? why would i need a new pallete?
Because you don't want blackish red rain.
Mode 13h (SCREEN 13) can have 256 different colors on the screen at any given point. These colors can be selected from an 18 bit rgb palette, giving you a total of a little over 260,000 colors that these 256 palettes can be. Think of it like having an art palette with room for 256 different paints.

256 colors is plenty, but you're going to want a custom palette if you're making a tileset, but the one qb gives you just isnt very good, there are a lot of useful colors missing. You can change any one of the colors by doing the following:

Code:
out &h3c8, colortochange
out &h3c9, redvalue '0-63
out &h3c9, greenvalue '0-63
out &h3c9, bluevalue '0-63
thanks guys helps alot!
I read that link, but it doesnt tell me how to actually change the port values, any ideas?
Quote:I read that link, but it doesnt tell me how to actually change the port values, any ideas?

Uh? :o

I think it does:

Quote:Or we can use OUTs to the DAC ports of the VGA (fast)...

Code:
OUT &H3C8, slot
OUT &H3C9, red
OUT &H3C9, green
OUT &H3C9, blue

That actually changes the port values... What's wrong with that?

Check this out also: http://qbasicnews.com/qboho/qckout.shtml
Pages: 1 2