Init
|
@ -0,0 +1,7 @@
|
|||
All art assets are licensed under Free Culture licenses that allow
|
||||
(commercial) redistribution, modification, etc.
|
||||
|
||||
They are mostly under Creative Commons licenses, or the Public Domain.
|
||||
|
||||
Each asset (under the "assets" directory) has a corresponding text-file with
|
||||
the author, the source URL, and licensing information.
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,11 @@
|
|||
love:
|
||||
zip -9r bats\&pray.love ./*
|
||||
|
||||
test: love
|
||||
love bats\&pray.love
|
||||
|
||||
clean:
|
||||
rm bats\&pray.love
|
||||
|
||||
all: love
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Game made for Open Jam 2020.
|
||||
|
||||
Tools used:
|
||||
LOVE2D (engine; ZLIB license)
|
||||
|
||||
Not much yet.
|
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 6.2 KiB |
|
@ -0,0 +1,3 @@
|
|||
Author: Jetrel
|
||||
Source: https://opengameart.org/content/castle-platformer
|
||||
License: CC0
|
|
@ -0,0 +1,3 @@
|
|||
Author: Pix3M
|
||||
Source: https://opengameart.org/content/pixel-fonts-by-pix3m
|
||||
License: CC-BY 3.0
|
|
@ -0,0 +1,3 @@
|
|||
Author: Pix3M
|
||||
Source: https://opengameart.org/content/pixel-fonts-by-pix3m
|
||||
License: CC-BY 3.0
|
After Width: | Height: | Size: 898 B |
|
@ -0,0 +1,3 @@
|
|||
Author: MoikMellah
|
||||
Source: https://opengameart.org/content/bat-32x32
|
||||
License: CC0
|
After Width: | Height: | Size: 2.0 KiB |
|
@ -0,0 +1,3 @@
|
|||
Author: MoikMellah
|
||||
Source: https://opengameart.org/content/animated-birds-32x32
|
||||
License: CC0
|
After Width: | Height: | Size: 898 B |
After Width: | Height: | Size: 549 B |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 2.0 KiB |
|
@ -0,0 +1,3 @@
|
|||
Author: Revangale
|
||||
Source: https://opengameart.org/content/owl-and-raven-sprites
|
||||
License: CC-BY-SA 3.0
|
After Width: | Height: | Size: 2.2 KiB |
|
@ -0,0 +1,3 @@
|
|||
Author: Refuzzle
|
||||
Source: https://opengameart.org/content/winter-birds
|
||||
License: CC0
|
|
@ -0,0 +1,28 @@
|
|||
RULES: Joust-style
|
||||
----------------------------------------
|
||||
|
||||
If a flier lands ON TOP of another, the lower flier is KILLED.
|
||||
If fliers run into each other HEAD-ON, they BOUNCE away from each other.
|
||||
|
||||
A flier can DASH to KILL another from ANY direction, but if they miss, they become DAZED.
|
||||
|
||||
A flier can SWIPE to KILL another flier HEAD-ON.
|
||||
|
||||
A flier can BLOCK both SWIPES and DASHES, and the attacker becomes DAZED.
|
||||
|
||||
A DAZED flier cannot BLOCK NOR DASH, and can be KILLED from ANY direction
|
||||
|
||||
Block has a cooldown; dashing's cooldown is daze; swipe has virtually no cooldown.
|
||||
|
||||
|
||||
CONTROLS: Joust-ish
|
||||
----------------------------------------
|
||||
(LEFT) point/walk left
|
||||
(RIGHT) point/walk right
|
||||
(UP) point up
|
||||
(DOWN) point down
|
||||
|
||||
(A) flap wings
|
||||
(B) dash where pointed
|
||||
(C) block where pointed
|
||||
(D) swipe
|
After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,14 @@
|
|||
<TextureAtlas imagePath="sheet.png">
|
||||
<!--Originally Kenney's asset (it still is). I only replaced 'alienPink_' with '' to make it work with animX and name alienPink.png was changed to idle.png. That's it!!-->
|
||||
<SubTexture name="alienPink.png" x="70" y="92" width="66" height="92"/>
|
||||
<SubTexture name="climb1.png" x="70" y="0" width="66" height="92"/>
|
||||
<SubTexture name="climb2.png" x="135" y="379" width="66" height="92"/>
|
||||
<SubTexture name="duck.png" x="0" y="380" width="69" height="71"/>
|
||||
<SubTexture name="hurt.png" x="0" y="288" width="69" height="92"/>
|
||||
<SubTexture name="jump.png" x="69" y="286" width="67" height="93"/>
|
||||
<SubTexture name="stand.png" x="69" y="379" width="66" height="92"/>
|
||||
<SubTexture name="swim1.png" x="0" y="193" width="69" height="95"/>
|
||||
<SubTexture name="swim2.png" x="0" y="96" width="70" height="97"/>
|
||||
<SubTexture name="walk1.png" x="69" y="193" width="68" height="93"/>
|
||||
<SubTexture name="walk2.png" x="0" y="0" width="70" height="96"/>
|
||||
</TextureAtlas>
|
|
@ -0,0 +1,8 @@
|
|||
animx=require 'animx'
|
||||
|
||||
alien=animx.newActor('alienPink.png')
|
||||
:switch('swim'):getAnimation():loop():setDelay(.4)
|
||||
|
||||
function love.draw()
|
||||
alien:draw(400,300,0,1,1,alien:getWidth()/2,alien:getHeight()/2)
|
||||
end
|
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,17 @@
|
|||
animx=require 'animx'
|
||||
|
||||
charAnim=animx.newAnimation{
|
||||
img='character.png',
|
||||
style='rough',
|
||||
noOfFrames=2,
|
||||
}:loop()
|
||||
|
||||
charAnim:setDelay(1,2) --the eye must be open for 2 seconds
|
||||
charAnim:setDelay(2,.1) --the eye must be closed for .1 second
|
||||
|
||||
function love.draw()
|
||||
charAnim:render(400,600,0,3,3,charAnim:getWidth()/2,charAnim:getHeight())
|
||||
end
|
||||
|
||||
--[[LEGAL NOTE: Pokemon is the copyright of Nintendo and all that! I have no right over this sprite nor do you. I used it because it was the only suitable image i found at the moment. (The internet shows you copyrighted stuff first) Please someone make a PR and replace this with a CC0 image!!
|
||||
]]
|
After Width: | Height: | Size: 57 KiB |
|
@ -0,0 +1,14 @@
|
|||
<TextureAtlas imageName="animation">
|
||||
<!--Hey Look I can have comments!-->
|
||||
<SubTexture name="1" x="267" y="183" width="24" height="24"/>
|
||||
<SubTexture name="2" x="291" y="183" width="24" height="24"/>
|
||||
|
||||
<!--and blank lines too-->
|
||||
<SubTexture name="3" x="315" y="183" width="24" height="24"/>
|
||||
<SubTexture name="4" x="339" y="183" width="24" height="24"/>
|
||||
<whatever name="5" x="363" y="183" width="24" height="24"/>
|
||||
<!--animX doesn't care about tag names-->
|
||||
<SubTexture name="6" x="387" y="183" width="24" height="24"/>
|
||||
<SubTexture name="7" x="411" y="183" width="24" height="24"/>
|
||||
</TextureAtlas>
|
||||
<!--however TextureAtlas has special meaning to animX>
|
|
@ -0,0 +1,7 @@
|
|||
animx=require 'animx'
|
||||
|
||||
anim=animx.newAnimation('atlas.png'):setStyle('rough'):loop()
|
||||
|
||||
function love.draw()
|
||||
anim:draw(400,300,0,15,15,24/2,24/2)
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
animx=require 'animx'
|
||||
|
||||
atlases={love.graphics.newImage("tc.png"),love.graphics.newImage("tc.png")}
|
||||
|
||||
-- This is how you can create an animation from scratch
|
||||
smokeAnim=animx.newAnimation{
|
||||
img=atlases[1],
|
||||
noOfFrames=17,
|
||||
tileWidth=30,tileHeight=55,
|
||||
style='rough',
|
||||
onCycleOver=function(this) print('Cycle #'..this:getTimes()) end,
|
||||
onAnimOver=function() print('Animation is over') end,
|
||||
onAnimStart=function() print('Starting Animation') end,
|
||||
onAnimRestart=function() print('Restarting Animation') end
|
||||
}:bounce(5)
|
||||
|
||||
--Try tweaking it with something like :rewind(2), :loop(2), :reverse(), :rewind(-1), :loop(-1)
|
||||
|
||||
-- Want to add a frame after you have created the animation?
|
||||
smokeAnim:addFrame(30*7,55,30,55)
|
||||
-- The above is exactly the same as doing
|
||||
--smokeAnim:addFrame(love.graphics.newQuad(30*7,55,30,55,smokeAnim:getTexture():getDimensions()))
|
||||
|
||||
love.update=function(dt) smokeAnim:update(dt) end
|
||||
--you could even say animx.update(dt)
|
||||
|
||||
function love.draw()
|
||||
love.graphics.print('Press Left/Right to change style!\nSpace to restart')
|
||||
smokeAnim:render(400,300,0,10,10,smokeAnim:getWidth()/2,smokeAnim:getHeight()/2)
|
||||
end
|
||||
|
||||
local i=1
|
||||
function love.keypressed(key)
|
||||
if key=='escape' then love.event.quit()
|
||||
elseif key=='space' then smokeAnim:restart()
|
||||
elseif key=='left' or key=='right' then
|
||||
i=i+(key=='left' and -1 or 1)
|
||||
i=i<1 and #atlases or (i>#atlases and 1 or i)
|
||||
smokeAnim:setAtlas(atlases[i])
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 20 KiB |
|
@ -0,0 +1,46 @@
|
|||
animx=require 'animx'
|
||||
evilImg=love.graphics.newImage('alienYellow.png')
|
||||
|
||||
--same as saying animx.newAnimatedSprite()
|
||||
evilChar=animx.newActor() --returns an empty actor with no animations
|
||||
|
||||
walkingDir='right'
|
||||
|
||||
evilChar:addAnimation('standing',{
|
||||
img=evilImg, --same as source/image/atlas/spritesheet/texure
|
||||
interval=1, --same as delay
|
||||
onAnimOver=function()
|
||||
evilChar:switch('walking')
|
||||
evilChar:flipX(walkingDir=='right')
|
||||
end,
|
||||
x=69,y=255, --same as offsetX and offsetY
|
||||
nq=1, --same as noOfQuads
|
||||
qw=66,qh=82 --same as quadWidth and quadHeight
|
||||
}):addAnimation('walking',{
|
||||
img=evilImg,
|
||||
delay=.5,
|
||||
quads={
|
||||
love.graphics.newQuad(0,339,68,83,evilImg:getDimensions()),
|
||||
love.graphics.newQuad(0,0,70,86,evilImg:getDimensions())
|
||||
}
|
||||
}):switch('standing')
|
||||
|
||||
evilChar:getAnimation('walking'):onAnimOver(function()
|
||||
evilChar:switch('standing')
|
||||
walkingDir=walkingDir=='left' and 'right' or 'left'
|
||||
end)
|
||||
|
||||
|
||||
--it'd hardly have any effect but just to demonstrate this feature
|
||||
evilChar:setStyle('smooth')
|
||||
|
||||
evilChar:exportToXML('alienYellow.xml')
|
||||
--See `Exporting Animation` for notes on exporting
|
||||
|
||||
love.graphics.setNewFont(25)
|
||||
function love.draw()
|
||||
love.graphics.printf("He..he..he (evil laugh)!!\nI can export this Animated Sprite to XML!!",0,20,800,'center')
|
||||
for i=1,5 do
|
||||
evilChar:draw(100+150*(i-1),600,0,2,2,evilChar:getWidth()/2,evilChar:getHeight())
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 297 KiB |
|
@ -0,0 +1,26 @@
|
|||
animx=require 'animx'
|
||||
|
||||
anim=animx.newAnimation{
|
||||
img='glitch_crab.png',
|
||||
spritesPerRow=6,
|
||||
interval=.03,
|
||||
tileHeight=516/4 -- try removing this and adding noOfFrames=24
|
||||
}:loop()
|
||||
--[[
|
||||
Note that unlike 'Working with TileSource' example we don't give
|
||||
the number of quads cause there's blank space at the end of the animation.
|
||||
So we leave it nil so that animX would calculate it on it's own
|
||||
]]
|
||||
|
||||
animx.hideWarnings=true --try removing this with animation.xml present
|
||||
anim:exportToXML('exported/animation.xml')
|
||||
--[[
|
||||
Note that animX will ignore any path thatchu give it!
|
||||
You can see it as a feature or as a bug - up to you!
|
||||
]]--
|
||||
|
||||
love.graphics.setNewFont(25)
|
||||
function love.draw()
|
||||
love.graphics.printf("He..he..he!!\nI can export this animation to XML!!",0,130,800,'center')
|
||||
anim:draw(400,300,0,1,1,108/2,160/2)
|
||||
end
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
animx=require 'animx'
|
||||
|
||||
--[[
|
||||
Since the spritesheet is symmetrical one-rowed tilesource we don't
|
||||
need to specify anything other then the number of images in the atlas!
|
||||
(Ofcourse specifying the image is must in any case)
|
||||
]]
|
||||
|
||||
skins={love.graphics.newImage('walk.png'),love.graphics.newImage('walk2.png')}
|
||||
|
||||
mushroomAnim=animx.newAnimation{
|
||||
img=skins[1],
|
||||
noOfFrames=4
|
||||
}:loop()
|
||||
|
||||
function love.draw()
|
||||
love.graphics.print("Press any key to change the skin!")
|
||||
mushroomAnim:draw(368,268)
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
mushroomAnim:setAtlas(mushroomAnim:getAtlas()==skins[1] and skins[2] or skins[1])
|
||||
end
|
After Width: | Height: | Size: 825 B |
After Width: | Height: | Size: 834 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 37 KiB |
|
@ -0,0 +1,20 @@
|
|||
animx=require 'animx'
|
||||
|
||||
alien=animx.newActor():
|
||||
addAnimation('idle',{
|
||||
img='front.png'
|
||||
}):
|
||||
addAnimation('walking','walk_sheet.png'):
|
||||
switch('idle'):setStyle('rough')
|
||||
|
||||
function love.draw()
|
||||
love.graphics.print('Press Space to Run')
|
||||
alien:draw(400,300,0,5,5,alien:getWidth()/2,alien:getHeight()/2)
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key=='space' then
|
||||
alien:switch('walking'):getAnimation('walking'):loop():setStyle('rough')
|
||||
end
|
||||
end
|
||||
|
After Width: | Height: | Size: 33 KiB |
|
@ -0,0 +1,13 @@
|
|||
<TextureAtlas imageName="whatever">
|
||||
<SubTexture name="1" x="0" y="0" width="72" height="97"/>
|
||||
<SubTexture name="2" x="72" y="0" width="72" height="97"/>
|
||||
<SubTexture name="3" x="144" y="0" width="72" height="97"/>
|
||||
<SubTexture name="4" x="0" y="97" width="72" height="97"/>
|
||||
<SubTexture name="5" x="72" y="97" width="72" height="97"/>
|
||||
<SubTexture name="6" x="144" y="97" width="72" height="97"/>
|
||||
<SubTexture name="7" x="0" y="194" width="72" height="97"/>
|
||||
<SubTexture name="8" x="72" y="194" width="72" height="97"/>
|
||||
<SubTexture name="9" x="144" y="194" width="72" height="97"/>
|
||||
<SubTexture name="10" x="0" y="291" width="72" height="97"/>
|
||||
<SubTexture name="11" x="72" y="291" width="72" height="97"/>
|
||||
</TextureAtlas>
|
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,85 @@
|
|||
animx=require 'animx'
|
||||
|
||||
--[[
|
||||
WARNING: Constrain yourself only with the library functions. Don't
|
||||
be inspired by how I implemented the movement part. We don't do jumping
|
||||
animation simply because it'd only make the code more difficult to read
|
||||
You can check up the modern platformer example for that!
|
||||
]]
|
||||
|
||||
characterImage=love.graphics.newImage('character.png')
|
||||
|
||||
idleAnim=animx.newAnimation{
|
||||
img=characterImage,
|
||||
style='rough',
|
||||
noOfFrames=1,
|
||||
tileWidth=16
|
||||
}
|
||||
|
||||
jumpAnim=animx.newAnimation{
|
||||
img=characterImage,
|
||||
frames={2,3}, --the animations consists of frame 2 and 3
|
||||
tileWidth=16
|
||||
}
|
||||
|
||||
walkAnim=animx.newAnimation{
|
||||
img=characterImage,
|
||||
startFrom=10,
|
||||
noOfQuads=2,
|
||||
delay=.2,
|
||||
tileWidth=16
|
||||
}:loop() --Try removing this loop
|
||||
|
||||
-- There are atleast three ways to add animations to an actor
|
||||
|
||||
--Method 1
|
||||
alien=animx.newActor{
|
||||
['idle']=idleAnim,
|
||||
['walking']=walkAnim
|
||||
}
|
||||
:onSwitch(function(this,prevState)
|
||||
print ((
|
||||
"I was %s before but I'm %s now!"
|
||||
):format(prevState,this.current))
|
||||
end)
|
||||
:switch('idle')
|
||||
|
||||
--Method 2:
|
||||
alien:addAnimation('jumping',jumpAnim)
|
||||
--Method 3:
|
||||
alien:addAnimation('climbing',{
|
||||
img=characterImage,
|
||||
frames={6,7}, --another way of adding frames
|
||||
tileWidth=16
|
||||
})
|
||||
alien:getAnimation('climbing'):loop()
|
||||
|
||||
ld=love.keyboard
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
animx.update(dt)
|
||||
|
||||
if ld.isDown('right') or ld.isDown('left') then
|
||||
alien:switch('walking')
|
||||
alien:flipX(ld.isDown('left'))
|
||||
alien.x=alien.x+200*dt*(ld.isDown('left') and -1 or 1)
|
||||
elseif ld.isDown('up') or ld.isDown('down') then
|
||||
alien:switch('climbing')
|
||||
alien.y=alien.y+200*dt*(ld.isDown('up') and -1 or 1)
|
||||
else
|
||||
for i=1,1000000 do
|
||||
--I call this function a million times and still no frame-drop!
|
||||
alien:switch('idle')
|
||||
--This is because this has no effect if alien is already idle!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--We exploit the fact that an actor in animX has no x and y members!
|
||||
alien.x,alien.y=400,300
|
||||
|
||||
function love.draw()
|
||||
alien:render(alien.x,alien.y,0,10,10,8,8)
|
||||
love.graphics.print(love.timer.getFPS())
|
||||
end
|
After Width: | Height: | Size: 2.4 KiB |
|
@ -0,0 +1,61 @@
|
|||
animx=require 'animx'
|
||||
|
||||
function love.load()
|
||||
down=animx.newAnimation{
|
||||
img='character.png',
|
||||
noOfFrames=3,
|
||||
tileHeight=128/4
|
||||
}:loop()
|
||||
left=animx.newAnimation{
|
||||
style='rough', -- since all sprites will share same image, we only need to set style once!
|
||||
img='character.png',
|
||||
startFrom=4, --start from 4 and go on till 4+3=7!!
|
||||
noOfFrames=3,
|
||||
tileHeight=128/4
|
||||
}:loop()
|
||||
right=animx.newAnimation{
|
||||
img='character.png',
|
||||
startFrom=7, --start from 7 and go on till 7+3=10!!
|
||||
noOfFrames=3,
|
||||
tileHeight=128/4
|
||||
}:loop()
|
||||
up=animx.newAnimation{
|
||||
img='character.png',
|
||||
startFrom=10, --start from 10 and go on till 10+3=13!!
|
||||
noOfFrames=3,
|
||||
tileHeight=128/4
|
||||
}:loop()
|
||||
character=animx.newActor{
|
||||
['down']=down,
|
||||
['left']=left,
|
||||
['right']=right, --> we could create right as mirror of left! but for now let it be!
|
||||
['up']=up,
|
||||
}:switch('down')
|
||||
SPEED=200
|
||||
characterX,characterY=400-16,300-16
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
animx.update(dt)
|
||||
if love.keyboard.isDown('down') or love.keyboard.isDown('up') then
|
||||
character:switch(love.keyboard.isDown('down') and 'down' or 'up')
|
||||
characterY=characterY+SPEED*dt*(love.keyboard.isDown('down') and 1 or -1)
|
||||
elseif love.keyboard.isDown('left') or love.keyboard.isDown('right') then
|
||||
character:switch(love.keyboard.isDown('right') and 'right' or 'left')
|
||||
characterX=characterX+SPEED*dt*(love.keyboard.isDown('right') and 1 or -1)
|
||||
else
|
||||
character:getAnimation():setFrame(2) --turns out 2 is the idle frame for all anim!!!
|
||||
character:stopAnimation()
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
character:draw(characterX,characterY,0,5,5,16,16)
|
||||
end
|
||||
|
||||
--[[
|
||||
In some cases the animation won't render (try pressing an arrow key twice)!
|
||||
This is the problem of real-time events not animX
|
||||
I am sure the user will come up with a solution!!
|
||||
(Please make a PR in that case :>)
|
||||
]]
|
|
@ -0,0 +1,21 @@
|
|||
animx=require 'animx'
|
||||
|
||||
samurai=animx.newActor('res/spritesheet.png'):loopAll()
|
||||
|
||||
samurai:getAnimation('dying'):bounce(-1)
|
||||
samurai:getAnimation('jumping'):setDelay(.5)
|
||||
|
||||
love.graphics.setNewFont(30)
|
||||
function love.draw()
|
||||
samurai:draw(400,300,0,1,1,samurai:getWidth()/2,samurai:getHeight()/2)
|
||||
love.graphics.printf('-> '..samurai:getState():upper(),0,440,800,'center')
|
||||
end
|
||||
|
||||
--Get all the states of samurai ('idle','blinking',etc) as a table
|
||||
local states,marker=samurai:getStates(),1
|
||||
samurai:switch(states[1])
|
||||
|
||||
function love.keypressed(key)
|
||||
marker=(marker+1)>#states and 1 or (marker+1)
|
||||
samurai:switch(states[marker])
|
||||
end
|
|
@ -0,0 +1,67 @@
|
|||
animx=require 'animx'
|
||||
|
||||
img=love.graphics.newImage('spritesheet.png')
|
||||
|
||||
samurai=animx.newActor():
|
||||
addAnimation('attack',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
nq=8
|
||||
}):addAnimation('blinking',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
y=275,
|
||||
nq=8
|
||||
}):
|
||||
addAnimation('die',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
y=2*275,
|
||||
nq=8
|
||||
}):
|
||||
addAnimation('hurt',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
y=3*275,
|
||||
nq=8
|
||||
}):
|
||||
addAnimation('standing',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
y=4*275,
|
||||
nq=8
|
||||
}):
|
||||
addAnimation('jumping',{
|
||||
img=img,
|
||||
tileWidth=332, --in this case we must give tileWidth
|
||||
tileHeight=275,
|
||||
y=5*275,
|
||||
nq=2
|
||||
}):
|
||||
addAnimation('walking',{
|
||||
img=img,
|
||||
tileHeight=275,
|
||||
y=6*275,
|
||||
nq=8
|
||||
}):
|
||||
loopAll()
|
||||
|
||||
samurai:exportToXML('spritesheet.xml')
|
||||
|
||||
love.graphics.setNewFont(30)
|
||||
function love.draw()
|
||||
samurai:draw(400,300,0,1,1,samurai:getWidth()/2,samurai:getHeight()/2)
|
||||
love.graphics.printf('-> '..samurai:getState():upper(),0,440,800,'center')
|
||||
end
|
||||
|
||||
--Get all the states of samurai ('idle','blinking',etc) as a table
|
||||
local states=samurai:getStates()
|
||||
local marker=1
|
||||
samurai:switch(states[1])
|
||||
|
||||
function love.keypressed(key)
|
||||
if key=='space' then
|
||||
marker=(marker+1)>#states and 1 or (marker+1)
|
||||
samurai:switch(states[marker])
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 1.5 MiB |
|
@ -0,0 +1,52 @@
|
|||
<TextureAtlas imageName="spritesheet">
|
||||
<SubTexture name="walking1" x="0" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking2" x="332" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking3" x="664" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking4" x="996" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking5" x="1328" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking6" x="1660" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking7" x="1992" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="walking8" x="2324" y="1650" width="332" height="275"/>
|
||||
<SubTexture name="dying1" x="0" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying2" x="332" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying3" x="664" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying4" x="996" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying5" x="1328" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying6" x="1660" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying7" x="1992" y="550" width="332" height="275"/>
|
||||
<SubTexture name="dying8" x="2324" y="550" width="332" height="275"/>
|
||||
<SubTexture name="blinking1" x="0" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking2" x="332" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking3" x="664" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking4" x="996" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking5" x="1328" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking6" x="1660" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking7" x="1992" y="275" width="332" height="275"/>
|
||||
<SubTexture name="blinking8" x="2324" y="275" width="332" height="275"/>
|
||||
<SubTexture name="attacking1" x="0" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking2" x="332" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking3" x="664" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking4" x="996" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking5" x="1328" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking6" x="1660" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking7" x="1992" y="0" width="332" height="275"/>
|
||||
<SubTexture name="attacking8" x="2324" y="0" width="332" height="275"/>
|
||||
<SubTexture name="jumping1" x="0" y="1375" width="332" height="275"/>
|
||||
<SubTexture name="jumping2" x="332" y="1375" width="332" height="275"/>
|
||||
<SubTexture name="hurt1" x="0" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt2" x="332" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt3" x="664" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt4" x="996" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt5" x="1328" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt6" x="1660" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt7" x="1992" y="825" width="332" height="275"/>
|
||||
<SubTexture name="hurt8" x="2324" y="825" width="332" height="275"/>
|
||||
<SubTexture name="standing1" x="0" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing2" x="332" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing3" x="664" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing4" x="996" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing5" x="1328" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing6" x="1660" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing7" x="1992" y="1100" width="332" height="275"/>
|
||||
<SubTexture name="standing8" x="2324" y="1100" width="332" height="275"/>
|
||||
</TextureAtlas>
|
After Width: | Height: | Size: 48 KiB |
|
@ -0,0 +1,16 @@
|
|||
animx=require 'animx'
|
||||
|
||||
anim=animx.newAnimation{
|
||||
img='glitch_asset.png',
|
||||
spritesPerRow=7,
|
||||
tileHeight=154, --I knew it'd be somewhere near 640/4!
|
||||
numberOfQuads=20 --try removing this!
|
||||
}:reverse() --reverse loop
|
||||
--[[
|
||||
Note that If we don't give the tileHeight then it'd be
|
||||
defaulted to image-height which we of-course don't want!!
|
||||
]]
|
||||
|
||||
function love.draw()
|
||||
anim:draw(400,300,0,3,3,108/2,160/2)
|
||||
end
|
|
@ -0,0 +1,109 @@
|
|||
# animX
|
||||
|
||||
*Animation in Love2d has never been so easy!!* Now I hate to look like a soap salesman... but animX has [all the features](#features-of-animx) you'd expect from an animation library plus some extra features of its own! I suggest you head over to [A quick walkthrough](#a-quick-walkthrough) if you are short on time!
|
||||
|
||||
## What animX is about?
|
||||
|
||||
animX is all about handling animations in a manner that makes your code much more declarative, much more readable, and much more shorter.
|
||||
|
||||
## Features of animX:
|
||||
-------------------------
|
||||
|
||||
- Has special Animation instances with animation modes like `loop`, `bounce`, `rewind`, etc!
|
||||
- Supports different delays for individual frames just like Bart's library but without consuming too much memory
|
||||
- Allows loading animations and animation instances from a metafile
|
||||
- Has special Animated Sprites aka *Actors* to handle animations (execution, transitions, etc) by their name
|
||||
- Allows loading group of animations and all animations for an *actor* from a metafile
|
||||
- Supports callback functions like `onSwitch`, `onFrameChange`,`onAnimOver`,`onCycleOver`,etc just like [Walt](https://github.com/davisdude/Walt)
|
||||
- Allows creating animation from single as well as multiple images (for *Actors* I mean)
|
||||
- Has a very comfortable animation extraction system supporting numerous algorithms **\***
|
||||
- After extracting animations you can export them to XML (again as a single entity or as group of animations)
|
||||
- Also supports animation's source styles like `rough`, `smooth` (just like Katsudo)
|
||||
- Has a number of aliases to make you feel it's *your* library and *you* wrote it!
|
||||
|
||||
> **\*** In case you don't have metafiles to work with!
|
||||
|
||||
------------------------------------------
|
||||
**Note:** For metafile, only XML data-format is supported (as of now). But I'll be happy to write for JSON (and other formats) if some-one really wants me to!
|
||||
|
||||
|
||||
## A Quick Walkthrough
|
||||
|
||||
Working with symmetric spritesheets is a *hell* lot easier with animX. Let's say we have this spritesheet:-
|
||||
<p align='center'>
|
||||
<img src='Examples/Exporting%20Animation/glitch_crab.png' title="The SpriteSheet for crab animation (Credit- Glitch)"><br/>
|
||||
</p>
|
||||
|
||||
There are 6 sprites per row and a total of 24 images!! So you do just this:-
|
||||
|
||||
```lua
|
||||
anim=animx.newAnimation{
|
||||
img='glitch_crab.png', --url/reference to the image
|
||||
spritesPerRow=6,
|
||||
noOfFrames=24
|
||||
}:loop()
|
||||
```
|
||||
And that's it! You loaded 24 quads in just four lines! (The last line only loops the animation which ofcourse is not necessary!)
|
||||
|
||||
> But what about huge non-symmetric spritesheets?
|
||||
|
||||
Let's say we have this spritesheet by Kenney and we want to animate this in Love2D (Note this spritesheet is unsymmetric with alternating width and height for each frame)
|
||||
|
||||
<p align='center'>
|
||||
<img src='Examples/Importing%20Animation%20from%20XML%20to%20Actor/kenney_asset.png' title="The SpriteSheet for walking animation (Credit- Kenney)"><br/>
|
||||
</p>
|
||||
|
||||
No probs. As long as you have an generic [XML metafile](Examples/Importing%20Animation%20from%20XML%20to%20Actor/walk_sheet.xml) describing the animation - this is a walk in the park - atleast with animX by your side:-
|
||||
|
||||
```lua
|
||||
animx=require 'animx'
|
||||
|
||||
alien=animx.newAnimation('res/spritesheet.png')
|
||||
--Note res/spritesheet.xml must be present!!
|
||||
|
||||
function love.draw()
|
||||
alien:draw()
|
||||
end
|
||||
```
|
||||
|
||||
But that was only for walking. What about jumping, swimming and all of these? Should one rely on multiple XML files for that? **No** To solve this problem animX has special *actors* which are nothing but animation holders and make switching between animations a lot easier
|
||||
|
||||
So to increase the bar let's say we have this image here with this difficult to parse [XML file](Examples/Side%20Scroller/res/spritesheet.xml) by the same name:
|
||||
|
||||
<p align='center'>
|
||||
<img width=664 height=481 src='Examples/Side%20Scroller/res/spritesheet.png' title="The SpriteSheet for our actor. Sorry about bad packing at some places! (Credit- Segel)"><br/>
|
||||
</p>
|
||||
|
||||
Since this image is symmetric we don't even need the metafile as demonstrated in [this example](Examples/Side%20Scroller/main2.lua) but since it's a good idea to keep data away from code here's how we do it with animX:-
|
||||
|
||||
```lua
|
||||
animx=require 'animx'
|
||||
|
||||
samurai=animx.newActor('res/spritesheet.png'):switch('running')
|
||||
|
||||
function love.draw()
|
||||
--This will display our Samurai running at the center of the screen
|
||||
samurai:draw(400,300,0,1,1,samurai:getWidth()/2,samurai:getHeight()/2)
|
||||
end
|
||||
```
|
||||
|
||||
Note that we are not doing ```animx.update(dt)``` in ``love.update`` only because there's nothing else in ``love.update`` and animX overrides it by default making work a little easier for us in such cases (where all that `love.update` contains is `animx.update`)
|
||||
|
||||
There are also other stuff such texture styles, animation modes, animation handlers, etc which we didn't talk here. But I've dedicated a short tutorial for that over [here](Examples)
|
||||
|
||||
|
||||
### Installing animX
|
||||
|
||||
Just drop the package (by the name `animx`) in a seperate folder and require it:-
|
||||
|
||||
```lua
|
||||
animx=require 'animx
|
||||
```
|
||||
|
||||
### Running Demos
|
||||
|
||||
animX comes with a lot of demos to get you started. These are available in the [demos](TODO) branch. You can run them with the latest (as of now) version of Love2D (11.3)
|
||||
|
||||
### Documentation
|
||||
|
||||
You can read the documentation over [here](https://github.com/YoungNeer/animX/wiki)
|
|
@ -0,0 +1,116 @@
|
|||
--[[
|
||||
The Actor Class for animX
|
||||
Author: Neer
|
||||
]]
|
||||
|
||||
local Actor={
|
||||
animations, --list of all the animations in the actor
|
||||
current, --the current animation (by it's name)
|
||||
p_onAnimSwitch, --handler called when an animation is switched [internal]
|
||||
}
|
||||
|
||||
--an internal function which just sets the default values
|
||||
function Actor:init()
|
||||
self.animations={}
|
||||
self.p_onAnimSwitch=function() end
|
||||
end
|
||||
|
||||
function Actor:switch(newState)
|
||||
local prevState=self.current
|
||||
if prevState==newState then return self end
|
||||
--This prevents a recursive situation!!
|
||||
if self:isActive() then self:stopAnimation() end
|
||||
self.current=newState
|
||||
self:p_onAnimSwitch(prevState)
|
||||
self:startAnimation()
|
||||
return self
|
||||
end
|
||||
|
||||
--Checks if the current animation of the actor is stopped
|
||||
function Actor:isActive()
|
||||
if not self:getCurrentAnimation() then return false end
|
||||
return self:getCurrentAnimation():isActive()
|
||||
end
|
||||
|
||||
--Stops the actor's animation
|
||||
function Actor:stopAnimation()
|
||||
if self:getCurrentAnimation() then
|
||||
self:getCurrentAnimation():stop()
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--Starts the animation for the actor
|
||||
function Actor:startAnimation()
|
||||
if self:getCurrentAnimation() then
|
||||
self:getCurrentAnimation():start()
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--These functions is defined in the main file
|
||||
Actor.addAnimation=nil
|
||||
Actor.exportToXML=nil
|
||||
|
||||
--Not to be confused with p_onAnimSwitch!
|
||||
function Actor:onSwitch(fn)
|
||||
self.p_onAnimSwitch=fn
|
||||
return self
|
||||
end
|
||||
|
||||
--Returns the given or current animation if given arg is nil
|
||||
function Actor:getAnimation(name)
|
||||
return self.animations[name or self.current]
|
||||
end
|
||||
|
||||
--Returns the current animation that's being rendered
|
||||
function Actor:getCurrentAnimation()
|
||||
return self:getAnimation(self.current)
|
||||
end
|
||||
|
||||
--Gets a table of all the states
|
||||
function Actor:getStates()
|
||||
local t={}
|
||||
for i in pairs(self.animations) do
|
||||
t[#t+1]=i
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--Loops all the animations in the actor
|
||||
function Actor:loopAll(...)
|
||||
for i in pairs(self.animations) do
|
||||
self.animations[i]:loop(...)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--Returns the name of the current animation
|
||||
function Actor:getName() return self.current end
|
||||
|
||||
--Returns the size of the current animation
|
||||
function Actor:getDimensions() return self:getCurrentAnimation():getDimensions() end
|
||||
function Actor:getWidth() return self:getCurrentAnimation():getWidth() end
|
||||
function Actor:getHeight() return self:getCurrentAnimation():getHeight() end
|
||||
|
||||
--Sets the style of the image
|
||||
function Actor:setStyle(val) self:getCurrentAnimation():setStyle(val) return self end
|
||||
|
||||
--Flips the current animation
|
||||
function Actor:flip(...) self:getCurrentAnimation():flip(...) return self end
|
||||
function Actor:flipX(...) self:getCurrentAnimation():flipX(...) return self end
|
||||
function Actor:flipY(...) self:getCurrentAnimation():flipY(...) return self end
|
||||
|
||||
function Actor:render(...)
|
||||
self:getCurrentAnimation():render(...)
|
||||
end
|
||||
|
||||
--==Aliases==--
|
||||
|
||||
Actor.getCurrentAnim=Actor.getCurrentAnimation
|
||||
Actor.getState=Actor.getName
|
||||
Actor.changeAnim=Actor.switch
|
||||
Actor.set=Actor.switch
|
||||
Actor.draw=Actor.render
|
||||
|
||||
return Actor
|
|
@ -0,0 +1,395 @@
|
|||
--[[
|
||||
The Animation Class for animX
|
||||
Author: Neer
|
||||
]]
|
||||
|
||||
--Unlike iffy we use metatables
|
||||
local Animation={
|
||||
texture, --the spritesheet for the animation
|
||||
frames, --the frames in the animation
|
||||
duration, --duration for each sprite- a smart table (idea stolen from Walt)
|
||||
cache, --an internal variable to account for same duration across multiple frames
|
||||
mode, --the mode of the animation - {'loop'/'rewind'/'once'/'bounce',times}
|
||||
direction, --the sense of the animation
|
||||
curFrame, --the current frame that's being rendered
|
||||
active, --whether the animation is being played or not
|
||||
curTimes, --keeps count of number of times animation executed
|
||||
timer, --an internal timer variable
|
||||
p_flipX, --whether to flip along x-axis [internal]
|
||||
p_flipY, --whether to flip along y-axis [internal]
|
||||
p_onCycleOver, --handler called when an animation cycle is complete [internal]
|
||||
p_onAnimOver, --handler called when the entire animation is over [internal]
|
||||
p_onAnimStart, --handler called when the animation is started [internal]
|
||||
p_onAnimRestart, --handler called whenever the animation is restarted [internal]
|
||||
p_onChange, --handler called whenever current frame is changed [internal]
|
||||
p_onUpdate, --called at every frame regardless of it's active property [internal]
|
||||
}
|
||||
|
||||
--an internal function which just sets the default values
|
||||
function Animation:init(startingFrame,delay)
|
||||
self:setDelay(delay)
|
||||
self.startingFrame=startingFrame
|
||||
self:start()
|
||||
self.mode={'loop',1}
|
||||
end
|
||||
|
||||
--[[the addFrame concept was stolen from BartBes' animation library. Anyways -
|
||||
what this func does is create a new quad and associate it with the given
|
||||
animation. The frame would be appended to the last of the framelist!
|
||||
]]
|
||||
function Animation:addFrame(x,y,w,h,delay)
|
||||
if y then
|
||||
--User passed in position of the quad
|
||||
table.insert(self.frames,
|
||||
love.graphics.newQuad(x,y,w,h,self:getAtlas():getDimensions())
|
||||
)
|
||||
else
|
||||
--User passed in a quad
|
||||
table.insert(self.frames,x)
|
||||
end
|
||||
|
||||
--Note we are not calling setDelay cause it's a new frame!
|
||||
if delay and delay~=self.duration[#self.duration] then
|
||||
self.duration[#self.duration+1]=delay
|
||||
self.cache[#self.cache+1]=1
|
||||
else
|
||||
self.cache[#self.cache]=self.cache[#self.cache]+1
|
||||
end
|
||||
end
|
||||
|
||||
--Not to be confused with p_onAnimOver!
|
||||
function Animation:onAnimOver(fn)
|
||||
self.p_onAnimOver=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Not to be confused with p_onCycleOver!
|
||||
function Animation:onCycleOver(fn)
|
||||
self.p_onCycleOver=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Not to be confused with p_onAnimStart!
|
||||
function Animation:onAnimStart(fn)
|
||||
self.p_onAnimStart=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Not to be confused with p_onAnimRestart!
|
||||
function Animation:onAnimRestart(fn)
|
||||
self.p_onAnimRestart=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Not to be confused with p_onChange!
|
||||
function Animation:onChange(fn)
|
||||
self.p_onChange=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Not to be confused with p_onUpdate!
|
||||
function Animation:onUpdate(fn)
|
||||
self.p_onUpdate=fn or function() end
|
||||
return self
|
||||
end
|
||||
|
||||
--Rewind the animation any number of times, (nil or negative)=>infinite
|
||||
function Animation:rewind(times)
|
||||
self.mode={'rewind',times or -1}
|
||||
return self
|
||||
end
|
||||
|
||||
--Similar to rewind except the definition of 'cycle' is different!
|
||||
--also `bounce` by default reverses only once while `rewind` rewinds forever
|
||||
function Animation:bounce(times)
|
||||
self.mode={'bounce',times or 1}
|
||||
return self
|
||||
end
|
||||
|
||||
--loops the animation in obverse or reverse direction (obverse by default)
|
||||
function Animation:loop(times,dir)
|
||||
self.mode={'loop',times or -1}
|
||||
self.direction=dir or 1
|
||||
return self
|
||||
end
|
||||
|
||||
--same as loop just direction is always reversed
|
||||
function Animation:reverse(times)
|
||||
return self:loop(times,-1)
|
||||
end
|
||||
|
||||
--Executes an animation once in the obverse direction!
|
||||
function Animation:once()
|
||||
return self:loop(1,1)
|
||||
end
|
||||
|
||||
--restarts the animation from where it was
|
||||
function Animation:restart()
|
||||
self.active=true
|
||||
self.curFrame=self.startingFrame
|
||||
self.curTimes=0
|
||||
self.p_onAnimRestart(self)
|
||||
end
|
||||
|
||||
--Returns the total number of frames in animation
|
||||
function Animation:getSize() return #self.frames end
|
||||
|
||||
--Returns the total number of times the animation has been played
|
||||
function Animation:getTimes() return self.curTimes end
|
||||
|
||||
--Returns the current Frame of the animation (a number)
|
||||
function Animation:getCurrentFrame() return math.max(1,math.min(self.curFrame,self:getSize())) end
|
||||
|
||||
--Returns the current quad that's being rendered (a Quad)
|
||||
function Animation:getCurrentQuad() return self.frames[self:getCurrentFrame()] end
|
||||
|
||||
--Returns whether or not is the animation active!
|
||||
function Animation:isActive() return self.active end
|
||||
|
||||
--Returns the dimensions of the current frame
|
||||
function Animation:getDimensions() local x,y,w,h=self:getCurrentQuad():getViewport(); return w,h end
|
||||
function Animation:getWidth() return select(1,self:getDimensions()) end
|
||||
function Animation:getHeight() return select(2,self:getDimensions()) end
|
||||
|
||||
function Animation:setStyle(style)
|
||||
assert(style=='rough' or style=='smooth',"animX Error!! Expected 'smooth' or 'rough' in setStyle fn")
|
||||
if style=='rough' then
|
||||
self:getImage():setFilter('nearest','nearest')
|
||||
else
|
||||
self:getImage():setFilter('linear','linear')
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--Returns the texture for the animation (an Image)
|
||||
function Animation:getAtlas() return self.texture end
|
||||
|
||||
--Sometimes you may want to change the atlas (maybe for something like character clothes)
|
||||
--The next fn changes the texture for the animation
|
||||
function Animation:setAtlas(img)
|
||||
if type(img)=='string' then img=love.graphics.newImage(img) end
|
||||
self.texture = img
|
||||
return self
|
||||
end
|
||||
|
||||
--Sets the current frame as n
|
||||
function Animation:jumpToFrame(n)
|
||||
assert(n>=1 and n<=self:getSize(), "animX Error: Frame is out of bounds!")
|
||||
self.curFrame=n
|
||||
return self
|
||||
end
|
||||
|
||||
--To be called only when an animation just starts (private fn)
|
||||
function Animation:start()
|
||||
self.p_onAnimStart(self)
|
||||
self.curFrame=self.startingFrame
|
||||
self.direction=1
|
||||
self.active=true
|
||||
self.timer=0
|
||||
self.curTimes=0
|
||||
end
|
||||
|
||||
--To be called only when an animation has completed a 'cycle' (private fn)
|
||||
function Animation:cycle()
|
||||
self.curTimes=self.curTimes+1
|
||||
self.p_onCycleOver(self)
|
||||
end
|
||||
|
||||
--To be called only when the current frame has to be changed (private fn)
|
||||
function Animation:change()
|
||||
self.curFrame=self.curFrame+self.direction
|
||||
self.p_onChange(self)
|
||||
end
|
||||
|
||||
--Stops the animation! Use anim.active=false if you don't want to trigger any callback!
|
||||
function Animation:stop()
|
||||
--It is important that active is first set to false and then handler is called
|
||||
self.active=false
|
||||
self.p_onAnimOver(self)
|
||||
end
|
||||
|
||||
--gets the duration of the given frame or current frame if provided nil
|
||||
function Animation:getDelay(frame)
|
||||
frame=frame or self:getCurrentFrame()
|
||||
--u for cache and v for duration
|
||||
local u,v=1,1
|
||||
assert(frame>=1 and frame<=self:getSize(),"animX Error: Frame is out of bounds!")
|
||||
for i=1,self:getSize() do
|
||||
if u>self.cache[v] then u=1 v=v+1 end
|
||||
if i==frame then
|
||||
return self.duration[v]
|
||||
end
|
||||
u=u+1
|
||||
end
|
||||
end
|
||||
|
||||
--sets the duration of the given frame or all frames if only one arg
|
||||
function Animation:setDelay(frame,delay)
|
||||
if not delay then
|
||||
--Set delay for all frames
|
||||
delay,frame=frame
|
||||
self.duration={delay}
|
||||
self.cache={self:getSize()}
|
||||
return self
|
||||
end
|
||||
--Set delay for only one frame
|
||||
assert(frame>=1 and frame<=self:getSize(),"animX Error: Frame is out of bounds!")
|
||||
|
||||
local u,v=1,1
|
||||
|
||||
for i=1,self:getSize() do
|
||||
if u>self.cache[v] then u=1 v=v+1 end
|
||||
if i==frame then
|
||||
--If same delay as before then breakout!
|
||||
if delay==self.duration[v] then break end
|
||||
if self.cache[v]==1 then
|
||||
--This is the most simple case (when no buffer)
|
||||
self.duration[v]=delay
|
||||
--so in other cases self.cache[v] is asserted to be >1
|
||||
elseif u==1 then
|
||||
--for beginning of the buffer
|
||||
table.insert(self.duration,v+1,self.duration[v])
|
||||
table.insert(self.cache,v+1,self.cache[v]-1)
|
||||
self.duration[v],self.cache[v]=delay,1
|
||||
elseif self.cache[v]==u then
|
||||
--for ending of the buffer
|
||||
table.insert(self.duration,v+1,delay)
|
||||
table.insert(self.cache,v+1,1)
|
||||
self.cache[v]=self.cache[v]-1
|
||||
else
|
||||
--at the middle of the buffer (darn it!)
|
||||
table.insert(self.duration,v+1,self.duration[v])
|
||||
table.insert(self.duration,v+1,delay)
|
||||
table.insert(self.cache,v+1,self.cache[v]-u)
|
||||
table.insert(self.cache,v+1,1)
|
||||
self.cache[v]=self.cache[v]-1
|
||||
end
|
||||
end
|
||||
u=u+1
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--gets the current animation mode
|
||||
function Animation:getMode()
|
||||
return self.mode and self.mode[1]
|
||||
end
|
||||
|
||||
--check if current mode is equal to one of the given modes
|
||||
function Animation:isMode(...)
|
||||
for i=1,select('#',...) do
|
||||
if self.mode[1]==select(i,...) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Animation:update(dt)
|
||||
self:p_onUpdate(dt)
|
||||
if not self.active then return end
|
||||
|
||||
self.timer=self.timer+dt
|
||||
|
||||
--Get the delay for the current frame!
|
||||
local delay=self:getDelay(self.curFrame)
|
||||
|
||||
if self.timer>delay then
|
||||
self.timer=self.timer%delay
|
||||
self:change()
|
||||
if self.curFrame>self:getSize() then
|
||||
self:cycle()
|
||||
if self:getMode()=='bounce' then
|
||||
--If we are bouncing and we are done then stop
|
||||
if self.mode[2]>0 and self.curTimes>=self.mode[2] then return self:stop() end
|
||||
end
|
||||
if self:isMode('bounce','rewind') then
|
||||
--If we are bouncing and we are NOT done or if we are rewinding then continue
|
||||
self.curFrame=self:getSize()
|
||||
self.direction=-1
|
||||
elseif self:getMode()=='loop' then
|
||||
--If we are looping in the obverse direction and we are done then stop
|
||||
--Regardless of whether we are done reset the current frame back to 1
|
||||
if self.direction==1 then
|
||||
self.curFrame=1
|
||||
if self.mode[2]>0 and self.curTimes>=self.mode[2] then return self:stop() end
|
||||
end
|
||||
else
|
||||
--I think I was drunk when I wrote this section but I'm letting it be
|
||||
--just in case I wasn't drunk!
|
||||
if self.mode[2]>0 and self.curTimes>=self.mode[2] then
|
||||
return self:stop()
|
||||
else
|
||||
self.curFrame=self:getSize()
|
||||
self:cycle()
|
||||
end
|
||||
end
|
||||
|
||||
elseif self.curFrame<1 then
|
||||
self.curFrame=1
|
||||
|
||||
if self:getMode()=='bounce' then
|
||||
self:cycle()
|
||||
end
|
||||
if self:isMode('bounce','rewind') then
|
||||
if self.mode[2]>0 and self.curTimes>=self.mode[2] then self:stop()
|
||||
else
|
||||
self.direction=1
|
||||
end
|
||||
elseif self:getMode()=='loop' then
|
||||
if self.mode[2]>0 and self.curTimes>=self.mode[2] then self:stop()
|
||||
else
|
||||
self:cycle()
|
||||
if self.mode[2]>0 and self.curTimes==self.mode[2] then return self:stop() end
|
||||
self.curFrame=self:getSize()
|
||||
end
|
||||
else
|
||||
self:stop()
|
||||
end
|
||||
end
|
||||
self.curFrame=math.max(1,self.curFrame)
|
||||
end
|
||||
end
|
||||
|
||||
--Whether to flip horizontally and/or vertically
|
||||
function Animation:flip(flipX,flipY)
|
||||
self.p_flipX,self.p_flipY=flipX,flipY
|
||||
return self
|
||||
end
|
||||
|
||||
--Specifically flip only along one axis!
|
||||
function Animation:flipX(b) return self:flip(b) end
|
||||
function Animation:flipY(b) return self:flip(nil,b) end
|
||||
|
||||
function Animation:render(x,y,r,sx,sy,ox,oy,...)
|
||||
sx,sy=sx or 1, sy or 1
|
||||
sx=self.p_flipX and -sx or sx
|
||||
sy=self.p_flipY and -sy or sy
|
||||
love.graphics.draw(
|
||||
self:getTexture(),self:getCurrentQuad(),
|
||||
x,y,r,sx,sy,ox,oy,...
|
||||
)
|
||||
end
|
||||
|
||||
--This function is not defined here but on the main library file!
|
||||
Animation.exportToXML=nil
|
||||
|
||||
--Just setting some aliases- kinda my speciality
|
||||
|
||||
Animation.getTexture=Animation.getAtlas
|
||||
Animation.getImage=Animation.getAtlas
|
||||
Animation.getSource=Animation.getAtlas
|
||||
Animation.setTexture=Animation.setAtlas
|
||||
Animation.setSource=Animation.setAtlas
|
||||
Animation.setImage=Animation.setAtlas
|
||||
Animation.getTotalFrames=Animation.getTimes
|
||||
Animation.draw=Animation.render
|
||||
Animation.goToFrame=Animation.jumpToFrame
|
||||
Animation.setFrame=Animation.jumpToFrame
|
||||
Animation.getActive=Animation.isActive
|
||||
Animation.onAnimationStart=Animation.onAnimStart
|
||||
Animation.onAnimationOver=Animation.onAnimOver
|
||||
Animation.onAnimationRestart=Animation.onAnimRestart
|
||||
Animation.onFrameChange=Animation.onChange
|
||||
Animation.onTick=Animation.onUpdate
|
||||
|
||||
return Animation
|
|
@ -0,0 +1,468 @@
|
|||
local animx={
|
||||
animObjs={} --the animation objects that were created
|
||||
}
|
||||
|
||||
local LIB_PATH=...
|
||||
|
||||
local function lastIndexOf(str,char)
|
||||
for i=str:len(),1,-1 do if str:sub(i,i)==char then return i end end
|
||||
end
|
||||
|
||||
local function fileExists(url)
|
||||
return love.filesystem.getInfo(url) and
|
||||
love.filesystem.getInfo(url).type=="file"
|
||||
end
|
||||
|
||||
local imgCache = {}
|
||||
|
||||
local function newImage(path)
|
||||
if not imgCache[path] then
|
||||
imgCache[path] = love.graphics.newImage(path)
|
||||
end
|
||||
return imgCache[path]
|
||||
end
|
||||
|
||||
--Borrowed from [euler](https://github.com/YoungNeer/euler)
|
||||
function round(value,precision)
|
||||
local temp = 10^(precision or 0)
|
||||
if value >= 0 then
|
||||
return math.floor(value * temp + 0.5) / temp
|
||||
else
|
||||
return math.ceil(value * temp - 0.5) / temp
|
||||
end
|
||||
end
|
||||
|
||||
--removes the path and only gets the filename
|
||||
local function removePath(filename)
|
||||
local pos=1
|
||||
local i = string.find(filename,'[\\/]', pos)
|
||||
pos=i
|
||||
while i do
|
||||
i = string.find(filename,'[\\/]', pos)
|
||||
if i then
|
||||
pos = i + 1
|
||||
else i=pos break
|
||||
end
|
||||
end
|
||||
if i then filename=filename:sub(i) end
|
||||
return filename
|
||||
end
|
||||
|
||||
--remove extension from a file as well as remove the path
|
||||
local function removeExtension(filename,dontremovepath)
|
||||
if not dontremovepath then filename=removePath(filename) end
|
||||
return filename:sub(1,lastIndexOf(filename,".")-1)
|
||||
end
|
||||
|
||||
local Animation=require (LIB_PATH..'.animation')
|
||||
local Actor=require (LIB_PATH..'.actor')
|
||||
|
||||
--[[
|
||||
Creates a new animation either from scratch or from an XML file!
|
||||
(Note that quads are added in LtR-TtB fashion)
|
||||
@Params:
|
||||
@OverLoad-1:
|
||||
img - The URL of the image. An XML file must exist by the same name!
|
||||
|
||||
@OverLoad-2:
|
||||
params - A table of parameters (something I stole from sodapop)
|
||||
img - The image (could be a reference or url)
|
||||
x,y - The offset from where to start extracting the quads (0,0)
|
||||
qw,qh - The dimensions of the quad
|
||||
sw,sh - The dimensions of the image (auto-calc'd if nil)
|
||||
spr - The number of sprites per row
|
||||
nq - The number of quads to extract (auto-calc'd if nil)
|
||||
quads - An already existing table of quads for animation
|
||||
frames - The frames (by number) that u wanna add in the animation
|
||||
style - The style of the image (just something I stole from katsudo)
|
||||
startingFrame - The frame from where to start the animation (must exist!)
|
||||
startFrom - The frame from where to start ripping the sprites
|
||||
delay - The interval between any two frames
|
||||
onAnimOver - What happens when the animation is over
|
||||
onAnimStart - What happens when the animation is started
|
||||
onAnimRestart - What happens when the animation is restarted
|
||||
onCycleOver - What happens when one cycle is over
|
||||
onChange - What happens at every animation frame change
|
||||
onUpdate - What happens at every frame
|
||||
@Returns
|
||||
An Animation Instance
|
||||
--]]
|
||||
function animx.newAnimation(params)
|
||||
|
||||
local img,quads,sw,sh,startingFrame,delay
|
||||
local onAnimStart,onAnimRestart,onAnimOver,onCycleOver,onChange,onUpdate
|
||||
|
||||
if type(params)=='string' then
|
||||
--Overload 1
|
||||
img=(params)
|
||||
sw,sh=img:getDimensions()
|
||||
quads=animx.newAnimationXML(img,removeExtension(params,true)..'.xml')
|
||||
startingFrame,delay=1,.1
|
||||
else
|
||||
--Overload 2
|
||||
img=params.img or params.source or params.image or params.texture or params.atlas or params.spritesheet
|
||||
assert(img,"animX Error: Expected Image or URI in `newAnimation`!")
|
||||
img = type(img)=='string' and newImage(img) or img
|
||||
|
||||
sw=params.sw or params.imgWidth or params.textureWidth or img:getWidth()
|
||||
sh=params.sh or params.imgHeight or params.textureHeight or img:getHeight()
|
||||
local x,y=params.x or params.offsetX or 0, params.y or params.y or params.offsetY or 0
|
||||
|
||||
local nq=params.nq or params.images or params.noOfTiles or params.numberOfQuads or params.noOfQuads or params.noOfFrames
|
||||
|
||||
--The tile-height will by default be the height of the image!
|
||||
local qw=params.qw or params.quadWidth or params.frameWidth or params.tileWidth
|
||||
local qh=params.qh or params.quadHeight or params.frameHeight or params.tileHeight
|
||||
local frames=params.frames or {}
|
||||
local spr=params.spr or params.spritesPerRow or params.tilesPerRow or params.quadsPerRow
|
||||
quads=params.quads or {}
|
||||
|
||||
if spr and nq then
|
||||
assert(nq>=spr,"animX Error: No of sprites per row can't be less than total number of quads!!!")
|
||||
end
|
||||
|
||||
--[[
|
||||
User has to give atleast one of quad-width and
|
||||
number of sprites per row to calculate no of quads
|
||||
]]--
|
||||
|
||||
--if user has not given sprites per row then let qh simply be image height
|
||||
if not spr then
|
||||
qh=qh or img:getHeight()
|
||||
else
|
||||
if not qh then
|
||||
assert(nq,"animX Error: You have to give number of quads in this case!!!")
|
||||
end
|
||||
qh=qh or img:getHeight()/(nq/spr)
|
||||
end
|
||||
|
||||
if qw then
|
||||
if #frames>0 then
|
||||
--If user has given us a bunch of frames then we set this to zero if nil
|
||||
nq=nq or 0
|
||||
else
|
||||
--Otherwise we make the number of quads equal to the max no of quads
|
||||
nq = math.min(nq or math.huge, math.floor(sw/qw) * math.floor(sh/qh))
|
||||
end
|
||||
elseif spr then
|
||||
--If user has given us number of sprites per row
|
||||
nq=math.min(nq or math.huge,spr*math.floor(sh/qh))
|
||||
elseif #quads>0 then
|
||||
--If user has given us some quads to work with - we set this to zero if nil
|
||||
nq=nq or 0
|
||||
end
|
||||
|
||||
spr = spr or nq
|
||||
|
||||
--If user has not given anything dissecting then make the image a quad!
|
||||
if not qw and not spr then
|
||||
spr,nq=1,1
|
||||
qw,qh=img:getWidth(),img:getHeight()
|
||||
end
|
||||
|
||||
if #quads==0 or not nq then
|
||||
if #frames==0 then
|
||||
assert(spr and spr>0,"animX Error: Sprites per row can't be zero!!")
|
||||
else
|
||||
assert(qw,"animX Error: You must give tileWidth in this case")
|
||||
end
|
||||
end
|
||||
|
||||
--If user has not given the tileWidth then calculate it based on number of sprites per row
|
||||
if nq>0 and spr then
|
||||
qw=qw or img:getWidth()/spr
|
||||
end
|
||||
|
||||
assert(
|
||||
qw~=1/0,
|
||||
'animX Error: Oops! Something bad happened! Please do report the error!'
|
||||
)
|
||||
|
||||
local style=params.style
|
||||
if style=='rough' then img:setFilter('nearest','nearest') end
|
||||
|
||||
local startPoint=params.startFrom or params.startPoint
|
||||
delay=params.delay or params.interval or .1
|
||||
startingFrame=params.startingFrame or 1
|
||||
onAnimOver=params.onAnimOver or params.onAnimEnd or params.onAnimationOver or params.onAnimationEnd
|
||||
onAnimStart=params.onAnimStart or params.onAnimationStart
|
||||
onAnimRestart=params.onAnimRestart or params.onAnimationRestart
|
||||
onChange=params.onChange or params.onFrameChange
|
||||
onUpdate=params.onUpdate or params.onTick
|
||||
onCycleOver=params.onCycleOver or params.onCycleEnd
|
||||
|
||||
--We need the quad dimensions if user has not given us a bunch of quads
|
||||
if #quads==0 then
|
||||
assert(qw and qh,"animX Error: Quad dimensions coudn't be calculated in `newAnimation`!")
|
||||
--IMPORTANT: We want integers not highly precise floats or doubles
|
||||
qw,qh=round(qw),round(qh)
|
||||
end
|
||||
|
||||
--Calculate offset from the startpoint
|
||||
if startPoint then
|
||||
x=((startPoint-1)*qw)%sw
|
||||
y=qh*math.floor(((startPoint-1)*qw)/sw)
|
||||
end
|
||||
|
||||
--Add given frames to the quads table
|
||||
for i=1,#frames do
|
||||
quads[#quads+1]=love.graphics.newQuad(
|
||||
((frames[i]-1)*qw)%sw,
|
||||
qh*math.floor(((frames[i]-1)*qw)/sw),
|
||||
qw,qh,sw,sh
|
||||
)
|
||||
end
|
||||
|
||||
local offsetx=x
|
||||
|
||||
assert(nq,"animX Error!! Number of quads couldn't be calculated!")
|
||||
|
||||
for i = 1, nq do
|
||||
if x >= sw then
|
||||
y = y + qh
|
||||
x = offsetx
|
||||
end
|
||||
quads[#quads+1]= love.graphics.newQuad(x, y, qw, qh, sw, sh)
|
||||
x = x + qw
|
||||
end
|
||||
end
|
||||
|
||||
local animation_obj={
|
||||
['texture']=img,
|
||||
['frames']=quads
|
||||
}
|
||||
table.insert(animx.animObjs,setmetatable(animation_obj,{__index=Animation}))
|
||||
animation_obj:onAnimStart(onAnimStart):init(startingFrame,delay)
|
||||
animation_obj
|
||||
:onAnimOver(onAnimOver)
|
||||
:onAnimRestart(onAnimRestart)
|
||||
:onChange(onChange)
|
||||
:onCycleOver(onCycleOver)
|
||||
:onUpdate(onUpdate)
|
||||
|
||||
return animx.animObjs[#animx.animObjs]
|
||||
end
|
||||
|
||||
--[[:-
|
||||
Creates a new Actor either from scratch or from an XML file
|
||||
@params:
|
||||
@Overload-1
|
||||
Takes no parameters. Returns an empty actor
|
||||
@Overload-2
|
||||
metafile:
|
||||
A string referring to the URL of the XML file containing
|
||||
the information about all the animations for the actor
|
||||
(you could ofcourse add animations later on if you want)
|
||||
If this is nil then an empty actor (without animations) is created
|
||||
@Overload-3
|
||||
{...}: A list of all the animations
|
||||
@returns:
|
||||
An Actor instance
|
||||
-:]]
|
||||
function animx.newActor(arg)
|
||||
local actor={}
|
||||
setmetatable(actor,{__index=Actor}):init()
|
||||
if type(arg)=='string' then
|
||||
--User gave us a link to the XML file
|
||||
local img=newImage(arg)
|
||||
local anims=animx.newActorXML(img,removeExtension(arg,true)..'.xml')
|
||||
for i in pairs(anims) do
|
||||
actor:addAnimation(i,{
|
||||
['img']=img,
|
||||
['quads']=anims[i]
|
||||
})
|
||||
end
|
||||
return actor
|
||||
else
|
||||
if arg then
|
||||
--User gave us a table of animations for the actor
|
||||
for name,anim in pairs(arg) do
|
||||
actor:addAnimation(name,anim)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Otherwise User gave us nothing
|
||||
- meaning empty actor has to be created
|
||||
]]
|
||||
end
|
||||
return actor
|
||||
end
|
||||
|
||||
--[[
|
||||
Adds an animation to the actor
|
||||
@Params
|
||||
name - The name of the animation
|
||||
@Overload-1
|
||||
anim - An animation instance
|
||||
@Overload-2
|
||||
anim - A to-be-created animation instance
|
||||
@Returns
|
||||
The actor itself
|
||||
]]--
|
||||
function Actor:addAnimation(name,anim)
|
||||
if anim.cache and anim.direction then
|
||||
--User provided an already created animation
|
||||
self.animations[name]=anim
|
||||
else
|
||||
--User provided a to-be-created animation
|
||||
self.animations[name]=animx.newAnimation(anim)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--[[
|
||||
Creates a new animation from XML file!
|
||||
You'll most of the time use newAnimation to indirectly call this fn!
|
||||
@Params:-
|
||||
image - The Image for the animation
|
||||
@Returns:-
|
||||
An array of quads denoting the animation
|
||||
]]--
|
||||
function animx.newAnimationXML(image,filename)
|
||||
local i,t,sw,sh=1,{},image:getDimensions()
|
||||
for line in love.filesystem.lines(filename) do
|
||||
if i>1 and line:match('%a') and not line:match('<!') and line~="</TextureAtlas>" then
|
||||
local _, frameNo = string.match(line, "name=([\"'])(.-)%1")
|
||||
frameNo=tonumber(frameNo)
|
||||
--Frames must start from 1!
|
||||
if not frameNo or frameNo<=0 then goto continue end
|
||||
|
||||
assert(not t[frameNo],
|
||||
"animX Error!! Duplicate Frames found for ("..frameNo..") for "..filename
|
||||
)
|
||||
local _, x = string.match(line, "x=([\"'])(.-)%1")
|
||||
local _, y = string.match(line, "y=([\"'])(.-)%1")
|
||||
local _, width = string.match(line, "width=([\"'])(.-)%1")
|
||||
local _, height = string.match(line, "height=([\"'])(.-)%1")
|
||||
|
||||
t[frameNo]=love.graphics.newQuad(x,y,width,height,sw,sh)
|
||||
::continue::
|
||||
end
|
||||
i=i+1
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--[[
|
||||
Creates a new actor from XML file!
|
||||
You'll most of the time use newActor to indirectly call this fn!
|
||||
@Params:-
|
||||
image - The Image for the animation
|
||||
@Returns:-
|
||||
A table/linkhash of quads indexed by the animation name and then the frame number
|
||||
]]--
|
||||
function animx.newActorXML(image,filename)
|
||||
local i,t,sw,sh=1,{},image:getDimensions()
|
||||
for line in love.filesystem.lines(filename) do
|
||||
if i>1 and line:match('%a') and not line:match('<!') and line~="</TextureAtlas>" then
|
||||
local _, frameNo = string.match(line, "name=([\"'])(.-)%1")
|
||||
local animName=frameNo:match('[%a ]+')
|
||||
frameNo=tonumber(frameNo:match('%d+'))
|
||||
--Frames must exist and must start from 1! Also animation name must be present
|
||||
if not animName or not frameNo or frameNo<=0 then goto continue end
|
||||
|
||||
if not t[animName] then t[animName]={} end
|
||||
assert(not t[animName][frameNo],
|
||||
"animX Error!! Duplicate Frames found for ("..frameNo..") for "..filename
|
||||
)
|
||||
local _, x = string.match(line, "x=([\"'])(.-)%1")
|
||||
local _, y = string.match(line, "y=([\"'])(.-)%1")
|
||||
local _, width = string.match(line, "width=([\"'])(.-)%1")
|
||||
local _, height = string.match(line, "height=([\"'])(.-)%1")
|
||||
|
||||
t[animName][frameNo]=love.graphics.newQuad(x,y,width,height,sw,sh)
|
||||
::continue::
|
||||
end
|
||||
i=i+1
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--[[
|
||||
Exports an animation (instance) to XML!
|
||||
@Params:
|
||||
filename: By what name should the animation be exported
|
||||
@Returns:-
|
||||
Whether or not animX was successful in exporting
|
||||
]]
|
||||
function Animation:exportToXML(filename)
|
||||
filename=removePath(filename)
|
||||
if fileExists(filename) then
|
||||
if not animx.hideWarnings then
|
||||
error(string.format("animX Warning! File '%s' Already Exists!",filename))
|
||||
end
|
||||
end
|
||||
local outfile=io.open(filename,'w')
|
||||
if not outfile then
|
||||
if animx.hideWarnings then
|
||||
return false
|
||||
else
|
||||
error("animx Error! Something's wrong with the io")
|
||||
end
|
||||
end
|
||||
local sname,x,y,width,height
|
||||
|
||||
outfile:write(string.format('<TextureAtlas imageName="%s">\n',removeExtension(filename)))
|
||||
for i=1,#self.frames do
|
||||
x,y,width,height=self.frames[i]:getViewport()
|
||||
outfile:write(
|
||||
string.format('\t<SubTexture name="%i" x="%i" y="%i" width="%i" height="%i"/>\n',
|
||||
i,x,y,width,height
|
||||
)
|
||||
)
|
||||
end
|
||||
outfile:write("</TextureAtlas>")
|
||||
return outfile:close()
|
||||
end
|
||||
|
||||
--[[
|
||||
Exports an actor (all the animations associated with it) to XML!
|
||||
@Params:
|
||||
filename: By what name should the actor be exported
|
||||
@Returns:-
|
||||
Whether or not animx was successful in exporting
|
||||
]]
|
||||
function Actor:exportToXML(filename)
|
||||
filename=removePath(filename)
|
||||
if fileExists(filename) then
|
||||
if not animx.hideWarnings then
|
||||
error(string.format("animX Warning! File '%s' Already Exists!",filename))
|
||||
end
|
||||
end
|
||||
local outfile=io.open(filename,'w')
|
||||
if not outfile then
|
||||
if animx.hideWarnings then
|
||||
return false
|
||||
else
|
||||
error("animx Error! Something's wrong with the io")
|
||||
end
|
||||
end
|
||||
local sname,x,y,width,height
|
||||
|
||||
outfile:write(string.format('<TextureAtlas imageName="%s">\n',removeExtension(filename)))
|
||||
for anim in pairs(self.animations) do
|
||||
for i=1,#self.animations[anim].frames do
|
||||
x,y,width,height=self.animations[anim].frames[i]:getViewport()
|
||||
outfile:write(
|
||||
string.format('\t<SubTexture name="%s" x="%i" y="%i" width="%i" height="%i"/>\n',
|
||||
anim..i,x,y,width,height
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
outfile:write("</TextureAtlas>")
|
||||
return outfile:close()
|
||||
end
|
||||
|
||||
--Updates all the animation objects at once so you won't see them in your code
|
||||
function animx.update(dt)
|
||||
for i=1,#animx.animObjs do
|
||||
animx.animObjs[i]:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
love.update=function(dt) animx.update(dt) end
|
||||
animx.newAnimatedSprite=animx.newActor
|
||||
|
||||
return animx
|
||||
|
|
@ -0,0 +1,368 @@
|
|||
local baton = {
|
||||
_VERSION = 'Baton v1.0.1',
|
||||
_DESCRIPTION = 'Input library for LÖVE.',
|
||||
_URL = 'https://github.com/tesselode/baton',
|
||||
_LICENSE = [[
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Andrew Minnich
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
}
|
||||
|
||||
-- string parsing functions --
|
||||
|
||||
-- splits a source definition into type and value
|
||||
-- example: 'button:a' -> 'button', 'a'
|
||||
local function parseSource(source)
|
||||
return source:match '(.+):(.+)'
|
||||
end
|
||||
|
||||
-- splits an axis value into axis and direction
|
||||
-- example: 'leftx-' -> 'leftx', '-'
|
||||
local function parseAxis(value)
|
||||
return value:match '(.+)([%+%-])'
|
||||
end
|
||||
|
||||
-- splits a joystick hat value into hat number and direction
|
||||
-- example: '2rd' -> '2', 'rd'
|
||||
local function parseHat(value)
|
||||
return value:match '(%d)(.+)'
|
||||
end
|
||||
|
||||
--[[
|
||||
-- source functions --
|
||||
|
||||
each source function checks the state of one type of input
|
||||
and returns a value from 0 to 1. for binary controls, such
|
||||
as keyboard keys and gamepad buttons, they return 1 if the
|
||||
input is held down and 0 if not. for analog controls, such
|
||||
as "leftx+" (the left analog stick held to the right), they
|
||||
return a number from 0 to 1.
|
||||
|
||||
source functions are split into keyboard/mouse functions
|
||||
and joystick/gamepad functions. baton treats these two
|
||||
categories slightly differently.
|
||||
]]
|
||||
|
||||
local sourceFunction = {keyboardMouse = {}, joystick = {}}
|
||||
|
||||
-- checks whether a keyboard key is down or not
|
||||
function sourceFunction.keyboardMouse.key(key)
|
||||
return love.keyboard.isDown(key) and 1 or 0
|
||||
end
|
||||
|
||||
-- checks whether a keyboard key is down or not,
|
||||
-- but it takes a scancode as an input
|
||||
function sourceFunction.keyboardMouse.sc(sc)
|
||||
return love.keyboard.isScancodeDown(sc) and 1 or 0
|
||||
end
|
||||
|
||||
-- checks whether a mouse buttons is down or not.
|
||||
-- note that baton doesn't detect mouse movement, just the buttons
|
||||
function sourceFunction.keyboardMouse.mouse(button)
|
||||
return love.mouse.isDown(tonumber(button)) and 1 or 0
|
||||
end
|
||||
|
||||
-- checks the position of a joystick axis
|
||||
function sourceFunction.joystick.axis(joystick, value)
|
||||
local axis, direction = parseAxis(value)
|
||||
-- "a and b or c" is ok here because b will never be boolean
|
||||
value = tonumber(axis) and joystick:getAxis(tonumber(axis))
|
||||
or joystick:getGamepadAxis(axis)
|
||||
if direction == '-' then value = -value end
|
||||
return value > 0 and value or 0
|
||||
end
|
||||
|
||||
-- checks whether a joystick button is held down or not
|
||||
-- can take a number or a GamepadButton string
|
||||
function sourceFunction.joystick.button(joystick, button)
|
||||
-- i'm intentionally not using the "a and b or c" idiom here
|
||||
-- because joystick.isDown returns a boolean
|
||||
if tonumber(button) then
|
||||
return joystick:isDown(tonumber(button)) and 1 or 0
|
||||
else
|
||||
return joystick:isGamepadDown(button) and 1 or 0
|
||||
end
|
||||
end
|
||||
|
||||
-- checks the direction of a joystick hat
|
||||
function sourceFunction.joystick.hat(joystick, value)
|
||||
local hat, direction = parseHat(value)
|
||||
return joystick:getHat(hat) == direction and 1 or 0
|
||||
end
|
||||
|
||||
--[[
|
||||
-- player class --
|
||||
|
||||
the player object takes a configuration table and handles input
|
||||
accordingly. it's called a "player" because it makes sense to use
|
||||
multiple of these for each player in a multiplayer game, but
|
||||
you can use separate player objects to organize inputs
|
||||
however you want.
|
||||
]]
|
||||
|
||||
local Player = {}
|
||||
Player.__index = Player
|
||||
|
||||
-- internal functions --
|
||||
|
||||
-- sets the player's config to a user-defined config table
|
||||
-- and sets some defaults if they're not already defined
|
||||
function Player:_loadConfig(config)
|
||||
if not config then
|
||||
error('No config table provided', 4)
|
||||
end
|
||||
if not config.controls then
|
||||
error('No controls specified', 4)
|
||||
end
|
||||
config.pairs = config.pairs or {}
|
||||
config.deadzone = config.deadzone or .5
|
||||
config.squareDeadzone = config.squareDeadzone or false
|
||||
self.config = config
|
||||
end
|
||||
|
||||
-- initializes a control object for each control defined in the config
|
||||
function Player:_initControls()
|
||||
self._controls = {}
|
||||
for controlName, sources in pairs(self.config.controls) do
|
||||
self._controls[controlName] = {
|
||||
sources = sources,
|
||||
rawValue = 0,
|
||||
value = 0,
|
||||
down = false,
|
||||
downPrevious = false,
|
||||
pressed = false,
|
||||
released = false,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- initializes an axis pair object for each axis pair defined in the config
|
||||
function Player:_initPairs()
|
||||
self._pairs = {}
|
||||
for pairName, controls in pairs(self.config.pairs) do
|
||||
self._pairs[pairName] = {
|
||||
controls = controls,
|
||||
rawX = 0,
|
||||
rawY = 0,
|
||||
x = 0,
|
||||
y = 0,
|
||||
down = false,
|
||||
downPrevious = false,
|
||||
pressed = false,
|
||||
released = false,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function Player:_init(config)
|
||||
self:_loadConfig(config)
|
||||
self:_initControls()
|
||||
self:_initPairs()
|
||||
self._activeDevice = 'none'
|
||||
end
|
||||
|
||||
--[[
|
||||
detects the active device (keyboard/mouse or joystick).
|
||||
if the keyboard or mouse is currently being used, joystick
|
||||
inputs will be ignored. this is to prevent slight axis movements
|
||||
from adding errant inputs when someone's using the keyboard.
|
||||
|
||||
the active device is saved to player._activeDevice, which is then
|
||||
used throughout the rest of the update loop to check only
|
||||
keyboard or joystick inputs.
|
||||
]]
|
||||
function Player:_setActiveDevice()
|
||||
for _, control in pairs(self._controls) do
|
||||
for _, source in ipairs(control.sources) do
|
||||
local type, value = parseSource(source)
|
||||
if sourceFunction.keyboardMouse[type] then
|
||||
if sourceFunction.keyboardMouse[type](value) > self.config.deadzone then
|
||||
self._activeDevice = 'kbm'
|
||||
return
|
||||
end
|
||||
elseif self.config.joystick and sourceFunction.joystick[type] then
|
||||
if sourceFunction.joystick[type](self.config.joystick, value) > self.config.deadzone then
|
||||
self._activeDevice = 'joy'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
gets the value of a control by running the appropriate source functions
|
||||
for all of its sources. does not apply deadzone.
|
||||
]]
|
||||
function Player:_getControlRawValue(control)
|
||||
local rawValue = 0
|
||||
for _, source in ipairs(control.sources) do
|
||||
local type, value = parseSource(source)
|
||||
if sourceFunction.keyboardMouse[type] and self._activeDevice == 'kbm' then
|
||||
if sourceFunction.keyboardMouse[type](value) == 1 then
|
||||
return 1
|
||||
end
|
||||
elseif sourceFunction.joystick[type] and self._activeDevice == 'joy' then
|
||||
rawValue = rawValue + sourceFunction.joystick[type](self.config.joystick, value)
|
||||
if rawValue >= 1 then
|
||||
return 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return rawValue
|
||||
end
|
||||
|
||||
--[[
|
||||
updates each control in a player. saves the value with and without deadzone
|
||||
and the down/pressed/released state.
|
||||
]]
|
||||
function Player:_updateControls()
|
||||
for _, control in pairs(self._controls) do
|
||||
control.rawValue = self:_getControlRawValue(control)
|
||||
control.value = control.rawValue >= self.config.deadzone and control.rawValue or 0
|
||||
control.downPrevious = control.down
|
||||
control.down = control.value > 0
|
||||
control.pressed = control.down and not control.downPrevious
|
||||
control.released = control.downPrevious and not control.down
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
updates each axis pair in a player. saves the value with and without deadzone
|
||||
and the down/pressed/released state.
|
||||
]]
|
||||
function Player:_updatePairs()
|
||||
for _, pair in pairs(self._pairs) do
|
||||
-- get raw x and y
|
||||
local l = self._controls[pair.controls[1]].rawValue
|
||||
local r = self._controls[pair.controls[2]].rawValue
|
||||
local u = self._controls[pair.controls[3]].rawValue
|
||||
local d = self._controls[pair.controls[4]].rawValue
|
||||
pair.rawX, pair.rawY = r - l, d - u
|
||||
|
||||
-- limit to 1
|
||||
local len = math.sqrt(pair.rawX^2 + pair.rawY^2)
|
||||
if len > 1 then
|
||||
pair.rawX, pair.rawY = pair.rawX / len, pair.rawY / len
|
||||
end
|
||||
|
||||
-- deadzone
|
||||
if self.config.squareDeadzone then
|
||||
pair.x = math.abs(pair.rawX) > self.config.deadzone and pair.rawX or 0
|
||||
pair.y = math.abs(pair.rawY) > self.config.deadzone and pair.rawY or 0
|
||||
else
|
||||
pair.x = len > self.config.deadzone and pair.rawX or 0
|
||||
pair.y = len > self.config.deadzone and pair.rawY or 0
|
||||
end
|
||||
|
||||
-- down/pressed/released
|
||||
pair.downPrevious = pair.down
|
||||
pair.down = pair.x ~= 0 or pair.y ~= 0
|
||||
pair.pressed = pair.down and not pair.downPrevious
|
||||
pair.released = pair.downPrevious and not pair.down
|
||||
end
|
||||
end
|
||||
|
||||
-- public API --
|
||||
|
||||
-- checks for changes in inputs
|
||||
function Player:update()
|
||||
self:_setActiveDevice()
|
||||
self:_updateControls()
|
||||
self:_updatePairs()
|
||||
end
|
||||
|
||||
-- gets the value of a control or axis pair without deadzone applied
|
||||
function Player:getRaw(name)
|
||||
if self._pairs[name] then
|
||||
return self._pairs[name].rawX, self._pairs[name].rawY
|
||||
elseif self._controls[name] then
|
||||
return self._controls[name].rawValue
|
||||
else
|
||||
error('No control with name "' .. name .. '" defined', 3)
|
||||
end
|
||||
end
|
||||
|
||||
-- gets the value of a control or axis pair with deadzone applied
|
||||
function Player:get(name)
|
||||
if self._pairs[name] then
|
||||
return self._pairs[name].x, self._pairs[name].y
|
||||
elseif self._controls[name] then
|
||||
return self._controls[name].value
|
||||
else
|
||||
error('No control with name "' .. name .. '" defined', 3)
|
||||
end
|
||||
end
|
||||
|
||||
-- gets whether a control or axis pair is "held down"
|
||||
function Player:down(name)
|
||||
if self._pairs[name] then
|
||||
return self._pairs[name].down
|
||||
elseif self._controls[name] then
|
||||
return self._controls[name].down
|
||||
else
|
||||
error('No control with name "' .. name .. '" defined', 3)
|
||||
end
|
||||
end
|
||||
|
||||
-- gets whether a control or axis pair was pressed this frame
|
||||
function Player:pressed(name)
|
||||
if self._pairs[name] then
|
||||
return self._pairs[name].pressed
|
||||
elseif self._controls[name] then
|
||||
return self._controls[name].pressed
|
||||
else
|
||||
error('No control with name "' .. name .. '" defined', 3)
|
||||
end
|
||||
end
|
||||
|
||||
-- gets whether a control or axis pair was released this frame
|
||||
function Player:released(name)
|
||||
if self._pairs[name] then
|
||||
return self._pairs[name].released
|
||||
elseif self._controls[name] then
|
||||
return self._controls[name].released
|
||||
else
|
||||
error('No control with name "' .. name .. '" defined', 3)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
gets the currently active device (either "kbm", "joy", or "none").
|
||||
this is useful for displaying instructional text. you may have
|
||||
a menu that says "press ENTER to confirm" or "press A to confirm"
|
||||
depending on whether the player is using their keyboard or gamepad.
|
||||
this function allows you to detect which they used most recently.
|
||||
]]
|
||||
function Player:getActiveDevice()
|
||||
return self._activeDevice
|
||||
end
|
||||
|
||||
-- main functions --
|
||||
|
||||
-- creates a new player with the user-provided config table
|
||||
function baton.new(config)
|
||||
local player = setmetatable({}, Player)
|
||||
player:_init(config)
|
||||
return player
|
||||
end
|
||||
|
||||
return baton
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Andrew Minnich
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,100 @@
|
|||
local baton = require 'baton'
|
||||
|
||||
local player = baton.new {
|
||||
controls = {
|
||||
left = {'key:left', 'axis:leftx-', 'button:dpleft'},
|
||||
right = {'key:right', 'axis:leftx+', 'button:dpright'},
|
||||
up = {'key:up', 'axis:lefty-', 'button:dpup'},
|
||||
down = {'key:down', 'axis:lefty+', 'button:dpdown'},
|
||||
action = {'key:x', 'button:a', 'mouse:1'},
|
||||
},
|
||||
pairs = {
|
||||
move = {'left', 'right', 'up', 'down'}
|
||||
},
|
||||
joystick = love.joystick.getJoysticks()[1],
|
||||
deadzone = .33,
|
||||
}
|
||||
|
||||
local pairDisplayAlpha = 0
|
||||
local pairDisplayTargetAlpha = 0
|
||||
local buttonDisplayAlpha = 0
|
||||
local buttonDisplayTargetAlpha = 0
|
||||
|
||||
local updates = 0
|
||||
local updateTime = 0
|
||||
|
||||
function love.update(dt)
|
||||
local time = love.timer.getTime()
|
||||
|
||||
player:update()
|
||||
|
||||
pairDisplayTargetAlpha = player:pressed 'move' and 1
|
||||
or player:released 'move' and 1
|
||||
or player:down 'move' and .5
|
||||
or 0
|
||||
if pairDisplayAlpha > pairDisplayTargetAlpha then
|
||||
pairDisplayAlpha = pairDisplayAlpha - 4 * dt
|
||||
end
|
||||
if pairDisplayAlpha < pairDisplayTargetAlpha then
|
||||
pairDisplayAlpha = pairDisplayTargetAlpha
|
||||
end
|
||||
|
||||
buttonDisplayTargetAlpha = player:pressed 'action' and 1
|
||||
or player:released 'action' and 1
|
||||
or player:down 'action' and .5
|
||||
or 0
|
||||
if buttonDisplayAlpha > buttonDisplayTargetAlpha then
|
||||
buttonDisplayAlpha = buttonDisplayAlpha - 4 * dt
|
||||
end
|
||||
if buttonDisplayAlpha < buttonDisplayTargetAlpha then
|
||||
buttonDisplayAlpha = buttonDisplayTargetAlpha
|
||||
end
|
||||
|
||||
updateTime = updateTime + (love.timer.getTime() - time)
|
||||
updates = updates + 1
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == 'escape' then
|
||||
love.event.quit()
|
||||
end
|
||||
end
|
||||
|
||||
local pairDisplayRadius = 128
|
||||
|
||||
function love.draw()
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.print('Current active device: ' .. tostring(player:getActiveDevice()))
|
||||
love.graphics.print('Average update time (us): ' .. math.floor(updateTime/updates*1000000), 0, 16)
|
||||
love.graphics.print('Memory usage (kb): ' .. math.floor(collectgarbage 'count'), 0, 32)
|
||||
|
||||
love.graphics.push()
|
||||
love.graphics.translate(400, 300)
|
||||
|
||||
love.graphics.setColor(.25, .25, .25, pairDisplayAlpha)
|
||||
love.graphics.circle('fill', 0, 0, pairDisplayRadius)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.circle('line', 0, 0, pairDisplayRadius)
|
||||
|
||||
local r = pairDisplayRadius * player.config.deadzone
|
||||
if player.config.squareDeadzone then
|
||||
love.graphics.rectangle('line', -r, -r, r*2, r*2)
|
||||
else
|
||||
love.graphics.circle('line', 0, 0, r)
|
||||
end
|
||||
|
||||
love.graphics.setColor(.5, .5, .5)
|
||||
local x, y = player:getRaw 'move'
|
||||
love.graphics.circle('fill', x*pairDisplayRadius, y*pairDisplayRadius, 4)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
x, y = player:get 'move'
|
||||
love.graphics.circle('fill', x*pairDisplayRadius, y*pairDisplayRadius, 4)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.rectangle('line', -50, 150, 100, 100)
|
||||
love.graphics.setColor(1, 1, 1, buttonDisplayAlpha)
|
||||
love.graphics.rectangle('fill', -50, 150, 100, 100)
|
||||
|
||||
love.graphics.pop()
|
||||
end
|
|
@ -0,0 +1,142 @@
|
|||
# Baton
|
||||
**Baton** is an input library for LÖVE that bridges the gap between keyboard and joystick controls and allows you to easily define and change controls on the fly. You can create multiple independent input managers, which you can use for multiplayer games or other organizational purposes.
|
||||
|
||||
```lua
|
||||
local baton = require 'baton'
|
||||
|
||||
local input = baton.new {
|
||||
controls = {
|
||||
left = {'key:left', 'key:a', 'axis:leftx-', 'button:dpleft'},
|
||||
right = {'key:right', 'key:d', 'axis:leftx+', 'button:dpright'},
|
||||
up = {'key:up', 'key:w', 'axis:lefty-', 'button:dpup'},
|
||||
down = {'key:down', 'key:s', 'axis:lefty+', 'button:dpdown'},
|
||||
action = {'key:x', 'button:a'},
|
||||
},
|
||||
pairs = {
|
||||
move = {'left', 'right', 'up', 'down'}
|
||||
},
|
||||
joystick = love.joystick.getJoysticks()[1],
|
||||
}
|
||||
|
||||
function love.update(dt)
|
||||
input:update()
|
||||
|
||||
local x, y = input:get 'move'
|
||||
playerShip:move(x*100, y*100)
|
||||
if input:pressed 'action' then
|
||||
playerShip:shoot()
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Installation
|
||||
To use Baton, place `baton.lua` in your project, and then add this code to your `main.lua`:
|
||||
```lua
|
||||
baton = require 'baton' -- if your baton.lua is in the root directory
|
||||
baton = require 'path.to.baton' -- if it's in subfolders
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Defining controls
|
||||
Controls are defined using a table. Each key should be the name of a control, and each value should be another table. This table contains strings defining what sources should be mapped to the control. For example, this table
|
||||
```lua
|
||||
controls = {
|
||||
left = {'key:left', 'key:a', 'axis:leftx-'}
|
||||
shoot = {'key:x', 'button:a'}
|
||||
}
|
||||
```
|
||||
will create a control called "left" that responds to the left arrow key, the A key, and pushing the left analog stick on the controller to the left, and a control called "shoot" that responds to the X key on the keyboard and the A button on the gamepad.
|
||||
|
||||
Sources are strings with the following format:
|
||||
```lua
|
||||
'[input type]:[input source]'
|
||||
```
|
||||
Here are the different input types and the sources that can be associated with them:
|
||||
|
||||
| Type | Description | Source |
|
||||
| --------| -----------------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `key` | A keyboard key. | Any LÖVE [KeyConstant](http://love2d.org/wiki/KeyConstant) |
|
||||
| `sc` | A scancode. | Any LÖVE [KeyConstant](http://love2d.org/wiki/KeyConstant) |
|
||||
| `mouse` | A mouse button. | A number representing a mouse button (see [love.mouse.isDown](https://love2d.org/wiki/love.mouse.isDown)) |
|
||||
| `axis` | A joystick or gamepad axis. | Either a number representing a joystick axis or a LÖVE [GamepadAxis](http://love2d.org/wiki/GamepadAxis). Add a '+' or '-' on the end to denote the direction to detect.|
|
||||
| `button`| A joystick or gamepad button.| Either a number representing a joystick button or a LÖVE [GamepadButton](http://love2d.org/wiki/GamepadButton) |
|
||||
| `hat` | A joystick hat. | A number representing a joystick hat and a [JoystickHat](https://love2d.org/wiki/JoystickHat). For example '1r' corresponds to the 1st hat pushed right. |
|
||||
|
||||
### Defining axis pairs
|
||||
Baton allows you to define **axis pairs**, which group four controls under a single name. This is perfect for analog sticks, arrow keys, etc., as it allows you to get x and y components quickly. Each pair is defined by a table with the names of the four controls (in the order left, right, up, down).
|
||||
```lua
|
||||
pairs = {
|
||||
move = {'moveLeft', 'moveRight', 'moveUp', 'moveDown'},
|
||||
aim = {'aimLeft', 'aimRight', 'aimUp', 'aimDown'},
|
||||
}
|
||||
```
|
||||
|
||||
### Players
|
||||
**Players** are the objects that monitor and manage inputs.
|
||||
|
||||
#### Creating players
|
||||
To create a player, use `baton.new`:
|
||||
```lua
|
||||
player = baton.new(config)
|
||||
```
|
||||
`config` is a table containing the following values:
|
||||
- `controls` - a table of controls
|
||||
- `pairs` - a table of axis pairs (optional)
|
||||
- `joystick` - a LÖVE joystick (returned from `love.joystick.getJoysticks`). The `joystick` argument is optional; if it's not specified, or if the joystick becomes unavailable later, the player object will just ignore controller inputs.
|
||||
- `deadzone` - a number from 0-1 representing the minimum value axes have to cross to be detected (optional)
|
||||
- `squareDeadzone` (bool) - whether to use square deadzones for axis pairs or not (optional)
|
||||
|
||||
#### Updating players
|
||||
You should update each player each frame by calling this function:
|
||||
```lua
|
||||
player:update()
|
||||
```
|
||||
|
||||
#### Getting the value of controls
|
||||
To get the value of a control, use:
|
||||
```lua
|
||||
value = player:get(control)
|
||||
```
|
||||
For example, for the controls defined above, we could get the value of the "left" control by doing
|
||||
```lua
|
||||
left = player:get 'left'
|
||||
```
|
||||
`player:get` always returns a number between 0 and 1, and as such, it is most applicable to controls that act as axes, such as movement controls. To get the value of a control without applying the deadzone, use `player:getRaw`.
|
||||
|
||||
#### Getting the value of axis pairs
|
||||
`player.get` can also get the x and y components of an axis pair.
|
||||
```lua
|
||||
x, y = player:get(pair)
|
||||
```
|
||||
In this case, `x` and `y` are numbers between -1 and 1. The length of the vector x, y is capped to 1. `player.getRaw` will return the value of axis pairs without deadzone applied.
|
||||
|
||||
#### Getting down, pressed, and released states
|
||||
To see whether a control is currently "held down", use:
|
||||
```lua
|
||||
down = player:down(control)
|
||||
```
|
||||
`player:down` returns `true` if the value of the control is greater than the deadzone, and `false` if not.
|
||||
|
||||
```lua
|
||||
pressed = player:pressed(control)
|
||||
```
|
||||
`player:pressed` return `true` if the control was pressed this `frame`, and false if not.
|
||||
|
||||
```lua
|
||||
released = player:released(control)
|
||||
```
|
||||
`player:released` return `true` if the control was released this `frame`, and false if not.
|
||||
|
||||
These functions are most applicable for controls that act as buttons, such as a shoot button. That being said, they can be used for any control, which is useful if you want to, for example, use a movement control as a discrete button press to operate a menu.
|
||||
|
||||
#### Updating the configuration
|
||||
The `controls` table, `pairs` table, `joystick`, `deadzone`, and `squareDeadzone` can all be accessed via `player.config`. Any of the values can be changed, and the player's behavior will be updated automatically. Note, however, that new controls and pairs cannot be added after the player is created, and controls and pairs should not be removed entirely (if you want to disable a control, you can set it to an empty table, removing all of its sources).
|
||||
|
||||
#### Getting the active input device
|
||||
At any time, only the keyboard/mouse sources or the joystick sources for a player will be active. A device will be considered active if any of the sources for that device exceed the deadzone. The keyboard and mouse will always take precedence over the joystick.
|
||||
|
||||
You can call `player:getActiveDevice()` to see which input device is currently active. It will return either `'kbm'` (keyboard/mouse) or `'joy'` (joystick) (or `'none'` if no sources have been used yet). This is useful if you need to change what you display on screen based on the controls the player is using (such as instructions).
|
||||
|
||||
## Contributing
|
||||
Issues and pull requests are always welcome. To run the test, run `love .` in the baton folder.
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Semyon Entsov <swalrus@yandex.ru>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,94 @@
|
|||
# center
|
||||
Center is a simple library that dynamically aligns content to the center of game window.
|
||||
|
||||
<img src="https://github.com/S-Walrus/center/blob/master/screenshots/center.png?raw=true" width="256">
|
||||
|
||||
## Setup
|
||||
|
||||
```lua
|
||||
local center = require "center"
|
||||
|
||||
center:setupScreen(600, 400)
|
||||
|
||||
function love.draw()
|
||||
center:start()
|
||||
|
||||
-- draw here
|
||||
|
||||
center:finish()
|
||||
end
|
||||
|
||||
function love.resize(width, height)
|
||||
center:resize(width, height)
|
||||
end
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### setupScreen
|
||||
```lua
|
||||
center:setupScreen(width, height)
|
||||
```
|
||||
Initializes Center
|
||||
|
||||
### apply
|
||||
```lua
|
||||
center:apply()
|
||||
```
|
||||
Applies changes.
|
||||
|
||||
This function is responsible for the whole alignment process, so any function (except for `setupScreen` and `resize`) will not make sense without `apply()` after it.
|
||||
|
||||
### setMaxWidth
|
||||
```lua
|
||||
center:setMaxWidth(width)
|
||||
```
|
||||
Width of the content **won't be greater** than specified value (default value is 0, that means that there is no boundaries).
|
||||
|
||||
### setMaxHeight
|
||||
```lua
|
||||
center:setMaxHeight(height)
|
||||
```
|
||||
Works the same as the previous one.
|
||||
|
||||
### setMaxRelativeWidth
|
||||
```lua
|
||||
center:setMaxRelativeWidth(width)
|
||||
```
|
||||
The **relative** width of the content (actual width / available width) **won't be greater** than specified value (default value is 0, that means that there is no relative boundaries).
|
||||
|
||||
### setMaxRelativeHeight
|
||||
```lua
|
||||
center:setMaxRelativeHeight(height)
|
||||
```
|
||||
Works the same as the previous one.
|
||||
|
||||
### setBorders
|
||||
```lua
|
||||
center:setBorders(t, r, b, l)
|
||||
```
|
||||
Specify the available area for the content.
|
||||
Each argument represents how far the content should be placed from each side from top to left clockwise.
|
||||
The content is aligned to the center of **this** area.
|
||||
|
||||
*For better understanding, illustrations will be added soon*
|
||||
|
||||
### start, finish
|
||||
|
||||
```lua
|
||||
function love.draw()
|
||||
center:start()
|
||||
|
||||
-- draw here
|
||||
|
||||
center:finish()
|
||||
end
|
||||
```
|
||||
This pair of functions is supposed to be called once inside `love.draw()`. Any rendering after `center.finish()` affect the default canvas, so you can draw UI or anything else.
|
||||
|
||||
### toGame
|
||||
|
||||
```lua
|
||||
center:toGame(x, y)
|
||||
```
|
||||
Return position of a point in aligned coordinate system insead of default one.
|
|
@ -0,0 +1,119 @@
|
|||
--[[
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Semyon Entsov <swalrus@yandex.ru>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]--
|
||||
|
||||
local center = {}
|
||||
|
||||
function center:setupScreen(width, height)
|
||||
self._WIDTH = width
|
||||
self._HEIGHT = height
|
||||
self._MAX_WIDTH = 0
|
||||
self._MAX_HEIGHT = 0
|
||||
self._MAX_RELATIVE_WIDTH = 0
|
||||
self._MAX_RELATIVE_HEIGHT = 0
|
||||
self._SCREEN_WIDTH = love.graphics.getWidth()
|
||||
self._SCREEN_HEIGHT = love.graphics.getHeight()
|
||||
self._BORDERS = {
|
||||
['t'] = 0,
|
||||
['r'] = 0,
|
||||
['b'] = 0,
|
||||
['l'] = 0
|
||||
}
|
||||
self:apply()
|
||||
return self
|
||||
end
|
||||
|
||||
function center:setBorders(top, right, bottom, left)
|
||||
self._BORDERS.t = top
|
||||
self._BORDERS.r = right
|
||||
self._BORDERS.b = bottom
|
||||
self._BORDERS.l = left
|
||||
end
|
||||
|
||||
function center:setMaxWidth(width)
|
||||
self._MAX_WIDTH = width
|
||||
end
|
||||
|
||||
function center:setMaxHeight(height)
|
||||
self._MAX_HEIGHT = height
|
||||
end
|
||||
|
||||
function center:setMaxRelativeWidth(width)
|
||||
self._MAX_RELATIVE_WIDTH = width
|
||||
end
|
||||
|
||||
function center:setMaxRelativeHeight(height)
|
||||
self._MAX_RELATIVE_HEIGHT = height
|
||||
end
|
||||
|
||||
function center:resize(width, height)
|
||||
self._SCREEN_WIDTH = width
|
||||
self._SCREEN_HEIGHT = height
|
||||
self:apply()
|
||||
end
|
||||
|
||||
function center:apply()
|
||||
local available_width = self._SCREEN_WIDTH - self._BORDERS.l - self._BORDERS.r
|
||||
local available_height = self._SCREEN_HEIGHT - self._BORDERS.t - self._BORDERS.b
|
||||
local max_width = available_width
|
||||
local max_height = available_height
|
||||
if self._MAX_RELATIVE_WIDTH > 0 and available_width * self._MAX_RELATIVE_WIDTH < max_width then
|
||||
max_width = available_width * self._MAX_RELATIVE_WIDTH
|
||||
end
|
||||
if self._MAX_RELATIVE_HEIGHT > 0 and available_height * self._MAX_RELATIVE_HEIGHT < max_height then
|
||||
max_height = available_height * self._MAX_RELATIVE_HEIGHT
|
||||
end
|
||||
if self._MAX_WIDTH > 0 and self._MAX_WIDTH < max_width then
|
||||
max_width = self._MAX_WIDTH
|
||||
end
|
||||
if self._MAX_HEIGHT > 0 and self._MAX_HEIGHT < max_height then
|
||||
max_height = self._MAX_HEIGHT
|
||||
end
|
||||
if max_height / max_width > self._HEIGHT / self._WIDTH then
|
||||
self._CANVAS_WIDTH = max_width
|
||||
self._CANVAS_HEIGHT = self._CANVAS_WIDTH * (self._HEIGHT / self._WIDTH)
|
||||
else
|
||||
self._CANVAS_HEIGHT = max_height
|
||||
self._CANVAS_WIDTH = self._CANVAS_HEIGHT * (self._WIDTH / self._HEIGHT)
|
||||
end
|
||||
self._SCALE = self._CANVAS_HEIGHT / self._HEIGHT
|
||||
self._OFFSET_X = self._BORDERS.l + (available_width - self._CANVAS_WIDTH) / 2
|
||||
self._OFFSET_Y = self._BORDERS.t + (available_height - self._CANVAS_HEIGHT) / 2
|
||||
end
|
||||
|
||||
function center:start()
|
||||
love.graphics.push()
|
||||
love.graphics.translate(self._OFFSET_X, self._OFFSET_Y)
|
||||
love.graphics.scale(self._SCALE, self._SCALE)
|
||||
end
|
||||
|
||||
function center:finish()
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
function center:toGame(x, y)
|
||||
return (x - self._OFFSET_X) / self._SCALE,
|
||||
(y - self._OFFSET_Y) / self._SCALE
|
||||
end
|
||||
|
||||
return center
|
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.3 KiB |
|
@ -0,0 +1,147 @@
|
|||
animx = require "lib/animx"
|
||||
|
||||
----------------------------------------
|
||||
-- LOAD
|
||||
----------------------------------------
|
||||
function love.load ()
|
||||
left = 0; right = 1; up = 2; down = 3
|
||||
upleft = 4; downleft = 5; upright = 6; downright = 7
|
||||
|
||||
aBatFly = animx.newAnimation{
|
||||
img = "art/sprites/bat.png",
|
||||
sprites_per_row = 5,
|
||||
noOfFrames = 5
|
||||
}:loop()
|
||||
|
||||
bat = { x = 50, y = 200,
|
||||
y_vel = 0, x_vel = 0,
|
||||
moving = false,
|
||||
flying = false,
|
||||
direction = left,
|
||||
animation = aBatFly
|
||||
}
|
||||
|
||||
-- for compliance with Statute 43.5 (2019); all birds must report births to local Officials
|
||||
birdRegistry = {}
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- UPDATE
|
||||
----------------------------------------
|
||||
function love.update ( dt )
|
||||
-- bat.x = bat.x + 100 * dt
|
||||
|
||||
flier_update( bat, dt )
|
||||
animx.update(dt)
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- DRAW
|
||||
----------------------------------------
|
||||
function love.draw ()
|
||||
love.graphics.print('Hello World!', 400, 300)
|
||||
flier_draw( bat )
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- INPUT
|
||||
----------------------------------------
|
||||
function love.keypressed ( key )
|
||||
if ( key == "right" ) then
|
||||
bat.moving = true
|
||||
bat.direction = right
|
||||
aBatFly:flipX(true)
|
||||
elseif ( key == "left" ) then
|
||||
bat.moving = true
|
||||
bat.direction = left
|
||||
aBatFly:flipX(false)
|
||||
elseif ( key == "space" ) then
|
||||
bat.flying = true
|
||||
end
|
||||
end
|
||||
|
||||
function love.keyreleased (key)
|
||||
if ( key == "right" and bat.direction == right ) then
|
||||
if ( love.keyboard.isDown("left") ) then
|
||||
bat.direction = left
|
||||
else
|
||||
bat.moving = false
|
||||
end
|
||||
elseif ( key == "left" and bat.direction == left ) then
|
||||
if ( love.keyboard.isDown("right") ) then
|
||||
bat.direction = right
|
||||
else
|
||||
bat.moving = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- FLIERS
|
||||
----------------------------------------
|
||||
-- generic flier update: physics + changing position
|
||||
function flier_update ( flier, dt )
|
||||
flier_physics( flier, dt )
|
||||
end
|
||||
|
||||
function flier_draw ( flier )
|
||||
flier.animation:draw( flier.x, flier.y )
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- "PHYSICS"
|
||||
----------------------------------------
|
||||
-- "physics" being used verryyyyy lightly here
|
||||
|
||||
-- does basics physics work (determines velocity) for a flier
|
||||
function flier_physics ( flier, dt )
|
||||
flier_physics_x( flier, dt )
|
||||
flier_physics_y( flier, dt )
|
||||
end
|
||||
|
||||
function flier_physics_x ( flier, dt )
|
||||
max_vel = 300
|
||||
min_vel = -300
|
||||
|
||||
if ( flier.moving ) then
|
||||
if ( flier.x_vel < max_vel and flier.direction == right ) then
|
||||
flier.x_vel = flier.x_vel + (max_vel / 300)
|
||||
elseif ( flier.x_vel > min_vel and flier.direction == left ) then
|
||||
flier.x_vel = flier.x_vel - (max_vel / 300)
|
||||
end
|
||||
else
|
||||
if ( flier.x_vel > 0 ) then
|
||||
flier.x_vel = flier.x_vel - (max_vel / 600)
|
||||
elseif ( flier.x_vel < 0 ) then
|
||||
flier.x_vel = flier.x_vel + (max_vel / 600)
|
||||
end
|
||||
end
|
||||
|
||||
flier.x = flier.x + flier.x_vel * dt
|
||||
end
|
||||
|
||||
function flier_physics_y ( flier, dt )
|
||||
gravity = .75
|
||||
floor = 500
|
||||
|
||||
-- wing-flap
|
||||
if ( flier.flying ) then
|
||||
flier.y_vel = -200
|
||||
flier.flying = false
|
||||
end
|
||||
|
||||
-- gravity
|
||||
if ( flier.y < floor ) then
|
||||
flier.y_vel = flier.y_vel + gravity
|
||||
end
|
||||
|
||||
-- if on ground; stop gravity
|
||||
if ( flier.y > floor ) then
|
||||
flier.y = floor
|
||||
flier.y_vel = 0
|
||||
end
|
||||
|
||||
flier.y = flier.y + flier.y_vel * dt
|
||||
end
|