24小时热门版块排行榜    

查看: 669  |  回复: 0

cean

金虫 (职业作家)

屌绳一条

[交流] 写个类似Candy Crush Saga的游戏

感觉Candy Crush Saga挺好玩。想着自己怎么写一个。先实现最简单的,3X3的格子,只有圆形,颜色可以不同。
用手指滑动移动圆。

初步的滑动代码,某个圆可在上下左右4方向中任一个方向移动。
CODE:
//the coordinates of the start of the gesture,
//     end of gesture and velocity in pixels/sec
void onFlick( float x, float y, float px, float py, float v)
{
  int imove;
  float idir,jdir;
  float dist;
  float dx,dy;
  
  imove=-1;
  idir=0.0;
  jdir=0.0;
  for (int i = 0; i < count; i++) {
    dx=x-ball[i].x;
    dy=y-ball[i].y;
    dist=sqrt(dx*dx+dy*dy);
    if (dist<unit) {
       imove=i;
   
     if (abs(dx)>1.5*abs(dy)) {
      if (dx>0.0) {
        idir=1.0;
      } else {
        idir=-1.0;
      }
      jdir=0.0;
     }
     
     if (abs(dy)>1.5*abs(dx)) {
      if (dy>0.0) {
        jdir=1.0;
      } else {
        jdir=-1.0;
      }
      idir=0.0;
     }
    }
   
  }
  
  if (imove>-1) {
     //print( x+" "+y+" "+ball[imove].x+" "+ball[imove].y);
     print (idir+","+jdir);
     ball[imove].x=ball[imove].x+idir*unit;
     ball[imove].y=ball[imove].y+jdir*unit;
  }
   
}

回复此楼

» 猜你喜欢

To do great work, you have to have a pure mind.
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

找到一些相关的精华帖子,希望有用哦~

科研从小木虫开始,人人为我,我为人人
相关版块跳转 我要订阅楼主 cean 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见