-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerBat.js
99 lines (67 loc) · 2.61 KB
/
PlayerBat.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
/*
class PlayerBat
{
constructor()
{
var geometry = new THREE.BoxGeometry(1, 8, 1);
var material = new THREE.MeshBasicMaterial( { color: 0x2f23cf } );
this.targetYPosition = 0;
this.yPosTick = 0.05;
this.mesh = new THREE.Mesh(geometry, material);
this.mesh.position.x = -20;
scene.add(this.mesh);
}
Update(deltaTime)
{
this.targetYPosition = (cameraHeight / 2) - mouseYPos * (cameraHeight / window.innerHeight);
if (this.mesh.position.y < this.targetYPosition)
{
this.mesh.position.y += this.yPosTick * deltaTime;
}
else if (this.mesh.position.y > this.targetYPosition)
{
this.mesh.position.y -= this.yPosTick * deltaTime;
}
};
};
*/
class PlayerBat
{
constructor(isThisBatAnEnemy, xPosOfTheBatsnStuff)
{
var batModel = new THREE.BoxGeometry(1, 8, 1);
var batMaterial = new THREE.MeshBasicMaterial({ color: 0xf2f2f2 })
this.targetYPosition = 0;
this.yPosSpeed = 0.05;
this.yEnemyPosSpeed = 0.025;
this.mesh = new THREE.Mesh(batModel, batMaterial);
this.mesh.position.x = xPosOfTheBatsnStuff;
this.enemyOrNot = isThisBatAnEnemy;
scene.add(this.mesh);
}
Update(deltaTime)
{
switch (this.enemyOrNot)
{
case false:
this.targetYPosition = (cameraHeight / 2) - mouseYPos * (cameraHeight / window.innerHeight);
if ((this.mesh.position.y) < this.targetYPosition && (Math.abs(this.mesh.position.y - this.targetYPosition) > 1))
{
this.mesh.position.y += (this.yPosSpeed * deltaTime);
}
else if ((this.mesh.position.y) > this.targetYPosition && (Math.abs(this.mesh.position.y - this.targetYPosition) > 1)) {
this.mesh.position.y -= (this.yPosSpeed * deltaTime);
}
break;
case true:
this.targetYPosition = currentBallPos.y;
if (((this.mesh.position.y) < this.targetYPosition) && (currentBallPos.x >= (8) && (Math.abs(this.mesh.position.y - this.targetYPosition) > 1))) {
this.mesh.position.y += (this.yEnemyPosSpeed * deltaTime);
}
else if ((this.mesh.position.y) > this.targetYPosition && (currentBallPos.x >= (8) && (Math.abs(this.mesh.position.y - this.targetYPosition) > 1))) {
this.mesh.position.y -= (this.yEnemyPosSpeed * deltaTime);
}
break;
}
}
}