3D游戏编程与设计 作业三

3D游戏编程与设计 作业三

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

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

    游戏对象运动的本质,是游戏对象跟随每一帧的变化自身空间坐标的变换。

  • 请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)

    方法一:利用position的改变来实现抛物线运动。
    抛物线运动在水平方向是匀速的,在竖直方向上是匀加速的,然后将两个方向的运动矢量相加即可,实现代码如下:在这里插入图片描述
    方法二:创建Vector3向量。
    定义Vector3变量的值,也是竖直方向上是一个均匀增加的数值,水平方向是一个保持不变的数值,然后将游戏对象原本的position属性与该向量相加即可实现抛物线运动,代码如下:
    在这里插入图片描述
    方法三:利用transform中的translate函数来进行改变position。
    传入一个Vector3向量的参数,实现position的改变,代码如下:
    在这里插入图片描述

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

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Rotate : 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;
    
    	Vector3[] a = new Vector3[9];
    	float y, z;
    
    	// Start is called before the first frame update
    	void Start()
    	{
        	sun.position = Vector3.zero;
        	for(int i = 0; i < 9; i++)
        	{
            	y = Random.Range(1, 360);
            	z = Random.Range(1, 360);
            	a[i] = new Vector3(0, y, z);
        	}
    	}
    
    	// Update is called once per frame
    	void Update()
    	{
        	mercury.RotateAround(sun.position, a[0], 47 * Time.deltaTime);
        	mercury.Rotate(Vector3.up * 47 * Time.deltaTime);
    
        	venus.RotateAround(sun.position, a[1], 35 * Time.deltaTime);
        	venus.Rotate(Vector3.up * 35 * Time.deltaTime);
    
            earth.RotateAround(sun.position, a[2], 30 * Time.deltaTime);
    	    earth.Rotate(Vector3.up * 30 * Time.deltaTime);
    
        	mars.RotateAround(sun.position, a[3], 24 * Time.deltaTime);
        	mars.Rotate(Vector3.up * 24 * Time.deltaTime);
    
        	jupiter.RotateAround(sun.position, a[4], 13 * Time.deltaTime);
        	jupiter.Rotate(Vector3.up * 13 * Time.deltaTime);
    
        	saturn.RotateAround(sun.position, a[5], 11 * Time.deltaTime);
        	saturn.Rotate(Vector3.up * 11 * Time.deltaTime);
    
        	uranus.RotateAround(sun.position, a[6], 9 * Time.deltaTime);
        	uranus.Rotate(Vector3.up * 9 * Time.deltaTime);
    
        	neptune.RotateAround(sun.position, a[7], 8 * Time.deltaTime);
        	neptune.Rotate(Vector3.up * 8 * Time.deltaTime);
    	}
    }
    

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 结构程序

  • 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!

代码如下

boatBehavior.cs

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

public class boatBehavior : MonoBehaviour
{

    public boatAction action;

    // Use this for initialization
    void Start()
    {
        action = SSDirector.getInstance().currentSceneController as boatAction;
    }

    private void OnMouseDown()
    {
        action.boat_move(this.gameObject);
    }

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

    }
}

priestBehavior.cs

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

public class priestBehavior : MonoBehaviour
{

    private priestAction action;

    // Use this for initialization
    void Start()
    {
        action = SSDirector.getInstance().currentSceneController as priestAction;
    }

    private void OnMouseDown()
    {
        action.priest_move(this.gameObject);
    }

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

    }
}

devilBehavior.cs

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

public class devilBehavior : MonoBehaviour
{

    private devilAction action;

    // Use this for initialization
    void Start()
    {
        action = SSDirector.getInstance().currentSceneController as devilAction;
    }

    private void OnMouseDown()
    {
        action.devil_move(this.gameObject);
    }

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

    }
}

UserGUI.cs

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

public class UserGUI : MonoBehaviour
{

    private IUserAction action;

    // Use this for initialization
    void Start()
    {
        action = SSDirector.getInstance().currentSceneController as IUserAction;
    }

    void onGUI()
    {

    }

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

    }
}

Interface.cs

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

public interface IsceneController
{
    void LoadResources();
    void Restart();
}

public interface IUserAction
{


}

public interface devilAction
{
    void devil_move(GameObject obj);
}

public interface priestAction
{
    void priest_move(GameObject obj);
}

public interface boatAction
{
    void boat_move(GameObject obj);
}

Director.cs

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

public class SSDirector : System.Object
{

    // singlton instance
    private static SSDirector _instance;

    public IsceneController currentSceneController { get; set; }
    public bool running { get; set; }

    //get instance anytime anywhere!
    public static SSDirector getInstance()
    {
        if (_instance == null)
        {
            _instance = new SSDirector();
        }
        return _instance;
    }

    public int getFPS()
    {
        return Application.targetFrameRate;
    }

    public void setFPS(int fps)
    {
        Application.targetFrameRate = fps;
    }
}

FirstController.cs

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

public class SSDirector : System.Object
{

    // singlton instance
    private static SSDirector _instance;

    public IsceneController currentSceneController { get; set; }
    public bool running { get; set; }

    //get instance anytime anywhere!
    public static SSDirector getInstance()
    {
        if (_instance == null)
        {
            _instance = new SSDirector();
        }
        return _instance;
    }

    public int getFPS()
    {
        return Application.targetFrameRate;
    }

    public void setFPS(int fps)
    {
        Application.targetFrameRate = fps;
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值