官方Match3解析——开篇

[复制链接]
查看4137 | 回复10 | 2017-5-18 09:50:03 | 显示全部楼层 |阅读模式
——个人版权 严禁转载 和 商业用途
我在知乎准备发布的文章 刚起头 先发在论坛 各位大拿 有建议 错误 请无情指摘 在此谢谢!
Hello大家好!
我是小FC,因为官方文档对于Match3简述过于含糊,官方视频在国内并不能正常观看。网上对于一款成熟Match3游戏核心逻辑描述零零散散。自己花费一些时间,对Match3代码仔细梳理,分为三篇 从 ‘基础游戏算法分析’ 到 ‘游戏流程逻辑分析’ 最后的 ‘整个游戏系统设计’。
希望未来成为游戏设计师的小伙伴 从小做起砥砺自己,未来做出伟大的游戏作品。——千里之行,始于足下
适合读者:
有c++基础和对UE4API一定的熟悉度
闲话不多说 正文开始:
总览:
翻看官方代码结构如下:在第一章 重点解析的是Grid 和 Tile中核心游戏逻辑,Match3Controller、Match3Gamemode、Match3GameInstance这几块重要的部分会在随后的文章逐步解析。Grid和Tile组成Match3的'天和地',掌握梳理棋盘和棋子逻辑是走入大门的第一步。
(一)Tile
(1)TileAbilities
官方Match3中大家看到六种不一样的Tile。它们都是从这个爸爸继承过去的儿子,龙生九子,六种Tile外貌不同,能力也不尽相同。
相同点:每个Tile下面没有兄弟支撑的时候都会下落。
不同点:比如石头Tile性情冷淡对玩家也爱理不理和其他兄弟也不互动,炸弹Tile脾气火爆一点就炸有时候带着其他炸弹兄弟搞爆破,红绿蓝黄Tile四兄弟性情温和,兄弟之间交换互动。
试联想下 这些Tile具有的基本能力是什么。如果让你做一个基础类的设计者,基础的爸爸类,都包含哪些能力那?
聪明的设计师把Tile是否能进行交换,会爆炸的能力抽象出来一个struct FTileAbilities 代码如下:
USTRUCT()struct FTileAbilities{        GENERATED_USTRUCT_BODY();        bool CanExplode() { return bExplodes; }        bool CanSwap() { return (!bPreventSwapping && !bExplodes); }protected:        /** Tile explodes when selected (change this!) */        UPROPERTY(EditAnywhere, BlueprintReadWrite)        uint32 bExplodes : 1;        /** Tile can't be selected as part of a normal swapping move. */        UPROPERTY(EditAnywhere, BlueprintReadWrite)        uint32 bPreventSwapping : 1;public:        /** Power rating of a bomb. What this means is determined in GameMode code, and can consider what kind of bomb this is. */        UPROPERTY(EditAnywhere, BlueprintReadWrite)        int32 BombPower;};
尽管石头Tile不理会玩家的‘戳’,我们的爸爸Tile依然具有这样的能力。由两个函数设置了对Tile的监听——我们什么时候被玩家选中呀!代码如下:
void ATile::TilePress(ETouchIndex::Type FingerIndex, AActor* TouchedActor){        // We clicked or touched the tile.        if (!UGameplayStatics::IsGamePaused(this) && Grid)        {                Grid->OnTileWasSelected(this);        }}void ATile::TileEnter(ETouchIndex::Type FingerIndex, AActor* TouchedActor){        // We have moved into the tile's space while we had a different tile selected. This is the same as pressing the tile directly.        // Note that we need to make sure it's a different actual tile (i.e. not NULL) because deselecting a tile by touching it twice will then trigger the TileEnter event and re-select it.        if (!UGameplayStatics::IsGamePaused(this) && Grid)        {                ATile* CurrentlySelectedTile = Grid->GetCurrentlySelectedTile();                if (CurrentlySelectedTile && (CurrentlySelectedTile != this))                {                        TilePress(FingerIndex, TouchedActor);                }        }}
在Tile被生出来 我们就在BeginPlay中将这两个函数加入InputComponent组件中,一旦发现被戳我们就运行我们的函数.代码如下:
void ATile::BeginPlay(){        Super::BeginPlay();                Grid = Cast<AGrid>(GetOwner());        // Set our class up to handle touch events.        OnInputTouchBegin.AddUniqueDynamic(this, &ATile::TilePress);        OnInputTouchEnter.AddUniqueDynamic(this, &ATile::TileEnter);}
(2)Tile Falling
Tile第二个重要的能力Falling——Tile被玩家干掉 获取分数,其他存活的Tile没有其他兄弟支撑,就会下落到有兄弟支撑地方。
刚起头到这个位置!

yangh1 | 2017-5-18 09:50:53 | 显示全部楼层
代码直接从知乎复制过来的一团浆糊 各位见谅哈
回复 支持 反对

使用道具 举报

跃动的光子 | 2017-5-19 12:02:57 | 显示全部楼层
知乎链接呢
回复 支持 反对

使用道具 举报

yangh1 | 2017-5-19 12:53:40 | 显示全部楼层

文章刚起头 没有发布
回复 支持 反对

使用道具 举报

yangh1 | 2017-5-19 12:54:14 | 显示全部楼层
感觉要沉贴
回复 支持 反对

使用道具 举报

wtda | 2017-5-19 14:29:37 | 显示全部楼层
求发知乎 求知乎链接
回复 支持 反对

使用道具 举报

堕落的牧羊人 | 2017-5-20 19:05:53 | 显示全部楼层
谢谢分享谢谢分享
回复 支持 反对

使用道具 举报

yangh1 | 2017-5-21 17:42:48 | 显示全部楼层
wtda 发表于 2017-5-19 14:29
求发知乎 求知乎链接

初稿 未发
回复 支持 反对

使用道具 举报

yangh1 | 2017-5-21 17:43:14 | 显示全部楼层

。。。。
回复 支持 反对

使用道具 举报

堕落的牧羊人 | 2017-5-31 00:11:28 | 显示全部楼层
谢谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

5

主题

126

回帖

849

积分

初阶编码师

积分
849