当前位置:网站首页>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
边栏推荐
- 【LeetCode第 300 场周赛】
- Implementation of queue
- 2022暑期项目实训(二)
- Splay
- Reprint: defect detection technology of industrial components based on deep learning
- Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
- 2022/02/12
- 微信为什么使用 SQLite 保存聊天记录?
- Common - magic number 7
- 递归的方式
猜你喜欢
![[the 300th weekly match of leetcode]](/img/a7/16b491656863e2c423ff657ac6e9c5.png)
[the 300th weekly match of leetcode]
![Jerry's updated equipment resource document [chapter]](/img/6c/17bd69b34c7b1bae32604977f6bc48.jpg)
Jerry's updated equipment resource document [chapter]

Why does wechat use SQLite to save chat records?

Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...

UDP协议:因性善而简单,难免碰到“城会玩”

Take you through ancient Rome, the meta universe bus is coming # Invisible Cities

Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock

從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...

C language exchanges two numbers through pointers

Top command details
随机推荐
Wchars, coding, standards and portability - wchars, encodings, standards and portability
Maixll-Dock 摄像头使用
关于这次通信故障,我想多说几句…
F200 - UAV equipped with domestic open source flight control system based on Model Design
win10系统下插入U盘有声音提示却不显示盘符
Interesting - questions about undefined
Penetration test information collection - CDN bypass
2022暑期项目实训(二)
递归的方式
阿里云国际版ECS云服务器无法登录宝塔面板控制台
Markdown grammar - better blogging
Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery
Jerry is the custom background specified by the currently used dial enable [chapter]
Dichotomy (integer dichotomy, real dichotomy)
Redis的五种数据结构
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
關於這次通信故障,我想多說幾句…
Cocos2d Lua 越来越小样本 内存游戏
DNS hijacking
STM32+ENC28J60+UIP协议栈实现WEB服务器示例