d252c7441884e39f2b28026aaf8a0184f8fd3119
5 var PlayerController
= new yT(yuu
.C
, {
6 constructor: function (body
, left
, right
) {
10 this.dleftLeft
= this.dleftRight
=
11 this.drightLeft
= this.drightRight
= 0;
16 this.x
= this.lastX
= body
.x
;
17 this.y
= this.lastY
= body
.y
;
19 dleftLeft
: yuu
.propcmd(this, 'dleftLeft'),
20 dleftRight
: yuu
.propcmd(this, 'dleftRight'),
21 drightLeft
: yuu
.propcmd(this, 'drightLeft'),
22 drightRight
: yuu
.propcmd(this, 'drightRight'),
23 up
: yuu
.propcmd(this, 'up'),
24 free
: yuu
.propcmd(this, 'free'),
28 _updatePivots: function () {
29 var PIVOT_SPEED
= 0.05;
30 var leftSpeed
= (this.dleftRight
- this.dleftLeft
) * PIVOT_SPEED
;
31 var rightSpeed
= (this.drightLeft
- this.drightRight
) * PIVOT_SPEED
;
32 this.leftPivot
= yf
.clamp(this.leftPivot
+ leftSpeed
, 0, 1);
33 this.rightPivot
= yf
.clamp(this.rightPivot
+ rightSpeed
, 0, 1);
36 _updateTransforms: function () {
37 this.left
.yaw
= -this.leftPivot
* Math
.PI
/ 2;
38 this.right
.yaw
= this.rightPivot
* Math
.PI
/ 2;
45 var GRAVITY
= -0.0004;
53 var leftAngle
= (1 - this.leftPivot
) * Math
.PI
/ 2;
54 var rightAngle
= (1 - this.rightPivot
) * Math
.PI
/ 2;
56 var vx
= this.x
- this.lastX
;
57 var vy
= this.y
- this.lastY
;
59 var cleft
= Math
.cos(leftAngle
);
60 var cright
= Math
.cos(rightAngle
);
61 var sleft
= Math
.sin(leftAngle
);
62 var sright
= Math
.sin(rightAngle
);
67 var thrust
= +!this.free
* +this.up
* THRUST
;
68 ax
+= thrust
* (cleft
- cright
);
69 ay
+= thrust
* (sright
+ sleft
);
71 var drag
= this.up
? DRAG_OPEN
: this.free
? DRAG_FREE
: DRAG_LOCK
;
72 ax
+= drag
* Math
.max(cleft
, cright
) * vx
* vx
* -Math
.sign(vx
);
73 ay
+= drag
* (sleft
+ sright
) * vy
* vy
* -Math
.sign(vy
);
78 var collided
= this.y
< 0;
80 var friction
= -Math
.sign(vx
) * Math
.abs(ay
)
81 * (Math
.abs(vx
) < 0.001 ? FRICTIONS
: FRICTIONK
);
82 ax
+= Math
.sign(friction
) * Math
.min(Math
.abs(friction
), Math
.abs(vx
));
85 this.y
= Math
.max(0, this.y
);
88 this._updateTransforms();
94 var GameScene
= yT(yuu
.Scene
, {
95 constructor: function () {
100 zoom
* -1.3333333333/2, zoom
* -0.2, zoom
* 1.3333333333, zoom
* 1);
102 var body
, left
, right
;
103 this.player
= new yuu
.E(body
= new yuu
.Transform()
104 .setScale([0.081, 0.091, 1]),
105 new yuu
.QuadC('@player')
107 .setPosition([0, 0]));
108 var leftWing
= new yuu
.E(left
= new yuu
.Transform()
109 .setPosition([-0.3, 0.65, 0])
110 .setScale([0.45, 0.22, 1]),
111 new yuu
.QuadC('@left')
114 .setPosition([0, 0]));
115 var rightWing
= new yuu
.E(right
= new yuu
.Transform()
116 .setPosition([0.3, 0.65, 0])
117 .setScale([0.45, 0.22, 1]),
118 new yuu
.QuadC('@right')
121 .setPosition([0, 0]));
122 this.player
.addChildren(leftWing
, rightWing
);
123 this.entity0
.addChild(this.player
);
125 var ground
= new yuu
.E(new yuu
.Transform()
126 .setPosition([0, -10, 1])
127 .setScale([100, 20, 1]),
129 .setColor([0, 0.5, 0, 1]));
130 this.entity0
.addChild(ground
);
133 this.controller
= new PlayerController(body
, left
, right
));
134 Object
.assign(this.commands
, this.controller
.commands
);
136 this.ready
= yuu
.ready([
137 new yuu
.Material('@player'),
138 new yuu
.Material('@left'),
139 new yuu
.Material('@right')]);
143 var audio0
= new Audio();
144 audio0
.src
= audio0
.canPlayType('audio/ogg')
145 ? "data/sound/starting-line.ogg"
146 : "data/sound/starting-line.mp3";
147 audio0
.autoplay
= true;
149 document
.body
.appendChild(audio0
);
150 var source
= yuu
.audio
.createMediaElementSource(audio0
);
151 source
.connect(yuu
.audio
.music
);
167 yuu
.director
.start();
171 storage
= ystorage
.getStorage();
172 yuu
.audio
.storage
= storage
;
173 var game
= new GameScene();
174 yuu
.director
.pushScene(game
);
178 window
.addEventListener("load", function() {
179 yuu
.registerInitHook(load
);
180 yuu
.init({ backgroundColor
: [0, 0, 0, 1], antialias
: false })