void CharSelectScreen::createCharCoins(int num) { for(int i=1; i<=num; i++) { CharCoin*a = new CharCoin(this,i); int space = View::getScalingWidth()/(num); addToGrid(a,25+(space/10),500,num,1,space,0,i); coinPoints[i-1].x=(int)a->x; coinPoints[i-1].y=(int)a->y; a->setScale(1.4f); charCoins.add(a); } }
static void fillWorld(void) { double ws = world.worldSize; for (int i = 0; i < world.numParticles; i++) { Particle *p = &world.particles[i]; p->pos = (Vec3) {0, 0, 0}; addToGrid(p); do { p->pos.x = ws * (rand01() - 1/2.0); p->pos.y = ws * (rand01() - 1/2.0); if (!world.twoDimensional) p->pos.z = ws * (rand01() - 1/2.0); reboxParticle(p); } while (collides(p)); } }
void CharSelectScreen::newCharIcon(int num, String anim) { CharIcon*a = new CharIcon(num, 0,0, new Animation("normal",1,anim)); addToGrid(a,70,115,9,5,95,65,charIcons.size()+1); if(charIcons.size()==0) { charSelectArea->x = a->x - (a->width/2); charSelectArea->y = a->y - (a->height/2); } float csW = (a->x + (a->width/2)) - charSelectArea->x; float csH = (a->y + (a->height/2)) - charSelectArea->y; if(csW>charSelectArea->width) { charSelectArea->width = (int)csW; } if(csH>charSelectArea->height) { charSelectArea->height = (int)csH; } WireframeActor*a2 = new WireframeActor(a->x-20,a->y-20,40,40); charIconPoints.add(a2); charIcons.add(a); }
void CharSelectScreen::createCards(ArrayList<int> type) { int total = type.size(); if(charSelectArea!=null) { delete charSelectArea; charSelectArea = null; } if(coinPoints!=null) { delete[] coinPoints; coinPoints = null; } if(cardTypes!=null) { delete[] cardTypes; cardTypes = null; } if(cardAvailable!=null) { delete[] cardAvailable; cardAvailable = null; } for(int i=0; i<charCards.size(); i++) { delete charCards.get(i); delete charPreviews.get(i); delete charNames.get(i); } charCards.clear(); charPreviews.clear(); charNames.clear(); cardAvailable = new boolean[type.size()]; cardTypes = new byte[type.size()]; coinPoints = new Vector2i[type.size()]; charSelectArea = new WireframeActor(); //CharSelectArea->setVisible(true); int space = View::getScalingWidth()/(total); for(int i=1; i<=total; i++) { Global::CPU[i-1]=false; cardAvailable[i-1]=false; cardTypes[i-1] = (byte)type.get(i-1); Actor*a = setUpCard(i,type.get(i-1)); a->setScale(1.65f); Actor*a2 = new Actor(0,0); TextActor*a3 = new TextActor(" ", AssetManager::getFont("Fonts/arial.ttf", Font::BOLD, 12), Color::WHITE); a3->setAlignment(TextActor::ALIGN_CENTER); addToGrid(a,100+(space/10),500,type.size(),1,space,0,i); a2->x = a->x; a2->y = a->y - 10; a3->x = a->x - 5; a3->y = a->y + 43; charCards.add(a); charPreviews.add(a2); charNames.add(a3); addCardAnimations(i); loadCharPreviews(i); } createCharCoins(total); }
InstanceObject *GameWorld::createInstance(const uint16_t id, const glm::vec3& pos, const glm::quat& rot) { auto oi = data->findObjectType<ObjectData>(id); if( oi ) { std::string modelname = oi->modelName; std::string texturename = oi->textureName; std::transform(std::begin(modelname), std::end(modelname), std::begin(modelname), tolower); std::transform(std::begin(texturename), std::end(texturename), std::begin(texturename), tolower); // Ensure the relevant data is loaded. if(! oi->modelName.empty()) { if( modelname != "null" ) { data->loadDFF(modelname + ".dff", false); } } if(! texturename.empty()) { data->loadTXD(texturename + ".txd", true); } ModelRef m = data->models[modelname]; // Check for dynamic data. auto dyit = data->dynamicObjectData.find(oi->modelName); std::shared_ptr<DynamicObjectData> dydata; if( dyit != data->dynamicObjectData.end() ) { dydata = dyit->second; } if( modelname.empty() ) { logger->warning("World", "Instance with missing model: " + std::to_string(id)); } auto instance = new InstanceObject( this, pos, rot, m, glm::vec3(1.f, 1.f, 1.f), oi, nullptr, dydata ); instancePool.insert(instance); allObjects.push_back(instance); if( shouldBeOnGrid(instance) ) { addToGrid( instance ); } modelInstances.insert({ oi->modelName, instance }); return instance; } return nullptr; }
/* ============================================================================= * maze_read * -- Return number of path to route * ============================================================================= */ long maze_read (maze_t* mazePtr, char* inputFileName) { FILE* inputFile = fopen(inputFileName, "rt"); if (!inputFile) { fprintf(stderr, "Error: Could not read %s\n", inputFileName); exit(1); } /* * Parse input file */ long lineNumber = 0; long height = -1; long width = -1; long depth = -1; char line[256]; list_t* workListPtr = list_alloc(&coordinate_comparePair); vector_t* wallVectorPtr = mazePtr->wallVectorPtr; vector_t* srcVectorPtr = mazePtr->srcVectorPtr; vector_t* dstVectorPtr = mazePtr->dstVectorPtr; while (fgets(line, sizeof(line), inputFile)) { char code; long x1, y1, z1; long x2, y2, z2; long numToken = sscanf(line, " %c %li %li %li %li %li %li", &code, &x1, &y1, &z1, &x2, &y2, &z2); lineNumber++; if (numToken < 1) { continue; } switch (code) { case '#': { /* comment */ /* ignore line */ break; } case 'd': { /* dimensions (format: d x y z) */ if (numToken != 4) { goto PARSE_ERROR; } width = x1; height = y1; depth = z1; if (width < 1 || height < 1 || depth < 1) { goto PARSE_ERROR; } break; } case 'p': { /* paths (format: p x1 y1 z1 x2 y2 z2) */ if (numToken != 7) { goto PARSE_ERROR; } coordinate_t* srcPtr = coordinate_alloc(x1, y1, z1); coordinate_t* dstPtr = coordinate_alloc(x2, y2, z2); assert(srcPtr); assert(dstPtr); if (coordinate_isEqual(srcPtr, dstPtr)) { goto PARSE_ERROR; } pair_t* coordinatePairPtr = pair_alloc(srcPtr, dstPtr); assert(coordinatePairPtr); bool_t status = list_insert(workListPtr, (void*)coordinatePairPtr); assert(status == TRUE); vector_pushBack(srcVectorPtr, (void*)srcPtr); vector_pushBack(dstVectorPtr, (void*)dstPtr); break; } case 'w': { /* walls (format: w x y z) */ if (numToken != 4) { goto PARSE_ERROR; } coordinate_t* wallPtr = coordinate_alloc(x1, y1, z1); vector_pushBack(wallVectorPtr, (void*)wallPtr); break; } PARSE_ERROR: default: { /* error */ fprintf(stderr, "Error: line %li of %s invalid\n", lineNumber, inputFileName); exit(1); } } } /* iterate over lines in input file */ fclose(inputFile); /* * Initialize grid contents */ if (width < 1 || height < 1 || depth < 1) { fprintf(stderr, "Error: Invalid dimensions (%li, %li, %li)\n", width, height, depth); exit(1); } grid_t* gridPtr = grid_alloc(width, height, depth); assert(gridPtr); mazePtr->gridPtr = gridPtr; addToGrid(gridPtr, wallVectorPtr, "wall"); addToGrid(gridPtr, srcVectorPtr, "source"); addToGrid(gridPtr, dstVectorPtr, "destination"); printf("Maze dimensions = %li x %li x %li\n", width, height, depth); printf("Paths to route = %li\n", list_getSize(workListPtr)); /* * Initialize work queue */ queue_t* workQueuePtr = mazePtr->workQueuePtr; list_iter_t it; list_iter_reset(&it, workListPtr); while (list_iter_hasNext(&it)) { pair_t* coordinatePairPtr = (pair_t*)list_iter_next(&it); queue_push(workQueuePtr, (void*)coordinatePairPtr); } list_free(workListPtr); return vector_getSize(srcVectorPtr); }
void doEntities() { int i; EntityList *el; /* Loop through the entities and perform their action */ for (el=entities->next;el!=NULL;el=el->next) { self = el->entity; if (self->inUse == TRUE) { self->flags &= ~(HELPLESS|INVULNERABLE|FLASH|ATTRACTED); for (i=0;i<MAX_CUSTOM_ACTIONS;i++) { if (self->customAction[i].thinkTime > 0) { doCustomAction(&self->customAction[i]); } } if (!(self->flags & TELEPORTING)) { if (!(self->flags & (FLY|GRABBED))) { switch (self->environment) { case WATER: case SLIME: self->dirY += GRAVITY_SPEED * 0.25 * self->weight; if (self->flags & FLOATS) { if (self->dirX != 0) { self->endY++; self->dirY = cos(DEG_TO_RAD(self->endY)) / 20; } } if (self->dirY >= MAX_WATER_SPEED) { self->dirY = MAX_WATER_SPEED; } break; default: self->dirY += GRAVITY_SPEED * self->weight; if (self->dirY >= MAX_AIR_SPEED) { self->dirY = MAX_AIR_SPEED; } else if (self->dirY > 0 && self->dirY < 1) { self->dirY = 1; } break; } } if (self->flags & GRABBED) { self->dirY = 0; } if (self->standingOn != NULL) { if (self->standingOn->dirX != 0) { self->dirX = self->standingOn->dirX; } if (self->standingOn->dirY > 0) { self->dirY = self->standingOn->dirY + 1; } } if (!(self->flags & HELPLESS)) { if (self->action == NULL) { showErrorAndExit("%s has no action function", self->name); } self->action(); } else { checkToMap(self); } if (self->standingOn != NULL) { self->flags |= WAS_STANDING_ON; } else { self->flags &= ~WAS_STANDING_ON; } self->standingOn = NULL; if (self->flags & SPAWNED_IN) { self->spawnTime--; } if (self->inUse == TRUE) { addToGrid(self); } } else { doTeleport(); } addToDrawLayer(self, self->layer); } } }