-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.vwf.yaml
152 lines (147 loc) · 4.32 KB
/
index.vwf.yaml
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
---
extends: http://vwf.example.com/scene.vwf
properties:
keyPressInfo:
paddleSpeed: 2.5
methods:
initializeCamera:
update:
movePlayer:
children:
playerOne:
extends: http://vwf.example.com/node3.vwf
source: paddle.dae
properties:
xPos: -220
translation: [ -470, 0, 0 ]
children:
paddleMaterial:
extends: http://vwf.example.com/material.vwf
properties:
color: "#ff0000"
playerTwo:
extends: http://vwf.example.com/node3.vwf
source: paddle.dae
properties:
xPos: 231
children:
material:
extends: http://vwf.example.com/material.vwf
properties:
color: "#ff0000"
ball:
extends: http://vwf.example.com/node3.vwf
source: ball.dae
properties:
xSpeed: 2
ySpeed: 5
methods:
move:
dealWithPaddleBounce:
children:
material:
extends: http://vwf.example.com/material.vwf
properties:
color: "#0000ff"
scripts:
- |
this.move = function() {
var newTrans = [
this.translation[ 0 ] + this.xSpeed,
this.translation[ 1 ] + this.ySpeed,
this.translation[ 2 ]
];
// Did we hit a wall?
var maxY = 145;
var minY = -maxY;
if ( newTrans[ 1 ] >= maxY ) {
newTrans[ 1 ] = maxY;
this.ySpeed = -this.ySpeed;
} else if ( newTrans[ 1 ] <= minY ) {
newTrans[ 1 ] = minY;
this.ySpeed = -this.ySpeed;
}
// Did we hit a paddle?
var ballAtRightSide = ( newTrans[ 0 ] >= this.parent.playerTwo.xPos );
var ballAtLeftSide = ( newTrans[ 0 ] <= this.parent.playerOne.xPos );
if ( ballAtRightSide ) {
this.dealWithPaddleBounce( this.parent.playerTwo, newTrans );
} else if ( ballAtLeftSide ) {
this.dealWithPaddleBounce( this.parent.playerOne, newTrans );
} else {
this.translation = newTrans;
}
};
this.dealWithPaddleBounce = function( paddle, translation ) {
var yPos = paddle.translation[ 1 ];
var paddleExtent = 36;
if ( translation[ 1 ] > ( yPos + paddleExtent ) || translation[ 1 ] < ( yPos - paddleExtent ) ) {
// Ball got past the paddle: reset the ball position and speed.
this.translateTo( [ 0, 0, 0 ] );
this.xSpeed = 2;
this.ySpeed = 5;
return true;
} else {
// Ball hit the paddle: just bounce.
translation[ 0 ] = paddle.xPos;
this.xSpeed = -this.xSpeed;
return false;
}
};
board:
extends: http://vwf.example.com/node3.vwf
source: board.dae
light:
extends: http://vwf.example.com/light.vwf
properties:
distance: 2000
translation: [ 400, -400, 900 ]
scripts:
- |
this.initialize = function() {
this.future( 0 ).initializeCamera();
this.future( 0 ).update();
}
this.initializeCamera = function() {
this.camera.translation = [ 250, -550, 150 ];
this.camera.rotation = [ 1, 0, 0, -10 ];
// Disable navigation
this.camera.touchmode = "none";
this.camera.navmode = "none";
}
this.update = function() {
if ( this.keyPressInfo ) {
for ( var keyPress in this.keyPressInfo.keysDown ) {
switch( keyPress ) {
case 'R':
this.movePlayer( this.playerOne, +1 );
break;
case 'F':
this.movePlayer( this.playerOne, -1 );
break;
case 'O':
this.movePlayer( this.playerTwo, +1 );
break;
case 'L':
this.movePlayer( this.playerTwo, -1 );
break;
default:
break;
}
}
}
this.ball.move();
this.future( 1.0/60.0 ).update(); // schedule the next step
}
this.keyDown = this.keyUp = function( input ) {
this.keyPressInfo = input;
}
this.movePlayer = function( player, direction ) {
var amount = direction * this.paddleSpeed;
if ( player.translation[ 1 ] + amount >= 120 || player.translation[ 1 ] + amount <= -120 ) {
player.translateTo( [ player.translation[ 0 ], 120 * direction, 0 ] );
return;
} else {
player.translateBy( [ 0, direction * this.paddleSpeed, 0 ] );
}
}