Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //LEVELLORD (File0): Controls pretty much everything.
- private var newVertices : Vector3[];
- private var newUV : Vector2[];
- private var newTriangles : int[];
- //local
- private var verts : Array;
- private var UVs : Array;
- private var triangles : Array;
- private var currentLength : int;
- //universal
- private var totalVerts : Array;
- private var totalUVs : Array;
- private var totalTriangles : Array;
- private var mesh : Mesh;
- var lines : GameObject;
- private var toggle : boolean;
- private var b : float;
- private var enumeration : int;
- var player : GameObject;
- var level : Texture2D;
- function Start () {
- enumeration = 0;
- totalVerts = new Array();
- totalUVs = new Array();
- totalTriangles = new Array();
- loadLevel ();
- mesh = new Mesh ();
- /*flat (Vector2(1,1),3);
- halfPipe(Vector2(0,0), Dir.Right, 2);*/
- newVertices = totalVerts.ToBuiltin(Vector3);
- newUV = totalUVs.ToBuiltin(Vector2);
- newTriangles = totalTriangles.ToBuiltin(int);
- mesh.vertices = newVertices;
- mesh.uv = newUV;
- mesh.triangles = newTriangles;
- mesh.RecalculateNormals();
- GetComponent.<MeshFilter>().mesh = mesh;
- var Caylan = Instantiate (lines, Vector3(0,0,0),Quaternion.identity);
- Caylan.SendMessage("setMesh",mesh);
- Caylan.transform.parent = transform;
- characterGraphics = Instantiate (player, Vector3(playerStart.x,levelData[playerStart.x,playerStart.y].height/2+.3, playerStart.y+.5),Quaternion.identity);
- currentDirection = Dir.Up;
- currentTile = levelData[playerStart.x,playerStart.y];
- yield WaitForSeconds (0.1);
- animHandle = GameObject.FindGameObjectWithTag("animHandle");
- }
- var animHandle : GameObject;
- var currentDirection : Dir;
- var baseSpeed : float; //(tiles/second)
- var maxSpeed : int; //baseSpeeds
- var currentSpeed : float; //baseSpeeds
- var characterGraphics : GameObject;
- var mode : modes;
- var currentTile : tile;
- var nextTile : tile;
- /*public class index {
- public var x : int;
- public var y : int;
- public function index (a:float, b:float) {
- x = Mathf.FloorToInt(a);
- y = Mathf.FloorToInt(b);
- } public function index (a: Vector2) {
- x = Mathf.FloorToInt(a.x);
- y = Mathf.FloorToInt(a.y);
- }} */
- enum modes {grounded, pipe, falling};
- //type; dir; height
- var expose : float;
- var up : boolean;
- var sendAnim : boolean = false;
- function FixedUpdate () {
- nextTile = levelData[Mathf.FloorToInt(characterGraphics.transform.position.x+0.24),Mathf.FloorToInt(characterGraphics.transform.position.z)];
- if (currentTile.type == Type.normal) {
- if (nextTile.type == Type.normal) {
- if (nextTile.height == currentTile.height) {
- currentTile = nextTile;
- }} else if (nextTile.type == Type.pipe) {
- mode = modes.pipe;
- animHandle.SendMessage("upRamp", baseSpeed*currentSpeed);
- currentTile = nextTile;
- up = true;
- }} if (mode == modes.grounded) {
- characterGraphics.transform.Translate(currentSpeed*baseSpeed, 0,0);
- } if (mode == modes.pipe) {
- expose = characterGraphics.transform.position.x+0.24-Mathf.Floor(characterGraphics.transform.position.x+0.24);
- if ((nextTile.type == currentTile.type) && up) {
- characterGraphics.transform.Translate(currentSpeed*baseSpeed, a*expose*expose*currentSpeed*baseSpeed,0);
- } else if ((characterGraphics.transform.position.y < (currentTile.height/2+1.2+(currentSpeed/2)))&& (up)) {
- characterGraphics.transform.Translate(0, currentSpeed*baseSpeed,0);
- sendAnim = true;
- } else if (characterGraphics.transform.position.y > (currentTile.height/2+0.65)) {
- up = false;
- characterGraphics.transform.Translate(0, 0-(currentSpeed*baseSpeed),0);
- if ((characterGraphics.transform.position.y < (currentTile.height/2+0.65+baseSpeed*currentSpeed*5.2))&&sendAnim){
- sendAnim = false;
- animHandle.SendMessage("downRamp", baseSpeed*currentSpeed);
- }} else if ((characterGraphics.transform.position.y > (currentTile.height/2)+.2)) {
- characterGraphics.transform.Translate(0-currentSpeed*baseSpeed, 0-a*expose*expose*currentSpeed*baseSpeed,0);
- }}}
- function move () {
- }
- var direct : Dir;
- var levelLoad : Color[];
- var playerStart : Vector2;
- var levelData : tile[,];
- function loadLevel () {
- debugArray = new Array();
- levelLoad = level.GetPixels(0,0,level.width,level.height);
- levelData = new tile[level.width,level.height];
- for (var i=0; i<level.width;i++){
- for (var j=0; j< level.height; j++){
- if (levelLoad[j*level.width+i].r < 0.1)
- direct = Dir.Right;
- else if (levelLoad[j*level.width+i].r < 0.3)
- direct = Dir.Up;
- else if (levelLoad[j*level.width+i].r < 0.6)
- direct = Dir.Left;
- else
- direct = Dir.Down;
- if (levelLoad[j*level.width+i].g == 1) {
- levelData [i,j] = tile(direct, Type.normal,Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- flat (Vector2(i,j), Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- } else if (levelLoad[j*level.width+i].g == (128.0/255.0)) {
- levelData [i,j] = tile(direct, Type.pipe,Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- halfPipe (Vector2(i,j), direct, Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- } else if (levelLoad[j*level.width+i].g == (91.0/255.0)){
- levelData [i,j] = tile(direct, Type.normal,Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- playerStart = Vector2(i,j);
- flat (Vector2(i,j), Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- } else
- levelData [i,j] = tile(direct, Type.pit,Mathf.RoundToInt(levelLoad[j*level.width+i].b*255));
- }}}
- public class tile {
- public var direction : Dir;
- public var type : Type;
- public var height : int;
- public function tile (a :Dir, b: Type, c:int) {
- direction = a;
- type = b;
- height = c;
- }}
- enum Dir {Up, Left, Right, Down};
- enum Type {normal, pipe, pit};
- var curvature : int; //must be even
- var a : float;
- function flat (root:Vector2, height:int){
- triangles = new Array();
- height = height/2;
- verts = Array(
- Vector3(root.x,height,root.y),
- Vector3(root.x+1,height,root.y),
- Vector3(root.x, height,root.y+1),
- Vector3(root.x+1, height,root.y+1),
- Vector3(root.x, 0,root.y),
- Vector3(root.x+1, 0,root.y),
- Vector3(root.x, 0,root.y+1),
- Vector3(root.x+1, 0,root.y+1));
- UVs = Array(Vector2(0,0), Vector2(0,2), Vector2(2,0), Vector2(2,2), Vector2 (2,2), Vector2(2,0),Vector2(0,2),Vector2(0,0));
- triangles = Array(0,3,1, 0,2,3, 0,1,4, 4,1,5, 1,7,5, 1,3,7, 3,6,7, 2,6,3, 0,4,6, 0,6,2);
- currentLength = triangles.length;
- for (i=0; i<currentLength;i++)
- triangles[i] += enumeration;
- totalVerts = totalVerts.concat(verts);
- enumeration = totalVerts.length;
- totalTriangles = totalTriangles.concat(triangles);
- totalUVs = totalUVs.concat(UVs);
- }
- function halfPipe (root:Vector2, direction:Dir, height:int) {
- toggle = true;
- verts = new Array();
- UVs = new Array();
- triangles = new Array();
- height = height/2;
- GetComponent.<MeshFilter>().mesh = mesh;
- for (var i =0; i< curvature; i++) {
- b = i* 1.0/curvature;
- if (direction == Dir.Up) {
- verts.Add(Vector3(root.x+b, a*b*b+height, root.y+0));
- verts.Add(Vector3(root.x+b, a*b*b+height, root.y+1));
- } else if (direction == Dir.Left) {
- verts.Add(Vector3(root.x+1, a*b*b+height, root.y+b));
- verts.Add(Vector3(root.x+0, a*b*b+height, root.y+b));
- } if (direction == Dir.Down) {
- verts.Add(Vector3(root.x+1-b, a*b*b+height, root.y+1));
- verts.Add(Vector3(root.x+1-b, a*b*b+height, root.y+0));
- } else if (direction == Dir.Right) {
- verts.Add(Vector3(root.x+0, a*b*b+height, root.y+1-b));
- verts.Add(Vector3(root.x+1, a*b*b+height, root.y+1-b));
- } if (toggle) {
- UVs.Add (Vector2(0,0));
- UVs.Add (Vector2(2,0));
- UVs.Add (Vector2(0,1));
- UVs.Add (Vector2(2,1));
- triangles.Add (enumeration + i*2);
- triangles.Add (enumeration + i*2+1);
- triangles.Add (enumeration + i*2+2);
- triangles.Add (enumeration + i*2+2);
- triangles.Add (enumeration + i*2+1);
- triangles.Add (enumeration + i*2+3);
- if (i < (curvature-2)) {
- triangles.Add (enumeration + i*2+2);
- triangles.Add (enumeration + i*2+3);
- triangles.Add (enumeration + i*2+5);
- triangles.Add (enumeration + i*2+2);
- triangles.Add (enumeration + i*2+5);
- triangles.Add (enumeration + i*2+4);
- }} toggle = !toggle;
- } currentLength = verts.length;
- for (j= 0; j< currentLength; j++) {
- verts.Add(Vector3(verts[j].x, 0, verts[j].z));
- if (toggle) {
- triangles.Add (enumeration + j, enumeration + j+2, enumeration + j+12);
- triangles.Add (enumeration + j, enumeration + j+12, enumeration + j+10);
- } else {
- triangles.Add (enumeration + j, enumeration + j+12, enumeration + j+2);
- triangles.Add (enumeration + j, enumeration + j+10, enumeration + j+12);
- } toggle=!toggle;
- } triangles.RemoveAt(93); triangles.RemoveAt(93); triangles.RemoveAt(93); triangles.RemoveAt(90); triangles.RemoveAt(90); triangles.RemoveAt(90);
- triangles.RemoveAt(39); triangles.RemoveAt(39); triangles.RemoveAt(39); triangles.RemoveAt(33); triangles.RemoveAt(33); triangles.RemoveAt(33);
- triangles.Add(enumeration + 20,enumeration + 10,enumeration + 22);
- currentLength = UVs.length;
- for (k = 0; k< currentLength; k++){
- if (UVs[k]==Vector2(0,0))
- UVs.Add(Vector2(2,0));
- else if (UVs[k]==Vector2(2,0))
- UVs.Add(Vector2(0,0));
- else if (UVs[k]==Vector2(0,1))
- UVs.Add(Vector2(2,1));
- else if (UVs[k]==Vector2(2,1))
- UVs.Add(Vector2(0,1));
- }
- verts.Add (verts[0], verts[1], verts[12], verts[13], verts[10], verts[11],verts[22],verts[23]);
- triangles.Add(enumeration + 25,enumeration + 24,enumeration + 26, enumeration + 25,enumeration + 26,enumeration + 27, enumeration + 28,enumeration + 29,enumeration + 30, enumeration + 30,enumeration + 29,enumeration + 31);
- UVs.Add(Vector2(0,0),Vector2(0,1),Vector2(2,0),Vector2(2,1)); UVs.Add(Vector2(0,0),Vector2(0,1),Vector2(2,0),Vector2(2,1));
- totalVerts = totalVerts.concat(verts);
- enumeration = totalVerts.length;
- totalTriangles = totalTriangles.concat(triangles);
- totalUVs = totalUVs.concat(UVs);
- }
- //y = ax^2
- //Animation Behavior (File 1) controls the rotation of the board and it's relative position compared to the camera.
- function Start () {
- transform.localScale = Vector3(.15,.15,.15);
- transform.localPosition = Vector3(0,0,0);
- }
- function upRamp (a:float) {
- baldGuy = 0;
- yield WaitForSeconds (a*2);
- up = true;
- slerpTime = a;
- }
- function downRamp (a:float) {
- baldGuy = 0;
- down = true;
- slerpTime = a;
- }
- var slerpTime : float;
- var up : boolean = false;
- var down : boolean = false;
- var baldGuy : float;
- function FixedUpdate () {
- if (up) {
- //baldGuy ++;
- if (transform.rotation.eulerAngles.z < 90)
- transform.Rotate(0,0,90*slerpTime);
- else up = false;
- } else if (down) {
- //baldGuy ++;
- if (transform.rotation.eulerAngles.z > 3)
- transform.Rotate(0,0,-90*slerpTime);
- else down = false;
- }}
- //Lines File 02 (Used to pass a mesh to a second object.) [the mesh with the lines and the solid color one are separate. it's (eventually) to allow customization of gameplay area without too much hassle).
- function setMesh (a : Mesh) {
- GetComponent.<MeshFilter>().mesh = a;
- }
- //Skateboard File 03 (This is literally a 3D model of a skateboard)
- var newVertices : Vector3[];
- var newUV : Vector2[];
- var newTriangles : int[];
- var triangles : Array;
- var UVs : Array;
- var vertices : Array;
- var player: GameObject;
- var width : float;
- var length : float;
- var depth : float;
- var duckHeight : float;
- private var currentLength : int;
- function Start () {
- UVs = new Array ();
- newVertices = [Vector3(0,0,0), Vector3(0,0,width), Vector3(length,0,0), Vector3(length,0,width), Vector3(0,0,width/2),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-30)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-60)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-90)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-120)))),
- Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-150)))),
- Vector3(length,0,width/2),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(30)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(60)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(90)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(120)))),
- Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(150))))
- ]; currentLength = newVertices.Length;
- vertices = Array(newVertices);
- for (j=0; j<currentLength; j++)
- vertices.Add(Vector3(newVertices[j].x,newVertices[j].y-depth,newVertices[j].z));
- newVertices = vertices.ToBuiltin(Vector3);
- newTriangles = [0,1,3, 0,3,2, 0,9,4, 5,4,6, 6,4,7, 7,4,8, 8,4,9, 5,1,4,
- 2,10,15, 15,10,14, 14,10,13, 13,10,12, 12,10,11, 11,10,3 ];
- currentLength = (newTriangles.Length/3);
- triangles = Array(newTriangles);
- for (k=0; k< currentLength; k++){
- triangles.Add(newTriangles[k*3]+16);
- triangles.Add(newTriangles[k*3+2]+16);
- triangles.Add(newTriangles[k*3+1]+16);
- } triangles.Add(0,2,16, 18,16,2,
- 2,15,18, 18,15,31,
- 15,14,31, 31,14,30,
- 14,13,30, 30,13,29,
- 13,12,28, 13,28,29,
- 12,11,27, 12,27,28,
- 11,3,19, 11,19,27,
- 3,1,19, 1,17,19,
- 1,5,21, 1,21,17,
- 5,6,22, 21,5,22,
- 6,23,22, 23,6,7,
- 23,7,24, 24,7,8,
- 8,25,24, 25,8,9,
- 16,25,9, 16,9,0);
- newTriangles = triangles.ToBuiltin(int);
- for (i=0; i< newVertices.length; i++)
- UVs.Add (Vector2(0,0));
- newUV = UVs.ToBuiltin(Vector2);
- var mesh : Mesh = new Mesh ();
- GetComponent.<MeshFilter>().mesh = mesh;
- mesh.vertices = newVertices;
- mesh.uv = newUV;
- mesh.triangles = newTriangles;
- mesh.RecalculateNormals();
- var tyler = Instantiate (player, Vector3 (transform.position.x+ length/2, transform.position.y+ 0 - depth/2, transform.position.z+ width/2), Quaternion.identity);
- tyler.transform.parent = transform.parent;
- transform.parent = tyler.transform;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement