ysh

Game development -三个游戏

1.roll-a-ball

2.space shooter

3.hover

roll-a-ball

Introduction to my game

A simple ball rolling game, players control the ball, eat all the floating square is victory. The game scene is limited to a flat surface and is bounded by walls. Each square represents a certain score, which is displayed in the upper left corner in real time.

Game design

  • Beautiful scenery - perfectly fit the color style of aesthetic design of human body, let a person want to wander in the ocean of infinite fun of rolling ball
  • Flexible operation - ball rolling speed is variable, our goal is only one: eat the box to win! You control the tempo!
  • Realistic lighting - squares, balls, even walls! All with shadow effects. Light and shadow competition, all in between the fingers!
  • Rotating square - a square that rotates evenly at an agreed rate, and is always appealing to the player to eat it!
  • Real-time score display - you can see the current score in the upper left corner of the interface at any time.
  • Want more? - press "r" immediately after the end of the game to play another wonderful game! Break through your limit speed!

Source code

CameraController.cs

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

public class CameraController : MonoBehaviour {

    public GameObject player;
    private Vector3 offset;

    // Use this for initialization
    void Start () {
        offset = transform.position;
    }
    
    // Update is called once per frame
    void LateUpdate () {
        transform.position = player.transform.position + offset;
    }
}

PlayerController.cs

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

public class PlayerController : MonoBehaviour {

    public float speed;
    private int score;
    public Text scoretext;

    // Use this for initialization
    void Start () {
        score = 0;
        SetCountText();
    }
    
    // Update is called once per frame
    void Update () {
        
    }

    void FixedUpdate(){
        float moveH = Input.GetAxis("Horizontal");
        float moveV = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveH,0.0f,moveV);

        Rigidbody body = GetComponent();
        body.AddForce(movement * speed * Time.deltaTime);
    }

    void OnTriggerEnter(Collider other){
        if(other.gameObject.tag == "pickup"){
        other.gameObject.SetActive(false);
        score++;
        SetCountText();
    }
  }

    void SetCountText(){
        scoretext.text = "Score:" + score.ToString();
    }
}

Rotator.cs

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

public class Rotator : MonoBehaviour {

    private Vector3 rotate;

    // Use this for initialization
    void Start () {
        rotate = new Vector3(15,30,45);
    }
    
    // Update is called once per frame
    void Update () {
        transform.Rotate(rotate * Time.deltaTime);
    }
}

Concrete explanation

  • CameraController.cs
    To control the camera move with the player's visual angle.
  • PlayerController.cs
    Main documents. Including the display of scores, the movement of small balls, the logic of small balls eating square, the principle of adding points.
  • Rotator.cs
    To control the rotation of square.

Screenshots in game

ysh_第1张图片
1.png

ysh_第2张图片
2.png

space shooter

Introduction to my game

The player controls a spacecraft, fires bullets to shoot down meteorites to score points, and ends the game when the plane is hit by a meteorite. Adjust the effect of light and shadow in the background picture of the game. Detection includes aircraft and meteorite collisions, bullets and meteorite collisions, with different explosion effects and sound effects. Real-time display of the current score, the game can be restarted after the end.

Game design

  • Avatars of discovery - pilot spacecraft to explore the vast universe. What secret is hidden in the darkness?
  • Shoot down an interstellar meteorite - fire a bullet to destroy the meteorite and get points to prove yourself! Ace pilot, apply!
  • Endless crusade - fight until the ship is destroyed by meteorites, general yak west march, ping Ming army flute. Eternal, heaven to the left, warriors to the right!
  • Conquer fear with manipulation - the speed of the bullet and the speed of the ship can be set. Is it to use bullets to wipe out interstellar debris, or to move flexibly away from the deadly meteorite, all in your mind!
  • Green shoots? - bad grades? Don't worry! No archives, no history of the game records show, immediately press r for the next star adventure bar!

Source code

BoundaryDestroy.cs

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

public class BoundaryDestroy : MonoBehaviour {

    void OnTriggerExit(Collider other) {
        Destroy(other.gameObject);
    }

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

ContactDestroy.cs

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

public class ContactDestroy : MonoBehaviour {

    public GameObject asteroidexplosion;
    public GameObject playerexplosion;
    private GameController controller;

    void OnTriggerEnter(Collider other) {
        if(other.tag == "Boundary"){
            return;
        }

        if (other.tag != "Player")
        {
            controller.AddScore(10);
        }

        Destroy(other.gameObject);
        Destroy(gameObject);

        GameObject tmp = Instantiate(asteroidexplosion, transform.position, transform.rotation) as GameObject;
        Destroy(tmp,1);

        if (other.tag == "Player"){
            tmp = Instantiate(playerexplosion, other.transform.position, other.transform.rotation) as GameObject;
            Destroy(tmp, 1);
            controller.EndGame();
        }
    }

    // Use this for initialization
    void Start () {
        GameObject tmp = GameObject.FindGameObjectWithTag("GameController");
        controller = tmp.GetComponent();
        if (controller == null) {
            Debug.LogError("false");
        }
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

GameController.cs

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameController : MonoBehaviour {

    public GameObject asteroid;
    public Vector3 spawnValues;
    public int asteroidCount;
    public float spawnWait;
    public float startWait;
    public Text scoretext;
    private int score;
    private bool gameEnded;


    // Use this for initialization
    void Start () {
        gameEnded = false;
        scoretext.gameObject.SetActive(false);
        scoretext.text = "Score:0";
        StartCoroutine(SpawnWaves());
    }

    public void AddScore(int points){
        score += points;
        scoretext.text = "Score:" + score;
    }

    IEnumerator SpawnWaves(){
        yield return new WaitForSeconds(startWait);

        while(true){
        for (int i = 0; i < asteroidCount; i++)
        {
            Vector3 spawnAt = new Vector3(
                Random.Range(-spawnValues.x, spawnValues.x),
                spawnValues.y,
                spawnValues.z);

            Instantiate(asteroid, spawnAt, Quaternion.identity);
            yield return new WaitForSeconds(spawnWait);
            }
        }
    }
    // Update is called once per frame
    void Update () {
        if (gameEnded){
            if(Input.GetKeyDown(KeyCode.R)){
                Scene level = SceneManager.GetActiveScene();
                SceneManager.LoadScene(level.name);
            }
        }
    }

    public void EndGame()
    {
        gameEnded = true;
        scoretext.gameObject.SetActive(true);
    }
}

Mover.cs

using System.Collections.Generic;
using UnityEngine;

public class Mover : MonoBehaviour {

    public float speed;

    // Use this for initialization
    void Start () {
        GetComponent().velocity = transform.forward * speed;
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

PlayerController.cs

using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Boundary {
    public float xMin, xMax, zMin, zMax;
}

public class PlayerController : MonoBehaviour {

    public float speed;
    public Boundary boundary;
    public float tilt;

    //shots
    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
    private float nextFire;

    void FixedUpdate() {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        GetComponent().velocity = movement * speed;

        GetComponent().position = new Vector3(
            Mathf.Clamp(GetComponent().position.x, boundary.xMin, boundary.xMax),
            0.0f,
            Mathf.Clamp(GetComponent().position.z, boundary.zMin, boundary.zMax)
            );
         GetComponent().rotation = Quaternion.Euler(
             0.0f,0.0f,
             GetComponent().velocity.x * -tilt);
             
    }

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if(Input.GetKey("space")&&Time.time>nextFire){
            nextFire = Time.time + fireRate;
            Instantiate(shot,shotSpawn.position,shotSpawn.rotation);
        } 
    }
}

RandomRotator.cs

using System.Collections.Generic;
using UnityEngine;

public class RandomRotator : MonoBehaviour {

    public float tumble;

    // Use this for initialization
    void Start () {
        GetComponent().angularVelocity = Random.insideUnitSphere * tumble;
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

Concrete explanation

  • BoundaryDestroy.cs
    Detect boundary collisions and destroy in-game items
  • ContactDestroy.cs
    Detection collision includes spacecraft and meteorite collision and bullet and meteorite collision, if the meteorite collision score +10, if the spacecraft collision is the end of the game, show the final score
  • GameController.cs
    Display game score, randomly generate meteorite and restart game scene
  • Mover.cs
    Control the movement of the spacecraft
  • PlayerController.cs
    Control the ship's left to right deviation and firing interval
  • RandomRotator.cs
    Meteorites spin randomly as they fall

Screenshots in game

ysh_第3张图片
1.png

ysh_第4张图片
2.png

ysh_第5张图片
3.png

ysh_第6张图片
4.png

hover

Introduction to my game

A 3D game. Players gain points by manipulating a ship to destroy randomly generated turrets based on time. The turrets rotate regularly and fire bullets. When the turrets find the players (within a distance of the turrets), the turrets will track and shoot the players. The game ends when the player's ship is destroyed.

Game design

  • Cool lifelike ship - exquisite texture, attention to detail, fashion color matching, forgive warships, start!
  • Equal to the endless energy of the sun - equipped with a powerful engine, the jet of flame is the perfect display of his powerful power system!
  • Boundless and indistinguishable cosmic space - all four sides and six sides are cosmic space! The huge amount of playing time makes you unable to stop!
  • Blithe combat system - the ship's armor is strong enough to withstand multiple bullets, but a collision with the turret can be devastating. Watch out, commander!
  • Unlimited resurrection mode - press r to start all over again! Anonymous mode, hero, go beyond!

Source code

BoltController.cs

using System.Collections.Generic;
using UnityEngine;

public class BoltController : MonoBehaviour {
    public int number;
    public GameObject explosion;
    public GameObject explosion2;
    private GameController controller;
    // Use this for initialization
    void Start () {
    }
    
    // Update is called once per frame
    void Update () {
        number = 0;
        GameObject tmp = GameObject.FindGameObjectWithTag("GameController");
        controller = tmp.GetComponent();
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            Destroy(gameObject, 0);
            number++;
            Instantiate(explosion, transform.position, transform.rotation);

            Destroy(explosion);
            if (number == 8)
            {
                Destroy(other.gameObject, 0);
                Instantiate(explosion2, transform.position, transform.rotation);
                Destroy(explosion2);
                controller.EndGame();
            }

        }
    }
}

BoundaryDestory.cs

using System.Collections.Generic;
using UnityEngine;

public class BoundaryDestory : MonoBehaviour {
    public GameObject player;
    private Vector3 offset2;
    // Use this for initialization
    void Start () {
        offset2 = transform.position;
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    void LateUpdate()
    {
       transform.position = player.transform.position + offset2;
    }
    void OnTriggerExit(Collider other) {
        if (other.gameObject.tag == "Bolt")
        {
            Destroy(other.gameObject);
        }
    }
}

CameraControlller.cs

using System.Collections.Generic;
using UnityEngine;

public class CameraControlller : MonoBehaviour {
    public GameObject player;
    private Vector3 offset;
    public float rotationDamping;
    public float distance;
    public float height;
    
    // Use this for initialization
    void Start () {
        offset = transform.position;
        

    }
    
    // Update is called once per frame
    void Update () {
        
    }
    void LateUpdate() {
        float wantedRotationAngle = player.transform.eulerAngles.y;
        float currentRotationAngle = transform.eulerAngles.y;
        currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
        Quaternion currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);
        transform.position = player.transform.position;
        transform.position -= currentRotation * Vector3.forward * distance;
        Vector3 newPosition = new Vector3(transform.position.x, height, transform.position.z);
        transform.position = newPosition;

        transform.LookAt(player.transform);
    }   
}

ContactDestory.cs

using System.Collections.Generic;
using UnityEngine;

public class ContactDestory : MonoBehaviour {
    public GameObject explosion;
    public GameObject shot;
    public Transform shotSpawn;
    private float nextFire;
    public float fireRate;
    private GameController controller;
    // Use this for initialization
    void Start () {
        GameObject tmp = GameObject.FindGameObjectWithTag("GameController");
        controller = tmp.GetComponent();
        if (controller == null) {
            Debug.LogError("Unable to find the GameController script");
        
        }
    }
    
    // Update is called once per frame
    void Update () {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
        }
    }
    void OnTriggerEnter(Collider other) {
        if (other.gameObject.tag == "Bolt") {
            Destroy(gameObject, 0);
            Destroy(other.gameObject, 0);
            controller.addScore(10);
            Instantiate(explosion, transform.position, transform.rotation);
            
            Destroy(explosion);
        }
        if (other.gameObject.tag == "Player")
        {
            Destroy(gameObject, 0);
            Destroy(other.gameObject, 0);
            Instantiate(explosion, transform.position, transform.rotation);

            Destroy(explosion);
            controller.EndGame();
        }
        
    }
}

GameBoundaryDestory.cs

using System.Collections.Generic;
using UnityEngine;

public class GameBoundaryDestory : MonoBehaviour {
    public GameObject player;
    // Use this for initialization
    void Start()
    {
    }

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

    }
    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Bolt" || other.gameObject.tag == "Turret_Bolt")
        {
            Destroy(other.gameObject);
        }
    }
}

GameController.cs

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

public class GameController : MonoBehaviour {
    public GameObject turret;
    public Vector3 spawnValues;
    public int turretCount;
    public float spawnWait;
    public float startWait;
    public int score = 0;
    public GUIText scoreText;
    public GUIText endText;
    private bool gameEnded;
    // Use this for initialization
    void Start()
    {
        gameEnded = false;
        endText.gameObject.SetActive(false);
        scoreText.text = "Score: 0";
        StartCoroutine(SpawnWaves());
        
    }
    
    // Update is called once per frame
    void Update () {
        if (gameEnded)
        {
            if(Input.GetKeyDown(KeyCode.R)){
                Scene level = SceneManager.GetActiveScene();
                SceneManager.LoadScene(level.name);
            
            }
        }
    }
    public void EndGame() {
        gameEnded = true;
        endText.gameObject.SetActive(true);
    }
    public void addScore(int points)
    {
        score += points;
        scoreText.text = "Score: " + score;
    }
    IEnumerator SpawnWaves()
    {
        yield return new WaitForSeconds(startWait);
        for (int i = 0; i < turretCount; i++)
        {
            Vector3 spawnAt = new Vector3(
            Random.Range(-spawnValues.x, spawnValues.x),
            spawnValues.y,
            Random.Range(-spawnValues.z, spawnValues.z));
            Instantiate(turret, spawnAt, Quaternion.identity);
            yield return new WaitForSeconds(spawnWait);
        }
        
        
    }
}

Mover.cs

using System.Collections.Generic;
using UnityEngine;

public class Mover : MonoBehaviour {
    public float speed;
    // Use this for initialization
    void Start () {
        GetComponent().velocity = transform.forward * speed;
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

PlayerController.cs

using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Boundary
{
    public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour {
    public GameObject explosion;
    public GameObject explosion2;
    public float turnSpeed;
    public float speed;
    public Boundary boundary;
    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
    private float nextFire;
    private int number;
    private Vector3 offset;
    private GameController controller;
    // Use this for initialization
    

    void Start () {
        //number = 0;
        offset = transform.position;
    }
    
    // Update is called once per frame
    void Update () {
        GameObject tmp = GameObject.FindGameObjectWithTag("GameController");
        controller = tmp.GetComponent();
        if (controller == null)
        {
            Debug.LogError("Unable to find the GameController script");

        }
        if (Input.GetKey("space") && Time.time > nextFire) {
            nextFire = Time.time + fireRate;
            Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
        }
    }
    void FixedUpdate() {
        float moveHorzontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        if(moveHorzontal !=0)
        {
            transform.Rotate(new Vector3(0.0f,moveHorzontal * turnSpeed,0.0f));
        }
        if(moveVertical !=0)
        {
            Vector3 fwd = transform.forward;
            GetComponent().velocity = fwd * speed * moveVertical;

        }
       /* GetComponent().position = new Vector3(
            Mathf.Clamp(GetComponent().position.x, boundary.xMin, boundary.xMax), 0.0f,
            Mathf.Clamp(GetComponent().position.z, boundary.zMin, boundary.zMax));
        */
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Turret_Bolt")
        {
            Destroy(other.gameObject, 0);
            number++;
            Instantiate(explosion, transform.position, transform.rotation);
            
            Destroy(explosion);
            if (number == 8)
            {
                Destroy(gameObject, 0);
                Instantiate(explosion2, transform.position, transform.rotation);
                Destroy(explosion2);
                controller.EndGame();
            }

        }
    }
}

RandomRotator.cs

using System.Collections.Generic;
using UnityEngine;

public class RandomRotator : MonoBehaviour {
    public float turn;
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    void FixedUpdate() {
        transform.Rotate(new Vector3(0.0f, turn, 0.0f));
    }
    
}

Concrete explanation

  • BoltController.cs
    Set up the spacecraft to be destroyed after being hit by bullets a certain number of times
  • BoundaryDestory.cs
    The spacecraft was destroyed directly when it hit the fort.
  • CameraControlller.cs
    Setting Player's Game Perspective as the First Perspective of Spacecraft
  • ContactDestory.cs
    Set the firing frequency and the bonus mechanism for destroying the turret, and end the game when the ship is destroyed
  • GameBoundaryDestory.cs
    Collision with the turret = explosion on both sides
  • GameController.cs
    Set up score panels, restart games, score statistics, and randomly generate turrets within the map range
  • Mover.cs
    Moving speed of spacecraft
  • PlayerController.cs
    Logic for controlling the spacecraft, including firing, steering, and attacking and destroying the spacecraft, and being hit by bullets in the middle
  • RandomRotator.cs
    Automatic rotation of turret

Screenshots in game

ysh_第7张图片
1.png

Forgive Warships for Upgrading to Sky Explorer


ysh_第8张图片
2.png

ysh_第9张图片
3.png

ysh_第10张图片
4.png

ysh_第11张图片
5.png

Note: Mr. Yan is the most handsome teacher in Zhejiang University of Technology.

你可能感兴趣的:(ysh)