-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster.js
127 lines (109 loc) · 3.11 KB
/
master.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
const THREE = require('three');
const Scene = require('./scene');
const Brick = require('./brick');
const Queue = require('./queue');
const socket = require('socket.io-client')(window.location.host);
//==================
//--Define command--
//==================
const SPACE = 0;
const PLAY = 1;
const PAUSE = 2;
const GAMEOVER = 3;
const PLAYAGAIN = 4;
//==================
//---Inisialisasi---
//==================
var scenes = new Array(new Scene());
var scene = new Scene();
let bricks = new Array(new Queue());
let brick = new Brick();
let scale = new THREE.Vector3();
let position = new THREE.Vector3();
let command = PLAY, startPos = 6.5, direction = 'x';
let hue = 0;
let scoreValue = 0;
let previousScoreValue = 0;
var scoreDisplay = document.getElementById("score");
var gameoverDisplay = document.getElementById("game-over");
function init() {
for(let i = 0;i < 4; i++) {
scene = new Scene({
numPlayer: i+1,
maxPlayer: 4
});
scenes.push(scene);
// Mengatur parameter warna berdasarkan nilai hue-nya
hue = Math.floor(Math.random() * 360);
// Membuat tumpukan awal hingga
// bagian bawah tertutupi
for(let j = -14;j < 0; j++) {
brick = new Brick({
position: new THREE.Vector3(0, j, 0),
direction: 'z',
color: "hsl(" + hue +", 100%, 50%)"
});
bricks[i].push(brick);
scenes[i].add(bricks[i].build);
}
// Tumpukan paling atas
brick = new Brick({
position: new THREE.Vector3(0, 0, startPos),
direction: 'z',
color: "hsl(" + hue +", 100%, 50%)"
});
bricks[i].push(brick);
scenes[i].add(bricks[i].build);
}
// Disable view gameover
gameoverDisplay.style.display = "none";
}
init();
//=======================
//-----Socket client-----
//=======================
const roomName = 'nganu';
socket.emit('join', roomName);
//-----------------------
socket.on('sync', function(data) {
for(let i = 0;i < data.property.length; i++) {
bricks[data.id-1].items[i].position = data.property[i].position;
bricks[data.id-1].items[i].scale = data.property[i].scale;
bricks[data.id-1].items[i].color = data.property[i].hue;
}
if(data.score != previousScoreValue) {
scoreValue = data.score;
scoreDisplay.innerHTML = scoreValue;
previousScoreValue = scoreValue;
}
});
//=======================
//--Algoritma permainan--
//=======================
function animate() {
requestAnimationFrame(() => {animate()});
loop();
}
//-----------------------
function loop() {
switch (command) {
// Balok melakukan update
case PLAY:
break;
case PAUSE:
break;
// Balok berhenti, memotong, dan stop
// sesuai kondisi
case SPACE:
break;
case GAMEOVER:
break;
case PLAYAGAIN:
break;
default:
break;
}
for(let i = 0;i < scenes.length; i++)
scenes[i].render();
}
animate();