【无标题】

3D游戏设计 homework_3

一、
1.游戏对象运动但是本质是什么/

是游戏对象跟随每一帧的变化,空间上发生变化。这里的空间变化包括了游戏对象的transform组件中的position和rotation两个属性,前者是绝对或者相对位置的改变,后者是所处位置的角度的旋转变化。

2.请用三种以上的方法,实现物体的抛物线运动。
(1)在每一帧更新物体的position属性
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class move : MonoBehaviour {

    public float speed = 10;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        this.transform.position += Vector3.up * Time.deltaTime * speed;
        this.transform.position += Vector3.right * Time.deltaTime * 5;
        speed -= Time.deltaTime * 10.0f;
    }
}

(2)同时改变Vector3的x和y
void Update () {
    Vector3 move = new Vector3(Time.deltaTime * 5, Time.deltaTime * speed, 0);
    this.transform.position += move;
    speed -= Time.deltaTime * 10.0f;
}

(3)利用了transform的Translate()函数
    void Update()
    {
        Vector3 move = new Vector3(Time.deltaTime * 5, Time.deltaTime * speed, 0);
        this.transform.Translate(move);
        speed -= Time.deltaTime * 10.0f;
    }

3、写一个程序,实现一个完整的太阳系。

(1)写行为脚本 将除月亮外的所有星球的转动行为都写在一个脚本,并将该脚本作为sun的组件,代码如下:

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

public class Sun : MonoBehaviour {
    public Transform sun;
    public Transform Mercury;
    public Transform Venus;
    public Transform Earth;
    public Transform Mars;
    public Transform Jupiter;
    public Transform Saturn;
    public Transform Uranus;
    public Transform Neptune;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        Mercury.Rotate(Vector3.up * Time.deltaTime * 100);
        Mercury.RotateAround(sun.position, new Vector3(0, 1, 0), 100 * Time.deltaTime);

        Venus.Rotate(Vector3.up * Time.deltaTime * 100);
        Venus.RotateAround(sun.position, new Vector3(0.1f, 1, 0), 90 * Time.deltaTime);

        Earth.Rotate(Vector3.up * Time.deltaTime * 100);
        Earth.RotateAround(sun.position, new Vector3(0.2f, 1, 0), 80 * Time.deltaTime);

        Mars.Rotate(Vector3.up * Time.deltaTime * 100);
        Mars.RotateAround(sun.position, new Vector3(0.3f, 1, 0), 70 * Time.deltaTime);

        Jupiter.Rotate(Vector3.up * Time.deltaTime * 100);
        Jupiter.RotateAround(sun.position, new Vector3(0, 1, 0.1f), 60 * Time.deltaTime);

        Saturn.Rotate(Vector3.up * Time.deltaTime * 100);
        Saturn.RotateAround(sun.position, new Vector3(0, 1, 0.2f), 50 * Time.deltaTime);

        Uranus.Rotate(Vector3.up * Time.deltaTime * 100);
        Uranus.RotateAround(sun.position, new Vector3(0, 1, 0.3f), 40 * Time.deltaTime);

        Neptune.Rotate(Vector3.up * Time.deltaTime * 100);
        Neptune.RotateAround(sun.position, new Vector3(0.1f, 1, 0.1f), 30 * Time.deltaTime);
    }
}

二、编程实践(Priests ande Devils)

牧师与恶魔

牧师与魔鬼是一款益智游戏,您将帮助牧师与魔鬼在规定时间内过河。河边有三个牧师和三个魔鬼。他们都想去河的另一边,但这里只有一艘船,这艘船每次只能载两个人。而且必须有一个人把船从一边开到另一边。在游戏中,您可以单击它们移动它们,然后单击船移动到另一个方向。如果牧师的人数少于恶魔人数他们就会被杀死,游戏就结束了。目标是让所有牧师都活着。

(1)文件结构

在这里插入图片描述

(2)简单介绍

① 鼠标点击角色的逻辑代码

public void characterIsClicked(MyCharacterController characterCtrl) {
		if (userGUI.status != 0 ) return;
		if (characterCtrl.isOnBoat ()) {
			CoastController whichCoast;
			if (boat.get_to_or_from () == -1) { // to->-1; from->1
				whichCoast = toCoast;
			} else {
				whichCoast = fromCoast;
			}

			boat.GetOffBoat (characterCtrl.getName());
			characterCtrl.moveToPosition (whichCoast.getEmptyPosition ());
			characterCtrl.getOnCoast (whichCoast);
			whichCoast.getOnCoast (characterCtrl);

		} else {									// character on coast
			CoastController whichCoast = characterCtrl.getCoastController ();

			if (boat.getEmptyIndex () == -1) {		// boat is full
				return;
			}

			if (whichCoast.get_to_or_from () != boat.get_to_or_from ())	// boat is not on the side of character
				return;

			whichCoast.getOffCoast(characterCtrl.getName());
			characterCtrl.moveToPosition (boat.getEmptyPosition());
			characterCtrl.getOnBoat (boat);
			boat.GetOnBoat (characterCtrl);
		}
		userGUI.status = check_game_over ();
	}


判断游戏结束条件

int check_game_over() {	// 0->not finish, 1->lose, 2->win
		int from_priest = 0;
		int from_devil = 0;
		int to_priest = 0;
		int to_devil = 0;

		int[] fromCount = fromCoast.getCharacterNum ();
		from_priest += fromCount[0];
		from_devil += fromCount[1];

		int[] toCount = toCoast.getCharacterNum ();
		to_priest += toCount[0];
		to_devil += toCount[1];

		if (to_priest + to_devil == 6)		// win
			return 2;

		int[] boatCount = boat.getCharacterNum ();
		if (boat.get_to_or_from () == -1) {	// boat at toCoast
			to_priest += boatCount[0];
			to_devil += boatCount[1];
		} else {	// boat at fromCoast
			from_priest += boatCount[0];
			from_devil += boatCount[1];
		}
		if (from_priest < from_devil && from_priest > 0) {		// lose
			return 1;
		}
		if (to_priest < to_devil && to_priest > 0) {
			return 1;
		}
		return 0;			// not finish
	}
三、关系图

在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是zp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值