int main(int argc, char** argv){ int worldsize = 500; int players = 500; int numSteps = 10000; if (argc > 1){ worldsize = (int)strtol(argv[1], NULL, 10); } if (argc > 2){ players = (int)strtol(argv[2], NULL, 10); //check that the number of players can't exceed the size of the world if (players > worldsize*worldsize){ players = worldsize*worldsize; } } if (argc > 3){ numSteps = (int)strtol(argv[3], NULL, 10); } int* world = calloc(worldsize*worldsize, sizeof(int)); player* people; people = malloc(sizeof(player) * players); setupWorld(world, worldsize, people, players); runSimulation(world, worldsize, people, players, numSteps); free(world); free(people); }
//接下的代码段中,我们将对OpenGL进行所有的设置。我们将设置清除屏幕所用的颜色,打开深度缓存,启用smooth shading(阴影平滑),等等。 //这个例程直到OpenGL窗口创建之后才会被调用。此过程将有返回值。但我们此处的初始化没那么复杂,现在还用不着担心这个返回值。 void MyGLWidget::initializeGL() { loadTexture(); glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations setupWorld(); m_blend=!m_blend; if (!m_blend) { glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } else { glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); } }
bool Physics::initializePhysicsEngine() { paused = false; twoPlayer = true; engine = createIrrKlangDevice(); broadphase = new btDbvtBroadphase(); collisionConfiguration = new btDefaultCollisionConfiguration(); dispatcher = new btCollisionDispatcher(collisionConfiguration); solver = new btSequentialImpulseConstraintSolver; dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); dynamicsWorld->setGravity(btVector3(0, -9.8, 0)); playerScore = new scores(); playerScore->player1Score = 0; playerScore->player2Score = 0; oldPlayer1 = 0; oldPlayer2 = 0; follow = new int(); *follow = 1; goalCollisionCallBack = new GoalContactResultCallback(playerScore); AICollisionBack = new AIContactResultCallback(follow); return setupWorld(); }
void CMazeGameEngine::setResulotion(unsigned int in_width, unsigned int in_height) { init(in_width, in_height); setupMenuAndWinScreen(); if (isGameOngoing()) setupWorld(); startEventLoop(); }
void CMazeGameEngine::startNextLevel() { //TODO: increase level difficulty _isNextLevelRequested = false; auto mazeDimensions = menu.getChosenMazeDimensions(); initWorld(mazeDimensions.first, mazeDimensions.second, menu.getChosenNumOfAIPlayers(), menu.getChosenAIDifficultyLevel()); setupWorld(); }
World::World(int screenwidth, int screenheight, PlatformVBO *platformRendering, ParticleVBO *particleRendering, ParticleVBO *mainCharRendering) { //Initialize data //Initialize world variables this->screenwidth = screenwidth; this->screenheight = screenheight; platformVBO = platformRendering; particleVBO = particleRendering; mainCharParticleVBO = mainCharRendering; //Initialize camera variables spawnX = 0; cameraSpeed = START_CAMERASPEED; newSpeed = START_CAMERASPEED; camOffX = camOffY = 0; //Initialize puzzle variables platforms = new vector<b2Body*>; puzzles = new vector<Puzzle*>; platformColors = new vector<b2Vec3>; inProgress = false; puzzlesSolved = 0; //Initialize player variables particles = new vector<Particle*>; numParticles = START_PARTICLES; numStored = 0; lost = false; score = 0; parR = parG = parB = -1; movementSpeedGained = 0; //Initialize random wall variables numWalls = START_WALLS - WALL_INCREASE; //Set random seed based on time time_t t = time(0); tm *now = new tm(); localtime_s(now, &t); int h = now->tm_hour; int m = now->tm_min; int s = now->tm_sec; int time = (h * 10000) + (m * 100) + s; srand(time); //Set audio variables bg_music = NULL; snd_Shoot = NULL; snd_PuzzleClear = NULL; snd_PuzzleFail = NULL; //Start world setup setupWorld(); }
//--------------------------------------------------------------------- void ofApp::setup() { ofBackground(0); ofSetFrameRate(30); ofSetVerticalSync(true); // ofSetCoordHandedness(OF_RIGHT_HANDED); // Setup post-processing chain post.init(ofGetWidth(), ofGetHeight()); post.createPass<FxaaPass>()->setEnabled(false); post.createPass<BloomPass>()->setEnabled(false); post.createPass<DofPass>()->setEnabled(true); _kaleido = post.createPass<KaleidoscopePass>(); _kaleido->setEnabled(false); post.createPass<NoiseWarpPass>()->setEnabled(false); post.createPass<PixelatePass>()->setEnabled(false); post.createPass<EdgePass>()->setEnabled(false); post.createPass<VerticalTiltShifPass>()->setEnabled(false); post.createPass<GodRaysPass>()->setEnabled(false); // setup physics param group _physicsParam.setName("Physics"); // Setup light light.setPosition(1000, 1000, 2000); _physicsParam.add(_bLight.setup(_nw.getSceneNode(),"Light",false)); // create our own box mesh as there is a bug with // normal scaling and ofDrawBox() at the moment //boxMesh = ofMesh::box(20, 20, 20); // setup physics setupWorld(); // setup camera params setupCamera(); // cam.disableMouseInput(); // create Particles _boxes.setup(); _balls.setup(); // Setup Gui communicating using Minuit with i-score setupGui(); }
void HelloWorld::onEnter() { Layer::onEnter(); setupWorld(); _terrain = Terrain::create(_world); addChild(_terrain, 1); genBackground(); // Enable Touches/Mouse. auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this); listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this); listener->onTouchesCancelled = CC_CALLBACK_2(HelloWorld::onTouchesCancelled, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); scheduleUpdate(); _hero = Hero::create(_world); _hero->autorelease(); _terrain->getBatchNode()->addChild(_hero); }