• 大小: 15.79MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-30
  • 语言: 其他
  • 标签: Unity3D  

资源简介

在Umedy上找到一门Unity的入门课,跟着课程写了一个俄罗斯方块的游戏。涉及到unity的基本概念,以及particle模块。

资源截图

代码片段和文件信息

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

public class Board : MonoBehaviour {

    public Transform m_emptySprite;
    public int m_height = 30;
    public int m_width = 10;
    public int m_header = 8;

    public int m_completedRows = 0;

    Transform[] m_grid;

    // create reference to the particle player
    public ParticlePlayer[] m_rowGlowFX = new ParticlePlayer[4];

    void Awake() // prestart
    {
        m_grid = new Transform[m_width m_height];
    }
// Use this for initialization
void Start () {
        DrawEmptyCells();
}

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

}

    bool IsWitinBoard(int x int y) {
        return (x >= 0 && x < m_width && y >= 0);
    }

    public bool IsValidPosition(Shape shape) {
        foreach(Transform child in shape.transform) {
            Vector2 pos = Vectorf.Round(child.position);
            if(!IsWitinBoard((int)pos.x (int)pos.y)) { // float to int cast here
                return false;
            }
            if(IsOccupied((int)pos.x (int)pos.y shape)) {
                return false;
            }
        }
        return true;
    }

    void DrawEmptyCells() {
        if(m_emptySprite != null)
        {
            for (int y = 0; y < m_height - m_header; y++)
            {
                for (int x = 0; x < m_width; x++)
                {
                    Transform clone;
                    clone = Instantiate(m_emptySprite new Vector3(x y 0) Quaternion.identity) as Transform; //  Quaternion.identity rotation zero...
                    clone.name = “Board Space: x=“ + x.ToString() + “ y=“ + y.ToString();
                    clone.transform.parent = transform;
                }
            }
        } else
        {
            Debug.Log(“init sprite“);

        }
    }

    public void StoreShapeInGrid(Shape shape) {
        if (shape == null) return;
        foreach(Transform child in shape.transform) {
            Vector2 pos = Vectorf.Round(child.position);
            Debug.LogWarning(“vector postiion: “ + pos.x + “ “ + pos.y);
            m_grid[(int)pos.x (int)pos.y] = child;
        }
    }

    bool IsOccupied(int x int y Shape shape) {
        return (m_grid[x y] != null && m_grid[x y].parent != shape.transform);// differet object    
    }
    
    bool IsCompleted(int y) {
        for(int x=0;x        {
            if(m_grid[x y] == null)
            {
                return false;
            }
        }
        return true;
    }
    
    void ClearRow(int y) {
        for(int x=0;x        {
            if(m_grid[x y] != null) {
                Destroy(m_grid[x y].gameobject);
            }
            m_grid[x y] = null;
        }
    }

    void ShiftOneRowDown(int y)
    {
        for(int x=0;x        {
            if(m_grid[x y] != null)
            {
                m_grid[x y - 1] = m_grid[x y];
                m_grid[x y] = null;
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-17 18:51  TetrisClone-section11\
     文件         422  2018-04-17 18:51  TetrisClone-section11\.gitignore
     目录           0  2018-04-17 18:51  TetrisClone-section11\Assets\
     文件      241944  2018-04-17 18:51  TetrisClone-section11\Assets\4-0-ShapePivots.jpeg
     文件        1687  2018-04-17 18:51  TetrisClone-section11\Assets\4-0-ShapePivots.jpeg.meta
     文件         192  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts.meta
     目录           0  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\
     文件         214  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426.meta
     文件      111219  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426.zip
     文件         197  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426.zip.meta
     目录           0  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\
     文件       81048  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\hemi head bd it.ttf
     文件         509  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\hemi head bd it.ttf.meta
     文件       12396  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\read-this.html
     文件         200  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\read-this.html.meta
     文件       71442  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\typodermic-eula-02-2014.pdf
     文件         197  2018-04-17 18:51  TetrisClone-section11\Assets\Fonts\hemi-head-426\typodermic-eula-02-2014.pdf.meta
     文件         192  2018-04-17 18:51  TetrisClone-section11\Assets\Particles.meta
     目录           0  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\
     文件         214  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials.meta
     目录           0  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\
     文件        4296  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\CircleMat.mat
     文件          95  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\CircleMat.mat.meta
     文件        4296  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\HexagonMat.mat
     文件         138  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\HexagonMat.mat.meta
     文件        4292  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\LineMat.mat
     文件         138  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\LineMat.mat.meta
     文件        5068  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\SparkleMat.mat
     文件         230  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\SparkleMat.mat.meta
     文件        5072  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\SquareGlowMat.mat
     文件         230  2018-04-17 18:51  TetrisClone-section11\Assets\Particles\Materials\SquareGlowMat.mat.meta
............此处省略245个文件信息

评论

共有 条评论