Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3df6e470a6 | ||
|
c0454e4591 | ||
|
4746dc9686 | ||
|
4ae6f13d78 | ||
|
2d5009e5bb | ||
|
dc1fe02d59 |
17
README.md
@ -14,8 +14,6 @@ Before training:
|
||||
|
||||
![Before training](/demo/flappy-lose.gif)
|
||||
|
||||
There is also a [a web version](https://lab.mahdi.blog/flappy-bird/) available for ease of access.
|
||||
|
||||
For each frame the bird stays alive, +0.1 score is given to him. For each wall he passes, +10 score is given.
|
||||
|
||||
Demonstration of rewards for individuals and the mean reward over time (y axis is logarithmic):
|
||||
@ -50,3 +48,18 @@ the updates become pretty large and will pull the model too much to sides, thus
|
||||
|
||||
To try it yourself, there is a `long.npy` file, rename it to `load.npy` (backup `load.npy` before doing so) and run `demo.py`,
|
||||
you will see the bird failing more often than not. `long.py` was trained for only 100 more epochs than `load.npy`.
|
||||
|
||||
Web Server
|
||||
----------
|
||||
|
||||
To setup the web server, after installing the dependencies by running `pip install -r requirements`, follow the steps below:
|
||||
|
||||
```
|
||||
cd web
|
||||
npm install
|
||||
node server.js
|
||||
```
|
||||
|
||||
You may want to use [pm2](https://github.com/Unitech/pm2) to run the server as a daemon in the background.
|
||||
|
||||
Now you can redirect traffic to the port the server is listening on (8088 by default).
|
||||
|
1
web/floppybird
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit c5bffc45e7baeced4b9a660325c624c81e11dbe7
|
17
web/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "web",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"compression": "^1.6.2",
|
||||
"express": "^4.15.2",
|
||||
"socket.io": "^1.7.3"
|
||||
}
|
||||
}
|
31
web/server.js
Normal file
@ -0,0 +1,31 @@
|
||||
var express = require('express'),
|
||||
app = express(),
|
||||
server = require('http').Server(app),
|
||||
io = require('socket.io')(server)
|
||||
exec = require('child_process').exec
|
||||
compression = require('compression')
|
||||
path = require('path'),
|
||||
router = express.Router();
|
||||
|
||||
|
||||
server.listen(8088);
|
||||
router.use(express.static(__dirname + '/static'))
|
||||
router.use(compression())
|
||||
router.use('/assets/', express.static(__dirname + '/../assets/'))
|
||||
|
||||
|
||||
var record = path.resolve(__dirname, '../record.py');
|
||||
router.get('/play', function(request, response) {
|
||||
var child = exec('python3 ' + record, { maxBuffer: 1024 * 5000 }, function(err, out, stderr) {
|
||||
if (err || stderr) {
|
||||
console.log(err || stderr)
|
||||
response.send(err || stderr);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
child.stdout.pipe(response);
|
||||
});
|
||||
|
||||
|
||||
app.use('/flappy-bird', router);
|
176
web/static/LICENSE
Normal file
@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
51
web/static/README.md
Normal file
@ -0,0 +1,51 @@
|
||||
Floppy Bird
|
||||
=========
|
||||
Initially, I wanted to try recreating Flappy Bird in HTML5, using a canvas and recycling the assets from the old game.
|
||||
|
||||
What I did instead is something way more primitive. This project uses nothing but good ol' div's for all the objects and graphics, will scale perfectly on almost any screen (mobile and desktop), is terribly unoptimized, laggy, and isn't nearly as fast as it would've been if I had just used a canvas instead. But here it is!
|
||||
|
||||
Live App
|
||||
------------
|
||||
Check out a live preview of it over here:
|
||||
http://nebez.github.io/floppybird/
|
||||
|
||||
Cool Stuff
|
||||
---------
|
||||
*Some cool things other people have done with the code. Let me know about your projects and I'll link it here*
|
||||
https://wanderingstan.github.io/handybird/ - **[@wanderinstan](https://github.com/wanderingstan)** - Real hand gestures to play Flappy Bird, using doppler effect and microphone.
|
||||
http://www.hhcc.com/404 - **[Hill Holiday](http://www.hhcc.com/)** using it for their 404
|
||||
http://heart-work.se/duvchi - Floppy bird, modified, and used as a promotional campaign for an album release
|
||||
https://www.progressivewebflap.com/ - **[@jsonthor](https://twitter.com/jsonthor)** turned Floppy Bird into a PWA!
|
||||
https://github.com/rukmal/FlappyLeapBird - **[Rukmal](http://rukmal.me/)** integrated LeapMotion Controller functionality! Check out his website, he's done some cool stuff.
|
||||
http://chrisbeaumont.github.io/floppybird/ - **[@chrisbeaumont](https://github.com/chrisbeaumont)** made an awesome auto-pilot, check it out
|
||||
http://www.lobe.io/flappy-math-saga/- **[@tikwid](https://github.com/tikwid)** made a really cool version designed to teach you times tables. really cool.
|
||||
http://dota2.cyborgmatt.com/flappydota/ - flappy dota, this one is really cool.
|
||||
http://tippy.gochiusa.net/ - Japanese anime inspired floppybird.
|
||||
http://emdigital.ru/wiki — floppybird on **[EyeMedia Instagram Marketing Agency](http://emdigital.ru/)** website.
|
||||
|
||||
Credits
|
||||
------
|
||||
**[@aregowe](https://github.com/aregowe)** for optimizing all the assets
|
||||
|
||||
Notice
|
||||
=====
|
||||
The assets powering the visual element of the game have all been extracted directly from the Flappy Bird android game. I have only done the coding, not designed the visual elements.
|
||||
I do not own the assets, nor do I have explicit permission to use them from their creator. They are the work and copyright of original creator Dong Nguyen and .GEARS games (http://www.dotgears.com/).
|
||||
I took this Tweet (https://twitter.com/dongatory/status/431060041009856512 / http://i.imgur.com/AcyWyqf.png) by Dong Nguyen, the creator of the game, as an open invitation to reuse the game concept and assets in an open source project. There is no ill intention to steal the game, or claim it as my own. This is merely a recreation for fun.
|
||||
If the copyright holder would like for the assets to be removed, let me know!
|
||||
|
||||
|
||||
License
|
||||
=====
|
||||
Copyright 2014 Nebez Briefkani
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
BIN
web/static/assets/bird.png
Normal file
After Width: | Height: | Size: 282 B |
BIN
web/static/assets/ceiling.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
web/static/assets/font_big.psd
Normal file
BIN
web/static/assets/font_big_0.png
Normal file
After Width: | Height: | Size: 121 B |
BIN
web/static/assets/font_big_1.png
Normal file
After Width: | Height: | Size: 130 B |
BIN
web/static/assets/font_big_2.png
Normal file
After Width: | Height: | Size: 126 B |
BIN
web/static/assets/font_big_3.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
web/static/assets/font_big_4.png
Normal file
After Width: | Height: | Size: 133 B |
BIN
web/static/assets/font_big_5.png
Normal file
After Width: | Height: | Size: 126 B |
BIN
web/static/assets/font_big_6.png
Normal file
After Width: | Height: | Size: 126 B |
BIN
web/static/assets/font_big_7.png
Normal file
After Width: | Height: | Size: 131 B |
BIN
web/static/assets/font_big_8.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
web/static/assets/font_big_9.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
web/static/assets/font_small.psd
Normal file
BIN
web/static/assets/font_small_0.png
Normal file
After Width: | Height: | Size: 99 B |
BIN
web/static/assets/font_small_1.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
web/static/assets/font_small_2.png
Normal file
After Width: | Height: | Size: 96 B |
BIN
web/static/assets/font_small_3.png
Normal file
After Width: | Height: | Size: 90 B |
BIN
web/static/assets/font_small_4.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
web/static/assets/font_small_5.png
Normal file
After Width: | Height: | Size: 94 B |
BIN
web/static/assets/font_small_6.png
Normal file
After Width: | Height: | Size: 92 B |
BIN
web/static/assets/font_small_7.png
Normal file
After Width: | Height: | Size: 94 B |
BIN
web/static/assets/font_small_8.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
web/static/assets/font_small_9.png
Normal file
After Width: | Height: | Size: 100 B |
BIN
web/static/assets/land.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
web/static/assets/medal_bronze.png
Normal file
After Width: | Height: | Size: 354 B |
BIN
web/static/assets/medal_gold.png
Normal file
After Width: | Height: | Size: 284 B |
BIN
web/static/assets/medal_platinum.png
Normal file
After Width: | Height: | Size: 337 B |
BIN
web/static/assets/medal_silver.png
Normal file
After Width: | Height: | Size: 340 B |
BIN
web/static/assets/pipe-down.png
Normal file
After Width: | Height: | Size: 456 B |
BIN
web/static/assets/pipe-up.png
Normal file
After Width: | Height: | Size: 421 B |
BIN
web/static/assets/pipe.png
Normal file
After Width: | Height: | Size: 161 B |
BIN
web/static/assets/replay.png
Normal file
After Width: | Height: | Size: 596 B |
BIN
web/static/assets/scoreboard.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
web/static/assets/sky.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
web/static/assets/sounds/sfx_die.ogg
Normal file
BIN
web/static/assets/sounds/sfx_hit.ogg
Normal file
BIN
web/static/assets/sounds/sfx_point.ogg
Normal file
BIN
web/static/assets/sounds/sfx_swooshing.ogg
Normal file
BIN
web/static/assets/sounds/sfx_wing.ogg
Normal file
BIN
web/static/assets/splash.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
web/static/assets/thumb.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
web/static/aylien.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
399
web/static/css/main.css
Normal file
@ -0,0 +1,399 @@
|
||||
/*
|
||||
Copyright 2014 Nebez Briefkani
|
||||
floppybird - main.css
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
@-webkit-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@-moz-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@-o-keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
@keyframes animLand {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -335px 0px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@-moz-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@-o-keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
@keyframes animSky {
|
||||
0% { background-position: 0px 100%; }
|
||||
100% { background-position: -275px 100%; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@-moz-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@-o-keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
@keyframes animBird {
|
||||
from { background-position: 0px 0px; }
|
||||
to { background-position: 0px -96px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@-moz-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@-o-keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
@keyframes animPipe {
|
||||
0% { left: 900px; }
|
||||
100% { left: -100px; }
|
||||
}
|
||||
|
||||
@-webkit-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@-moz-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@-o-keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
@keyframes animCeiling {
|
||||
0% { background-position: 0px 0px; }
|
||||
100% { background-position: -63px 0px; }
|
||||
}
|
||||
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
/* border box */
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
/* gpu acceleration */
|
||||
-webkit-transition: translate3d(0,0,0);
|
||||
/* select disable */
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#gamecontainer
|
||||
{
|
||||
position: relative;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
|
||||
margin: 3rem auto;
|
||||
}
|
||||
|
||||
/*
|
||||
Screen - Game
|
||||
*/
|
||||
#gamescreen
|
||||
{
|
||||
position: absolute;
|
||||
width: 300px;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
#sky
|
||||
{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 300px;
|
||||
height: 200px;
|
||||
background-image: url('../assets/sky.png');
|
||||
background-repeat: repeat-x;
|
||||
background-position: 0px 100%;
|
||||
background-color: #4ec0ca;
|
||||
|
||||
-webkit-animation: animSky 7s linear infinite;
|
||||
animation: animSky 7s linear infinite;
|
||||
}
|
||||
|
||||
#flyarea
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
height: 200px;
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
#ceiling
|
||||
{
|
||||
position: absolute;
|
||||
top: -16px;
|
||||
height: 16px;
|
||||
width: 300px;
|
||||
background-image: url('../assets/ceiling.png');
|
||||
background-repeat: repeat-x;
|
||||
|
||||
-webkit-animation: animCeiling 481ms linear infinite;
|
||||
animation: animCeiling 481ms linear infinite;
|
||||
}
|
||||
|
||||
#land
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 20%;
|
||||
background-image: url('../assets/land.png');
|
||||
background-repeat: repeat-x;
|
||||
background-position: 0px 0px;
|
||||
background-color: #ded895;
|
||||
|
||||
-webkit-animation: animLand 2516ms linear infinite;
|
||||
animation: animLand 2516ms linear infinite;
|
||||
}
|
||||
|
||||
#bigscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 10px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#bigscore img
|
||||
{
|
||||
display: inline-block;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
#splash
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 75px;
|
||||
left: 65px;
|
||||
width: 188px;
|
||||
height: 170px;
|
||||
background-image: url('../assets/splash.png');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
#scoreboard
|
||||
{
|
||||
position: absolute;
|
||||
display: none;
|
||||
opacity: 0;
|
||||
top: 64px;
|
||||
left: 43px;
|
||||
width: 236px;
|
||||
height: 280px;
|
||||
background-image: url('../assets/scoreboard.png');
|
||||
background-repeat: no-repeat;
|
||||
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#medal
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 114px;
|
||||
left: 32px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
#currentscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 105px;
|
||||
left: 107px;
|
||||
width: 104px;
|
||||
height: 14px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#currentscore img
|
||||
{
|
||||
padding-left: 2px;
|
||||
}
|
||||
|
||||
#highscore
|
||||
{
|
||||
position: absolute;
|
||||
top: 147px;
|
||||
left: 107px;
|
||||
width: 104px;
|
||||
height: 14px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#highscore img
|
||||
{
|
||||
padding-left: 2px;
|
||||
}
|
||||
|
||||
#replay
|
||||
{
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
top: 205px;
|
||||
left: 61px;
|
||||
height: 115px;
|
||||
width: 70px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.boundingbox
|
||||
{
|
||||
position: absolute;
|
||||
display: none;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 1px solid red;
|
||||
}
|
||||
|
||||
#player
|
||||
{
|
||||
left: 60px;
|
||||
top: 200px;
|
||||
}
|
||||
|
||||
.bird
|
||||
{
|
||||
position: absolute;
|
||||
width: 34px;
|
||||
height: 24px;
|
||||
background-image: url('../assets/bird.png');
|
||||
|
||||
-webkit-animation: animBird 300ms steps(4) infinite;
|
||||
animation: animBird 300ms steps(4) infinite;
|
||||
}
|
||||
|
||||
.pipe
|
||||
{
|
||||
position: absolute;
|
||||
left: -100px;
|
||||
width: 52px;
|
||||
height: 100%;
|
||||
z-index: 10;
|
||||
text-align: left;
|
||||
|
||||
/*-webkit-animation: animPipe 7500ms linear;*/
|
||||
/*animation: animPipe 7500ms linear;*/
|
||||
}
|
||||
|
||||
.pipe_upper
|
||||
{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 52px;
|
||||
background-image: url('../assets/pipe.png');
|
||||
background-repeat: repeat-y;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.pipe_upper:after
|
||||
{
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 52px;
|
||||
height: 26px;
|
||||
background-image: url('../assets/pipe-down.png');
|
||||
}
|
||||
|
||||
.pipe_lower
|
||||
{
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 52px;
|
||||
background-image: url('../assets/pipe.png');
|
||||
background-repeat: repeat-y;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.pipe_lower:after
|
||||
{
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 52px;
|
||||
height: 26px;
|
||||
background-image: url('../assets/pipe-up.png');
|
||||
}
|
||||
|
||||
#footer
|
||||
{
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 3px;
|
||||
left: 3px;
|
||||
}
|
||||
|
||||
#footer a,
|
||||
#footer a:link,
|
||||
#footer a:visited,
|
||||
#footer a:hover,
|
||||
#footer a:active
|
||||
{
|
||||
padding: 2px;
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.links {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: middle;
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 20px;
|
||||
}
|
2
web/static/css/reset.css
Normal file
@ -0,0 +1,2 @@
|
||||
/* html5doctor.com Reset v1.6.1 - http://cssreset.com */
|
||||
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}nav ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:transparent}ins{background-color:#ff9;color:#000;text-decoration:none}mark{background-color:#ff9;color:#000;font-style:italic;font-weight:bold}del{text-decoration:line-through}abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help}table{border-collapse:collapse;border-spacing:0}hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0;padding:0}input,select{vertical-align:middle}
|
4
web/static/font-awesome.min.css
vendored
Normal file
83
web/static/frame.html
Normal file
@ -0,0 +1,83 @@
|
||||
<html class="fa-events-icons-ready"><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Playing Flappy Bird using Evolution Strategies</title>
|
||||
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
||||
|
||||
<!-- Open Graph tags -->
|
||||
<meta property="og:title" content="Floppy Bird" />
|
||||
<meta property="og:description" content="play floppy bird. a remake of popular game flappy bird using just html/css/js" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:image" content="http://nebez.github.io/floppybird/assets/thumb.png" />
|
||||
<meta property="og:url" content="http://nebez.github.io/floppybird/" />
|
||||
<meta property="og:site_name" content="Floppy Bird" />
|
||||
|
||||
<!-- Style sheets -->
|
||||
<link href="css/reset.css" rel="stylesheet">
|
||||
<link href="css/main.css" rel="stylesheet">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<script src="main_files/befea5cf35.js"></script><link href="main_files/befea5cf35.css" media="all" rel="stylesheet">
|
||||
<script src="main_files/socket.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="gamecontainer">
|
||||
<div id="gamescreen">
|
||||
<div id="sky" class="animated">
|
||||
<div id="flyarea">
|
||||
<div id="ceiling" class="animated"></div>
|
||||
<!-- This is the flying and pipe area container -->
|
||||
<div id="player" class="bird animated"></div>
|
||||
|
||||
<div id="bigscore"></div>
|
||||
|
||||
<div id="splash"></div>
|
||||
|
||||
<div id="scoreboard">
|
||||
<div id="medal"></div>
|
||||
<div id="currentscore"></div>
|
||||
<div id="highscore"></div>
|
||||
<div id="replay"><img src="assets/replay.png" alt="replay"></div>
|
||||
</div>
|
||||
|
||||
<!-- Pipes go here! -->
|
||||
</div>
|
||||
</div>
|
||||
<div id="land" class="animated"><div id="debug"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="boundingbox" id="playerbox"></div>
|
||||
<div class="boundingbox" id="pipebox"></div>
|
||||
|
||||
<div class='overlay' id='loading'>
|
||||
Fetching a new game from the server...
|
||||
</div>
|
||||
|
||||
<div class='controls'>
|
||||
<a id='new' class='btn' title='Fetch a new game'><i class='fa fa-refresh'></i></a>
|
||||
<a id='faster' class='btn' title='Faster'><i class='fa fa-plus-square'></i></a>
|
||||
<a id='slower' class='btn' title='Slower'><i class='fa fa-minus-square'></i></a>
|
||||
|
||||
<p>Note: we have limited the game to run only for 10000 frames to avoid infinitely long games, if you want to watch the game indefinitely, <a href='https://github.com/mdibaiee/flappy-es'>get the python version</a> and try it yourself. <i class='fa fa-hand-peace-o'></i></p>
|
||||
</div>
|
||||
|
||||
<div style='display: none;'>
|
||||
<img src='assets/font_big_0.png'>
|
||||
<img src='assets/font_big_1.png'>
|
||||
<img src='assets/font_big_2.png'>
|
||||
<img src='assets/font_big_3.png'>
|
||||
<img src='assets/font_big_4.png'>
|
||||
<img src='assets/font_big_5.png'>
|
||||
<img src='assets/font_big_6.png'>
|
||||
<img src='assets/font_big_7.png'>
|
||||
<img src='assets/font_big_8.png'>
|
||||
<img src='assets/font_big_9.png'>
|
||||
</div>
|
||||
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/jquery.transit.min.js"></script>
|
||||
<script src="js/buzz.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
46
web/static/game.js
Normal file
@ -0,0 +1,46 @@
|
||||
var canvas = document.getElementById('canvas'),
|
||||
c = canvas.getContext('2d'),
|
||||
birdie = document.getElementById('birdie'),
|
||||
socket = io();
|
||||
|
||||
var JUMP_SPEED = 7
|
||||
var bird = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
}
|
||||
|
||||
WALL_WIDTH = 30
|
||||
GATE_HEIGHT = 60
|
||||
var wall = {
|
||||
x: 0,
|
||||
gate: {
|
||||
y: 0,
|
||||
height: GATE_HEIGHT
|
||||
},
|
||||
width: WALL_WIDTH,
|
||||
}
|
||||
|
||||
var game = {
|
||||
width: 250,
|
||||
height: 200,
|
||||
lost: false,
|
||||
score: 0,
|
||||
}
|
||||
|
||||
socket.on('game', function() {
|
||||
|
||||
});
|
||||
|
||||
(function loop() {
|
||||
requestAnimationFrame(function() {
|
||||
|
||||
loop();
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
function draw() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.draw
|
||||
}
|
97
web/static/index.html
Normal file
@ -0,0 +1,97 @@
|
||||
<html class="fa-events-icons-ready"><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Playing Flappy Bird using Evolution Strategies</title>
|
||||
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
||||
|
||||
<!-- Open Graph tags -->
|
||||
<meta property="og:title" content="Floppy Bird" />
|
||||
<meta property="og:description" content="play floppy bird. a remake of popular game flappy bird using just html/css/js" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:image" content="http://nebez.github.io/floppybird/assets/thumb.png" />
|
||||
<meta property="og:url" content="http://nebez.github.io/floppybird/" />
|
||||
<meta property="og:site_name" content="Floppy Bird" />
|
||||
|
||||
<!-- Style sheets -->
|
||||
<link href="css/reset.css" rel="stylesheet">
|
||||
<link href="css/main.css" rel="stylesheet">
|
||||
<link href="style.css" rel="stylesheet">
|
||||
<script src="main_files/befea5cf35.js"></script><link href="main_files/befea5cf35.css" media="all" rel="stylesheet">
|
||||
<script src="main_files/socket.js"></script>
|
||||
</head>
|
||||
|
||||
<body><header>
|
||||
<h1>Playing Flappy Bird using Evolution Strategies</h1>
|
||||
</header>
|
||||
|
||||
<div id="gamecontainer">
|
||||
<div id="gamescreen">
|
||||
<div id="sky" class="animated">
|
||||
<div id="flyarea">
|
||||
<div id="ceiling" class="animated"></div>
|
||||
<!-- This is the flying and pipe area container -->
|
||||
<div id="player" class="bird animated"></div>
|
||||
|
||||
<div id="bigscore"></div>
|
||||
|
||||
<div id="splash"></div>
|
||||
|
||||
<div id="scoreboard">
|
||||
<div id="medal"></div>
|
||||
<div id="currentscore"></div>
|
||||
<div id="highscore"></div>
|
||||
<div id="replay"><img src="assets/replay.png" alt="replay"></div>
|
||||
</div>
|
||||
|
||||
<!-- Pipes go here! -->
|
||||
</div>
|
||||
</div>
|
||||
<div id="land" class="animated"><div id="debug"></div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="boundingbox" id="playerbox"></div>
|
||||
<div class="boundingbox" id="pipebox"></div>
|
||||
|
||||
<div class='overlay' id='loading'>
|
||||
Fetching a new game from the server...
|
||||
</div>
|
||||
|
||||
<div class='controls'>
|
||||
<a id='new' class='btn' title='Fetch a new game'><i class='fa fa-refresh'></i></a>
|
||||
<a id='faster' class='btn' title='Faster'><i class='fa fa-plus-square'></i></a>
|
||||
<a id='slower' class='btn' title='Slower'><i class='fa fa-minus-square'></i></a>
|
||||
|
||||
<p>Note: we have limited the game to run only for 10000 frames to avoid infinitely long games, if you want to watch the game indefinitely, <a href='https://github.com/mdibaiee/flappy-es'>get the python version</a> and try it yourself. <i class='fa fa-hand-peace-o'></i></p>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<p>Inspired by <a href="https://blog.openai.com/evolution-strategies/">Evolution Strategies as a Scalable Alternative to Reinforcement Learning</a> by <a href="https://openai.com/">OpenAI</a></p><a href="https://openai.com/">
|
||||
|
||||
<a class='small' href="http://github.com/nebez/floppybird/">HTML5 game by nebez/floppybird</a>
|
||||
|
||||
</a><div class="links"><a href="https://openai.com/">
|
||||
</a><a class="github" href="https://github.com/mdibaiee/flappy-es" alt="GitHub">GitHub <i class="fa fa-github"></i></a>
|
||||
<a class="aylien" href="https://aylien.com/"><img src="main_files/aylien.png" alt="Aylien" width="32"></a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<div style='display: none;'>
|
||||
<img src='assets/font_big_0.png'>
|
||||
<img src='assets/font_big_1.png'>
|
||||
<img src='assets/font_big_2.png'>
|
||||
<img src='assets/font_big_3.png'>
|
||||
<img src='assets/font_big_4.png'>
|
||||
<img src='assets/font_big_5.png'>
|
||||
<img src='assets/font_big_6.png'>
|
||||
<img src='assets/font_big_7.png'>
|
||||
<img src='assets/font_big_8.png'>
|
||||
<img src='assets/font_big_9.png'>
|
||||
</div>
|
||||
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/jquery.transit.min.js"></script>
|
||||
<script src="js/buzz.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
11
web/static/js/buzz.min.js
vendored
Normal file
6
web/static/js/jquery.min.js
vendored
Normal file
9
web/static/js/jquery.transit.min.js
vendored
Normal file
584
web/static/js/main.js
Normal file
@ -0,0 +1,584 @@
|
||||
/*
|
||||
Copyright 2014 Nebez Briefkani
|
||||
floppybird - main.js
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
var debugmode = false;
|
||||
|
||||
var states = Object.freeze({
|
||||
SplashScreen: 0,
|
||||
GameScreen: 1,
|
||||
ScoreScreen: 2
|
||||
});
|
||||
|
||||
var currentstate;
|
||||
|
||||
var gravity = 0.25;
|
||||
var velocity = 0;
|
||||
var position = 180;
|
||||
var rotation = 0;
|
||||
var jump = -4.6;
|
||||
var flyArea = $("#flyarea").height();
|
||||
|
||||
var score = 0;
|
||||
var highscore = 0;
|
||||
|
||||
var pipeheight = 90;
|
||||
var pipewidth = 52;
|
||||
var pipes = new Array();
|
||||
|
||||
var replayclickable = false;
|
||||
|
||||
//sounds
|
||||
var volume = 30;
|
||||
var soundJump = new buzz.sound("assets/sounds/sfx_wing.ogg");
|
||||
var soundScore = new buzz.sound("assets/sounds/sfx_point.ogg");
|
||||
var soundHit = new buzz.sound("assets/sounds/sfx_hit.ogg");
|
||||
var soundDie = new buzz.sound("assets/sounds/sfx_die.ogg");
|
||||
var soundSwoosh = new buzz.sound("assets/sounds/sfx_swooshing.ogg");
|
||||
buzz.all().setVolume(volume);
|
||||
|
||||
//loops
|
||||
var loopGameloop;
|
||||
var loopPipeloop;
|
||||
|
||||
$(document).ready(function() {
|
||||
if(window.location.search == "?debug")
|
||||
debugmode = true;
|
||||
if(window.location.search == "?easy")
|
||||
pipeheight = 200;
|
||||
|
||||
//get the highscore
|
||||
var savedscore = getCookie("highscore");
|
||||
if(savedscore != "")
|
||||
highscore = parseInt(savedscore);
|
||||
|
||||
//start with the splash screen
|
||||
//showSplash();
|
||||
});
|
||||
|
||||
function getCookie(cname)
|
||||
{
|
||||
var name = cname + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0; i<ca.length; i++)
|
||||
{
|
||||
var c = ca[i].trim();
|
||||
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function setCookie(cname,cvalue,exdays)
|
||||
{
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime()+(exdays*24*60*60*1000));
|
||||
var expires = "expires="+d.toGMTString();
|
||||
document.cookie = cname + "=" + cvalue + "; " + expires;
|
||||
}
|
||||
|
||||
function showSplash()
|
||||
{
|
||||
currentstate = states.SplashScreen;
|
||||
|
||||
//set the defaults (again)
|
||||
velocity = 0;
|
||||
position = 180;
|
||||
rotation = 0;
|
||||
score = 0;
|
||||
|
||||
//update the player in preparation for the next game
|
||||
$("#player").css({ y: 0, x: 0});
|
||||
updatePlayer($("#player"));
|
||||
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//clear out all the pipes if there are any
|
||||
$(".pipe").remove();
|
||||
pipes = new Array();
|
||||
|
||||
//make everything animated again
|
||||
$(".animated").css('animation-play-state', 'running');
|
||||
$(".animated").css('-webkit-animation-play-state', 'running');
|
||||
|
||||
//fade in the splash
|
||||
$("#splash").transition({ opacity: 1 }, 2000, 'ease');
|
||||
}
|
||||
|
||||
function startGame()
|
||||
{
|
||||
currentstate = states.GameScreen;
|
||||
|
||||
//fade out the splash
|
||||
$("#splash").stop();
|
||||
$("#splash").transition({ opacity: 0 }, 500, 'ease');
|
||||
|
||||
//update the big score
|
||||
setBigScore();
|
||||
|
||||
//debug mode?
|
||||
if(debugmode)
|
||||
{
|
||||
//show the bounding boxes
|
||||
$(".boundingbox").show();
|
||||
}
|
||||
|
||||
//start up our loops
|
||||
var updaterate = 1000.0 / 60.0 ; //60 times a second
|
||||
loopGameloop = setInterval(gameloop, updaterate);
|
||||
loopPipeloop = setInterval(updatePipes, 1400);
|
||||
|
||||
//jump from the start!
|
||||
playerJump();
|
||||
}
|
||||
|
||||
function updatePlayer(player)
|
||||
{
|
||||
//rotation
|
||||
rotation = Math.min((velocity / 10) * 90, 90);
|
||||
|
||||
//apply rotation and position
|
||||
$(player).css({ rotate: rotation, top: position });
|
||||
}
|
||||
|
||||
function gameloop() {
|
||||
var player = $("#player");
|
||||
|
||||
//update the player speed/position
|
||||
velocity += gravity;
|
||||
position += velocity;
|
||||
|
||||
//update the player
|
||||
updatePlayer(player);
|
||||
|
||||
//create the bounding box
|
||||
var box = document.getElementById('player').getBoundingClientRect();
|
||||
var origwidth = 34.0;
|
||||
var origheight = 24.0;
|
||||
|
||||
var boxwidth = origwidth - (Math.sin(Math.abs(rotation) / 90) * 8);
|
||||
var boxheight = (origheight + box.height) / 2;
|
||||
var boxleft = ((box.width - boxwidth) / 2) + box.left;
|
||||
var boxtop = ((box.height - boxheight) / 2) + box.top;
|
||||
var boxright = boxleft + boxwidth;
|
||||
var boxbottom = boxtop + boxheight;
|
||||
|
||||
//if we're in debug mode, draw the bounding box
|
||||
if(debugmode)
|
||||
{
|
||||
var boundingbox = $("#playerbox");
|
||||
boundingbox.css('left', boxleft);
|
||||
boundingbox.css('top', boxtop);
|
||||
boundingbox.css('height', boxheight);
|
||||
boundingbox.css('width', boxwidth);
|
||||
}
|
||||
|
||||
//did we hit the ground?
|
||||
if(box.bottom >= $("#land").offset().top)
|
||||
{
|
||||
playerDead();
|
||||
return;
|
||||
}
|
||||
|
||||
//have they tried to escape through the ceiling? :o
|
||||
var ceiling = $("#ceiling");
|
||||
if(boxtop <= (ceiling.offset().top + ceiling.height()))
|
||||
position = 0;
|
||||
|
||||
//we can't go any further without a pipe
|
||||
if(pipes[0] == null)
|
||||
return;
|
||||
|
||||
//determine the bounding box of the next pipes inner area
|
||||
var nextpipe = pipes[0];
|
||||
var nextpipeupper = nextpipe.children(".pipe_upper");
|
||||
|
||||
var pipetop = nextpipeupper.offset().top + nextpipeupper.height();
|
||||
var pipeleft = nextpipeupper.offset().left - 2; // for some reason it starts at the inner pipes offset, not the outer pipes.
|
||||
var piperight = pipeleft + pipewidth;
|
||||
var pipebottom = pipetop + pipeheight;
|
||||
|
||||
if(debugmode)
|
||||
{
|
||||
var boundingbox = $("#pipebox");
|
||||
boundingbox.css('left', pipeleft);
|
||||
boundingbox.css('top', pipetop);
|
||||
boundingbox.css('height', pipeheight);
|
||||
boundingbox.css('width', pipewidth);
|
||||
}
|
||||
|
||||
//have we gotten inside the pipe yet?
|
||||
if(boxright > pipeleft)
|
||||
{
|
||||
//we're within the pipe, have we passed between upper and lower pipes?
|
||||
if(boxtop > pipetop && boxbottom < pipebottom)
|
||||
{
|
||||
//yeah! we're within bounds
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//no! we touched the pipe
|
||||
playerDead();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//have we passed the imminent danger?
|
||||
if(boxleft > piperight)
|
||||
{
|
||||
//yes, remove it
|
||||
pipes.splice(0, 1);
|
||||
|
||||
//and score a point
|
||||
playerScore();
|
||||
}
|
||||
}
|
||||
|
||||
//Handle space bar
|
||||
$(document).keydown(function(e){
|
||||
//space bar!
|
||||
if(e.keyCode == 32)
|
||||
{
|
||||
//in ScoreScreen, hitting space should click the "replay" button. else it's just a regular spacebar hit
|
||||
if(currentstate == states.ScoreScreen)
|
||||
$("#replay").click();
|
||||
else
|
||||
screenClick();
|
||||
}
|
||||
});
|
||||
|
||||
//Handle mouse down OR touch start
|
||||
if("ontouchstart" in window)
|
||||
$(document).on("touchstart", screenClick);
|
||||
else
|
||||
$(document).on("mousedown", screenClick);
|
||||
|
||||
function screenClick()
|
||||
{
|
||||
if(currentstate == states.GameScreen)
|
||||
{
|
||||
playerJump();
|
||||
}
|
||||
else if(currentstate == states.SplashScreen)
|
||||
{
|
||||
startGame();
|
||||
}
|
||||
}
|
||||
|
||||
function playerJump()
|
||||
{
|
||||
velocity = jump;
|
||||
//play jump sound
|
||||
soundJump.stop();
|
||||
soundJump.play();
|
||||
}
|
||||
|
||||
function setBigScore(erase)
|
||||
{
|
||||
var elemscore = $("#bigscore");
|
||||
elemscore.empty();
|
||||
|
||||
if(erase)
|
||||
return;
|
||||
|
||||
var digits = score.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_big_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setSmallScore()
|
||||
{
|
||||
var elemscore = $("#currentscore");
|
||||
elemscore.empty();
|
||||
|
||||
var digits = score.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_small_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setHighScore()
|
||||
{
|
||||
var elemscore = $("#highscore");
|
||||
elemscore.empty();
|
||||
|
||||
var digits = highscore.toString().split('');
|
||||
for(var i = 0; i < digits.length; i++)
|
||||
elemscore.append("<img src='assets/font_small_" + digits[i] + ".png' alt='" + digits[i] + "'>");
|
||||
}
|
||||
|
||||
function setMedal()
|
||||
{
|
||||
var elemmedal = $("#medal");
|
||||
elemmedal.empty();
|
||||
|
||||
if(score < 10)
|
||||
//signal that no medal has been won
|
||||
return false;
|
||||
|
||||
if(score >= 10)
|
||||
medal = "bronze";
|
||||
if(score >= 20)
|
||||
medal = "silver";
|
||||
if(score >= 30)
|
||||
medal = "gold";
|
||||
if(score >= 40)
|
||||
medal = "platinum";
|
||||
|
||||
elemmedal.append('<img src="assets/medal_' + medal +'.png" alt="' + medal +'">');
|
||||
|
||||
//signal that a medal has been won
|
||||
return true;
|
||||
}
|
||||
|
||||
function playerDead()
|
||||
{
|
||||
//stop animating everything!
|
||||
$(".animated").css('animation-play-state', 'paused');
|
||||
$(".animated").css('-webkit-animation-play-state', 'paused');
|
||||
|
||||
//drop the bird to the floor
|
||||
var playerbottom = $("#player").position().top + $("#player").width(); //we use width because he'll be rotated 90 deg
|
||||
var floor = flyArea;
|
||||
var movey = Math.max(0, floor - playerbottom);
|
||||
$("#player").transition({ y: movey + 'px', rotate: 90}, 1000, 'easeInOutCubic');
|
||||
|
||||
//it's time to change states. as of now we're considered ScoreScreen to disable left click/flying
|
||||
currentstate = states.ScoreScreen;
|
||||
|
||||
//destroy our gameloops
|
||||
clearInterval(loopGameloop);
|
||||
clearInterval(loopPipeloop);
|
||||
loopGameloop = null;
|
||||
loopPipeloop = null;
|
||||
|
||||
//mobile browsers don't support buzz bindOnce event
|
||||
if(isIncompatible.any())
|
||||
{
|
||||
//skip right to showing score
|
||||
showScore();
|
||||
}
|
||||
else
|
||||
{
|
||||
//play the hit sound (then the dead sound) and then show score
|
||||
soundHit.play().bindOnce("ended", function() {
|
||||
soundDie.play().bindOnce("ended", function() {
|
||||
showScore();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function showScore()
|
||||
{
|
||||
//unhide us
|
||||
$("#scoreboard").css("display", "block");
|
||||
|
||||
//remove the big score
|
||||
setBigScore(true);
|
||||
|
||||
//have they beaten their high score?
|
||||
if(score > highscore)
|
||||
{
|
||||
//yeah!
|
||||
highscore = score;
|
||||
//save it!
|
||||
setCookie("highscore", highscore, 999);
|
||||
}
|
||||
|
||||
//update the scoreboard
|
||||
setSmallScore();
|
||||
setHighScore();
|
||||
var wonmedal = setMedal();
|
||||
|
||||
//SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//show the scoreboard
|
||||
$("#scoreboard").css({ y: '40px', opacity: 0 }); //move it down so we can slide it up
|
||||
$("#replay").css({ y: '40px', opacity: 0 });
|
||||
$("#scoreboard").transition({ y: '0px', opacity: 1}, 600, 'ease', function() {
|
||||
//When the animation is done, animate in the replay button and SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
$("#replay").transition({ y: '0px', opacity: 1}, 600, 'ease');
|
||||
|
||||
//also animate in the MEDAL! WOO!
|
||||
if(wonmedal)
|
||||
{
|
||||
$("#medal").css({ scale: 2, opacity: 0 });
|
||||
$("#medal").transition({ opacity: 1, scale: 1 }, 1200, 'ease');
|
||||
}
|
||||
});
|
||||
|
||||
//make the replay button clickable
|
||||
replayclickable = true;
|
||||
}
|
||||
|
||||
$("#replay").click(function() {
|
||||
//make sure we can only click once
|
||||
if(!replayclickable)
|
||||
return;
|
||||
else
|
||||
replayclickable = false;
|
||||
//SWOOSH!
|
||||
soundSwoosh.stop();
|
||||
soundSwoosh.play();
|
||||
|
||||
//fade out the scoreboard
|
||||
$("#scoreboard").transition({ y: '-40px', opacity: 0}, 1000, 'ease', function() {
|
||||
//when that's done, display us back to nothing
|
||||
$("#scoreboard").css("display", "none");
|
||||
|
||||
//start the game over!
|
||||
newGame();
|
||||
});
|
||||
});
|
||||
|
||||
function playerScore()
|
||||
{
|
||||
score += 1;
|
||||
//play score sound
|
||||
soundScore.stop();
|
||||
soundScore.play();
|
||||
setBigScore();
|
||||
}
|
||||
|
||||
function updatePipes()
|
||||
{
|
||||
//Do any pipes need removal?
|
||||
$(".pipe").filter(function() { return $(this).position().left <= -100; }).remove()
|
||||
|
||||
//add a new pipe (top height + bottom height + pipeheight == flyArea) and put it in our tracker
|
||||
var padding = 80;
|
||||
var constraint = flyArea - pipeheight - (padding * 2); //double padding (for top and bottom)
|
||||
var topheight = Math.floor((Math.random()*constraint) + padding); //add lower padding
|
||||
var bottomheight = (flyArea - pipeheight) - topheight;
|
||||
var newpipe = $('<div class="pipe animated"><div class="pipe_upper" style="height: ' + topheight + 'px;"></div><div class="pipe_lower" style="height: ' + bottomheight + 'px;"></div></div>');
|
||||
$("#flyarea").append(newpipe);
|
||||
pipes.push(newpipe);
|
||||
}
|
||||
|
||||
var isIncompatible = {
|
||||
Android: function() {
|
||||
return navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
BlackBerry: function() {
|
||||
return navigator.userAgent.match(/BlackBerry/i);
|
||||
},
|
||||
iOS: function() {
|
||||
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
},
|
||||
Opera: function() {
|
||||
return navigator.userAgent.match(/Opera Mini/i);
|
||||
},
|
||||
Safari: function() {
|
||||
return (navigator.userAgent.match(/OS X.*Safari/) && ! navigator.userAgent.match(/Chrome/));
|
||||
},
|
||||
Windows: function() {
|
||||
return navigator.userAgent.match(/IEMobile/i);
|
||||
},
|
||||
any: function() {
|
||||
return (isIncompatible.Android() || isIncompatible.BlackBerry() || isIncompatible.iOS() || isIncompatible.Opera() || isIncompatible.Safari() || isIncompatible.Windows());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var pipe = $('<div class="pipe animated"><div class="pipe_upper"></div><div class="pipe_lower"></div></div>');
|
||||
$("#flyarea").append(pipe);
|
||||
|
||||
var gameSpeed = 20
|
||||
var playing = false;
|
||||
function newGame() {
|
||||
if (playing) {
|
||||
playing = false;
|
||||
setTimeout(newGame, gameSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
$('#loading').addClass('active');
|
||||
|
||||
fetch('play').then(res => res.json()).then(function(states) {
|
||||
playing = true;
|
||||
|
||||
$('#loading').removeClass('active');
|
||||
|
||||
$("#player").css({ rotate: 0 });
|
||||
|
||||
var i = 0;
|
||||
setTimeout(function p() {
|
||||
if (!playing) return;
|
||||
|
||||
var state = states[i];
|
||||
if (!state || state.lost) {
|
||||
$(".animated").css('animation-play-state', 'paused');
|
||||
$(".animated").css('-webkit-animation-play-state', 'paused');
|
||||
|
||||
//drop the bird to the floor
|
||||
var playerbottom = $("#player").position().top + $("#player").width(); //we use width because he'll be rotated 90 deg
|
||||
var floor = flyArea;
|
||||
var movey = Math.max(0, floor - playerbottom);
|
||||
$("#player").transition({ top: movey + 'px', rotate: 90}, 1000, 'easeInOutCubic');
|
||||
|
||||
if(isIncompatible.any())
|
||||
{
|
||||
//skip right to showing score
|
||||
showScore();
|
||||
}
|
||||
else
|
||||
{
|
||||
//play the hit sound (then the dead sound) and then show score
|
||||
soundHit.play().bindOnce("ended", function() {
|
||||
soundDie.play().bindOnce("ended", function() {
|
||||
showScore();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
score = Math.round((state.score - i * 0.1) / 10);
|
||||
setBigScore();
|
||||
|
||||
$("#player").css({ top: state.bird.y, left: state.bird.x });
|
||||
|
||||
$(".pipe").css({ left: state.wall.x });
|
||||
$(".pipe_upper").css({ height: state.wall.gate.y });
|
||||
$(".pipe_lower").css({ height: 200 - state.wall.gate.y - state.wall.gate.height });
|
||||
|
||||
i++;
|
||||
setTimeout(p, gameSpeed)
|
||||
}, gameSpeed)
|
||||
});
|
||||
}
|
||||
|
||||
$('#new').click(newGame)
|
||||
|
||||
$('#faster').click(function() {
|
||||
gameSpeed = Math.max(5, gameSpeed - 5);
|
||||
});
|
||||
|
||||
$('#slower').click(function() {
|
||||
gameSpeed = Math.min(50, gameSpeed + 5);
|
||||
});
|
||||
|
||||
|
||||
newGame();
|
||||
|
||||
|
25
web/static/main.htm
Normal file
@ -0,0 +1,25 @@
|
||||
<html class="fa-events-icons-ready"><head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Playing Flappy Bird using Evolution Strategies</title>
|
||||
|
||||
<link rel="stylesheet" href="main_files/style.css">
|
||||
|
||||
<script src="main_files/befea5cf35.js"></script><link href="main_files/befea5cf35.css" media="all" rel="stylesheet">
|
||||
<script src="main_files/socket.js"></script>
|
||||
</head>
|
||||
|
||||
<body><header>
|
||||
<h1>Playing Flappy Bird using Evolution Strategies</h1>
|
||||
</header>
|
||||
|
||||
<canvas id="canvas" width="450" height="400"></canvas>
|
||||
|
||||
<footer>
|
||||
<p>Inspired by <a href="https://blog.openai.com/evolution-strategies/">Evolution Strategies as a Scalable Alternative to Reinforcement Learning</a> by <a href="https://openai.com/">OpenAI</a></p><a href="https://openai.com/">
|
||||
|
||||
</a><div class="links"><a href="https://openai.com/">
|
||||
</a><a class="github" href="https://github.com/mdibaiee/flappy-es" alt="GitHub">GitHub <i class="fa fa-github"></i></a>
|
||||
<a class="aylien" href="https://aylien.com/"><img src="main_files/aylien.png" alt="Aylien" width="32"></a>
|
||||
</div>
|
||||
</footer>
|
||||
</body></html>
|
BIN
web/static/main_files/aylien.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
21
web/static/main_files/befea5cf35.css
Normal file
@ -0,0 +1,21 @@
|
||||
/*!
|
||||
* Font Awesome v4.7.0 by @davegandy - http://fontawesome.io - @fontawesome
|
||||
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
|
||||
*/
|
||||
@import url('//use.fontawesome.com/releases/v4.7.0/css/font-awesome-css.min.css');
|
||||
/* FONT PATH
|
||||
* -------------------------- */
|
||||
@font-face {
|
||||
font-family: 'FontAwesome';
|
||||
src: url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.eot');
|
||||
src: url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.woff2') format('woff2'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.woff') format('woff'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.ttf') format('truetype'),
|
||||
url('//use.fontawesome.com/releases/v4.7.0/fonts/fontawesome-webfont.svg#fontawesomeregular') format('svg');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
/*
|
||||
Embed code befea5cf35
|
||||
*/
|
15
web/static/main_files/befea5cf35.js
Normal file
3
web/static/main_files/socket.js
Normal file
36
web/static/main_files/style.css
Normal file
@ -0,0 +1,36 @@
|
||||
html, body {
|
||||
color: rgb(50, 50, 50);
|
||||
background: rgb(246, 248, 251);
|
||||
|
||||
font-family: Open Sans, sans-serif;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(140, 140, 180);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: rgb(90, 90, 130);
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.links a {
|
||||
margin: 0 0.5rem;
|
||||
}
|
102
web/static/style.css
Normal file
@ -0,0 +1,102 @@
|
||||
html, body {
|
||||
color: rgb(50, 50, 50);
|
||||
background: rgb(246, 248, 251);
|
||||
|
||||
font-family: Open Sans, sans-serif;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
header {
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(140, 140, 180);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: rgb(90, 90, 130);
|
||||
}
|
||||
|
||||
.github {
|
||||
font-size: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.github .fa {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.links a {
|
||||
margin: 0 0.5rem;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 8px;
|
||||
}
|
||||
|
||||
footer > * {
|
||||
margin-top: 2rem;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
cursor: pointer;
|
||||
margin: 0 1rem;
|
||||
}
|
||||
|
||||
.btn i {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
|
||||
z-index: 9999;
|
||||
|
||||
font-size: 25px;
|
||||
font-weight: bold;
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
|
||||
position: fixed;
|
||||
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
|
||||
text-align: center;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.overlay.active {
|
||||
opacity: 1;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
.controls p {
|
||||
margin: 2rem auto;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
font-size: 12px;
|
||||
line-height: 1.4em;
|
||||
}
|