SRPG游戏开发(四十一)第九章 战斗系统 - 三 战斗动画(Combat Animation)

SRPG游戏开发(一)前言 返回目录 前言 从现在开始,本人将通过一系列的文章详细记录关于我的SRPG游戏的开发过程。由于涉及面可能很广泛,大概这会成为一个长期且不定期的坑。(是否半路弃坑都不得而知>_ 一、什么是SRPG游戏 SRPG,即为策略角色扮演游戏(Strategy Role-Playing Game)的简称,通常以战棋游戏呈现。在美国通常被称为“Tactical role-playing game 阅读详情

返回总目录

第九章 战斗系统(Combat System)

在SRPG中,大多数情况是指角色与角色之间的战斗。而这种战斗一般有两种模式:

  • 地图中直接战斗;

  • 有专门的战斗场景。

这两种模式的战斗在数据上没有任何区别,只有战斗动画的区别。

就像之前描述的,SRPG也是RPG,所以战斗方式和回合制RPG的战斗几乎是相同的。主要区别是RPG每个回合需要手动操作(也有自动战斗的),直到战斗结束;而SRPG是自动战斗,且多数情况只有一个回合(额外回合也是由于技能、物品或剧情需要)。且RPG多数是多人战斗,而SRPG多数是每边就一个。

我们这一章就来写一个战斗系统。



三 战斗动画(Combat Animation)

在之前,我们已经计算出所有的战斗数据,而且每一步的动画也进行了保存。这样,在这里就可以它们为基准来播放需要的动画。


1 战斗动画控制器(Combat Animation Controller)

同样,我们创建一个组件来控制播放动画(CombatAnimaController):

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace DR.Book.SRPG_Dev.CombatManagement
{
   
   
    using DR.Book.SRPG_Dev.Maps;

    [DisallowMultipleComponent, RequireComponent(typeof(Combat))]
    [AddComponentMenu("SRPG/Combat System/Combat Anima Controller")]
    public class CombatAnimaController : MonoBehaviour
    {
   
   
        private Combat m_Combat;

        public Combat combat
        {
   
   
            get
            {
   
   
                if (m_Combat == null)
                {
   
   
                    m_Combat = GetComponent<Combat>();
                }
                return m_Combat;
            }
        }

        // TODO 其它属性与方法
    }
}

它将依赖于Combat组件,所以添加了Attribute(RequireComponent(typeof(Combat)))。


2 控制器属性(Controller Properties)

在播放每一步(或者说角色每一次行动)时,我们需要一个时间间隔。如果连续播放可能会对感官有影响。

        [SerializeField]
        private float m_AnimationInterval = 1f;
        
        /// <summary>
        /// 每个动画的间隔时间
        /// </summary>
        public float animationInterval
        {
   
   
            get {
   
    return m_AnimationInterval; }
            set {
   
    m_AnimationInterval = value; }
        }

另外,在播放时我们采用Coroutine(当然,你也可以使用void Update(),并使用参数控制播放进程)。

        private Coroutine m_AnimaCoroutine;

        public bool isAnimaRunning
        {
   
   
            get {
   
    return m_AnimaCoroutine != null; }
        }

在最后,我们添加一些Combat的代理。

        public bool isCombatLoaded
        {
   
   
            get {
   
    return combat.isLoaded; }
        }

        public bool isBattleCalced
        {
   
   
            get {
   
    return combat.stepCount > 0; }
        }

        public int stepCount
        {
   
   
            get {
   
    return combat.stepCount; }
        }

        /// <summary>
        /// 初始化战斗双方
        /// </summary>
        /// <param name="mapClass0"></param>
        /// <param name="mapClass1"></param>
        /// <returns></returns>
        public bool LoadCombatUnit(MapClass mapClass0, MapClass mapClass1)
        {
   
   
            return combat.LoadCombatUnit(mapClass0, mapClass1);
        }

这些属性中,有一些不是必须的,这取决于你如何控制动画播放。


3 播放动画(Play Animation)

关于动画的播放,要了解一些情况:

  • 有一些动画并不是所有的游戏中都存在的(例如躲闪和爆击动画),相当一部分都只是弹出文字提醒,除此之外防守者没有动画;

  • 在地图上的攻击动画,需要注意方向问题,是使用四方向还是八方向?使用四方向时,斜线要注意朝向;

  • 还要记住,游戏的UI还没有写,动画中可能要通知UI播放UI动画;

  • 地图上的动画与单独场景的动画只会播放一个,取决于设置。

创建播放动画方法:

        /// <summary>
        /// 运行动画
        /// </summary>
        /// <param name="combat"></param>
        /// <param name="inMap"></param>
        public void PlayAnimas(bool inMap)
        {
   
   
            if (combat == null || !isCombatLoaded || isAnimaRunning)
            {
   
   
                return;
            }

            // 如果没有计算,则先计算
            if (!isBattleCalced)
            {
   
   
                combat.BattleBegin();
                if (!isBattleCalced)
                {
   
   
                    Debug.LogError("CombatAnimaController -> calculate error! check the `Combat` code.");
                    return;
                }
            }

            m_AnimaCoroutine = StartCoroutine(RunningAnimas(inMap));
        }

RunningAnimas(inMap)是播放动画的具体实现,我们暂时先不考虑单独场景的动画。

        private IEnumerator RunningAnimas(bool inMap)
        {
   
   
            if (inMap)
            {
   
   
                
SRPG游戏开发(十八)第六章 基本框架 - 三 消息事件系统(Message Center) 返回目录 第六章 基本框架(Framework) 三 消息事件系统(Message Center) 常见的消息事件系统,无外乎注册,注销和执行三个方法。基本都是大同小异。 这里也是相同的,只是把参数分离成单独一个类。 下面介绍几种常见方式,各有利弊,你可以使用1种或几种混用。 namespace DR.Book.SRPG_Dev.Framework { /// ... 阅读详情

相关推荐

SRPG游戏开发(十六)第六章 基本框架 - 一 本章简介(Introduction)

返回目录 第六章 基本框架(Framework) 这一章主要编写各个游戏都有的基本框架。 关于源码、打包好的dll文件还没有上传,如何使用它们的Example工程也没有上传。 先来介绍一下源码的各个文件,有个初步认识。 一 源码文件介绍 Author: DarKRabbit Blog: CSDN The introduction of files. 文件介绍 Si...

DarkRabbit的专栏 1479

SRPG游戏开发(二)第一章 FE4部分技术简述

  返回目录 第一章 FE4部分技术简述   本章节主要记录在开发FE4时,分析Rom的内容。我们从进入游戏后所见的顺序进行简述,详细的内容到开发时再谈论。   一    不再阐述的常用系统   这个部分的系统在所有游戏中都会出现,故不再详细阐述,编写代码时将从简。如果想要详细了解,可以搜索相关资料,非常的多。 视图系统(View/UI); 消息事件系统(Messag...

DarkRabbit的专栏 5180

SRPG游戏开发(二十三)第七章 寻路与地图对象 - 一 A*寻路算法(A* Search Algorithm)

返回总目录 第七章 寻路与地图对象(Path Finding and Map Object) 这一章主要进行寻路与地图对象的部分工作。 第七章 寻路与地图对象(Path Finding and Map Object) 一 A*寻路算法(A* Search Algorithm) 1 什么是A*寻路算法(Definition) 2 节点与格子信息(Node and Cell Data...

DarkRabbit的专栏 1714

SRPG游戏开发(六)第三章 绘制地图 - 三 创建自己的SrpgTile

返回目录 第三章 绘制地图 一        导入素材 http://blog.csdn.net/darkrabbit/article/details/79168225 二        绘制一张简单地图 http://blog.csdn.net/darkrabbit/article/details/79177935 三        创建自

DarkRabbit的专栏 3731

SRPG游戏开发(十九)第六章 基本框架 - 四 程序入口(Application Entry)

返回目录 第六章 基本框架(Framework) 四 程序入口(Application Entry) 游戏入口,一般来说,作用有初始化游戏和一些游戏配置属性。 在这里,我们的游戏入口类,也是同样的作用。 但我们同时将场景的操作也写入其中,作为SceneManager的扩展。 1 了解场景管理器(SceneManager) Unity管理场景的API都在SceneM...

DarkRabbit的专栏 1493

SRPG游戏开发(二十六)第七章 寻路与地图对象 - 四 地图对象(Map Object)

返回总目录 第七章 寻路与地图对象(Pathfinding and Map Object) 这一章主要进行寻路与地图对象的部分工作。 第七章 寻路与地图对象(Pathfinding and Map Object) 四 地图对象(Map Object) 1 抽象地图对象(MapObject.cs) 2 标注范围的光标(MapCursor.cs) 3 用户光标(MapMouseCur...

DarkRabbit的专栏 1270

可衔接的动画效果JHChainableAnimations

源码JHChainableAnimations,动画的问题,CAAnimations 和 UIView动画都非常强大,但我们很难把多个动画串联在一起,特别是当锚点有变化的时候。 此外,复杂的动画代码很难理解。比如,我想把 myView 向右跳跃移动50像素,然后当移动完成时向内过渡地更改背景颜色。

LoRa项目实战:手把手教你为ESP32选配和焊接天线(从PCB到信号测试)

本文详细介绍了为ESP32选配和焊接LoRa天线的全流程,包括天线选型、PCB布局设计、焊接工艺及信号测试。重点解析了PCB板载天线、导线天线和陶瓷贴片天线的适用场景与性能特点,并提供专业的焊接技巧和信号测试方案,帮助开发者优化LoRa模块的无线通信性能。

weixin_30470643的博客 406

波束形成算法:LCMV实现(MATLAB)

阵列信号处理,波束成形,

weixin_43601588的博客 1万+

【同花顺公式编辑教程】第4章 功能函数

本章节主要给出大部分能够运行且常用的同花顺指标编辑器提供的函数。其中,计算类函数不作演示,绘图类函数提供示例及示例运行结果。

LiaoYi2016218的博客 2万+

5分钟搞定!用FunASR在本地快速部署达摩院Paraformer语音识别模型(附常见问题解决)

本文详细介绍了如何在本地快速部署阿里达摩院开源的Paraformer语音识别模型。通过FunASR工具包,用户可在5分钟内完成环境配置、模型下载与基础识别,并掌握批量处理、性能调优及构建API服务等进阶技巧。文章重点解析了Paraformer的非自回归架构带来的速度优势,并提供了音频格式转换、依赖冲突、显存不足等常见问题的实战解决方案,助力开发者实现高效、离线的语音转写应用。

p1q2r的博客 715

【2026最新版】Open3D(C++)点云处理算法汇总(C++长期更新版)

C++版本Open3D进行点云处理的一些算法使用案例。博客长期更新,最近一次更新时间为:2026年4月11日。

点云侠的博客 1万+

基于STM32L4XX、HAL库的CH182H1以太网收发器(PHY)驱动程序设计

define PHY_REG_PHYSCR 0x12 // PHY特殊控制寄存器。#define PHY_REG_PHYSTS 0x10 // PHY状态寄存器。#define PHY_REG_PHYIDR 0x11 // PHY标识寄存器。#define PHY_REG_ID1 0x02 // PHY标识符1。#define PHY_REG_ID2 0x03 // PHY标识符2。

zhusl6688的博客 421

【swjtu】算法实验2.4分析算法时间复杂度

分析给定算法的时间复杂度。 上机实验,绘制不同输入情况下的运行时间曲线,并与(1)中的分析结果进行比较。 撰写相应的实验报告,实验报告内容包括:实验目的、实验任务、 实验环境、实验步骤、实验结果及其分析以及实验总结等部分内容。

qq_52046937的博客 739

RK3588开发板NPU加速YOLO目标检测完整实战教程

🚀 RK3588开发板NPU加速YOLO目标检测实战 本文详细介绍了如何在瑞芯微RK3588开发板上利用内置NPU加速YOLO目标检测的全流程: 1️⃣ 环境准备:配置RKNPU2 SDK和aarch64交叉编译器,搭建Ubuntu开发环境 2️⃣ 模型转换:从ONNX格式转换为专用RKNN模型,适配NPU硬件特性 3️⃣ 性能对比:NPU推理将处理时间从833ms降至50ms以下,帧率提升16倍 4️⃣ 实战应用:支持图像/视频流/摄像头实时检测,提供完整编译和运行命令 关键优势:专为边缘AI设计的6T

FJN110的博客 936

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: SRPG游戏开发(四十)第九章 战斗系统 - 二 计算战斗数据(Calculate Combat Data)
下一篇: SRPG游戏开发(四十二)第九章 战斗系统 - 四 计算战斗数据II(Calculate Combat Data II)
沙沙的兔子
博客等级 码龄17年 360粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值