S! // File sprite2.h
#ifndef __SPRITE__ #define __SPRITE_
#define MAX_STAGES 20
, #define MAX_H EIGHT 100
#define TRANSP_COLOR OxFF
class Sprite {
public:
int x, y; // location of upper-left corner
int width, height; // size of single image
int stageCount; // number of stages '
int curStage; // current stage
char * underlmage; // place to store image
// under the sprite
char * lineStart [MAX_STAGES*MAX_HEIGHT];
Sprite (int, int, char *, …); -Sprite ()

Компьютерная графика. Полигональные модели

{
free ( underlmage );
}
void set (int ax, int ay )
{
x = ax; y = ay;
}
void draw (); void storeUnder (); void restoreUnder ();
};
inline int min (int x, int y)
{
return x < y ? x : y;
}
inline int max (int x, int y ) {
return x > y ? x : y;
}
extern char far * videoAddr;
extern int screen Width;
extern int screenHeight;
extern int orgX;
extern int orgY;
#endif
SI // File sprite2.cpp
#include <alloc.h> #include <dos.h> #include Msprite2.h"
Sprite :: Sprite (int w, int h, char * im1,…) {
char ** imPtr = &im1;
x =0; y =0; width = w; height = h; curStage = 0;
underlmage = (char *) malloc ( width * height);
for (int lineCount = 0; * imPtr != NULL; imPtr ++ ) {
char * ptr = * imPtr;
for (int i = 0; i < height; i++ ) {
lineStart [lineCount] = ptr; for (int j = 0; j < width; j++ ).

4. Работа с основными графическими устройствам

{
int count = * ptr++;
// not transparent if (( count & 0x80 ) == 0 )
ptr += count & 0x7F;
j += count & 0x7F;
}
}
}
}
void Sprite :: draw () {
int x1 = max (0, x - orgX);
int x2 = min ( screenWidth, x - orgX + width );
if ( x2 < x1 )
return;
int y1 = max ( 0, y - orgY );
int y2 = min (screenHeight, y - orgY + height);
rf (y2 < y1 )
return;
char far * videoPtr = videoAddr + y1 * screenWidth + x1; int step = screenWidth - (x2 - x1);
for (register int y = y1; y < y2; y++, videoPtr += step ) {
char * dataPtr =tineStart [curStage*height+y1-y]; char far * videoPtr=videoAddr + y * screenWidth + x1;

⇐ Предыдущая| |Следующая ⇒