Skip to content

Commit 2acea00

Browse files
committed
2 parents 51fdafb + 8798212 commit 2acea00

File tree

4 files changed

+62
-20
lines changed

4 files changed

+62
-20
lines changed

css/style.css

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ body, #c {
2727
z-index: 1;
2828
}
2929

30+
#perfect {
31+
font-size: 2.5em;
32+
font-family: 'Courier New', Courier, monospace;
33+
font-weight: lighter;
34+
color: white;
35+
position: absolute;
36+
bottom: 15%;
37+
width: 100%;
38+
text-align: center;
39+
display:block;
40+
font-weight: bold;
41+
text-shadow: 5px 5px #2915A7;
42+
z-index: 1;
43+
opacity: 0.0;
44+
}
45+
3046
#game-over {
3147
font-size: 1.5em !important;
3248
font-family: 'Courier New', Courier, monospace;

js/app.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ function init() {
4343
gameoverDisplay.style.display = "none";
4444

4545
// Membuat ground tempat pijakan balok
46-
var ground_material = Physijs.createMaterial(
47-
new THREE.MeshLambertMaterial({color: 0xffffff}),
48-
1.,
49-
0,1
50-
);
51-
var ground = new Physijs.BoxMesh(
52-
new THREE.BoxGeometry(5, 1, 5),
53-
ground_material,
54-
0
55-
);
56-
ground.position.set(0,-13.5,0);
57-
scene.add(ground);
46+
// var ground_material = Physijs.createMaterial(
47+
// new THREE.MeshLambertMaterial({color: 0xffffff}),
48+
// 1.,
49+
// 0,1
50+
// );
51+
// var ground = new Physijs.BoxMesh(
52+
// new THREE.BoxGeometry(5, 1, 5),
53+
// ground_material,
54+
// 0
55+
// );
56+
// ground.position.set(0,-13.5,0);
57+
// scene.add(ground);
5858

5959
// Membuat tumpukan awal hingga
6060
// bagian bawah tertutupi
@@ -190,7 +190,8 @@ function loop() {
190190
spawnBox();
191191

192192
// Jika balok masih bisa memotong, maka loop lanjut
193-
if(brick.cut(prevBrick)) {
193+
var cutted_brick = brick.cut(prevBrick);
194+
if(cutted_brick[0]) {
194195
// Balok baru berupa potongan akan dapat efek Physijs
195196
// var fallingbrick = new FallingBrick(prevBrick.params);
196197
// fallingbricks.push(fallingbrick);
@@ -241,6 +242,9 @@ function loop() {
241242

242243
// Update score
243244
scoreValue++;
245+
if(cutted_brick[5]==true){
246+
scoreValue++;
247+
}
244248
scoreDisplay.innerHTML = scoreValue;
245249

246250
// mengembalikan state menjadi play
@@ -371,7 +375,6 @@ function nambahlagu(){
371375
else if (isPlay==1)
372376
{
373377
myAudio.stop();
374-
console.log("aaa");
375378
}
376379
}
377380

js/brick.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Brick {
88
//===============
99
//---Parameter---
1010
//===============
11+
var perfect = document.getElementById("perfect");
1112
var defaultParam = {
1213
size: new THREE.Vector3(1, 1, 1),
1314
position: new THREE.Vector3(0, 0, 0),
@@ -136,23 +137,41 @@ class Brick {
136137
*/
137138
cut(prevBrick)
138139
{
140+
console.log(this.color);
141+
var mantap = false;
139142
var prevPosition = prevBrick.position;
143+
prevPosition.x = Number((prevPosition.x).toFixed(1));
144+
prevPosition.y = Number((prevPosition.y).toFixed(1));
145+
prevPosition.z = Number((prevPosition.z).toFixed(1));
146+
140147
var curScale = this.scale;
148+
curScale.x = Number((curScale.x).toFixed(1));
149+
curScale.y = Number((curScale.y).toFixed(1));
150+
curScale.z = Number((curScale.z).toFixed(1));
151+
141152
var curPosition = this.position;
153+
curPosition.x = Number((curPosition.x).toFixed(1));
154+
curPosition.y = Number((curPosition.y).toFixed(1));
155+
curPosition.z = Number((curPosition.z).toFixed(1));
142156

143157
var diffX = curPosition.x - prevPosition.x;
144158
var diffZ = curPosition.z - prevPosition.z;
145159

146-
console.log("x : " + diffX, curScale.x);
147-
console.log("Z : " + diffZ, curScale.z);
160+
// console.log("x : " + diffX, curScale.x);
161+
// console.log("Z : " + diffZ, curScale.z);
162+
163+
if(diffX==0 && diffZ==0){
164+
perfect.style.opacity = 1.0;
165+
mantap = true;
166+
}
148167

149168
// Jika ukuran saat ini lebih kecil
150169
// dari potongannya, maka error / gameover (return false)
151170
if(curScale.x < Math.abs(diffX)
152171
|| curScale.z < Math.abs(diffZ) ) {
153172
this.disabledMass();
154173
Brick.resetSpeed();
155-
return false;
174+
return [false, prevPosition, curScale, curPosition, this.color, mantap];
156175
}
157176

158177
curScale.x -= Math.abs(diffX);
@@ -162,18 +181,21 @@ class Brick {
162181

163182
Brick.increaseSpeed();
164183
this.scale.copy(curScale);
165-
return true;
184+
return [true, prevPosition, curScale, curPosition, this.color, mantap];
166185
}
167186

168187
/**
169188
* Melakukan move object sesuai arah
170189
* pada sumbu cartesian 'x' dan 'z'
171190
*/
172191
move() {
192+
if(perfect.style.opacity>0){
193+
perfect.style.opacity-=0.03;
194+
}
173195
const batas = 6.5;
174196

175-
console.log("x : " + this.position.x);
176-
console.log("Z : " + this.position.y);
197+
// console.log("x : " + this.position.x);
198+
// console.log("Z : " + this.position.y);
177199

178200
switch (this.params.direction) {
179201
// Jika bergerak di-sumbu 'x'

views/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</head>
1111
<body>
1212
<div id="score">0</div>
13+
<div id="perfect">MANTAP MANTAP</div>
1314
<div id="game-over">
1415
<img style="width: 300px;" src="img/over.png" alt="">
1516
<!-- <br>Tekan 'ENTER'<br> -->

0 commit comments

Comments
 (0)