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

简答并用程序验证

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

——使用矩阵变换(平移、旋转、缩放)改变游戏对象的空间属性(Transform)

物体抛物线运动实现的三种方式

假设此物体做平抛运动,只受重力,初速度 v 0 = 5 v_0 = 5 v0=5,重力加速度 g = 9.8 g = 9.8 g=9.8
实现方法1:

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

public class ParabolicMotion : MonoBehaviour
{
    private float graviationalAcceleration = 9.8f;
    private float initialVelocity = 5;
    private float y_velocity = 0;
    // Update is called once per frame
    void Update()
    {
        y_velocity += graviationalAcceleration * Time.deltaTime;
        float x_distance = initialVelocity * Time.deltaTime;
        float y_distance = y_velocity * Time.deltaTime;

        this.transform.position -= Vector3.up * y_distance;
        this.transform.position += Vector3.right * x_distance;
    }
}

实现方法2:

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

public class ParabolicMotion : MonoBehaviour
{
    private float graviationalAcceleration = 9.8f;
    private float initialVelocity = 5;
    private float y_velocity = 0;
    // Update is called once per frame
    void Update()
    {
        y_velocity += graviationalAcceleration * Time.deltaTime;
        float x_distance = initialVelocity * Time.deltaTime;
        float y_distance = y_velocity * Time.deltaTime;
        
        Vector3 move = new Vector3(x_distance, -y_distance, 0);
        this.transform.position += move;
    }
}

实现方法3:

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

public class ParabolicMotion : MonoBehaviour
{
    private float graviationalAcceleration = 9.8f;
    private float initialVelocity = 5;
    private float y_velocity = 0;
    // Update is called once per frame
    void Update()
    {
        y_velocity += graviationalAcceleration * Time.deltaTime;
        float x_distance = initialVelocity * Time.deltaTime;
        float y_distance = y_velocity * Time.deltaTime;

        Vector3 move = new Vector3(x_distance, -y_distance, 0);
        this.transform.Translate(move);
    }
}

Priests and Devils编程初实践

列出游戏中提及的事物(Objects)

Objects个数Resource
牧师(Priest)3个蓝色长方体
恶魔(Devil)3个黑色胶囊状物体
1个棕色圆柱体
河岸2个以rock为纹理的长方体

玩家动作表

动作参数结果
查看游戏规则游戏规则介绍界面
启动游戏游戏初始界面
选择乘船人河岸上的人,1人/2人被选对象由河岸移动至船中
选择下船人船中的俩人,1人/2人被选对象由船中移动至河岸上
将船从一岸移向另一岸至少选择1个乘船人结束/未结束

代码设计

MVC架构——界面人机交互程序设计的一种架构模式
将程序分为三部分:

  • 模型
    • RoleModel.cs
    • BoatModel.cs
    • LandModel.cs
    • SSDirector.cs
    • Move.cs
    • Click.cs
    • PlayAnimation.cs
  • 控制器
    • ISceneController.cs
    • Controllor.cs
    • IUserAction.cs
  • 界面
    • UserGUI.cs

完整工程项目及代码参考我的github仓库:代码传送门
P.S. 此次我的代码设计主要参考了师姐的代码,但仍有许多不足之处,将在第四次作业中做进一步的改进

参考文献

  1. 前辈的博客
  2. 潘老师的课程网站
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值