// Function creates the Board with specified size static board_p boardCreate(long seed, int width, int height) { board_p board = NULL; ASSERT(MINIMAL_SIZE <= width, "boardCreate"); ASSERT(MAXIMAL_SIZE >= width, "boardCreate"); ASSERT(MINIMAL_SIZE <= height, "boardCreate"); ASSERT(MAXIMAL_SIZE >= height, "boardCreate"); board = (board_p)objectCreate( sizeof(board_t), (destructor_f)boardDestroy); board->width = width; board->height = height; board->seed = seed; board->progress = 0x7; // empty, 2 and 4 board->goal = width * height * 3 / 4; if (board->goal > 11) board->goal = 11; boardGenerate(board); boardGenerate(board); board->state = State_Game; board->round = 1; board->score = 0; board->prev = NULL; return board; };
boat boatCreate(texture tex, point pos, velocity vel) { boat b; static double boatRadius = -1; if (boatRadius == -1) boatRadius = configGetValue("Radius", "Boat").real; b = objectCreate(TYPE_BOAT, 0, pos, vel, boatRadius, tex); AUTOMALLOC(b->extra); b->extra->accel = boatDefaults.accel; b->extra->life = boatDefaults.lives; b->extra->friction = boatDefaults.friction; b->extra->anchorMultiplier = boatDefaults.anchorMultiplier; b->extra->turnRate = boatDefaults.turnRate; b->extra->defaultTimeStuck = boatDefaults.timeStuck; b->extra->unloadTime = boatDefaults.unloadTime; b->extra->unloadDistance = boatDefaults.unloadDistance; b->extra->extraLifeScore = boatDefaults.extraLifeScore; b->extra->maxAnchorSpeed = boatDefaults.maxAnchorSpeed; b->extra->color = b->tex.color; b->extra->isAnchored = 0; b->extra->isTurning = 0; b->extra->isAccel = 0; b->extra->anchorButtonHeld = 0; b->extra->peopleHeld = 0; b->extra->points = 0; b->extra->unloadTimeLeft = b->extra->unloadTime; b->extra->timeStuckLeft = 0; b->extra->personList = NULL; b->extra->extraLivesCount = 1; b->extra->prevVel = vectorCreate(0,0); return b; }
LCObjectRef objectCreateFromContext(LCContextRef context, LCTypeRef type, char hash[HASH_LENGTH]) { LCObjectRef object = objectCreate(type, NULL); object->context = context; if (hash) { _objectSetHash(object, hash); } return object; }
ship shipCreate(point pos, texture tex) { static double shipRadius = -1; if (shipRadius == -1) shipRadius = configGetValue("Radius", "Ship").real; return objectCreate(TYPE_SHIP, 0, pos, vectorCreate(0, 0), shipRadius, tex); }
extern Object* objectAddCreate(int add) { Object *o; ObjectContext *c; o = objectCreate(&c, sizeof(ObjectContext), method, release); if (NULL != o) { c->add = add; } return o; }
// Function loads a resource with specified name resource_p resourceLoad(const char* name) { resource_p resource = NULL; MemHandle handle = NULL; ASSERT(NULL != name, "resourceLoad"); resource = resourceFind(name); if (NULL == resource) { handle = resourceOpen(name); if (NULL == handle) { THROW("resourceLoad", appErrResourceNotFound); } TRY { resource = (resource_p)objectCreate( sizeof(*resource), (destructor_f)resourceDestroy); resource->handle = handle; resource->memory = (const void*)MemHandleLock( handle); resource->size = MemHandleSize(handle); if (NULL != resourcesList) { resource->prev = NULL; resource->next = resourcesList; resourcesList->prev = resource; } resourcesList = resource; resource = resourceRetain(resource); } CATCH { MemHandleUnlock(handle); RETHROW(); } END; resource = resourceAutorelease(resource); }
// Function allocates and init a Game static game_p gameNew(engine_p engine, board_p board) { game_p game = NULL; context_p screen = NULL; int hd = 0; ASSERT(NULL != board, "gameNew"); game = (game_p)objectCreate( sizeof(game_t), (destructor_f)gameDestroy); game->board = boardRetain(board); screen = engineScreen(engine); game->width = contextWidth(screen); game->height = contextHeight(screen); game->padding = (game->width < game->height ? game->width : game->height) / 64; hd = engineHDSupported(engine); game->regular = fontRetain( fontLoad(hd ? fontNameRegularHD : fontNameRegularSD)); game->bold = fontRetain(fontLoad( hd ? fontNameBoldHD : fontNameBoldSD)); game->status_line = MAX(fontLine(game->regular), fontLine(game->bold)); game->images[0] = imageRetain( imageLoad(hd ? imageNameEmptyHD : imageNameEmptySD)); game->images[1] = imageRetain(imageLoad( hd ? imageName2HD : imageName2SD)); game->images[2] = imageRetain(imageLoad( hd ? imageName4HD : imageName4SD)); game->images[3] = imageRetain(imageLoad( hd ? imageName8HD : imageName8SD)); game->images[4] = imageRetain(imageLoad( hd ? imageName16HD : imageName16SD)); game->images[5] = imageRetain(imageLoad( hd ? imageName32HD : imageName32SD)); game->images[6] = imageRetain(imageLoad( hd ? imageName64HD : imageName64SD)); game->images[7] = imageRetain(imageLoad( hd ? imageName128HD : imageName128SD)); game->images[8] = imageRetain(imageLoad( hd ? imageName256HD : imageName256SD)); game->images[9] = imageRetain(imageLoad( hd ? imageName512HD : imageName512SD)); game->images[10] = imageRetain(imageLoad( hd ? imageName1024HD : imageName1024SD)); game->images[11] = imageRetain(imageLoad( hd ? imageName2048HD : imageName2048SD)); game->images[12] = imageRetain(imageLoad( hd ? imageName4096HD : imageName4096SD)); game->images[13] = imageRetain(imageLoad( hd ? imageName8192HD : imageName8192SD)); game->images[14] = imageRetain( imageLoad(hd ? imageName16384HD : imageName16384SD)); game->images[15] = imageRetain( imageLoad(hd ? imageName32768HD : imageName32768SD)); game->images[16] = imageRetain( imageLoad(hd ? imageName65536HD : imageName65536SD)); game->images[17] = imageRetain( imageLoad(hd ? imageName131072HD : imageName131072SD)); game->cell = MIN(imageWidth(game->images[0]), imageHeight(game->images[0])); game->board_back = rgbColor(0xBB, 0xAD, 0xA0); return game; };
tMenuOption playAnimation(int id) { /* Declare variables */ int imgCount, objCount, sndCount, i; animImage* img; animObject* obj; animSound* snd; titleImage* imgArray; titleObject* objArray; /*animSound* sndArray;*/ int imgsActive=0; int objsActive=0; /*int sndsActive=0;*/ int imgTotal, objTotal, sndTotal; tKey key=inputCreateKey(); tKey nullKey=inputCreateKey(); /* Initialize animation and allocate memory */ animStart(id,&imgTotal,&objTotal,&sndTotal); imgArray=(titleImage*)malloc(imgTotal*sizeof(titleImage)); objArray=(titleObject*)malloc(objTotal*sizeof(titleObject)); /*sndArray=(animSound*)malloc(sndTotal*sizeof(animSound));*/ /* main animation kernel loop */ while (animGetFrame(&imgCount,&objCount,&sndCount,&img,&obj,&snd)) { int reprocessInput=1; while(reprocessInput) { if (!inputGetEvent(&key)) { /* key pressed */ /* if there is an action and the action wasn't control key */ if (key.actionPerformed!=none && !(inputGetCtrl(key.status)&&key.actionPerformed==other)) return getAction(key); } else { reprocessInput=0; /* create new images/objects/sounds */ for (i=0;i<imgCount;i++) { /*images*/ imgArray[imgsActive].img=resLoad(img[i].res); if (!imgArray[imgsActive].img) { fprintf(stderr,"resource coudn't be loaded."); return menuQuit; } imgArray[imgsActive].y=img[i].y; imgArray[imgsActive].x=img[i].x; imgArray[imgsActive].layer=img[i].layer; imgArray[imgsActive].duration=img[i].duration; imgsActive++; } for (i=0;i<objCount;i++) { /*objects*/ objArray[objsActive].obj=objectCreate(obj[i].location,obj[i].floor,DIR_LEFT,obj[i].state,obj[i].res,obj[i].cacheMirror,oGeneric); objArray[objsActive].active=1; objArray[objsActive].duration=obj[i].duration; objsActive++; } /* TODO: code sounds * for (i=0;i<sndCount;i++) { sndArray[sndsActive]=snd[i]; sndsActive++; }*/ outputClearScreen(); /* The bottom layer */ for (i=0;i<imgsActive;i++) { if (imgArray[i].layer==ANIMS_LAYERTYPE_BOTTOM) outputDrawBitmap(imgArray[i].img->pFrames[0], imgArray[i].x, imgArray[i].y); } /* move objects */ for (i=0;i<objsActive;i++) { /*TODO: detect exits */ if (objArray[i].active) { int exitCode; exitCode=objectMove(&(objArray[i].obj),nullKey,NULL); if (objArray[i].duration) objArray[i].duration--; /* detect exited states and destroy them */ /* if the time is over or exit code detected */ if ((objArray[i].duration==1)||(exitCode<0)) { /*printf("exit Code detected: i=%d exit=%d \n",i,exitCode);*/ objectFree(&objArray[i].obj); objArray[i].active=0; /* remember it is destroyed */ } else { objectDraw(&objArray[i].obj); } } } /* The top layer */ for (i=0;i<imgsActive;i++) { if (imgArray[i].layer==ANIMS_LAYERTYPE_TOP) { outputDrawBitmap(imgArray[i].img->pFrames[0], imgArray[i].x, imgArray[i].y); } } outputUpdateScreen(); /* caducied backgrounds destruction */ i=imgsActive; while(i) { i--; if (imgArray[i].duration) { /* if not 0 (infinite) */ imgArray[i].duration--; if (!imgArray[i].duration) { /* time is over for this images */ imgsActive--; resFree(imgArray[i].img); imgArray[i]=imgArray[imgsActive]; } } } } } } for (i=0;i<objsActive;i++) if (objArray[i].active) objectFree(&objArray[i].obj); for (i=0;i<imgsActive;i++) resFree(imgArray[i].img); free(imgArray); free(objArray); /*free(sndArray);*/ return menuQuit; }