1. Fat Bit
Can someone help me make a FatBit editor I don't know how to go about doing
this.
Albert
2. Re: Fat Bit
Albert Brauneis wrote:
>Can someone help me make a FatBit editor I don't
>know how to go about doing this.
I'll try to put something together for you if I get a chance. It's not that
hard. Take a look at any of my example games (Ex17, Ex18, Ex19, Mines) to
see how hit testing is performed. If replace the game tiles with fatbit
tiles, the code's 90% written.
-- David Cuny
3. Re: Fat Bit
- Posted by Daniel Berstein <daber at PAIR.COM>
Dec 05, 1998
-
Last edited Dec 06, 1998
>Can someone help me make a FatBit editor I don't know how to go about doing
>this.
What is a FatBit?
Regards,
Daniel Berstein
daber at pair.com
4. Re: Fat Bit
- Posted by David Cuny <dcuny at LANSET.COM>
Dec 05, 1998
-
Last edited Dec 06, 1998
Albert Brauneis wrote:
>Can someone help me make a FatBit editor
Here's a program that shows off most of the features you need. I would have
done it in Win32Lib, but I haven't got filled rectangles working yet. When I
get them coded, I'll probably put together a cheezey paint program together
for Win32Lib...
The calculation for the position of the color spots are a bit magical, but
not that difficult to figure out. The rest of the code should be fairly
obvious.
Hope this helps!
-- David Cuny
-- fatbits demo
-- demonstrates hit testing
include graphics.e
include mouse.e
constant
BitWide = 16, -- size of bits on screen
BitmapX = 60, -- x position of bitmap
BitmapY = 10, -- y position of bitmap
SpotSize = 16 -- size of a color spot
-- holds the bitmap
sequence
bitmap, -- bitmap being edited
colorSpots -- list of rectangles holding colors
-- holds the current color
integer useColor
useColor = BLACK
procedure Rect( integer color, integer x1, integer y1,
integer x2, integer y2 )
-- draw a framed rectangle
-- hide the mouse
mouse_pointer(0)
-- draw a filled block
polygon( color, 1, { {x1,y1},
{x2,y1},
{x2,y2},
{x1,y2}} )
-- frame it
polygon( BLACK, 0, { {x1,y1},
{x2,y1},
{x2,y2},
{x1,y2}} )
-- show the mouse
mouse_pointer(1)
end procedure
procedure DrawFatBit( integer x, integer y )
-- draw a bitmap point on the screen
integer color
-- determine color
color = bitmap[y][x]
-- adjust onto screen
x = BitmapX + ((x - 1) * BitWide)
y = BitmapY + ((y - 1) * BitWide)
-- show bit
Rect( color, x, y, x+BitWide, y+BitWide )
end procedure
procedure DrawColorSpots()
-- draw the color spots
-- frame color is current color
sequence spot
-- frame the color spots
Rect( useColor, 5, 10, 50, 200 )
-- build the color pots
for i = 1 to length( colorSpots ) do
-- get a spot
spot = colorSpots[i]
-- put on window
Rect( i-1, spot[1], spot[2], spot[3], spot[4] )
end for
end procedure
procedure SetupScreen()
-- draw the screen and bitmap
integer x, y, color
sequence extent, vc, spot
-- get the window size
vc = video_config()
extent = { vc[VC_XPIXELS], vc[VC_YPIXELS] }
-- paint the window
Rect( CYAN, 0, 0, extent[1], extent[2] )
-- fill with bitmap
for i = 1 to length( bitmap ) do
for j = 1 to length( bitmap[1] ) do
-- draw it
DrawFatBit( i, j )
end for
end for
-- calcualate position of color spots
colorSpots = {}
x = 10
y = 3
for i = 1 to 16 do
-- position the spot
if i = 9 then
x = 30
y = 3
end if
-- offset the position
y = y + 20
-- build a rectangle
spot = { x, y, x+SpotSize, y+SpotSize }
-- add to list
colorSpots = append( colorSpots, spot )
end for
-- display the color spots
DrawColorSpots()
end procedure
function HitColorSpot( integer x, integer y )
-- checks if point falls in color spot
-- if it does, changes the current color and
-- redraws palette to show indicated color
for i = 1 to length( colorSpots ) do
-- in spot?
if x >= colorSpots[i][1]
and y >= colorSpots[i][2]
and x <= colorSpots[i][3]
and y <= colorSpots[i][4] then
-- pick color
useColor = i-1
-- update color spots
DrawColorSpots()
-- indicate a color spot was hit
return 1
end if
end for
-- indicate no color spots were hit
return 0
end function
function HitBitmap( integer x, integer y )
-- test to see if point falls in bitmap
-- if it does, update the pixel
integer bmpX, bmpY
-- convert to a position the the bitmap
bmpX = (floor((x-BitmapX)/BitWide)+1)
bmpY = (floor((y-BitmapY)/BitWide)+1)
-- point falls in bitmap?
if bmpY > 0
and bmpY <= length( bitmap )
and bmpX > 0
and bmpX <= length( bitmap[1] ) then
-- set the color
bitmap[bmpY][bmpX] = useColor
-- show the bit
DrawFatBit( bmpX, bmpY )
-- indicate the bitmap was hit
return 1
else
-- indicate the bitmap was missed
return 0
end if
end function
function FatBits( sequence bmp )
-- edit bitmap in "fatbits" mode
integer x, y, bmpX, bmpY, color
object mouse
-- save as global
bitmap = bmp
-- draw the color spots and bitmap
SetupScreen()
-- show mouse
mouse_pointer(1)
-- until the esc key is pressed...
while get_key() != 27 do
-- poll the mouse
mouse = get_mouse()
if sequence( mouse ) then
-- clicked?
if and_bits( LEFT_DOWN, mouse[1] ) then
-- get mouse position
x = mouse[2]
y = mouse[3]
-- what did the mouse hit?
if HitColorSpot( x, y ) then
-- hit a color spot
elsif HitBitmap( x, y ) then
-- hit a bitmap point
else
-- nothing hit
end if
end if
end if
end while
-- hide mouse
mouse_pointer(0)
return bitmap
end function
-- demonstrate the code
integer result
sequence s
-- set graphics mode
result = graphics_mode( 18 )
-- create a bitmap
s = repeat( repeat( WHITE, 8 ), 8 )
-- edit it
s = FatBits( s )
-- restore normal mode
result = graphics_mode( -1 )