喏,咱们已经调通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的更多相关文章

  1. 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 ...

  2. 解高次同余方程 (A^x=B(mod C),0<=x<C)Baby Step Giant Step算法

    先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝  扩展Baby Step Gian ...

  3. 【POJ2417】baby step giant step

    最近在学习数论,然而发现之前学的baby step giant step又忘了,于是去翻了翻以前的代码,又复习了一下. 觉得总是忘记是因为没有彻底理解啊. 注意baby step giant step ...

  4. 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 ...

  5. HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法

    联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  6. enode框架step by step之事件驱动架构(EDA)思想的在框架中如何体现

    enode框架step by step之事件驱动架构(EDA)思想的在框架中如何体现 上一篇文章,我给大家分享了我的一个基于DDD以及EDA架构的框架enode,但是只是介绍了一个大概.接下来我准备用 ...

  7. enode框架step by step之saga的思想与实现

    enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...

  8. 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 ...

  9. Metrics.NET step by step使用Metrics监控应用程序的性能

    使用Metrics监控应用程序的性能 在编写应用程序的时候,通常会记录日志以便事后分析,在很多情况下是产生了问题之后,再去查看日志,是一种事后的静态分析.在很多时候,我们可能需要了解整个系统在当前,或 ...

  10. HDU 2815 扩展baby step giant step 算法

    题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/2 ...

随机推荐

  1. 在spring boot中使用webSocket组件(二)

    该篇演示如何使用websocket创建一对一的聊天室,废话不多说,我们马上开始! 一.首先先创建前端页面,代码如下图所示: 1.login.html <!DOCTYPE html> < ...

  2. luogu1939 【模板】矩阵加速(数列)

    upd:现在推荐使用一个长度为 \(n\) 的一维向量.若状态矩阵 \(F\) 对下一时间的状态矩阵 \(F'\) 有影响,则 \(F'=FA\) 中的 转移矩阵 \(A\) 的赋值方法是: 若状态矩 ...

  3. Eclipse下创建Spring MVC web程序--maven版

    1. 创建一个maven工程: File->New->Other... 2. 创建完成后的结构如下: 3. 配置pom.xml文件,添加spring-webmvc依赖项   <pro ...

  4. 老男孩全栈python学习进程表

     老男孩Python高级全栈开发工程师-1  0001.开学典礼_ALEX简介  00:55:53 ☆  0002.职业生涯_来培训的目的  01:12:29 ☆  0003.课程目标  00:29: ...

  5. AtCoder Regular Contest 064 F - Rotated Palindromes

    Problem Statement Takahashi and Aoki are going to together construct a sequence of integers. First, ...

  6. LaTeX Hierarchical Tables

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52692655 简单整理一下表格中的分级 ...

  7. js的编码函数

    js对文字进行编码,涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent ...

  8. curl 设置头部

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...

  9. 用-webkit-box-reflect制作倒影

    1.只在webkit内核的浏览器上有效果 2.语法: -webkit-box-reflect: <direction> <offset> <mask-box-image& ...

  10. ACM程序设计选修课——Problem E:(ds:图)公路村村通(Prim)

    问题 E: (ds:图)公路村村通 时间限制: 1 Sec  内存限制: 128 MB 提交: 9  解决: 5 题目描述 现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本, ...