int main(int argc, char *argv[])
{
    errlog = fopen("errlog.txt", "a");
    Difficulty d;
    /* check command line args */
    if (argc != 3)
        exit(1);
    if (strcmp(argv[1], "-d"))
        exit(1);
    switch (argv[2][0]) {
    case '1':
        d = BEGINNER;
        break;
    case '2':
        d = INTERMEDIATE;
        break;
    case '3':
        d = EXPERT;
        break;
    default:
        exit(1);
    }
    setUp();
    Game *g = newGame(d);
    while (!(g->gameOver)) {
        drawGame(g);
        pollInput(g);
    }
    free(g);
    quitWithError("Game over");
    return 0;
}
Exemple #2
0
bool Window::mainLoop()
{
    double time     = m_deltaTimer.seconds();
    double delta    = time - m_prevTime;
    m_prevTime      = time;
    
    pollInput(delta);
    
    clear();

    Camera* cam = &getCamera();
    cam->recalculate();
    cam->applyView();
    
    if (m_zoneModel)
        m_zoneModel->draw(&getCamera());
    
    if (m_skele)
    {
        m_skele->animate(delta);
        m_skele->draw();
    }
    else if (m_animModel)
    {
        m_animModel->draw();
    }
    
    display();
    
    return m_running;
}
Exemple #3
0
void openvox::Window::sync(u32 frameTime /*= UINT_MAX*/) {
    pollInput();
    SDL_GL_SwapWindow((SDL_Window*)m_window);

    // Limit FPS
    if (m_displayMode.swapInterval == GameSwapInterval::USE_VALUE_CAP) {
        f32 desiredFPS = 1000.0f / (f32)m_displayMode.maxFPS;
        u32 sleepTime = (u32)(desiredFPS - frameTime);
        if (desiredFPS > frameTime && sleepTime > 0) SDL_Delay(sleepTime);
    }
}
Exemple #4
0
int main(void) {
  wdt_enable(WDTO_4S); // We don't want to hang.

  // Set up the outputs:
  DDRB  |= _BV(PB5);  // LED output on SCK pin

  DDRC  |= _BV(PC5);  // Compressor Relay
  DDRD  |= _BV(PD7);  // Fan Relay
  DDRB  |= _BV(PB0);  // Tank circulation pump Relay

  led(1);

  initADC();
  initPWM();
  resetInputBuffer();

  muartInit();
  mprintf(PSTR("#Power up!\n"));

  lcd_init(LCD_DISP_ON);
  led(0);
  setState(STATE_OFF);
  memcpy_P(parameters, (PGM_VOID_P)DEFAULT_PARAMETERS, sizeof(DEFAULT_PARAMETERS));

  char frame = 0;
  updateDisplay();

  while(1) {
    led(ledToggle); 
    ledToggle = ledToggle ? 0 : 1;

    if ((frame & 15) == 0) {
      updateDisplay();
    } 

    pollInput();
    updateStateMachine();
    updatePWM();
    //_delay_ms(10);
    wdt_reset();
    frame++;
  }	
}
Exemple #5
0
void Player::update(float dt)
{
    mDeltaHitTime += dt;

    // Walking or running.
    if(getVelocity().x != 0 || getVelocity().y != 0 && getOnGround()) {
        float speed = sqrt(	getVelocity().x * getVelocity().x + getVelocity().z * getVelocity().z);
        setSpeedAdjust(1.7f);
    }
    else
        setSpeedAdjust(1.0f);

    if(mJumping) {
        mElapsed += dt;
        if(mElapsed > 0.4f) {
            setAnimation(2, 0.80f);
            mJumping = false;
        }
    }

    // Get keypresses from the user.
    pollInput();

    // Standing still? Check if not jumping!
    if(abs(getVelocity().x) <= 0.0001 && abs(getVelocity().z) <= 0.0001 && !mJumping)
        setAnimation(2, 0.5f);

    // Limit the fall speed.
    if(getVelocity().y < -34.0f)
        setVelocity(D3DXVECTOR3(getVelocity().x, -34.0f, getVelocity().z));

    // Set the camera position.
    gCamera->setPosition(getPosition());

    // Update the camera.
    gCamera->update(dt);

    setRotation(D3DXVECTOR3(0.0f, atan2f(gCamera->getDirection().x, gCamera->getDirection().z), 0));

    SkinnedMesh::update(dt);
    mWeapon->update(dt);
}
Exemple #6
0
void mainLoop()
{
    try
    {
        while (running)
        {
            setupWindow(width, height, "raycar");
            Asset::init(GLContext::context());
            SceneGraph::init(GLContext::context());
            loadScene("content/raycar.scn");
            resetTimer();
            double now = 0;
            while (sceneRunning && running)
            {
                pollInput();
                double next = timer();
                if (active)
                {
                    if (next > now + maxStepTime)
                    {   //  falling behind
                        now = next - maxStepTime;
                    }
                    while (now < next)
                    {
                        stepScene();
                        now += stepTime;
                    }
                }
                else
                {
                    now = next;
                }
                renderWindow();
            }
        }
    }
    catch (std::exception const &x)
    {
        error(x.what());
    }
}
Exemple #7
0
int main(int argc, char* args[])
{
    initDisplay();
    
    struct Player player = {128, 128, (PI / 180) * 60};
    struct Input input = {false, false, false, false, false};
    

    while (!input.exit) {
        pollInput(&input);

        if (input.forward) {
            player.x += cos(player.a) * MOVE_SPEED;
            player.y -= sin(player.a) * MOVE_SPEED; 
        }
        if (input.left) {
            player.a -= TURN_SPEED;
            wrap(&player.a);
        }
        if (input.back) {
            player.x -= cos(player.a) * MOVE_SPEED;
            player.y += sin(player.a) * MOVE_SPEED; 
        }
        if (input.right) {
            player.a += TURN_SPEED;
            wrap(&player.a);
        }

        clearDisplay(); 
        drawWalls(&player);
        flipDisplay();
    }

    closeDisplay(); 

    return 0;
}
Exemple #8
0
//-----------------------------------------------------------------------------
int SDL_main(int argc, char *argv[]) {
	// NOTE: check for the correct number of arguements
	if(argc<2) {
		fprintf(stderr, "Error: need a level name.\n");
		return -1;
	}

	// NOTE: add the sqlite db to the levels directory
	char filename[0xFF];
	sprintf(filename, "levels/%s.db", argv[1]);

	// NOTE: open database connection
	if(sqlite3_open_v2(filename, &db, SQLITE_OPEN_READONLY, NULL)) {
		fprintf(stderr, "sqlite3_open: %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		return -1;
	}

	/* === */

	start();

	/* === */

	int wallSprite00Inds[2*3] = {
		03, 04,
		35, 36,
		67, 68
	};

	SDL_Color wall00Color = {0xFF,0xFF,0xFF,0xFF};
	SDL_Surface *wallSprite00 = buildSprite(2, 3, wall00Color, wallSprite00Inds);

	int floorSprite00Inds[2*3] = {
		17, 18,
		49, 50,
		81, 82
	};

	SDL_Color floorSprite00Color = {0x33,0x33,0x33,0xFF};
	SDL_Surface *floorSprite00 = buildSprite(2, 3, floorSprite00Color, floorSprite00Inds);

	int doorSprite00Inds[2*3] = {
		29, 30,
		61, 62,
		93, 94
	};

	SDL_Color doorSprite00Color = {0xFF,0xFF,0xFF,0xFF};
	SDL_Surface *doorSprite00 = buildSprite(2, 3, doorSprite00Color, doorSprite00Inds);

	int wallSprite01Inds[2*3] = {
		 97,  98,
		129, 130,
		161, 162
	};

	SDL_Color wall01Color = {0xFF,0xFF,0xFF,0xFF};
	SDL_Surface *wallSprite01 = buildSprite(2, 3, wall01Color, wallSprite01Inds);

	int wallSprite02Inds[2*3] = {
		105, 106,
		137, 138,
		169, 170
	};

	SDL_Color wallSprite02Color = {0xFF,0xFF,0xFF,0xFF};
	SDL_Surface *wallSprite02 = buildSprite(2, 3, wallSprite02Color, wallSprite02Inds);

	/* === */

	while(running) {
		/* === */

		pollInput();

		SDL_RenderClear(renderer);
		SDL_FillRect(screen, 0, 0x00);

		/* === */

		loadTiles();

		SDL_Rect tempRect = {
			0, 0, SPRITE_W*2, SPRITE_H*3
		};

		int i, j;
		for(j=0; j<12; j++) {
			for(i=0; i<30; i++) {
				tempRect.x = SPRITE_W*2*i;
				tempRect.y = SPRITE_H*3*j;

				switch(lvl.tiles[j][i]) {
					case 0x01: {
						SDL_BlitSurface(wallSprite00, NULL, screen, &tempRect);
					} break;
					case 0x02: {
						SDL_BlitSurface(doorSprite00, NULL, screen, &tempRect);
					} break;
					case 0x03: {
						SDL_BlitSurface(wallSprite01, NULL, screen, &tempRect);
					} break;
					case 0x04: {
						SDL_BlitSurface(wallSprite02, NULL, screen, &tempRect);
					} break;
					default: {
						SDL_BlitSurface(floorSprite00, NULL, screen, &tempRect);
					} break;
				}
			}
		}

		/* === */

		int pitch;
		void *pixels;

		// NOTE: get the pixels for the screen texture
		SDL_LockTexture(texture, NULL, &pixels, &pitch);

		// NOTE: set the pixels for the screen texture
		SDL_ConvertPixels(
			screen->w,
			screen->h,
			screen->format->format,
			screen->pixels,
			screen->pitch,
			SDL_PIXELFORMAT_RGBA8888,
			pixels, pitch
		);

		// NOTE: lock the texture so that it may be presented
		SDL_UnlockTexture(texture);

		// NOTE: present the texture
		SDL_RenderCopy(renderer, texture, NULL, NULL);
		SDL_RenderPresent(renderer);

		SDL_Delay(10);

		/* === */
	}

	/* === */

	SDL_FreeSurface(wallSprite00);
	wallSprite00 = NULL;

	SDL_FreeSurface(floorSprite00);
	floorSprite00 = NULL;

	SDL_FreeSurface(doorSprite00);
	doorSprite00 = NULL;

	SDL_FreeSurface(wallSprite01);
	wallSprite01 = NULL;

	SDL_FreeSurface(wallSprite02);
	wallSprite02 = NULL;

	/* === */

	quit();

	/* === */

	// NTOE: close the database connection
	sqlite3_close(db);
	db = NULL;

	fclose(stderr);
	return 0;
}