예제 #1
0
void displayHUD(Object * ship, SDL_Texture * font, uint32_t timer)
{
    Object * temp;
    char buffer[BUFFER_SIZE] = {0};
    int previous = 0;
    SDL_Rect bar;

    /* Set the HUD bar */
    bar.x = 0;
    bar.y = 0;
    bar.w = Global->screenWidth;
    bar.h = Global->screenTop;

    setWindowColor(0, 51, 102, 0xFF);
    SDL_RenderFillRect(Global->renderer, &bar);
    setWindowColor(0x0, 0x0, 0x0, 0xFF);

    /* Display score text */
    strncpy(buffer, "Score", BUFFER_SIZE);
    temp = createTextObject(font, buffer, FONT_LARGE, 1.0);

    positionTextObject(temp, 0, 0);

    /* Display score number */
    previous = (temp->x + ((countObjects(temp) + 5 - snprintf(buffer, BUFFER_SIZE, "%d", score)) * temp->clip.w * 0.5 * temp->scale));
    freeObjects(temp);
    temp = createTextObject(font, buffer, FONT_LARGE, 1.0);

    positionTextObject(temp, previous, 0);

    /* Display lives text */
    previous += getTextObjectLength(temp, 5);
    freeObjects(temp);
    strncpy(buffer, "Lives", BUFFER_SIZE);
    temp = createTextObject(font, buffer, FONT_LARGE, 1.0);

    positionTextObject(temp, previous, 0);

    /* Display lives number */
    previous = (temp->x + ((countObjects(temp) + 3 - snprintf(buffer, BUFFER_SIZE, "%d", ship->lives)) * temp->clip.w * 0.5 * temp->scale));
    freeObjects(temp);
    temp = createTextObject(font, buffer, FONT_LARGE, 1.0);

    positionTextObject(temp, previous, 0);    
    freeObjects(temp);

    /* Display Timer */
    snprintf(buffer, BUFFER_SIZE, "%d", timer);
    temp = createTextObject(font, buffer, FONT_LARGE, 1.0);

    positionTextObject(temp, ((Global->screenWidth - (countObjects(temp) * temp->clip.w))), 0);
    freeObjects(temp);
}
예제 #2
0
파일: HashTable.cpp 프로젝트: BigEd/Cores
	/* -----------------------------------------------------------------------------
	      Prints a table.
	   Returns:
	      (int) 1 if table is output as requested
	            0 if memory for sorted table could not be allocated.
	----------------------------------------------------------------------------- */
	bool HashTable::printSorted(FILE *fp) const
	{
		ListObject **OutTab;
		ListObject *obj;
		int i;
		int cnt = countObjects();
		
		OutTab = getLinearList();
		if (OutTab==NULL)
			return false;
			
		sort(OutTab);
		printHeading(fp);
		for (i = 0; i < cnt; i++) {
			obj = OutTab[i];
			fprintf(fp, "%3d ", i);
			if (obj)
				obj->print(fp);
			else
				fputs("????", fp);
			fputs("\n",fp);
		}
		delete[] OutTab;
		return true;
	}
예제 #3
0
파일: HashTable.cpp 프로젝트: BigEd/Cores
	void HashTable::sort(ListObject **base) const
	{
		int i,j,gap;
		ListObject *p1, *p2;
		int cnt = countObjects();

		if (cnt==1) return;
		for (gap = 1; gap <= cnt; gap = 3 * gap + 1);
		
		for (gap /= 3; gap > 0; gap /= 3)
			for (i = gap; i < cnt; i++)
				for (j = i - gap; j >= 0; j -= gap) {
					p1 = base[j];
					p2 = base[j+gap];
					
					if(p1==NULL||p2==NULL)
						break;
					if (p1->cmp(p2) <= 0)
						break;

					base[j] = p2;
					base[j+gap] = p1;
				}
	}
예제 #4
0
파일: Room.cpp 프로젝트: ronw23/prime-osx
void
shMapLevel::mundaneRoom (int sx, int sy, int ex, int ey)
{
    int i, npiles, n;
    int x, y;

    if (mDLevel != TOWNLEVEL) {
        if (RNG (mDLevel + 6) > 9) {
            darkRoom (sx, sy, ex, ey);
        }

        if (!RNG (30)) {
            /* Radioactive room. */
            for (x = sx + 1; x < ex; x++) {
                for (y = sy + 1; y < ey; y++) {
                    mSquares[x][y].mFlags |= shSquare::kRadioactive;
                }
            }
        }
    }

    /* treasure expectation per room:
       version 0.3:
         0.375 piles x 1.1875 obj per pile +
         (~) 0.125 niches x 0.8 obj per niche
         ~ .5453125 objs per room

       version 0.2.9:
         0.375 piles x 1.375 obj per pile
         = .515625 obj per room
   */

    npiles = RNG (4) ? 0 : RNG (2) + RNG (2) + RNG (2);

    while (npiles--) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor)  and !isObstacle (x, y)) {
            n = RNG (10) ? 1 : RNG (2, 3);
            for (i = 0; i < n; i++) {
                putObject (generateObject (mDLevel), x, y);
            }
        }
    }

    if (0 == RNG (9)) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor) and !isObstacle (x, y) and
            0 == countObjects (x, y))
        {
            addVat (x, y);
        }
    }

    /* Reticulans of PRIME are weak enough to get instakilled in a pit.
       Do not place traps at all on first level. */
    while (!RNG (12) and mDLevel > 1) {
        x = RNG (sx + 1, ex - 1);
        y = RNG (sy + 1, ey - 1);
        if (TESTSQ (x, y, kFloor) and !isObstacle (x, y) and
            !getFeature (x, y))
        {
            shFeature::Type ttype;
        retrap:
            /* I'm using this retrap label because putting a for or while
               loop here uncovers a bug in g++! */
            /* FIXME: Probably the bug is long gone.  Get rid of goto. */
                ttype = (shFeature::Type) RNG (shFeature::kPit,
                                              shFeature::kPortal);
                switch (ttype) {
                case shFeature::kPit:
                case shFeature::kTrapDoor:
                    break;
                case shFeature::kAcidPit:
                    if (mDLevel < 7) goto retrap;
                    break;
                case shFeature::kHole:
                    if (RNG (5)) goto retrap;
                    break;
                case shFeature::kWeb:
                    goto retrap;
                case shFeature::kRadTrap:
                    if (mDLevel < 5) goto retrap;
                    break;
                case shFeature::kPortal:
                default: /* these traps are unimplemented */
                    goto retrap;
                }

            addTrap (x, y, ttype);
        }
    }
}