From 3ef4e45daefa735d0b2d2f2feb6b38208fb31f19 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 2 Mar 2016 10:28:50 -0800 Subject: [PATCH] Flappy bird first draft --- examples/flappyBird.js | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/flappyBird.js diff --git a/examples/flappyBird.js b/examples/flappyBird.js new file mode 100644 index 0000000000..95e018089e --- /dev/null +++ b/examples/flappyBird.js @@ -0,0 +1,71 @@ +// +// flappyBird.js +// +// Created by Clement 3/2/16 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// Constants + + + +// Class definitions +function Game() { + // public methods + this.start = function() { + if (!isRunning) { + setup(); + Script.update.connect(idle); + } + }; + + this.stop = function() { + if (isRunning) { + Script.update.disconnect(idle); + cleanup(); + } + }; + + // Private game state + var that = this; + var isRunning = false; + + // Game loop setup + function idle(deltaTime) { + inputs(); + update(deltaTime); + draw(); + }; + + // Private methods + function setup() { + print("setup"); + }; + function inputs() { + print("inputs"); + }; + function update(deltaTime) { + print("update: " + deltaTime); + }; + function draw() { + print("draw"); + }; + function cleanup() { + print("cleanup"); + }; +} + +// Script logic +function scriptStarting() { + var game = new Game(); + + Script.scriptEnding.connect(function() { + game.stop(); + }); + game.start(); +} + +scriptStarting(); \ No newline at end of file