Пример #1
0
void Dot::move(SDL_Rect &wall)
{
	/* move the dot left or right */
	mPosX += mVelX;
	mCollider.x = mPosX;

	/* if the dot collided or went too far to the left or right */
	if ((mPosX < 0) || (mPosX + DOT_WIDTH > SCREEN_WIDTH)
		|| check_collision(mCollider, wall))
	{
		/* move back */
		mPosX -= mVelX;
		mCollider.x = mPosX;
	}


	/* move the dot up or down */
	mPosY += mVelY;
	mCollider.y = mPosY;

	/* if the dot collided or went to far up or down */
	if ((mPosY < 0) || (mPosY + DOT_HEIGHT > SCREEN_HEIGHT)
		|| check_collision(mCollider, wall))
	{
		/* move back */
		mPosY -= mVelY;
		mCollider.y = mPosY;
	}
}
Пример #2
0
void update_game(Game *g) {
    --(g->swait);
    update_object(&(g->player));
    if(g->player.speed > 0.0)
        g->player.speed -= 0.01;
    for(Object *o = g->asteroids; o; o = o->next) {
        rotate(o, 0.05);
        update_object(o);
        if(check_collision(&g->player, o) || check_collision(o, &g->player))
            game_over(g);
    }
    for(Object **o = &(g->shot); *o; o = &(*o)->next) {
        update_object(*o);
        if((*o)->lifetime == 0) {
            Object *t = *o;
            *o = (*o)->next;
            free(t);
            if(!*o)
                return;
        }
        for(Object **p = &(g->asteroids); *p; p = &(*p)->next) {
            if(check_collision(*p, *o)) {
                Object *t = *o;
                *o = (*o)->next;
                free(t);
                
                (*p)->size *= 0.75;
                if((*p)->size < 0.5) {
                    t = *p;
                    *p = (*p)->next;
                    free(t);
                } else {
                    t = (*p)->next;
                    (*p)->next = memcpy(malloc(sizeof(Object)), *p, sizeof(Object));
                    (*p)->next->next = t;
                    (*p)->dir += ((float)(rand()%628))/100.0;
                    accelerate(g, *p, 0.5);
                    (*p)->next->dir += ((float)(rand()%628))/100.0;
                    accelerate(g, (*p)->next, 1.0);
                }

                if(!*o)
                    return;
                if(!*p)
                    break;
            }
        }
    }
    for(Object **o = &(g->particles); *o;) {
        update_object(*o);
        if((*o)->lifetime == 0) {
            Object *t = *o;
            *o = (*o)->next;
            free(t);
        } else {
            o = &(*o)->next;
        }
    }
}
Пример #3
0
void c_Manor::logic()
{
	entityManager.logicAll();

	if ( check_collision( manor_player->getBox(), exit->getBox() ) == true ){
		set_next_State( STATE_OVERWORLD );
	}

	else if ( check_collision( manor_player->getBox(), upStairs->getBox() ) == true ){
		set_next_State( STATE_MANOR2F );
	}
}
Пример #4
0
void Square::move()
{
  box.x += xVel;

  if((box.x < 0) || (box.x + SQUARE_WIDTH > SCREEN_WIDTH) || (check_collision(box, wall)))
  {
    box.x -= xVel;
  }

  box.y += yVel;
  if((box.y < 0) || (box.y + SQUARE_HEIGHT > SCREEN_HEIGHT) || (check_collision(box, wall)))
  {
    box.y -= yVel;
  }
}
Пример #5
0
bool Object::check_behind(Map *map, int start, int end)
{
    int top = get_attribute("top");
    int bottom = get_attribute("bottom");
    int min_dx = m_dx;

    if (m_dir == Right) {
        int left = get_attribute("left");
        for (int i = top; i <= bottom; i++) {
            int dx;
            for (dx = m_dx; dx > 0; dx--) {
                if (!check_collision(m_x + left - dx, m_y + i,
                                     map, start, end)) {
                    break;
                }
            }
            if (dx < min_dx) {
                min_dx = dx;
            }
        }
    }
    else if (m_dir == Left) {
        int right = get_attribute("right");
        for (int i = top; i <= bottom; i++) {
            int dx;
            for (dx = m_dx; dx > 0; dx--) {
                if (!check_collision(m_x + right + dx, m_y + i,
                                     map, start, end)) {
                    break;
                }
            }
            if (dx < min_dx) {
                min_dx = dx;
            }
        }
    }

    bool result;
    if (min_dx != m_dx) {
        m_dx = min_dx;
        result = true;
    }
    else {
        result = false;
    }

    return result;
}
Пример #6
0
bool SceneNode::MoveRight(float distance, SceneNode* root_node)
{
	float old_x = m_x;
	float old_z = m_z;

	m_z += sin(m_yangle * (XM_PI / 180.0f))*distance;
	m_x += cos(m_yangle * (XM_PI / 180.0f))*distance;

	XMMATRIX identity = XMMatrixIdentity();

	// since state has changed, need to update collision tree
	// this basic system requires entire hirearchy to be updated
	// so start at root node passing in identity matrix
	root_node->update_collision_tree(&identity, 1.0);

	// check for collision of this node (and children) against all other nodes
	if (check_collision(root_node) == true)
	{
		// if collision restore state
		m_z = old_z;

		return true;
	}

	return false;

}
Пример #7
0
static void	app(t_game *game)
{
	t_level		*current;

	init_glfw(game);
	current = game->levels;
	while (current)
	{
		load_level(game, current);
		while (!glfwWindowShouldClose(game->window) && !game->win)
		{
			update_time(game);
			if (game->started && !game->paused)
			{
				do_gl_stuff(game);
				move_ball(game);
				check_collision(game);
				draw_stuff(game);
				check_game_state(game);
				glfwSwapBuffers(game->window);
				usleep(12500);
			}
			glfwPollEvents();
			usleep(100);
		}
		current = current->next;
	}
}
Пример #8
0
bool Object::check_above(Map *map, int start, int end)
{
    int top = get_attribute("top");
    int left = get_attribute("left");
    int right = get_attribute("right");
    int min_dy = m_dy;

    for (int i = left; i <= right; i++) {
        int dy;
        for (dy = m_dy; dy > 0; dy--) {
            if (!check_collision(m_x + i, m_y + top - dy,
                                 map, start, end)) {
                break;
            }
        }
        if (dy < min_dy) {
            min_dy = dy;
        }
    }

    bool result;
    if (min_dy != m_dy) {
        m_dy = min_dy;
        result = true;
    }
    else {
        result = false;
    }

    return result;
}
Пример #9
0
void c_Store::logic()
{
	entityManager.logicAll();
	
	if(!store_player->deadfriend_visited){
	update_stereo_Position();
	}

	if (check_collision( store_player->getBox(), exit->getBox()) == true ){
		set_next_State(STATE_OVERWORLD);
	}

	else if (check_collision( store_player->getBox(), extensionDoor) == true ){
		set_next_State(STATE_STORE_EXTENSION);
	}
}
Пример #10
0
void Lines::paintEvent(QPaintEvent *e){
	Q_UNUSED(e);
	QPainter qp(this);
	/*Create serial object */
	try { 

			// Make a SimpleSerial object with the parameter for your Wunderboard/OS
			
			
			this->tmp = this->wunder->readLine();

			/*handles odd SimpleSerial Problems*/
			if(this->tmp.length() != 3)
				adcval = MADC; //send it back to the middle
			else
				adcval = atoi(this->tmp.c_str()) - MADC ;

		} catch(boost::system::system_error& e)
		{
			std::cerr<<tmp<<": Error: "<<std::endl;//<<e.what()<<std::endl;
		}
	qp.setWindow(0,0, 800, 600);
	drawBoundary(&qp);
	drawPaddle(&qp);
	drawBall(&qp);
	drawBlocks(&qp);
	check_collision();

	
}
Пример #11
0
void run_game(){
/* THE GAME RUNS WITHIN THIS TRUE WHILE LOOP */
	while (!0)
    {
    while(speed_limit > 0)
    {
         speed_limit --;
    /*============================================*/
        draw_court();               // GAME STEP 1
        show_mouse(court);
        set_mouse_range(0,0,court->w,court->h);
       	check_keyboard_entry();     // GAME STEP 2
    	control_bats();             // GAME STEP 3
        check_collision();          // GAME STEP 4
        update_cock_position();     // GAME STEP 5
		
        draw_bats_and_cock();       // GAME STEP 6
        draw_speed_meter();         // GAME STEP 7
        display_game_status();      // GAME STEP 8
        draw_buffer();              // GAME STEP 9
    /*============================================*/
    }
    // Speed limiting loop ends
    }
    deinitialize_game();
}
Пример #12
0
void gun_shell::simulate(double delta_time)
{
	check_collision();
	oldpos = position;
	//log_debug("GS: position="<<position);
	sea_object::simulate(delta_time);
}
Пример #13
0
//returns a tetrimino that serves as the ghost piece.
Tetrimino get_ghost_piece()
{
    Tetrimino ghost_piece = *in_play;
    while(!check_collision(ghost_piece))
        ghost_piece.posy++;
    ghost_piece.posy--;
    return ghost_piece;
}
//timer funcion which will be called repeatedly
void timer_func(int v)
{
  if(game_state==2)
  {
    if (count==0)
    exit(0);
    else
     count--;
  }
  if(game_state==0)
  {
    count--;
    if(count==0)
    {
     game_state=2;
     count=100;
     
    }
    
    else
    {
     int i;
     //yc-=3;
     for(i=0;i<10;i++)
     {
       if(eggs[i]==1)
       {
         egg_pos[i][1]-=10;
         //printf("\nyvu");
       }
     }
     draw_basket();
     check_collision();
    }
   }
   else
     if(game_state==1)
     {
        draw_basket();
        check_collision();
     
     }
   glutPostRedisplay();
  
   glutTimerFunc(50, timer_func, v);
}
Пример #15
0
void Crawler::check_ground(Map *map)
{
    if (get_hit_ground()) {
        if (m_dir == Right) {
            if (!check_collision(m_x + get_attribute("right"),
                                 m_y + get_attribute("bottom") + 1, map)) {
                set_dir(Left);
            }
        }
        else if (m_dir == Left) {
            if (!check_collision(m_x + get_attribute("left"),
                                 m_y + get_attribute("bottom") + 1, map)) {
                set_dir(Right);
            }
        }
    }
}
Пример #16
0
void c_Shovel::logic()
{
	if ( check_collision(collisionBox, c_Entity_manager::getPlayer()->getBox()) == true )
	{
		/*c_Entity_manager::getPlayer()->setWeapon( SHOVEL );*/
		/*c_Entity_manager::remove( ID_number );*/
	}
}
Пример #17
0
void c_Store_Extension::logic()
{
	entityManager.logicAll();

	if ( check_collision(store_player->getBox(), exit) ){
		set_next_State(STATE_STORE);
	}
}
Пример #18
0
void c_Manor_2F::logic()
{
	entityManager.logicAll();

	if ( check_collision( manor_player->getBox(), exit->getBox() ) == true )
	{
		set_next_State(STATE_MANOR);
	}
}
Пример #19
0
void Tile::show()
{
    //If the tile is on screen
    if( check_collision( camera, box ) == true )
    {
        //Show the tile
        apply_surface( box.x - camera.x, box.y - camera.y, tileSheet, screen, &clips[ type ] );
    }
}
Пример #20
0
Файл: GridCell.c Проект: osen/gc
void GridCellDraw(struct GridCell *ctx)
{
  SDL_Rect rect = {0};
  struct Camera *camera = NULL;
  int mouseX = 0;
  int mouseY = 0;
  SDL_Rect mouseRect = {0};

  camera = ctx->world->camera;

  rect.x = ctx->x;
  rect.y = ctx->y;
  rect.w = GRIDCELL_SIZE;
  rect.h = GRIDCELL_SIZE;

  MousePosition(ctx->world->mouse, &mouseX, &mouseY);
  CameraTranslate(camera, &mouseX, &mouseY);
  //mouseRect.x = mouseX + ctx->world->camera->x;
  //mouseRect.y = mouseY + ctx->world->camera->y;
  mouseRect.x = mouseX;
  mouseRect.y = mouseY;
  mouseRect.w = 1;
  mouseRect.h = 1;

  if(ctx->type == 0)
  {
    CameraDrawImage(camera, ctx->image, ctx->x, ctx->y);
  }
  else
  {
    CameraDrawImage(camera, ctx->blockImage, ctx->x, ctx->y);
  }

  ctx->active = 0;

  if(check_collision(rect, mouseRect) == 1)
  {
    ctx->active = 1;

    if(MouseClicked(ctx->world->mouse) == 1)
    {
      ctx->type = 1;

      //printf("Connections: ^%p >%p \\/%p <%p \\%p /%p \\%p /%p\n",
      //  ctx->top, ctx->right, ctx->bottom, ctx->left,
      //  ctx->topLeft, ctx->topRight, ctx->bottomRight, ctx->bottomLeft);
    }

    CameraDrawImage(camera, ctx->cursorImage, ctx->x, ctx->y);
  }

  if(_GridCellHasNeighbourActive(ctx) == 1)
  {
    CameraDrawImage(camera, ctx->highlightImage, ctx->x, ctx->y);
  }
}
Пример #21
0
void Tile::draw() {
  if ((image_pointer != NULL) and (check_collision(camera_rect, box))) {
    //zoip = Z_Ordered_Image_Pointer
    Z_Ordered_Image_Pointer temp_zoip;
    temp_zoip.x = box.x - camera_rect.x;
    temp_zoip.y = box.y - camera_rect.y;
    temp_zoip.z = z;
    temp_zoip.image_pointer = image_pointer;
    z_order_pq.push(temp_zoip);
  }
}
Пример #22
0
void Level::update()
{
	if(loading)
	{
		loading--;
		return;
	}
	float cx, cy, cz;
	Camera::getCamera()->getPos(&cx, &cy, &cz);
	float ay;
	Camera::getCamera()->getLookAngle(&ay, NULL);
	float vw, vh;
	Camera::getCamera()->getViewport(&vw, &vh);
	if(_is_shooting)
	{
		Camera::getCamera()->translate(0.0f, 0.0f,PLAYER_STEP*SHOT_VELOCITY);
		Camera::getCamera()->getPos(&cx, &cy, &cz);
	}else{
		gun->setPos(cx, cy, cz);
	}
	bullet->setPos(cx, cy-2, cz+2);
	glutWarpPointer(vw/2, vh/2);//+vh/4);

	for(unsigned int i=0;i<targets.size();i++)
	{
		targets.at(i)->update();
	}
	//
	if(check_collision())
	{
		unsigned int i;
		for(i=0;i<targets.size();i++)
		{
			if(targets.at(i)->getLife()>0)
				break;
		}
		if(i==targets.size())
		{
			loading_message=std::string("YOU WIN!");
			end_game(1);
		}
	}
	//
	if(!Player::bullets && !_is_shooting)
	{
		int total = 0;
		for(unsigned int i=0;i<targets.size();i++)
		{
			total+=targets.at(i)->getLife();
		}
		if(total)
			end_game(2);
	}
}
Пример #23
0
bool check_tet_collision(Tetramino A, Tetramino B)
{
    if(check_collision(A.blocks[0].offsets, B.blocks[0].offsets) == true)
    {
	return true;
    }
    if(check_collision(A.blocks[1].offsets, B.blocks[1].offsets) == true)
    {
	return true;
    }
    if(check_collision(A.blocks[2].offsets, B.blocks[2].offsets) == true)
    {
	return true;
    }
    if(check_collision(A.blocks[3].offsets, B.blocks[3].offsets) == true)
    {
	return true;
    }
    return false;
}
Пример #24
0
int main(int argc, char* args[])
{
	int ret = 0;
	int fbfd = 0;
	struct pollfd evpoll = {
		.events = POLLIN,
	};
	
	srand (time(NULL));

	evpoll.fd = open_evdev("Raspberry Pi Sense HAT Joystick");
	if (evpoll.fd < 0) {
		fprintf(stderr, "Event device not found.\n");
		return evpoll.fd;
	}

	fbfd = open_fbdev("RPi-Sense FB");
	if (fbfd <= 0) {
		ret = fbfd;
		printf("Error: cannot open framebuffer device.\n");
		goto err_ev; 
		
	}
	
	fb = mmap(0, 128, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
	if (!fb) {
		ret = EXIT_FAILURE;
		printf("Failed to mmap.\n");
		goto err_fb;
	}
	memset(fb, 0, 128);

	snake.tail = &snake.head;
	reset();
	while (running) {
		while (poll(&evpoll, 1, 0) > 0)
			handle_events(evpoll.fd);
		game_logic();
		if (check_collision(0)) {
			reset();
		}
		render();
		usleep (300000);
	}
	memset(fb, 0, 128);
	reset();
	munmap(fb, 128);
err_fb:
	close(fbfd);
err_ev:
	close(evpoll.fd);
	return ret;
}
Пример #25
0
void increase_ticks()
{
    Tetrimino new_pos = *in_play;
    new_pos.posy++;
    if(check_collision(new_pos)) //means that there's something below, so we count down
    {
        ticks_before_glue++;
	if(ticks_before_glue >= cfg.glue_delay[level-1])
            glue();
    }

}
Пример #26
0
/*
Moves the tetrimino to the right.
*/
void go_right()
{
    Tetrimino copy = *in_play;
    copy.posx++;
    if(!check_collision(copy))
    {
        in_play->posx++;
	last_T_rotation = 0;
	if(!cfg.ARS || !ARS_glue_lock)
	    ticks_before_glue = 0;
    }
}
Пример #27
0
void game_logic(void)
{
	struct segment_t *seg_i;
	struct segment_t *new_tail;
	for(seg_i = snake.tail; seg_i->next; seg_i=seg_i->next) {
		seg_i->x = seg_i->next->x;
		seg_i->y = seg_i->next->y;
	}
	if (check_collision(1)) {
		new_tail = malloc(sizeof(struct segment_t));
		if (!new_tail) {
			printf("Ran out of memory.\n");
			running = 0;
			return;
		}
		new_tail->x=snake.tail->x;
		new_tail->y=snake.tail->y;
		new_tail->next=snake.tail;
		snake.tail = new_tail;

		while (check_collision(1)) {
			apple.x = rand() % 8;
			apple.y = rand() % 8;
		}
	}
	switch (snake.heading) {
		case LEFT:
			seg_i->y--;
			break;
		case DOWN:
			seg_i->x++;
			break;
		case RIGHT:
			seg_i->y++;
			break;
		case UP:
			seg_i->x--;
			break;
	}
}
Пример #28
0
void c_stageOne::logic()
{
	entityManager.logicAll();

	if ( check_collision(entityManager.get(0)->getBox(), player->getBox()) ){
		set_next_State( STATE_HOUSE1 );
	}

	else if ( check_collision(entityManager.get(1)->getBox(), player->getBox()) ){
		set_next_State( STATE_HOUSE2 );
	}

	else if ( check_collision(entityManager.get(2)->getBox(), player->getBox()) ){
		set_next_State( STATE_STORE );
	}

	else if (check_collision(entityManager.get(3)->getBox(), player->getBox()) ){
		set_next_State( STATE_MANOR );
	}

	else if (check_collision(exit, player->getBox()) && c_Manor_2F::isVisited){
		set_next_State(STATE_GAMEWIN_WITH_FRIEND);
	}

	else if (check_collision(exit, player->getBox()) && !c_Manor_2F::isVisited){
		narrator.setMessage( "No point in turning back now..." );
	}

	else
		narrator.setMessage("");

	if (enemy != NULL){
		narrator.setMessage("You feel a cold wind through the air...");
	}
}
Пример #29
0
void Square::move()
{
    //Move the square left or right
    box.x += xVel;

    //If the square went too far to the left or right or has collided with the wall
    if( ( box.x < 0 ) || ( box.x + SQUARE_WIDTH > SCREEN_WIDTH ) || ( check_collision( box, wall ) ) )
    {
        //Move back
        box.x -= xVel;
    }

    //Move the square up or down
    box.y += yVel;

    //If the square went too far up or down or has collided with the wall
    if( ( box.y < 0 ) || ( box.y + SQUARE_HEIGHT > SCREEN_HEIGHT ) || ( check_collision( box, wall ) ) )
    {
        //Move back
        box.y -= yVel;
    }
}
Пример #30
0
int Object::check_ahead(Map *map, int len, int start, int end)
{
    int result = len;
    int top = get_attribute("top");
    int bottom = get_attribute("bottom");

    if (m_dir == Right) {
        int right = get_attribute("right");
        for (int i = top; i <= bottom; i++) {
            int dx;
            for (dx = len; dx > 0; dx--) {
                if (!check_collision(m_x + right + dx, m_y + i,
                                     map, start, end)) {
                    break;
                }
            }
            if (dx < result) {
                result = dx;
            }
        }
    }
    else if (m_dir == Left) {
        int left = get_attribute("left");
        for (int i = top; i <= bottom; i++) {
            int dx;
            for (dx = len; dx > 0; dx--) {
                if (!check_collision(m_x + left - dx, m_y + i,
                                     map, start, end)) {
                    break;
                }
            }
            if (dx < result) {
                result = dx;
            }
        }
    }

    return result;
}