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 ...
随机推荐
- ubuntu12.04安装wireshark
1 安装 $ sudo apt-get install wireshark 2 启动 $ sudo wireshark 3 启动报错
- INDEX && PRIMARY KEY && UNIQUE KEY
When I have do some sql tody, some confusion come up to me. Its about the index && PRIMARY K ...
- Prolog&Epilog
这篇博客会简单介绍一下Prolog&Epilog 然后再简单介绍下我对于程序在计算机中到底如何运行的一些理解(因为自己之前也从来没有接触过这些方面的知识,所以如果有讲的不对的地方希望大家能够帮 ...
- python 查看异常
接触python 一直觉着编译后报错经常没能捕捉显示,每次也只能从头看到尾 恰好在水木社区中看到关于异常捕捉帖子 方法一:捕获所有异常 try: a=b b=c except Exception,ex ...
- dubbo控制台在tomcat上的部署
1.下载dubbo-admin的war包,比如dubbo-admin-2.5.4.war 2.因为在tomcat上部署,所以务必确认安装了JDK和tomcat,以及配置好了环境变量. 3.将dubbo ...
- 使用python在校内发人人网状态(人人网看状态)_python
#_*_coding:utf_8_ from sgmllib import SGMLParserimport sys, urllib2, urllib, cookielibimport datetim ...
- python递归函数、二分法、匿名函数、(sorted、map、filter内置函数应用)
#函数递归是一种特殊的函数嵌套调用,在调用一个函数的过程中,又直接或间接的调用该函数本身递归必须要有两个明确的阶段: 递推:一层一层递归调用下去,强调每进入下一层递归问题的规模都必须有所减少 回溯:递 ...
- jQuery 样式操作、文档操作、属性操作的方法总结
文档操作: addClass() 向匹配的元素添加指定的类名.after() 在匹配的元素之后插入内容.append() ...
- dpkg: deb包的操作命令
dpkg -i package.deb #安装包 dpkg -r package #删除包 dpkg -P package #删除包(包括配置文件) dpkg -L package #列出与该包关联的 ...
- 刷题总结——advanced fruits(hud1503)
题目: The company "21st Century Fruits" has specialized in creating new sorts of fruits by t ...