1、简答并用程序验证【建议做】
1.1游戏对象运动的本质是什么?
游戏对象运动本质上是游戏对象空间属性的改变,包括Position和Rotation的变换。
1.2请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
- 通过修改Transform属性实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move1 : MonoBehaviour
{
private float xSpeed = 5f;
private float ySpeed = 0;
private float gravity = 9.8f;
// Start is called before the first frame update
void Start()
{
}// Update is called once per frame
void Update()
{
this.transform.position += Vector3.right * Time.deltaTime * xSpeed;
this.transform.position += Vector3.down * Time.deltaTime * ySpeed;
ySpeed += gravity * Time.deltaTime;
}
}
- 使用向量Vector3实现
void Update()
{
Vector3 trans = new Vector3(xSpeed * Time.deltaTime, -ySpeed * Time.deltaTime, 0);
this.transform.position += trans;
ySpeed += gravity * Time.deltaTime;
}
- 使用 Translate 实现
void Update()
{
Vector3 trans = new Vector3(xSpeed * Time.deltaTime, -ySpeed * Time.deltaTime, 0);
this.transform.Translate(trans);
ySpeed += gravity * Time.deltaTime;
}
1.3 写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
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 ( http://www.flash-game.net/game/2535/priests-and-devils.html )
- 列出游戏中提及的事物(Objects)
- 用表格列出玩家动作表(规则表),注意,动作越少越好
- 请将游戏中对象做成预制
- 在场景控制器 LoadResources 方法中加载并初始化长方形、正方形、球及其色彩代表游戏中的对象。
- 使用 C# 集合类型有效组织对象
- 整个游戏仅主摄像机和 一个 Empty 对象, 其他对象必须代码动态生成!!! 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的通讯耦合语句。 违背本条准则,不给分
- 请使用课件架构图编程,不接受非 MVC 结构程序
- 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!
2.1 列出游戏中提及的事物(Objects)
牧师x3、魔鬼x3、船、河流、河岸x2
2.2 用表格列出玩家动作表(规则表)
| 牧师、魔鬼上船 | 船靠岸且船上不得多于两人 |
|---|---|
| 牧师、魔鬼下船 | 船靠岸 |
| 船过河 | 船上不得少于1个人 |
2.3 将游戏中对象做成预制

2.4 MVC结构

- Model(用于动态生成游戏对象)
- Boat.cs
- Character.cs
- River.cs
- Coast.cs
- View(处理 Input 事件,渲染 GUI ,接收事件)
- User.cs
- Controller(接受用户事件,控制模型的变化)
- BoatController.cs
- CharacterController.cs
- CoastController.cs
- Director.cs
- Interface.cs
- KernelController.cs
- Move.cs
运行结果:

本文探讨了游戏对象运动的本质,通过修改Transform属性、使用向量Vector3以及Translate方法实现了物体的抛物线运动。此外,还介绍了如何在Unity中创建一个完整的太阳系模拟,其中每个星球的转速不同且不在同一平面。文章强调了游戏脚本设计,包括牧师和魔鬼的渡河谜题,提出了游戏对象的预制、MVC结构和输入处理的规范要求。
487

被折叠的 条评论
为什么被折叠?



