本文主要是介绍(结对编程)基于unity3d游戏引擎的魔方游戏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
unity3d魔方游戏
结对编程成员:
姓名:王曦 学号:2012211834
姓名:万炼炼 学号:2012211474
王曦的心得:
软件工程第二次作业的结对编程,我和我的队友万炼炼设计了一个基于unity3d的魔方游戏,通过在网上边学习边操作的方式,了解了unity3d游戏引擎的基本机制, 同时也深刻体会到要做出一个软件,团队合作的重要性。在这次结对编程中,我主要担任的是代码的编写,以及游戏逻辑的设计。万炼炼同学主要负责的是游戏资源的管理,以及游戏的整体设计。unity是一款强大的3d游戏引擎,目前市面上大部分流行的3d游戏都可以用u3d来设计,我们设计的魔方游戏虽然简单,但也付出了一定的心血,其中涉及到对每一层魔方的旋转,还包括横向旋转和竖向旋转。在游戏中还要兼顾到玩家的体验,比如在游戏中可以旋转视图来让玩家更好地来观察魔方的几个面的变化。
游戏开发界面:
主要的脚本程序:
#endregion #region Easing Curvesprivate float linear(float start, float end, float value){return Mathf.Lerp(start, end, value);}private float clerp(float start, float end, float value){float min = 0.0f;float max = 360.0f;float half = Mathf.Abs((max - min) / 2.0f);float retval = 0.0f;float diff = 0.0f;if ((end - start) < -half){diff = ((max - start) + end) * value;retval = start + diff;}else if ((end - start) > half){diff = -((max - end) + start) * value;retval = start + diff;}else retval = start + (end - start) * value;return retval;}private float spring(float start, float end, float value){value = Mathf.Clamp01(value);value = (Mathf.Sin(value * Mathf.PI * (0.2f + 2.5f * value * value * value)) * Mathf.Pow(1f - value, 2.2f) + value) * (1f + (1.2f * (1f - value)));return start + (end - start) * value;}private float easeInQuad(float start, float end, float value){end -= start;return end * value * value + start;}private float easeOutQuad(float start, float end, float value){end -= start;return -end * value * (value - 2) + start;}private float easeInOutQuad(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return end / 2 * value * value + start;value--;return -end / 2 * (value * (value - 2) - 1) + start;}private float easeInCubic(float start, float end, float value){end -= start;return end * value * value * value + start;}private float easeOutCubic(float start, float end, float value){value--;end -= start;return end * (value * value * value + 1) + start;}private float easeInOutCubic(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return end / 2 * value * value * value + start;value -= 2;return end / 2 * (value * value * value + 2) + start;}private float easeInQuart(float start, float end, float value){end -= start;return end * value * value * value * value + start;}private float easeOutQuart(float start, float end, float value){value--;end -= start;return -end * (value * value * value * value - 1) + start;}private float easeInOutQuart(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return end / 2 * value * value * value * value + start;value -= 2;return -end / 2 * (value * value * value * value - 2) + start;}private float easeInQuint(float start, float end, float value){end -= start;return end * value * value * value * value * value + start;}private float easeOutQuint(float start, float end, float value){value--;end -= start;return end * (value * value * value * value * value + 1) + start;}private float easeInOutQuint(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return end / 2 * value * value * value * value * value + start;value -= 2;return end / 2 * (value * value * value * value * value + 2) + start;}private float easeInSine(float start, float end, float value){end -= start;return -end * Mathf.Cos(value / 1 * (Mathf.PI / 2)) + end + start;}private float easeOutSine(float start, float end, float value){end -= start;return end * Mathf.Sin(value / 1 * (Mathf.PI / 2)) + start;}private float easeInOutSine(float start, float end, float value){end -= start;return -end / 2 * (Mathf.Cos(Mathf.PI * value / 1) - 1) + start;}private float easeInExpo(float start, float end, float value){end -= start;return end * Mathf.Pow(2, 10 * (value / 1 - 1)) + start;}private float easeOutExpo(float start, float end, float value){end -= start;return end * (-Mathf.Pow(2, -10 * value / 1) + 1) + start;}private float easeInOutExpo(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return end / 2 * Mathf.Pow(2, 10 * (value - 1)) + start;value--;return end / 2 * (-Mathf.Pow(2, -10 * value) + 2) + start;}private float easeInCirc(float start, float end, float value){end -= start;return -end * (Mathf.Sqrt(1 - value * value) - 1) + start;}private float easeOutCirc(float start, float end, float value){value--;end -= start;return end * Mathf.Sqrt(1 - value * value) + start;}private float easeInOutCirc(float start, float end, float value){value /= .5f;end -= start;if (value < 1) return -end / 2 * (Mathf.Sqrt(1 - value * value) - 1) + start;value -= 2;return end / 2 * (Mathf.Sqrt(1 - value * value) + 1) + start;}private float easeInBounce(float start, float end, float value){end -= start;float d = 1f;return end - easeOutBounce(0, end, d-value) + start;}private float easeOutBounce(float start, float end, float value){value /= 1f;end -= start;if (value < (1 / 2.75f)){return end * (7.5625f * value * value) + start;}else if (value < (2 / 2.75f)){value -= (1.5f / 2.75f);return end * (7.5625f * (value) * value + .75f) + start;}else if (value < (2.5 / 2.75)){value -= (2.25f / 2.75f);return end * (7.5625f * (value) * value + .9375f) + start;}else{value -= (2.625f / 2.75f);return end * (7.5625f * (value) * value + .984375f) + start;}}private float easeInOutBounce(float start, float end, float value){end -= start;float d = 1f;if (value < d/2) return easeInBounce(0, end, value*2) * 0.5f + start;else return easeOutBounce(0, end, value*2-d) * 0.5f + end*0.5f + start;}private float easeInBack(float start, float end, float value){end -= start;value /= 1;float s = 1.70158f;return end * (value) * value * ((s + 1) * value - s) + start;}private float easeOutBack(float start, float end, float value){float s = 1.70158f;end -= start;value = (value / 1) - 1;return end * ((value) * value * ((s + 1) * value + s) + 1) + start;}private float easeInOutBack(float start, float end, float value){float s = 1.70158f;end -= start;value /= .5f;if ((value) < 1){s *= (1.525f);return end / 2 * (value * value * (((s) + 1) * value - s)) + start;}value -= 2;s *= (1.525f);return end / 2 * ((value) * value * (((s) + 1) * value + s) + 2) + start;}private float punch(float amplitude, float value){float s = 9;if (value == 0){return 0;}if (value == 1){return 0;}float period = 1 * 0.3f;s = period / (2 * Mathf.PI) * Mathf.Asin(0);return (amplitude * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * 1 - s) * (2 * Mathf.PI) / period));}private float easeInElastic(float start, float end, float value){end -= start;float d = 1f;float p = d * .3f;float s = 0;float a = 0;if (value == 0) return start;if ((value /= d) == 1) return start + end;if (a == 0f || a < Mathf.Abs(end)){a = end;s = p / 4;}else{s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);}return -(a * Mathf.Pow(2, 10 * (value-=1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) + start;} private float easeOutElastic(float start, float end, float value){//Thank you to rafael.marteleto for fixing this as a port over from Pedro's UnityTweenend -= start;float d = 1f;float p = d * .3f;float s = 0;float a = 0;if (value == 0) return start;if ((value /= d) == 1) return start + end;if (a == 0f || a < Mathf.Abs(end)){a = end;s = p / 4;}else{s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);}return (a * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) + end + start);} private float easeInOutElastic(float start, float end, float value){end -= start;float d = 1f;float p = d * .3f;float s = 0;float a = 0;if (value == 0) return start;if ((value /= d/2) == 2) return start + end;if (a == 0f || a < Mathf.Abs(end)){a = end;s = p / 4;}else{s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);}if (value < 1) return -0.5f * (a * Mathf.Pow(2, 10 * (value-=1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) + start;return a * Mathf.Pow(2, -10 * (value-=1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) * 0.5f + end + start;} /* GFX47 MOD END */#endregion #region Deprecated and Renamed#endregion
}
演示效果:
在游戏的基础上我们还添加了快捷输入公式功能,能够让你在输入公式过后魔方自动执行步骤。由于这只是基础版的,游戏也只是开发出了一个雏形,后来可以添加一些计时功能,或者能够网络对战。
性能分析:
由于是自带的3d引擎,感觉也比较耗性能,特别是3d渲染,还有对每一帧的更新也比较吃cpu和显卡,程序自身比较简单,这次能够在unity3d上运行一个小小的demo也算是一种学习吧。
这篇关于(结对编程)基于unity3d游戏引擎的魔方游戏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!