Exemplo n.º 1
0
int Pacman::update(char gameboard[][28])
{
	int new_x = getNextX();
	int new_y = getNextY();
	boolean move = true;
	switch(gameboard[new_y][new_x]) {
		case 'd':
		case 'u':
		case '0':
			break;
		case '9':
			wrap();
			break;
		case 'a':
		case 'c':
		case 'f':
		case 's':
			//die();
			// :(
		default:
			move = false;
			break;
	}
	if(move) {
		incrementX();
		incrementY();
	}
	return gameboard[int(y)][int(x)];
}
osg::Geometry* ShapeVisitor_VisualizerCreator::createGridGeometry( int size, int noOfLines, osg::Vec3f center )
{

	osg::Geometry* geom = new osg::Geometry();
	osg::Vec3Array* positionsOfLines = new osg::Vec3Array;

	geom->setVertexArray( positionsOfLines );

	// position of borders
	osg::Vec3f dif1( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 ); // top left
	osg::Vec3f dif2( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( -size/2 ), -10 );
	osg::Vec3f dif3( ( osg::Vec3f::value_type )( size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 );

	// increment for creating points of mesh at border
	osg::Vec3f incrementX( ( osg::Vec3f::value_type )( size/noOfLines ), 0, 0 );
	osg::Vec3f incrementY( 0, ( osg::Vec3f::value_type )( -size/noOfLines ), 0 );

	// computing and saving positions of points at border of mesh
	for ( int i=0; i<2; i++ ) {

		osg::Vec3f base1 = center + dif1;
		osg::Vec3f base2 = center + dif2;

		// computing positions at x axis
		for ( int j=0; j<noOfLines; j++ ) {
			positionsOfLines->push_back( base1 + incrementX );
			base1 += incrementX;
			positionsOfLines->push_back( base2 + incrementX + incrementY );
			base2 += incrementX;
		}

		base1 = center + dif1;
		base2 = center + dif3;

		// computing positions at y axis
		for ( int j=0; j<noOfLines; j++ ) {
			positionsOfLines->push_back( base1 + incrementY );
			base1 += incrementY;
			positionsOfLines->push_back( base2 + incrementY + incrementX );
			base2 += incrementY;
		}

		// connecting two corresponding points at border of mesh
		for ( int k=0; k<noOfLines*4; k=k+2 ) {
			osg::DrawElementsUInt* line = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
			line->push_back( k );
			line->push_back( k+1 );
			geom->addPrimitiveSet( line );
		}
	}

	return geom;
}
Exemplo n.º 3
0
void Hero::logic() {

        //logic
        if(currentKeyStates[SDL_SCANCODE_DOWN] == true && currentKeyStates[SDL_SCANCODE_UP] == false) {
            incrementY(1);
        } else if(currentKeyStates[SDL_SCANCODE_UP] == true && currentKeyStates[SDL_SCANCODE_DOWN] == false) {
            incrementY(-1);
        }
        if(currentKeyStates[SDL_SCANCODE_RIGHT] == true && currentKeyStates[SDL_SCANCODE_LEFT] == false) {
            incrementX(1);
        } else if(currentKeyStates[SDL_SCANCODE_LEFT] == true && currentKeyStates[SDL_SCANCODE_RIGHT] == false) {
            incrementX(-1);
        }
        if(currentKeyStates[SDL_SCANCODE_SPACE] == true) {
            //animation->load("herosad");
            animation->start("herosad.png", getId());
        }
        if(currentKeyStates[SDL_SCANCODE_Z]== true) {
            //SDL_Log("Z input detected");
            animation->start("herosinks.png", getId());
        }

}