BOB (blitter
Object) engine
A
BOB is a graphical object that you can draw, move or animate. It supports sequence animation (blitting a series of different images to form motion). 8
& 16 bit color are supported.
// BOB functions
as defined in T3dlib
int Create_BOB(BOB_PTR
bob,int x, int y,int width, int height,int num_frames,int attr,
int mem_flags=0, USHORT color_key_value=0, int bpp=8);
int Clone_BOB(BOB_PTR
source, BOB_PTR dest);
int Destroy_BOB(BOB_PTR
bob);
int Draw_BOB(BOB_PTR
bob, LPDIRECTDRAWSURFACE7 dest);
int Draw_Scaled_BOB(BOB_PTR
bob, int swidth, int sheight,LPDIRECTDRAWSURFACE7 dest);
int Draw_BOB16(BOB_PTR bob,
LPDIRECTDRAWSURFACE7 dest);
int Draw_Scaled_BOB16(BOB_PTR bob, int swidth, int
sheight,LPDIRECTDRAWSURFACE7 dest);
int Load_Frame_BOB(BOB_PTR
bob, BITMAP_FILE_PTR bitmap, int frame, int cx,int cy,int
mode);
int Load_Frame_BOB16(BOB_PTR bob,
BITMAP_FILE_PTR bitmap, int frame, int cx,int cy,int
mode);
int Animate_BOB(BOB_PTR
bob);
int Move_BOB(BOB_PTR
bob);
int Load_Animation_BOB(BOB_PTR
bob, int anim_index, int num_frames, int *sequence);
int Set_Pos_BOB(BOB_PTR
bob, int x, int y);
int Set_Vel_BOB(BOB_PTR
bob,int xv, int yv);
int Set_Anim_Speed_BOB(BOB_PTR
bob,int speed);
int Set_Animation_BOB(BOB_PTR
bob, int anim_index);
int Hide_BOB(BOB_PTR
bob);
int Show_BOB(BOB_PTR
bob);
int Collision_BOBS(BOB_PTR
bob1, BOB_PTR bob2);
Functions
//
BOB functions
int Create_BOB(BOB_PTR bob, // ptr to BOB obj
int
x, int y, // loc of BOB
int width, int height, // size of BOB
int num_frames, // # frames (images)
int attr,
int mem_flags=0,
USHORT color_key_value=0,
int bpp=8);
Create
a BOB object.
Attributes:
|
Value |
Meaning |
|
BOB_ATTR_SINGLE_FRAME |
Single
image |
|
BOB_ATTR_MULTI_FRAME |
Animation
w/ n images, linear animation (0 – n-1) |
|
BOB_ATTR_MULTI_ANIM |
Animated
BOB |
|
BOB_ATTR_ANIM_ONE_SHOT |
Play
animation once then stop |
|
BOB_ATTR_BOUNCE |
Move_BOB will bounce off screen boundaries |
|
BOB_ATTR_WRAPAROUND |
Move_BOB will wrap screen boundaries to other
side |
EX:
BOB
mario;
If
(!Create_BOB(&mario, 10, 20, 50,
30, 6,
BOB_ATTR_MULTI_ANIM, 0, 0, 16)))
// error
To
delete and return memory:
int Destroy_BOB(&mario);
Drawing the object at its current location:
int Draw_BOB16(BOB_PTR bob, // obj ptr
LPDIRECTDRAWSURFACE7 dest); //
destination surface
mario.curr_frame = 3; // draw frame 3
Draw_BOB16(mario, lpddSurfdest);
Similarly,
Draw_Scaled_BOB16 works the same
except you can change the size.
int Draw_Scaled_BOB16 (BOB_PTR bob, int swidth,
int sheight,LPDIRECTDRAWSURFACE7 dest);
Loading a cell
int Load_Frame_BOB16(BOB_PTR bob,
BITMAP_FILE_PTR bitmap, // ptr to image
int frame, // frame #
in animation seq
int cx,int cy, // cell position of top/left
int mode); // scan mode
loads a portion (cell) of a memory resident bmp into
the object
To
load an animated sequence:
int Load_Animation_BOB(BOB_PTR bob,
int
anim_index, // animation sequence # 0 - 15
int num_frames, // # of frames in animation
int *sequence); // array holding sequence
this allows you to select a subset of frames to be
player to perform an action.
Ex:
int marioJump[]
= {0, 1, 3, 1, 0}; // animation #3
Load_Animation_BOB(&Mario, 3, 5, marioJump);
To
position the object to location (x, y):
int
Set_Pos_BOB(BOB_PTR
bob, int x, int y);
To
set the velocity of the object (used by Move_BOB)
int
Set_Vel_BOB(BOB_PTR
bob, int dx, int dy);
To
set animation speed (used by Animate_BOB)
int
Set_Anim_Speed_BOB(BOB_PTR
bob, int speed);
where 0 is the fastest and higher values slow it down
To
select an animation to play:
int
Set_Animation_BOB(BOB_PTR
bob, int anim_index);
anim_index is a sequence created
by Load_Animation_BOB.
Moving
int
Animate_BOB(BOB_PTR
bob);
Plays the animation sequence. Normally
called once per frame.
int
Move_BOB(BOB_PTR
bob);
Moves
the object by dx, dy
int
Hide_BOB(BOB_PTR
bob); // dah!
Set
flag to invisible so Draw_BOB doesn’t draw it
int
Show_BOB(BOB_PTR
bob); // daaaah!
int
Collision_BOBS(BOB_PTR
bob1, BOB_PTR bob2);
checks for a collision of two BOBs
(bounding box method)