cocos2d-x step by step(3) Double Kill
喏,咱们已经调通hello world 了,然后呢,咱们做一些高大上的东西,那做什么呢,做一个打乒乓球的小东西,啊哈!

这就是最终界面了,没画一个球形 就用一个白色方框代替吧。
啊哈!
public:
virtual bool init(); static cocos2d::Scene* scene();
void update(float dt) override; void menuCloseCallback(Ref* sender); void onButtonClicked(Ref *pSender,ui::Widget::TouchEventType type);
void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
CREATE_FUNC(FishTestScence);
首先呢,我们需要keypreed 和keyreleased 两个事件,因为要触发键盘事件
bool isUp = false;
bool isLeft = true;
bool isPreessLeft = false;
bool isPressRight = false;
bool isDead = true;
void FishTestScence::update(float dt)
{
if (isDead)return; const cocos2d::Vector<cocos2d::Node*> arr = this->getChildren();
Sprite* sprite1 = (Sprite*)arr.at();
Sprite* sprite2 = (Sprite*)arr.at(); if (ballPosition.x < )
{
isLeft = false;
}
else if (ballPosition.x > maxWidth)
{
isLeft = true;
} if (ballPosition.y < )
{
isUp = true;
}
else if (ballPosition.y > maxHeight)
{
isUp = false;
} isLeft ? ballPosition.x -= : ballPosition.x += ;
isUp ? ballPosition.y += : ballPosition.y -= ; if (isPreessLeft)dangbanVec.x -= ;
if (isPressRight)dangbanVec.x += ; if (((ballPosition.x - dangbanVec.x) > && ballPosition.y <= ) || ((ballPosition.x - dangbanVec.x) < - && ballPosition.y <= )) isDead = true; sprite1->setPosition(Vec2(dangbanVec.x, dangbanVec.y)); sprite2->setPosition(Vec2(ballPosition.x, ballPosition.y)); } // 键位响应函数原型
void FishTestScence::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{
const cocos2d::Vector<cocos2d::Node*> arr = this->getChildren();
Sprite* sprite1 = (Sprite*)arr.at();
Vec2 vec = sprite1->getPosition();
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
isPreessLeft = true;
break;
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
isPressRight = true;
break; default:
break;
}
} void FishTestScence::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
isPreessLeft = false;;
break;
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
isPressRight = false;
break;
case EventKeyboard::KeyCode::KEY_UP_ARROW:
isDead = false;
break;
default:
break;
}
}
这是代码实现,大概是这样的,当点击up箭头,游戏开始,当白色方块不在触板内,则game over ,用 isDead缓存
再次按up重新开始,
小东西,没什么技术含量,只是娱乐!
不写了,代码里有!
// create a scene. it's an autorelease object
auto scene = HelloWorld::scene();
auto fish = FishTestScence::scene();
// run
director->runWithScene(fish);
这里替换一下就行,图片如果没有的话 上一篇内有呢
烦死了!
妈蛋的淘宝,给姑娘买东西半天提示我重置密码和支付密码,老子重置了,浪费老子一个小时,还你妈比的不能买,qnmlgb!艹!
代码:源代码
cocos2d-x step by step(3) Double Kill的更多相关文章
- POJ 3243 Clever Y (求解高次同余方程A^x=B(mod C) Baby Step Giant Step算法)
不理解Baby Step Giant Step算法,请戳: http://www.cnblogs.com/chenxiwenruo/p/3554885.html #include <iostre ...
- 解高次同余方程 (A^x=B(mod C),0<=x<C)Baby Step Giant Step算法
先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝 扩展Baby Step Gian ...
- 【POJ2417】baby step giant step
最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...
- Step by step guide to set up master and slave machines(转)
Note: There is no need to install Jenkins on the slave machine. On your master machine go to Manage ...
- HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法
联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...
- enode框架step by step之事件驱动架构(EDA)思想的在框架中如何体现
enode框架step by step之事件驱动架构(EDA)思想的在框架中如何体现 上一篇文章,我给大家分享了我的一个基于DDD以及EDA架构的框架enode,但是只是介绍了一个大概.接下来我准备用 ...
- enode框架step by step之saga的思想与实现
enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...
- Step by step guide to set up master and slave machines on Windows
Note: There is no need to install Jenkins on the slave machine. On your master machine go to Manage ...
- Metrics.NET step by step使用Metrics监控应用程序的性能
使用Metrics监控应用程序的性能 在编写应用程序的时候,通常会记录日志以便事后分析,在很多情况下是产生了问题之后,再去查看日志,是一种事后的静态分析.在很多时候,我们可能需要了解整个系统在当前,或 ...
- HDU 2815 扩展baby step giant step 算法
题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...
随机推荐
- 全网最详细python中socket套接字send与sendall的区别
将数据发送到套接字. 套接字必须连接到远程套接字. 返回发送的字节数. 应用程序负责检查是否已发送所有数据; 如果仅传输了一些数据, 则应用程序需要尝试传递剩余数据.(需要用户自己完成) 将数据发送 ...
- TensorFlow TFRecord封装不定长的序列数据(文本)
TensorFlow TFRecord封装不定长的序列数据(文本) 在实验室环境中,通常数据都是一次性导入内存的,然后使用手工写的数据mini-batch函数来切分数据,但是这样的做法在海量数据下显得 ...
- URAL 1033 Labyrinth
E - Labyrinth Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submi ...
- ansible /usr/bin/python: not found
使用ansible命令的时候出错 ansible all -m ping 出现报错 192.168.199.154 | FAILED! => { "changed": fal ...
- 九度oj 题目1466:排列与二进制
题目描述: 在组合数学中,我们学过排列数.从n个不同元素中取出m(m<=n)个元素的所有排列的个数,叫做从n中取m的排列数,记为p(n, m).具体计算方法为p(n, m)=n(n-1)(n-2 ...
- 【转】Bad Smell(代码的坏味道)
1.Duplicated Code(重复的代码) 臭味行列中首当其冲的就是Duplicated Code.如果你在一个以上的地点看到相同的程序结构,那么当可肯定:设法将它们合而为一,程序会变得更好. ...
- Spring c3p0连接池通过Hibernate配置
首先进行Hibernate配置,详见http://www.cnblogs.com/claricre/p/6509931.html 然后调用这三个包. 配置hibernate.cfg.xml文件: &l ...
- Codeforces Round #345 (Div. 2)——A. Joysticks(模拟+特判)
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- C++ 错误解决 —— internal compiler error
问题: g++ 编译时,报错: g++: internal compiler error: Killed (program cc1plus) 出错原因: 出错的原因是(虚拟机)运行内存不足,而大量te ...
- 关于npm run dev和npm run build的问题
之前build打包好在我本地运行是没问题的,但是发给后端部署,他说我的路径有问题,这个是由于vue-cli默认的打包路径 的“/”根目录,由于文件没有部署到根目录所以出现了这个问题. 修改webpac ...