Ejemplo n.º 1
0
void blockHit(){
	int i = 0;
	for( ; i < 10; i ++){
		if( blocks[i].visible == 1){
			//side collision
			if( ball.row >= blocks[i].row && ball.row <= (blocks[i].row + BLOCK_HEIGHT) )
				if( ball.col == blocks[i].col || (ball.col == (blocks[i].col + BLOCK_WIDTH) )){
					moveC = -moveC;
					blocks[i].visible = 0;
					updateBlocks();
					break;
			}
			//top or bottom collision
			if( (ball.col >= blocks[i].col ) && (ball.col <= (blocks[i].col + BLOCK_WIDTH) )){
				if( ball.row == blocks[i].row || (ball.row == (blocks[i].row + BLOCK_HEIGHT))){
					moveR = -moveR;
					blocks[i].visible = 0;
					updateBlocks();
					break;
				}
			}

		}
	}
}
Ejemplo n.º 2
0
AerialMapDisplay::AerialMapDisplay()
    : Display(), map_id_(0), scene_id_(0), dirty_(false),
      received_msg_(false), loader_(0) {

  static unsigned int map_ids = 0;
  map_id_ = map_ids++; //  global counter of map ids

  topic_property_ = new RosTopicProperty(
      "Topic", "", QString::fromStdString(
                       ros::message_traits::datatype<sensor_msgs::NavSatFix>()),
      "nav_msgs::Odometry topic to subscribe to.", this, SLOT(updateTopic()));

  alpha_property_ = new FloatProperty(
      "Alpha", 0.7, "Amount of transparency to apply to the map.", this,
      SLOT(updateAlpha()));
  alpha_ = alpha_property_->getValue().toFloat();
  alpha_property_->setMin(0);
  alpha_property_->setMax(1);
  alpha_property_->setShouldBeSaved(true);

  draw_under_property_ =
      new Property("Draw Behind", false,
                   "Rendering option, controls whether or not the map is always"
                   " drawn behind everything else.",
                   this, SLOT(updateDrawUnder()));
  draw_under_property_->setShouldBeSaved(true);
  draw_under_ = draw_under_property_->getValue().toBool();

  //  output, resolution of the map in meters/pixel
  resolution_property_ = new FloatProperty(
      "Resolution", 0, "Resolution of the map. (Read only)", this);
  resolution_property_->setReadOnly(true);

  //  properties for map
  object_uri_property_ = new StringProperty(
      "Object URI", "http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg",
      "URL from which to retrieve map tiles.", this, SLOT(updateObjectURI()));
  object_uri_property_->setShouldBeSaved(true);
  object_uri_ = object_uri_property_->getStdString();

  zoom_property_ = new IntProperty("Zoom", 16, "Zoom level (0 - 19 usually)",
                                   this, SLOT(updateZoom()));
  zoom_property_->setShouldBeSaved(true);
  zoom_ = zoom_property_->getInt();

  blocks_property_ =
      new IntProperty("Blocks", 3, "Number of adjacent blocks (6 max)", this,
                      SLOT(updateBlocks()));
  blocks_property_->setShouldBeSaved(true);

  //  updating one triggers reload
  updateBlocks();
}
Ejemplo n.º 3
0
  void ParallelCGCudaTask<N, T>::execute(const Thread* caller){
    /*Zero range, skip allocation/computation*/
    if(cmat->getMRange(TID)->range == 0)
      return;

    if(TID == 0){
      Vector<T>::mul(*r, *b, *b);
      bnorm = Sqrt(r->sum());
    }
    caller->sync();

    switch(subTask){
    case Allocate:
#if 1
      try{
        /*Try to allocate all the memory needed. If this fails,
          deallocate and throw an exception*/
        allocate(caller);
      }catch(CUDAException& e){
        std::cerr << e.getError();
        valid = false;
        deallocate(caller);
        throw;
      }catch(Exception& e){
        std::cerr << e.getError();
        throw;
      }
#else
      allocate(caller);
#endif
      break;
    case Deallocate:
      deallocate(caller);
      break;
    case CopyResult:
      copyResult(caller);
      break;
    case UpdateBlocks:
      updateBlocks(caller);
      break;
    case SolveSystem:
      solveSystem(caller);
      break;
    }
  }
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    Game *g = (Game*) malloc(sizeof(Game));
    SDL_Event event;
    Uint8 *keystates;
    Uint8 quit = false;
    long lastplayerupdate = ms_time();
    long lastenemyupdate = ms_time();
    long lastshotupdate = ms_time();
    long lastufoupdate = ms_time();
    
    srand((unsigned int) time(NULL));
    
    // SDL initialisieren
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
        printf("Kann Video nicht initialisieren: %s\n", SDL_GetError());
        exit(1);
    }
    
    atexit(SDL_Quit);
    
    g->screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_HWSURFACE);
    
    if (g->screen == NULL) {
        printf("Kann Video-Modus nicht festlegen: %s\n", SDL_GetError());
        exit(1);
    }
    
    TTF_Init();
    
    
    // Game initialisieren
    initGame(g);
    startNewLevel(g);
    updateScore(g);
    updateLives(g);
    showHighscore(g);
    updateBlocks(g);
    
    // Nächster Grafikzustand
    SDL_Flip(g->screen);
    
    // Loop
    while (!quit) {
        // SDL Events abfragen
        SDL_PollEvent(&event);
        
        // Tastenstatus laden
        keystates = SDL_GetKeyState(NULL);
        
        // Escape gedrückt -> beenden
        // TODO: Menü aufrufen statt beenden
        if (keystates[SDLK_ESCAPE]) {
            saveHighscore(g->score);
            quit = true;
        }
        
        // Nur wenn entweder Links oder Rechts, nicht beide zur selben Zeit
        if (keystates[SDLK_LEFT] != keystates[SDLK_RIGHT] && lastplayerupdate >= 100) {
            lastplayerupdate = ms_time();
            
            // Links
            if (keystates[SDLK_LEFT]) {
                movePlayer(g, Left);
            }
            // Rechts
            if (keystates[SDLK_RIGHT]) {
                movePlayer(g, Right);
            }
        }
        
        if (keystates[SDLK_SPACE]) {
            shoot(g);
        }
        
        // UFO
        if (ms_time() - lastufoupdate >= UFO_UPDATE) {
            lastufoupdate = ms_time();
            ufo(g);
        }
        
        // Alienposition aktualisieren?
        // Exponentialfunktion, die Level und Alienanzahl berücksichtigt
        if (ms_time() - lastenemyupdate >= ENEMY_UPDATE_BASE * pow(0.95, g->level * 3 + (ENEMY_COUNT - g->enemyContainer.aliveCount) / 4)) {
            lastenemyupdate = ms_time();
            updateBlocks(g);
            moveEnemys(g);
            alienShot(g);
        }
        
        // Schüsse aktualisieren
        if (ms_time() - lastshotupdate >= SHOT_UPDATE) {
            lastshotupdate = ms_time();
            updateShots(g);
            checkCollision(g);
            movePlayer(g, None);
        }
        
        usleep(20000); // begrenzt CPU Last
        // Nächster Grafikzustand
        SDL_Flip(g->screen);
    }
    
    SDL_Quit();
    return 0;
}
Ejemplo n.º 5
0
int main(int argc, char* args[])
{
	Screen screen = {};
	screen.width = SQUARE_DIM*SCALE*COLUMNS;
	screen.height = SQUARE_DIM*SCALE*ROWS;
	
	//init everything (window, main surface, renderer, SDL_Image)
	//NOTE: This is probably a bad way to do this since I am changing data inside function instead of returning something
	if(!init(&screen))
	{
		printf("Something could not be initialized! Error: %s\n", SDL_GetError());
	}

	//set Texture class render pointer
	Texture::setRenderer(screen.renderer);

	//set Square's main texture
	Square::setTexture("tiles.png");

	//create a blockbuilder
	BlockBuilder builder;

	//get a block pointer
	Block* block = null;

	//create an array for the Tetris board that will hold all inanimate squares
	Board board = {0};
	//int numGrid = ROWS*COLUMNS;
	//Square board_squares[ROWS*COLUMNS];
	
	//set up locations for board squares
	board.numSquares = COLUMNS*ROWS;	
	for(int i = 0; i < board.numSquares; ++i)
	{
		int x = (i%COLUMNS)*SQUARE_DIM*SCALE;
		int y = (i/COLUMNS)*SQUARE_DIM*SCALE;

		board.squares[i].setX(x);
		board.squares[i].setY(y);
		board.squares[i].concrete = 0;
	}

	//create vector for blocks
	//std::vector<Block*> blocks;
	//blocks.push_back(builder.buildBlock(L_BLOCK, RED, 0, 0));

	bool quit = false;
	SDL_Event event;
	
	//timer variables
	uint32 currentTime = SDL_GetTicks();
	uint32 previousTime = 0;

	//init RNG
	srand(time(0));

	Color colors[4];
	colors[0] = RED;
	colors[1] = BLUE;
	colors[2] = GREEN;
	colors[3] = YELLOW;

	BlockType blockTypes[5];

	blockTypes[0] = T_BLOCK;
	blockTypes[1] = I_BLOCK;
	blockTypes[2] = O_BLOCK;
	blockTypes[3] = S_BLOCK;
	blockTypes[4] = L_BLOCK;

	while(!quit)
	{
		//check to see if there is no active block
		if(!block)
		{
			int color = rand()%4;
			int blockType = rand()%5;
			block = builder.buildBlock(blockTypes[blockType], colors[color], 210, 30);
			block->setLowestPoint(board.blocksInColumn);
			//block->setLowestBlockY();
		}

		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
			{
				quit = true;
				printf("QUITTING! Another successful run! :)\n");
			}	
			else if(event.type == SDL_KEYDOWN)
			{
				switch(event.key.keysym.sym)
				{
					case SDLK_UP:
					{
						//rotate block counter - clockwise
						block->rotateBlock(board.squares, board.blocksInColumn, -1);
					} break;

					case SDLK_DOWN:
					{
					} break;

					case SDLK_RIGHT:
					{
						block->moveBlock(VELOCITY, board.squares, board.blocksInColumn);
					} break;

					case SDLK_LEFT:
					{
						block->moveBlock(-VELOCITY, board.squares, board.blocksInColumn);
					} break;
					case SDLK_SPACE:
					{
						//first set block's squares to resting place height
						block->setToRest();
					} break;

					default:
					{
					}
				}
			
			}
			
		}
		
		//clear screen set to light gray	
		SDL_SetRenderDrawColor(screen.renderer, 0, 0, 0, 0);
		SDL_RenderClear(screen.renderer);
	
		//render the grid
		renderGrid(screen.renderer);
		//the block
		block->render();	
		//printf("Final Y: %d, LowY: %d\n", block->finalY, block->blockLowY);
		//render board
		for(int i = 0; i < board.numSquares; ++i)
		{
			if(!board.squares[i].concrete) //check if null
			{
				continue;
			}
			board.squares[i].renderBoardSquare();
		}

		//printf("x: %d y: %d\n", block->getX(), block->getY());
		SDL_RenderPresent(screen.renderer);
		
		//bool makeStatic = false; // has block reached its final resting place?

		//check to see if 1/2 of a second has passed. 
		//if so, update locationsj
 		currentTime = SDL_GetTicks();	
		if((currentTime - previousTime) > 500)
		{
			//printf("currentTime - previousTime = %d\n", currentTime - previousTime);
			//updateBlocks(&blocks, board_squares);
			if(updateBlocks(block, &board))
			{
				block = null;

				//check to see if any rows are full
				FilledRowRegion check = checkBoard(&board);

				if(check.firstFilledRow > -1) //then there is a row that is filled!
				{
					clearBoard(check.firstFilledRow, check.lastFilledRow, &board);
				}
			}
			previousTime = currentTime;
		}
		
	}
	
	SDL_DestroyRenderer(screen.renderer);
	SDL_DestroyWindow(screen.window);
	screen.window = null;

	SDL_Quit();
	IMG_Quit();
	return 0;
}
Ejemplo n.º 6
0
void drawBlocks(){
	int i = 0;
	for( ; i < 10; i ++)
		drawRect(blocks[i].row, blocks[i].col, BLOCK_HEIGHT, BLOCK_WIDTH, blocks[i].color);
	updateBlocks();
}