#80992 - 2002-06-25 10:05 AM
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Normally attributes are collected together in a single integer, or large integer, and you use binary math to evaluate /set them.
Some definitions:
code:
$BLACK=0 $BLUE=1 $GREEN=2 $CYAN=3 $RED=4 $MAGENTA=5 $YELLOW=6 $WHITE=7 $BLINK=8 $BITMASK=&0F
Now these colours can be stored in just four bits(1,2,4,8, or &0F), which means that the foreground and background colours can both be stored in 8 bits, or a byte (short integer).
To get the colour of the foreground assuming $iAttribute is the attribute value of the screen location:
code:
$iForeColour=($iAttribute & $WHITE) If $iForeColour=$RED "Foreground is red" EndIf
To see if the foreground blink/highlight sttribute is set:
code:
If $iAttribute & $BLINK "Foreground blink is set" ? EndIf
The background attributes work exactly the same way, except you need to shift the bits before you can compare them. This is simply done by dividing the value by 16.
code:
$iForeColour=($iAttribute / 16) & $WHITE
To set the bits you just work in reverse. To set yellow flashing text on a blue background:
code:
$iAttribute=( $YELLOW |$BLINK ) | ( 16 * ( $BLUE | $BLINK ) )
This is a fast efficient way of storing attribute information, and is how you would do it in 'C'. It allows you to use a host of programming tricks to simplify and speed up programs. Early games used to use attributes for collision detection, and making all the things that can blow you up high intensity simplifies the code a lot
The problem is that bitwise math is not everyone's cup of tea.
|
|
Top
|
|
|
|
@CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
BrianTX
|
2002-06-20 08:41 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Radimus
|
2002-06-20 08:44 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
BrianTX
|
2002-06-21 05:23 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Shawn
|
2002-06-21 05:32 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
BrianTX
|
2002-06-21 05:54 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Shawn
|
2002-06-21 06:01 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Shawn
|
2002-06-21 06:05 PM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Richard H.
|
2002-06-24 10:00 AM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
BrianTX
|
2002-06-25 05:46 AM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
Richard H.
|
2002-06-25 10:05 AM
|
Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
|
BrianTX
|
2002-06-25 06:46 PM
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 764 anonymous users online.
|
|
|