UML图:
规则说明:
靶分为6环,由内而外射中得分分别为10,8,6,4,2,1
游戏仅一轮,可无限射箭
仅在左右方向上具有风力
实现效果:
大致思路:
与飞碟游戏很相似,仅是增添了箭和靶子的碰撞,并在箭射中靶子时将其刚体属性去除实现箭插在靶子上
UserGUI类:
该类中主要负责检测鼠标的点击,根据鼠标点击得到射线确认箭射出去的方向
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UserGUI : MonoBehaviour {
SceneController MySceneController;
void Start () {
MySceneController = (SceneController)FindObjectOfType (typeof(SceneController));
}
void Update () {
if (Input.GetButtonDown ("Fire1")) {
Debug.Log ("mouse down");
//get the direction of sending an arrow
Ray mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
MySceneController.sendArrow (mouseRay.direction);
}
}
void OnGUI() {
//the style of text
GUIStyle fontStyle = new GUIStyle ();
fontStyle.normal.textColor = new Color (230, 231, 158);
fontStyle.fontSize = 20;
GUI.Label (new Rect (100, 120, 400, 200), "Your Score: " + MySceneController.getScore (), fontStyle);
if (MySceneController.getWind () < 0) {
GUI.Label (new Rect (270, 120, 400, 200), "Wind: " + (-MySceneController.getWind ()) + " <<", fontStyle);
}
else if (MySceneController.getWind () > 0) {
GUI.Label (new Rect (270, 120, 400, 200), "Wind: " + ">> " + MySceneController.getWind (), fontStyle);
}
else {
GUI.Label (new Rect (270, 120, 400, 200), "Wind: " + MySceneController.getWind (), fontStyle);
}
}
}
SceneController类:
该类中通过调用WindController和Factory中的方法,实现对于场景的控制