简答题
1、简答并用程序验证【建议做】
游戏对象运动的本质是什么?
游戏对象运动的本质就是在每一帧图像上使用矩阵变换(平移、旋转、缩放)改变游戏对象的空间属性,如transform里的position、rotation。
请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
第一种方法是利用position的改变来实现抛物线运动。
public float x_speed = 10;
public float y_speed = 5;
void Update()
{
float ymove= y_speed * Time.deltaTime + 1 / 2 * (-1) * Time.deltaTime *Time.deltaTime;
this.transform.position += Vector3.up * ymove;
float xmove = x_speed * Time.deltaTime;
this.transform.position += Vector3.left * xmove;
y_speed -= 1;
}
第二种方法是直接声明创建一个Vector3变量,然后将游戏对象原本的position属性与该向量相加即可实现抛物线运动。
public float x_speed = 10;
public float y_speed = 5;
void Update()
{
Vector3 move = new Vector3((-1)*Time.deltaTime * x_speed, y_speed *Time.deltaTime + 1 / 2 * (-1) * Time.deltaTime * Time.deltaTime, 0);
this.transform.position+= move;
y_speed -= 1;
}
第三种方法利用transform中的translate函数来进行改变position,传入参数也需要是一个Vector3向量,才可以实现position的改变。
public float x_speed = 10;
public float y_speed = 5;
void Update()
{
Vector3 move = new Vector3((-1) * Time.deltaTime * x_speed, y_speed *Time.deltaTime + 1 / 2 * (-1) * Time.deltaTime * Time.deltaTime, 0);
this.transform.Translate(move);
y_speed-= 1;
}
写一个程序,实现一个完整的太阳系,其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
某个行星公转自转的函数,其他的类似
GameObject.Find("Earth").transform.RotateAround(Vector3.zero,new Vector3(0, 1, 0), 30 * Time.deltaTime);
GameObject.Find("Earth").transform.Rotate(Vector3.up* Time.deltaTime * 10000);
月球围绕地球旋转的实现:
建立一个与地球类似的只公转的空对象,然后月亮以其为中心旋转即可。
空对象的函数:
this.transform.RotateAround(Vector3.zero,new Vector3(0, 1, 0), 30 * Time.deltaTime);
月球的函数:
Vector3 position = this.transform.parent.position;
this.transform.RotateAround(position,Vector3.up, 360 * Time.deltaTime);
游戏对象图:
效果图:
编程实践
阅读以下游戏脚本
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)
用表格列出玩家动作表(规则表),注意,动作越少越好
请将游戏中对象做成预制
在 GenGameObjects 中创建长方形、正方形、球及其色彩代表游戏中的对象。
使用 C# 集合类型有效组织对象
整个游戏仅主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象,SendMessage 这类突破程序结构的通讯耦合 语句。 违背本条准则,不给分
请使用课件架构图编程,不接受非 MVC 结构程序
注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!
游戏中的对象(Objects)有:牧师x3、魔鬼x3、小船、岸*2、水流
玩家动作表
条件 | 事情 |
---|---|
按下Reset键 | 重置 |
按下On键且对应位置有空位 | 将对应对象移到船上 |
按下Off键且对应位置有空位 | 将对应对象移到对应的岸上 |
按下Go键且船上最少有一人 | 将船移到另一个岸边 |
游戏运行前具体的游戏对象:
游戏运行时具体的游戏对象:
游戏运行界面如下:
文件管理如下: