From: Joe Wreschnig Date: Mon, 8 Sep 2014 14:20:04 +0000 (+0200) Subject: Port over controller logic from Python. X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=6a662cfe7cd27e67c4457feceda67a966ca75f09;p=featherfall2.git Port over controller logic from Python. --- diff --git a/src/data/sound/starting-line.ogg b/src/data/sound/starting-line.ogg new file mode 100644 index 0000000..7028829 Binary files /dev/null and b/src/data/sound/starting-line.ogg differ diff --git a/src/index.html b/src/index.html index c1b8032..24ab463 100644 --- a/src/index.html +++ b/src/index.html @@ -37,7 +37,7 @@ - +
0) { + dragy = -dragy; + liftx = -liftx; + } + if (vx > 0) { + dragx = -dragx; + lifty = -lifty; + } + + var ax = dvx + liftx + dragx; + var ay = dvy + lifty + dragy; + + var origX = this.x; + var origY = this.y; + this.x += (this.x - this.lastX) + ax * dt * dt; + this.y += (this.y - this.lastY) + ay * dt * dt; + this.y = Math.max(0, this.y); + this.lastX = origX; + this.lastY = origY; + this._updateTransforms(); }, TAPS: ['tick'], -});*/ +}); var GameScene = yT(yuu.Scene, { constructor: function () { yuu.Scene.call(this); - this.layer0.resize(-0.5, -0.5, 1, 1); + this.layer0.resize(-1.3333333333/2, -0.2, 1.3333333333, 1); - this.player = new yuu.E(new yuu.Transform(), - new yuu.QuadC('@player')); - var leftWing = new yuu.E(new yuu.Transform(), - new yuu.QuadC('@left')); - var rightWing = new yuu.E(new yuu.Transform(), - new yuu.QuadC('@right')); + var body, left, right; + this.player = new yuu.E(body = new yuu.Transform() + .setScale([0.081, 0.091, 1]), + new yuu.QuadC('@player') + .setAnchor('bottom') + .setPosition([0, 0])); + var leftWing = new yuu.E(left = new yuu.Transform() + .setPosition([-0.3, 0.65, 0]) + .setScale([0.45, 0.22, 1]), + new yuu.QuadC('@left') + .setZ(-1) + .setAnchor("right") + .setPosition([0, 0])); + var rightWing = new yuu.E(right = new yuu.Transform() + .setPosition([0.3, 0.65, 0]) + .setScale([0.45, 0.22, 1]), + new yuu.QuadC('@right') + .setZ(-1) + .setAnchor('left') + .setPosition([0, 0])); this.player.addChildren(leftWing, rightWing); this.entity0.addChild(this.player); + var ground = new yuu.E(new yuu.Transform() + .setPosition([0, -10, 1]) + .setScale([100, 20, 1]), + new yuu.QuadC() + .setColor([0, 0.5, 0, 1])); + this.entity0.addChild(ground); + + this.player.attach( + this.controller = new PlayerController(body, left, right)); + Object.assign(this.commands, this.controller.commands); + this.ready = yuu.ready([ new yuu.Material('@player'), new yuu.Material('@left'), new yuu.Material('@right')]); }, + init: function () { + var audio0 = new Audio(); + audio0.src = audio0.canPlayType('audio/ogg') + ? "data/sound/starting-line.ogg" + : "data/sound/starting-line.mp3"; + audio0.autoplay = true; + audio0.loop = true; + document.body.appendChild(audio0); + var source = yuu.audio.createMediaElementSource(audio0); + source.connect(yuu.audio.music); + }, + KEYBINDS: { space: '+up', up: '+up', - q: '+dleft_left', - w: '+dleft_right', - o: '+dright_left', - p: '+dright_right', + q: '+dleftLeft', + w: '+dleftRight', + o: '+drightLeft', + p: '+drightRight', } }); @@ -50,6 +185,7 @@ function load () { yuu.audio.storage = storage; var game = new GameScene(); yuu.director.pushScene(game); + return game.ready; } window.addEventListener("load", function() { diff --git a/src/yuu/audio.js b/src/yuu/audio.js index 881924e..128ff84 100644 --- a/src/yuu/audio.js +++ b/src/yuu/audio.js @@ -118,6 +118,7 @@ sampleRate: { alias: "_ctx.sampleRate" }, createGain: { proxy: "_ctx.createGain" }, + createMediaElementSource: { proxy: "_ctx.createMediaElementSource" }, createOscillator: { proxy: "_ctx.createOscillator" }, });