Example #1
0
// -------------------------------------------------------
// move down
// -------------------------------------------------------
bool Grid::moveDown() {
	if (_limit == 0) {
		return false;
	}
	// FIXME: check if we can even move down
	ds::SID ids[256];
	int num = _world->find_by_type(OT_BRICK, ids, 256);
	Vector2i gp;
	for (int i = 0; i < num; ++i) {
		v2 p = _world->getPosition(ids[i]);
		if (convertToGrid(p, &gp)) {
			_board[gp.x][gp.y] = ds::INVALID_SID;
			_board[gp.x][gp.y - 1] = ids[i];
			if (gp.y - 1 < 0) {
				// game over
			}
			else {
				_world->scaleTo(ids[i], v2(0.7f, 0.7f), v2(1, 1), 0.4f, 0, tweening::easeInOutQuad);
				_world->moveTo(ids[i], p, v2(p.x, p.y - GDY), 0.4f, 0, tweening::easeInOutQuad);
			}
		}
	}

	findLimit();

	num = _world->find_by_type(OT_NEW_BRICK, ids, 256);
	for (int i = 0; i < num; ++i) {
		v2 p = _world->getPosition(ids[i]);
		gp.y = 0;
		gp.x = (p.x - GSX) / GDX;
		int r = -1;
		for (int j = GMY - 1; j >= 0; --j) {
			if (r == -1 && _board[gp.x][j] != ds::INVALID_SID) {
				r = j;
			}
		}		
		r += 1;
		if (r == -1) {
			r = _limit;
		}
		if (r < _limit) {
			r = _limit;
		}
		LOG << "p.x " << gp.x << " r " << r;
		_board[gp.x][r] = ids[i];
		_world->setType(ids[i], OT_BRICK);
		_world->attachBoxCollider(ids[i], OT_BRICK, 0);
		v2 np;
		if (convertFromGrid(gp.x, r, &np)) {
			_world->moveTo(ids[i], p, np, 0.4f, 0, tweening::easeInOutQuad);
		}
	}
	return true;
	//debug();
}
Example #2
0
void mouse(int btn, int state, int x, int y){
	switch(btn){
		case GLUT_LEFT_BUTTON:
			if(state==GLUT_DOWN){
				glColor3f(Red, Green, Blue);
		
				if(pointsSelected == 0){
					point1x = convertToGrid(x,y)[0];
					point1y = convertToGrid(x,y)[1];
					printf("Point 1: %f, %f\n", point1x, point1y);
				}
				else{
					point2x = convertToGrid(x,y)[0];
					point2y = convertToGrid(x,y)[1];
					printf("Point 2: %f, %f\n", point2x, point2y);
				}

				pointsSelected++;
	
				flag = 0;
			}
			break;
	}
}
Example #3
0
// -------------------------------------------------------
// handle hit
// -------------------------------------------------------
int Grid::handleHit(ds::SID sid) {
	if (_world->contains(sid) && _world->getType(sid) == OT_BRICK) {		
		Brick* data = (Brick*)_world->get_data(sid);
		if (data != 0) {
			--data->energy;
			LOG << "sid: " << sid << " energy: " << data->energy;
			if (data->energy <= 0) {
				v2 p = _world->getPosition(sid);
				Vector2i gp;
				if (convertToGrid(p, &gp)) {
					_board[gp.x][gp.y] = ds::INVALID_SID;
				}
				return 1;
			}
			_world->scaleByPath(sid, &_scalePath, 0.2f);
		}
	}
	return 0;
}
Example #4
0
void motion(int x,int y){
	point1x = convertToGrid(x,y)[0];
	point1y = convertToGrid(x,y)[1];
	display();
}