Sprite_T *CreateBasicSprite(const char *filename, Vec2i frame_size) { int x, y; int frames_per_row; Rect r; Sprite_T *s = NewSprite(); SDL_Surface *surf; if((surf = IMG_Load(filename)) == NULL) { printf("CreateBasicSprite(): %s failed to load!", filename); return NULL; } //SDL_InvertSurface(surf); r.w = (GLfloat)frame_size.x / (GLfloat)surf->w; r.h = (GLfloat)frame_size.y / (GLfloat)surf->h; s->numFrames = 0; frames_per_row = surf->w / frame_size.x; for(y = 0;y < surf->h / frame_size.y;y++) for(x = 0;x < surf->w / frame_size.x;x++) { r.x = x * r.w; r.y = 1.0f - (y+1) * r.h; s->frames[x+y*frames_per_row] = r; s->numFrames++; } s->numAnimations = 0; s->texId = SurfaceToTexture(surf); return s; }
SimSprite * MakeNewSprite(int type, int x, int y) { SimSprite *sprite; sprite = NewSprite("", type, x, y); return sprite; }
/** * Creates and sets up the hero entity * @return The hero entity created */ Entity_T *SetupHero() { int i, x; const GLfloat SPRITE_WIDTH = 32.0f / 128; const GLfloat SPRITE_HEIGHT = 48.0f / 192; Rect frames[20]; Animation_T animations[MAX_ANIMATIONS]; Entity_T *e = NewEntity(); e->currentAnimation = 0; e->currentFrame = 0; e->sprite = NewSprite(); e->body = cpBodyNew(100.0f, 100.0f); e->size.x = TILE_WIDTH; e->size.y = 1.5f * TILE_HEIGHT; e->shape = cpBoxShapeNew(e->body, e->size.x/2, e->size.y/2); for(i = 0;i < 20;i++) { frames[i].x = (i % 4) * SPRITE_WIDTH; frames[i].y = 1.0f - (i/4+1) * SPRITE_HEIGHT; frames[i].w = SPRITE_WIDTH; frames[i].h = SPRITE_HEIGHT; } for(x = 0;x < 4;x++) { animations[x].numFrames = 1; animations[x].frames[0] = x*4; animations[x].frameLengths[0] = 100; animations[x].flags = ANIMFLAG_NONE; } for(x = 4;x < 8;x++){ animations[x].numFrames = 4; for(i = 0;i < 4;i++){ animations[x].frames[i] = (x-4)*4+i; animations[x].frameLengths[i] = 100; } animations[x].flags = ANIMFLAG_NONE; } SetupSprite(e->sprite, "hero.png", frames, 20, animations, 8); //Set up the hero's inner light e->light = NewLight(); e->light->brightness = 0.75f; e->light->color.x = 1.0f; e->light->color.y = .95f; e->light->color.z = 0.5f; e->light->span = TILE_WIDTH / 2; e->light->offset.x = TILE_WIDTH / 2; e->light->offset.y = 0; SET_FLAG(e->flags, ENTFLAG_LIGHT); e->next = NULL; return e; }
SimSprite * MakeSprite(int type, int x, int y) { SimSprite *sprite; if ((sprite = GlobalSprites[type]) == NULL) { sprite = NewSprite("", type, x, y); } else { InitSprite(sprite, x, y); } return sprite; }
Entity_T *SetupMonster(int monster) { int i, x; const GLfloat SPRITE_WIDTH = 32.0f / 128; const GLfloat SPRITE_HEIGHT = 48.0f / 192; Rect frames[20]; Animation_T animations[MAX_ANIMATIONS]; Entity_T *e = NewEntity(); e->currentAnimation = 0; e->currentFrame = 0; e->sprite = NewSprite(); e->body = cpBodyNew(1.0f, 1.0f); e->size.x = 3* TILE_WIDTH; e->size.y = 3 * 1.5f * TILE_HEIGHT; e->shape = cpBoxShapeNew(e->body, e->size.x/2, e->size.y/2); for(i = 0;i < 20;i++) { frames[i].x = (i % 4) * SPRITE_WIDTH; frames[i].y = 1.0f - (i/4+1) * SPRITE_HEIGHT; frames[i].w = SPRITE_WIDTH; frames[i].h = SPRITE_HEIGHT; } for(x = 0;x < 4;x++) { animations[x].numFrames = 1; animations[x].frames[0] = x*4; animations[x].frameLengths[0] = 100; animations[x].flags = ANIMFLAG_NONE; } for(x = 4;x < 8;x++){ animations[x].numFrames = 4; for(i = 0;i < 4;i++){ animations[x].frames[i] = (x-4)*4+i; animations[x].frameLengths[i] = 100; } animations[x].flags = ANIMFLAG_NONE; } //TODO: Kludgy as heck, redo later. switch(monster){ case 0: SetupSprite(e->sprite, "monster0.png", frames, 20, animations, 8); break; case 1: SetupSprite(e->sprite, "monster1.png", frames, 20, animations, 8); break; } return e; }
//========================================================================== // // // //========================================================================== void HWDrawList::SortSpriteIntoPlane(SortNode * head, SortNode * sort) { HWFlat * fh = flats[drawitems[head->itemindex].index]; HWSprite * ss = sprites[drawitems[sort->itemindex].index]; bool ceiling = fh->z > SortZ; auto hiz = ss->z1 > ss->z2 ? ss->z1 : ss->z2; auto loz = ss->z1 < ss->z2 ? ss->z1 : ss->z2; if ((hiz > fh->z && loz < fh->z) || ss->modelframe) { // We have to split this sprite HWSprite *s = NewSprite(); *s = *ss; // Splitting is done in the shader with clip planes, if available. // The fallback here only really works for non-y-billboarded sprites. if (screen->hwcaps & RFL_NO_CLIP_PLANES) { float newtexv = ss->vt + ((ss->vb - ss->vt) / (ss->z2 - ss->z1))*(fh->z - ss->z1); if (!ceiling) { ss->z1 = s->z2 = fh->z; ss->vt = s->vb = newtexv; } else { s->z1 = ss->z2 = fh->z; s->vt = ss->vb = newtexv; } } SortNode * sort2 = SortNodes.GetNew(); memset(sort2, 0, sizeof(SortNode)); sort2->itemindex = drawitems.Size() - 1; head->AddToLeft(sort); head->AddToRight(sort2); } else if ((ss->z2<fh->z && !ceiling) || (ss->z1>fh->z && ceiling)) // completely on the left side { head->AddToLeft(sort); } else { head->AddToRight(sort); } }
static void Load() { screen = NewBitmap(WIDTH, HEIGHT, DEPTH, FALSE); cp = NewCopList(100); nullspr = NewSprite(0, FALSE); pointer = CloneSystemPointer(); CopInit(cp); CopMakePlayfield(cp, NULL, screen, DEPTH); CopMakeDispWin(cp, X(0), Y(0), WIDTH, HEIGHT); CopMakeSprites(cp, sprptr, nullspr); CopEnd(cp); CopInsSet32(sprptr[0], pointer->data); UpdateSpritePos(pointer, X(0), Y(0)); }
Entity_T *SetupObject(int object) { int i, x; const GLfloat SPRITE_WIDTH = 32.0f / 128; const GLfloat SPRITE_HEIGHT = 48.0f / 192; Rect frames[20]; Animation_T animations[MAX_ANIMATIONS]; Entity_T *e = NewEntity(); e->currentAnimation = 0; e->currentFrame = 0; e->sprite = NewSprite(); e->body = cpBodyNew(1.0f, 1.0f); e->size.x = TILE_WIDTH; e->size.y = 1.5f * TILE_HEIGHT; e->shape = cpBoxShapeNew(e->body, e->size.x/2, e->size.y/2); frames[0].x = 0; frames[0].y = 0; frames[0].w = 1; frames[0].h = 1; animations[0].numFrames = 1; animations[0].frames[0] = 0; animations[0].frameLengths[0] = 100; animations[0].flags = ANIMFLAG_NONE; //TODO: Kludgy as heck, redo later. switch(object){ case 0: SetupSprite(e->sprite, "torch.png", frames, 1, animations, 1); e->light = NewLight(); e->light->color.x = 1.0f; e->light->color.y = 0.0f; e->light->color.z = 1.0f; e->light->brightness = 0.75f; e->light->span = TILE_WIDTH * .75f; e->light->offset.x = TILE_WIDTH / 2; e->light->offset.y = 0; SET_FLAG(e->flags, ENTFLAG_LIGHT); e->currentAnimation = 0; e->currentFrame = 0; e->dir = ENTDIR_DOWN; break; } return e; }
int SpriteCmd(CLIENT_ARGS) { SimSprite *sprite; int type; if ((argc != 3) || (Tcl_GetInt(interp, argv[2], &type) != TCL_OK) || (type < 1) || (type >= OBJN)) { return TCL_ERROR; } sprite = NewSprite(argv[1], type, 0, 0); sprite->frame = 0; Tcl_CreateCommand(interp, sprite->name, DoSpriteCmd, (ClientData) sprite, (void (*)()) NULL); interp->result = sprite->name; return TCL_OK; }
static void Load() { screen = NewBitmap(320, 256, 1, FALSE); bitmap = LoadILBM("data/sprites4.ilbm", TRUE); cp = NewCopList(100); CopInit(cp); CopMakePlayfield(cp, NULL, screen, screen->depth); CopMakeDispWin(cp, X(0), Y(0), screen->width, screen->height); CopLoadPal(cp, bitmap->palette, 16); CopMakeSprites(cp, sprptr, nullspr); CopEnd(cp); sprite[0] = NewSpriteFromBitmap(19, bitmap, 0, 0); sprite[1] = NewSpriteFromBitmap(24, bitmap, 0, 19); sprite[2] = NewSpriteFromBitmap(42, bitmap, 0, 43); UpdateSpritePos(sprite[0], X(0), Y(113)); UpdateSpritePos(sprite[1], X(0), Y(110)); UpdateSpritePos(sprite[2], X(0), Y(101)); nullspr = NewSprite(0, FALSE); }
void HWDrawList::SortSpriteIntoWall(HWDrawInfo *di, SortNode * head,SortNode * sort) { HWWall *wh= walls[drawitems[head->itemindex].index]; HWSprite * ss= sprites[drawitems[sort->itemindex].index]; float v1 = wh->PointOnSide(ss->x1, ss->y1); float v2 = wh->PointOnSide(ss->x2, ss->y2); if (fabs(v1)<MIN_EQ && fabs(v2)<MIN_EQ) { if (wh->type==RENDERWALL_FOGBOUNDARY) { head->AddToLeft(sort); } else { head->AddToEqual(sort); } } else if (v1<MIN_EQ && v2<MIN_EQ) { head->AddToLeft(sort); } else if (v1>-MIN_EQ && v2>-MIN_EQ) { head->AddToRight(sort); } else { const bool drawWithXYBillboard = ((ss->particle && gl_billboard_particles) || (!(ss->actor && ss->actor->renderflags & RF_FORCEYBILLBOARD) && (gl_billboard_mode == 1 || (ss->actor && ss->actor->renderflags & RF_FORCEXYBILLBOARD)))); const bool drawBillboardFacingCamera = gl_billboard_faces_camera; // [Nash] has +ROLLSPRITE const bool rotated = (ss->actor != nullptr && ss->actor->renderflags & (RF_ROLLSPRITE | RF_WALLSPRITE | RF_FLATSPRITE)); // cannot sort them at the moment. This requires more complex splitting. if (drawWithXYBillboard || drawBillboardFacingCamera || rotated) { float v1 = wh->PointOnSide(ss->x, ss->y); if (v1 < 0) { head->AddToLeft(sort); } else { head->AddToRight(sort); } return; } double r=CalcIntersectionVertex(ss, wh); float ix=(float)(ss->x1 + r * (ss->x2-ss->x1)); float iy=(float)(ss->y1 + r * (ss->y2-ss->y1)); float iu=(float)(ss->ul + r * (ss->ur-ss->ul)); HWSprite *s = NewSprite(); *s = *ss; s->x1=ss->x2=ix; s->y1=ss->y2=iy; s->ul=ss->ur=iu; SortNode * sort2=SortNodes.GetNew(); memset(sort2,0,sizeof(SortNode)); sort2->itemindex=drawitems.Size()-1; if (v1>0) { head->AddToLeft(sort2); head->AddToRight(sort); } else { head->AddToLeft(sort); head->AddToRight(sort2); } if (screen->BuffersArePersistent()) { s->vertexindex = ss->vertexindex = -1; } else { s->CreateVertices(di); ss->CreateVertices(di); } } }
void CreateSprites (void) { long lIndex; PicHandle hpicImage; OSErr nErr; RGBColor rgbcKeyColor; SetRect(&gDestRects[0], 132, 132, 132 + kSpaceShipWidth, 132 + kSpaceShipHeight); SetRect(&gDestRects[1], 50, 50, 50 + kSpaceShipWidth, 50 + kSpaceShipHeight); SetRect(&gDestRects[2], 100, 100, 100 + kSpaceShipWidth, 100 + kSpaceShipHeight); SetRect(&gDestRects[3], 130, 130, 130 + kSpaceShipWidth, 130 + kSpaceShipHeight); gDeltas[0].h = -3; gDeltas[0].v = 0; gDeltas[1].h = -5; gDeltas[1].v = 3; gDeltas[2].h = 4; gDeltas[2].v = -6; gDeltas[3].h = 6; gDeltas[3].v = 4; gCurrentImages[0] = 0; gCurrentImages[1] = kNumSpaceShipImages / 4; gCurrentImages[2] = kNumSpaceShipImages / 2; gCurrentImages[3] = kNumSpaceShipImages * 4 / 3; rgbcKeyColor.red = 0; rgbcKeyColor.green = 0; rgbcKeyColor.blue = 0; // recompress PICT images to make them transparent for (lIndex = 0; lIndex < kNumSpaceShipImages; lIndex++) { hpicImage = (PicHandle)GetPicture(lIndex + kFirstSpaceShipPictID); DetachResource((Handle)hpicImage); nErr = RecompressPictureWithTransparency(hpicImage, &rgbcKeyColor, nil, &gImageDescriptions[lIndex], &gCompressedPictures[lIndex]); KillPicture(hpicImage); } // create the sprites for the sprite world for (lIndex = 0; lIndex < kNumSprites; lIndex++) { MatrixRecord matrix; SetIdentityMatrix(&matrix); matrix.matrix[2][0] = ((long)gDestRects[lIndex].left << 16); matrix.matrix[2][1] = ((long)gDestRects[lIndex].top << 16); nErr = NewSprite(&(gSprites[lIndex]), /* on return, the ID of the new sprite */ gSpriteWorld, /* the sprite world for this sprite */ gImageDescriptions[lIndex], /* image description of the spriteÕs image. */ *gCompressedPictures[lIndex], /* sprite image data */ &matrix, /* sprite matrix */ true, /* is sprite visible? */ lIndex); /* sprite layer */ } }