This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game1_noSound-BACKUP.js
181 lines (150 loc) · 4.43 KB
/
game1_noSound-BACKUP.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*{# Copyright (c) 2012 Turbulenz Limited #}*/
/*
* @title: 2D Physics
* @description:
* This sample shows how to create and use the Turbulenz 2D physics device.
* The sample creates several 2D static objects with surface velocity,
* two animated kinematic objects to push and lift objects around,
* and a hundred rigid bodies with different material properties.
* Left click to pick up and move the rigid bodies and right click to add new ones.
*/
/*{{ javascript("jslib/draw2d.js") }}*/
/*{{ javascript("jslib/utilities.js") }}*/
/*{{ javascript("jslib/requesthandler.js") }}*/
/*{{ javascript("jslib/services/turbulenzservices.js") }}*/
/*{{ javascript("jslib/services/turbulenzbridge.js") }}*/
/*{{ javascript("jslib/services/gamesession.js") }}*/
TurbulenzEngine.onload = function onLoadFn() {
//===================================================
// Turbulenz Initialization =
//===================================================
var bgColor = [0.0, 1.0, 0.0, 1.0];
//TODO remove
var screen = 0;
var graphicsDevice = TurbulenzEngine.createGraphicsDevice({});
var mathDevice = TurbulenzEngine.createMathDevice({});
var requestHandler = RequestHandler.create({});
var gameSession;
function sessionCreated(gameSession) {
//Great, and now?
}
gameSession = TurbulenzServices.createGameSession(requestHandler, sessionCreated);
//===================================================
// Draw2D/Physics =
//===================================================
//setup
var draw2D = Draw2D.create({
graphicsDevice : graphicsDevice
});
//configure
draw2D.configure({
viewportRectangle : [0, 0, 1920, 1080],
scaleMode : 'scale'
});
//startup
var loadedItems = 0;
var layer0 = Draw2DSprite.create({
x : 1920 / 2,
y : 1080 / 2,
width : 1920,
height : 1080
});
var layer1 = Draw2DSprite.create({
x : 1920 / 2,
y : 1012,
width : 1920,
height : 136
});
var layer2 = Draw2DSprite.create({
x : 1920 / 2,
y : 396,
width : 1138,
height : 742
});
var sprite1 = graphicsDevice.createTexture({
src : "assets/Game1_sprite1_v1.0.png",
mipmaps : true,
onload : function(texture) {
if (texture) {
layer0.setTexture(texture);
layer1.setTexture(texture);
layer2.setTexture(texture);
layer0.setTextureRectangle([0, 0, 1920, 1080]);
layer0.setOrigin([1920 / 2, 1080 / 2]);
layer1.setTextureRectangle([0, 1080, 1920, 1216]);
layer1.setOrigin([960, 68]);
layer2.setTextureRectangle([0, 1300, 1138, 2042]);
loadedItems++;
screen = 1;
}
}
});
//===================================================
// Input Controls =
//===================================================
var inputDevice = TurbulenzEngine.createInputDevice({});
var keyCodes = inputDevice.keyCodes;
var mouseCodes = inputDevice.mouseCodes;
var onKeyDown = function onKeyDownFn(keynum) {
if (keynum === keyCodes.RETURN) {
console.log("Pressed Return");
screen = 2;
}
};
inputDevice.addEventListener('keydown', onKeyDown);
//===================================================
// Main Loop =
//===================================================
function mainLoop() {
//Tick Tock Tick Tock...
console.log("TICK");
inputDevice.update();
if (graphicsDevice.beginFrame()) {
graphicsDevice.clear(bgColor, 1.0);
//Render here
draw2D.begin();
draw2D.drawSprite(layer0);
draw2D.end();
draw2D.begin('alpha');
draw2D.drawSprite(layer1);
draw2D.end();
graphicsDevice.endFrame();
}
}
TurbulenzEngine.onunload = function onUnloadFn() {
if (intervalID) {
TurbulenzEngine.clearInterval(intervalID);
}
//TODO clean everything
};
TurbulenzEngine.onerror = function gameErrorFn(msg) {
window.alert(msg);
};
var intervalID;
function menu() {
if (screen < 1) {
return;
}
inputDevice.update();
if (graphicsDevice.beginFrame()) {
graphicsDevice.clear(bgColor, 1.0);
if (loadedItems === 1) {
//Render here
draw2D.begin();
draw2D.drawSprite(layer0);
draw2D.end();
draw2D.begin('alpha');
draw2D.drawSprite(layer2);
draw2D.drawSprite(layer1);
draw2D.end();
}
graphicsDevice.endFrame();
}
//TODO restrict!
if (screen === 2) {
TurbulenzEngine.clearInterval(intervalID);
intervalID = TurbulenzEngine.setInterval(mainLoop, 1000 / 60);
}
}
intervalID = TurbulenzEngine.setInterval(menu, 10);
};