|
本帖最后由 laotang365 于 2014-10-10 16:59 编辑
开始- static struct
- {
- float x, y; /* position of happyface */
- float xvel, yvel; /* velocity of happyface */
- } faces[NUM_HAPPY_FACES];
- /*
- Produces a random float x, min <= x <= max
- following a uniform distribution
- */
- static float randomFloat(float min, float max)
- {
- return rand() / (float) RAND_MAX * (max - min) + min;
- }
- static void initializeHappyFaces()
- {
- int i;
- for (i = 0; i < NUM_HAPPY_FACES; i++)
- {
- faces[i].x = randomFloat(0.0f, SCREEN_WIDTH - HAPPY_FACE_SIZE);
- faces[i].y = randomFloat(0.0f, SCREEN_HEIGHT - HAPPY_FACE_SIZE);
- faces[i].xvel = randomFloat(-0.4f, 0.4f);
- faces[i].yvel = randomFloat(-0.4f, 0.4f);
- }
- }
复制代码- static void minigame(void)
- {
- struct surface_t * screen;
- struct surface_t * obj;
- struct rect_t dstRect, srcRect;
- u32_t c;
- int i;
- u32_t startFrame, endFrame;
- u32_t delay;
- initializeHappyFaces();
- screen = s5pv210_screen_surface();//初始化图片的地址,速率。
- c = surface_map_color(screen, get_named_color("chocolate"));//得到咖啡色
- obj = surface_alloc_from_gimage(&obj_image);//得到图片的surface_t结构
- /* setup boundaries for happyface bouncing */
- u32_t maxx = SCREEN_WIDTH - HAPPY_FACE_SIZE;
- u32_t maxy = SCREEN_HEIGHT - HAPPY_FACE_SIZE;
- u32_t minx = 0;
- u32_t miny = 0;
- /* setup rects for drawing */
- srcRect.x = 0;
- srcRect.y = 0;
- srcRect.w = HAPPY_FACE_SIZE;
- srcRect.h = HAPPY_FACE_SIZE;
- dstRect.w = HAPPY_FACE_SIZE;
- dstRect.h = HAPPY_FACE_SIZE;
- while (1)
- {
- startFrame = jiffies;//标记cpu时刻为帧起始时刻
- s5pv210_screen_swap();//切换图层
- surface_fill(screen, &screen->clip, c, BLEND_MODE_REPLACE);//用咖啡色清屏
- for (i = 0; i < NUM_HAPPY_FACES; i++)
- {
- faces[i].x += faces[i].xvel * MILLESECONDS_PER_FRAME;//x += ((-0.4~0.4) * 20 )
- faces[i].y += faces[i].yvel * MILLESECONDS_PER_FRAME;//
- if (faces[i].x > maxx)//横坐标越界
- {
- faces[i].x = maxx;
- faces[i].xvel = -faces[i].xvel;
- }
- else if (faces[i].y > maxy)//纵坐标越界
- {
- faces[i].y = maxy;
- faces[i].yvel = -faces[i].yvel;
- }
- if (faces[i].x < minx)//横坐标越界
- {
- faces[i].x = minx;
- faces[i].xvel = -faces[i].xvel;
- }
- else if (faces[i].y < miny)//纵坐标越界
- {
- faces[i].y = miny;
- faces[i].yvel = -faces[i].yvel;
- }
- dstRect.x = faces[i].x;
- dstRect.y = faces[i].y;
- surface_blit(screen, &dstRect, obj, &srcRect, BLEND_MODE_REPLACE);//移动图片
- }
- s5pv210_screen_flush();
- endFrame = jiffies;
- delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame) * 10;//计算延时
- if (delay < 0)
- delay = 0;
- else if (delay > MILLESECONDS_PER_FRAME)
- delay = MILLESECONDS_PER_FRAME;
- mdelay(delay);//延时到帧间隔20ms
- }
- surface_free(obj);
- }
复制代码 完
|
|