256
Fl
FlyingFunctions / files
FlyingFunctions / README.md
2.7 KB
1 ____ _ __ __ _ __ _ ____ ____ __ __ __ _ ____ _____ _ ____ __ _ ____ 2 | ===|| |__\ \/ /| || \| |/ (_,` | ===|| | || \| |/ (__`|_ _|| |/ () \| \| | (_ (_` 3 |__| |____||__| |_||_|\__|\____) |__| \___/ |_|\__|\____) |_| |_|\____/|_|\__|.__)__) 4 5 6Flying functions is a JS game engine. This is a study project, I'm doing this to learn more about 7game development and in specific game development in the browser. 8 9I started with an engine, so that I can use it for future experiments with animating the HTML5 canvas. 10 11Still want to try it out? Ok, just include the `lib/flying-functions.js` in your page. 12After it's loaded you can initialize the engine. There are a options you can pass to the constructor 13check out the annotted source code in `docs/` for more on this. 14 15```javascript 16var ff = new FlyingFunctions({ 17 width: 640, 18 height: 320 19}); 20 21ff.on('frame', function () { 22 // my drawing code 23}); 24 25// start the game loop 26ff.loop(); 27``` 28 29Here is a full example (form the test folder): 30 31```html 32<!doctype html> 33<html lang="en"> 34<head> 35 <title>Flying Functions Main test</title> 36</head> 37<body> 38 39 <script src="../lib/flying-functions.js"></script> 40 <script> 41 console.log(FlyingFunctions); 42 console.log(FlyingFunctions.prototype); 43 44 var ff = new FlyingFunctions({ 45 width: 640, 46 height: 320, 47 init: function (o) { 48 console.log('in init func'); 49 // this is the ff object 50 console.log(typeof this); 51 console.log(this instanceof FlyingFunctions); 52 console.log(o); 53 } 54 }); 55 56 console.log(ff); 57 58 var particle = { 59 x: 10, 60 y: 10, 61 speed: 5, 62 size: 2, 63 random: true 64 }; 65 66 ff.on('frame', function () { 67 var c = this.c; 68 69 if (particle.random) { 70 particle.x += particle.speed + Math.floor(Math.random() * 220); 71 particle.y += particle.speed + Math.floor(Math.random() * 160); 72 } else { 73 particle.x += particle.speed; 74 particle.y += particle.speed; 75 } 76 77 if (particle.x >= this.canvas.width || particle.y >= this.canvas.height) { 78 particle.x = 10; 79 particle.y = 10; 80 } 81 82 c.save(); 83 c.fillStyle = "hsl(190, 100%, 50%)"; 84 c.beginPath(); 85 c.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2, true); 86 c.fill(); 87 c.restore(); 88 }); 89 90 window.onload = function () { 91 ff.loop(); 92 }; 93 </script> 94 95</body> 96</html> 97```