Hello World

By Plump Helmet Studios on

Hello World

The Plump Helmet Studios website is currently under construction. In time, it will show case our progress towards making some beautiful indie games. Right now, though, it is but a seed. Here's to the future!

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

public class HelloWorld : MonoBehaviour
{
    Mesh mesh;
    List<Vector3> vertices;
    List<int> triangles;
    int[][] helloWorldMessageData;
    Vector3 offset;

    void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        vertices = new List<Vector3>();
        triangles = new List<int>();
        helloWorldMessageData = new int[][] {
            new int[] { 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0 },
            new int[] { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1 },
            new int[] { 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0 }

        };
        offset = new Vector3(helloWorldMessageData[0].Length / 2, 0, helloWorldMessageData.Length / 2);
    }

    void Start()
    {
        GenerateMeshData();
        CreateNewMesh();
    }

    void GenerateMeshData()
    {
        for (int z = 0; z < helloWorldMessageData.Length; z++)
        {
            for (int x = 0; x < helloWorldMessageData[z].Length; x++)
            {
                if (helloWorldMessageData[z][x] == 1)
                {
                    GenerateQuad(z, x);
                }
            }
        }
    }

    void GenerateQuad(int z, int x)
    {
        int vIdx = vertices.Count;
        vertices.Add(new Vector3(x - offset.x, 0, z - offset.z));
        vertices.Add(new Vector3(x - offset.x, 0, z - offset.z + 1));
        vertices.Add(new Vector3(x - offset.x + 1, 0, z - offset.z));
        vertices.Add(new Vector3(x - offset.x + 1, 0, z - offset.z + 1));
        triangles.AddRange(new int[] { vIdx, vIdx + 1, vIdx + 2 });
        triangles.AddRange(new int[] { vIdx + 2, vIdx + 1, vIdx + 3 });
    }

    void CreateNewMesh()
    {
        mesh.Clear();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();
    }
}