3D游戏编程作业3

阅读: 评论:0

3D游戏编程作业3

3D游戏编程作业3

3D游戏编程作业3

    • 作业内容
      • 1、简答并用程序验证【建议做】
        • (1)游戏对象运动的本质是什么?
        • (2)使用三种方法实现物体的抛物线运动。
        • (3)写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
      • 2、编程实践
        • (1)play the game
        • (2)列出游戏中提及的事物(Objects)
        • (3)用表格列出玩家动作表(规则表),注意,动作越少越好
        • (4)请将游戏中对象做成预制
        • (5)在LoadResources方法中加载并初始化游戏对象
        • (6)整体代码
        • (7)遇到的问题
        • (8)效果展示

作业内容

1、简答并用程序验证【建议做】

首先先按照【建议做】里的步骤做一遍,了解设计一个游戏所需要的框架结构以及核心代码。(具体过程【建议做】里便有了,代码的话文章中也给了,就不再赘述)

(1)游戏对象运动的本质是什么?

游戏对象运动的本质是游戏对象的空间属性(位置和旋转角)随着每一帧的变化。

(2)使用三种方法实现物体的抛物线运动。
  • 第一种方法:改变position的值来实现抛物线运动,其中水平方向的值是随时间匀速增加,竖直方向的值则是随时间匀加速增加。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola1 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 1*Time.ansform.position += Vector3.right*Time.deltaTime*ansform.position += Vector3.down*Time.deltaTime*yspeed;}
}
  • 第二种方法:用三维向量类Vector3对物体的position值进行叠加
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola2 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 2*Time.ansform.position += new Vector3(xspeed*Time.deltaTime, -yspeed*Time.deltaTime, 0);}
}
  • 第三种方法:用Vector3向量和transform中的translate函数来改变position的值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Parabola3 : MonoBehaviour
{public float xspeed = 1;public float yspeed = 1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){yspeed += 2*Time.deltaTime;Vector3 v = new Vector3(xspeed*Time.deltaTime, -yspeed*Time.deltaTime, 0);ansform.Translate(v);}
}
(3)写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。

完整的太阳系一共要求有太阳以及它的八大行星,其他的天体都不在考虑范围内。

  1. 首先先做好太阳系的预制,其实就是建立起九个球体,可以根据自己的想法来调整这些球体的大小和位置,然后分别给这些球体贴上合适的贴图来代表各大星球。
  2. 然后按照【建议做】里面的内容来建立MVC架构,编写好相应的代码。(具体代码放在gitee仓库中,这里就不多写一遍了)
  3. 将编写好的脚本代码按照需要添加到游戏对象中去。创建一个空的游戏对象,将FirstController加入其中;将RoundSun添加到预制好的sun游戏对象中,并且将对应的星球部件添加好。
  4. 建立背景图层
  5. 运行一下查看效果。

2、编程实践

阅读游戏脚本:

Priests and Devils
Priests and Devils is a puzzle game in which you will help the Priests and Devils to cross the river within the time limit. There are 3 priests and 3 devils at one side of the river. They all want to get to the other side of this river, but there is only one boat and this boat can only carry two persons each time. And there must be one person steering the boat from one side to the other side. In the flash game, you can click on them to move them and click the go button to move the boat to the other direction. If the priests are out numbered by the devils on either side of the river, they get killed and the game is over. You can try it in many > ways. Keep all priests alive! Good luck!

程序需要满足的要求:

  • play the game ( .html )
  • 列出游戏中提及的事物(Objects)
  • 用表格列出玩家动作表(规则表),注意,动作越少越好
  • 请将游戏中对象做成预制
  • 在场景控制器 LoadResources 方法中加载并初始化 长方形、正方形、球 及其色彩代表游戏中的对象。
  • 使用 C# 集合类型 有效组织对象
  • 整个游戏仅 主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的 通讯耦合 语句。 违背本条准则,不给分
  • 请使用课件架构图编程,不接受非 MVC 结构程序
  • 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!
(1)play the game

(2)列出游戏中提及的事物(Objects)

游戏中提及的事物有:牧师、魔鬼、船、河以及两个河岸

(3)用表格列出玩家动作表(规则表),注意,动作越少越好
动作条件
点击船船在岸且船上有1~2人
牧师上船牧师与船在同岸且船上有空位
魔鬼上船魔鬼与床同岸且船上有空位
牧师下船船靠岸且牧师在船上
魔鬼下船船靠岸且魔鬼在船上
(4)请将游戏中对象做成预制

用白色球体代表牧师,黑色柱体代表魔鬼,绿色柱体代表河岸,蓝色柱体代表河流,棕色柱体代表船。

(5)在LoadResources方法中加载并初始化游戏对象
    public void LoadResources(){GameObject river = Instantiate (Resources.Load ("Prefabs/river", typeof(GameObject)), river_pos, Quaternion.identity, null) as GameObject;river.name = "river";fromSide = new SideController("from");toSide = new SideController("to");boat = new BoatController();loadCharacter();}
(6)整体代码

整个游戏的代码以及其他游戏资源都放在了gitee仓库中了。(传送门)

(7)遇到的问题

在设计MVC架构中的控制器部分时,一开始我将控制器拆分成FirstController.cs、BoatController.cs、SideController.cs、MyCharacterController.cs、moveable.cs等文件,但是在最后运行出现了以下问题
上网查询说是不同文件的游戏对象加载时间不一样,没有放在同一个代码文件的话可能会出现一个类加载后另一个类还没加载的情况。
**解决方法:**将除了FIrstController.cs文件外的所有内容整合到同一个文件中(basecode.cs),并将这些代码定义为命名空间,可以被其他文件所引用。(namespace mygame{})

(8)效果展示

本文发布于:2024-01-27 18:57:08,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063530262019.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:作业   游戏
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23