当前位置:网站首页>Cocos2d Lua smaller and smaller sample memory game
Cocos2d Lua smaller and smaller sample memory game
2022-07-06 18:25:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
1. Introduction to the game
One ” memory ” Class game . You fight against the computer , Whose turn is it , Who turns two cards , Suppose two cards are the same . Just eliminate these two cards , have to 2 branch , Can continue to flip , Suppose two cards are different , Just another person . Until the last . Look who scores high .
Game design ideas can be seen in this article 《Cocos2d Game state machine 》
2. Lua Simple object oriented
We know Lua It's script language , Not really an object-oriented language . But object-oriented seems to make the code structure more reasonable .Javascript, Lua Can simulate object-oriented .Lua There are many ways to realize object orientation , Of course, there is no introduction here .
Simply look at inheritance Sprite Writing . Copy official .
MatchCard = class("Match",function (spriteFrameName, value)
MatchCard.value = value //-- attribute
return cc.Sprite:createWithSpriteFrameName("MatchCardBg.png")
end)
MatchCard.test= true //-- attribute
//-- One way
function MatchCard:containsTouchLocation(x,y)
local position = cc.p(self:getPosition())
local s = self:getContentSize()
local touchRect = cc.rect(-s.width / 2 + position.x, -s.height / 2 + position.y, s.width, s.height)
local b = cc.rectContainsPoint(touchRect,cc.p(x,y))
return b
end
//--new An object , Of course, this is the same as c++ The kind of different
local card = MatchCard.new()
//-- Calling method
card:containsTouchLocation()
3.Cocos Code Ide establish Lua project
My game uses Cocos Code Ide Created . Fairly smooth .API Refer to Lua-Tests That's all. .
The overall is the same . I haven't played yet Quick cocos2d-x.
4.cocos2d lua Use feeling
Use Cocos2d-x Of C++ Programming is the most comfortable , Even though C++ Grammar is hard to write . But I don't easy Encounter very strange Bug. The compilation speed is too slow , It's hard to cooperate with the planner . image Js, and Lua, You have defined some writing methods . Planning can also be written directly Js and Lua,C++ No way. . also Cocos2d-x C++ Can use the latest version number , transplant Android and IOS No problem .
also Cocos2d-x C++ I feel I can write high-quality code . also VS2012 Very easy to use .
Lua,JS It's all script language , It is used to develop games very fast .
There is no need to compile . Just get used to it C++ That kind of disciplined object-oriented , Write Lua,JS Object orientation is always weird .Debug Sometimes relative C++ Relatively difficult .cocos2d JS Or use it WebStorm Writing is cool .Cocos Code Ide Follow VS2012 and WebStorm There is still a gap , Some aspects are integrated Cocos Game framework for , So some aspects are easier to use .
5. Dynamic diagram and project source code download
I am right. Lua Less use , I feel the writing is poor , Too many global variables . Project download address :
exe Can directly execute in /runtime/win32/MatchGame.exe, I won't support it XP,Win7 Should be able to .
http://www.waitingfy.com/archives/1289
Copyright notice : This article is an original blog article , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117397.html Link to the original text :https://javaforall.cn
边栏推荐
- Recursive way
- POJ 2208 已知边四面体六个长度,计算体积
- 第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
- A method of sequentially loading Unity Resources
- Interview shock 62: what are the precautions for group by?
- STM32+HC05串口蓝牙设计简易的蓝牙音箱
- Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
- 2019阿里集群数据集使用总结
- [Android] kotlin code writing standardization document
- 1700C - Helping the Nature
猜你喜欢
Four processes of program operation
递归的方式
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
Why does wechat use SQLite to save chat records?
简单易用的PDF转SVG程序
Coco2017 dataset usage (brief introduction)
CSRF vulnerability analysis
IP, subnet mask, gateway, default gateway
Declval (example of return value of guidance function)
declval(指导函数返回值范例)
随机推荐
[the 300th weekly match of leetcode]
78 year old professor Huake has been chasing dreams for 40 years, and the domestic database reaches dreams to sprint for IPO
具体说明 Flume介绍、安装和配置
Maixll dock camera usage
celery最佳实践
【剑指 Offer】 60. n个骰子的点数
echart简单组件封装
Declval of template in generic programming
解读云原生技术
std::true_type和std::false_type
小程序在产业互联网中的作用
Grafana 9.0 正式发布!堪称最强!
Jerry's watch reads the file through the file name [chapter]
The difference between parallelism and concurrency
传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
bonecp使用数据源
CRMEB 商城系统如何助力营销?
Declval (example of return value of guidance function)
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
Jerry's setting currently uses the dial. Switch the dial through this function [chapter]