forked from nathanctung/MoonRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.js
136 lines (122 loc) · 3.83 KB
/
global.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// GLOBAL VARIABLES:
var canvas;
var gl;
var program;
var length = 0.5;
var time = 0.0;
var timer = new Timer();
// GAME SETTINGS:
var SMART_MOVEMENT = false;
var DEBUGGING_MODE = false;
var RESET_READY = false;
// constant game data (i.e. number of each object to render, total health capacity, etc.
var NUM_DEBRIS = 20; // (MAX: 40)
var NUM_HEALTH = 1; // (MAX: 10)
var NUM_FLAG = 2; // (MAX: 10)
var NUM_SLOW = 1; // (MAX: 10)
var FLAG_NUM_POINTS = 250;
var MAX_TOTAL_HEALTH = 3; // incrementing this beyond 3 will require heartPositions to be modified
var CAPTION_TIME_LENGTH = 2000; // in milliseconds
// invincibility frames
var BORDER_COLOR_INVINCIBLE = "rgb(102, 178, 255)";
var BORDER_COLOR_NORMAL = "rgb(0, 0, 0)";
// player progress
var gamestart = false;
var instructionsOn = false;
var life = 3;
var score = 0;
var invincibility = 0;
var invincibilityPeriod = 45; // number of invincibility frames after being hit
var previouslyHit;
var captionTimer = CAPTION_TIME_LENGTH;
// NAVIGATION SYSTEM:
var x = 0;
var y = 0;
var z = 0;
var textureDegree = 0; // rotational degree (left/right turning)
var textureScrollSpeed = 0.005; // speed
var scrollX = 0;
var scrollY = 0;
var scrollZ = 0;
var turnInterval = 0;
// BUFFER VARIABLES:
var positionBuffer;
var normalBuffer;
var uvBuffer;
// VIEW/TRANSFORMATION MATRIX:
var uniform_mvpMatrix;
var viewMatrix;
var projectionMatrix;
var mvpMatrix;
var orthoProjectionMatrix;
// VIEW MATRIX:
var eye = vec3(0, 1, 0.001);
var at = vec3(0, 0, -100);
var up = vec3(0, 1, 0);
// LIGHT AND SHADING:
var attribute_position;
var attribute_normal;
var uniform_lightPosition;
var uniform_shininess;
var uniform_sampler;
var shininess = 50;
var lightPosition = vec3(0.0, 0.0, 0.0);
// TEXTURES:
var groundTexture;
var spaceTexture;
var planetTexture;
var debrisTexture;
var heartTexture;
var healthTexture;
var flagTexture;
var slowTexture;
// GROUND VARIABLES:
var groundVertices = [
vec3(length, 0, length),
vec3(length, 0, -length),
vec3(-length, 0, -length),
vec3(-length, 0, length)
];
var planePoints = [];
var planeNormals = [];
var planeUv = [];
var index = 0;
// CUBE VARIABLES:
var cubeVertices = [
vec3( length, length, length ), //vertex 0
vec3( length, -length, length ), //vertex 1
vec3( -length, length, length ), //vertex 2
vec3( -length, -length, length ), //vertex 3
vec3( length, length, -length ), //vertex 4
vec3( length, -length, -length ), //vertex 5
vec3( -length, length, -length ), //vertex 6
vec3( -length, -length, -length ) //vertex 7
];
var cubePoints = [];
var cubeNormals = [];
var cubeUv = [];
//SPHERE VARIABLES:
var planetPoints;
var planetNormals;
var planetUv;
var planetIndexBuffer;
var planetIndexData;
// OBJECT DATA:
// data for debris continually being re-rendered (MAX 40)
var debris_positionX = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var debris_positionZ = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// data for health pack(s) continually being re-rendered (MAX 10)
var health_positionX = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var health_positionZ = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// data for flag(s) continually being re-rendered (MAX 10)
var flag_positionX = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var flag_positionZ = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// data for slow sign(s) continually being re-rendered (MAX 10)
var slow_positionX = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
var slow_positionZ = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
// life bar HUD data
var heartPositions = [
vec3(-4.5, 4.5, 0),
vec3(-3.5, 4.5, 0),
vec3(-2.5, 4.5, 0)
];