Cocos2dx 3.0 过渡篇(二十四)死不了的贪食蛇(重力版)(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-04-20 03:36 点击:次
3)通过draw()绘制游戏界面的格子与食物等
尊重原创,转载请注明来源:http://blog.csdn.net/start530/article/details/23707985
void GameLayer::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
///绘制形状
::glLineWidth(2);//设定画线的宽度
for(int i=0;i<11;i++)
{
DrawPrimitives::drawLine(Point(0,i*32),Point(320,i*32));//绘制条横线
DrawPrimitives::drawLine(Point(i*32,0),Point(i*32,320));//绘制条竖线
}
// RGBA
//DrawPrimitives::drawColor4B(ccc4(255,0,0,255));//设定画线的颜色
//绘制蛇头
DrawPrimitives::drawSolidRect(Point(sHead->col*32+2,sHead->row*32+2),
Point(sHead->col*32+32,sHead->row*32+32),
Color4F(Color3B(255,0,0)));
//绘制食物
DrawPrimitives::drawSolidRect(Point(sFood->col*32+2,sFood->row*32+2),
Point(sFood->col*32+32,sFood->row*32+32),
Color4F(Color3B(0,0,255)));
//绘制身体
for(int i=0;icol*32+2,node->row*32+2),
Point(node->col*32+32,node->row*32+32),
Color4F(Color3B(0,0,255)));
}
/*Rect r(340,0,57,57);
chead->drawInRect(r);
Layer::draw();*/
}4)通过重力的回调函数来更新蛇的移动方向void GameLayer::onAcceleration(Acceleration* acc, Event* event)
{
//0.5这东西很微妙的说
if(acc->x<=-0.5)
{
sHead->dir=DIR_DEF::LEFT;
log("LEFT");
}
else if(acc->x>=0.5)
{
sHead->dir=DIR_DEF::RIGHT;
log("RIGHT");
}
else if(acc->y<=-0.5)
{
sHead->dir=DIR_DEF::DOWN;
log("DOWN");
}
else if(acc->y>=0.5)
{
sHead->dir = DIR_DEF::UP;
log("UP");
}
else
{
;
}
}恩,差不都就是这样了。最后附上游戏截图,如果觉得游戏画面您还满意的话,请给我点32个赞!谢谢!~:

看到这里有的人可能要吐槽了,为什么没有写当蛇撞到尾巴会结束游戏的处理。原因很简单,因为我...懒...。就如开头说的那样,该篇的主要目的是通过一个例子来较为系统的介绍cocos2dx2.0与3.0一些不同的地方。
尊重原创,转载请注明来源:http://blog.csdn.net/start530/article/details/23707985
尊重原创,转载请注明来源:http://blog.csdn.net/start530/article/details/23707985
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>

![cocos2d_x+lua[2]](/uploads/allimg/131030/110J64609-0-lp.jpg)








