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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Wed Feb 17 23:55:43 2016 +0300
     1.3 @@ -0,0 +1,10 @@
     1.4 +syntax: glob
     1.5 +
     1.6 +node_modules
     1.7 +bower_components
     1.8 +
     1.9 +src/*.js
    1.10 +test_runner.js
    1.11 +config.js
    1.12 +the.js
    1.13 +*~
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Gruntfile.js	Wed Feb 17 23:55:43 2016 +0300
     2.3 @@ -0,0 +1,116 @@
     2.4 +'use strict';
     2.5 +
     2.6 +module.exports = function (grunt) {
     2.7 +    var path = require('path'),
     2.8 +        helpers = require('amber-dev').helpers;
     2.9 +
    2.10 +    // These plugins provide necessary tasks.
    2.11 +    grunt.loadNpmTasks('grunt-contrib-clean');
    2.12 +    grunt.loadNpmTasks('grunt-contrib-requirejs');
    2.13 +    grunt.loadNpmTasks('grunt-execute');
    2.14 +    grunt.loadNpmTasks('amber-dev');
    2.15 +
    2.16 +    // Default task.
    2.17 +    grunt.registerTask('default', ['amdconfig:app', 'amberc:all']);
    2.18 +    grunt.registerTask('test', ['amdconfig:app', 'requirejs:test_runner', 'execute:test_runner', 'clean:test_runner']);
    2.19 +    grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
    2.20 +    grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
    2.21 +
    2.22 +    // Project configuration.
    2.23 +    grunt.initConfig({
    2.24 +        // Metadata.
    2.25 +        // pkg: grunt.file.readJSON(''),
    2.26 +        banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
    2.27 +        '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
    2.28 +        '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
    2.29 +        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
    2.30 +        ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
    2.31 +        // task configuration
    2.32 +        amberc: {
    2.33 +            options: {
    2.34 +                amber_dir: path.join(__dirname, "bower_components", "amber"),
    2.35 +                configFile: "config.js"
    2.36 +            },
    2.37 +            all: {
    2.38 +                src: [
    2.39 +                    'src/Serpentron.st', // list all sources in dependency order
    2.40 +                    'src/Serpentron-Tests.st' // list all tests in dependency order
    2.41 +                ],
    2.42 +                amd_namespace: 'amber-serpentron',
    2.43 +                libraries: ['amber_core/SUnit', 'silk/Silk']
    2.44 +            }
    2.45 +        },
    2.46 +
    2.47 +        amdconfig: {app: {dest: 'config.js'}},
    2.48 +
    2.49 +        requirejs: {
    2.50 +            options: {
    2.51 +                useStrict: true
    2.52 +            },
    2.53 +            deploy: {
    2.54 +                options: {
    2.55 +                    mainConfigFile: "config.js",
    2.56 +                    rawText: {
    2.57 +                        "amber/compatibility": "/*stub*/",
    2.58 +                        "amber/Platform": "/*stub*/",
    2.59 +                        "app": 'define(["deploy"],function(x){return x});'
    2.60 +                    },
    2.61 +                    pragmas: {
    2.62 +                        excludeIdeData: true,
    2.63 +                        excludeDebugContexts: true
    2.64 +                    },
    2.65 +                    include: ['config', 'config-browser', 'node_modules/requirejs/require', 'app'],
    2.66 +                    optimize: "uglify2",
    2.67 +                    out: "the.js"
    2.68 +                }
    2.69 +            },
    2.70 +            devel: {
    2.71 +                options: {
    2.72 +                    mainConfigFile: "config.js",
    2.73 +                    rawText: {
    2.74 +                        "amber/compatibility": "/*stub*/",
    2.75 +                        "amber/Platform": "/*stub*/",
    2.76 +                        "app": 'define(["devel"],function(x){return x});'
    2.77 +                    },
    2.78 +                    include: ['config', 'config-browser', 'node_modules/requirejs/require', 'app'],
    2.79 +                    exclude: ['devel'],
    2.80 +                    out: "the.js"
    2.81 +                }
    2.82 +            },
    2.83 +            test_runner: {
    2.84 +                options: {
    2.85 +                    mainConfigFile: "config.js",
    2.86 +                    rawText: {
    2.87 +                        "app": "(" + function () {
    2.88 +                            define(["testing", "amber_devkit/NodeTestRunner"], function (amber) {
    2.89 +                                amber.initialize().then(function () {
    2.90 +                                    amber.globals.NodeTestRunner._main();
    2.91 +                                });
    2.92 +                            });
    2.93 +                        } + "());"
    2.94 +                    },
    2.95 +                    paths: {"amber_devkit": helpers.libPath},
    2.96 +                    pragmas: {
    2.97 +                        excludeIdeData: true
    2.98 +                    },
    2.99 +                    include: ['config-node', 'app'],
   2.100 +                    insertRequire: ['app'],
   2.101 +                    optimize: "none",
   2.102 +                    wrap: helpers.nodeWrapperWithShebang,
   2.103 +                    out: "test_runner.js"
   2.104 +                }
   2.105 +            }
   2.106 +        },
   2.107 +
   2.108 +        execute: {
   2.109 +            test_runner: {
   2.110 +                src: ['test_runner.js']
   2.111 +            }
   2.112 +        },
   2.113 +
   2.114 +        clean: {
   2.115 +            test_runner: ['test_runner.js']
   2.116 +        }
   2.117 +    });
   2.118 +
   2.119 +};
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/LICENSE-GPL-3.0	Wed Feb 17 23:55:43 2016 +0300
     3.3 @@ -0,0 +1,674 @@
     3.4 +                    GNU GENERAL PUBLIC LICENSE
     3.5 +                       Version 3, 29 June 2007
     3.6 +
     3.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     3.8 + Everyone is permitted to copy and distribute verbatim copies
     3.9 + of this license document, but changing it is not allowed.
    3.10 +
    3.11 +                            Preamble
    3.12 +
    3.13 +  The GNU General Public License is a free, copyleft license for
    3.14 +software and other kinds of works.
    3.15 +
    3.16 +  The licenses for most software and other practical works are designed
    3.17 +to take away your freedom to share and change the works.  By contrast,
    3.18 +the GNU General Public License is intended to guarantee your freedom to
    3.19 +share and change all versions of a program--to make sure it remains free
    3.20 +software for all its users.  We, the Free Software Foundation, use the
    3.21 +GNU General Public License for most of our software; it applies also to
    3.22 +any other work released this way by its authors.  You can apply it to
    3.23 +your programs, too.
    3.24 +
    3.25 +  When we speak of free software, we are referring to freedom, not
    3.26 +price.  Our General Public Licenses are designed to make sure that you
    3.27 +have the freedom to distribute copies of free software (and charge for
    3.28 +them if you wish), that you receive source code or can get it if you
    3.29 +want it, that you can change the software or use pieces of it in new
    3.30 +free programs, and that you know you can do these things.
    3.31 +
    3.32 +  To protect your rights, we need to prevent others from denying you
    3.33 +these rights or asking you to surrender the rights.  Therefore, you have
    3.34 +certain responsibilities if you distribute copies of the software, or if
    3.35 +you modify it: responsibilities to respect the freedom of others.
    3.36 +
    3.37 +  For example, if you distribute copies of such a program, whether
    3.38 +gratis or for a fee, you must pass on to the recipients the same
    3.39 +freedoms that you received.  You must make sure that they, too, receive
    3.40 +or can get the source code.  And you must show them these terms so they
    3.41 +know their rights.
    3.42 +
    3.43 +  Developers that use the GNU GPL protect your rights with two steps:
    3.44 +(1) assert copyright on the software, and (2) offer you this License
    3.45 +giving you legal permission to copy, distribute and/or modify it.
    3.46 +
    3.47 +  For the developers' and authors' protection, the GPL clearly explains
    3.48 +that there is no warranty for this free software.  For both users' and
    3.49 +authors' sake, the GPL requires that modified versions be marked as
    3.50 +changed, so that their problems will not be attributed erroneously to
    3.51 +authors of previous versions.
    3.52 +
    3.53 +  Some devices are designed to deny users access to install or run
    3.54 +modified versions of the software inside them, although the manufacturer
    3.55 +can do so.  This is fundamentally incompatible with the aim of
    3.56 +protecting users' freedom to change the software.  The systematic
    3.57 +pattern of such abuse occurs in the area of products for individuals to
    3.58 +use, which is precisely where it is most unacceptable.  Therefore, we
    3.59 +have designed this version of the GPL to prohibit the practice for those
    3.60 +products.  If such problems arise substantially in other domains, we
    3.61 +stand ready to extend this provision to those domains in future versions
    3.62 +of the GPL, as needed to protect the freedom of users.
    3.63 +
    3.64 +  Finally, every program is threatened constantly by software patents.
    3.65 +States should not allow patents to restrict development and use of
    3.66 +software on general-purpose computers, but in those that do, we wish to
    3.67 +avoid the special danger that patents applied to a free program could
    3.68 +make it effectively proprietary.  To prevent this, the GPL assures that
    3.69 +patents cannot be used to render the program non-free.
    3.70 +
    3.71 +  The precise terms and conditions for copying, distribution and
    3.72 +modification follow.
    3.73 +
    3.74 +                       TERMS AND CONDITIONS
    3.75 +
    3.76 +  0. Definitions.
    3.77 +
    3.78 +  "This License" refers to version 3 of the GNU General Public License.
    3.79 +
    3.80 +  "Copyright" also means copyright-like laws that apply to other kinds of
    3.81 +works, such as semiconductor masks.
    3.82 +
    3.83 +  "The Program" refers to any copyrightable work licensed under this
    3.84 +License.  Each licensee is addressed as "you".  "Licensees" and
    3.85 +"recipients" may be individuals or organizations.
    3.86 +
    3.87 +  To "modify" a work means to copy from or adapt all or part of the work
    3.88 +in a fashion requiring copyright permission, other than the making of an
    3.89 +exact copy.  The resulting work is called a "modified version" of the
    3.90 +earlier work or a work "based on" the earlier work.
    3.91 +
    3.92 +  A "covered work" means either the unmodified Program or a work based
    3.93 +on the Program.
    3.94 +
    3.95 +  To "propagate" a work means to do anything with it that, without
    3.96 +permission, would make you directly or secondarily liable for
    3.97 +infringement under applicable copyright law, except executing it on a
    3.98 +computer or modifying a private copy.  Propagation includes copying,
    3.99 +distribution (with or without modification), making available to the
   3.100 +public, and in some countries other activities as well.
   3.101 +
   3.102 +  To "convey" a work means any kind of propagation that enables other
   3.103 +parties to make or receive copies.  Mere interaction with a user through
   3.104 +a computer network, with no transfer of a copy, is not conveying.
   3.105 +
   3.106 +  An interactive user interface displays "Appropriate Legal Notices"
   3.107 +to the extent that it includes a convenient and prominently visible
   3.108 +feature that (1) displays an appropriate copyright notice, and (2)
   3.109 +tells the user that there is no warranty for the work (except to the
   3.110 +extent that warranties are provided), that licensees may convey the
   3.111 +work under this License, and how to view a copy of this License.  If
   3.112 +the interface presents a list of user commands or options, such as a
   3.113 +menu, a prominent item in the list meets this criterion.
   3.114 +
   3.115 +  1. Source Code.
   3.116 +
   3.117 +  The "source code" for a work means the preferred form of the work
   3.118 +for making modifications to it.  "Object code" means any non-source
   3.119 +form of a work.
   3.120 +
   3.121 +  A "Standard Interface" means an interface that either is an official
   3.122 +standard defined by a recognized standards body, or, in the case of
   3.123 +interfaces specified for a particular programming language, one that
   3.124 +is widely used among developers working in that language.
   3.125 +
   3.126 +  The "System Libraries" of an executable work include anything, other
   3.127 +than the work as a whole, that (a) is included in the normal form of
   3.128 +packaging a Major Component, but which is not part of that Major
   3.129 +Component, and (b) serves only to enable use of the work with that
   3.130 +Major Component, or to implement a Standard Interface for which an
   3.131 +implementation is available to the public in source code form.  A
   3.132 +"Major Component", in this context, means a major essential component
   3.133 +(kernel, window system, and so on) of the specific operating system
   3.134 +(if any) on which the executable work runs, or a compiler used to
   3.135 +produce the work, or an object code interpreter used to run it.
   3.136 +
   3.137 +  The "Corresponding Source" for a work in object code form means all
   3.138 +the source code needed to generate, install, and (for an executable
   3.139 +work) run the object code and to modify the work, including scripts to
   3.140 +control those activities.  However, it does not include the work's
   3.141 +System Libraries, or general-purpose tools or generally available free
   3.142 +programs which are used unmodified in performing those activities but
   3.143 +which are not part of the work.  For example, Corresponding Source
   3.144 +includes interface definition files associated with source files for
   3.145 +the work, and the source code for shared libraries and dynamically
   3.146 +linked subprograms that the work is specifically designed to require,
   3.147 +such as by intimate data communication or control flow between those
   3.148 +subprograms and other parts of the work.
   3.149 +
   3.150 +  The Corresponding Source need not include anything that users
   3.151 +can regenerate automatically from other parts of the Corresponding
   3.152 +Source.
   3.153 +
   3.154 +  The Corresponding Source for a work in source code form is that
   3.155 +same work.
   3.156 +
   3.157 +  2. Basic Permissions.
   3.158 +
   3.159 +  All rights granted under this License are granted for the term of
   3.160 +copyright on the Program, and are irrevocable provided the stated
   3.161 +conditions are met.  This License explicitly affirms your unlimited
   3.162 +permission to run the unmodified Program.  The output from running a
   3.163 +covered work is covered by this License only if the output, given its
   3.164 +content, constitutes a covered work.  This License acknowledges your
   3.165 +rights of fair use or other equivalent, as provided by copyright law.
   3.166 +
   3.167 +  You may make, run and propagate covered works that you do not
   3.168 +convey, without conditions so long as your license otherwise remains
   3.169 +in force.  You may convey covered works to others for the sole purpose
   3.170 +of having them make modifications exclusively for you, or provide you
   3.171 +with facilities for running those works, provided that you comply with
   3.172 +the terms of this License in conveying all material for which you do
   3.173 +not control copyright.  Those thus making or running the covered works
   3.174 +for you must do so exclusively on your behalf, under your direction
   3.175 +and control, on terms that prohibit them from making any copies of
   3.176 +your copyrighted material outside their relationship with you.
   3.177 +
   3.178 +  Conveying under any other circumstances is permitted solely under
   3.179 +the conditions stated below.  Sublicensing is not allowed; section 10
   3.180 +makes it unnecessary.
   3.181 +
   3.182 +  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
   3.183 +
   3.184 +  No covered work shall be deemed part of an effective technological
   3.185 +measure under any applicable law fulfilling obligations under article
   3.186 +11 of the WIPO copyright treaty adopted on 20 December 1996, or
   3.187 +similar laws prohibiting or restricting circumvention of such
   3.188 +measures.
   3.189 +
   3.190 +  When you convey a covered work, you waive any legal power to forbid
   3.191 +circumvention of technological measures to the extent such circumvention
   3.192 +is effected by exercising rights under this License with respect to
   3.193 +the covered work, and you disclaim any intention to limit operation or
   3.194 +modification of the work as a means of enforcing, against the work's
   3.195 +users, your or third parties' legal rights to forbid circumvention of
   3.196 +technological measures.
   3.197 +
   3.198 +  4. Conveying Verbatim Copies.
   3.199 +
   3.200 +  You may convey verbatim copies of the Program's source code as you
   3.201 +receive it, in any medium, provided that you conspicuously and
   3.202 +appropriately publish on each copy an appropriate copyright notice;
   3.203 +keep intact all notices stating that this License and any
   3.204 +non-permissive terms added in accord with section 7 apply to the code;
   3.205 +keep intact all notices of the absence of any warranty; and give all
   3.206 +recipients a copy of this License along with the Program.
   3.207 +
   3.208 +  You may charge any price or no price for each copy that you convey,
   3.209 +and you may offer support or warranty protection for a fee.
   3.210 +
   3.211 +  5. Conveying Modified Source Versions.
   3.212 +
   3.213 +  You may convey a work based on the Program, or the modifications to
   3.214 +produce it from the Program, in the form of source code under the
   3.215 +terms of section 4, provided that you also meet all of these conditions:
   3.216 +
   3.217 +    a) The work must carry prominent notices stating that you modified
   3.218 +    it, and giving a relevant date.
   3.219 +
   3.220 +    b) The work must carry prominent notices stating that it is
   3.221 +    released under this License and any conditions added under section
   3.222 +    7.  This requirement modifies the requirement in section 4 to
   3.223 +    "keep intact all notices".
   3.224 +
   3.225 +    c) You must license the entire work, as a whole, under this
   3.226 +    License to anyone who comes into possession of a copy.  This
   3.227 +    License will therefore apply, along with any applicable section 7
   3.228 +    additional terms, to the whole of the work, and all its parts,
   3.229 +    regardless of how they are packaged.  This License gives no
   3.230 +    permission to license the work in any other way, but it does not
   3.231 +    invalidate such permission if you have separately received it.
   3.232 +
   3.233 +    d) If the work has interactive user interfaces, each must display
   3.234 +    Appropriate Legal Notices; however, if the Program has interactive
   3.235 +    interfaces that do not display Appropriate Legal Notices, your
   3.236 +    work need not make them do so.
   3.237 +
   3.238 +  A compilation of a covered work with other separate and independent
   3.239 +works, which are not by their nature extensions of the covered work,
   3.240 +and which are not combined with it such as to form a larger program,
   3.241 +in or on a volume of a storage or distribution medium, is called an
   3.242 +"aggregate" if the compilation and its resulting copyright are not
   3.243 +used to limit the access or legal rights of the compilation's users
   3.244 +beyond what the individual works permit.  Inclusion of a covered work
   3.245 +in an aggregate does not cause this License to apply to the other
   3.246 +parts of the aggregate.
   3.247 +
   3.248 +  6. Conveying Non-Source Forms.
   3.249 +
   3.250 +  You may convey a covered work in object code form under the terms
   3.251 +of sections 4 and 5, provided that you also convey the
   3.252 +machine-readable Corresponding Source under the terms of this License,
   3.253 +in one of these ways:
   3.254 +
   3.255 +    a) Convey the object code in, or embodied in, a physical product
   3.256 +    (including a physical distribution medium), accompanied by the
   3.257 +    Corresponding Source fixed on a durable physical medium
   3.258 +    customarily used for software interchange.
   3.259 +
   3.260 +    b) Convey the object code in, or embodied in, a physical product
   3.261 +    (including a physical distribution medium), accompanied by a
   3.262 +    written offer, valid for at least three years and valid for as
   3.263 +    long as you offer spare parts or customer support for that product
   3.264 +    model, to give anyone who possesses the object code either (1) a
   3.265 +    copy of the Corresponding Source for all the software in the
   3.266 +    product that is covered by this License, on a durable physical
   3.267 +    medium customarily used for software interchange, for a price no
   3.268 +    more than your reasonable cost of physically performing this
   3.269 +    conveying of source, or (2) access to copy the
   3.270 +    Corresponding Source from a network server at no charge.
   3.271 +
   3.272 +    c) Convey individual copies of the object code with a copy of the
   3.273 +    written offer to provide the Corresponding Source.  This
   3.274 +    alternative is allowed only occasionally and noncommercially, and
   3.275 +    only if you received the object code with such an offer, in accord
   3.276 +    with subsection 6b.
   3.277 +
   3.278 +    d) Convey the object code by offering access from a designated
   3.279 +    place (gratis or for a charge), and offer equivalent access to the
   3.280 +    Corresponding Source in the same way through the same place at no
   3.281 +    further charge.  You need not require recipients to copy the
   3.282 +    Corresponding Source along with the object code.  If the place to
   3.283 +    copy the object code is a network server, the Corresponding Source
   3.284 +    may be on a different server (operated by you or a third party)
   3.285 +    that supports equivalent copying facilities, provided you maintain
   3.286 +    clear directions next to the object code saying where to find the
   3.287 +    Corresponding Source.  Regardless of what server hosts the
   3.288 +    Corresponding Source, you remain obligated to ensure that it is
   3.289 +    available for as long as needed to satisfy these requirements.
   3.290 +
   3.291 +    e) Convey the object code using peer-to-peer transmission, provided
   3.292 +    you inform other peers where the object code and Corresponding
   3.293 +    Source of the work are being offered to the general public at no
   3.294 +    charge under subsection 6d.
   3.295 +
   3.296 +  A separable portion of the object code, whose source code is excluded
   3.297 +from the Corresponding Source as a System Library, need not be
   3.298 +included in conveying the object code work.
   3.299 +
   3.300 +  A "User Product" is either (1) a "consumer product", which means any
   3.301 +tangible personal property which is normally used for personal, family,
   3.302 +or household purposes, or (2) anything designed or sold for incorporation
   3.303 +into a dwelling.  In determining whether a product is a consumer product,
   3.304 +doubtful cases shall be resolved in favor of coverage.  For a particular
   3.305 +product received by a particular user, "normally used" refers to a
   3.306 +typical or common use of that class of product, regardless of the status
   3.307 +of the particular user or of the way in which the particular user
   3.308 +actually uses, or expects or is expected to use, the product.  A product
   3.309 +is a consumer product regardless of whether the product has substantial
   3.310 +commercial, industrial or non-consumer uses, unless such uses represent
   3.311 +the only significant mode of use of the product.
   3.312 +
   3.313 +  "Installation Information" for a User Product means any methods,
   3.314 +procedures, authorization keys, or other information required to install
   3.315 +and execute modified versions of a covered work in that User Product from
   3.316 +a modified version of its Corresponding Source.  The information must
   3.317 +suffice to ensure that the continued functioning of the modified object
   3.318 +code is in no case prevented or interfered with solely because
   3.319 +modification has been made.
   3.320 +
   3.321 +  If you convey an object code work under this section in, or with, or
   3.322 +specifically for use in, a User Product, and the conveying occurs as
   3.323 +part of a transaction in which the right of possession and use of the
   3.324 +User Product is transferred to the recipient in perpetuity or for a
   3.325 +fixed term (regardless of how the transaction is characterized), the
   3.326 +Corresponding Source conveyed under this section must be accompanied
   3.327 +by the Installation Information.  But this requirement does not apply
   3.328 +if neither you nor any third party retains the ability to install
   3.329 +modified object code on the User Product (for example, the work has
   3.330 +been installed in ROM).
   3.331 +
   3.332 +  The requirement to provide Installation Information does not include a
   3.333 +requirement to continue to provide support service, warranty, or updates
   3.334 +for a work that has been modified or installed by the recipient, or for
   3.335 +the User Product in which it has been modified or installed.  Access to a
   3.336 +network may be denied when the modification itself materially and
   3.337 +adversely affects the operation of the network or violates the rules and
   3.338 +protocols for communication across the network.
   3.339 +
   3.340 +  Corresponding Source conveyed, and Installation Information provided,
   3.341 +in accord with this section must be in a format that is publicly
   3.342 +documented (and with an implementation available to the public in
   3.343 +source code form), and must require no special password or key for
   3.344 +unpacking, reading or copying.
   3.345 +
   3.346 +  7. Additional Terms.
   3.347 +
   3.348 +  "Additional permissions" are terms that supplement the terms of this
   3.349 +License by making exceptions from one or more of its conditions.
   3.350 +Additional permissions that are applicable to the entire Program shall
   3.351 +be treated as though they were included in this License, to the extent
   3.352 +that they are valid under applicable law.  If additional permissions
   3.353 +apply only to part of the Program, that part may be used separately
   3.354 +under those permissions, but the entire Program remains governed by
   3.355 +this License without regard to the additional permissions.
   3.356 +
   3.357 +  When you convey a copy of a covered work, you may at your option
   3.358 +remove any additional permissions from that copy, or from any part of
   3.359 +it.  (Additional permissions may be written to require their own
   3.360 +removal in certain cases when you modify the work.)  You may place
   3.361 +additional permissions on material, added by you to a covered work,
   3.362 +for which you have or can give appropriate copyright permission.
   3.363 +
   3.364 +  Notwithstanding any other provision of this License, for material you
   3.365 +add to a covered work, you may (if authorized by the copyright holders of
   3.366 +that material) supplement the terms of this License with terms:
   3.367 +
   3.368 +    a) Disclaiming warranty or limiting liability differently from the
   3.369 +    terms of sections 15 and 16 of this License; or
   3.370 +
   3.371 +    b) Requiring preservation of specified reasonable legal notices or
   3.372 +    author attributions in that material or in the Appropriate Legal
   3.373 +    Notices displayed by works containing it; or
   3.374 +
   3.375 +    c) Prohibiting misrepresentation of the origin of that material, or
   3.376 +    requiring that modified versions of such material be marked in
   3.377 +    reasonable ways as different from the original version; or
   3.378 +
   3.379 +    d) Limiting the use for publicity purposes of names of licensors or
   3.380 +    authors of the material; or
   3.381 +
   3.382 +    e) Declining to grant rights under trademark law for use of some
   3.383 +    trade names, trademarks, or service marks; or
   3.384 +
   3.385 +    f) Requiring indemnification of licensors and authors of that
   3.386 +    material by anyone who conveys the material (or modified versions of
   3.387 +    it) with contractual assumptions of liability to the recipient, for
   3.388 +    any liability that these contractual assumptions directly impose on
   3.389 +    those licensors and authors.
   3.390 +
   3.391 +  All other non-permissive additional terms are considered "further
   3.392 +restrictions" within the meaning of section 10.  If the Program as you
   3.393 +received it, or any part of it, contains a notice stating that it is
   3.394 +governed by this License along with a term that is a further
   3.395 +restriction, you may remove that term.  If a license document contains
   3.396 +a further restriction but permits relicensing or conveying under this
   3.397 +License, you may add to a covered work material governed by the terms
   3.398 +of that license document, provided that the further restriction does
   3.399 +not survive such relicensing or conveying.
   3.400 +
   3.401 +  If you add terms to a covered work in accord with this section, you
   3.402 +must place, in the relevant source files, a statement of the
   3.403 +additional terms that apply to those files, or a notice indicating
   3.404 +where to find the applicable terms.
   3.405 +
   3.406 +  Additional terms, permissive or non-permissive, may be stated in the
   3.407 +form of a separately written license, or stated as exceptions;
   3.408 +the above requirements apply either way.
   3.409 +
   3.410 +  8. Termination.
   3.411 +
   3.412 +  You may not propagate or modify a covered work except as expressly
   3.413 +provided under this License.  Any attempt otherwise to propagate or
   3.414 +modify it is void, and will automatically terminate your rights under
   3.415 +this License (including any patent licenses granted under the third
   3.416 +paragraph of section 11).
   3.417 +
   3.418 +  However, if you cease all violation of this License, then your
   3.419 +license from a particular copyright holder is reinstated (a)
   3.420 +provisionally, unless and until the copyright holder explicitly and
   3.421 +finally terminates your license, and (b) permanently, if the copyright
   3.422 +holder fails to notify you of the violation by some reasonable means
   3.423 +prior to 60 days after the cessation.
   3.424 +
   3.425 +  Moreover, your license from a particular copyright holder is
   3.426 +reinstated permanently if the copyright holder notifies you of the
   3.427 +violation by some reasonable means, this is the first time you have
   3.428 +received notice of violation of this License (for any work) from that
   3.429 +copyright holder, and you cure the violation prior to 30 days after
   3.430 +your receipt of the notice.
   3.431 +
   3.432 +  Termination of your rights under this section does not terminate the
   3.433 +licenses of parties who have received copies or rights from you under
   3.434 +this License.  If your rights have been terminated and not permanently
   3.435 +reinstated, you do not qualify to receive new licenses for the same
   3.436 +material under section 10.
   3.437 +
   3.438 +  9. Acceptance Not Required for Having Copies.
   3.439 +
   3.440 +  You are not required to accept this License in order to receive or
   3.441 +run a copy of the Program.  Ancillary propagation of a covered work
   3.442 +occurring solely as a consequence of using peer-to-peer transmission
   3.443 +to receive a copy likewise does not require acceptance.  However,
   3.444 +nothing other than this License grants you permission to propagate or
   3.445 +modify any covered work.  These actions infringe copyright if you do
   3.446 +not accept this License.  Therefore, by modifying or propagating a
   3.447 +covered work, you indicate your acceptance of this License to do so.
   3.448 +
   3.449 +  10. Automatic Licensing of Downstream Recipients.
   3.450 +
   3.451 +  Each time you convey a covered work, the recipient automatically
   3.452 +receives a license from the original licensors, to run, modify and
   3.453 +propagate that work, subject to this License.  You are not responsible
   3.454 +for enforcing compliance by third parties with this License.
   3.455 +
   3.456 +  An "entity transaction" is a transaction transferring control of an
   3.457 +organization, or substantially all assets of one, or subdividing an
   3.458 +organization, or merging organizations.  If propagation of a covered
   3.459 +work results from an entity transaction, each party to that
   3.460 +transaction who receives a copy of the work also receives whatever
   3.461 +licenses to the work the party's predecessor in interest had or could
   3.462 +give under the previous paragraph, plus a right to possession of the
   3.463 +Corresponding Source of the work from the predecessor in interest, if
   3.464 +the predecessor has it or can get it with reasonable efforts.
   3.465 +
   3.466 +  You may not impose any further restrictions on the exercise of the
   3.467 +rights granted or affirmed under this License.  For example, you may
   3.468 +not impose a license fee, royalty, or other charge for exercise of
   3.469 +rights granted under this License, and you may not initiate litigation
   3.470 +(including a cross-claim or counterclaim in a lawsuit) alleging that
   3.471 +any patent claim is infringed by making, using, selling, offering for
   3.472 +sale, or importing the Program or any portion of it.
   3.473 +
   3.474 +  11. Patents.
   3.475 +
   3.476 +  A "contributor" is a copyright holder who authorizes use under this
   3.477 +License of the Program or a work on which the Program is based.  The
   3.478 +work thus licensed is called the contributor's "contributor version".
   3.479 +
   3.480 +  A contributor's "essential patent claims" are all patent claims
   3.481 +owned or controlled by the contributor, whether already acquired or
   3.482 +hereafter acquired, that would be infringed by some manner, permitted
   3.483 +by this License, of making, using, or selling its contributor version,
   3.484 +but do not include claims that would be infringed only as a
   3.485 +consequence of further modification of the contributor version.  For
   3.486 +purposes of this definition, "control" includes the right to grant
   3.487 +patent sublicenses in a manner consistent with the requirements of
   3.488 +this License.
   3.489 +
   3.490 +  Each contributor grants you a non-exclusive, worldwide, royalty-free
   3.491 +patent license under the contributor's essential patent claims, to
   3.492 +make, use, sell, offer for sale, import and otherwise run, modify and
   3.493 +propagate the contents of its contributor version.
   3.494 +
   3.495 +  In the following three paragraphs, a "patent license" is any express
   3.496 +agreement or commitment, however denominated, not to enforce a patent
   3.497 +(such as an express permission to practice a patent or covenant not to
   3.498 +sue for patent infringement).  To "grant" such a patent license to a
   3.499 +party means to make such an agreement or commitment not to enforce a
   3.500 +patent against the party.
   3.501 +
   3.502 +  If you convey a covered work, knowingly relying on a patent license,
   3.503 +and the Corresponding Source of the work is not available for anyone
   3.504 +to copy, free of charge and under the terms of this License, through a
   3.505 +publicly available network server or other readily accessible means,
   3.506 +then you must either (1) cause the Corresponding Source to be so
   3.507 +available, or (2) arrange to deprive yourself of the benefit of the
   3.508 +patent license for this particular work, or (3) arrange, in a manner
   3.509 +consistent with the requirements of this License, to extend the patent
   3.510 +license to downstream recipients.  "Knowingly relying" means you have
   3.511 +actual knowledge that, but for the patent license, your conveying the
   3.512 +covered work in a country, or your recipient's use of the covered work
   3.513 +in a country, would infringe one or more identifiable patents in that
   3.514 +country that you have reason to believe are valid.
   3.515 +
   3.516 +  If, pursuant to or in connection with a single transaction or
   3.517 +arrangement, you convey, or propagate by procuring conveyance of, a
   3.518 +covered work, and grant a patent license to some of the parties
   3.519 +receiving the covered work authorizing them to use, propagate, modify
   3.520 +or convey a specific copy of the covered work, then the patent license
   3.521 +you grant is automatically extended to all recipients of the covered
   3.522 +work and works based on it.
   3.523 +
   3.524 +  A patent license is "discriminatory" if it does not include within
   3.525 +the scope of its coverage, prohibits the exercise of, or is
   3.526 +conditioned on the non-exercise of one or more of the rights that are
   3.527 +specifically granted under this License.  You may not convey a covered
   3.528 +work if you are a party to an arrangement with a third party that is
   3.529 +in the business of distributing software, under which you make payment
   3.530 +to the third party based on the extent of your activity of conveying
   3.531 +the work, and under which the third party grants, to any of the
   3.532 +parties who would receive the covered work from you, a discriminatory
   3.533 +patent license (a) in connection with copies of the covered work
   3.534 +conveyed by you (or copies made from those copies), or (b) primarily
   3.535 +for and in connection with specific products or compilations that
   3.536 +contain the covered work, unless you entered into that arrangement,
   3.537 +or that patent license was granted, prior to 28 March 2007.
   3.538 +
   3.539 +  Nothing in this License shall be construed as excluding or limiting
   3.540 +any implied license or other defenses to infringement that may
   3.541 +otherwise be available to you under applicable patent law.
   3.542 +
   3.543 +  12. No Surrender of Others' Freedom.
   3.544 +
   3.545 +  If conditions are imposed on you (whether by court order, agreement or
   3.546 +otherwise) that contradict the conditions of this License, they do not
   3.547 +excuse you from the conditions of this License.  If you cannot convey a
   3.548 +covered work so as to satisfy simultaneously your obligations under this
   3.549 +License and any other pertinent obligations, then as a consequence you may
   3.550 +not convey it at all.  For example, if you agree to terms that obligate you
   3.551 +to collect a royalty for further conveying from those to whom you convey
   3.552 +the Program, the only way you could satisfy both those terms and this
   3.553 +License would be to refrain entirely from conveying the Program.
   3.554 +
   3.555 +  13. Use with the GNU Affero General Public License.
   3.556 +
   3.557 +  Notwithstanding any other provision of this License, you have
   3.558 +permission to link or combine any covered work with a work licensed
   3.559 +under version 3 of the GNU Affero General Public License into a single
   3.560 +combined work, and to convey the resulting work.  The terms of this
   3.561 +License will continue to apply to the part which is the covered work,
   3.562 +but the special requirements of the GNU Affero General Public License,
   3.563 +section 13, concerning interaction through a network will apply to the
   3.564 +combination as such.
   3.565 +
   3.566 +  14. Revised Versions of this License.
   3.567 +
   3.568 +  The Free Software Foundation may publish revised and/or new versions of
   3.569 +the GNU General Public License from time to time.  Such new versions will
   3.570 +be similar in spirit to the present version, but may differ in detail to
   3.571 +address new problems or concerns.
   3.572 +
   3.573 +  Each version is given a distinguishing version number.  If the
   3.574 +Program specifies that a certain numbered version of the GNU General
   3.575 +Public License "or any later version" applies to it, you have the
   3.576 +option of following the terms and conditions either of that numbered
   3.577 +version or of any later version published by the Free Software
   3.578 +Foundation.  If the Program does not specify a version number of the
   3.579 +GNU General Public License, you may choose any version ever published
   3.580 +by the Free Software Foundation.
   3.581 +
   3.582 +  If the Program specifies that a proxy can decide which future
   3.583 +versions of the GNU General Public License can be used, that proxy's
   3.584 +public statement of acceptance of a version permanently authorizes you
   3.585 +to choose that version for the Program.
   3.586 +
   3.587 +  Later license versions may give you additional or different
   3.588 +permissions.  However, no additional obligations are imposed on any
   3.589 +author or copyright holder as a result of your choosing to follow a
   3.590 +later version.
   3.591 +
   3.592 +  15. Disclaimer of Warranty.
   3.593 +
   3.594 +  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
   3.595 +APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
   3.596 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
   3.597 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
   3.598 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   3.599 +PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
   3.600 +IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
   3.601 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   3.602 +
   3.603 +  16. Limitation of Liability.
   3.604 +
   3.605 +  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
   3.606 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
   3.607 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
   3.608 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
   3.609 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
   3.610 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
   3.611 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
   3.612 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
   3.613 +SUCH DAMAGES.
   3.614 +
   3.615 +  17. Interpretation of Sections 15 and 16.
   3.616 +
   3.617 +  If the disclaimer of warranty and limitation of liability provided
   3.618 +above cannot be given local legal effect according to their terms,
   3.619 +reviewing courts shall apply local law that most closely approximates
   3.620 +an absolute waiver of all civil liability in connection with the
   3.621 +Program, unless a warranty or assumption of liability accompanies a
   3.622 +copy of the Program in return for a fee.
   3.623 +
   3.624 +                     END OF TERMS AND CONDITIONS
   3.625 +
   3.626 +            How to Apply These Terms to Your New Programs
   3.627 +
   3.628 +  If you develop a new program, and you want it to be of the greatest
   3.629 +possible use to the public, the best way to achieve this is to make it
   3.630 +free software which everyone can redistribute and change under these terms.
   3.631 +
   3.632 +  To do so, attach the following notices to the program.  It is safest
   3.633 +to attach them to the start of each source file to most effectively
   3.634 +state the exclusion of warranty; and each file should have at least
   3.635 +the "copyright" line and a pointer to where the full notice is found.
   3.636 +
   3.637 +    <one line to give the program's name and a brief idea of what it does.>
   3.638 +    Copyright (C) <year>  <name of author>
   3.639 +
   3.640 +    This program is free software: you can redistribute it and/or modify
   3.641 +    it under the terms of the GNU General Public License as published by
   3.642 +    the Free Software Foundation, either version 3 of the License, or
   3.643 +    (at your option) any later version.
   3.644 +
   3.645 +    This program is distributed in the hope that it will be useful,
   3.646 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.647 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   3.648 +    GNU General Public License for more details.
   3.649 +
   3.650 +    You should have received a copy of the GNU General Public License
   3.651 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   3.652 +
   3.653 +Also add information on how to contact you by electronic and paper mail.
   3.654 +
   3.655 +  If the program does terminal interaction, make it output a short
   3.656 +notice like this when it starts in an interactive mode:
   3.657 +
   3.658 +    <program>  Copyright (C) <year>  <name of author>
   3.659 +    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
   3.660 +    This is free software, and you are welcome to redistribute it
   3.661 +    under certain conditions; type `show c' for details.
   3.662 +
   3.663 +The hypothetical commands `show w' and `show c' should show the appropriate
   3.664 +parts of the General Public License.  Of course, your program's commands
   3.665 +might be different; for a GUI interface, you would use an "about box".
   3.666 +
   3.667 +  You should also get your employer (if you work as a programmer) or school,
   3.668 +if any, to sign a "copyright disclaimer" for the program, if necessary.
   3.669 +For more information on this, and how to apply and follow the GNU GPL, see
   3.670 +<http://www.gnu.org/licenses/>.
   3.671 +
   3.672 +  The GNU General Public License does not permit incorporating your program
   3.673 +into proprietary programs.  If your program is a subroutine library, you
   3.674 +may consider it more useful to permit linking proprietary applications with
   3.675 +the library.  If this is what you want to do, use the GNU Lesser General
   3.676 +Public License instead of this License.  But first, please read
   3.677 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/README.md	Wed Feb 17 23:55:43 2016 +0300
     4.3 @@ -0,0 +1,24 @@
     4.4 +# Serpentron
     4.5 +
     4.6 +Implementation of a classic arcade game.  Survive as long as possible
     4.7 +without hitting anything.  Up to 4 players can play on a single
     4.8 +computer. Players with the same color form a team.  The scoring system
     4.9 +is balanced for all possible team configurations.
    4.10 +
    4.11 +[Play here](http://www.games1729.com/serpentron/)
    4.12 +
    4.13 +## Getting Started
    4.14 +
    4.15 +Install Amber and create an Amber project, as shown in
    4.16 +[Amber Instructions](https://github.com/amber-smalltalk/amber#prerequisites).
    4.17 +
    4.18 +To bring project alive after cloning the repository:
    4.19 +
    4.20 +```sh
    4.21 +npm install
    4.22 +bower install
    4.23 +grunt default devel
    4.24 +```
    4.25 +
    4.26 +Developing the project (after brought alive): start server with 
    4.27 +`amber serve` and go to `http://localhost:4000/`.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/bower.json	Wed Feb 17 23:55:43 2016 +0300
     5.3 @@ -0,0 +1,39 @@
     5.4 +{
     5.5 +  "name": "serpentron",
     5.6 +  "description": "Implementation of a classic arcade game. Survive as long as possible without hitting anything.",
     5.7 +  "ignore": [
     5.8 +    "**/.*",
     5.9 +    "node_modules",
    5.10 +    "bower_components",
    5.11 +    "/*.js",
    5.12 +    "/*.html",
    5.13 +    "test",
    5.14 +    "tests"
    5.15 +  ],
    5.16 +  "authors": [
    5.17 +    {
    5.18 +      "name": "Mikhail Kryshen",
    5.19 +      "email": "mikhail@kryshen.net"
    5.20 +    }
    5.21 +  ],
    5.22 +  "homepage": "http://www.games1729.com/serpentron/",
    5.23 +  "keywords": [
    5.24 +    "Amber",
    5.25 +    "Smalltalk"
    5.26 +  ],
    5.27 +  "license": [
    5.28 +    "GPL-3.0"
    5.29 +  ],
    5.30 +  "private": false,
    5.31 +  "dependencies": {
    5.32 +    "amber": "^0.15.1",
    5.33 +    "amber-compat-es2015": "^0.1.0",
    5.34 +    "domite": "^0.4.0",
    5.35 +    "silk": "^0.2.0"
    5.36 +  },
    5.37 +  "devDependencies": {
    5.38 +    "amber-contrib-legacy": "^0.3.0",
    5.39 +    "amber-ide-starter-dialog": "^0.1.0",
    5.40 +    "helios": "^0.6.0"
    5.41 +  }
    5.42 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/config-browser.js	Wed Feb 17 23:55:43 2016 +0300
     6.3 @@ -0,0 +1,2 @@
     6.4 +define("amber/Platform", ["amber_core/Platform-Browser"], {});
     6.5 +define("amber/compatibility", ["amber/browser-compatibility"], {});
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/config-node.js	Wed Feb 17 23:55:43 2016 +0300
     7.3 @@ -0,0 +1,7 @@
     7.4 +// This file is used to make additional changes
     7.5 +// when building an app to run in node.js.
     7.6 +// Free to edit. You can break tests (cli test runner uses
     7.7 +// this to build itself - it is a node executable).
     7.8 +define("amber/Platform", ["amber_core/Platform-Node"], {});
     7.9 +define("amber/compatibility", ["amber/node-compatibility"], {});
    7.10 +define("jquery", {});
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/deploy.js	Wed Feb 17 23:55:43 2016 +0300
     8.3 @@ -0,0 +1,11 @@
     8.4 +define([
     8.5 +    'amber/deploy',
     8.6 +    // Should not be required in deployment,
     8.7 +    // but something still tries to load it.
     8.8 +    'jquery',
     8.9 +    // --- packages to be deployed begin here ---
    8.10 +    'amber-serpentron/Serpentron'
    8.11 +    // --- packages to be deployed end here ---
    8.12 +], function (amber) {
    8.13 +    return amber;
    8.14 +});
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/devel.js	Wed Feb 17 23:55:43 2016 +0300
     9.3 @@ -0,0 +1,11 @@
     9.4 +define([
     9.5 +    './testing',
     9.6 +    'amber/devel',
     9.7 +    // --- packages used only during development begin here ---
     9.8 +    'amber/legacy/Benchfib',
     9.9 +    'amber/legacy/Examples',
    9.10 +    'amber/legacy/IDE'
    9.11 +    // --- packages used only during development end here ---
    9.12 +], function (amber) {
    9.13 +    return amber;
    9.14 +});
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/index.html	Wed Feb 17 23:55:43 2016 +0300
    10.3 @@ -0,0 +1,162 @@
    10.4 +<!DOCTYPE html>
    10.5 +<html>
    10.6 +    <head>
    10.7 +        <title>Serpentron</title>
    10.8 +        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    10.9 +        <meta name="author" content="Mikhail Kryshen" />
   10.10 +        <script type='text/javascript' src='the.js'></script>
   10.11 +        <style>
   10.12 +         body {
   10.13 +             margin: 0;
   10.14 +             background: #333;
   10.15 +             color: #fff;
   10.16 +         }
   10.17 +         #serpentron {
   10.18 +             font-family: 'PT Sans', 'Helvetica', sans-serif;
   10.19 +         }
   10.20 +         #title {
   10.21 +             overflow: auto;
   10.22 +             padding: 5px 10px;
   10.23 +             height: 25px;
   10.24 +             background: #ddd;
   10.25 +             color: black;
   10.26 +         }
   10.27 +         #title h1 {
   10.28 +             display: inline;
   10.29 +             margin: 0 15px 0 0;
   10.30 +             padding: 0;
   10.31 +             line-height: 24px;
   10.32 +             font-size: 22px;
   10.33 +             font-weight: bold;
   10.34 +         }
   10.35 +         #title h1 a,
   10.36 +         #title h1 a:visited {
   10.37 +             color: #00c;
   10.38 +         }
   10.39 +         #status {
   10.40 +             display: inline;
   10.41 +             font-weight: bold;
   10.42 +         }
   10.43 +         #status .player-color {
   10.44 +             filter: brightness(60%) saturate(180%);
   10.45 +         }
   10.46 +         #serpentron canvas {
   10.47 +             position: absolute;
   10.48 +             width: 100%;
   10.49 +             height: 100%;
   10.50 +             /* image-rendering: optimizeSpeed;
   10.51 +                image-rendering: -moz-crisp-edges;
   10.52 +                image-rendering: -webkit-optimize-contrast;
   10.53 +                image-rendering: -o-crisp-edges; */
   10.54 +             image-rendering: pixelated;         
   10.55 +             /* -ms-interpolation-mode: nearest-neighbor; */
   10.56 +         }
   10.57 +         #field {
   10.58 +             position: relative;
   10.59 +             clear: both;
   10.60 +         }
   10.61 +         #start-screen {
   10.62 +             background: rgba(0, 0, 0, 0.7);
   10.63 +             margin: 0;
   10.64 +             padding: 15px;
   10.65 +             position: absolute;
   10.66 +             top: 0;
   10.67 +             left: 0;
   10.68 +             bottom: 0;
   10.69 +             right: 0;
   10.70 +         }
   10.71 +         #message {
   10.72 +             color: white;
   10.73 +             text-shadow: 1px 1px 1px #000;
   10.74 +             background: rgba(0, 0, 0, 0.8);
   10.75 +             font-size: 28px;
   10.76 +             font-weight: bold;
   10.77 +             text-align: center;
   10.78 +             padding: 1em;
   10.79 +             position: absolute;
   10.80 +             top: 50%;
   10.81 +             left: 50%;
   10.82 +             transform: translateX(-50%) translateY(-50%);
   10.83 +             -webkit-transform: translateX(-50%) translateY(-50%);
   10.84 +             border: 2px solid #aaa;
   10.85 +             border-radius: 1em;
   10.86 +         }
   10.87 +         #message .player-color {
   10.88 +             filter: brightness(150%) saturate(90%);
   10.89 +         }
   10.90 +         .player {
   10.91 +             margin: 10px 0;
   10.92 +         }
   10.93 +         .color-selector {
   10.94 +             margin-right: 5px;
   10.95 +             vertical-align: center;
   10.96 +         }
   10.97 +         .player input,
   10.98 +         .player select {
   10.99 +             vertical-align: middle;
  10.100 +             background: rgba(60, 60, 60, 0.7);
  10.101 +             color: white;
  10.102 +             border: solid 2px grey;
  10.103 +             outline: none;
  10.104 +             margin: 0 5px;
  10.105 +         }
  10.106 +         .color-button,
  10.107 +         .selected-color-button {
  10.108 +             display: inline-block;
  10.109 +             vertical-align: middle;
  10.110 +             text-align: center;
  10.111 +             width: 21px;
  10.112 +             height: 21px;
  10.113 +         }
  10.114 +         .color-button span,
  10.115 +         .selected-color-button span {
  10.116 +             color: white;
  10.117 +             vertical-align: middle;
  10.118 +         }
  10.119 +         .color-button {
  10.120 +             padding: 2px;
  10.121 +         }
  10.122 +         .selected-color-button {
  10.123 +             padding: 0;
  10.124 +             border: solid 2px white;
  10.125 +         }
  10.126 +         .color-button:hover {
  10.127 +             padding: 0;
  10.128 +             border: solid 2px #ccc;
  10.129 +         }
  10.130 +         #start-screen button {
  10.131 +             background: white;
  10.132 +             color: black;
  10.133 +             border: none;
  10.134 +             padding: 2px 5px;
  10.135 +             margin: 5px 10px 5px 0;
  10.136 +         }
  10.137 +         .visible {
  10.138 +             visibility: visible;
  10.139 +             opacity: 1;
  10.140 +             transition: visibility 0s, opacity 0.2s linear;
  10.141 +             -moz-transition: visibility 0s, opacity 0.2s linear;
  10.142 +         }
  10.143 +         .hidden {
  10.144 +             visibility: hidden;
  10.145 +             opacity: 0;
  10.146 +             transition: visibility 0.2s, opacity 0.2s linear;
  10.147 +             -moz-transition: visibility 0.2s, opacity 0.2s linear;
  10.148 +         }
  10.149 +        </style>
  10.150 +    </head>
  10.151 +    <body>
  10.152 +        <div id="serpentron"></div>
  10.153 +        <script type='text/javascript'>
  10.154 +         require(['app'], function (amber) {
  10.155 +             amber.initialize({
  10.156 +                 //used for all new packages in IDE
  10.157 +                 'transport.defaultAmdNamespace': "amber-serpentron"
  10.158 +             }).then(function () {
  10.159 +                 require(["amber-ide-starter-dialog"], function (dlg) { dlg.start(); });
  10.160 +                 amber.globals.Serpentron._start();
  10.161 +             });
  10.162 +         });
  10.163 +        </script>
  10.164 +    </body>
  10.165 +</html>
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/local.amd.json	Wed Feb 17 23:55:43 2016 +0300
    11.3 @@ -0,0 +1,5 @@
    11.4 +{
    11.5 +    "paths": {
    11.6 +        "amber-serpentron": "src"
    11.7 +    }
    11.8 +}
    11.9 \ No newline at end of file
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/package.json	Wed Feb 17 23:55:43 2016 +0300
    12.3 @@ -0,0 +1,42 @@
    12.4 +{
    12.5 +  "name": "serpentron",
    12.6 +  "title": "Serpentron",
    12.7 +  "description": "Implementation of a classic arcade game. Survive as long as possible without hitting anything.",
    12.8 +  "version": "1.0.0-beta",
    12.9 +  "homepage": "http://www.games1729.com/serpentron/",
   12.10 +  "author": {
   12.11 +    "name": "Mikhail Kryshen",
   12.12 +    "email": "mikhail@kryshen.net"
   12.13 +  },
   12.14 +  "repository": {
   12.15 +    "type": "git",
   12.16 +    "url": ""
   12.17 +  },
   12.18 +  "bugs": {
   12.19 +    "url": ""
   12.20 +  },
   12.21 +  "licenses": [
   12.22 +    {
   12.23 +      "type": "GPL-3.0",
   12.24 +      "url": "http://www.gnu.org/licenses/gpl.html"
   12.25 +    }
   12.26 +  ],
   12.27 +  "engines": {
   12.28 +    "node": "0.10.x || 0.12.x || >=4.0.0"
   12.29 +  },
   12.30 +  "scripts": {
   12.31 +    "test": "grunt test"
   12.32 +  },
   12.33 +  "devDependencies": {
   12.34 +    "amber-dev": "^0.8.2",
   12.35 +    "grunt": "^0.4.5",
   12.36 +    "grunt-contrib-clean": "^0.7.0",
   12.37 +    "grunt-contrib-requirejs": "^0.4.4",
   12.38 +    "grunt-execute": "^0.2.2",
   12.39 +    "requirejs": "^2.1.15"
   12.40 +  },
   12.41 +  "keywords": [
   12.42 +    "Amber",
   12.43 +    "Smalltalk"
   12.44 +  ]
   12.45 +}
   12.46 \ No newline at end of file
    13.1 Binary file resources/skin.png has changed
    14.1 Binary file skin/background.png has changed
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/skin/compose.rkt	Wed Feb 17 23:55:43 2016 +0300
    15.3 @@ -0,0 +1,38 @@
    15.4 +#lang racket
    15.5 +(require 2htdp/image)
    15.6 +(require lang/posn)
    15.7 +
    15.8 +(define background (bitmap/file "background.png"))
    15.9 +(define tile (bitmap/file "tile.png"))
   15.10 +(define snake (bitmap/file "snake.png"))
   15.11 +(define snake-mask (bitmap/file "snake_mask.png"))
   15.12 +
   15.13 +(define s (image-width tile))
   15.14 +
   15.15 +(define head (crop 0 0 s s snake))
   15.16 +(define head-mask (crop 0 0 s s snake-mask))
   15.17 +
   15.18 +(define body (crop 0 s s s snake))
   15.19 +(define body-mask (crop 0 s s s snake-mask))
   15.20 +
   15.21 +(define corner (crop 0 (* s 2) s s snake))
   15.22 +(define corner-mask (crop 0 (* s 2) s s snake-mask))
   15.23 +
   15.24 +(define (orientations pict)
   15.25 +  (beside/align "top"
   15.26 +                pict
   15.27 +                (rotate -90 pict)
   15.28 +                (rotate 180 pict)
   15.29 +                (rotate 90 pict)))
   15.30 +
   15.31 +(save-image
   15.32 + (above/align "left"
   15.33 +              background
   15.34 +              (beside tile
   15.35 +                      (orientations head)
   15.36 +                      (orientations body)
   15.37 +                      (orientations corner)
   15.38 +                      (orientations head-mask)
   15.39 +                      (orientations body-mask)
   15.40 +                      (orientations corner-mask)))
   15.41 + "skin.png")
    16.1 Binary file skin/snake.png has changed
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/skin/snake.svg	Wed Feb 17 23:55:43 2016 +0300
    17.3 @@ -0,0 +1,156 @@
    17.4 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    17.5 +<!-- Created with Inkscape (http://www.inkscape.org/) -->
    17.6 +
    17.7 +<svg
    17.8 +   xmlns:dc="http://purl.org/dc/elements/1.1/"
    17.9 +   xmlns:cc="http://creativecommons.org/ns#"
   17.10 +   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   17.11 +   xmlns:svg="http://www.w3.org/2000/svg"
   17.12 +   xmlns="http://www.w3.org/2000/svg"
   17.13 +   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   17.14 +   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   17.15 +   sodipodi:docname="snake.svg"
   17.16 +   inkscape:version="0.91 r13725"
   17.17 +   version="1.1"
   17.18 +   id="svg2"
   17.19 +   viewBox="0 0 28 42.000001"
   17.20 +   height="42"
   17.21 +   width="28"
   17.22 +   inkscape:export-filename="/home/mikhail/projects/own/serpentron/skin/path4407.png"
   17.23 +   inkscape:export-xdpi="90"
   17.24 +   inkscape:export-ydpi="90">
   17.25 +  <sodipodi:namedview
   17.26 +     inkscape:snap-smooth-nodes="true"
   17.27 +     inkscape:object-nodes="true"
   17.28 +     inkscape:window-maximized="1"
   17.29 +     inkscape:window-y="27"
   17.30 +     inkscape:window-x="0"
   17.31 +     inkscape:window-height="960"
   17.32 +     inkscape:window-width="1280"
   17.33 +     inkscape:guide-bbox="true"
   17.34 +     showguides="true"
   17.35 +     units="px"
   17.36 +     showgrid="true"
   17.37 +     inkscape:current-layer="svg2"
   17.38 +     inkscape:document-units="px"
   17.39 +     inkscape:cy="15.241741"
   17.40 +     inkscape:cx="-3.6398525"
   17.41 +     inkscape:zoom="8"
   17.42 +     inkscape:pageshadow="2"
   17.43 +     inkscape:pageopacity="0.0"
   17.44 +     borderopacity="1.0"
   17.45 +     bordercolor="#666666"
   17.46 +     pagecolor="#ffffff"
   17.47 +     id="base">
   17.48 +    <sodipodi:guide
   17.49 +       inkscape:color="rgb(0,0,255)"
   17.50 +       inkscape:label=""
   17.51 +       id="guide4146"
   17.52 +       orientation="1,0"
   17.53 +       position="14,14" />
   17.54 +    <sodipodi:guide
   17.55 +       inkscape:color="rgb(0,0,255)"
   17.56 +       inkscape:label=""
   17.57 +       id="guide4148"
   17.58 +       orientation="0,1"
   17.59 +       position="14,28.000001" />
   17.60 +    <inkscape:grid
   17.61 +       enabled="true"
   17.62 +       spacingx="1"
   17.63 +       id="grid4169"
   17.64 +       type="xygrid" />
   17.65 +    <sodipodi:guide
   17.66 +       inkscape:color="rgb(0,0,255)"
   17.67 +       inkscape:label=""
   17.68 +       id="guide4175"
   17.69 +       orientation="1,0"
   17.70 +       position="7,28.000001" />
   17.71 +    <sodipodi:guide
   17.72 +       inkscape:color="rgb(0,0,255)"
   17.73 +       inkscape:label=""
   17.74 +       id="guide4207"
   17.75 +       orientation="0,1"
   17.76 +       position="14,14" />
   17.77 +    <inkscape:grid
   17.78 +       enabled="false"
   17.79 +       spacingy="0.50000001"
   17.80 +       spacingx="0.5"
   17.81 +       id="grid4209"
   17.82 +       type="xygrid" />
   17.83 +    <sodipodi:guide
   17.84 +       inkscape:color="rgb(0,0,255)"
   17.85 +       inkscape:label=""
   17.86 +       id="guide4287"
   17.87 +       orientation="1,0"
   17.88 +       position="42,14" />
   17.89 +    <sodipodi:guide
   17.90 +       inkscape:color="rgb(0,0,255)"
   17.91 +       inkscape:label=""
   17.92 +       id="guide4274"
   17.93 +       orientation="1,0"
   17.94 +       position="28,14" />
   17.95 +  </sodipodi:namedview>
   17.96 +  <defs
   17.97 +     id="defs4" />
   17.98 +  <metadata
   17.99 +     id="metadata7">
  17.100 +    <rdf:RDF>
  17.101 +      <cc:Work
  17.102 +         rdf:about="">
  17.103 +        <dc:format>image/svg+xml</dc:format>
  17.104 +        <dc:type
  17.105 +           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
  17.106 +        <dc:title></dc:title>
  17.107 +      </cc:Work>
  17.108 +    </rdf:RDF>
  17.109 +  </metadata>
  17.110 +  <g
  17.111 +     transform="translate(0,-1010.3622)"
  17.112 +     id="layer1"
  17.113 +     inkscape:groupmode="layer"
  17.114 +     inkscape:label="Layer 1">
  17.115 +    <path
  17.116 +       sodipodi:nodetypes="zzzzzzzzzzz"
  17.117 +       inkscape:connector-curvature="0"
  17.118 +       id="path4177"
  17.119 +       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"
  17.120 +       style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
  17.121 +    <path
  17.122 +       sodipodi:nodetypes="cczzccczzcc"
  17.123 +       inkscape:connector-curvature="0"
  17.124 +       id="path4261"
  17.125 +       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"
  17.126 +       style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
  17.127 +    <g
  17.128 +       id="g4401">
  17.129 +      <path
  17.130 +         id="path4403"
  17.131 +         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"
  17.132 +         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" />
  17.133 +      <path
  17.134 +         id="path4405"
  17.135 +         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"
  17.136 +         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" />
  17.137 +      <path
  17.138 +         id="path4407"
  17.139 +         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"
  17.140 +         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" />
  17.141 +      <path
  17.142 +         id="path4409"
  17.143 +         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"
  17.144 +         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" />
  17.145 +      <path
  17.146 +         id="path4411"
  17.147 +         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"
  17.148 +         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" />
  17.149 +      <path
  17.150 +         id="path4413"
  17.151 +         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"
  17.152 +         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" />
  17.153 +      <path
  17.154 +         id="path4415"
  17.155 +         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"
  17.156 +         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" />
  17.157 +    </g>
  17.158 +  </g>
  17.159 +</svg>
    18.1 Binary file skin/snake.xcf.gz has changed
    19.1 Binary file skin/snake_mask.png has changed
    20.1 Binary file skin/tile.png has changed
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/Serpentron-Tests.st	Wed Feb 17 23:55:43 2016 +0300
    21.3 @@ -0,0 +1,5 @@
    21.4 +Smalltalk createPackage: 'Serpentron-Tests'!
    21.5 +TestCase subclass: #SerpentronTest
    21.6 +	instanceVariableNames: ''
    21.7 +	package: 'Serpentron-Tests'!
    21.8 +
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/Serpentron.st	Wed Feb 17 23:55:43 2016 +0300
    22.3 @@ -0,0 +1,1230 @@
    22.4 +Smalltalk createPackage: 'Serpentron'!
    22.5 +(Smalltalk packageAt: 'Serpentron') imports: {'silk/Silk'}!
    22.6 +Object subclass: #Serpentron
    22.7 +	instanceVariableNames: 'field skin players playerColors controllerPrototypes score pointsToWin'
    22.8 +	package: 'Serpentron'!
    22.9 +!Serpentron commentStamp!
   22.10 +The game UI.!
   22.11 +
   22.12 +!Serpentron methodsFor: 'initialization'!
   22.13 +
   22.14 +initialize
   22.15 +	super initialize.
   22.16 +	playerColors := #('#377eb8' '#e41a1c' '#4daf4a' '#ff7f00' '#984ea3' '#b3ad78').
   22.17 +	skin := TronSkin new.
   22.18 +	field := TronField new
   22.19 +		skin: skin;
   22.20 +		onEndGame: [ self handleEndGame ].
   22.21 +	self initializePlayers; initializeControllers.
   22.22 +	(Silk fromElement: document)
   22.23 +		on: #keydown bind: [ :event | field keyDown: event ].
   22.24 +! !
   22.25 +
   22.26 +!Serpentron methodsFor: 'private'!
   22.27 +
   22.28 +handleEndGame
   22.29 +	| color |
   22.30 +	field isGameFinished
   22.31 +		"Interrupted game, no winner."
   22.32 +		ifFalse: [ ^ self startScreenVisible: true ].
   22.33 +	color := field winningColorIfNone: [ 
   22.34 +		^ self status: 'No winner in this round.'; nextRound ].
   22.35 +	self updateScore.
   22.36 +	(score anySatisfy: [ :each | each >= pointsToWin ])
   22.37 +		ifFalse: [
   22.38 +			self status: (self winnerDOM: color) << ' won the round.'.
   22.39 +			^ self nextRound ].
   22.40 +	self status: self scoreDOM.
   22.41 +	window
   22.42 +		setTimeout: [ 
   22.43 +			self startScreenVisible: true.
   22.44 +			self hideMessage.
   22.45 +			self status: self scoreDOM << '. ' << (self winnerDOM: color) << ' won!!' ]
   22.46 +		after: 2000.	
   22.47 +	window
   22.48 +		setTimeout: [ self showMessage: (self winnerDOM: color) << ' won!!' ]
   22.49 +		after: 1000.
   22.50 +!
   22.51 +
   22.52 +hideMessage
   22.53 +	(Silk at: '#message') element className: 'hidden'.
   22.54 +!
   22.55 +
   22.56 +initializeControllers
   22.57 +	controllerPrototypes := {
   22.58 +		TronKeyboardController new
   22.59 +			keyMap: #{
   22.60 +				38 -> (0 @ -1).
   22.61 +				39 -> (1 @ 0).
   22.62 +				40 -> (0 @ 1).
   22.63 +				37 -> (-1 @ 0)}
   22.64 +			name: 'arrows'.
   22.65 +		TronKeyboardController new
   22.66 +			keyMap: #{
   22.67 +				87 -> (0 @ -1).
   22.68 +				68 -> (1 @ 0).
   22.69 +				83 -> (0 @ 1).
   22.70 +				65 -> (-1 @ 0)}
   22.71 +			name: 'WASD'.
   22.72 +		TronKeyboardController new
   22.73 +			keyMap: #{
   22.74 +				89 -> (0 @ -1).
   22.75 +				74 -> (1 @ 0).
   22.76 +				72 -> (0 @ 1).
   22.77 +				71 -> (-1 @ 0)}
   22.78 +			name: 'YGHJ'.
   22.79 +		TronKeyboardController new
   22.80 +			keyMap: #{
   22.81 +				80 -> (0 @ -1).
   22.82 +				222 -> (1 @ 0).
   22.83 +				59 -> (0 @ 1).
   22.84 +				76 -> (-1 @ 0)}
   22.85 +			name: 'PL;'''.
   22.86 +		TronComputerController1 new.
   22.87 +		"TronRandomController new"
   22.88 +	}.
   22.89 +	(players at: 1) controller: (controllerPrototypes at: 1) copy.
   22.90 +	(players at: 2) controller: (controllerPrototypes at: 5) copy.
   22.91 +	(players at: 3) controller: (controllerPrototypes at: 5) copy.
   22.92 +	(players at: 4) controller: (controllerPrototypes at: 5) copy.
   22.93 +!
   22.94 +
   22.95 +initializePlayers
   22.96 +	players := { 
   22.97 +		TronPlayer new
   22.98 +			name: 'Player 1';
   22.99 +			color: (playerColors at: 1).
  22.100 +		TronPlayer new
  22.101 +			name: 'Player 2';
  22.102 +			color: (playerColors at: 2).
  22.103 +		TronPlayer new
  22.104 +			name: 'Player 3';
  22.105 +			color: (playerColors at: 3);
  22.106 +			enabled: false.
  22.107 +		TronPlayer new
  22.108 +			name: 'Player 4';
  22.109 +			color: (playerColors at: 4);
  22.110 +			enabled: false
  22.111 +	}.
  22.112 +!
  22.113 +
  22.114 +nextRound
  22.115 +	window
  22.116 +		setTimeout: [
  22.117 +			self status: self scoreDOM.
  22.118 +			field start: field players ]
  22.119 +		after: 2000.
  22.120 +!
  22.121 +
  22.122 +randomizePlayerColors
  22.123 +	| enabledPlayers |
  22.124 +	enabledPlayers := players select: #isEnabled.
  22.125 +	enabledPlayers do: [ :each |
  22.126 +		| color |
  22.127 +		[ color := playerColors atRandom.
  22.128 +		  enabledPlayers allSatisfy: [ :p |
  22.129 +		  	  p = each | (p color ~= color) ]
  22.130 +		] whileFalse.
  22.131 +		each color: color.
  22.132 +	].
  22.133 +!
  22.134 +
  22.135 +randomizeTeams
  22.136 +	| colorA colorB teamA |
  22.137 +	players do: [ :each | each enabled: true ].
  22.138 +	colorA := playerColors atRandom.
  22.139 +	[ colorB := playerColors atRandom.
  22.140 +	  colorB = colorA ] whileTrue.
  22.141 +	teamA := players copy.
  22.142 +	players size // 2 
  22.143 +		timesRepeat: [ (teamA remove: teamA atRandom) color: colorB ].
  22.144 +	teamA do: [ :each | each color: colorA ].
  22.145 +!
  22.146 +
  22.147 +renderColorSelectorFor: aPlayer on: aSilk
  22.148 +	| container buttons onChange |
  22.149 +	container := aSilk SPAN: {#class -> 'color-selector'}.
  22.150 +	buttons := Dictionary from:
  22.151 +		(playerColors collect: [ :each |
  22.152 +			| button |
  22.153 +			button := container A.
  22.154 +			button on: #click bind: [ 
  22.155 +				aPlayer enabled: true; color: each.
  22.156 +				self validatePlayerColor: aPlayer ].
  22.157 +			button element style background: each.
  22.158 +			each -> button ]).
  22.159 +	buttons at: #disabled put: (container A
  22.160 +		SPAN: '✗';
  22.161 +		on: #click bind: [ 
  22.162 +			aPlayer enabled: false.
  22.163 +			self validatePlayerColor: aPlayer ]).
  22.164 +	onChange := [
  22.165 +		buttons keysAndValuesDo: [ :k :v |
  22.166 +			(aPlayer isEnabled not & k = #disabled) |
  22.167 +				(aPlayer isEnabled & k = aPlayer color)
  22.168 +					ifTrue: [ v element className: 'selected-color-button' ]
  22.169 +					ifFalse: [ v element className: 'color-button' ] ] ].
  22.170 +	aPlayer
  22.171 +		onEnabledChange: onChange;
  22.172 +		onColorChange: onChange.
  22.173 +	onChange value.
  22.174 +!
  22.175 +
  22.176 +renderControllerSelectorFor: aPlayer on: aSilk
  22.177 +	| select options onChange |
  22.178 +	select := aSilk SELECT.
  22.179 +	options := Dictionary new.
  22.180 +	controllerPrototypes do: [ :each |
  22.181 +		options at: each name put: (select OPTION: each name) element ].
  22.182 +	select
  22.183 +		on: #change
  22.184 +		bind: [
  22.185 +			aPlayer controller:
  22.186 +				(controllerPrototypes
  22.187 +					detect: [ :each | each name = select element value ])
  22.188 +						copy ].
  22.189 +	onChange := [
  22.190 +		| value |
  22.191 +		value := aPlayer controller name.
  22.192 +		(options at: value) selected: 'selected'.
  22.193 +		aPlayer controller class = TronKeyboardController
  22.194 +			ifTrue: [
  22.195 +				players do: [ :each |
  22.196 +					(each ~= aPlayer and: [ each controller name = value ])
  22.197 +						ifTrue: [ each controller: TronComputerController1 new ]]]].
  22.198 +	aPlayer onControllerChange: onChange.
  22.199 +	onChange value.
  22.200 +!
  22.201 +
  22.202 +renderPlayer: aPlayer on: aSilk
  22.203 +	| container |
  22.204 +	container := aSilk DIV: { #class -> 'player' }.
  22.205 +	self renderColorSelectorFor: aPlayer on: container.
  22.206 +	(container INPUT
  22.207 +		on: #change bind: [ :event |
  22.208 +			aPlayer name: event target value ])
  22.209 +		element value: aPlayer name.
  22.210 +	self renderControllerSelectorFor: aPlayer on: container.
  22.211 +!
  22.212 +
  22.213 +renderStartScreenOn: aSilk
  22.214 +	| startScreen |
  22.215 +	startScreen := aSilk DIV: {#id -> 'start-screen'}.
  22.216 +	
  22.217 +	players do: [ :each | self renderPlayer: each on: startScreen ].
  22.218 +	
  22.219 +	(startScreen BUTTON: 'Random colors')
  22.220 +		on: #click bind: [ self randomizePlayerColors ].
  22.221 +	(startScreen BUTTON: 'Random teams')
  22.222 +		on: #click bind: [ self randomizeTeams ].
  22.223 +
  22.224 +	startScreen BR.
  22.225 +
  22.226 +	(startScreen BUTTON: 'Start')
  22.227 +		on: #click bind: [ :event | self startGame; status: self scoreDOM ].
  22.228 +!
  22.229 +
  22.230 +scoreDOM
  22.231 +	| message |
  22.232 +	message := Silk SPAN: 'Score: '.
  22.233 +	score associations
  22.234 +		do: [ :each | 
  22.235 +			(message SPAN: {#class -> 'player-color'. (each value * 10) rounded / 10})
  22.236 +				element style color: each key ]
  22.237 +		separatedBy: [ message << ':' ].
  22.238 +	message << ('/', pointsToWin).
  22.239 +	^ message.
  22.240 +!
  22.241 +
  22.242 +showMessage: anObject
  22.243 +	((Silk at: '#message') resetContents << anObject)
  22.244 +		element className: 'visible'.
  22.245 +!
  22.246 +
  22.247 +startGame
  22.248 +	| enabledPlayers |
  22.249 +	self startScreenVisible: false.
  22.250 +	field start: (players select: #isEnabled).
  22.251 +	pointsToWin := (30 / (field players size + 1)) ceiling.
  22.252 +	score := field colors collect: [ :each | 0 ].
  22.253 +!
  22.254 +
  22.255 +startScreenVisible: aBoolean
  22.256 +	(Silk at: '#start-screen') element 
  22.257 +		className: (aBoolean ifTrue: [ 'visible' ] ifFalse: [ 'hidden' ])
  22.258 +!
  22.259 +
  22.260 +status: anObject
  22.261 +	'#status' asSilk resetContents << anObject
  22.262 +!
  22.263 +
  22.264 +updateScore
  22.265 +	| color teamSize alive points defeated |
  22.266 +	color := field winningColorIfNone: [ ^ self ].
  22.267 +	teamSize := field colors at: color.
  22.268 +	defeated := field players size - teamSize.
  22.269 +	alive := field liveColors at: color.
  22.270 +	points := defeated * alive / teamSize * (teamSize + 1) / 2.
  22.271 +	points := points / (field players size - 1).
  22.272 +	score at: color	put: (score at: color) + points.
  22.273 +!
  22.274 +
  22.275 +validatePlayerColor: aPlayer
  22.276 +	| enabledPlayers otherPlayers freeColor |
  22.277 +	enabledPlayers := players select: #isEnabled.
  22.278 +	((enabledPlayers collect: #color) asSet size > 1)
  22.279 +		ifTrue: [ ^ self ].
  22.280 +	freeColor := playerColors detect: [ :each | each ~= enabledPlayers anyOne color ].
  22.281 +	otherPlayers := players select: [ :each | each ~~ aPlayer ].
  22.282 +	(otherPlayers
  22.283 +		detect: [ :each | each isEnabled not ]
  22.284 +		ifNone: [ otherPlayers first ])
  22.285 +			enabled: true;
  22.286 +			color: freeColor.
  22.287 +!
  22.288 +
  22.289 +winnerDOM: color
  22.290 +	| names team message |	
  22.291 +	team := field players select: [ :each | each color = color ].
  22.292 +	names := ''.
  22.293 +	(team collect: #name)
  22.294 +		do: [ :each | names := names, each]
  22.295 +		separatedBy: [ names := names, ' and ' ].
  22.296 +	message := Silk SPAN.
  22.297 +	(message SPAN: {#class -> 'player-color'. names})
  22.298 +		element style color: color.
  22.299 +	^ message
  22.300 +! !
  22.301 +
  22.302 +!Serpentron methodsFor: 'rendering'!
  22.303 +
  22.304 +augmentPage
  22.305 +	'#serpentron' asSilk resetContents << 'Loading...'.
  22.306 +	skin
  22.307 +		load: 'resources/skin.png'
  22.308 +		andDo: [ '#serpentron' asSilk resetContents << self ]
  22.309 +!
  22.310 +
  22.311 +renderOnSilk: aSilk
  22.312 +	| scale container width height |
  22.313 +	scale := 1.
  22.314 +	skin tileSize >= 20
  22.315 +		ifTrue: [ scale := 0.5 ].
  22.316 +	skin tileSize < 10
  22.317 +		ifTrue: [ scale := 2].
  22.318 +	
  22.319 +	width := field fieldSize x * skin tileSize * scale.
  22.320 +	height := field fieldSize y * skin tileSize * scale.
  22.321 +	
  22.322 +	aSilk element style
  22.323 +		width: width asString , 'px'.
  22.324 +	
  22.325 +	(aSilk DIV: {#id -> 'title'})
  22.326 +		H1: (Silk A: {	#href -> 'http://www.games1729.com/serpentron/'.
  22.327 +						#target -> '_top'.
  22.328 +						'Serpentron'});
  22.329 +		SPAN: {#id -> 'status'. '1.0 beta'}.
  22.330 +	
  22.331 +	container := aSilk DIV: {#id -> 'field'}.
  22.332 +	container element style
  22.333 +		width: width asString , 'px';
  22.334 +		height: height asString , 'px'.
  22.335 +	
  22.336 +	container << field.
  22.337 +	self renderStartScreenOn: container.
  22.338 +
  22.339 +	(container DIV: {#id -> 'message'. #class -> 'hidden'})
  22.340 +		element style
  22.341 +			margin: '0 auto'.
  22.342 +	
  22.343 +	aSilk << container.
  22.344 +! !
  22.345 +
  22.346 +Serpentron class instanceVariableNames: 'Instance'!
  22.347 +
  22.348 +!Serpentron class methodsFor: 'starting'!
  22.349 +
  22.350 +start
  22.351 +	(Instance := self new) augmentPage
  22.352 +! !
  22.353 +
  22.354 +Object subclass: #TronCollider
  22.355 +	instanceVariableNames: 'canvas context skin animationRequest lastFrameTime particles particlePool particlesPerCollision'
  22.356 +	package: 'Serpentron'!
  22.357 +!TronCollider commentStamp!
  22.358 +Particle system for collision effect.!
  22.359 +
  22.360 +!TronCollider methodsFor: 'accessing'!
  22.361 +
  22.362 +canvas: aCanvas
  22.363 +	canvas := aCanvas.
  22.364 +	context := canvas getContext: '2d'.
  22.365 +!
  22.366 +
  22.367 +skin: aTronSkin
  22.368 +	skin := aTronSkin
  22.369 +! !
  22.370 +
  22.371 +!TronCollider methodsFor: 'initialization'!
  22.372 +
  22.373 +initialize
  22.374 +	super initialize.
  22.375 +	particlesPerCollision := 200.
  22.376 +	particlePool := Queue new.
  22.377 +	particlesPerCollision * 2 + 10 timesRepeat: [ 
  22.378 +		particlePool nextPut: TronColliderParticle new ].
  22.379 +	particles := OrderedCollection new
  22.380 +! !
  22.381 +
  22.382 +!TronCollider methodsFor: 'private'!
  22.383 +
  22.384 +renderFrame: timestamp
  22.385 +	| liveParticles delta |
  22.386 +	delta := lastFrameTime
  22.387 +		ifNil: [ 0 ]
  22.388 +		ifNotNil: [	timestamp - lastFrameTime ].
  22.389 +	lastFrameTime := timestamp.
  22.390 +	"Transcript show: 'renderFrame: ';
  22.391 +		show: timestamp;
  22.392 +		show: '; ';
  22.393 +		show: delta;
  22.394 +		cr."
  22.395 +	liveParticles := OrderedCollection new.
  22.396 +	context clearRect: 0 y: 0 w: canvas width h: canvas height.
  22.397 +	particles do: [ :each |
  22.398 +		each
  22.399 +			update: delta;
  22.400 +			drawOn: context tileSize: skin tileSize.
  22.401 +		each
  22.402 +			ifAlive: [ liveParticles add: each ]
  22.403 +			ifNotAlive: [ particlePool nextPut: each ] ].
  22.404 +	particles := liveParticles.
  22.405 +	animationRequest := particles
  22.406 +		ifEmpty: [ nil ]
  22.407 +		ifNotEmpty: [
  22.408 +			window
  22.409 +				requestAnimationFrame: [ :ts | 
  22.410 +					self renderFrame: ts ]
  22.411 +				on: canvas ]
  22.412 +!
  22.413 +
  22.414 +startAnimation
  22.415 +	animationRequest ifNotNil: [ ^ self ].
  22.416 +	lastFrameTime := nil.
  22.417 +	animationRequest := window
  22.418 +		requestAnimationFrame: [ :ts | self renderFrame: ts ]
  22.419 +		on: canvas.
  22.420 +! !
  22.421 +
  22.422 +!TronCollider methodsFor: 'starting'!
  22.423 +
  22.424 +animateCollisionFor: aPlayer
  22.425 +	| particle |
  22.426 +	particlesPerCollision timesRepeat: [
  22.427 +		particles add: 
  22.428 +			((particlePool nextIfAbsent: [ TronColliderParticle new ])
  22.429 +				resetPosition: 
  22.430 +					aPlayer location - 0.5 - (aPlayer direction / 2)
  22.431 +				color: (Math random < 0.5
  22.432 +					ifTrue: [ aPlayer color ]
  22.433 +					ifFalse: [ '#ff3000' ])) ].
  22.434 +	self startAnimation.
  22.435 +! !
  22.436 +
  22.437 +Object subclass: #TronColliderParticle
  22.438 +	instanceVariableNames: 'color size velocity position alpha decay'
  22.439 +	package: 'Serpentron'!
  22.440 +
  22.441 +!TronColliderParticle methodsFor: 'accessing'!
  22.442 +
  22.443 +ifAlive: aliveBlock ifNotAlive: notAliveBlock
  22.444 +	^ alpha > 0.01 ifTrue: aliveBlock ifFalse:notAliveBlock
  22.445 +!
  22.446 +
  22.447 +resetPosition: positionPoint color: aString
  22.448 +	position := positionPoint.
  22.449 +	color := aString.
  22.450 +	"Particles return to the pool as soon as they die.
  22.451 +	Randomize on each reset or the pool will end up sotrted by particles' life time."
  22.452 +	alpha := 1 - (Math random * 0.5).
  22.453 +	decay := 0.997 - (Math random * 0.01)
  22.454 +! !
  22.455 +
  22.456 +!TronColliderParticle methodsFor: 'drawing'!
  22.457 +
  22.458 +drawOn: aContext tileSize: tileSize
  22.459 +	aContext
  22.460 +		globalAlpha: alpha;
  22.461 +		fillStyle: color;
  22.462 +		fillRect: (position x - (size / 2)) * tileSize
  22.463 +			y: (position y - (size / 2)) * tileSize
  22.464 +			w: size * tileSize
  22.465 +			h: size * tileSize.
  22.466 +! !
  22.467 +
  22.468 +!TronColliderParticle methodsFor: 'initialization'!
  22.469 +
  22.470 +initialize
  22.471 +	super initialize.
  22.472 +	size := (Math random * 0.3 + 0.7).
  22.473 +	velocity := (Math random - 0.5) @ (Math random - 0.5).
  22.474 +	velocity := velocity / (velocity dist: 0 @ 0) * (Math random raisedTo: 4 + 0.1) * 0.06
  22.475 +! !
  22.476 +
  22.477 +!TronColliderParticle methodsFor: 'updating'!
  22.478 +
  22.479 +update: delta
  22.480 +	position := position + (velocity * delta).
  22.481 +	alpha := alpha * (decay raisedTo: delta).
  22.482 +! !
  22.483 +
  22.484 +Object subclass: #TronController
  22.485 +	instanceVariableNames: 'field player'
  22.486 +	package: 'Serpentron'!
  22.487 +!TronController commentStamp!
  22.488 +Abstract superclass for controlling input devices and algorithms.!
  22.489 +
  22.490 +!TronController methodsFor: 'accessing'!
  22.491 +
  22.492 +field: aTronField
  22.493 +	field := aTronField
  22.494 +!
  22.495 +
  22.496 +name
  22.497 +	self subclassResponsibility.
  22.498 +!
  22.499 +
  22.500 +nextDirection: aPoint
  22.501 +	"Do not turn back."
  22.502 +	player nextDirection = (aPoint * (-1 @ -1))
  22.503 +		ifTrue: [ ^ self ].
  22.504 +	player nextDirection: aPoint.
  22.505 +!
  22.506 +
  22.507 +player: aTronPlayer
  22.508 +	player := aTronPlayer
  22.509 +! !
  22.510 +
  22.511 +!TronController methodsFor: 'computing'!
  22.512 +
  22.513 +compute
  22.514 +!
  22.515 +
  22.516 +isAtDecisionPoint
  22.517 +	| loc dir turn |
  22.518 +	player isFirstMove ifTrue: [ ^ true ].
  22.519 +	dir := player nextDirection.
  22.520 +	loc := player location.
  22.521 +	(field isFreeAt: loc + dir)
  22.522 +		ifFalse: [ ^ true ].
  22.523 +	turn := dir rotate90ccw.
  22.524 +	((field isFreeAt: loc + turn)
  22.525 +		and: [ (field isFreeAt: loc + dir + turn) not ])
  22.526 +		ifTrue: [ ^ true ].
  22.527 +	turn := dir rotate90cw.
  22.528 +	((field isFreeAt: loc + turn)
  22.529 +		and: [ (field isFreeAt: loc + dir + turn) not ])
  22.530 +		ifTrue: [ ^ true ].
  22.531 +	^ false
  22.532 +! !
  22.533 +
  22.534 +!TronController methodsFor: 'event handling'!
  22.535 +
  22.536 +keyDown: keyCode
  22.537 +	^ false
  22.538 +! !
  22.539 +
  22.540 +!TronController methodsFor: 'initialization'!
  22.541 +
  22.542 +reset
  22.543 +! !
  22.544 +
  22.545 +TronController class instanceVariableNames: 'directions'!
  22.546 +
  22.547 +TronController subclass: #TronComputerController1
  22.548 +	instanceVariableNames: 'weight aggressiveness'
  22.549 +	package: 'Serpentron'!
  22.550 +
  22.551 +!TronComputerController1 methodsFor: 'accessing'!
  22.552 +
  22.553 +name
  22.554 +	^ 'Computer'
  22.555 +! !
  22.556 +
  22.557 +!TronComputerController1 methodsFor: 'computing'!
  22.558 +
  22.559 +compute
  22.560 +	| best bestDirection |
  22.561 +	"player isFirstMove
  22.562 +		ifTrue: [ self nextDirection: TronPlayer directions atRandom ]."
  22.563 +	(self isAtDecisionPoint 
  22.564 +		or: [ (field isFreeAt: player location + (player nextDirection * 2)) not ])
  22.565 +		ifFalse: [ ^ self ].
  22.566 +	aggressiveness := 200 atRandom.
  22.567 +	best := 0.
  22.568 +	TronPlayer directions do: [ :each | 
  22.569 +		weight := 0.
  22.570 +		self scan: each.
  22.571 +		weight > best
  22.572 +			ifTrue:	[
  22.573 +				best := weight.
  22.574 +				bestDirection := each ]].
  22.575 +	bestDirection ifNil: [ ^ self ].
  22.576 +	self nextDirection: bestDirection.
  22.577 +! !
  22.578 +
  22.579 +!TronComputerController1 methodsFor: 'private'!
  22.580 +
  22.581 +extend: directionPoint from: nwPoint to: sePoint
  22.582 +	| point scanDir |
  22.583 +	scanDir := directionPoint y abs @ directionPoint x abs.
  22.584 +	point := Point
  22.585 +		x: (directionPoint x <= 0 ifTrue: [ nwPoint x ] ifFalse: [ sePoint x ])
  22.586 +		y: (directionPoint y <= 0 ifTrue: [ nwPoint y ] ifFalse: [ sePoint y ]).
  22.587 +	[ point <= sePoint ] 
  22.588 +		whileTrue: [
  22.589 +			weight := weight + 1.
  22.590 +			(field isFreeAt: point)
  22.591 +				ifFalse: [ 
  22.592 +					(self isEnemyHeadAt: point)
  22.593 +						ifTrue: [ weight := weight + aggressiveness ]
  22.594 +						ifFalse: [ ^ false ] ].
  22.595 +			point := point + scanDir ].
  22.596 +	^ true
  22.597 +!
  22.598 +
  22.599 +isEnemyHeadAt: aPoint
  22.600 +	(field playerWithHeadAt: aPoint)
  22.601 +		ifNotNil: [ :p | ^ p color ~= player color ].
  22.602 +	^ false
  22.603 +!
  22.604 +
  22.605 +scan: directionPoint
  22.606 +	| nw se nextNW nextSE directions scanDir |
  22.607 +	nw := se := player location + directionPoint.
  22.608 +	(field isFreeAt: nw) ifFalse: [ ^ self ].
  22.609 +	directions := TronPlayer directions copy
  22.610 +		remove: directionPoint * -1;
  22.611 +		yourself.
  22.612 +	[	scanDir := directions atRandom.
  22.613 +		scanDir <= 0 asPoint
  22.614 +			ifTrue: [ nextNW := nw + scanDir. nextSE := se ]
  22.615 +			ifFalse: [ nextNW := nw. nextSE := se + scanDir ].
  22.616 +		(self extend: scanDir from: nextNW to: nextSE)
  22.617 +			ifTrue: [ nw := nextNW. se := nextSE ]
  22.618 +			ifFalse: [ directions remove: scanDir ].
  22.619 +		directions isEmpty not
  22.620 +	] whileTrue.
  22.621 +! !
  22.622 +
  22.623 +TronController subclass: #TronKeyboardController
  22.624 +	instanceVariableNames: 'keyMap name'
  22.625 +	package: 'Serpentron'!
  22.626 +
  22.627 +!TronKeyboardController methodsFor: 'accessing'!
  22.628 +
  22.629 +keyMap: aDictionary name: aString
  22.630 +	keyMap := aDictionary.
  22.631 +	name := 'Keyboard: ', aString.
  22.632 +!
  22.633 +
  22.634 +name
  22.635 +	^ name
  22.636 +! !
  22.637 +
  22.638 +!TronKeyboardController methodsFor: 'event handling'!
  22.639 +
  22.640 +keyDown: keyCode
  22.641 +	self nextDirection: (keyMap at: keyCode ifAbsent: [ ^ false ]).
  22.642 +	^ true
  22.643 +! !
  22.644 +
  22.645 +TronKeyboardController class instanceVariableNames: 'keyMaps'!
  22.646 +
  22.647 +TronController subclass: #TronRandomController
  22.648 +	instanceVariableNames: ''
  22.649 +	package: 'Serpentron'!
  22.650 +
  22.651 +!TronRandomController methodsFor: 'accessing'!
  22.652 +
  22.653 +name
  22.654 +	^ 'Computer (random)'
  22.655 +! !
  22.656 +
  22.657 +!TronRandomController methodsFor: 'computing'!
  22.658 +
  22.659 +compute
  22.660 +	| dirs |
  22.661 +	(self isAtDecisionPoint or: [ 50 atRandom = 1 ])
  22.662 +		ifFalse: [ ^ self ].
  22.663 +	dirs := TronPlayer directions
  22.664 +		select: [ :each | field isFreeAt: player location + each ].
  22.665 +	dirs ifNotEmpty: [ self nextDirection: dirs atRandom ]
  22.666 +! !
  22.667 +
  22.668 +Object subclass: #TronField
  22.669 +	instanceVariableNames: 'skin size matrix players livePlayers colors liveColors canvas context collider timerId onEndGame'
  22.670 +	package: 'Serpentron'!
  22.671 +!TronField commentStamp!
  22.672 +The game field. Provides game logic and rendering.!
  22.673 +
  22.674 +!TronField methodsFor: 'accessing'!
  22.675 +
  22.676 +at: aPoint
  22.677 +	^ (matrix at: aPoint y) at: aPoint x
  22.678 +!
  22.679 +
  22.680 +at: aPoint ifAbsent: aBlock
  22.681 +	^ matrix
  22.682 +		at: aPoint y 
  22.683 +		ifPresent: [ :value | value at: aPoint x ifAbsent: aBlock ]
  22.684 +		ifAbsent: aBlock
  22.685 +!
  22.686 +
  22.687 +at: aPoint put: aSegment
  22.688 +	(matrix at: aPoint y) at: aPoint x put: aSegment
  22.689 +!
  22.690 +
  22.691 +colors
  22.692 +	^ colors
  22.693 +!
  22.694 +
  22.695 +fieldSize
  22.696 +	^ size
  22.697 +!
  22.698 +
  22.699 +isFreeAt: aPoint
  22.700 +	^ (self at: aPoint ifAbsent: [ ^ false ]) isNil
  22.701 +!
  22.702 +
  22.703 +isGameFinished
  22.704 +	^ liveColors size < 2
  22.705 +!
  22.706 +
  22.707 +liveColors
  22.708 +	^ liveColors
  22.709 +!
  22.710 +
  22.711 +playerWithHeadAt: aPoint
  22.712 +	| s |
  22.713 +	s := self at: aPoint ifAbsent: [ ^ nil ].
  22.714 +	s isHead ifTrue: [ ^ s player ] ifFalse: [ ^ nil ]
  22.715 +!
  22.716 +
  22.717 +players
  22.718 +	^ players
  22.719 +!
  22.720 +
  22.721 +skin
  22.722 +	^ skin
  22.723 +!
  22.724 +
  22.725 +skin: aTronSkin
  22.726 +	skin := aTronSkin
  22.727 +!
  22.728 +
  22.729 +winningColorIfNone: aBlock
  22.730 +	^ (liveColors size = 1)
  22.731 +		ifTrue: [ liveColors keys anyOne ]
  22.732 +		ifFalse: aBlock.
  22.733 +! !
  22.734 +
  22.735 +!TronField methodsFor: 'event handling'!
  22.736 +
  22.737 +keyDown: event
  22.738 +	"Handle Esc key."
  22.739 +	livePlayers isEmpty not & (event keyCode = 27)
  22.740 +		ifTrue: [
  22.741 +			event preventDefault.
  22.742 +			self endGame.
  22.743 +			^ self ].
  22.744 +	"Check all players rather than livePlayers 
  22.745 +	so that preventDefault is called for all used keys."
  22.746 +	(players anySatisfy: [ :each | each keyDown: event keyCode ])
  22.747 +		ifTrue: [ event preventDefault ].
  22.748 +	timerId ifNil: [ self startIfAllReady ].
  22.749 +! !
  22.750 +
  22.751 +!TronField methodsFor: 'initialization'!
  22.752 +
  22.753 +initialize
  22.754 +	super initialize.
  22.755 +	livePlayers := players := #().
  22.756 +	size := 50 @ 35
  22.757 +! !
  22.758 +
  22.759 +!TronField methodsFor: 'observing'!
  22.760 +
  22.761 +onEndGame: aBlock
  22.762 +	onEndGame := aBlock
  22.763 +! !
  22.764 +
  22.765 +!TronField methodsFor: 'private'!
  22.766 +
  22.767 +endGame
  22.768 +	self stopTimer.
  22.769 +	livePlayers := #().
  22.770 +	onEndGame ifNotNil: #value.
  22.771 +!
  22.772 +
  22.773 +killPlayer: aPlayer
  22.774 +	collider animateCollisionFor: aPlayer.
  22.775 +	livePlayers remove: aPlayer.
  22.776 +	self updateLiveColors.
  22.777 +!
  22.778 +
  22.779 +locatePlayers
  22.780 +	players size = 2 ifTrue: [
  22.781 +		(players at: 1) location: 16 @ 18.
  22.782 +		(players at: 2) location: 35 @ 18.
  22.783 +		^ self ].
  22.784 +	players size = 3 ifTrue: [
  22.785 +		(players at: 1) location: 18 @ 13.
  22.786 +		(players at: 2) location: 18 @ 23.
  22.787 +		(players at: 3) location: 33 @ 18.
  22.788 +		^ self ].
  22.789 +	players size = 4 ifTrue: [
  22.790 +		(players at: 1) location: 16 @ 11.
  22.791 +		(players at: 2) location: 35 @ 11.
  22.792 +		(players at: 3) location: 16 @ 25.
  22.793 +		(players at: 4) location: 35 @ 25.
  22.794 +		^ self ].
  22.795 +	self error: 'Invalid number of players.'
  22.796 +!
  22.797 +
  22.798 +renderCanvasOn: aSilk
  22.799 +	^ aSilk CANVAS: {
  22.800 +		#width -> (size x * skin tileSize).
  22.801 +		#height -> (size y * skin tileSize)}.
  22.802 +!
  22.803 +
  22.804 +startIfAllReady
  22.805 +	(livePlayers isEmpty not
  22.806 +		and: [ livePlayers allSatisfy: #isReady ])
  22.807 +			ifTrue: [ self startTimer ]
  22.808 +!
  22.809 +
  22.810 +startTimer
  22.811 +	timerId ifNotNil: [ self error: 'Timer already running.' ].
  22.812 +	timerId := window setInterval: [ self update ] every: 75.
  22.813 +!
  22.814 +
  22.815 +stopTimer
  22.816 +	timerId ifNotNil: [
  22.817 +		window clearInterval: timerId.
  22.818 +		timerId := nil ]
  22.819 +!
  22.820 +
  22.821 +update
  22.822 +	| lpCopy |
  22.823 +	lpCopy := livePlayers copy.
  22.824 +	lpCopy do: [ :each |
  22.825 +		| l |
  22.826 +		l := each location.
  22.827 +		self at: l put: each move.
  22.828 +		skin drawField: self on: context at: l ].
  22.829 +	lpCopy do: [ :each |
  22.830 +		| l other |
  22.831 +		l := each location.
  22.832 +		(self isFreeAt: l)
  22.833 +			ifTrue: [ self at: l put: each headSegment. ]
  22.834 +			ifFalse: [
  22.835 +				self killPlayer: each.
  22.836 +				"Check for head-to-head collision."
  22.837 +				other := self playerWithHeadAt: l.
  22.838 +				(other isNil | (other = each))
  22.839 +					ifFalse: [ 
  22.840 +						self killPlayer: other.
  22.841 +						self at: l put: nil. ]]].
  22.842 +	livePlayers do: [ :each | 
  22.843 +		skin drawField: self on: context at: each location ].
  22.844 +	self isGameFinished ifTrue: [ ^ self endGame ].
  22.845 +	livePlayers do: #compute.
  22.846 +!
  22.847 +
  22.848 +updateLiveColors
  22.849 +	liveColors := Dictionary new.
  22.850 +	livePlayers do: [ :each |
  22.851 +		liveColors
  22.852 +			at: each color
  22.853 +			ifPresent: [ :v | liveColors at: each color put: v + 1 ]
  22.854 +			ifAbsent: [ liveColors at: each color put: 1 ]].
  22.855 +! !
  22.856 +
  22.857 +!TronField methodsFor: 'rendering'!
  22.858 +
  22.859 +renderOnSilk: aSilk
  22.860 +	| backgroundCanvas |
  22.861 +	
  22.862 +	backgroundCanvas := (self renderCanvasOn: aSilk) element.
  22.863 +	
  22.864 +	canvas := (self renderCanvasOn: aSilk) element.
  22.865 +	context := canvas getContext: '2d'.
  22.866 +	
  22.867 +	collider := TronCollider new
  22.868 +		canvas: (self renderCanvasOn: aSilk) element;
  22.869 +		skin: skin.
  22.870 +	
  22.871 +	skin drawBackgroundOn: (backgroundCanvas getContext: '2d') from: 1 @ 1 to: size
  22.872 +! !
  22.873 +
  22.874 +!TronField methodsFor: 'starting'!
  22.875 +
  22.876 +start: anArrayOfPlayers
  22.877 +	players := anArrayOfPlayers.
  22.878 +	livePlayers := players copy.
  22.879 +	self updateLiveColors.
  22.880 +	colors := liveColors.
  22.881 +	matrix := (1 to: size y) collect: [ :i | Array new: size x ].
  22.882 +	context clearRect: 0 y: 0 w: canvas width h: canvas height.
  22.883 +	self locatePlayers.
  22.884 +	players do: [ :each | each field: self; reset; compute ].
  22.885 +	players do: [ :each |
  22.886 +		self at: each location put: each headSegment.
  22.887 +		skin drawField: self on: context at: each location ].
  22.888 +	self startIfAllReady.
  22.889 +! !
  22.890 +
  22.891 +Object subclass: #TronPlayer
  22.892 +	instanceVariableNames: 'enabled color name controller segments location moved direction nextDirection onColorChange onEnabledChange onControllerChange'
  22.893 +	package: 'Serpentron'!
  22.894 +
  22.895 +!TronPlayer methodsFor: 'accessing'!
  22.896 +
  22.897 +color
  22.898 +	^ color
  22.899 +!
  22.900 +
  22.901 +color: anObject
  22.902 +	color := anObject.
  22.903 +	onColorChange ifNotNil: #value.
  22.904 +!
  22.905 +
  22.906 +controller
  22.907 +	^ controller
  22.908 +!
  22.909 +
  22.910 +controller: aTronController
  22.911 +	aTronController player: self.
  22.912 +	controller := aTronController.
  22.913 +	onControllerChange ifNotNil: #value.
  22.914 +!
  22.915 +
  22.916 +direction
  22.917 +	^ direction
  22.918 +!
  22.919 +
  22.920 +enabled: aBoolean
  22.921 +	enabled := aBoolean.
  22.922 +	onEnabledChange ifNotNil: #value.
  22.923 +!
  22.924 +
  22.925 +field: aField
  22.926 +	controller field: aField
  22.927 +!
  22.928 +
  22.929 +headSegment
  22.930 +	^ segments at: direction
  22.931 +!
  22.932 +
  22.933 +isEnabled
  22.934 +	^ enabled
  22.935 +!
  22.936 +
  22.937 +isFirstMove
  22.938 +	^ moved not
  22.939 +!
  22.940 +
  22.941 +isReady
  22.942 +	^ nextDirection notNil
  22.943 +!
  22.944 +
  22.945 +location
  22.946 +	^ location
  22.947 +!
  22.948 +
  22.949 +location: anObject
  22.950 +	location := anObject
  22.951 +!
  22.952 +
  22.953 +name
  22.954 +	^ name
  22.955 +!
  22.956 +
  22.957 +name: anObject
  22.958 +	name := anObject.
  22.959 +!
  22.960 +
  22.961 +nextDirection
  22.962 +	^ nextDirection
  22.963 +!
  22.964 +
  22.965 +nextDirection: aPoint
  22.966 +	moved ifFalse: [ direction := aPoint ].
  22.967 +	nextDirection := aPoint
  22.968 +! !
  22.969 +
  22.970 +!TronPlayer methodsFor: 'event handling'!
  22.971 +
  22.972 +keyDown: keyCode
  22.973 +	^ controller keyDown: keyCode
  22.974 +! !
  22.975 +
  22.976 +!TronPlayer methodsFor: 'initialization'!
  22.977 +
  22.978 +initialize
  22.979 +	super initialize.
  22.980 +	enabled := true.
  22.981 +	self reset; initializeSegments.
  22.982 +!
  22.983 +
  22.984 +reset
  22.985 +	direction := 0 @ -1.
  22.986 +	nextDirection := nil.
  22.987 +	moved := false.
  22.988 +	controller ifNotNil: [ controller reset ].
  22.989 +! !
  22.990 +
  22.991 +!TronPlayer methodsFor: 'observing'!
  22.992 +
  22.993 +onColorChange: aBlock
  22.994 +	onColorChange := aBlock.
  22.995 +!
  22.996 +
  22.997 +onControllerChange: aBlock
  22.998 +	onControllerChange := aBlock.
  22.999 +!
 22.1000 +
 22.1001 +onEnabledChange: aBlock
 22.1002 +	onEnabledChange := aBlock.
 22.1003 +! !
 22.1004 +
 22.1005 +!TronPlayer methodsFor: 'private'!
 22.1006 +
 22.1007 +initializeSegments
 22.1008 +	segments := Dictionary new.
 22.1009 +	TronPlayer directionNames keysAndValuesDo: [ :to :toName |
 22.1010 +		segments 
 22.1011 +			at: to 
 22.1012 +			put: (TronHead new 
 22.1013 +					player: self;
 22.1014 +					sprite: 'head', toName;
 22.1015 +					direction: to);
 22.1016 +			at: {to. to}
 22.1017 +			put: (TronSegment new
 22.1018 +					player: self;
 22.1019 +					sprite: 'body', toName).
 22.1020 +		TronPlayer directionNames keysAndValuesDo: [ :from :fromName |		
 22.1021 +			(from x = to x) | (from y = to y) ifFalse: [
 22.1022 +				segments
 22.1023 +					at: {from. to}
 22.1024 +					put: (TronSegment new
 22.1025 +							player: self;
 22.1026 +							sprite: 'body', fromName, 'To', toName) ]]].
 22.1027 +! !
 22.1028 +
 22.1029 +!TronPlayer methodsFor: 'updating'!
 22.1030 +
 22.1031 +compute
 22.1032 +	controller compute
 22.1033 +!
 22.1034 +
 22.1035 +move
 22.1036 +	| segment |
 22.1037 +	segment := segments at: {direction. nextDirection} ifAbsent: [ nil ].
 22.1038 +	direction := nextDirection.
 22.1039 +	location := location + direction.
 22.1040 +	moved := true.
 22.1041 +	^ segment
 22.1042 +! !
 22.1043 +
 22.1044 +TronPlayer class instanceVariableNames: 'directions directionNames'!
 22.1045 +
 22.1046 +!TronPlayer class methodsFor: 'initialization'!
 22.1047 +
 22.1048 +directionNames
 22.1049 +	^ directionNames
 22.1050 +!
 22.1051 +
 22.1052 +directions
 22.1053 +	^ directions
 22.1054 +!
 22.1055 +
 22.1056 +initialize
 22.1057 +	super initialize.
 22.1058 +	directionNames := Dictionary new
 22.1059 +		at: 0 @ -1 put: 'North';
 22.1060 +		at: 1 @ 0 put: 'East';
 22.1061 +		at: 0 @ 1 put: 'South';
 22.1062 +		at: -1 @ 0 put: 'West';
 22.1063 +		yourself.
 22.1064 +	directions := directionNames keys.
 22.1065 +! !
 22.1066 +
 22.1067 +Object subclass: #TronSegment
 22.1068 +	instanceVariableNames: 'player sprite'
 22.1069 +	package: 'Serpentron'!
 22.1070 +
 22.1071 +!TronSegment methodsFor: 'accessing'!
 22.1072 +
 22.1073 +color
 22.1074 +	^ player color
 22.1075 +!
 22.1076 +
 22.1077 +isHead
 22.1078 +	^ false
 22.1079 +!
 22.1080 +
 22.1081 +player
 22.1082 +	^ player
 22.1083 +!
 22.1084 +
 22.1085 +player: anObject
 22.1086 +	player := anObject
 22.1087 +!
 22.1088 +
 22.1089 +sprite
 22.1090 +	^ sprite
 22.1091 +!
 22.1092 +
 22.1093 +sprite: anObject
 22.1094 +	sprite := anObject
 22.1095 +! !
 22.1096 +
 22.1097 +TronSegment subclass: #TronHead
 22.1098 +	instanceVariableNames: 'direction'
 22.1099 +	package: 'Serpentron'!
 22.1100 +
 22.1101 +!TronHead methodsFor: 'accessing'!
 22.1102 +
 22.1103 +direction
 22.1104 +	^ direction
 22.1105 +!
 22.1106 +
 22.1107 +direction: anObject
 22.1108 +	direction := anObject
 22.1109 +!
 22.1110 +
 22.1111 +isHead
 22.1112 +	^ true
 22.1113 +! !
 22.1114 +
 22.1115 +Object subclass: #TronSkin
 22.1116 +	instanceVariableNames: 'skinMap skinImage tileSize maskOffset'
 22.1117 +	package: 'Serpentron'!
 22.1118 +
 22.1119 +!TronSkin methodsFor: 'accessing'!
 22.1120 +
 22.1121 +tileSize
 22.1122 +	^ tileSize
 22.1123 +! !
 22.1124 +
 22.1125 +!TronSkin methodsFor: 'drawing'!
 22.1126 +
 22.1127 +drawBackgroundOn: aContext at: aPoint
 22.1128 +	self drawTile: #background offset: aPoint - 1 on: aContext at: aPoint;
 22.1129 +		 drawTile: #backgroundTile on: aContext at: aPoint
 22.1130 +!
 22.1131 +
 22.1132 +drawBackgroundOn: aContext from: nwPoint to: sePoint
 22.1133 +	nwPoint y to: sePoint y do: [ :row |
 22.1134 +		nwPoint x to: sePoint x do: [ :col |
 22.1135 +			self drawBackgroundOn: aContext at: col @ row ]]
 22.1136 +!
 22.1137 +
 22.1138 +drawField: aField on: aContext at: aPoint
 22.1139 +	| x y segment |
 22.1140 +	
 22.1141 +	x := (aPoint - 1) x * tileSize.
 22.1142 +	y := (aPoint - 1) y * tileSize.
 22.1143 +	
 22.1144 +	aContext
 22.1145 +		clearRect: x and: y and: tileSize and: tileSize.
 22.1146 +	
 22.1147 +	segment := (aField at: aPoint) ifNil: [ ^ self ].
 22.1148 +	
 22.1149 +	self 
 22.1150 +		drawTile: segment sprite
 22.1151 +		offset: maskOffset
 22.1152 +		on: aContext
 22.1153 +		at: aPoint.
 22.1154 +	aContext
 22.1155 +		globalCompositeOperation: 'source-atop';
 22.1156 +		fillStyle: segment color;
 22.1157 +		fillRect: x and: y and: tileSize and: tileSize.
 22.1158 +	self drawTile: segment sprite on: aContext at: aPoint.
 22.1159 +	
 22.1160 +	aContext globalCompositeOperation: 'source-over'.
 22.1161 +!
 22.1162 +
 22.1163 +drawSkinImageOn: aContext source: sourcePoint destination: destinationPoint
 22.1164 +	aContext drawImage: skinImage
 22.1165 +		sx: sourcePoint x
 22.1166 +		sy: sourcePoint y
 22.1167 +		sw: tileSize
 22.1168 +		sh: tileSize
 22.1169 +		dx: destinationPoint x
 22.1170 +		dy: destinationPoint y
 22.1171 +		dw: tileSize
 22.1172 +		dh: tileSize
 22.1173 +!
 22.1174 +
 22.1175 +drawTile: aSymbol offset: offsetPoint on: aContext at: targetPoint
 22.1176 +	self 
 22.1177 +		drawSkinImageOn: aContext
 22.1178 +		source: ((skinMap at: aSymbol) + offsetPoint) * tileSize
 22.1179 +		destination: (targetPoint - 1) * tileSize
 22.1180 +!
 22.1181 +
 22.1182 +drawTile: aSymbol on: aContext at: aPoint
 22.1183 +	self drawTile: aSymbol offset: 0@0 on: aContext at: aPoint
 22.1184 +! !
 22.1185 +
 22.1186 +!TronSkin methodsFor: 'initialization'!
 22.1187 +
 22.1188 +initialize
 22.1189 +	super initialize.
 22.1190 +	skinMap := Dictionary new
 22.1191 +		at: #background put: 0@0;
 22.1192 +		at: #backgroundBottomRight put: 49@34;
 22.1193 +		at: #backgroundTile put: 0@35;
 22.1194 +		at: #headNorth put: 1@35;
 22.1195 +		at: #headEast put: 2@35;
 22.1196 +		at: #headSouth put: 3@35;
 22.1197 +		at: #headWest put: 4@35;
 22.1198 +		at: #bodyNorth put: 5@35;
 22.1199 +		at: #bodyEast put: 6@35;
 22.1200 +		at: #bodySouth put: 7@35;
 22.1201 +		at: #bodyWest put: 8@35;
 22.1202 +		at: #bodySouthToEast put: 9@35;
 22.1203 +		at: #bodyWestToNorth put: 9@35;
 22.1204 +		at: #bodyNorthToEast put: 10@35;
 22.1205 +		at: #bodyWestToSouth put: 10@35;
 22.1206 +		at: #bodyNorthToWest put: 11@35;
 22.1207 +		at: #bodyEastToSouth put: 11@35;
 22.1208 +		at: #bodySouthToWest put: 12@35;
 22.1209 +		at: #bodyEastToNorth put: 12@35;
 22.1210 +		yourself.
 22.1211 +	maskOffset := 12 @ 0.
 22.1212 +	skinImage := document createElement: 'img'
 22.1213 +! !
 22.1214 +
 22.1215 +!TronSkin methodsFor: 'loading'!
 22.1216 +
 22.1217 +load: url andDo: aBlock
 22.1218 +	skinImage onload: [
 22.1219 +		tileSize := skinImage width / 50.
 22.1220 +		aBlock value ].
 22.1221 +	skinImage src: url.
 22.1222 +! !
 22.1223 +
 22.1224 +!Point methodsFor: '*Serpentron'!
 22.1225 +
 22.1226 +rotate90ccw
 22.1227 +	^ self y @ self x negated
 22.1228 +!
 22.1229 +
 22.1230 +rotate90cw
 22.1231 +	^ self y negated @ self x
 22.1232 +! !
 22.1233 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/testing.js	Wed Feb 17 23:55:43 2016 +0300
    23.3 @@ -0,0 +1,9 @@
    23.4 +define([
    23.5 +    './deploy',
    23.6 +    'amber_core/SUnit',
    23.7 +    // --- packages used only during automated testing begin here ---
    23.8 +    'amber-serpentron/Serpentron-Tests'
    23.9 +    // --- packages used only during automated testing end here ---
   23.10 +], function (amber) {
   23.11 +    return amber;
   23.12 +});