Esempio n. 1
0
/* 基本动作——指定方向移动一步 */
void step(Person * x)
{
	int i = x->positionx;
	int j = x->positiony;
	
	switch(x->direction)
	{
	case DIR_RIGHT:
		if(i+1<POSWIDTH)
		{
			map[j][i] = 0;
			x->positionx = i+1;
		}
		break;
	case DIR_UP:
		if(j-1>=0)
		{
			map[j][i] = 0;
			x->positiony=j-1;
		}
		break;
	case DIR_LEFT:
		if(i-1>=0)
		{
			map[j][i] = 0;
			x->positionx = i-1;
		}
		break;
	case DIR_DOWN:
		if(j+1<POSHEIGHT)
		{
			map[j][i] = 0;
			x->positiony=j+1;
		}
		break;
	default:
		break;
	}

	drawing();
	drawPerson(&xiaoming);
	drawPerson(&xiaohong);
	return ;
}
Esempio n. 2
0
int main () {
	int x, y, dx, dy, radius = 100;
	double pi, i = 0.07;
	char c;

	pi = M_PI;

	gfx_open(500,500,"Rotating Animation Emily");

	printf("To speed up display press f key; to slow down display press s key.\n");

	while (1) {
			drawPerson();

			x = radius*cos(i) + 250;
			y = radius*sin(i) + 150;
			gfx_color(0, 0, 255);
			gfx_circle(x, y, 20); //ball 1 (blue)
		
			x = radius*cos(i+1.5) + 250;
			y = radius*sin(i+1.5) + 150;
			gfx_color(0, 255, 0);
			gfx_circle(x, y, 20); //ball 2 (green)

			x = radius*cos(i+3.) + 250;
			y = radius*sin(i+3.) + 150;
			gfx_color(255, 0, 0);
			gfx_circle(x, y, 20); //ball 3 (red)
			

			gfx_flush();
			usleep(10000);
			gfx_clear();
			

			if (gfx_event_waiting()) {
				c = gfx_wait();
				if (c =='s') { //slows down juggling
					i-=0.1;
				} else if (c =='f') { //speeds  juggling
					i+=0.1;
				} else if (c =='q') {
					break;
				}
			}

			i+= 0.01;
		}

	
	

	return 0;
}
Esempio n. 3
0
/* 根据map中的数值显示绘图区域 */
void drawing()
{
	int i, j;
	for(j=0;j<POSHEIGHT;j++)
		for(i=0;i<POSWIDTH;i++)
		{
			if(map[j][i]==1)
			{
				putimage(i*IMGWIDTH,j*IMGHEIGHT,&WallImg);
			}
			else
			{
				putimage(i*IMGWIDTH,j*IMGHEIGHT,&BlankImg);
			}
		}
	putimage(endx*IMGWIDTH,endy*IMGHEIGHT,&EndImg);

	drawPerson(&xiaoming);
	drawPerson(&xiaohong);
}
Esempio n. 4
0
void Mazer::goAhead()					  //声明向当前方向前进的方法
{
	switch(forward)
	{
	case NORTH: moveNorth(); break;
	case WEST:  moveWest();  break;
	case SOUTH: moveSouth(); break;
	case EAST:  moveEast();  break;
	default: cout << "方向不明,无法前进。" << endl;
	}
	drawPerson();
	if(MazeMap::checkMazeDoor(m_iPosX, m_iPosY))
	{
		gotoxy(0,10);
		cout << "哈哈,终于出来啦!" << endl;
		outOrNot = true;
	}
}
Esempio n. 5
0
/*  drawGrid()

Draws the map, and people.

*/
void drawGrid ()
{
	PERSON *thePerson = personHeader;
	int y;
	int x;
	int i;
   for (y = 0; y < mapWidth; y++)
   {
        for (x = 0; x < mapWidth; x++)
        {
				//Draw the squares
        		draw_sprite(screenBuffer, aMapSquare[x][y].picture, placeOnGridX(x, y), placeOnGridY(x, y) - anObject[aMapSquare[x][y].objectType].printOffset);
            drawHistogram(x,y);

				/*	Drawing people
				Because people are always moving, ther can be no fixed order for printing them.
				Instead, they are constantly sorted, and once sorted, this loop prints them.
				They are sorted by gridX and gridY, in the same order as the squares.
				Thus, while stepping though the squares, you can step through the list of people
				and print all of them until  you reach the next square
				*/
				while (thePerson != NULL && thePerson->gridY == y && thePerson->gridX == x)
				{
               drawPerson(thePerson);
					thePerson = thePerson->next;
    			}
			}
   }
	if(showPersonInfo)
	{
		for(i = 0; i < NUMRESOURCES; i++)
		{
			if (selectionX != -1 && selectionY != -1){
				if (aMapSquare[selectionX][selectionY].walker[i] != NULL)
				{
					thePerson = aMapSquare[selectionX][selectionY].walker[i];
					line(screenBuffer, thePerson->x + cameraX, thePerson->y + cameraY - 15, placeOnGridX(selectionX, selectionY) + squareWidth/2,  placeOnGridY(selectionX, selectionY) + squareWidth/4, resourceColour[i]);
				}
			}
		}
	}
}
Esempio n. 6
0
/*
 * 函数名称:goAhead
 * 函数功能:朝当前的前方走一步
 * 返回内容:无
 */
void MazePerson::goAhead()
{
	switch(forward)
	{
	case NORTH: moveNorth(); break;
	case WEST:  moveWest();  break;
	case SOUTH: moveSouth(); break;
	case EAST:  moveEast();  break;
	default: cout << "方向不明,无法前进。" << endl;
	}
	//形成动画
	drawPerson();
	//检测是否到达出口
	//如果到达出口,则提示
	if(MazeMap::checkMazeDoor(positionX, positionY))
	{
		gotoxy(0,22);
		cout << "哈哈,终于出来啦!" << endl;
		outOrNot = true;
	}
}
Esempio n. 7
0
/* first we see if we even need to draw by checking if it is
   in the camera, via cameraGetLoc()
   cameraGetLoc() returns a drawable rect (if camera is zoomed it needs to translate)
   which draw can use.

   DRAW SHOULD NEVER AFFECT GAME WORLD
*/
void drawObject(dioneObject *obj) {
	SDL_Rect drawable;
	SDL_bool in_camera;

	in_camera = cameraGetLoc(&(obj->l), &drawable);
	if (in_camera == SDL_FALSE) {
		return;
	}
	/* drawable is now in pixels not world units.
	   We can just draw it like it is! */
	switch (TYPEOF(obj)) {
	case OBJ_LINE:
		drawLine((lineObject*)obj, &drawable);
		break;
	case OBJ_PEOPLE:
		drawPerson((humanObject*)obj, &drawable);
		break;
	case OBJ_WAVE:
		drawWave((waveObject*)obj, &drawable);
		break;
	case OBJ_CUSTOM:
		(((customObject*)obj)->drawFunc)(obj);
		break;
	case OBJ_POLY:
		drawPoly((polyObject*)obj, &drawable);
		break;
	case OBJ_BEZIER:
		drawBezier((bezierObject*)obj, &drawable);
		break;
	case OBJ_TEXTURE:
		drawTexture((textureObject*)obj, &drawable);
		break;
	case OBJ_TEXT:
		drawText((textObject*)obj, &drawable);
		break;
	default:
		/* I never want to be here */
		print_message(MSG_VERBOSE_ERROR, MSG_FLAG_NONE, "[draw] I have no idea how to handle this obj: %x!", obj);
	}
}
Esempio n. 8
0
void display(void )
{
	glClear(GL_COLOR_BUFFER_BIT);

	for(int i=0;i<GROUP_NUM;i++)
	{
		glColor3f(map.groupPtr[i]->color[0],map.groupPtr[i]->color[1],map.groupPtr[i]->color[2]);
		for(int j=0;j<GROUP_PEOPLE;j++)
		{
			if(map.groupPtr[i]->people_list[j].pos[0]<MAP_WIDTH && 
				map.groupPtr[i]->people_list[j].pos[0]>0 &&
				map.groupPtr[i]->people_list[j].pos[1]<MAP_HEIGHT &&
				map.groupPtr[i]->people_list[j].pos[1]>0 )
			drawPerson(map.groupPtr[i]->people_list[j].pos[0], map.groupPtr[i]->people_list[j].pos[1]);
		}
	}

	map.update();

	glFlush();
	glutSwapBuffers();
}