コード例 #1
0
ファイル: wormhole.c プロジェクト: davehorner/XScreenSaverWin
static void addStar( wormhole * worm )
{

	starline * star_new;
	starline ** xstars;
	int old_stars;
	int q;
	int ang;
	star_new = (starline *)malloc( sizeof( starline ) );
	ang = rnd( 360 );
	initStar( &star_new->begin, worm->max_Z, ang, worm );
	initStar( &star_new->end, worm->max_Z+rnd(6)+4, ang, worm );

	for ( q = 0; q < worm->num_stars; q++ ){
		if ( worm->stars[q] == NULL ){
			worm->stars[q] = star_new;
			return;
		}
	}

	old_stars = worm->num_stars;
	worm->num_stars = worm->num_stars << 1;
	xstars = (starline **)malloc( sizeof(starline *) * worm->num_stars );
	for ( q = 0; q < worm->num_stars; q++ )
		xstars[q] = NULL;

	for ( q = 0; q < old_stars; q++ )
		if ( worm->stars[q] != NULL ) xstars[q] = worm->stars[q];
	free( worm->stars );
	worm->stars = xstars;

	worm->stars[ old_stars ] = star_new;

}
コード例 #2
0
ファイル: core.c プロジェクト: Zugamifk/asteroids-mp
// Game initialization function
// ==========================================================
void init(void) {

	// init random seed
	unsigned int seed = time(NULL);
	srand(seed);
	
	// Init asteroid object array
	asteroids = (object *)malloc(sizeof(object)*MAXASTEROIDS);
	int i;
	for(i=0;i<MAXASTEROIDS;i++) {

		// Create an asteroid at a random location on screen
		vector p = makeVec(10.0-(float)(rand()%25), 10.0-(float)(rand()%25));
		initAsteroid(asteroids+i, &p, 3.0);

		// If asteroid spawns too close to ship, make it somewhere else
		while(lengthVec(&(asteroids[i].pos)) < 5.0) {
			p = makeVec(10.0-(float)(rand()%25), 10.0-(float)(rand()%25));
			initAsteroid(asteroids+i, &p, 3.0);
		}

		// Activate 4 big asteroids at the beginning
		if (i%4!=0) asteroids[i].state &= !ASTEROID_ACTIVE;
		else asteroids[i].state |= ASTEROID_BIG;
	}

	// Init asteroid gibs (inactive)
	asteroidGibs = (object**)malloc(sizeof(object*)*MAXASTEROIDS);
	int ab;
	for (ab=0; ab<MAXASTEROIDS; ab++) {
		asteroidGibs[ab] = (object*)malloc(sizeof(object)*asteroids[ab].size);
		initGib(asteroidGibs[ab], asteroids+ab, 0);
	}
	
	// init ship
	ships = malloc(sizeof(object)*MAXSHIPS);
	for (i = 0; i < MAXSHIPS; i++) {
		initShip(ships+i);
	}
	myship = ships;
	myship->state = 0;
	
	// init ship stuff
	//initMissile();	

	// init ship gibs (inactive)
	shipGibs = (object*)malloc(sizeof(object)*ships[0].size*MAXSHIPS);	
	for (i=0; i < MAXSHIPS; i++) {
		initGib(shipGibs+i*ships[0].size, ships, 0);
	}
	
	// init stars
	stars = (object*)malloc(sizeof(object)*MAXSTARS);
	int si; for(si=0;si<MAXSTARS; si++) {
		vector v =  makeVec((float)(rand()%50)-25.0, (float)(rand()%50)-25.0);
		initStar(stars+si, &v);
	}

}	
コード例 #3
0
ファイル: stars.c プロジェクト: domaubert/EMMA
void addStar(struct CELL *cell, struct Wtype *init_field, int level, REAL xc, REAL yc, REAL zc, struct CPUINFO *cpu, REAL dttilde, struct RUNPARAMS *param, REAL aexp, int is,  int nstars, REAL mstar){
// ----------------------------------------------------------//
/// Add a stellar particle in the double linked list\n
/// Call the initialisation and the conservation functions
// ----------------------------------------------------------//

#ifdef PIC
	struct PART *star = cpu->freepart;

	if (star==NULL){
    printf("\n");
    printf("----------------------------\n");
    printf("No more memory for particles\n");
    printf("----------------------------\n");
	//	exit(0);
	}else{

		cpu->freepart = cpu->freepart->next;
		cpu->freepart->prev = NULL;

		if (cell->phead==NULL){
			cell->phead = star;
			star->prev = NULL;
			star->next =NULL;
		}else{
			struct PART *lasp = findlastpart(cell->phead);
			lasp->next = star;
			star->prev = lasp;
			star->next = NULL;
		}

		cpu->npart[level-1]++;
		cpu->nstar[level-1]++;

		REAL dx = POW(2.0,-level);

		initStar(init_field, star, param, level, xc, yc, zc, param->stars->n+nstars, aexp, is, dttilde, dx,mstar);

		conserveField(&cell->field   , param, star,  dx, aexp,mstar);
		conserveField(&cell->fieldnew, param, star,  dx, aexp,mstar);

		//printPart(star);
	}
#endif
}
コード例 #4
0
ファイル: MapFlag.cpp プロジェクト: KrisLee/KingdomRush
bool MapFlag::initWithLevel(int level)
{
	instance = GameManager::getInstance();
	setLevel(level);
	if (!Sprite::init())
	{
		return false;
	}
	switch (UserDefault::getInstance()->getIntegerForKey(String::createWithFormat(instance->LEVELX_STARNUM,getLevel())->getCString(),0))
	{
	case(0)://得星个数为0,为完成
		setType(0);
		flag = Sprite::createWithSpriteFrameName("mapFlag_0022.png");
		break;
	case(4)://得星个数为4
		setType(2);
		flag = Sprite::createWithSpriteFrameName("mapFlag_0112.png");
		break;
	case(5)://得星个数为5
		setType(3);
		wings = Sprite::createWithSpriteFrameName("mapFlag_wings_0015.png");
		addChild(wings);
		flag = Sprite::createWithSpriteFrameName("mapFlag_0112.png");
		break;
	default:
		setType(1);
		flag = Sprite::createWithSpriteFrameName("mapFlag_0094.png");
		break;
	}
	addChild(flag);
	initStar();
	addStar();
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(MapFlag::onTouchBegan, this);
	listener->onTouchEnded = CC_CALLBACK_2(MapFlag::onTouchEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,flag);
	
	return true;
}
コード例 #5
0
ファイル: main.c プロジェクト: mellowonpsx/SVDRV_as02
// function that init model
void initModel()
{
    // camera position
    startX=0;
    startY= 500.0;
    startZ= -500.0;
    // camera modifier
    deltaZMax = -(startZ/2.0);
    deltaZMin = -10000.0;
    // not used
    deltaXMax = -500.0;
    deltaXMin = +500.0;
    deltaYMax = -500.0;
    deltaYMin = +500.0;
    // end not used

    showLabels = 0; //false
    isRunning = 1; //true

    // it's for background stars effect
    initStar(&universe,"universe", 18000.0,0.0,0.0,0.0,1000000.0);
    setStarColor(&universe, 1.0, 1.0, 1.0);
    setStarLight(&universe, 0.0);
    initRotatingTexturedSphere(&universe.sphereModel, "../SVDRV_as02/image/universemap.jpg", GL_RGB);

    // add a star in this case sun
    // i make the sun really small cause i can't respect proportion
    // diam = 1391000km
    // tr = 27d 6h = ~650h (?)
    initStar(&sun,"SUN", 139.1000,0.0,0.0,0.0,650);
    setStarColor(&sun, 1.0, 1.0, 1.0);
    setStarLight(&sun, 1.0);
    initRotatingTexturedSphere(&sun.sphereModel, "../SVDRV_as02/image/sun.jpg", GL_RGB);

    // planet data from wikipedia, not really checked eventual error

    // add a planet in this case earth
    // diam 12756km
    // tr 24 h
    // tR 365 g
    // orbit 6.1 UA
    initPlanet(&p1, "Earth", &sun, 127.56, 610,0.0,0.0,24,365);
    setPlanetColor(&p1, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p1.sphereModel, "../SVDRV_as02/image/earthmap1k.jpg", GL_RGB);

    // add a planet in this case Mercury
    // diam 4879km
    // tr 58g
    // tR 88g
    // orbit 4.5 UA
    initPlanet(&p2, "Mercury", &sun, 48.79, 450,0.0,0.0,58*24,88);
    setPlanetColor(&p2, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p2.sphereModel, "../SVDRV_as02/image/mercurymap.jpg", GL_RGB);

    // add a planet in this case Venus
    // diam 12103km
    // tr 243g
    // tR 224g
    // orbit 2.4 UA
    initPlanet(&p3, "Venus", &sun, 12.103, 240,0.0,0.0,243*24,224);
    setPlanetColor(&p3, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p3.sphereModel, "../SVDRV_as02/image/venusmap.jpg", GL_RGB);

    // add a planet in this case Mars
    // diam 6804km
    // tr 24h
    // tR 687g
    // orbit 9.5 UA
    initPlanet(&p4, "Mars", &sun, 6.804, 950,0.0,0.0,24,687);
    setPlanetColor(&p4, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p4.sphereModel, "../SVDRV_as02/image/mars_1k_color.jpg", GL_RGB);

    // add a planet in this case Jupiter
    // diam 142984km
    // tr 10h
    // tR 4333g
    // orbit 32,67 UA
    initPlanet(&p5, "Jupiter", &sun, 142.984, 3267,0.0,0.0,9,4333);
    setPlanetColor(&p5, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p5.sphereModel, "../SVDRV_as02/image/jupitermap.jpg", GL_RGB);

    // add a planet in this case Saturn
    // diam 120536km
    // tr 11h
    // tR 10756g
    // orbit 59,9 UA
    initPlanet(&p6, "Saturn", &sun, 120.536, 5990,0.0,0.0,11,10756);
    setPlanetColor(&p6, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p6.sphereModel, "../SVDRV_as02/image/saturnmap.jpg", GL_RGB);

    // add a planet in this case Uranus
    // diam 51118km
    // tr 17h
    // tR 42718 d
    // orbit 120,5 UA
    initPlanet(&p7, "Uranus", &sun, 51.118, 12050,0.0,0.0,17,42718);
    setPlanetColor(&p7, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p7.sphereModel, "../SVDRV_as02/image/uranusmap.jpg", GL_RGB);

    // add a planet in this case Neptune
    // diam 49528km
    // tr 16h
    // tR 60233g
    // orbit 189 UA
    initPlanet(&p8, "Neptune", &sun, 49.528, 18900,0.0,0.0,16,60233);
    setPlanetColor(&p8, 0.0, 1.0, 1.0);
    initRotatingTexturedSphere(&p8.sphereModel, "../SVDRV_as02/image/neptunemap.jpg", GL_RGB);
}