Unity——牧师与魔鬼

简答并用程序验证

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

游戏对象运动的本质,就是游戏对象跟随每一帧发生变化的过程。在变化的过程中,主要是指游戏对象的transform中的rotation与position两个属性。其中,rotation是指游戏对象所处位置的角度变化,而position则是指游戏对象在坐标系中位置的改变。

请用三种方法以上方法,实现物体的抛物线运动

第一种:使用向量Vector3

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

public class changet_ransform : MonoBehaviour
{
    
    
    public float vx = 4;
    public float vy = 0;
    
    // Start is called before the first frame update
    void Start()  {
    
     }
    // Update is called once per frame
    void Update()
    {
    
    
        vy += 0.1f;
        transform.position += new Vector3(vx * Time.deltaTime, -vy * Time.deltaTime, 0);
    }
}

第二种:添加重力特性

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

public class use_gravity : MonoBehaviour
{
    
    
	//初速度
    public float vx;
    
    // Start is called before the first frame update
    void Start()
    {
    
    
        //给对象添加刚体属性,使之具有重力
        gameObject.AddComponent<Rigidbody>();
        //设置物体初速度
        Vector3 _velocity = new Vector3(vx,0,0);
        gameObject.GetComponent<Rigidbody>().velocity = _velocity;
    }

    // Update is called once per frame
    void Update()  {
    
     }
}

第三种:调用transform中的translate函数来改变position

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

public class translate : MonoBehaviour
{
    
    
    public float vx = 4;
    public float vy = 0;

    // Start is called before the first frame update
    void Start()  {
    
      }

    // Update is called once per frame
    void Update()
    {
    
    
        vy += 0.1f;
        Vector3 change = new Vector3(Time.deltaTime * vx, -Time.deltaTime * vy, 0);
        transform.Translate(change);
    }
}

第四种:直接修改position

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

public class change_position : MonoBehaviour
{
    
    
    public float vx = 4;
    public float vy = 0;

    // Start is called before the first frame update
    void Start()  {
    
    }

    // Update is called once per frame
    void Update()
    {
    
    
        transform.position += Vector3.right * Time.deltaTime * vx;
        transform.position += Vector3.down * Time.deltaTime * vy;
        vy += 0.1f;
    }
}

写一个程序,实现一个完整的太阳系,其他星球围绕太阳的转速必须不一样,且不在一个法平面上。

传送门

编程实践

阅读以下游戏脚本

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

  • 列出游戏中提及的事物(Objects)
    河岸(Coast)、船(Boat)、河流(River)、魔鬼(Devils)、牧师(Priests)

  • 用表格列出玩家动作表(规则表)。注意:动作越少越好

动作 条件 结果
点击牧师/魔鬼 游戏未结束,船没有正在移动,与船在相同的一边 牧师/魔鬼移动
点击船 游戏未结束且船上至少有一人 船移动
  • 请将游戏中对象做成预制

在这里插入图片描述

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

MVC架构
在这里插入图片描述
运行效果视频:传送门

代码:传送门

超时效果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_56266553/article/details/127474511