changeset 0:27280b550d56 1.0-beta

Serpentron 1.0-beta.
author Mikhail Kryshen <mikhail@kryshen.net>
date Wed, 17 Feb 2016 23:55:43 +0300
parents
children bffc42c9b7c5
files .hgignore Gruntfile.js LICENSE-GPL-3.0 README.md bower.json config-browser.js config-node.js deploy.js devel.js index.html local.amd.json package.json resources/skin.png skin/background.png skin/compose.rkt skin/snake.png skin/snake.svg skin/snake.xcf.gz skin/snake_mask.png skin/tile.png src/Serpentron-Tests.st src/Serpentron.st testing.js
diffstat 23 files changed, 2541 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,10 @@
+syntax: glob
+
+node_modules
+bower_components
+
+src/*.js
+test_runner.js
+config.js
+the.js
+*~
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gruntfile.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,116 @@
+'use strict';
+
+module.exports = function (grunt) {
+    var path = require('path'),
+        helpers = require('amber-dev').helpers;
+
+    // These plugins provide necessary tasks.
+    grunt.loadNpmTasks('grunt-contrib-clean');
+    grunt.loadNpmTasks('grunt-contrib-requirejs');
+    grunt.loadNpmTasks('grunt-execute');
+    grunt.loadNpmTasks('amber-dev');
+
+    // Default task.
+    grunt.registerTask('default', ['amdconfig:app', 'amberc:all']);
+    grunt.registerTask('test', ['amdconfig:app', 'requirejs:test_runner', 'execute:test_runner', 'clean:test_runner']);
+    grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
+    grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
+
+    // Project configuration.
+    grunt.initConfig({
+        // Metadata.
+        // pkg: grunt.file.readJSON(''),
+        banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
+        '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
+        '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
+        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
+        ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
+        // task configuration
+        amberc: {
+            options: {
+                amber_dir: path.join(__dirname, "bower_components", "amber"),
+                configFile: "config.js"
+            },
+            all: {
+                src: [
+                    'src/Serpentron.st', // list all sources in dependency order
+                    'src/Serpentron-Tests.st' // list all tests in dependency order
+                ],
+                amd_namespace: 'amber-serpentron',
+                libraries: ['amber_core/SUnit', 'silk/Silk']
+            }
+        },
+
+        amdconfig: {app: {dest: 'config.js'}},
+
+        requirejs: {
+            options: {
+                useStrict: true
+            },
+            deploy: {
+                options: {
+                    mainConfigFile: "config.js",
+                    rawText: {
+                        "amber/compatibility": "/*stub*/",
+                        "amber/Platform": "/*stub*/",
+                        "app": 'define(["deploy"],function(x){return x});'
+                    },
+                    pragmas: {
+                        excludeIdeData: true,
+                        excludeDebugContexts: true
+                    },
+                    include: ['config', 'config-browser', 'node_modules/requirejs/require', 'app'],
+                    optimize: "uglify2",
+                    out: "the.js"
+                }
+            },
+            devel: {
+                options: {
+                    mainConfigFile: "config.js",
+                    rawText: {
+                        "amber/compatibility": "/*stub*/",
+                        "amber/Platform": "/*stub*/",
+                        "app": 'define(["devel"],function(x){return x});'
+                    },
+                    include: ['config', 'config-browser', 'node_modules/requirejs/require', 'app'],
+                    exclude: ['devel'],
+                    out: "the.js"
+                }
+            },
+            test_runner: {
+                options: {
+                    mainConfigFile: "config.js",
+                    rawText: {
+                        "app": "(" + function () {
+                            define(["testing", "amber_devkit/NodeTestRunner"], function (amber) {
+                                amber.initialize().then(function () {
+                                    amber.globals.NodeTestRunner._main();
+                                });
+                            });
+                        } + "());"
+                    },
+                    paths: {"amber_devkit": helpers.libPath},
+                    pragmas: {
+                        excludeIdeData: true
+                    },
+                    include: ['config-node', 'app'],
+                    insertRequire: ['app'],
+                    optimize: "none",
+                    wrap: helpers.nodeWrapperWithShebang,
+                    out: "test_runner.js"
+                }
+            }
+        },
+
+        execute: {
+            test_runner: {
+                src: ['test_runner.js']
+            }
+        },
+
+        clean: {
+            test_runner: ['test_runner.js']
+        }
+    });
+
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE-GPL-3.0	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,24 @@
+# Serpentron
+
+Implementation of a classic arcade game.  Survive as long as possible
+without hitting anything.  Up to 4 players can play on a single
+computer. Players with the same color form a team.  The scoring system
+is balanced for all possible team configurations.
+
+[Play here](http://www.games1729.com/serpentron/)
+
+## Getting Started
+
+Install Amber and create an Amber project, as shown in
+[Amber Instructions](https://github.com/amber-smalltalk/amber#prerequisites).
+
+To bring project alive after cloning the repository:
+
+```sh
+npm install
+bower install
+grunt default devel
+```
+
+Developing the project (after brought alive): start server with 
+`amber serve` and go to `http://localhost:4000/`.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bower.json	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,39 @@
+{
+  "name": "serpentron",
+  "description": "Implementation of a classic arcade game. Survive as long as possible without hitting anything.",
+  "ignore": [
+    "**/.*",
+    "node_modules",
+    "bower_components",
+    "/*.js",
+    "/*.html",
+    "test",
+    "tests"
+  ],
+  "authors": [
+    {
+      "name": "Mikhail Kryshen",
+      "email": "mikhail@kryshen.net"
+    }
+  ],
+  "homepage": "http://www.games1729.com/serpentron/",
+  "keywords": [
+    "Amber",
+    "Smalltalk"
+  ],
+  "license": [
+    "GPL-3.0"
+  ],
+  "private": false,
+  "dependencies": {
+    "amber": "^0.15.1",
+    "amber-compat-es2015": "^0.1.0",
+    "domite": "^0.4.0",
+    "silk": "^0.2.0"
+  },
+  "devDependencies": {
+    "amber-contrib-legacy": "^0.3.0",
+    "amber-ide-starter-dialog": "^0.1.0",
+    "helios": "^0.6.0"
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config-browser.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,2 @@
+define("amber/Platform", ["amber_core/Platform-Browser"], {});
+define("amber/compatibility", ["amber/browser-compatibility"], {});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config-node.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,7 @@
+// This file is used to make additional changes
+// when building an app to run in node.js.
+// Free to edit. You can break tests (cli test runner uses
+// this to build itself - it is a node executable).
+define("amber/Platform", ["amber_core/Platform-Node"], {});
+define("amber/compatibility", ["amber/node-compatibility"], {});
+define("jquery", {});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/deploy.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,11 @@
+define([
+    'amber/deploy',
+    // Should not be required in deployment,
+    // but something still tries to load it.
+    'jquery',
+    // --- packages to be deployed begin here ---
+    'amber-serpentron/Serpentron'
+    // --- packages to be deployed end here ---
+], function (amber) {
+    return amber;
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/devel.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,11 @@
+define([
+    './testing',
+    'amber/devel',
+    // --- packages used only during development begin here ---
+    'amber/legacy/Benchfib',
+    'amber/legacy/Examples',
+    'amber/legacy/IDE'
+    // --- packages used only during development end here ---
+], function (amber) {
+    return amber;
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.html	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,162 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Serpentron</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+        <meta name="author" content="Mikhail Kryshen" />
+        <script type='text/javascript' src='the.js'></script>
+        <style>
+         body {
+             margin: 0;
+             background: #333;
+             color: #fff;
+         }
+         #serpentron {
+             font-family: 'PT Sans', 'Helvetica', sans-serif;
+         }
+         #title {
+             overflow: auto;
+             padding: 5px 10px;
+             height: 25px;
+             background: #ddd;
+             color: black;
+         }
+         #title h1 {
+             display: inline;
+             margin: 0 15px 0 0;
+             padding: 0;
+             line-height: 24px;
+             font-size: 22px;
+             font-weight: bold;
+         }
+         #title h1 a,
+         #title h1 a:visited {
+             color: #00c;
+         }
+         #status {
+             display: inline;
+             font-weight: bold;
+         }
+         #status .player-color {
+             filter: brightness(60%) saturate(180%);
+         }
+         #serpentron canvas {
+             position: absolute;
+             width: 100%;
+             height: 100%;
+             /* image-rendering: optimizeSpeed;
+                image-rendering: -moz-crisp-edges;
+                image-rendering: -webkit-optimize-contrast;
+                image-rendering: -o-crisp-edges; */
+             image-rendering: pixelated;         
+             /* -ms-interpolation-mode: nearest-neighbor; */
+         }
+         #field {
+             position: relative;
+             clear: both;
+         }
+         #start-screen {
+             background: rgba(0, 0, 0, 0.7);
+             margin: 0;
+             padding: 15px;
+             position: absolute;
+             top: 0;
+             left: 0;
+             bottom: 0;
+             right: 0;
+         }
+         #message {
+             color: white;
+             text-shadow: 1px 1px 1px #000;
+             background: rgba(0, 0, 0, 0.8);
+             font-size: 28px;
+             font-weight: bold;
+             text-align: center;
+             padding: 1em;
+             position: absolute;
+             top: 50%;
+             left: 50%;
+             transform: translateX(-50%) translateY(-50%);
+             -webkit-transform: translateX(-50%) translateY(-50%);
+             border: 2px solid #aaa;
+             border-radius: 1em;
+         }
+         #message .player-color {
+             filter: brightness(150%) saturate(90%);
+         }
+         .player {
+             margin: 10px 0;
+         }
+         .color-selector {
+             margin-right: 5px;
+             vertical-align: center;
+         }
+         .player input,
+         .player select {
+             vertical-align: middle;
+             background: rgba(60, 60, 60, 0.7);
+             color: white;
+             border: solid 2px grey;
+             outline: none;
+             margin: 0 5px;
+         }
+         .color-button,
+         .selected-color-button {
+             display: inline-block;
+             vertical-align: middle;
+             text-align: center;
+             width: 21px;
+             height: 21px;
+         }
+         .color-button span,
+         .selected-color-button span {
+             color: white;
+             vertical-align: middle;
+         }
+         .color-button {
+             padding: 2px;
+         }
+         .selected-color-button {
+             padding: 0;
+             border: solid 2px white;
+         }
+         .color-button:hover {
+             padding: 0;
+             border: solid 2px #ccc;
+         }
+         #start-screen button {
+             background: white;
+             color: black;
+             border: none;
+             padding: 2px 5px;
+             margin: 5px 10px 5px 0;
+         }
+         .visible {
+             visibility: visible;
+             opacity: 1;
+             transition: visibility 0s, opacity 0.2s linear;
+             -moz-transition: visibility 0s, opacity 0.2s linear;
+         }
+         .hidden {
+             visibility: hidden;
+             opacity: 0;
+             transition: visibility 0.2s, opacity 0.2s linear;
+             -moz-transition: visibility 0.2s, opacity 0.2s linear;
+         }
+        </style>
+    </head>
+    <body>
+        <div id="serpentron"></div>
+        <script type='text/javascript'>
+         require(['app'], function (amber) {
+             amber.initialize({
+                 //used for all new packages in IDE
+                 'transport.defaultAmdNamespace': "amber-serpentron"
+             }).then(function () {
+                 require(["amber-ide-starter-dialog"], function (dlg) { dlg.start(); });
+                 amber.globals.Serpentron._start();
+             });
+         });
+        </script>
+    </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/local.amd.json	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,5 @@
+{
+    "paths": {
+        "amber-serpentron": "src"
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.json	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,42 @@
+{
+  "name": "serpentron",
+  "title": "Serpentron",
+  "description": "Implementation of a classic arcade game. Survive as long as possible without hitting anything.",
+  "version": "1.0.0-beta",
+  "homepage": "http://www.games1729.com/serpentron/",
+  "author": {
+    "name": "Mikhail Kryshen",
+    "email": "mikhail@kryshen.net"
+  },
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "bugs": {
+    "url": ""
+  },
+  "licenses": [
+    {
+      "type": "GPL-3.0",
+      "url": "http://www.gnu.org/licenses/gpl.html"
+    }
+  ],
+  "engines": {
+    "node": "0.10.x || 0.12.x || >=4.0.0"
+  },
+  "scripts": {
+    "test": "grunt test"
+  },
+  "devDependencies": {
+    "amber-dev": "^0.8.2",
+    "grunt": "^0.4.5",
+    "grunt-contrib-clean": "^0.7.0",
+    "grunt-contrib-requirejs": "^0.4.4",
+    "grunt-execute": "^0.2.2",
+    "requirejs": "^2.1.15"
+  },
+  "keywords": [
+    "Amber",
+    "Smalltalk"
+  ]
+}
\ No newline at end of file
Binary file resources/skin.png has changed
Binary file skin/background.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skin/compose.rkt	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,38 @@
+#lang racket
+(require 2htdp/image)
+(require lang/posn)
+
+(define background (bitmap/file "background.png"))
+(define tile (bitmap/file "tile.png"))
+(define snake (bitmap/file "snake.png"))
+(define snake-mask (bitmap/file "snake_mask.png"))
+
+(define s (image-width tile))
+
+(define head (crop 0 0 s s snake))
+(define head-mask (crop 0 0 s s snake-mask))
+
+(define body (crop 0 s s s snake))
+(define body-mask (crop 0 s s s snake-mask))
+
+(define corner (crop 0 (* s 2) s s snake))
+(define corner-mask (crop 0 (* s 2) s s snake-mask))
+
+(define (orientations pict)
+  (beside/align "top"
+                pict
+                (rotate -90 pict)
+                (rotate 180 pict)
+                (rotate 90 pict)))
+
+(save-image
+ (above/align "left"
+              background
+              (beside tile
+                      (orientations head)
+                      (orientations body)
+                      (orientations corner)
+                      (orientations head-mask)
+                      (orientations body-mask)
+                      (orientations corner-mask)))
+ "skin.png")
Binary file skin/snake.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skin/snake.svg	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   sodipodi:docname="snake.svg"
+   inkscape:version="0.91 r13725"
+   version="1.1"
+   id="svg2"
+   viewBox="0 0 28 42.000001"
+   height="42"
+   width="28"
+   inkscape:export-filename="/home/mikhail/projects/own/serpentron/skin/path4407.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90">
+  <sodipodi:namedview
+     inkscape:snap-smooth-nodes="true"
+     inkscape:object-nodes="true"
+     inkscape:window-maximized="1"
+     inkscape:window-y="27"
+     inkscape:window-x="0"
+     inkscape:window-height="960"
+     inkscape:window-width="1280"
+     inkscape:guide-bbox="true"
+     showguides="true"
+     units="px"
+     showgrid="true"
+     inkscape:current-layer="svg2"
+     inkscape:document-units="px"
+     inkscape:cy="15.241741"
+     inkscape:cx="-3.6398525"
+     inkscape:zoom="8"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     borderopacity="1.0"
+     bordercolor="#666666"
+     pagecolor="#ffffff"
+     id="base">
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4146"
+       orientation="1,0"
+       position="14,14" />
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4148"
+       orientation="0,1"
+       position="14,28.000001" />
+    <inkscape:grid
+       enabled="true"
+       spacingx="1"
+       id="grid4169"
+       type="xygrid" />
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4175"
+       orientation="1,0"
+       position="7,28.000001" />
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4207"
+       orientation="0,1"
+       position="14,14" />
+    <inkscape:grid
+       enabled="false"
+       spacingy="0.50000001"
+       spacingx="0.5"
+       id="grid4209"
+       type="xygrid" />
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4287"
+       orientation="1,0"
+       position="42,14" />
+    <sodipodi:guide
+       inkscape:color="rgb(0,0,255)"
+       inkscape:label=""
+       id="guide4274"
+       orientation="1,0"
+       position="28,14" />
+  </sodipodi:namedview>
+  <defs
+     id="defs4" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     transform="translate(0,-1010.3622)"
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="Layer 1">
+    <path
+       sodipodi:nodetypes="zzzzzzzzzzz"
+       inkscape:connector-curvature="0"
+       id="path4177"
+       d="m 7,1011.3622 c -2,0 -6,5 -6,8 0,3 0,20 0,20 0,10 2,12 12,12 0,0 17,0 20,0 3,0 8,-3 8,-6 0,-3 -5,-6 -8,-6 -3,0 -19,0 -19,0 -0.5,0 -1,-0.5 -1,-1 0,0 0,-16 0,-19 0,-3 -4,-8 -6,-8 z"
+       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <path
+       sodipodi:nodetypes="cczzccczzcc"
+       inkscape:connector-curvature="0"
+       id="path4261"
+       d="m 7,1014.3622 -1,5 0,23 c 0,2 2,4 4,4 l 23,0 5,-1 -5,-1 -21,0 c -3,0 -4,-1 -4,-4 l 0,-21 z"
+       style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+    <g
+       id="g4401">
+      <path
+         id="path4403"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#000000"
+         d="M7.0 1011.3622C5.81396484375 1011.3622 3.92458999157 1013.12054924 2.5831538527 1015.17742291C1.66253876686 1016.58903609 1.0 1018.14125273 1.0 1019.3622C1.0 1022.3622 1.0 1039.3622 1.0 1039.3622C1.0 1040.26429961 1.0162756741 1041.10129652 1.05323170609 1041.87759542C1.20883119981 1045.14612046 1.7310402154 1047.33862595 2.94862200698 1048.78387514C4.64754022609 1050.80046261 7.70029532909 1051.3622 13.0 1051.3622C13.0 1051.3622 23.38732839 1051.3622 29.3557683609 1051.3622C31.0227559283 1051.3622 32.3450317383 1051.3622 33.0 1051.3622C33.6892089844 1051.3622 34.4839755297 1051.20386366 35.2994232133 1050.92356659C37.1450378735 1050.28916612 39.0965935891 1049.03001047 40.1700297464 1047.56783987C40.6867543487 1046.8639885 41.0 1046.11309425 41.0 1045.3622C41.0 1042.3622 36.0 1039.3622 33.0 1039.3622C31.3928833008 1039.3622 26.0550207011 1039.3622 21.4447859723 1039.3622C17.4491091371 1039.3622 14.0 1039.3622 14.0 1039.3622C13.8740234375 1039.3622 13.748046875 1039.33045981 13.6300673522 1039.27497647C13.2797870636 1039.11024688 13.0 1038.73622344 13.0 1038.3622C13.0 1038.3622 13.0 1022.3622 13.0 1019.3622C13.0 1018.14125273 12.3374612331 1016.58903609 11.4168461473 1015.17742291C10.0754100084 1013.12054924 8.18603515625 1011.3622 7.0 1011.3622" />
+      <path
+         id="path4405"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#2a2a2a"
+         d="M7.0 1011.8622C6.01163736979 1011.8622 4.27049165964 1014.16082437 3.15262821058 1015.87488576C2.38544897238 1017.05123007 1.83333333333 1018.60365347 1.83333333333 1020.00435377C1.83333333333 1023.31798109 1.83333333333 1038.85866743 1.83333333333 1039.50538335C1.83333333333 1040.47792927 1.84689639509 1041.3114471 1.87769308841 1041.95836285C2.00735933317 1045.01546705 2.77586684617 1047.17588829 4.12385167248 1048.38026262C5.53961685508 1050.06075217 8.79153402088 1050.52886667 14.0153788525 1050.52886667C15.0867841896 1050.52886667 24.989440325 1050.52886667 29.9631403008 1050.52886667C31.3522966069 1050.52886667 32.7270997365 1050.47428534 33.5063697075 1050.42759273C34.2552102407 1050.39269278 35.0699796081 1050.23025305 35.7495193444 1049.99667215C37.2875315612 1049.4680051 38.0804946576 1048.25204205 38.9750247886 1047.03356656C39.4056286239 1046.44702375 39.5367986659 1045.82127854 39.327094819 1045.19553333C38.969163511 1042.69553333 34.2119790314 1040.19553333 31.1376625112 1040.19553333C28.962403085 1040.19553333 23.712517251 1040.19553333 19.8706549769 1040.19553333C16.0594789684 1040.19553333 13.0128288269 1040.04100694 13.0006970701 1039.58316214C12.8952490489 1039.56551701 12.7900390625 1039.5209712 12.6917227935 1039.45618039C12.399822553 1039.31890573 12.1666666667 1038.94683681 12.1666666667 1038.53024742C12.1666666667 1038.05489309 12.1666666667 1023.33205591 12.1666666667 1020.00428351C12.1666666667 1018.60649162 11.6145510276 1017.05123007 10.8473717894 1015.87488576C9.72950834036 1014.16082437 7.98836263021 1011.8622 7.0 1011.8622" />
+      <path
+         id="path4407"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#555555"
+         d="M7.0 1012.3622C6.20930989583 1012.3622 4.61639332771 1015.20109949 3.72210256847 1016.57234861C3.10835917791 1017.51342406 2.66666666667 1019.0660542 2.66666666667 1020.64650753C2.66666666667 1024.27376218 2.66666666667 1038.35513486 2.66666666667 1039.64856669C2.66666666667 1040.69155893 2.67751711607 1041.52159768 2.70215447073 1042.03913028C2.80588746654 1044.88481364 3.82069347694 1047.01315063 5.29908133798 1047.97665009C6.43169348406 1049.32104174 9.88277271266 1049.69553333 15.030757705 1049.69553333C17.1735683791 1049.69553333 26.59155226 1049.69553333 30.5705122406 1049.69553333C31.6818372856 1049.69553333 33.1091677348 1049.58637068 34.012739415 1049.49298545C34.821211497 1049.42318557 35.6559836864 1049.25664244 36.1996154755 1049.06977772C37.430025249 1048.64684408 37.064395726 1047.47407364 37.7800198309 1046.49929325C38.1245028991 1046.030059 38.0735973318 1045.52946283 37.654189638 1045.02886667C36.938327022 1043.02886667 32.4239580627 1041.02886667 29.2753250224 1041.02886667C26.5319228692 1041.02886667 21.3700138008 1041.02886667 18.2965239815 1041.02886667C14.6698487997 1041.02886667 12.0256576538 1040.71981388 12.0013941402 1039.80412428C11.9164746602 1039.76883401 11.83203125 1039.71148258 11.7533782348 1039.63738432C11.5198580424 1039.52756458 11.3333333333 1039.15745018 11.3333333333 1038.69829484C11.3333333333 1037.74758617 11.3333333333 1024.30191183 11.3333333333 1020.64636702C11.3333333333 1019.07173051 10.8916408221 1017.51342406 10.2778974315 1016.57234861C9.38360667229 1015.20109949 7.79069010417 1012.3622 7.0 1012.3622" />
+      <path
+         id="path4409"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#7f7f7f"
+         d="M7.0 1012.8622C6.40698242188 1012.8622 4.96229499578 1016.24137462 4.29157692635 1017.26981145C3.83126938343 1017.97561804 3.5 1019.52845493 3.5 1021.2886613C3.5 1025.22954327 3.5 1037.85160229 3.5 1039.79175004C3.5 1040.90518859 3.50813783705 1041.73174826 3.52661585304 1042.11989771C3.6044155999 1044.75416023 4.8655201077 1046.85041297 6.47431100349 1047.57303757C7.32377011305 1048.5813313 10.9740114044 1048.8622 16.0461365575 1048.8622C19.2603525687 1048.8622 28.193664195 1048.8622 31.1778841805 1048.8622C32.0113779642 1048.8622 33.491235733 1048.69845603 34.5191091225 1048.55837818C35.3872127533 1048.45367835 36.2419877648 1048.28303183 36.6497116067 1048.14288329C37.5725189367 1047.82568306 36.0482967945 1046.69610523 36.5850148732 1045.96501994C36.8433771743 1045.61309425 36.6103959978 1045.23764712 35.981284457 1044.8622C34.907490533 1043.3622 30.6359370941 1041.8622 27.4129875336 1041.8622C24.1014426534 1041.8622 19.0275103506 1041.8622 16.7223929861 1041.8622C13.280218631 1041.8622 11.0384864807 1041.39862082 11.0020912103 1040.02508642C10.9377002716 1039.97215102 10.8740234375 1039.90199397 10.8150336761 1039.81858824C10.6398935318 1039.73622344 10.5 1039.36806355 10.5 1038.86634226C10.5 1037.44027926 10.5 1025.27176774 10.5 1021.28845053C10.5 1019.53696939 10.1687306166 1017.97561804 9.70842307365 1017.26981145C9.03770500422 1016.24137462 7.59301757812 1012.8622 7.0 1012.8622" />
+      <path
+         id="path4411"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#aaaaaa"
+         d="M7.0 1013.3622C6.60465494792 1013.3622 5.30819666386 1017.28164975 4.86105128423 1017.9672743C4.55417958895 1018.43781203 4.33333333333 1019.99085566 4.33333333333 1021.93081506C4.33333333333 1026.18532436 4.33333333333 1037.34806972 4.33333333333 1039.93493339C4.33333333333 1041.11881825 4.33875855803 1041.94189884 4.35107723536 1042.20066514C4.40294373327 1044.62350682 5.91034673847 1046.68767532 7.64954066899 1047.16942505C8.21584674203 1047.84162087 12.0652500962 1048.02886667 17.06151541 1048.02886667C21.3471367583 1048.02886667 29.79577613 1048.02886667 31.7852561203 1048.02886667C32.3409186428 1048.02886667 33.8733037313 1047.81054137 35.0254788299 1047.6237709C35.9532140096 1047.48417113 36.8279918432 1047.30942122 37.0998077378 1047.21598886C37.7150126245 1047.00452204 35.032197863 1045.91813682 35.3900099155 1045.43074662C35.5622514496 1045.1961295 35.1471946637 1044.94583142 34.3083792761 1044.69553333C32.8766540441 1043.69553333 28.8479161255 1042.69553333 25.5506500448 1042.69553333C21.6709624376 1042.69553333 16.6850069004 1042.69553333 15.1482619908 1042.69553333C11.8905884624 1042.69553333 10.0513153076 1042.07742776 10.0027882804 1040.24604856C9.95892588298 1040.17546803 9.916015625 1040.09250535 9.8766891174 1039.99979216C9.7599290212 1039.94488229 9.66666666667 1039.57867692 9.66666666667 1039.03438968C9.66666666667 1037.13297235 9.66666666667 1026.24162366 9.66666666667 1021.93053404C9.66666666667 1020.00220828 9.44582041105 1018.43781203 9.13894871577 1017.9672743C8.69180333614 1017.28164975 7.39534505208 1013.3622 7.0 1013.3622" />
+      <path
+         id="path4413"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#d4d4d4"
+         d="M7.0 1013.8622C6.80232747396 1013.8622 5.65409833193 1018.32192487 5.43052564212 1018.66473715C5.27708979448 1018.90000601 5.16666666667 1020.45325639 5.16666666667 1022.57296883C5.16666666667 1027.14110544 5.16666666667 1036.84453715 5.16666666667 1040.07811673C5.16666666667 1041.33244791 5.16937927902 1042.15204942 5.17553861768 1042.28143257C5.20147186663 1044.49285341 6.95517336923 1046.52493766 8.8247703345 1046.76581252C9.10792337102 1047.10191043 13.156488788 1047.19553333 18.0768942625 1047.19553333C23.4339209478 1047.19553333 31.397888065 1047.19553333 32.3926280602 1047.19553333C32.6704593214 1047.19553333 34.2553717295 1046.92262671 35.5318485374 1046.68916363C36.5192152659 1046.51466391 37.4139959216 1046.33581061 37.5499038689 1046.28909443C37.8575063122 1046.18336102 34.0160989315 1045.14016841 34.1950049577 1044.89647331C34.2811257248 1044.77916475 33.6839933296 1044.65401571 32.6354740951 1044.52886667C30.8458175551 1044.02886667 27.0598951568 1043.52886667 23.6883125559 1043.52886667C19.2404822218 1043.52886667 14.3425034502 1043.52886667 13.5741309954 1043.52886667C10.5009582937 1043.52886667 9.06414413452 1042.7562347 9.00348535056 1040.4670107C8.98015149434 1040.37878503 8.9580078125 1040.28301674 8.9383445587 1040.18099608C8.8799645106 1040.15354115 8.83333333333 1039.78929029 8.83333333333 1039.2024371C8.83333333333 1036.82566543 8.83333333333 1027.21147957 8.83333333333 1022.57261754C8.83333333333 1020.46744716 8.72291020552 1018.90000601 8.56947435788 1018.66473715C8.34590166807 1018.32192487 7.19767252604 1013.8622 7.0 1013.8622" />
+      <path
+         id="path4415"
+         style="stroke-linejoin:miter;opacity:1.0;stroke-opacity:1;fill-rule:evenodd;fill-opacity:1.0;stroke:none;stroke-linecap:butt;stroke-width:1.0;fill:#ffffff"
+         d="M7.0 1014.3622C7.0 1014.3622 6.0 1019.3622 6.0 1019.3622C6.0 1019.3622 6.0 1020.91565713 6.0 1023.21512259C6.0 1028.09688653 6.0 1036.34100458 6.0 1040.22130008C6.0 1041.54607757 6.0 1042.3622 6.0 1042.3622C6.0 1044.3622 8.0 1046.3622 10.0 1046.3622C10.0 1046.3622 14.2477274798 1046.3622 19.092273115 1046.3622C25.5207051374 1046.3622 33.0 1046.3622 33.0 1046.3622C33.0 1046.3622 34.6374397278 1046.03471205 36.0382182449 1045.75455635C37.0852165222 1045.5451567 38.0 1045.3622 38.0 1045.3622C38.0 1045.3622 33.0 1044.3622 33.0 1044.3622C33.0 1044.3622 32.2207919955 1044.3622 30.9625689141 1044.3622C28.8149810661 1044.3622 25.2718741882 1044.3622 21.8259750671 1044.3622C16.810002006 1044.3622 12.0 1044.3622 12.0 1044.3622C9.111328125 1044.3622 8.07697296143 1043.43504164 8.00418242067 1040.68797284C8.00137710571 1040.58210204 8.0 1040.47352813 8.0 1040.3622C8.0 1040.3622 8.0 1039.99990366 8.0 1039.37048452C8.0 1036.51835852 8.0 1028.18133549 8.0 1023.21470105C8.0 1020.93268605 8.0 1019.3622 8.0 1019.3622C8.0 1019.3622 7.0 1014.3622 7.0 1014.3622" />
+    </g>
+  </g>
+</svg>
Binary file skin/snake.xcf.gz has changed
Binary file skin/snake_mask.png has changed
Binary file skin/tile.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Serpentron-Tests.st	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,5 @@
+Smalltalk createPackage: 'Serpentron-Tests'!
+TestCase subclass: #SerpentronTest
+	instanceVariableNames: ''
+	package: 'Serpentron-Tests'!
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Serpentron.st	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,1230 @@
+Smalltalk createPackage: 'Serpentron'!
+(Smalltalk packageAt: 'Serpentron') imports: {'silk/Silk'}!
+Object subclass: #Serpentron
+	instanceVariableNames: 'field skin players playerColors controllerPrototypes score pointsToWin'
+	package: 'Serpentron'!
+!Serpentron commentStamp!
+The game UI.!
+
+!Serpentron methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	playerColors := #('#377eb8' '#e41a1c' '#4daf4a' '#ff7f00' '#984ea3' '#b3ad78').
+	skin := TronSkin new.
+	field := TronField new
+		skin: skin;
+		onEndGame: [ self handleEndGame ].
+	self initializePlayers; initializeControllers.
+	(Silk fromElement: document)
+		on: #keydown bind: [ :event | field keyDown: event ].
+! !
+
+!Serpentron methodsFor: 'private'!
+
+handleEndGame
+	| color |
+	field isGameFinished
+		"Interrupted game, no winner."
+		ifFalse: [ ^ self startScreenVisible: true ].
+	color := field winningColorIfNone: [ 
+		^ self status: 'No winner in this round.'; nextRound ].
+	self updateScore.
+	(score anySatisfy: [ :each | each >= pointsToWin ])
+		ifFalse: [
+			self status: (self winnerDOM: color) << ' won the round.'.
+			^ self nextRound ].
+	self status: self scoreDOM.
+	window
+		setTimeout: [ 
+			self startScreenVisible: true.
+			self hideMessage.
+			self status: self scoreDOM << '. ' << (self winnerDOM: color) << ' won!!' ]
+		after: 2000.	
+	window
+		setTimeout: [ self showMessage: (self winnerDOM: color) << ' won!!' ]
+		after: 1000.
+!
+
+hideMessage
+	(Silk at: '#message') element className: 'hidden'.
+!
+
+initializeControllers
+	controllerPrototypes := {
+		TronKeyboardController new
+			keyMap: #{
+				38 -> (0 @ -1).
+				39 -> (1 @ 0).
+				40 -> (0 @ 1).
+				37 -> (-1 @ 0)}
+			name: 'arrows'.
+		TronKeyboardController new
+			keyMap: #{
+				87 -> (0 @ -1).
+				68 -> (1 @ 0).
+				83 -> (0 @ 1).
+				65 -> (-1 @ 0)}
+			name: 'WASD'.
+		TronKeyboardController new
+			keyMap: #{
+				89 -> (0 @ -1).
+				74 -> (1 @ 0).
+				72 -> (0 @ 1).
+				71 -> (-1 @ 0)}
+			name: 'YGHJ'.
+		TronKeyboardController new
+			keyMap: #{
+				80 -> (0 @ -1).
+				222 -> (1 @ 0).
+				59 -> (0 @ 1).
+				76 -> (-1 @ 0)}
+			name: 'PL;'''.
+		TronComputerController1 new.
+		"TronRandomController new"
+	}.
+	(players at: 1) controller: (controllerPrototypes at: 1) copy.
+	(players at: 2) controller: (controllerPrototypes at: 5) copy.
+	(players at: 3) controller: (controllerPrototypes at: 5) copy.
+	(players at: 4) controller: (controllerPrototypes at: 5) copy.
+!
+
+initializePlayers
+	players := { 
+		TronPlayer new
+			name: 'Player 1';
+			color: (playerColors at: 1).
+		TronPlayer new
+			name: 'Player 2';
+			color: (playerColors at: 2).
+		TronPlayer new
+			name: 'Player 3';
+			color: (playerColors at: 3);
+			enabled: false.
+		TronPlayer new
+			name: 'Player 4';
+			color: (playerColors at: 4);
+			enabled: false
+	}.
+!
+
+nextRound
+	window
+		setTimeout: [
+			self status: self scoreDOM.
+			field start: field players ]
+		after: 2000.
+!
+
+randomizePlayerColors
+	| enabledPlayers |
+	enabledPlayers := players select: #isEnabled.
+	enabledPlayers do: [ :each |
+		| color |
+		[ color := playerColors atRandom.
+		  enabledPlayers allSatisfy: [ :p |
+		  	  p = each | (p color ~= color) ]
+		] whileFalse.
+		each color: color.
+	].
+!
+
+randomizeTeams
+	| colorA colorB teamA |
+	players do: [ :each | each enabled: true ].
+	colorA := playerColors atRandom.
+	[ colorB := playerColors atRandom.
+	  colorB = colorA ] whileTrue.
+	teamA := players copy.
+	players size // 2 
+		timesRepeat: [ (teamA remove: teamA atRandom) color: colorB ].
+	teamA do: [ :each | each color: colorA ].
+!
+
+renderColorSelectorFor: aPlayer on: aSilk
+	| container buttons onChange |
+	container := aSilk SPAN: {#class -> 'color-selector'}.
+	buttons := Dictionary from:
+		(playerColors collect: [ :each |
+			| button |
+			button := container A.
+			button on: #click bind: [ 
+				aPlayer enabled: true; color: each.
+				self validatePlayerColor: aPlayer ].
+			button element style background: each.
+			each -> button ]).
+	buttons at: #disabled put: (container A
+		SPAN: '✗';
+		on: #click bind: [ 
+			aPlayer enabled: false.
+			self validatePlayerColor: aPlayer ]).
+	onChange := [
+		buttons keysAndValuesDo: [ :k :v |
+			(aPlayer isEnabled not & k = #disabled) |
+				(aPlayer isEnabled & k = aPlayer color)
+					ifTrue: [ v element className: 'selected-color-button' ]
+					ifFalse: [ v element className: 'color-button' ] ] ].
+	aPlayer
+		onEnabledChange: onChange;
+		onColorChange: onChange.
+	onChange value.
+!
+
+renderControllerSelectorFor: aPlayer on: aSilk
+	| select options onChange |
+	select := aSilk SELECT.
+	options := Dictionary new.
+	controllerPrototypes do: [ :each |
+		options at: each name put: (select OPTION: each name) element ].
+	select
+		on: #change
+		bind: [
+			aPlayer controller:
+				(controllerPrototypes
+					detect: [ :each | each name = select element value ])
+						copy ].
+	onChange := [
+		| value |
+		value := aPlayer controller name.
+		(options at: value) selected: 'selected'.
+		aPlayer controller class = TronKeyboardController
+			ifTrue: [
+				players do: [ :each |
+					(each ~= aPlayer and: [ each controller name = value ])
+						ifTrue: [ each controller: TronComputerController1 new ]]]].
+	aPlayer onControllerChange: onChange.
+	onChange value.
+!
+
+renderPlayer: aPlayer on: aSilk
+	| container |
+	container := aSilk DIV: { #class -> 'player' }.
+	self renderColorSelectorFor: aPlayer on: container.
+	(container INPUT
+		on: #change bind: [ :event |
+			aPlayer name: event target value ])
+		element value: aPlayer name.
+	self renderControllerSelectorFor: aPlayer on: container.
+!
+
+renderStartScreenOn: aSilk
+	| startScreen |
+	startScreen := aSilk DIV: {#id -> 'start-screen'}.
+	
+	players do: [ :each | self renderPlayer: each on: startScreen ].
+	
+	(startScreen BUTTON: 'Random colors')
+		on: #click bind: [ self randomizePlayerColors ].
+	(startScreen BUTTON: 'Random teams')
+		on: #click bind: [ self randomizeTeams ].
+
+	startScreen BR.
+
+	(startScreen BUTTON: 'Start')
+		on: #click bind: [ :event | self startGame; status: self scoreDOM ].
+!
+
+scoreDOM
+	| message |
+	message := Silk SPAN: 'Score: '.
+	score associations
+		do: [ :each | 
+			(message SPAN: {#class -> 'player-color'. (each value * 10) rounded / 10})
+				element style color: each key ]
+		separatedBy: [ message << ':' ].
+	message << ('/', pointsToWin).
+	^ message.
+!
+
+showMessage: anObject
+	((Silk at: '#message') resetContents << anObject)
+		element className: 'visible'.
+!
+
+startGame
+	| enabledPlayers |
+	self startScreenVisible: false.
+	field start: (players select: #isEnabled).
+	pointsToWin := (30 / (field players size + 1)) ceiling.
+	score := field colors collect: [ :each | 0 ].
+!
+
+startScreenVisible: aBoolean
+	(Silk at: '#start-screen') element 
+		className: (aBoolean ifTrue: [ 'visible' ] ifFalse: [ 'hidden' ])
+!
+
+status: anObject
+	'#status' asSilk resetContents << anObject
+!
+
+updateScore
+	| color teamSize alive points defeated |
+	color := field winningColorIfNone: [ ^ self ].
+	teamSize := field colors at: color.
+	defeated := field players size - teamSize.
+	alive := field liveColors at: color.
+	points := defeated * alive / teamSize * (teamSize + 1) / 2.
+	points := points / (field players size - 1).
+	score at: color	put: (score at: color) + points.
+!
+
+validatePlayerColor: aPlayer
+	| enabledPlayers otherPlayers freeColor |
+	enabledPlayers := players select: #isEnabled.
+	((enabledPlayers collect: #color) asSet size > 1)
+		ifTrue: [ ^ self ].
+	freeColor := playerColors detect: [ :each | each ~= enabledPlayers anyOne color ].
+	otherPlayers := players select: [ :each | each ~~ aPlayer ].
+	(otherPlayers
+		detect: [ :each | each isEnabled not ]
+		ifNone: [ otherPlayers first ])
+			enabled: true;
+			color: freeColor.
+!
+
+winnerDOM: color
+	| names team message |	
+	team := field players select: [ :each | each color = color ].
+	names := ''.
+	(team collect: #name)
+		do: [ :each | names := names, each]
+		separatedBy: [ names := names, ' and ' ].
+	message := Silk SPAN.
+	(message SPAN: {#class -> 'player-color'. names})
+		element style color: color.
+	^ message
+! !
+
+!Serpentron methodsFor: 'rendering'!
+
+augmentPage
+	'#serpentron' asSilk resetContents << 'Loading...'.
+	skin
+		load: 'resources/skin.png'
+		andDo: [ '#serpentron' asSilk resetContents << self ]
+!
+
+renderOnSilk: aSilk
+	| scale container width height |
+	scale := 1.
+	skin tileSize >= 20
+		ifTrue: [ scale := 0.5 ].
+	skin tileSize < 10
+		ifTrue: [ scale := 2].
+	
+	width := field fieldSize x * skin tileSize * scale.
+	height := field fieldSize y * skin tileSize * scale.
+	
+	aSilk element style
+		width: width asString , 'px'.
+	
+	(aSilk DIV: {#id -> 'title'})
+		H1: (Silk A: {	#href -> 'http://www.games1729.com/serpentron/'.
+						#target -> '_top'.
+						'Serpentron'});
+		SPAN: {#id -> 'status'. '1.0 beta'}.
+	
+	container := aSilk DIV: {#id -> 'field'}.
+	container element style
+		width: width asString , 'px';
+		height: height asString , 'px'.
+	
+	container << field.
+	self renderStartScreenOn: container.
+
+	(container DIV: {#id -> 'message'. #class -> 'hidden'})
+		element style
+			margin: '0 auto'.
+	
+	aSilk << container.
+! !
+
+Serpentron class instanceVariableNames: 'Instance'!
+
+!Serpentron class methodsFor: 'starting'!
+
+start
+	(Instance := self new) augmentPage
+! !
+
+Object subclass: #TronCollider
+	instanceVariableNames: 'canvas context skin animationRequest lastFrameTime particles particlePool particlesPerCollision'
+	package: 'Serpentron'!
+!TronCollider commentStamp!
+Particle system for collision effect.!
+
+!TronCollider methodsFor: 'accessing'!
+
+canvas: aCanvas
+	canvas := aCanvas.
+	context := canvas getContext: '2d'.
+!
+
+skin: aTronSkin
+	skin := aTronSkin
+! !
+
+!TronCollider methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	particlesPerCollision := 200.
+	particlePool := Queue new.
+	particlesPerCollision * 2 + 10 timesRepeat: [ 
+		particlePool nextPut: TronColliderParticle new ].
+	particles := OrderedCollection new
+! !
+
+!TronCollider methodsFor: 'private'!
+
+renderFrame: timestamp
+	| liveParticles delta |
+	delta := lastFrameTime
+		ifNil: [ 0 ]
+		ifNotNil: [	timestamp - lastFrameTime ].
+	lastFrameTime := timestamp.
+	"Transcript show: 'renderFrame: ';
+		show: timestamp;
+		show: '; ';
+		show: delta;
+		cr."
+	liveParticles := OrderedCollection new.
+	context clearRect: 0 y: 0 w: canvas width h: canvas height.
+	particles do: [ :each |
+		each
+			update: delta;
+			drawOn: context tileSize: skin tileSize.
+		each
+			ifAlive: [ liveParticles add: each ]
+			ifNotAlive: [ particlePool nextPut: each ] ].
+	particles := liveParticles.
+	animationRequest := particles
+		ifEmpty: [ nil ]
+		ifNotEmpty: [
+			window
+				requestAnimationFrame: [ :ts | 
+					self renderFrame: ts ]
+				on: canvas ]
+!
+
+startAnimation
+	animationRequest ifNotNil: [ ^ self ].
+	lastFrameTime := nil.
+	animationRequest := window
+		requestAnimationFrame: [ :ts | self renderFrame: ts ]
+		on: canvas.
+! !
+
+!TronCollider methodsFor: 'starting'!
+
+animateCollisionFor: aPlayer
+	| particle |
+	particlesPerCollision timesRepeat: [
+		particles add: 
+			((particlePool nextIfAbsent: [ TronColliderParticle new ])
+				resetPosition: 
+					aPlayer location - 0.5 - (aPlayer direction / 2)
+				color: (Math random < 0.5
+					ifTrue: [ aPlayer color ]
+					ifFalse: [ '#ff3000' ])) ].
+	self startAnimation.
+! !
+
+Object subclass: #TronColliderParticle
+	instanceVariableNames: 'color size velocity position alpha decay'
+	package: 'Serpentron'!
+
+!TronColliderParticle methodsFor: 'accessing'!
+
+ifAlive: aliveBlock ifNotAlive: notAliveBlock
+	^ alpha > 0.01 ifTrue: aliveBlock ifFalse:notAliveBlock
+!
+
+resetPosition: positionPoint color: aString
+	position := positionPoint.
+	color := aString.
+	"Particles return to the pool as soon as they die.
+	Randomize on each reset or the pool will end up sotrted by particles' life time."
+	alpha := 1 - (Math random * 0.5).
+	decay := 0.997 - (Math random * 0.01)
+! !
+
+!TronColliderParticle methodsFor: 'drawing'!
+
+drawOn: aContext tileSize: tileSize
+	aContext
+		globalAlpha: alpha;
+		fillStyle: color;
+		fillRect: (position x - (size / 2)) * tileSize
+			y: (position y - (size / 2)) * tileSize
+			w: size * tileSize
+			h: size * tileSize.
+! !
+
+!TronColliderParticle methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	size := (Math random * 0.3 + 0.7).
+	velocity := (Math random - 0.5) @ (Math random - 0.5).
+	velocity := velocity / (velocity dist: 0 @ 0) * (Math random raisedTo: 4 + 0.1) * 0.06
+! !
+
+!TronColliderParticle methodsFor: 'updating'!
+
+update: delta
+	position := position + (velocity * delta).
+	alpha := alpha * (decay raisedTo: delta).
+! !
+
+Object subclass: #TronController
+	instanceVariableNames: 'field player'
+	package: 'Serpentron'!
+!TronController commentStamp!
+Abstract superclass for controlling input devices and algorithms.!
+
+!TronController methodsFor: 'accessing'!
+
+field: aTronField
+	field := aTronField
+!
+
+name
+	self subclassResponsibility.
+!
+
+nextDirection: aPoint
+	"Do not turn back."
+	player nextDirection = (aPoint * (-1 @ -1))
+		ifTrue: [ ^ self ].
+	player nextDirection: aPoint.
+!
+
+player: aTronPlayer
+	player := aTronPlayer
+! !
+
+!TronController methodsFor: 'computing'!
+
+compute
+!
+
+isAtDecisionPoint
+	| loc dir turn |
+	player isFirstMove ifTrue: [ ^ true ].
+	dir := player nextDirection.
+	loc := player location.
+	(field isFreeAt: loc + dir)
+		ifFalse: [ ^ true ].
+	turn := dir rotate90ccw.
+	((field isFreeAt: loc + turn)
+		and: [ (field isFreeAt: loc + dir + turn) not ])
+		ifTrue: [ ^ true ].
+	turn := dir rotate90cw.
+	((field isFreeAt: loc + turn)
+		and: [ (field isFreeAt: loc + dir + turn) not ])
+		ifTrue: [ ^ true ].
+	^ false
+! !
+
+!TronController methodsFor: 'event handling'!
+
+keyDown: keyCode
+	^ false
+! !
+
+!TronController methodsFor: 'initialization'!
+
+reset
+! !
+
+TronController class instanceVariableNames: 'directions'!
+
+TronController subclass: #TronComputerController1
+	instanceVariableNames: 'weight aggressiveness'
+	package: 'Serpentron'!
+
+!TronComputerController1 methodsFor: 'accessing'!
+
+name
+	^ 'Computer'
+! !
+
+!TronComputerController1 methodsFor: 'computing'!
+
+compute
+	| best bestDirection |
+	"player isFirstMove
+		ifTrue: [ self nextDirection: TronPlayer directions atRandom ]."
+	(self isAtDecisionPoint 
+		or: [ (field isFreeAt: player location + (player nextDirection * 2)) not ])
+		ifFalse: [ ^ self ].
+	aggressiveness := 200 atRandom.
+	best := 0.
+	TronPlayer directions do: [ :each | 
+		weight := 0.
+		self scan: each.
+		weight > best
+			ifTrue:	[
+				best := weight.
+				bestDirection := each ]].
+	bestDirection ifNil: [ ^ self ].
+	self nextDirection: bestDirection.
+! !
+
+!TronComputerController1 methodsFor: 'private'!
+
+extend: directionPoint from: nwPoint to: sePoint
+	| point scanDir |
+	scanDir := directionPoint y abs @ directionPoint x abs.
+	point := Point
+		x: (directionPoint x <= 0 ifTrue: [ nwPoint x ] ifFalse: [ sePoint x ])
+		y: (directionPoint y <= 0 ifTrue: [ nwPoint y ] ifFalse: [ sePoint y ]).
+	[ point <= sePoint ] 
+		whileTrue: [
+			weight := weight + 1.
+			(field isFreeAt: point)
+				ifFalse: [ 
+					(self isEnemyHeadAt: point)
+						ifTrue: [ weight := weight + aggressiveness ]
+						ifFalse: [ ^ false ] ].
+			point := point + scanDir ].
+	^ true
+!
+
+isEnemyHeadAt: aPoint
+	(field playerWithHeadAt: aPoint)
+		ifNotNil: [ :p | ^ p color ~= player color ].
+	^ false
+!
+
+scan: directionPoint
+	| nw se nextNW nextSE directions scanDir |
+	nw := se := player location + directionPoint.
+	(field isFreeAt: nw) ifFalse: [ ^ self ].
+	directions := TronPlayer directions copy
+		remove: directionPoint * -1;
+		yourself.
+	[	scanDir := directions atRandom.
+		scanDir <= 0 asPoint
+			ifTrue: [ nextNW := nw + scanDir. nextSE := se ]
+			ifFalse: [ nextNW := nw. nextSE := se + scanDir ].
+		(self extend: scanDir from: nextNW to: nextSE)
+			ifTrue: [ nw := nextNW. se := nextSE ]
+			ifFalse: [ directions remove: scanDir ].
+		directions isEmpty not
+	] whileTrue.
+! !
+
+TronController subclass: #TronKeyboardController
+	instanceVariableNames: 'keyMap name'
+	package: 'Serpentron'!
+
+!TronKeyboardController methodsFor: 'accessing'!
+
+keyMap: aDictionary name: aString
+	keyMap := aDictionary.
+	name := 'Keyboard: ', aString.
+!
+
+name
+	^ name
+! !
+
+!TronKeyboardController methodsFor: 'event handling'!
+
+keyDown: keyCode
+	self nextDirection: (keyMap at: keyCode ifAbsent: [ ^ false ]).
+	^ true
+! !
+
+TronKeyboardController class instanceVariableNames: 'keyMaps'!
+
+TronController subclass: #TronRandomController
+	instanceVariableNames: ''
+	package: 'Serpentron'!
+
+!TronRandomController methodsFor: 'accessing'!
+
+name
+	^ 'Computer (random)'
+! !
+
+!TronRandomController methodsFor: 'computing'!
+
+compute
+	| dirs |
+	(self isAtDecisionPoint or: [ 50 atRandom = 1 ])
+		ifFalse: [ ^ self ].
+	dirs := TronPlayer directions
+		select: [ :each | field isFreeAt: player location + each ].
+	dirs ifNotEmpty: [ self nextDirection: dirs atRandom ]
+! !
+
+Object subclass: #TronField
+	instanceVariableNames: 'skin size matrix players livePlayers colors liveColors canvas context collider timerId onEndGame'
+	package: 'Serpentron'!
+!TronField commentStamp!
+The game field. Provides game logic and rendering.!
+
+!TronField methodsFor: 'accessing'!
+
+at: aPoint
+	^ (matrix at: aPoint y) at: aPoint x
+!
+
+at: aPoint ifAbsent: aBlock
+	^ matrix
+		at: aPoint y 
+		ifPresent: [ :value | value at: aPoint x ifAbsent: aBlock ]
+		ifAbsent: aBlock
+!
+
+at: aPoint put: aSegment
+	(matrix at: aPoint y) at: aPoint x put: aSegment
+!
+
+colors
+	^ colors
+!
+
+fieldSize
+	^ size
+!
+
+isFreeAt: aPoint
+	^ (self at: aPoint ifAbsent: [ ^ false ]) isNil
+!
+
+isGameFinished
+	^ liveColors size < 2
+!
+
+liveColors
+	^ liveColors
+!
+
+playerWithHeadAt: aPoint
+	| s |
+	s := self at: aPoint ifAbsent: [ ^ nil ].
+	s isHead ifTrue: [ ^ s player ] ifFalse: [ ^ nil ]
+!
+
+players
+	^ players
+!
+
+skin
+	^ skin
+!
+
+skin: aTronSkin
+	skin := aTronSkin
+!
+
+winningColorIfNone: aBlock
+	^ (liveColors size = 1)
+		ifTrue: [ liveColors keys anyOne ]
+		ifFalse: aBlock.
+! !
+
+!TronField methodsFor: 'event handling'!
+
+keyDown: event
+	"Handle Esc key."
+	livePlayers isEmpty not & (event keyCode = 27)
+		ifTrue: [
+			event preventDefault.
+			self endGame.
+			^ self ].
+	"Check all players rather than livePlayers 
+	so that preventDefault is called for all used keys."
+	(players anySatisfy: [ :each | each keyDown: event keyCode ])
+		ifTrue: [ event preventDefault ].
+	timerId ifNil: [ self startIfAllReady ].
+! !
+
+!TronField methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	livePlayers := players := #().
+	size := 50 @ 35
+! !
+
+!TronField methodsFor: 'observing'!
+
+onEndGame: aBlock
+	onEndGame := aBlock
+! !
+
+!TronField methodsFor: 'private'!
+
+endGame
+	self stopTimer.
+	livePlayers := #().
+	onEndGame ifNotNil: #value.
+!
+
+killPlayer: aPlayer
+	collider animateCollisionFor: aPlayer.
+	livePlayers remove: aPlayer.
+	self updateLiveColors.
+!
+
+locatePlayers
+	players size = 2 ifTrue: [
+		(players at: 1) location: 16 @ 18.
+		(players at: 2) location: 35 @ 18.
+		^ self ].
+	players size = 3 ifTrue: [
+		(players at: 1) location: 18 @ 13.
+		(players at: 2) location: 18 @ 23.
+		(players at: 3) location: 33 @ 18.
+		^ self ].
+	players size = 4 ifTrue: [
+		(players at: 1) location: 16 @ 11.
+		(players at: 2) location: 35 @ 11.
+		(players at: 3) location: 16 @ 25.
+		(players at: 4) location: 35 @ 25.
+		^ self ].
+	self error: 'Invalid number of players.'
+!
+
+renderCanvasOn: aSilk
+	^ aSilk CANVAS: {
+		#width -> (size x * skin tileSize).
+		#height -> (size y * skin tileSize)}.
+!
+
+startIfAllReady
+	(livePlayers isEmpty not
+		and: [ livePlayers allSatisfy: #isReady ])
+			ifTrue: [ self startTimer ]
+!
+
+startTimer
+	timerId ifNotNil: [ self error: 'Timer already running.' ].
+	timerId := window setInterval: [ self update ] every: 75.
+!
+
+stopTimer
+	timerId ifNotNil: [
+		window clearInterval: timerId.
+		timerId := nil ]
+!
+
+update
+	| lpCopy |
+	lpCopy := livePlayers copy.
+	lpCopy do: [ :each |
+		| l |
+		l := each location.
+		self at: l put: each move.
+		skin drawField: self on: context at: l ].
+	lpCopy do: [ :each |
+		| l other |
+		l := each location.
+		(self isFreeAt: l)
+			ifTrue: [ self at: l put: each headSegment. ]
+			ifFalse: [
+				self killPlayer: each.
+				"Check for head-to-head collision."
+				other := self playerWithHeadAt: l.
+				(other isNil | (other = each))
+					ifFalse: [ 
+						self killPlayer: other.
+						self at: l put: nil. ]]].
+	livePlayers do: [ :each | 
+		skin drawField: self on: context at: each location ].
+	self isGameFinished ifTrue: [ ^ self endGame ].
+	livePlayers do: #compute.
+!
+
+updateLiveColors
+	liveColors := Dictionary new.
+	livePlayers do: [ :each |
+		liveColors
+			at: each color
+			ifPresent: [ :v | liveColors at: each color put: v + 1 ]
+			ifAbsent: [ liveColors at: each color put: 1 ]].
+! !
+
+!TronField methodsFor: 'rendering'!
+
+renderOnSilk: aSilk
+	| backgroundCanvas |
+	
+	backgroundCanvas := (self renderCanvasOn: aSilk) element.
+	
+	canvas := (self renderCanvasOn: aSilk) element.
+	context := canvas getContext: '2d'.
+	
+	collider := TronCollider new
+		canvas: (self renderCanvasOn: aSilk) element;
+		skin: skin.
+	
+	skin drawBackgroundOn: (backgroundCanvas getContext: '2d') from: 1 @ 1 to: size
+! !
+
+!TronField methodsFor: 'starting'!
+
+start: anArrayOfPlayers
+	players := anArrayOfPlayers.
+	livePlayers := players copy.
+	self updateLiveColors.
+	colors := liveColors.
+	matrix := (1 to: size y) collect: [ :i | Array new: size x ].
+	context clearRect: 0 y: 0 w: canvas width h: canvas height.
+	self locatePlayers.
+	players do: [ :each | each field: self; reset; compute ].
+	players do: [ :each |
+		self at: each location put: each headSegment.
+		skin drawField: self on: context at: each location ].
+	self startIfAllReady.
+! !
+
+Object subclass: #TronPlayer
+	instanceVariableNames: 'enabled color name controller segments location moved direction nextDirection onColorChange onEnabledChange onControllerChange'
+	package: 'Serpentron'!
+
+!TronPlayer methodsFor: 'accessing'!
+
+color
+	^ color
+!
+
+color: anObject
+	color := anObject.
+	onColorChange ifNotNil: #value.
+!
+
+controller
+	^ controller
+!
+
+controller: aTronController
+	aTronController player: self.
+	controller := aTronController.
+	onControllerChange ifNotNil: #value.
+!
+
+direction
+	^ direction
+!
+
+enabled: aBoolean
+	enabled := aBoolean.
+	onEnabledChange ifNotNil: #value.
+!
+
+field: aField
+	controller field: aField
+!
+
+headSegment
+	^ segments at: direction
+!
+
+isEnabled
+	^ enabled
+!
+
+isFirstMove
+	^ moved not
+!
+
+isReady
+	^ nextDirection notNil
+!
+
+location
+	^ location
+!
+
+location: anObject
+	location := anObject
+!
+
+name
+	^ name
+!
+
+name: anObject
+	name := anObject.
+!
+
+nextDirection
+	^ nextDirection
+!
+
+nextDirection: aPoint
+	moved ifFalse: [ direction := aPoint ].
+	nextDirection := aPoint
+! !
+
+!TronPlayer methodsFor: 'event handling'!
+
+keyDown: keyCode
+	^ controller keyDown: keyCode
+! !
+
+!TronPlayer methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	enabled := true.
+	self reset; initializeSegments.
+!
+
+reset
+	direction := 0 @ -1.
+	nextDirection := nil.
+	moved := false.
+	controller ifNotNil: [ controller reset ].
+! !
+
+!TronPlayer methodsFor: 'observing'!
+
+onColorChange: aBlock
+	onColorChange := aBlock.
+!
+
+onControllerChange: aBlock
+	onControllerChange := aBlock.
+!
+
+onEnabledChange: aBlock
+	onEnabledChange := aBlock.
+! !
+
+!TronPlayer methodsFor: 'private'!
+
+initializeSegments
+	segments := Dictionary new.
+	TronPlayer directionNames keysAndValuesDo: [ :to :toName |
+		segments 
+			at: to 
+			put: (TronHead new 
+					player: self;
+					sprite: 'head', toName;
+					direction: to);
+			at: {to. to}
+			put: (TronSegment new
+					player: self;
+					sprite: 'body', toName).
+		TronPlayer directionNames keysAndValuesDo: [ :from :fromName |		
+			(from x = to x) | (from y = to y) ifFalse: [
+				segments
+					at: {from. to}
+					put: (TronSegment new
+							player: self;
+							sprite: 'body', fromName, 'To', toName) ]]].
+! !
+
+!TronPlayer methodsFor: 'updating'!
+
+compute
+	controller compute
+!
+
+move
+	| segment |
+	segment := segments at: {direction. nextDirection} ifAbsent: [ nil ].
+	direction := nextDirection.
+	location := location + direction.
+	moved := true.
+	^ segment
+! !
+
+TronPlayer class instanceVariableNames: 'directions directionNames'!
+
+!TronPlayer class methodsFor: 'initialization'!
+
+directionNames
+	^ directionNames
+!
+
+directions
+	^ directions
+!
+
+initialize
+	super initialize.
+	directionNames := Dictionary new
+		at: 0 @ -1 put: 'North';
+		at: 1 @ 0 put: 'East';
+		at: 0 @ 1 put: 'South';
+		at: -1 @ 0 put: 'West';
+		yourself.
+	directions := directionNames keys.
+! !
+
+Object subclass: #TronSegment
+	instanceVariableNames: 'player sprite'
+	package: 'Serpentron'!
+
+!TronSegment methodsFor: 'accessing'!
+
+color
+	^ player color
+!
+
+isHead
+	^ false
+!
+
+player
+	^ player
+!
+
+player: anObject
+	player := anObject
+!
+
+sprite
+	^ sprite
+!
+
+sprite: anObject
+	sprite := anObject
+! !
+
+TronSegment subclass: #TronHead
+	instanceVariableNames: 'direction'
+	package: 'Serpentron'!
+
+!TronHead methodsFor: 'accessing'!
+
+direction
+	^ direction
+!
+
+direction: anObject
+	direction := anObject
+!
+
+isHead
+	^ true
+! !
+
+Object subclass: #TronSkin
+	instanceVariableNames: 'skinMap skinImage tileSize maskOffset'
+	package: 'Serpentron'!
+
+!TronSkin methodsFor: 'accessing'!
+
+tileSize
+	^ tileSize
+! !
+
+!TronSkin methodsFor: 'drawing'!
+
+drawBackgroundOn: aContext at: aPoint
+	self drawTile: #background offset: aPoint - 1 on: aContext at: aPoint;
+		 drawTile: #backgroundTile on: aContext at: aPoint
+!
+
+drawBackgroundOn: aContext from: nwPoint to: sePoint
+	nwPoint y to: sePoint y do: [ :row |
+		nwPoint x to: sePoint x do: [ :col |
+			self drawBackgroundOn: aContext at: col @ row ]]
+!
+
+drawField: aField on: aContext at: aPoint
+	| x y segment |
+	
+	x := (aPoint - 1) x * tileSize.
+	y := (aPoint - 1) y * tileSize.
+	
+	aContext
+		clearRect: x and: y and: tileSize and: tileSize.
+	
+	segment := (aField at: aPoint) ifNil: [ ^ self ].
+	
+	self 
+		drawTile: segment sprite
+		offset: maskOffset
+		on: aContext
+		at: aPoint.
+	aContext
+		globalCompositeOperation: 'source-atop';
+		fillStyle: segment color;
+		fillRect: x and: y and: tileSize and: tileSize.
+	self drawTile: segment sprite on: aContext at: aPoint.
+	
+	aContext globalCompositeOperation: 'source-over'.
+!
+
+drawSkinImageOn: aContext source: sourcePoint destination: destinationPoint
+	aContext drawImage: skinImage
+		sx: sourcePoint x
+		sy: sourcePoint y
+		sw: tileSize
+		sh: tileSize
+		dx: destinationPoint x
+		dy: destinationPoint y
+		dw: tileSize
+		dh: tileSize
+!
+
+drawTile: aSymbol offset: offsetPoint on: aContext at: targetPoint
+	self 
+		drawSkinImageOn: aContext
+		source: ((skinMap at: aSymbol) + offsetPoint) * tileSize
+		destination: (targetPoint - 1) * tileSize
+!
+
+drawTile: aSymbol on: aContext at: aPoint
+	self drawTile: aSymbol offset: 0@0 on: aContext at: aPoint
+! !
+
+!TronSkin methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	skinMap := Dictionary new
+		at: #background put: 0@0;
+		at: #backgroundBottomRight put: 49@34;
+		at: #backgroundTile put: 0@35;
+		at: #headNorth put: 1@35;
+		at: #headEast put: 2@35;
+		at: #headSouth put: 3@35;
+		at: #headWest put: 4@35;
+		at: #bodyNorth put: 5@35;
+		at: #bodyEast put: 6@35;
+		at: #bodySouth put: 7@35;
+		at: #bodyWest put: 8@35;
+		at: #bodySouthToEast put: 9@35;
+		at: #bodyWestToNorth put: 9@35;
+		at: #bodyNorthToEast put: 10@35;
+		at: #bodyWestToSouth put: 10@35;
+		at: #bodyNorthToWest put: 11@35;
+		at: #bodyEastToSouth put: 11@35;
+		at: #bodySouthToWest put: 12@35;
+		at: #bodyEastToNorth put: 12@35;
+		yourself.
+	maskOffset := 12 @ 0.
+	skinImage := document createElement: 'img'
+! !
+
+!TronSkin methodsFor: 'loading'!
+
+load: url andDo: aBlock
+	skinImage onload: [
+		tileSize := skinImage width / 50.
+		aBlock value ].
+	skinImage src: url.
+! !
+
+!Point methodsFor: '*Serpentron'!
+
+rotate90ccw
+	^ self y @ self x negated
+!
+
+rotate90cw
+	^ self y negated @ self x
+! !
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testing.js	Wed Feb 17 23:55:43 2016 +0300
@@ -0,0 +1,9 @@
+define([
+    './deploy',
+    'amber_core/SUnit',
+    // --- packages used only during automated testing begin here ---
+    'amber-serpentron/Serpentron-Tests'
+    // --- packages used only during automated testing end here ---
+], function (amber) {
+    return amber;
+});