Compare commits
200 commits
Author | SHA1 | Date | |
---|---|---|---|
|
df08bd1f27 | ||
|
a91b078285 | ||
|
bceff3fb14 | ||
|
631a31876f | ||
|
8cbd261238 | ||
|
84d1af5ccf | ||
|
cf28f10fd1 | ||
|
2a424d17e5 | ||
|
c9f013a465 | ||
|
0c4423c4aa | ||
|
337fcf9cd0 | ||
|
0a2e3f05d4 | ||
|
819559607c | ||
|
5c634c3865 | ||
|
8dd37e8e95 | ||
|
87b70cd93a | ||
|
d71437774f | ||
|
95f5b2c3a8 | ||
|
3f45ae580c | ||
|
5567b515e8 | ||
|
26e6825d0e | ||
|
d7373e0c28 | ||
|
b3a2e58af4 | ||
|
40e82e26f6 | ||
|
25b6eb659d | ||
|
2e25c4cfcc | ||
|
58ae21724b | ||
|
865e931a43 | ||
|
6633fffb30 | ||
|
1ab8befd8f | ||
|
61451a4a10 | ||
|
03a577fd18 | ||
|
6f816eedef | ||
|
3079ee74e1 | ||
|
21df43b773 | ||
|
370d6def45 | ||
|
9e04a4fddb | ||
|
d095569911 | ||
|
5a15be6eef | ||
|
b51248e7e7 | ||
|
310105ed48 | ||
|
927d7af132 | ||
|
2ec22ea6b0 | ||
|
039d567be8 | ||
|
083ef004cd | ||
|
f3a70c100f | ||
|
efb5046ec7 | ||
|
84923b2622 | ||
|
b5064d8c7c | ||
|
7456840238 | ||
|
9a9408edf3 | ||
|
7657a35415 | ||
|
56bf486fbf | ||
|
134445ed20 | ||
|
9da16fc6a7 | ||
|
d9a0128958 | ||
|
7654888f6f | ||
|
7799387cf2 | ||
|
c7f4f00a2f | ||
|
9d09365e7d | ||
|
50329f7790 | ||
|
9118d6fcde | ||
|
67e4c9ca80 | ||
|
55db04c27f | ||
|
de22c2fffe | ||
|
87b2b2ad05 | ||
|
f9ff9d1db2 | ||
|
a1af74be74 | ||
|
bf04946a1b | ||
|
ae38902d9c | ||
|
3d9af3eaf8 | ||
|
fe947c8ba5 | ||
|
0b03c306c3 | ||
|
bb61df8b6d | ||
|
a99a70eb9d | ||
|
03c406fd3e | ||
|
3b3b9822f5 | ||
|
430e2fff14 | ||
|
8627f80be2 | ||
|
6a4c0e5b42 | ||
|
56779daa22 | ||
|
e820437bdf | ||
|
1e71b63f67 | ||
|
43f5649ce5 | ||
|
2e359d9b0f | ||
|
24a04ecb36 | ||
|
5ec8901dd7 | ||
|
eecbe73893 | ||
|
ecffdaf467 | ||
|
bbf2cc9911 | ||
|
e3c3caec0b | ||
|
a6977e81aa | ||
|
3797869d14 | ||
|
20954c0484 | ||
|
cd303affc8 | ||
|
b043ff7707 | ||
|
8e870e3525 | ||
|
02d11e7e2e | ||
|
2f8b9054f2 | ||
|
4941ec1904 | ||
|
0977680004 | ||
|
d55cb1f38e | ||
|
7b174248ec | ||
|
454405b564 | ||
|
253e698cc4 | ||
|
4137101dbc | ||
|
3bfa8671b0 | ||
|
675b0ff155 | ||
|
99f37fc6b2 | ||
|
2f03adc8f4 | ||
|
a859814fda | ||
|
5c90eee84a | ||
|
3873c62f17 | ||
|
c557b9cc3c | ||
|
9c2f93a60c | ||
|
efbbc49b54 | ||
|
6523f13cac | ||
|
b176155b8a | ||
|
e4bd5198e0 | ||
|
1eae6ae381 | ||
|
7142ce9b55 | ||
|
d0a9d342c7 | ||
|
dbc3188317 | ||
|
a3f92c9960 | ||
|
29c531ef73 | ||
|
84e1c4ded2 | ||
|
c58cc24910 | ||
|
6073ba6cc9 | ||
|
e7e157c8ab | ||
|
ec087113f8 | ||
|
e3fd34731b | ||
|
5675cf7f6d | ||
|
b3e1d204c5 | ||
|
7e3fbd45c7 | ||
|
5aaa2dd41b | ||
|
a9165b852a | ||
|
0fb10b0981 | ||
|
de5e692305 | ||
|
171f71180f | ||
|
dc78b0fe7b | ||
|
3b5d0a90ad | ||
|
31f56d62a3 | ||
|
00ac2ef5b2 | ||
|
2e280d6e19 | ||
|
7c18915e9b | ||
|
cf520852d0 | ||
|
ada9c1368f | ||
|
4eb31b1bf5 | ||
|
29f8551b84 | ||
|
864aa694ee | ||
|
a49afbdee8 | ||
|
a66e67ee69 | ||
|
02ed49a17b | ||
|
ff77587042 | ||
|
31a58280ae | ||
|
4ea4de78f6 | ||
|
77698627eb | ||
|
bdc020e511 | ||
|
a1144db6d9 | ||
|
bb364d6b1a | ||
|
12b788af5e | ||
|
0c53c11942 | ||
|
9b30b11e18 | ||
|
b945cc1fb6 | ||
|
f5353c5de2 | ||
|
2bff7b942f | ||
|
3ada04c3c1 | ||
|
e5e4c7a4d1 | ||
|
8ce4edba25 | ||
|
35810c7b4a | ||
|
556ebd814d | ||
|
86c1791822 | ||
|
e1039005c8 | ||
|
900e8bd777 | ||
|
53e164fe6a | ||
|
0fb1d12702 | ||
|
2dae38d4b4 | ||
|
ac24c3605d | ||
|
dcad00d93f | ||
|
52c6d2ab3a | ||
|
80ae98220d | ||
|
8fafe65b84 | ||
|
6d8c93b7a0 | ||
|
7925bbb600 | ||
|
eb3fc7052a | ||
|
9a7eeace0a | ||
|
e7089411f5 | ||
|
eabbb22fb1 | ||
|
864c135dae | ||
|
43264e7856 | ||
|
3ed715c7aa | ||
|
129912174e | ||
|
96670cdc8c | ||
|
ca7b14d6a2 | ||
|
fd06185f6a | ||
|
8aecda952f | ||
|
ee5ed9d376 | ||
|
9787364ae6 | ||
|
58fd609095 | ||
|
9e89962af0 |
28
.gitignore
vendored
|
@ -1,20 +1,18 @@
|
|||
*.hi
|
||||
*.o
|
||||
.hsenv*
|
||||
.stack-work
|
||||
.git
|
||||
.cabal-sandbox/
|
||||
cabal.sandbox.config
|
||||
dist-newstyle/
|
||||
dist/
|
||||
*.prof
|
||||
*.out
|
||||
*.toc
|
||||
*.aux
|
||||
*.log
|
||||
*.synctex.gz
|
||||
.*.swp
|
||||
*.*~
|
||||
*.trace
|
||||
*.hp
|
||||
*.ps
|
||||
*.swp
|
||||
.ghc*
|
||||
cabal.project.local*
|
||||
dist*/
|
||||
report.html
|
||||
*.bak
|
||||
/*.pdf
|
||||
*.prof
|
||||
*.ps
|
||||
*.html
|
||||
.direnv/
|
||||
.envrc
|
||||
result
|
||||
|
|
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Revision history for pituicat
|
||||
|
||||
## 0.0.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
|
@ -1,5 +0,0 @@
|
|||
# Revision history for affection
|
||||
|
||||
## 0.0.0.7 -- 2017-12-23
|
||||
|
||||
* Release with working scaffold for engine subsystems.
|
755
LICENSE
|
@ -1,165 +1,674 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
0. Additional Definitions.
|
||||
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.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
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.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
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.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
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.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
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.
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
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.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
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.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
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.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
0. Definitions.
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
"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.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
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) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
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.
|
||||
|
||||
4. Combined Works.
|
||||
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.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
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.
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
1. Source Code.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
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.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
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.
|
||||
|
||||
d) Do one of the following:
|
||||
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.
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
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.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
5. Combined Libraries.
|
||||
2. Basic Permissions.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
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.
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
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.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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.
|
||||
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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
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 Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
|
65
README.md
|
@ -1,8 +1,63 @@
|
|||
# ![Affection logo](./affection.svg)
|
||||
# pituicat
|
||||
|
||||
A simple Game Engine in Haskell using SDL
|
||||
This repository contains the source and game design files for the game
|
||||
`pituicat`.
|
||||
|
||||
## Disclaimer
|
||||
This game is still an experimental work in progress, so things are subject to
|
||||
change and no version or revision numbers are being assigned (yet).
|
||||
|
||||
This Engine is not stable yet. Things may change. horribly.
|
||||
Even minor version bumps may break the API.
|
||||
## Build and run instructions
|
||||
|
||||
For any system you want to buil on, you will need a current version of `ghc`
|
||||
as well as the build tool `cabal`. Additional libraries may be needed,
|
||||
depending on your operating system.
|
||||
|
||||
### Linux
|
||||
|
||||
I develop this game in [NixOS](https://nixos.org), so the build instructions
|
||||
for this system are the ones I use on a daily basis.
|
||||
|
||||
#### NixOS
|
||||
|
||||
To set up the build environment, simply run this in the command line of your
|
||||
choice in the project's root directory:
|
||||
|
||||
```bash
|
||||
nix-shell shell.nix
|
||||
```
|
||||
|
||||
After the setup and build process is finished and you are given the prompt of
|
||||
the environmet you just built, you can run
|
||||
|
||||
```bash
|
||||
cabal new-run
|
||||
```
|
||||
|
||||
to compile and run the game.
|
||||
|
||||
#### Other Linux flavours
|
||||
|
||||
You will need at least the development libraries for `sdl2` and a development
|
||||
setup for `OpenGL`.
|
||||
|
||||
TODO: provide list of development libraries this game directly depends on.
|
||||
|
||||
After setting up the system with all development dependencies, simply run
|
||||
|
||||
```bash
|
||||
cabal new-run
|
||||
```
|
||||
|
||||
for compiling and running the game.
|
||||
|
||||
### Other operating systems
|
||||
|
||||
I wish you good luck with that. If you manage to run the game on other systms,
|
||||
ping me with build and run instructions on <nek0@nek0.eu> and I will gladly
|
||||
include them here.
|
||||
|
||||
## Gameplay
|
||||
|
||||
To move around, use the `D` and `A` Keys respectively.
|
||||
|
||||
Press `Space` to jump.
|
||||
|
|
181
affection.cabal
|
@ -1,181 +0,0 @@
|
|||
name: affection
|
||||
|
||||
-- The package version. See the Haskell package versioning policy (PVP)
|
||||
-- for standards guiding when and how versions should be incremented.
|
||||
-- http://www.haskell.org/haskellwiki/Package_versioning_policy
|
||||
-- PVP summary: +-+------- breaking API changes
|
||||
-- | | +----- non-breaking API additions
|
||||
-- | | | +--- code changes with no API change
|
||||
version: 0.0.0.10
|
||||
synopsis: A simple Game Engine using SDL
|
||||
description: This package contains Affection, a simple game engine
|
||||
written in Haskell using SDL.
|
||||
This Engine is still work in progress and even minor
|
||||
version bumps may contain breaking api changes.
|
||||
homepage: https://github.com/nek0/affection#readme
|
||||
license: LGPL-3
|
||||
license-file: LICENSE
|
||||
author: nek0
|
||||
maintainer: nek0@chelnok.de
|
||||
category: Game
|
||||
build-type: Simple
|
||||
extra-source-files: ChangeLog.md
|
||||
|
||||
-- Extra files to be distributed with the package, such as examples or a
|
||||
-- README.
|
||||
-- extra-source-files:
|
||||
|
||||
cabal-version: >=2.0
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://github.com/nek0/affection
|
||||
|
||||
flag verbose
|
||||
description: Enable verbose debug messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag debug
|
||||
description: Enable debug messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag warn
|
||||
description: Enable warning messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag error
|
||||
description: Enable error messages
|
||||
default: False
|
||||
manual: True
|
||||
|
||||
flag examples
|
||||
description: Build example programs
|
||||
default: False
|
||||
|
||||
library
|
||||
if flag(verbose)
|
||||
cpp-options: -DVERBOSE
|
||||
if flag(debug)
|
||||
cpp-options: -DDEBUG
|
||||
if flag(warn)
|
||||
cpp-options: -DWARN
|
||||
if flag(error)
|
||||
cpp-options: -DERROR
|
||||
exposed-modules: Affection
|
||||
, Affection.Logging
|
||||
, Affection.Types
|
||||
, Affection.Class
|
||||
, Affection.StateMachine
|
||||
, Affection.Util
|
||||
, Affection.MessageBus
|
||||
, Affection.MessageBus.Class
|
||||
, Affection.MessageBus.Message
|
||||
, Affection.MessageBus.Message.Class
|
||||
, Affection.MessageBus.Message.WindowMessage
|
||||
, Affection.MessageBus.Message.KeyboardMessage
|
||||
, Affection.MessageBus.Message.MouseMessage
|
||||
, Affection.MessageBus.Message.JoystickMessage
|
||||
, Affection.Subsystems
|
||||
, Affection.Subsystems.Class
|
||||
, Affection.Subsystems.AffectionWindow
|
||||
, Affection.Subsystems.AffectionKeyboard
|
||||
, Affection.Subsystems.AffectionMouse
|
||||
, Affection.Subsystems.AffectionJoystick
|
||||
default-extensions: OverloadedStrings
|
||||
, TypeFamilies
|
||||
, AllowAmbiguousTypes
|
||||
|
||||
-- Modules included in this library but not exported.
|
||||
-- other-modules:
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions: GADTs
|
||||
-- , KindSignatures
|
||||
-- , FlexibleInstances
|
||||
-- , MultiParamTypeClasses
|
||||
-- , UndecidableInstances
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall
|
||||
-- Other library packages from which modules are imported.
|
||||
build-depends: base >=4.9 && < 5
|
||||
, sdl2 ^>= 2.5
|
||||
, linear
|
||||
, text
|
||||
, mtl
|
||||
, monad-loops
|
||||
, monad-parallel
|
||||
, containers
|
||||
, clock >= 0.8
|
||||
, glib
|
||||
, bytestring
|
||||
, OpenGL
|
||||
, OpenGLRaw
|
||||
, stm
|
||||
, uuid
|
||||
, vector
|
||||
|
||||
-- This example shows the message system. only makes sense when compiling with
|
||||
-- verbose flag.
|
||||
executable example00
|
||||
hs-source-dirs: examples/example00
|
||||
main-is: Main.hs
|
||||
ghc-options: -threaded -Wall
|
||||
default-language: Haskell2010
|
||||
default-extensions: OverloadedStrings
|
||||
if flag(examples)
|
||||
build-depends: base >=4.9 && < 5
|
||||
, affection
|
||||
, sdl2 ^>= 2.5
|
||||
, stm
|
||||
else
|
||||
buildable: False
|
||||
|
||||
-- A small game of life implementation
|
||||
executable example01
|
||||
hs-source-dirs: examples/example01
|
||||
main-is: Main.hs
|
||||
other-modules: Types
|
||||
ghc-options: -threaded -Wall
|
||||
default-language: Haskell2010
|
||||
default-extensions: OverloadedStrings
|
||||
if flag(examples)
|
||||
build-depends: base >=4.9 && < 5
|
||||
, affection
|
||||
, sdl2 ^>= 2.5
|
||||
, stm
|
||||
, OpenGL
|
||||
, random
|
||||
, containers
|
||||
, linear
|
||||
, matrix
|
||||
, nanovg >= 0.6.0.0
|
||||
, deepseq
|
||||
else
|
||||
buildable: False
|
||||
|
||||
-- Another small game of life implementation
|
||||
executable example02
|
||||
hs-source-dirs: examples/example02
|
||||
main-is: Main.hs
|
||||
other-modules: Types
|
||||
ghc-options: -threaded -Wall
|
||||
default-language: Haskell2010
|
||||
default-extensions: OverloadedStrings
|
||||
if flag(examples)
|
||||
build-depends: base >=4.9 && < 5
|
||||
, affection
|
||||
, sdl2 ^>= 2.5
|
||||
, stm
|
||||
, OpenGL
|
||||
, random
|
||||
, containers
|
||||
, linear
|
||||
, matrix
|
||||
, nanovg >= 0.6.0.0
|
||||
, deepseq
|
||||
else
|
||||
buildable: False
|
|
@ -1,18 +0,0 @@
|
|||
{ mkDerivation, base, bytestring, clock, containers, glib, linear
|
||||
, monad-loops, monad-parallel, mtl, OpenGL, sdl2, stdenv, stm, text
|
||||
, uuid, vector
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "affection";
|
||||
version = "0.0.0.9";
|
||||
src = ./.;
|
||||
isLibrary = true;
|
||||
isExecutable = true;
|
||||
libraryHaskellDepends = [
|
||||
base bytestring clock containers glib linear monad-loops
|
||||
monad-parallel mtl OpenGL sdl2 stm text uuid vector
|
||||
];
|
||||
homepage = "https://github.com/nek0/affection#readme";
|
||||
description = "A simple Game Engine using SDL";
|
||||
license = stdenv.lib.licenses.lgpl3;
|
||||
}
|
106
affection.svg
Before Width: | Height: | Size: 14 KiB |
|
@ -1,4 +1,5 @@
|
|||
constraints: affection +verbose
|
||||
profiling: true
|
||||
packages:
|
||||
./.
|
||||
./
|
||||
|
||||
constraints:
|
||||
affection +verbose
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MVar
|
||||
import Control.Monad
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Data.Maybe (isJust, fromJust)
|
||||
import Data.String
|
||||
|
||||
data StateData = StateData
|
||||
{ sdSubs :: Subsystems
|
||||
, sdJoys :: MVar [SDL.Joystick]
|
||||
, doNextStep :: MVar Bool
|
||||
}
|
||||
|
||||
instance Affectionate StateData where
|
||||
loadState = load
|
||||
preLoop = pre
|
||||
handleEvents = handle
|
||||
update = Main.update
|
||||
draw = Main.draw
|
||||
cleanUp = clean
|
||||
hasNextStep = liftIO . readMVar . doNextStep
|
||||
|
||||
data Subsystems = Subsystems
|
||||
{ subWindow :: Main.Window
|
||||
, subMouse :: Main.Mouse
|
||||
, subKeyboard :: Main.Keyboard
|
||||
, subJoystick :: Main.Joystick
|
||||
}
|
||||
|
||||
newtype Window = Window (TVar [(UUID, WindowMessage -> Affection ())])
|
||||
newtype Mouse = Mouse (TVar [(UUID, MouseMessage -> Affection ())])
|
||||
newtype Keyboard = Keyboard (TVar [(UUID, KeyboardMessage -> Affection ())])
|
||||
newtype Joystick = Joystick (TVar [(UUID, JoystickMessage -> Affection ())])
|
||||
|
||||
instance Participant Main.Window where
|
||||
type Mesg Main.Window = WindowMessage
|
||||
|
||||
partSubscribers (Window t) = generalSubscribers t
|
||||
|
||||
partSubscribe (Window t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Window t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Main.Window where
|
||||
consumeSDLEvents = consumeSDLWindowEvents
|
||||
|
||||
instance Participant Mouse where
|
||||
type Mesg Mouse = MouseMessage
|
||||
|
||||
partSubscribers (Mouse t) = generalSubscribers t
|
||||
|
||||
partSubscribe (Mouse t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Mouse t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Mouse where
|
||||
consumeSDLEvents = consumeSDLMouseEvents
|
||||
|
||||
instance Participant Keyboard where
|
||||
type Mesg Keyboard = KeyboardMessage
|
||||
|
||||
partSubscribers (Keyboard t) = generalSubscribers t
|
||||
|
||||
partSubscribe (Keyboard t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Keyboard t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Keyboard where
|
||||
consumeSDLEvents = consumeSDLKeyboardEvents
|
||||
|
||||
instance Participant Joystick where
|
||||
type Mesg Joystick = JoystickMessage
|
||||
|
||||
partSubscribers (Joystick t) = generalSubscribers t
|
||||
|
||||
partSubscribe (Joystick t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Joystick t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Joystick where
|
||||
consumeSDLEvents = consumeSDLJoystickEvents
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
logIO Debug "Starting"
|
||||
let conf = AffectionConfig
|
||||
{ initComponents = All
|
||||
, windowTitle = "affection: example00"
|
||||
, windowConfigs =
|
||||
[
|
||||
( 0
|
||||
, SDL.defaultWindow
|
||||
{ SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
||||
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
|
||||
}
|
||||
}
|
||||
, SDL.Windowed
|
||||
)
|
||||
]
|
||||
} :: AffectionConfig StateData
|
||||
withAffection conf
|
||||
|
||||
load :: IO StateData
|
||||
load =
|
||||
StateData <$> (Subsystems
|
||||
<$> (Window <$> newTVarIO [])
|
||||
<*> (Mouse <$> newTVarIO [])
|
||||
<*> (Keyboard <$> newTVarIO [])
|
||||
<*> (Joystick <$> newTVarIO [])
|
||||
)
|
||||
<*> newMVar []
|
||||
<*> newMVar True
|
||||
|
||||
pre :: StateData -> Affection ()
|
||||
pre sd = do
|
||||
_ <- partSubscribe (subKeyboard $ sdSubs sd) (exitOnQ (doNextStep sd))
|
||||
_ <- partSubscribe (subWindow $ sdSubs sd) (exitOnWindowClose (doNextStep sd))
|
||||
_ <- partSubscribe (subJoystick $ sdSubs sd) (joyConnectDisconnect (sdJoys sd))
|
||||
return ()
|
||||
|
||||
exitOnQ :: MVar Bool -> KeyboardMessage -> Affection ()
|
||||
exitOnQ nextStep (MsgKeyboardEvent _ _ _ _ sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeQ -> do
|
||||
liftIO $ logIO Debug "Yo dog I heard..."
|
||||
void $ liftIO $ swapMVar nextStep False
|
||||
_ -> return ()
|
||||
|
||||
exitOnWindowClose :: MVar Bool -> WindowMessage -> Affection ()
|
||||
exitOnWindowClose nextStep wm =
|
||||
case wm of
|
||||
MsgWindowClose _ _ -> do
|
||||
liftIO $ logIO Debug "I heard another one..."
|
||||
void $ liftIO $ swapMVar nextStep False
|
||||
_ -> return ()
|
||||
|
||||
joyConnectDisconnect :: MVar [SDL.Joystick] -> JoystickMessage -> Affection ()
|
||||
joyConnectDisconnect mvjs msg = do
|
||||
mj <- joystickAutoConnect msg
|
||||
when (isJust mj) $ do
|
||||
js <- liftIO $ readMVar mvjs
|
||||
void $ liftIO $ swapMVar mvjs (fromJust mj : js)
|
||||
js <- liftIO $ readMVar mvjs
|
||||
njs <- joystickAutoDisconnect js msg
|
||||
liftIO $ putMVar mvjs njs
|
||||
|
||||
handle :: StateData -> [SDL.EventPayload] -> Affection ()
|
||||
handle sd es = do
|
||||
let (Subsystems a b c d) = sdSubs sd
|
||||
leftovers <- consumeSDLEvents a
|
||||
=<< consumeSDLEvents b
|
||||
=<< consumeSDLEvents c
|
||||
=<< consumeSDLEvents d es
|
||||
mapM_ (\e -> liftIO $ logIO Verbose $ "LEFTOVER: " <> fromString (show e))
|
||||
leftovers
|
||||
|
||||
update :: StateData -> Double -> Affection ()
|
||||
update _ _ = return ()
|
||||
|
||||
draw :: StateData -> Affection ()
|
||||
draw _ = return ()
|
||||
|
||||
clean :: StateData -> IO ()
|
||||
clean _ = return ()
|
||||
|
||||
generalSubscribers
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> Affection [msg -> Affection ()]
|
||||
generalSubscribers t = do
|
||||
subTups <- liftIO $ readTVarIO t
|
||||
return $ map snd subTups
|
||||
|
||||
generalSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> (msg -> Affection())
|
||||
-> Affection UUID
|
||||
generalSubscribe t funct = do
|
||||
uuid <- genUUID
|
||||
liftIO $ atomically $ modifyTVar' t ((uuid, funct) :)
|
||||
return uuid
|
||||
|
||||
generalUnSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> UUID
|
||||
-> Affection ()
|
||||
generalUnSubscribe t uuid =
|
||||
liftIO $ atomically $ modifyTVar' t (filter (\(u, _) -> u /= uuid))
|
|
@ -1,251 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
|
||||
import Affection as A
|
||||
import qualified SDL
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MVar
|
||||
import Control.Monad
|
||||
import Control.DeepSeq (deepseq)
|
||||
|
||||
import Data.Matrix as M
|
||||
import qualified Data.Set as S
|
||||
import Data.String
|
||||
|
||||
import System.Random (randomRIO)
|
||||
|
||||
import NanoVG hiding (V2(..))
|
||||
|
||||
import Foreign.C.Types (CInt(..))
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
|
||||
instance Affectionate UserData where
|
||||
loadState = load
|
||||
preLoop = pre
|
||||
handleEvents = handle
|
||||
update = Main.update
|
||||
draw = Main.draw
|
||||
cleanUp = clean
|
||||
hasNextStep = liftIO . readMVar . doNextStep
|
||||
|
||||
foreign import ccall unsafe "glewInit"
|
||||
glewInit :: IO CInt
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
logIO A.Debug "Starting"
|
||||
let conf = AffectionConfig
|
||||
{ initComponents = All
|
||||
, windowTitle = "affection: example01"
|
||||
, windowConfigs =
|
||||
[
|
||||
( 0
|
||||
, SDL.defaultWindow
|
||||
{ SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
||||
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
|
||||
}
|
||||
, SDL.windowInitialSize = SDL.V2 600 600
|
||||
, SDL.windowResizable = True
|
||||
}
|
||||
, SDL.Windowed
|
||||
)
|
||||
]
|
||||
} :: AffectionConfig UserData
|
||||
withAffection conf
|
||||
|
||||
load :: IO UserData
|
||||
load = do
|
||||
-- emptyMatrix <- zero 60 60
|
||||
liftIO $ logIO A.Debug "init GLEW"
|
||||
_ <- glewInit
|
||||
liftIO $ logIO A.Debug "making random"
|
||||
randList <- mapM (\_ -> randomRIO (0,1)) [0 .. (3599 :: Int)]
|
||||
liftIO $ logIO A.Debug "creating context"
|
||||
nanoCtx <- createGL3 (S.fromList [Antialias, StencilStrokes, NanoVG.Debug])
|
||||
let fullMatrix = fromList 60 60 randList
|
||||
-- logIO A.Debug $ prettyMatrix fullMatrix
|
||||
empty1 <- newTVarIO [] -- ([] :: [(UUID, WindowMessage -> Affection ())])
|
||||
empty3 <- newTVarIO [] -- ([] :: [(UUID, KeyboardMessage -> Affection ())])
|
||||
step <- newMVar True
|
||||
(\life food time -> UserData
|
||||
{ subsystems = Subsystems
|
||||
(Window empty1)
|
||||
(Keyboard empty3)
|
||||
, lifeMat = life
|
||||
, foodMat = food
|
||||
, timeMat = time
|
||||
, nano = nanoCtx
|
||||
, doNextStep = step
|
||||
}
|
||||
)
|
||||
<$> newMVar fullMatrix
|
||||
<*> (newMVar (fromList 60 60 (repeat 10)))
|
||||
<*> (newMVar (M.zero 60 60))
|
||||
|
||||
pre :: UserData -> Affection ()
|
||||
pre ud = do
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) (exitOnEsc (doNextStep ud))
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) (reloadOnR ud)
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) showFPS
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) toggleFullScreen
|
||||
void $ partSubscribe (subWindow $ subsystems ud) (exitOnWindowClose (doNextStep ud))
|
||||
void $ partSubscribe (subWindow $ subsystems ud) (fitViewport (600/600))
|
||||
|
||||
toggleFullScreen :: KeyboardMessage -> Affection ()
|
||||
toggleFullScreen (MsgKeyboardEvent _ _ SDL.Pressed False sym)
|
||||
| SDL.keysymKeycode sym == SDL.KeycodeF11 = toggleScreen 0
|
||||
| otherwise = return ()
|
||||
toggleFullScreen _ = return ()
|
||||
|
||||
exitOnEsc :: MVar Bool -> KeyboardMessage -> Affection ()
|
||||
exitOnEsc step (MsgKeyboardEvent _ _ SDL.Pressed False sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeEscape -> do
|
||||
liftIO $ logIO A.Debug "Yo dog I heard..."
|
||||
void $ liftIO $ swapMVar step False
|
||||
_ -> return ()
|
||||
exitOnEsc _ _ = return ()
|
||||
|
||||
reloadOnR :: UserData -> KeyboardMessage -> Affection ()
|
||||
reloadOnR ud (MsgKeyboardEvent _ _ _ _ sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeR -> reload ud
|
||||
_ -> return ()
|
||||
|
||||
reload :: UserData -> Affection ()
|
||||
reload ud = do
|
||||
randList <- liftIO $ mapM (\_ -> randomRIO (0,1)) [0 .. (3599 :: Int)]
|
||||
let fullMatrix = fromList 60 60 randList
|
||||
void $ liftIO $ swapMVar (lifeMat ud) fullMatrix
|
||||
void $ liftIO $ swapMVar (foodMat ud) (fromList 60 60 (repeat 10))
|
||||
void $ liftIO $ swapMVar (timeMat ud) (M.zero 60 60)
|
||||
|
||||
showFPS :: KeyboardMessage -> Affection ()
|
||||
showFPS (MsgKeyboardEvent _ _ _ _ sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeF -> do
|
||||
dt <- getDelta
|
||||
liftIO $ logIO A.Debug $ "FPS: " <> fromString (show (1 / dt))
|
||||
_ -> return ()
|
||||
|
||||
exitOnWindowClose :: MVar Bool -> WindowMessage -> Affection ()
|
||||
exitOnWindowClose step wm =
|
||||
case wm of
|
||||
MsgWindowClose _ _ -> do
|
||||
liftIO $ logIO A.Debug "I heard another one..."
|
||||
void $ liftIO $ swapMVar step False
|
||||
_ -> return ()
|
||||
|
||||
handle :: UserData -> [SDL.EventPayload] -> Affection ()
|
||||
handle ud es = do
|
||||
let (Subsystems a b) = subsystems ud
|
||||
_ <- consumeSDLEvents a =<< consumeSDLEvents b es
|
||||
return ()
|
||||
|
||||
update :: UserData -> Double -> Affection ()
|
||||
update ud _ = do
|
||||
-- liftIO $ logIO A.Debug ("FPS: " <> fromString (show (1/dt)))
|
||||
pastLife <- liftIO $ readMVar (lifeMat ud)
|
||||
pastFood <- liftIO $ readMVar (foodMat ud)
|
||||
pastTime <- liftIO $ readMVar (timeMat ud)
|
||||
newList <- mapM (\coord -> do
|
||||
let x = (coord `mod` 60) + 1
|
||||
y = (coord `div` 60) + 1
|
||||
subm
|
||||
| x == 1 && y == 1 =
|
||||
(submatrix 60 60 60 60 pastLife <|> submatrix 60 60 1 2 pastLife)
|
||||
<->
|
||||
(submatrix 1 2 60 60 pastLife <|> submatrix 1 2 1 2 pastLife)
|
||||
| x == 1 && y == 60 =
|
||||
(submatrix 59 60 60 60 pastLife <|> submatrix 59 60 1 2 pastLife)
|
||||
<->
|
||||
(submatrix 1 1 60 60 pastLife <|> submatrix 1 1 1 2 pastLife)
|
||||
| x == 60 && y == 1 =
|
||||
(submatrix 60 60 59 60 pastLife <|> submatrix 60 60 1 1 pastLife)
|
||||
<->
|
||||
(submatrix 1 2 59 60 pastLife <|> submatrix 1 2 1 1 pastLife)
|
||||
| x == 60 && y == 60 =
|
||||
(submatrix 59 60 59 60 pastLife <|> submatrix 59 60 1 1 pastLife)
|
||||
<->
|
||||
(submatrix 1 1 59 60 pastLife <|> submatrix 1 1 1 1 pastLife)
|
||||
| x == 1 =
|
||||
(submatrix (y - 1) (y + 1) 60 60 pastLife)
|
||||
<|>
|
||||
(submatrix (y - 1) (y + 1) 1 2 pastLife)
|
||||
| y == 1 =
|
||||
(submatrix 60 60 (x - 1) (x + 1) pastLife)
|
||||
<->
|
||||
(submatrix 1 2 (x - 1) (x + 1) pastLife)
|
||||
| x == 60 =
|
||||
(submatrix (y - 1) (y + 1) 59 60 pastLife)
|
||||
<|>
|
||||
(submatrix (y - 1) (y + 1) 1 1 pastLife)
|
||||
| y == 60 =
|
||||
(submatrix 59 60 (x -1 ) (x + 1) pastLife)
|
||||
<->
|
||||
(submatrix 1 1 (x - 1) (x + 1) pastLife)
|
||||
| otherwise =
|
||||
(submatrix (y - 1) (y + 1) (x - 1) (x + 1) pastLife)
|
||||
life = countLife subm
|
||||
if pastLife M.! (y, x) == 1
|
||||
then if (life == 2 || life == 3) && pastFood M.! (y, x) > 0
|
||||
then return (1, (pastFood M.! (y, x)) - 1, 0)
|
||||
else return (0, pastFood M.! (y, x), 0)
|
||||
else if life == 3 && pastFood M.! (y, x) > 0
|
||||
then return (1, (pastFood M.! (y, x)) - 1, 0)
|
||||
else return
|
||||
( (0 :: Word)
|
||||
, if pastTime M.! (y, x) > 10
|
||||
then min 10 ((pastFood M.! (y, x)) + 1)
|
||||
else min 10 (pastFood M.! (y, x))
|
||||
, pastTime M.! (y, x) + 1
|
||||
)
|
||||
) [0..3599]
|
||||
let newLifeMat = fromList 60 60 (map (\(x, _, _) -> x) newList)
|
||||
newFoodMat = fromList 60 60 (map (\(_, x, _) -> x) newList)
|
||||
newTimeMat = fromList 60 60 (map (\(_, _, x) -> x) newList)
|
||||
if newLifeMat == M.zero 60 60
|
||||
then
|
||||
reload ud
|
||||
else do
|
||||
((newLifeMat, newFoodMat, newTimeMat) `deepseq` return ())
|
||||
void $ liftIO $ swapMVar (lifeMat ud) newLifeMat
|
||||
void $ liftIO $ swapMVar (timeMat ud) newTimeMat
|
||||
|
||||
countLife :: Matrix Word -> Word
|
||||
countLife mat = res - (mat M.! (2, 2))
|
||||
where
|
||||
res = foldr (flip (+)) 0 mat
|
||||
|
||||
draw :: UserData -> Affection ()
|
||||
draw ud = do
|
||||
life <- liftIO $ readMVar (lifeMat ud)
|
||||
food <- liftIO $ readMVar (foodMat ud)
|
||||
liftIO $ do
|
||||
beginFrame (nano ud) 600 600 1
|
||||
save (nano ud)
|
||||
mapM_ (\coord -> do
|
||||
let x = coord `mod` 60
|
||||
y = coord `div` 60
|
||||
ctx = nano ud
|
||||
mult = life M.! (x + 1, y + 1)
|
||||
-- logIO A.Debug $ show mult
|
||||
beginPath ctx
|
||||
rect ctx (fromIntegral $ x * 10) (fromIntegral $ y * 10) 10 10
|
||||
if mult == 1
|
||||
then
|
||||
fillColor ctx (rgba 255 255 255 255)
|
||||
else
|
||||
fillColor ctx (rgba 0 (fromIntegral $ 25 * (food M.! (x+1, y+1))) 0 255)
|
||||
fill ctx
|
||||
) [0..3599]
|
||||
restore (nano ud)
|
||||
endFrame (nano ud)
|
||||
|
||||
clean :: UserData -> IO ()
|
||||
clean _ = return ()
|
|
@ -1,78 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
module Types where
|
||||
|
||||
import Affection
|
||||
|
||||
import Data.Matrix as M
|
||||
|
||||
import NanoVG
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MVar
|
||||
|
||||
data UserData = UserData
|
||||
{ lifeMat :: MVar (Matrix Word)
|
||||
, foodMat :: MVar (Matrix Word)
|
||||
, timeMat :: MVar (Matrix Word)
|
||||
, subsystems :: Subsystems
|
||||
, nano :: Context
|
||||
, doNextStep :: MVar Bool
|
||||
}
|
||||
|
||||
data Subsystems = Subsystems
|
||||
{ subWindow :: Types.Window
|
||||
, subKeyboard :: Types.Keyboard
|
||||
}
|
||||
|
||||
newtype Window = Window (TVar [(UUID, WindowMessage -> Affection ())])
|
||||
|
||||
newtype Keyboard = Keyboard (TVar [(UUID, KeyboardMessage -> Affection ())])
|
||||
|
||||
instance Participant Types.Window where
|
||||
type Mesg Types.Window = WindowMessage
|
||||
|
||||
partSubscribers (Window t) = do
|
||||
subTups <- liftIO $ readTVarIO t
|
||||
return $ map snd subTups
|
||||
|
||||
partSubscribe (Window t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Window t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Types.Window where
|
||||
consumeSDLEvents = consumeSDLWindowEvents
|
||||
|
||||
instance Participant Keyboard where
|
||||
type Mesg Keyboard = KeyboardMessage
|
||||
|
||||
partSubscribers (Keyboard t) = do
|
||||
subTups <- liftIO $ readTVarIO t
|
||||
return $ map snd subTups
|
||||
|
||||
partSubscribe (Keyboard t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Keyboard t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Keyboard where
|
||||
consumeSDLEvents = consumeSDLKeyboardEvents
|
||||
|
||||
generalSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> (msg -> Affection ())
|
||||
-> Affection UUID
|
||||
generalSubscribe t funct = do
|
||||
uuid <- genUUID
|
||||
liftIO $ atomically $ modifyTVar' t ((uuid, funct) :)
|
||||
return uuid
|
||||
|
||||
generalUnSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> UUID
|
||||
-> Affection ()
|
||||
generalUnSubscribe t uuid =
|
||||
liftIO $ atomically $ modifyTVar' t (filter (`filterMsg` uuid))
|
||||
where
|
||||
filterMsg :: (UUID, msg -> Affection ()) -> UUID -> Bool
|
||||
filterMsg (u, _) p = u /= p
|
|
@ -1,253 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||
|
||||
import Affection as A
|
||||
import qualified SDL
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MVar
|
||||
import Control.Monad
|
||||
import Control.DeepSeq (deepseq)
|
||||
|
||||
import Data.Matrix as M
|
||||
import qualified Data.Set as S
|
||||
import Data.String
|
||||
|
||||
import System.Random (randomRIO)
|
||||
|
||||
import NanoVG hiding (V2(..))
|
||||
|
||||
import Foreign.C.Types (CInt(..))
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
|
||||
instance Affectionate UserData where
|
||||
loadState = load
|
||||
preLoop = pre
|
||||
handleEvents = handle
|
||||
update = Main.update
|
||||
draw = Main.draw
|
||||
cleanUp = clean
|
||||
hasNextStep = liftIO . readMVar . doNextStep
|
||||
|
||||
foreign import ccall unsafe "glewInit"
|
||||
glewInit :: IO CInt
|
||||
|
||||
maxFood :: Word
|
||||
maxFood = 255
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
logIO A.Debug "Starting"
|
||||
let conf = AffectionConfig
|
||||
{ initComponents = All
|
||||
, windowTitle = "affection: example01"
|
||||
, windowConfigs =
|
||||
[
|
||||
( 0
|
||||
, SDL.defaultWindow
|
||||
{ SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
||||
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
|
||||
}
|
||||
, SDL.windowInitialSize = SDL.V2 600 600
|
||||
, SDL.windowResizable = True
|
||||
}
|
||||
, SDL.Windowed
|
||||
)
|
||||
]
|
||||
} :: AffectionConfig UserData
|
||||
withAffection conf
|
||||
|
||||
load :: IO UserData
|
||||
load = do
|
||||
-- emptyMatrix <- zero 60 60
|
||||
liftIO $ logIO A.Debug "init GLEW"
|
||||
_ <- glewInit
|
||||
liftIO $ logIO A.Debug "making random"
|
||||
randList <- mapM (\_ -> randomRIO (0,1)) [0 .. (3599 :: Int)]
|
||||
liftIO $ logIO A.Debug "creating context"
|
||||
nanoCtx <- createGL3 (S.fromList [Antialias, StencilStrokes, NanoVG.Debug])
|
||||
let fullMatrix = fromList 60 60 randList
|
||||
-- logIO A.Debug $ prettyMatrix fullMatrix
|
||||
empty1 <- newTVarIO [] -- ([] :: [(UUID, WindowMessage -> Affection ())])
|
||||
empty3 <- newTVarIO [] -- ([] :: [(UUID, KeyboardMessage -> Affection ())])
|
||||
(\life food time nextStep -> UserData
|
||||
{ subsystems = Subsystems
|
||||
(Window empty1)
|
||||
(Keyboard empty3)
|
||||
, lifeMat = life
|
||||
, foodMat = food
|
||||
, timeMat = time
|
||||
, nano = nanoCtx
|
||||
, doNextStep = nextStep
|
||||
}
|
||||
)
|
||||
<$> newMVar fullMatrix
|
||||
<*> newMVar (fromList 60 60 (repeat maxFood))
|
||||
<*> newMVar (M.zero 60 60)
|
||||
<*> newMVar True
|
||||
|
||||
pre :: UserData -> Affection ()
|
||||
pre ud = do
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) (exitOnEsc (doNextStep ud))
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) (reloadOnR ud)
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) showFPS
|
||||
void $ partSubscribe (subKeyboard $ subsystems ud) toggleFullScreen
|
||||
void $ partSubscribe (subWindow $ subsystems ud) (exitOnWindowClose (doNextStep ud))
|
||||
void $ partSubscribe (subWindow $ subsystems ud) (fitViewport (600/600))
|
||||
|
||||
toggleFullScreen :: KeyboardMessage -> Affection ()
|
||||
toggleFullScreen (MsgKeyboardEvent _ _ SDL.Pressed False sym)
|
||||
| SDL.keysymKeycode sym == SDL.KeycodeF11 = toggleScreen 0
|
||||
| otherwise = return ()
|
||||
toggleFullScreen _ = return ()
|
||||
|
||||
exitOnEsc :: MVar Bool -> KeyboardMessage -> Affection ()
|
||||
exitOnEsc step (MsgKeyboardEvent _ _ SDL.Pressed False sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeEscape -> do
|
||||
liftIO $ logIO A.Debug "Yo dog I heard..."
|
||||
void $ liftIO $ swapMVar step False
|
||||
_ -> return ()
|
||||
exitOnEsc _ _ = return ()
|
||||
|
||||
reloadOnR :: UserData -> KeyboardMessage -> Affection ()
|
||||
reloadOnR ud (MsgKeyboardEvent _ _ _ _ sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeR -> reload ud
|
||||
_ -> return ()
|
||||
|
||||
reload :: UserData -> Affection ()
|
||||
reload ud = do
|
||||
randList <- liftIO $ mapM (\_ -> randomRIO (0,1)) [0 .. (3599 :: Int)]
|
||||
let fullMatrix = fromList 60 60 randList
|
||||
void $ liftIO $ swapMVar (lifeMat ud) fullMatrix
|
||||
void $ liftIO $ swapMVar (foodMat ud) (fromList 60 60 (repeat maxFood))
|
||||
void $ liftIO $ swapMVar (timeMat ud) (M.zero 60 60)
|
||||
|
||||
showFPS :: KeyboardMessage -> Affection ()
|
||||
showFPS (MsgKeyboardEvent _ _ _ _ sym) =
|
||||
case SDL.keysymKeycode sym of
|
||||
SDL.KeycodeF -> do
|
||||
dt <- getDelta
|
||||
liftIO $ logIO A.Debug $ "FPS: " <> fromString (show (1 / dt))
|
||||
_ -> return ()
|
||||
|
||||
exitOnWindowClose :: MVar Bool -> WindowMessage -> Affection ()
|
||||
exitOnWindowClose step wm =
|
||||
case wm of
|
||||
MsgWindowClose _ _ -> do
|
||||
liftIO $ logIO A.Debug "I heard another one..."
|
||||
void $ liftIO $ swapMVar step False
|
||||
_ -> return ()
|
||||
|
||||
handle :: UserData -> [SDL.EventPayload] -> Affection ()
|
||||
handle ud es = do
|
||||
let (Subsystems a b) = subsystems ud
|
||||
_ <- consumeSDLEvents a =<< consumeSDLEvents b es
|
||||
return ()
|
||||
|
||||
update :: UserData -> Double -> Affection ()
|
||||
update ud _ = do
|
||||
pastLife <- liftIO $ readMVar (lifeMat ud)
|
||||
pastFood <- liftIO $ readMVar (foodMat ud)
|
||||
pastTime <- liftIO $ readMVar (timeMat ud)
|
||||
newList <- mapM (\coord -> do
|
||||
let x = (coord `mod` 60) + 1
|
||||
y = (coord `div` 60) + 1
|
||||
subm
|
||||
| x == 1 && y == 1 =
|
||||
(submatrix 60 60 60 60 pastLife <|> submatrix 60 60 1 2 pastLife)
|
||||
<->
|
||||
(submatrix 1 2 60 60 pastLife <|> submatrix 1 2 1 2 pastLife)
|
||||
| x == 1 && y == 60 =
|
||||
(submatrix 59 60 60 60 pastLife <|> submatrix 59 60 1 2 pastLife)
|
||||
<->
|
||||
(submatrix 1 1 60 60 pastLife <|> submatrix 1 1 1 2 pastLife)
|
||||
| x == 60 && y == 1 =
|
||||
(submatrix 60 60 59 60 pastLife <|> submatrix 60 60 1 1 pastLife)
|
||||
<->
|
||||
(submatrix 1 2 59 60 pastLife <|> submatrix 1 2 1 1 pastLife)
|
||||
| x == 60 && y == 60 =
|
||||
(submatrix 59 60 59 60 pastLife <|> submatrix 59 60 1 1 pastLife)
|
||||
<->
|
||||
(submatrix 1 1 59 60 pastLife <|> submatrix 1 1 1 1 pastLife)
|
||||
| x == 1 =
|
||||
(submatrix (y - 1) (y + 1) 60 60 pastLife)
|
||||
<|>
|
||||
(submatrix (y - 1) (y + 1) 1 2 pastLife)
|
||||
| y == 1 =
|
||||
(submatrix 60 60 (x - 1) (x + 1) pastLife)
|
||||
<->
|
||||
(submatrix 1 2 (x - 1) (x + 1) pastLife)
|
||||
| x == 60 =
|
||||
(submatrix (y - 1) (y + 1) 59 60 pastLife)
|
||||
<|>
|
||||
(submatrix (y - 1) (y + 1) 1 1 pastLife)
|
||||
| y == 60 =
|
||||
(submatrix 59 60 (x -1 ) (x + 1) pastLife)
|
||||
<->
|
||||
(submatrix 1 1 (x - 1) (x + 1) pastLife)
|
||||
| otherwise =
|
||||
(submatrix (y - 1) (y + 1) (x - 1) (x + 1) pastLife)
|
||||
life = countLife subm
|
||||
if pastLife M.! (y, x) == 1
|
||||
then if (life == 2 || life == 3) && pastFood M.! (y, x) > 0
|
||||
then return (1, (pastFood M.! (y, x)) - 1, 0)
|
||||
else return (0, pastFood M.! (y, x), 0)
|
||||
else if life == 3 && pastFood M.! (y, x) > 0
|
||||
then return (1, (pastFood M.! (y, x)) - 1, 0)
|
||||
else return
|
||||
( 0 :: Word
|
||||
, if pastTime M.! (y, x) > 10
|
||||
then min maxFood ((pastFood M.! (y, x)) + 1)
|
||||
else min maxFood (pastFood M.! (y, x))
|
||||
, pastTime M.! (y, x) + 1
|
||||
)
|
||||
) [0..3599]
|
||||
let newLifeMat = fromList 60 60 (map (\(x, _, _) -> x) newList)
|
||||
newFoodMat = fromList 60 60 (map (\(_, x, _) -> x) newList)
|
||||
newTimeMat = fromList 60 60 (map (\(_, _, x) -> x) newList)
|
||||
if newLifeMat == M.zero 60 60
|
||||
then
|
||||
reload ud
|
||||
else do
|
||||
((newLifeMat, newFoodMat, newTimeMat) `deepseq` return ())
|
||||
void $ liftIO $ swapMVar (lifeMat ud) newLifeMat
|
||||
void $ liftIO $ swapMVar (timeMat ud) newTimeMat
|
||||
void $ liftIO $ swapMVar (foodMat ud) newFoodMat
|
||||
|
||||
countLife :: Matrix Word -> Word
|
||||
countLife mat = res - (mat M.! (2, 2))
|
||||
where
|
||||
res = foldr (flip (+)) 0 mat
|
||||
|
||||
draw :: UserData -> Affection ()
|
||||
draw ud = liftIO $ do
|
||||
pastLife <- readMVar (lifeMat ud)
|
||||
pastFood <- readMVar (foodMat ud)
|
||||
beginFrame (nano ud) 600 600 1
|
||||
save (nano ud)
|
||||
mapM_ (\coord -> do
|
||||
let x = coord `mod` 60
|
||||
y = coord `div` 60
|
||||
ctx = nano ud
|
||||
multiplicator = pastLife M.! (x + 1, y + 1)
|
||||
-- logIO A.Debug $ show mult
|
||||
beginPath ctx
|
||||
rect ctx (fromIntegral $ x * 10) (fromIntegral $ y * 10) 10 10
|
||||
if multiplicator == 1
|
||||
then
|
||||
fillColor ctx (rgba 255 255 255 255)
|
||||
else
|
||||
fillColor ctx (rgba 0 (fromIntegral $ (255 `div` maxFood) * (pastFood M.! (x+1, y+1))) 0 255)
|
||||
fill ctx
|
||||
) [0..3599]
|
||||
restore (nano ud)
|
||||
endFrame (nano ud)
|
||||
|
||||
clean :: UserData -> IO ()
|
||||
clean _ = return ()
|
|
@ -1,78 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
module Types where
|
||||
|
||||
import Affection
|
||||
|
||||
import Data.Matrix as M
|
||||
|
||||
import NanoVG
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Control.Concurrent.MVar
|
||||
|
||||
data UserData = UserData
|
||||
{ lifeMat :: MVar (Matrix Word)
|
||||
, foodMat :: MVar (Matrix Word)
|
||||
, timeMat :: MVar (Matrix Word)
|
||||
, subsystems :: Subsystems
|
||||
, nano :: Context
|
||||
, doNextStep :: MVar Bool
|
||||
}
|
||||
|
||||
data Subsystems = Subsystems
|
||||
{ subWindow :: Types.Window
|
||||
, subKeyboard :: Types.Keyboard
|
||||
}
|
||||
|
||||
newtype Window = Window (TVar [(UUID, WindowMessage -> Affection ())])
|
||||
|
||||
newtype Keyboard = Keyboard (TVar [(UUID, KeyboardMessage -> Affection ())])
|
||||
|
||||
instance Participant Types.Window where
|
||||
type Mesg Types.Window = WindowMessage
|
||||
|
||||
partSubscribers (Window t) = do
|
||||
subTups <- liftIO $ readTVarIO t
|
||||
return $ map snd subTups
|
||||
|
||||
partSubscribe (Window t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Window t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Types.Window where
|
||||
consumeSDLEvents = consumeSDLWindowEvents
|
||||
|
||||
instance Participant Keyboard where
|
||||
type Mesg Keyboard = KeyboardMessage
|
||||
|
||||
partSubscribers (Keyboard t) = do
|
||||
subTups <- liftIO $ readTVarIO t
|
||||
return $ map snd subTups
|
||||
|
||||
partSubscribe (Keyboard t) = generalSubscribe t
|
||||
|
||||
partUnSubscribe (Keyboard t) = generalUnSubscribe t
|
||||
|
||||
instance SDLSubsystem Keyboard where
|
||||
consumeSDLEvents = consumeSDLKeyboardEvents
|
||||
|
||||
generalSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> (msg -> Affection ())
|
||||
-> Affection UUID
|
||||
generalSubscribe t funct = do
|
||||
uuid <- genUUID
|
||||
liftIO $ atomically $ modifyTVar' t ((uuid, funct) :)
|
||||
return uuid
|
||||
|
||||
generalUnSubscribe
|
||||
:: TVar [(UUID, msg -> Affection ())]
|
||||
-> UUID
|
||||
-> Affection ()
|
||||
generalUnSubscribe t uuid =
|
||||
liftIO $ atomically $ modifyTVar' t (filter (`filterMsg` uuid))
|
||||
where
|
||||
filterMsg :: (UUID, msg -> Affection ()) -> UUID -> Bool
|
||||
filterMsg (u, _) p = u /= p
|
110
flake.lock
Normal file
|
@ -0,0 +1,110 @@
|
|||
{
|
||||
"nodes": {
|
||||
"affection-src": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1679777510,
|
||||
"narHash": "sha256-FXtXhmUWtBt8944WIAXgB3OuIT446vUvfmccobXu6ts=",
|
||||
"ref": "refs/heads/master",
|
||||
"rev": "445b5807e021ff6fb70fdfa3f7e6a0a2b2221609",
|
||||
"revCount": 300,
|
||||
"type": "git",
|
||||
"url": "https://gitea.nek0.eu/nek0/affection"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.nek0.eu/nek0/affection"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1678901627,
|
||||
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1679747397,
|
||||
"narHash": "sha256-btdjcq9pGJyKNbU5qQpKfWdEwoj+uazeSpchJjHrt3k=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e235465058f37b1a4f222957352c1e373905521d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681963077,
|
||||
"narHash": "sha256-8uJm8D6bJ7HEUkeHiWYbSfYKKhEIcgCsp/FQaGTS8RM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "7ddf6698abe1eec2479590144701ca88fe2fcfe9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"affection-src": "affection-src",
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
58
flake.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
description = "A game stub written in Haskell";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
affection-src.url = "git+https://gitea.nek0.eu/nek0/affection";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, affection-src }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
haskellPackages = pkgs.haskellPackages;
|
||||
|
||||
jailbreakUnbreak = pkg:
|
||||
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
|
||||
|
||||
packageName = "pituicat";
|
||||
in rec {
|
||||
packages.${packageName} = # (ref:haskell-package-def)
|
||||
haskellPackages.callCabal2nix packageName self rec {
|
||||
# Dependency overrides go here
|
||||
affection = affection-src.defaultPackage.${system};
|
||||
};
|
||||
|
||||
defaultPackage = self.packages.${system}.${packageName};
|
||||
|
||||
devShell = haskellPackages.shellFor {
|
||||
packages = p: [ defaultPackage ];
|
||||
withHoogle = true;
|
||||
buildInputs = (with haskellPackages; [
|
||||
haskell-language-server
|
||||
ghcid
|
||||
cabal-install
|
||||
]) ++ (with pkgs; [
|
||||
glib.dev
|
||||
]);
|
||||
};
|
||||
#devShell = pkgs.mkShell {
|
||||
# buildInputs = with haskellPackages; [
|
||||
# haskell-language-server
|
||||
# ghcid
|
||||
# cabal-install
|
||||
# ];
|
||||
# nativeBuildInputs = with pkgs; [
|
||||
# pkg-config
|
||||
# SDL2
|
||||
# vulkan-validation-layers
|
||||
# vulkan-headers
|
||||
# vulkan-loader
|
||||
# ];
|
||||
# inputsFrom = builtins.attrValues self.packages.${system};
|
||||
#};
|
||||
});
|
||||
}
|
||||
|
BIN
gdd/10pager.pdf
Normal file
445
gdd/10pager.tex
Normal file
|
@ -0,0 +1,445 @@
|
|||
\documentclass[12pt,a4paper]{scrartcl}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[english]{babel}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{csquotes}
|
||||
\usepackage{menukeys}
|
||||
\usepackage[hidelinks]{hyperref}
|
||||
\usepackage[left=3.00cm, right=3.00cm, top=3.00cm, bottom=3.00cm]{geometry}
|
||||
|
||||
\setlength{\parindent}{0pt}
|
||||
\newcommand{\nbreak}{
|
||||
\hspace*{0pt}
|
||||
\newpage
|
||||
\hspace*{0pt}
|
||||
}
|
||||
|
||||
\author{Amedeo Molnár}
|
||||
\title{\vfill Pituicat}
|
||||
\date{\today}
|
||||
|
||||
\begin{document}
|
||||
\pagenumbering{gobble}
|
||||
\maketitle
|
||||
\begin{center}
|
||||
Target Platform: PC(Linux/Win) \quad Target audience: Ages 15 - 35
|
||||
\end{center}
|
||||
\vfill
|
||||
|
||||
\newpage
|
||||
\tableofcontents
|
||||
|
||||
\newpage
|
||||
\pagenumbering{arabic}
|
||||
\setcounter{page}{1}
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Game story}
|
||||
|
||||
You are a cat. or at least you used to be one, until you accidentally fell into
|
||||
a vat with the latest failed biochem experiment of your owner as the military,
|
||||
your owners employers, sack him and clean the lab in a hurry. You get poured down
|
||||
the drain by an assistant while your owner gets escorted away in handcuffs.
|
||||
|
||||
When you wake up again in the sewer you have solidified again to a small meowing
|
||||
gelatinous blob. You are hungry and you yearn for your owner's affection. But
|
||||
where has he been taken to?
|
||||
|
||||
You set out to find him, but have to fend off enemies and withstand dangerous
|
||||
environments while you make your journey through multiple locations finding clues
|
||||
about your owner's whereabouts.
|
||||
|
||||
Powerups and DNA-Fragments for unlocking new
|
||||
abilities help you on your way through increasingly dangerous stages full of
|
||||
different levels.
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Game play}
|
||||
|
||||
In \enquote{Pituicat} You play as slime cat in search of its owner.
|
||||
|
||||
The Levels of the game as well as its story are divided into six stages,
|
||||
each ending with a boss fight.
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Player character}
|
||||
|
||||
In the beginning the player character is about the size of a pea, has low health and
|
||||
can barely lift off the ground when jumping. But as the player advances he will be
|
||||
awarded DNA-Fragments for defeating bosses and will be able to find powerups and
|
||||
hidden DNA-Fragments.
|
||||
Powerups grant some temporary boni whereas DNA-Fragments are used to activate
|
||||
permanent abilities or increase your health.
|
||||
With every stage also the size of the character increases. Starting at pea size, you
|
||||
grow to grape size to golf ball size to tennis ball size to rugby size until you
|
||||
reach the size of a large cat.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Abilities}
|
||||
|
||||
The activatable abilities, all having three levels, include:
|
||||
|
||||
\begin{itemize}
|
||||
\item Health up (Adds 50\% of your start health to your max health per level)
|
||||
\item Congeal (reduces damage by 25\% of remaining damage per level)
|
||||
\item Vacuole (store one collected powerup per level)
|
||||
\item Spit (shoot acidic projectiles with ranges from 2 over 4 to 8 tiles)
|
||||
\item Harden (become invulnerable but almost immobile for 1 second. Cooldown starts at 4
|
||||
seconds and can be reduced to two and finally to 1 second)
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Powerups}
|
||||
|
||||
Powerups appear on the map as floating droplets and can also be occasionally dropped by
|
||||
enemies or during boss fights. Droplets spawning on the map do respawn, others not.
|
||||
|
||||
These are the available powerups, which will be gradually introduced into the game with
|
||||
every new stage:
|
||||
|
||||
\begin{itemize}
|
||||
\item Peptide (replenishes 5\% of start health)
|
||||
\item Oily Emulsion (Increase speed by 25\% for 5 seconds)
|
||||
\item Latex (Increase jump height by 100\% for 5 seconds)
|
||||
\item Organic Lead (decrease damage by 50\% but disable jumping for 5 seconds)
|
||||
\item Antidote (Heal poisoning immediately)
|
||||
\item Purified Caffeine (Stop surrounding time for 2 seconds)
|
||||
\item Agent X (Become almost invisible for 5 seconds)
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Player Controls}
|
||||
|
||||
The controls described here take a QWERTZ-keyboard as reference.
|
||||
|
||||
\begin{tabular}{ll}
|
||||
|
||||
\keys{A} & Slither left\\
|
||||
|
||||
\keys{D} & Slither right\\
|
||||
|
||||
\keys{W} & Jump\\
|
||||
|
||||
\keys{S} & Jump down through Platform\\
|
||||
|
||||
\keys{F} & Interact\\
|
||||
|
||||
\keys{1}, \keys{2}, \keys{3} & Release powerup from specified vacuole\\
|
||||
|
||||
\keys{E} & Harden\\
|
||||
|
||||
\keys{\space} & Spit\\
|
||||
|
||||
\keys{Esc} & Enter/Exit Menu\\
|
||||
|
||||
\end{tabular}
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Game world}
|
||||
|
||||
The game world is a mostly urbanized landscape with some elements
|
||||
from cyberpunk.
|
||||
|
||||
The levels are themed after the stages they are in and vary slightly
|
||||
in size, but aim to be rather big and not monolinear. Players can collect
|
||||
powerups and rarely even DNA-Fragments, which at the end of the Level can
|
||||
be traded in for new or improved abilities.
|
||||
|
||||
Hand crafted carefully composed assets paired with thoughtful level
|
||||
design aim for an immersable game with a strong retro feel.
|
||||
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Game experience}
|
||||
|
||||
The game is divided into the following six stages:
|
||||
|
||||
\begin{itemize}
|
||||
\item The Sewer
|
||||
\item Back Alley
|
||||
\item Abandoned Lab
|
||||
\item The Highway
|
||||
\item Military-Industrial complex
|
||||
\item Secret base
|
||||
\end{itemize}
|
||||
|
||||
Every stage has its distinct design and set of enemies, puzzles and obstacles as
|
||||
well as a final Boss to be overcome to succeed.
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{The Sewer}
|
||||
|
||||
The Sewer is a dark and wet place full of dangerous waste and different vermin.
|
||||
|
||||
Your main enemies are giant woodlice, mice, rats and goldfish. Contact with
|
||||
water or other fluids pooling, flowing or driping down there is harmful to the
|
||||
character.
|
||||
|
||||
Puzzles include opening valve systems or restoring lighting to pitch
|
||||
dark areas.
|
||||
|
||||
The Boss at the end of this stage is \enquote{King Rat}.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Back Alley}
|
||||
|
||||
The back alley is a dim place heaping with garbage of various kinds and access
|
||||
point to many different kinds of infrastructure mostly fallen into disrepair.
|
||||
|
||||
Fluids pooling in dumpsters or the street as well as ill maintained electrical
|
||||
wiring are the environmental dangers accompanied by rats, spiders, robotic
|
||||
cleaners and various birds as enemies.
|
||||
|
||||
You will have to shut down electricity to progress or carefully time runs
|
||||
between active garbage chutes and trick birds.
|
||||
|
||||
The boss at the end of this stage is \enquote{The Raven}.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Abandoned Lab}
|
||||
|
||||
The abandoned lab is the place you used to live with your owner while he was
|
||||
tinkering on various projects from varying fields of science and engineering.
|
||||
Now this place is deserted, stripped of all usable equipment and left to rot.
|
||||
|
||||
Unfortunately for you this place is far from empty. Semi conscious AI robots
|
||||
cybernetically or genetically enhanced hamsters which all managed to escape
|
||||
the sudden purge of the lab as well es still present malfunctioning equipment
|
||||
and custom or even selfmade security measures are blocking your way.
|
||||
|
||||
As you might expect, the puzzles in an former lab of an almost mad scientist
|
||||
are hard, include teleporting or even manipulation of space and time and force
|
||||
you to be present at multiple locations simultaneously.
|
||||
|
||||
The boss at the end of this stage is \enquote{CyberPsy}
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{The Highway}
|
||||
|
||||
The hot and dusty highway is not a good place for a small lonely little slime
|
||||
cat.
|
||||
|
||||
These surroundings are only scarcely populated, but some snakelings and
|
||||
lizards thrive here. In addition the scorching sun heating up the asphalt and
|
||||
lizard traps pose dangers in this environment.
|
||||
|
||||
The main Puzzle here will be how to stay outside the sun most of the time or
|
||||
how to change the environment to create shade.
|
||||
|
||||
The boss at the end of this stage is \enquote{Mother Snake}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Military-Industrial Complex}
|
||||
|
||||
This compound of barracks, factories, workshops and traininig grounds is off
|
||||
limits to the general public and is surrounded by a heavily guarded death strip.
|
||||
|
||||
You will have to deal with automated turrets, electric fences, ground spikes in
|
||||
addition to guard dogs, mobile defense bots and flying surveillance or attack
|
||||
drones.
|
||||
|
||||
You will have to figure out how to enter the seemingly impenetrable fortress
|
||||
of the secret base without arising too much suspicion on your way in.
|
||||
|
||||
The boss at the end of this stage is \enquote{M30w}.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Secret Base}
|
||||
|
||||
Under the Complex it lies, the secret base and only few know of its existence.
|
||||
Here lies the heart of most secret military research and surveillance.
|
||||
|
||||
Enemies include military personel and special operatives and even experimental
|
||||
cyborgs or armed killer robots. There is a lot of lethal security measures
|
||||
installed to prevent unauthorized entering.
|
||||
|
||||
Trick your way in through mazes of deadly laser arrays, confuse enemies so they
|
||||
turn on each other and deactivate complex defense mechanisms to path your way
|
||||
to the heart of the base.
|
||||
|
||||
The Boss at the end of this stage is \enquote{Node Kroenen}.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{How to win}
|
||||
|
||||
clear all levels and stages and defeat all bosses.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{How to lose}
|
||||
|
||||
Your health drops to zero.
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Game mechanics}
|
||||
|
||||
\enquote{Pituicat} takes place in a two-dimensional world viewed from the side, the typical
|
||||
platformer view. The camera is usually centered on the player and follows his character thus
|
||||
scrolling horizontally and vertically, depending on level size in the direction of movement.
|
||||
The player moves around the map in real time as do the enemies. A HUD on screen schows
|
||||
remaining health in from of a bar the active powerup if any and the stored up to three
|
||||
powerups if any.
|
||||
|
||||
\hspace{.5cm}
|
||||
|
||||
A player in game can move around, jump and interact with certain objects in the game like
|
||||
valves or switches. The number of active control buttons on the keyboard rises as the player
|
||||
progresses and activates new abilities, but are mapped out to be easily reachable with one
|
||||
hand. Powerups and DNA-Fragments laying around on the map or dropped by enemies are collected
|
||||
actively by the player through direct contact. After clearing each level the player can spend
|
||||
newly gained DNA-Fragments on abilities on a static screen also showing some statistics on
|
||||
the player's progress before advancing to the next level.
|
||||
|
||||
\hspace{.5cm}
|
||||
|
||||
In \enquote{Pituicat} there is a number of active and passive abilities a player can invest
|
||||
DNA-Fragments in, enabling new actions or simply aiding the player's survival.
|
||||
Every ability has three levels of power, which can be activated coonsuming a DNA-Fragment,
|
||||
but only when the previous power level has been already activated. Unlocking an ability,
|
||||
also raising the power level to one, does not require any previous level of any other
|
||||
ability, but also consumes a DNA-Fragment.
|
||||
|
||||
\hspace{.5cm}
|
||||
|
||||
An example for a passive ability would be \enquote{Congeal}, which reduces received damage
|
||||
by 25\% per power level.
|
||||
|
||||
\hspace{.5cm}
|
||||
|
||||
Another example, this time for an active ability, is \enquote{Spit}, which enables the
|
||||
player to shoot a projectile with increasing range for each power level starting with
|
||||
two tile lengths over four to eight before dissolving into thin air.
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Enemies}
|
||||
|
||||
Every stage of the game has it's own set of enemies with varying sets of abilities. Below
|
||||
is a sample of enemies ordered by stage and a short description of the stage's boss.
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{The Sewer}
|
||||
|
||||
\begin{itemize}
|
||||
\item Woodlice eat everything looking edible and can roll up to a ball if threatened.
|
||||
\item Goldfish jump out of water to catch prey.
|
||||
\item \enquote{King Rat} is accompanied by his large and ever hungry court of rat minions
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Back alley}
|
||||
|
||||
\begin{itemize}
|
||||
\item Rats mourn their lost king and are furious
|
||||
\item Spiders can shoot webs slowing you down
|
||||
\item \enquote{The Raven} drops heavy pieces of garbage onto its prey and deflects
|
||||
projectiles with mighty gusts of wind.
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Abandoned Lab}
|
||||
|
||||
\begin{itemize}
|
||||
\item Cyberhamsters ccan dash forward very quickly with their cybernetic limbs
|
||||
\item Axolotls spit acidic drops and can return from the dead.
|
||||
\item \enquote{CyberPsy} is a genetically altered cybernetically enhanced capuchin monkey
|
||||
with psionic abilities.
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\nbreak
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{The Highway}
|
||||
|
||||
\begin{itemize}
|
||||
\item Lizards can be particularly tough and fast, it is very hot there.
|
||||
\item Bigger snakescan spit venom at the player.
|
||||
\item \enquote{Mother Snake} has a lot of hungry babies and has powerful venom dealing
|
||||
damage over a prolonged period of time.
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Military-Industrial Complex}
|
||||
|
||||
\begin{itemize}
|
||||
\item Flying drones use the blades of their rotors as weapons
|
||||
\item Guard dogs can alert other guard dogs
|
||||
\item \enquote{M30w}, a cybernetically enhanced bobcat, has a powerful jaw and can eject
|
||||
its claws attached with dangerous microfilament
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\subsection{Secret Base}
|
||||
|
||||
\begin{itemize}
|
||||
\item Military personel is armed and shoots on sight
|
||||
\item Operatives can turn invisible for a period of time
|
||||
\item \enquote{Node Kroenen} is your owner, stripped of his personality and attached as
|
||||
central command and control unit to a giant Mech
|
||||
\end{itemize}
|
||||
|
||||
\vfill
|
||||
|
||||
\section{Cutscenes}
|
||||
|
||||
Narrative cutscenes will take place at the beginning of the game and et the end of each stage.
|
||||
|
||||
\section{Bonus Materials}
|
||||
|
||||
Bonus levels might be possible.
|
||||
|
||||
\hspace*{0pt}
|
||||
|
||||
\end{document}
|
BIN
gdd/1pager.pdf
Normal file
67
gdd/1pager.tex
Normal file
|
@ -0,0 +1,67 @@
|
|||
\documentclass[10pt,a4paper]{scrartcl}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[english]{babel}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{graphicx}
|
||||
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
|
||||
\author{Amedeo Molnár}
|
||||
\title{Pituicat}
|
||||
\date{\today}
|
||||
|
||||
\setlength{\parindent}{0pt}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\section{Game Platform}
|
||||
|
||||
PC (Linux/Win)
|
||||
|
||||
\section{Target audience}
|
||||
|
||||
Ages 15 - 35
|
||||
|
||||
\section{Game summary}
|
||||
|
||||
You are a cat. At least you used to be one, until you fell into one of your
|
||||
owner's experiments at the biochem lab, dissolved to goo and got poured down
|
||||
the drain by one of the assistants.
|
||||
|
||||
When you wake up in the sewer you turned into a gelatinous meowing blob. As
|
||||
you set out to look for your owner you pass multiple locations and find useful
|
||||
stuff.
|
||||
|
||||
\section{Game outline}
|
||||
|
||||
The player controls a slime cat in a through a jump'n'run styled game avoiding
|
||||
enemies and harsh environment.
|
||||
|
||||
The Game and its story are divided into several
stages, which in turn are
|
||||
divided into multiple levels. Between levels you can
invest collected
|
||||
DNA-Fragments on already unlocked abilities or increase your
health and
|
||||
every few levels you hit a milestone where you can unlock new
abilities
|
||||
through DNA-Fragments.
|
||||
|
||||
\section{Unique selling points}
|
||||
|
||||
\begin{itemize}
|
||||
\item Old school Jump'n'Run meets RPG elements
|
||||
\item Retro-styled graphics
|
||||
\item Solve puzzles as you progress
|
||||
\item 3.1415 different difficulty modes
|
||||
\item 6.022 $\cdot$ 10\textsuperscript{23} unique enemies
|
||||
\item meow
|
||||
\end{itemize}
|
||||
|
||||
\section{Similar competitive products}
|
||||
|
||||
\begin{itemize}
|
||||
\item Super Mario game series
|
||||
\item Celeste
|
||||
\end{itemize}
|
||||
|
||||
\end{document}
|
BIN
gdd/beat_chart.pdf
Normal file
482
gdd/beat_chart.tex
Normal file
|
@ -0,0 +1,482 @@
|
|||
\documentclass[12pt,a4paper,landscape]{scrartcl}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[english]{babel}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{csquotes}
|
||||
\usepackage[left=2.00cm,right=2.00cm,
|
||||
top=2.00cm,bottom=2.00cm]{geometry}
|
||||
\author{Amedeo Molnár}
|
||||
\title{Pituicat -- Beat Chart}
|
||||
\date{\today}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\pagenumbering{gobble}
|
||||
\maketitle
|
||||
|
||||
\newpage
|
||||
\tableofcontents
|
||||
\newpage
|
||||
\pagenumbering{arabic}
|
||||
\setcounter{page}{1}
|
||||
|
||||
\section{The Sewer}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: The Sewer 1} &
|
||||
\textbf{Level: The Sewer 2} &
|
||||
\textbf{Level: The Sewer 3} &
|
||||
\textbf{Level: The Sewer 4} \\
|
||||
\textbf{Name: The Sewer -- This is (not) the end} &
|
||||
\textbf{Name: The Sewer -- Fish and Chips} &
|
||||
\textbf{Name: The Sewer -- Ratty business} &
|
||||
\textbf{Name: The Sewer -- Facing the King} \\
|
||||
\textbf{Story:} Pituicat awakens in a dark corner
|
||||
of the sewers. &
|
||||
\textbf{Story:} Pituicat crosses the sewer, encounters
|
||||
first rat scouts. &
|
||||
\textbf{Story:} Pituicat has to fights his way through
|
||||
the sewer. &
|
||||
\textbf{Story:} King Rat is furious about Pituicat
|
||||
entering his domain and fights. \\
|
||||
\textbf{Progression:} Player taught basic movement,
|
||||
combat and collecting powerups &
|
||||
\textbf{Progression:} Player crosses first level and
|
||||
collects first powerups and solves first puzzles &
|
||||
\textbf{Progression:} Player solves more complex
|
||||
puzzles
|
||||
and encounters lots of rats &
|
||||
\textbf{Progression:} Player fights
|
||||
\enquote{King Rat} \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} brownish tones (eww!), red
|
||||
(bricks, pipes), yellow (lights), blue (pipes) &
|
||||
\textbf{Color map:} brownish tones (eww!), red
|
||||
(bricks, pipes), yellow (lights), blue (pipes),
|
||||
yellowish blue (water?) &
|
||||
\textbf{Color map:} brownish tones (eww!), red
|
||||
(bricks, pipes), yellow (lights), blue (pipes),
|
||||
yellowish blue (water?) &
|
||||
\textbf{Color map:} brownish tones (eww!, Wood), red
|
||||
(bricks, pipes), yellow (lights), blue (pipes),
|
||||
yellowish blue (water?) \\
|
||||
\textbf{Enemies}: Woodlice, Goldfish &
|
||||
\textbf{Enemies}: Woodlice, Goldfish, Rat scout &
|
||||
\textbf{Enemies}: Woodlice, Goldfish, Rat scout, Rat,
|
||||
Big Rat &
|
||||
\textbf{Enemies}: \enquote{King Rat} \\
|
||||
\textbf{Mechanics:} Wall jump &
|
||||
\textbf{Mechanics:} Wall jump &
|
||||
\textbf{Mechanics:} Wall jump &
|
||||
\textbf{Mechanics:} Wall jump \\
|
||||
\textbf{Hazards:} Cracky platform, Sewage &
|
||||
\textbf{Hazards:} Cracky platform, Sewage, Sewage Drops &
|
||||
\textbf{Hazards:} Cracky platform, Sewage, Sewage Drops,
|
||||
Slippery ground &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment \\
|
||||
\textbf{Puzzles:} Light switch &
|
||||
\textbf{Puzzles:} Timed pump activation run &
|
||||
\textbf{Puzzles:} Slime ground maze &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
|
||||
\newpage
|
||||
|
||||
\section{Back Alley}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: Back Alley 1} &
|
||||
\textbf{Level: Back Alley 2} &
|
||||
\textbf{Level: Back Alley 3} &
|
||||
\textbf{Level: Back Alley 4} \\
|
||||
\textbf{Name: Back Alley -- Under pressure} &
|
||||
\textbf{Name: Back Alley -- Light of day} &
|
||||
\textbf{Name: Back Alley -- Up the Pipe} &
|
||||
\textbf{Name: Back Alley -- Shadow in the sky} \\
|
||||
\textbf{Story:} Pituicat first reaches the world above
|
||||
ground since transformation and is greeted by a
|
||||
garbage compressor. &
|
||||
\textbf{Story:} After getting out of the garbage
|
||||
Compressor the back alley is open for exploration. &
|
||||
\textbf{Story:} To get out of the alley to the lab
|
||||
Pituicat has to get higher up. &
|
||||
\textbf{Story:} The roof is reached, but guarded by a
|
||||
raven. \\
|
||||
\textbf{Progression:} Player reaches new stage and is
|
||||
introduced to new Powerup &
|
||||
\textbf{Progression:} Player has to traverse a mostly
|
||||
vertical level to get above the garbage containers &
|
||||
\textbf{Progression:} Player climbs through garbage
|
||||
chutes and over fire excape ladders to get to the roof
|
||||
&
|
||||
\textbf{Progression:} Player fights
|
||||
\enquote{The Raven} \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} red (bricks), blueish grey
|
||||
(steel), grey (asphalt, concrete) &
|
||||
\textbf{Color map:} red (bricks), blueish grey
|
||||
(steel), grey (asphalt, concrete) &
|
||||
\textbf{Color map:} red (bricks), blueish grey
|
||||
(steel), grey (asphalt, concrete),
|
||||
blue/black (glass panes) &
|
||||
\textbf{Color map:} grey (roof), white (air chutes),
|
||||
red (brick), blue (glass panes) \\
|
||||
\textbf{Enemies}: Rat, Spider, Big Spider &
|
||||
\textbf{Enemies}: Rat, Spider, Big Spider, Cleaner Bot
|
||||
&
|
||||
\textbf{Enemies}: Spider, Big Spider, Sparrow &
|
||||
\textbf{Enemies}: \enquote{The Raven} \\
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump \\
|
||||
\textbf{Hazards:} Glass shard pit, Battery acid,
|
||||
conveyor belt, cardboard platform (breaks) &
|
||||
\textbf{Hazards:} Glass shard pit, Battery acid,
|
||||
conveyor belt, cardboard platform (breaks),
|
||||
dripping bleh &
|
||||
\textbf{Hazards:} conveyor belt,
|
||||
cardboard platform (breaks),
|
||||
dripping bleh &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment \\
|
||||
\textbf{Puzzles:} Disable garbage compressor &
|
||||
\textbf{Puzzles:} Find and shutt off breakers for bad
|
||||
wiring &
|
||||
\textbf{Puzzles:} trick a flock of birds into going
|
||||
somewhere else &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
|
||||
\newpage
|
||||
|
||||
\section{Abandoned Lab}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: Abandoned Lab 1} &
|
||||
\textbf{Level: Abandoned Lab 2} &
|
||||
\textbf{Level: Abandoned Lab 3} &
|
||||
\textbf{Level: Abandoned Lab 4} \\
|
||||
\textbf{Name: Abandoned Lab -- Knock Knock} &
|
||||
\textbf{Name: Abandoned Lab -- Downwards} &
|
||||
\textbf{Name: Abandoned Lab -- Back home?} &
|
||||
\textbf{Name: Abandoned Lab -- The Experiment} \\
|
||||
\textbf{Story:} Pituicat enters its former home through a ventilation chute on the
|
||||
roof. &
|
||||
\textbf{Story:} Pituicat has to find a way through the ventilation system. &
|
||||
\textbf{Story:} Pituicat finds its old now mostly empty home and looks for his
|
||||
owner, but someone seems to have claimed the lab in the meantime. &
|
||||
\textbf{Story:} Pituicat fights the claimer of the lab. \\
|
||||
\textbf{Progression:} Player is introduced to new stage and new powerup &
|
||||
\textbf{Progression:} Player has to traverse a labyrinthine level &
|
||||
\textbf{Progression:} Player crosses tha lab and fights through hordes of
|
||||
enemies &
|
||||
\textbf{Progression:} Player faces and fights \enquote{CyberPsy} \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} greyish blue (steel), red (rust), brown (wood) &
|
||||
\textbf{Color map:} greyish blue (steel), red (rust), brown (wood) &
|
||||
\textbf{Color map:} grey-white (walls), brown (wood, furniture) &
|
||||
\textbf{Color map:} grey-white (walls), brown (wood, furniture) \\
|
||||
\textbf{Enemies}: Crazy Hamster, CyberSpider &
|
||||
\textbf{Enemies}: Crazy Hamster, CyberSpider, CyberHamster &
|
||||
\textbf{Enemies}: Crazy Hamster, CyberSpider, CyberHamster, PsyHamster &
|
||||
\textbf{Enemies}: \enquote{CyberPsy} \\
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump \\
|
||||
\textbf{Hazards:} Ventilator, UV-Sterilizer &
|
||||
\textbf{Hazards:} Ventilator, UV-Sterilizer, Laser Trap &
|
||||
\textbf{Hazards:} Robotic Limbs, Acid Puddle, Laser Trap, Explosive Bottles &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment \\
|
||||
\textbf{Puzzles:} Cross UV-Sterilizer &
|
||||
\textbf{Puzzles:} Get to the bottom of the main shaft &
|
||||
\textbf{Puzzles:} Deactivate shields guarding the new master of the lab &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
|
||||
\newpage
|
||||
|
||||
\section{The Highway}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: The Highway 1} &
|
||||
\textbf{Level: The Highway 2} &
|
||||
\textbf{Level: The Highway 3} &
|
||||
\textbf{Level: The Highway 4} \\
|
||||
\textbf{Name: The Highway -- On the Road} &
|
||||
\textbf{Name: The Highway -- Searing Sun} &
|
||||
\textbf{Name: The Highway -- Snake Country} &
|
||||
\textbf{Name: The Highway -- Serpent Dream} \\
|
||||
\textbf{Story:} After defeating \enquote{CyberPsy} Pituicat makes his way to the
|
||||
Highway. &
|
||||
\textbf{Story:} Pituicat is on the Road to the Military-Industrial Complex. &
|
||||
\textbf{Story:} Pituicat follows the Highway and enters Rattlesnake infested
|
||||
areas. &
|
||||
\textbf{Story:} Pituicat faces \enquote{Mother Snake}. \\
|
||||
\textbf{Progression:} Player is introduced to new stage and powerup &
|
||||
\textbf{Progression:} Player crosses a rather long level with scarce resources &
|
||||
\textbf{Progression:} Player enters a rattlesnake infested area of the Highway &
|
||||
\textbf{Progression:} Player faces \enquote{Mother Snake}, the Boss of this
|
||||
Area \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} grey (concrete), black (asphalt), yellowish brown (sand),
|
||||
light blue (sky) &
|
||||
\textbf{Color map:} grey (concrete), black (asphalt), yellowish brown (sand),
|
||||
light blue (sky), brown (dirt) &
|
||||
\textbf{Color map:} grey (concrete), black (asphalt), yellowish brown (sand),
|
||||
light blue (sky), brown (dirt) &
|
||||
\textbf{Color map:} yellowish brown (sand), brown (dirt) \\
|
||||
\textbf{Enemies}: Small Yellow Lizard, Small green Lizard &
|
||||
\textbf{Enemies}: Small Lizards (green and yellow),
|
||||
Big Lizard (yellow and green), Tarantulas &
|
||||
\textbf{Enemies}: Big Lizard (yellow and green), Snakeling, Rattlesnake &
|
||||
\textbf{Enemies}: \enquote{Mother Snake}, Snakeling, Rattlesnake \\
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump \\
|
||||
\textbf{Hazards:} Hot Asphalt &
|
||||
\textbf{Hazards:} Hot Asphalt, Poison bait &
|
||||
\textbf{Hazards:} Hot Asphalt, Poison bait, Snake nest &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment \\
|
||||
\textbf{Puzzles:} Avoid Lizard Traps &
|
||||
\textbf{Puzzles:} Avoid long stretches of hot asphalt &
|
||||
\textbf{Puzzles:} Avoid long stretches of hot asphalt and snake nests &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
|
||||
\newpage
|
||||
|
||||
\section{Military-Industrial Complex}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: Military-Industrial Complex 1} &
|
||||
\textbf{Level: Military-Industrial Complex 2} &
|
||||
\textbf{Level: Military-Industrial Complex 3} &
|
||||
\textbf{Level: Military-Industrial Complex 4} \\
|
||||
\textbf{Name: Military-Industrial Complex -- Outer Ring} &
|
||||
\textbf{Name: Military-Industrial Complex -- Death Zone} &
|
||||
\textbf{Name: Military-Industrial Complex -- At the Gates} &
|
||||
\textbf{Name: Military-Industrial Complex -- Nice Kitty?} \\
|
||||
\textbf{Story:} Pituicat reaches the Military-Industrial Complex and needs to
|
||||
find a way to get past the first security ring. &
|
||||
\textbf{Story:} Pituicat has to cross the death zone between the outer ring and
|
||||
the entrance to the Base. &
|
||||
\textbf{Story:} Pituicat enters the Military-Industrial Complex and works his way
|
||||
to the base. &
|
||||
\textbf{Story:} Pituicat faces \enquote{M30w} guarding the base. \\
|
||||
\textbf{Progression:} Introduction to new stage and powerup &
|
||||
\textbf{Progression:} Crossing of a vast, open and dangerous terrain &
|
||||
\textbf{Progression:} Crossing a branched Level with lots of obstacles &
|
||||
\textbf{Progression:} Fight the stage boss \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} black (asphalt), dark green (grasy groud), purple (sky),
|
||||
dark gray (concrete, steel) &
|
||||
\textbf{Color map:} black (asphalt), dark green (grasy groud), purple (sky),
|
||||
dark gray (concrete, steel) &
|
||||
\textbf{Color map:} black (asphalt), purple (sky), dark gray (concrete, steel) &
|
||||
\textbf{Color map:} black (asphalt), purple (sky), dark gray (concrete, steel) \\
|
||||
\textbf{Enemies}: Guard Dog, TaserTurret, CyberEagle, Doubleheaded Cobra &
|
||||
\textbf{Enemies}: Guard Dog, CyberDog, LaserTurret, CyberEagle,
|
||||
Doubleheaded Cobra, ManHack &
|
||||
\textbf{Enemies}: Guard Dog, CyberDog, LaserTurret, CyberEagle,
|
||||
Doubleheaded Cobra, ManHack, Armed Skimmer &
|
||||
\textbf{Enemies}: \enquote{M30w} \\
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump \\
|
||||
\textbf{Hazards:} Electric Fence, Ground Spikes &
|
||||
\textbf{Hazards:} Electric Fence, Electrified Ground Spikes, Mines &
|
||||
\textbf{Hazards:} Electric Fence, Electrified Ground Spikes, Mines,
|
||||
Conveyor Belt, Industrial Press &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment \\
|
||||
\textbf{Puzzles:} Get over electric Fence, Turret Area, Deactivate Ground Spikes &
|
||||
\textbf{Puzzles:} Deactivate electrified Ground spikes &
|
||||
\textbf{Puzzles:} Deactivate the industrial machines to reach the base entrance &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
|
||||
\newpage
|
||||
|
||||
\section{Secret Base}
|
||||
|
||||
\begin{tabular}{
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
p{.23\linewidth}|
|
||||
}
|
||||
\textbf{Level: Secret Base 1} &
|
||||
\textbf{Level: Secret Base 2} &
|
||||
\textbf{Level: Secret Base 3} &
|
||||
\textbf{Level: Secret Base 4} \\
|
||||
\textbf{Name: Secret Base -- Into Darkness} &
|
||||
\textbf{Name: Secret Base -- Elevator music} &
|
||||
\textbf{Name: Secret Base -- Where the Strange Things are} &
|
||||
\textbf{Name: Secret Base -- Friend or Foe?} \\
|
||||
\textbf{Story:} Pituicat enters the secret base, where his owner is kept. &
|
||||
\textbf{Story:} Pituicat is inside the base and has to reach the bottom most
|
||||
level. &
|
||||
\textbf{Story:} Pituicat reaches the bottom most level of the base and proceeds
|
||||
to The Core. &
|
||||
\textbf{Story:} Pituicat faces \enquote{Node Kroenen}, his former owner. \\
|
||||
\textbf{Progression:} Introduction to new stage and powerup &
|
||||
\textbf{Progression:} traverse an inveresely vertical level &
|
||||
\textbf{Progression:} Traverse a branched, non-linear level full of enemies &
|
||||
\textbf{Progression:} The Final boss of the game \\
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 15 min. &
|
||||
\textbf{Est. play time:} 5 min. \\
|
||||
\textbf{Color map:} black (ground, ceiling), blue-grey (steel),
|
||||
dark grey (concrete), blue-gray (wall paint) &
|
||||
\textbf{Color map:} black (ground, ceiling), blue-grey (steel),
|
||||
dark grey (concrete), green-gray (wall paint) &
|
||||
\textbf{Color map:} black (ground, ceiling), blue-grey (steel),
|
||||
dark grey (concrete), yellow-gray (wall paint) &
|
||||
\textbf{Color map:} black (ground, ceiling), blue-grey (steel),
|
||||
dark grey (concrete), red-gray (wall paint) \\
|
||||
\textbf{Enemies}: Armed Guard, RoboGuard, Operative &
|
||||
\textbf{Enemies}: Armed Guard, RoboGuard, RoboSamurai, Operative &
|
||||
\textbf{Enemies}: RoboSamurai, Operative, BrainSpider, ExploFly &
|
||||
\textbf{Enemies}: \enquote{Node Kroenen} \\
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump &
|
||||
\textbf{Mechanics:} Wall Jump \\
|
||||
\textbf{Hazards:} Turret, Plasma Burners, Laser Barrier,
|
||||
Charged MicroFilament Fence &
|
||||
\textbf{Hazards:} Elevator, Electric Trap, Laser Barrier, Charged Microfilament Fence &
|
||||
\textbf{Hazards:} PulsarTurret, LaserBarrier, PlasmaFilament Cutter, Enzyme Pit &
|
||||
\textbf{Hazards:} None \\
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine, Agent X &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine, Agent X &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine, Agent X &
|
||||
\textbf{Power-ups:} Peptide, Oily Emulsion, Latex, Organic lead, Antidote,
|
||||
Purified Caffeine, Agent X \\
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} DNA-Fragment &
|
||||
\textbf{Economy:} None &
|
||||
\textbf{Economy:} None \\
|
||||
\textbf{Puzzles:} Work your way into the base &
|
||||
\textbf{Puzzles:} Use elevators to pass barriers inside elevator shafts &
|
||||
\textbf{Puzzles:} Deactivate various defence mechanisms &
|
||||
\textbf{Puzzles:} None \\
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD &
|
||||
\textbf{Music track:} TBD \\
|
||||
\end{tabular}
|
||||
\end{document}
|
81
pituicat.cabal
Normal file
|
@ -0,0 +1,81 @@
|
|||
cabal-version: 2.4
|
||||
-- Initial package description 'pituicat.cabal' generated by 'cabal init'.
|
||||
-- For further documentation, see http://haskell.org/cabal/users-guide/
|
||||
|
||||
name: pituicat
|
||||
version: 0.0.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
-- bug-reports:
|
||||
license: GPL-3.0-only
|
||||
license-file: LICENSE
|
||||
author: nek0
|
||||
maintainer: nek0@nek0.eu
|
||||
-- copyright:
|
||||
category: Game
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable pituicat
|
||||
main-is: Main.hs
|
||||
other-modules: Types
|
||||
, Types.Application
|
||||
, Types.Subsystems
|
||||
, Types.Map
|
||||
, Types.Cast
|
||||
, Types.StageSet
|
||||
, Types.Tangible
|
||||
, Types.Util
|
||||
, Types.Player
|
||||
, Types.PowerUp
|
||||
, Classes
|
||||
, Classes.Scene
|
||||
, Classes.Actor
|
||||
, Classes.Prop
|
||||
, Classes.Collectable
|
||||
, Graphics
|
||||
, Graphics.Types
|
||||
, Graphics.Types.VertexArray
|
||||
, Graphics.Types.VertexBuffer
|
||||
, Graphics.Types.IndexBuffer
|
||||
, Graphics.Types.Shader
|
||||
, Graphics.Types.Texture
|
||||
, Graphics.Classes
|
||||
, Graphics.Classes.Bindable
|
||||
, Graphics.Classes.Buffer
|
||||
, Graphics.Classes.VertexLayout
|
||||
, Graphics.Classes.Drawable
|
||||
, Physics
|
||||
, Physics.Classes
|
||||
, Physics.Classes.Mass
|
||||
, Physics.Classes.Collidible
|
||||
, Scenes.Test
|
||||
, Scenes.Test.Types
|
||||
, Scenes.Test.Util
|
||||
, Scenes.Test.Load
|
||||
, Scenes.Test.Update
|
||||
, Scenes.Test.EventHandler
|
||||
, Map
|
||||
, StateMachine
|
||||
, Renderer
|
||||
, Util
|
||||
-- other-extensions:
|
||||
build-depends: base >=4.13.0.0
|
||||
, affection
|
||||
, stm
|
||||
, OpenGL
|
||||
, OpenGLRaw
|
||||
, sdl2
|
||||
, containers
|
||||
, linear
|
||||
, text
|
||||
, aeson
|
||||
, vector
|
||||
, JuicyPixels
|
||||
, JuicyPixels-extra
|
||||
, bytestring
|
||||
, derive-storable
|
||||
, monad-loops
|
||||
, StateVar
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall -threaded
|
BIN
res-old/audio/meow-1.wav
Normal file
BIN
res-old/audio/meow-3.wav
Normal file
BIN
res-old/audio/meow-4.wav
Normal file
BIN
res-old/audio/meow-8.wav
Normal file
BIN
res-old/audio/meow.wav
Normal file
BIN
res-old/audio/purr.wav
Normal file
BIN
res-old/img/pituicat.kra
Normal file
BIN
res-old/img/pituicat.png
Normal file
After Width: | Height: | Size: 984 B |
BIN
res-old/img/pituicat_slither_1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
res-old/img/pituicat_slither_2.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
res/maps/00_test/00_test.bmp
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
res/maps/00_test/00_test.kra
Normal file
BIN
res/pituicat/pituicat.kra
Normal file
BIN
res/pituicat/pituicat.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
18
res/shaders/frag.shader
Normal file
|
@ -0,0 +1,18 @@
|
|||
#version 400 core
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
in vec4 v_color;
|
||||
in vec2 v_texCoord;
|
||||
in float v_texIndex;
|
||||
|
||||
uniform sampler2D[2] u_textures;
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec4 texColor = texture(u_texture, v_texCoord);
|
||||
int index = int(v_texIndex);
|
||||
//color = texture(u_textures[index], v_texCoord);
|
||||
color = texture(u_textures[index], v_texCoord) * v_color;
|
||||
//color = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
}
|
20
res/shaders/vert.shader
Normal file
|
@ -0,0 +1,20 @@
|
|||
#version 400 core
|
||||
|
||||
layout(location = 0) in vec3 a_position;
|
||||
layout(location = 1) in vec4 a_color;
|
||||
layout(location = 2) in vec2 a_texCoord;
|
||||
layout(location = 3) in float a_texIndex;
|
||||
|
||||
out vec4 v_color;
|
||||
out vec2 v_texCoord;
|
||||
out float v_texIndex;
|
||||
|
||||
uniform mat4 u_mvp;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_mvp * vec4(a_position, 1);
|
||||
v_texCoord = a_texCoord;
|
||||
v_color = a_color;
|
||||
v_texIndex = a_texIndex;
|
||||
}
|
BIN
res/tiles/00_test/00_test.kra
Normal file
BIN
res/tiles/00_test/00_test.png
Normal file
After Width: | Height: | Size: 6 KiB |
13
shell.nix
|
@ -1,7 +1,16 @@
|
|||
{ pkgs ? import <nixpkgs> {}}:
|
||||
|
||||
let
|
||||
affection = pkgs.haskellPackages.callCabal2nix "affection" (gitignore ./.) {};
|
||||
# create a modified haskell package set with my package inside it and broken dependencies
|
||||
# jailbroken.
|
||||
hpkgs = pkgs.haskellPackages.override {
|
||||
overrides = hself: hsuper: {
|
||||
pituicat = hself.callCabal2nix "mateamt" (gitignore ./.) {};
|
||||
affection = hself.callCabal2nix "affection" (gitignore ./extern/affection) {};
|
||||
#pg-transact = with pkgs.haskell.lib;
|
||||
# doJailbreak (unmarkBroken (dontCheck hsuper.pg-transact));
|
||||
};
|
||||
};
|
||||
gitignore = dir: pkgs.nix-gitignore.gitignoreSource [] dir;
|
||||
in
|
||||
affection.env
|
||||
hpkgs.pituicat.env
|
||||
|
|
151
src/Affection.hs
|
@ -1,151 +0,0 @@
|
|||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE Strict #-}
|
||||
{-# LANGUAGE ExplicitForAll #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE RankNTypes #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
module Affection
|
||||
( withAffection
|
||||
, get
|
||||
, put
|
||||
, liftIO
|
||||
, module A
|
||||
) where
|
||||
|
||||
import SDL (($=))
|
||||
import qualified SDL
|
||||
import qualified SDL.Raw.Video as SDL (glSetAttribute)
|
||||
import qualified SDL.Raw.Enum as SDL
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL (clear, flush, ClearBuffer(..))
|
||||
import qualified Graphics.GL as GLRaw
|
||||
|
||||
import Foreign.Marshal.Array
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.ByteString.Char8 as B8
|
||||
|
||||
import System.Clock
|
||||
|
||||
import Control.Monad.Loops
|
||||
import Control.Monad.State.Strict
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Affection.Types as A
|
||||
import Affection.Class as A
|
||||
import Affection.StateMachine as A
|
||||
import Affection.Util as A
|
||||
import Affection.MessageBus as A
|
||||
import Affection.Subsystems as A
|
||||
|
||||
import Affection.Logging as A
|
||||
|
||||
-- | Main function which bootstraps everything else.
|
||||
withAffection
|
||||
:: forall us. (Affectionate us)
|
||||
=> AffectionConfig us -- ^ Configuration of the Game and its engine.
|
||||
-> IO ()
|
||||
withAffection AffectionConfig{..} = do
|
||||
liftIO $ logIO Debug "Affection starting"
|
||||
liftIO $ logIO Debug "Initializing SDL"
|
||||
-- intialiaze SDL
|
||||
case initComponents of
|
||||
All ->
|
||||
SDL.initializeAll
|
||||
Only is ->
|
||||
SDL.initialize is
|
||||
-- give SDL render quality
|
||||
SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear
|
||||
-- just checking…
|
||||
do
|
||||
renderQuality <- SDL.get SDL.HintRenderScaleQuality
|
||||
when (renderQuality /= SDL.ScaleLinear) $
|
||||
logIO Warn "Linear texture filtering not enabled!"
|
||||
-- construct window
|
||||
liftIO $ logIO Debug "Creating Window(s)"
|
||||
windows <- zip3 (map (\(x,_,_) -> x) windowConfigs) <$>
|
||||
mapM
|
||||
(\wc -> SDL.createWindow windowTitle ((\(_,y,_) -> y) wc))
|
||||
windowConfigs <*>
|
||||
pure (map (\(_,_,z) -> z) windowConfigs)
|
||||
|
||||
mapM_ (SDL.showWindow . (\(_,y,_) -> y)) windows
|
||||
_ <- SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1
|
||||
contexts <- zip (map (\(x,_,_) -> x) windows) <$>
|
||||
mapM (SDL.glCreateContext . (\(_,y,_) -> y)) windows
|
||||
mapM_ (\w -> flip SDL.setWindowMode ((\(_,_,z) -> z) w) ((\(_,y,_) -> y) w)) windows
|
||||
-- sync updates with monitor
|
||||
-- SDL.swapInterval $= SDL.SynchronizedUpdates -- <- causes Problems with windows
|
||||
liftIO $ logIO Debug "Getting Time"
|
||||
-- print current used GL Version
|
||||
version <- peekArray0 (0 :: Word8) =<< GLRaw.glGetString GLRaw.GL_VERSION
|
||||
print (B.pack version)
|
||||
-- get current time
|
||||
execTime <- getTime Monotonic
|
||||
liftIO $ logIO Debug "Loading initial data container"
|
||||
-- construct game data object from provided Affectionate instance
|
||||
gameData <- loadState @us
|
||||
-- build state container
|
||||
let initContainer = AffectionData
|
||||
{ drawWindows = windows
|
||||
, glContext = contexts
|
||||
, elapsedTime = 0
|
||||
, deltaTime = 0
|
||||
, sysTime = execTime
|
||||
, pausedTime = False
|
||||
}
|
||||
-- initialize and run state
|
||||
(_, _) <- runStateT
|
||||
(A.runState
|
||||
(do
|
||||
liftIO $ logIO Debug "Running Pre-Loop stage"
|
||||
-- run preLoop function from Affectionate
|
||||
preLoop gameData
|
||||
liftIO $ logIO Debug "Starting Loop"
|
||||
whileM_ (hasNextStep gameData)
|
||||
(do
|
||||
-- get state
|
||||
ad <- get
|
||||
-- Measure time difference form last run
|
||||
now <- liftIO $ getTime Monotonic
|
||||
let lastTime = sysTime ad
|
||||
-- compute dt and update elapsedTime
|
||||
let dt = fromIntegral
|
||||
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
||||
ne = elapsedTime ad + dt
|
||||
-- update state data object with new time values
|
||||
put $ ad
|
||||
{ elapsedTime = ne
|
||||
, deltaTime = dt
|
||||
}
|
||||
-- poll events
|
||||
liftIO SDL.pumpEvents
|
||||
evs <- preHandleEvents =<< liftIO SDL.pollEvents
|
||||
-- handle events
|
||||
handleEvents gameData evs
|
||||
-- execute user defined update loop
|
||||
unless (pausedTime ad) (update gameData dt)
|
||||
-- clear GL buffer >> execute user defined draw loop >> flush GL buffer
|
||||
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||
draw gameData
|
||||
liftIO GL.flush
|
||||
-- actual displaying of newly drawn frame
|
||||
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
|
||||
-- save new time
|
||||
ad3 <- get
|
||||
when (sysTime ad == sysTime ad3) (
|
||||
put ad3
|
||||
{ sysTime = now
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
) initContainer
|
||||
liftIO $ logIO Debug "Loop ended. Cleaning"
|
||||
cleanUp gameData
|
||||
liftIO $ logIO Debug "Destroying Window"
|
||||
mapM_ (SDL.glDeleteContext . snd) contexts
|
||||
mapM_ (SDL.destroyWindow . (\(_,y,_) -> y)) windows
|
||||
-- SDL.quit -- <- This causes segfaults depending on hardware
|
||||
liftIO $ logIO Debug "This is the end"
|
|
@ -1,21 +0,0 @@
|
|||
module Affection.Class where
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Affection.Types as A
|
||||
|
||||
class Affectionate a where
|
||||
|
||||
loadState :: IO a
|
||||
|
||||
preLoop :: a -> Affection ()
|
||||
|
||||
handleEvents :: a -> [SDL.EventPayload] -> Affection ()
|
||||
|
||||
update :: a -> Double -> Affection ()
|
||||
|
||||
draw :: a -> Affection ()
|
||||
|
||||
cleanUp :: a -> IO ()
|
||||
|
||||
hasNextStep :: a -> Affection Bool
|
|
@ -1,54 +0,0 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
-- | This module defines the logging capability of Affection, whis is derived
|
||||
-- from "Debug.Trace".
|
||||
module Affection.Logging where
|
||||
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Debug.Trace
|
||||
|
||||
-- | The log level definition
|
||||
data LogLevel
|
||||
= Verbose -- ^ Log everything
|
||||
| Debug -- ^ Log Debug messages and above
|
||||
| Warn -- ^ Log only Warnings and errors
|
||||
| Error -- ^ Log only errors
|
||||
|
||||
-- | Pure logging function
|
||||
log
|
||||
:: LogLevel -- ^ Log level to log to
|
||||
-> T.Text -- ^ The message string
|
||||
-> a -- ^ Arbitrary datatype to return
|
||||
-> a -- ^ Returned data
|
||||
#if defined(VERBOSE)
|
||||
log Verbose s = trace ("VERBOSE: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(DEBUG) || defined(VERBOSE)
|
||||
log Debug s = trace ("DEBUG: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
|
||||
log Warn s = trace ("WARN: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
|
||||
log Error s = trace ("ERROR: " ++ T.unpack s)
|
||||
#endif
|
||||
log _ _ = id
|
||||
|
||||
-- | Manadic logging function residing in the 'IO' Monad
|
||||
logIO
|
||||
:: LogLevel -- ^ Log level to log to
|
||||
-> T.Text -- ^ The message string
|
||||
-> IO ()
|
||||
#if defined(VERBOSE)
|
||||
logIO Verbose s = traceIO ("VERBOSE: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(DEBUG) || defined(VERBOSE)
|
||||
logIO Debug s = traceIO ("DEBUG: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(WARN) || defined(DEBUG) || defined(VERBOSE)
|
||||
logIO Warn s = traceIO ("WARN: " ++ T.unpack s)
|
||||
#endif
|
||||
#if defined(ERROR) || defined(WARN) || defined(DEBUG) || defined(VERBOSE)
|
||||
logIO Error s = traceIO ("ERROR: " ++ T.unpack s)
|
||||
#endif
|
||||
logIO _ _ = return ()
|
|
@ -1,6 +0,0 @@
|
|||
module Affection.MessageBus
|
||||
( module M
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Class as M
|
||||
import Affection.MessageBus.Message as M
|
|
@ -1,68 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE ExistentialQuantification #-}
|
||||
module Affection.MessageBus.Class
|
||||
( Participant(..)
|
||||
, genUUID
|
||||
, UUID
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message
|
||||
import Affection.Types
|
||||
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
|
||||
import Data.UUID
|
||||
import Data.UUID.V4
|
||||
|
||||
import Data.String as S (fromString)
|
||||
|
||||
import Affection.Logging
|
||||
|
||||
-- | This typeclass defines the behaviour of a participant in the message system
|
||||
class (Message (Mesg prt), Show (Mesg prt)) => Participant prt where
|
||||
-- | Message datatype
|
||||
type Mesg prt :: *
|
||||
|
||||
-- | Function to get the list of subscribers from the participant
|
||||
partSubscribers
|
||||
:: prt
|
||||
-- ^ the 'Participant''s subscriber storage
|
||||
-> Affection [Mesg prt -> Affection ()]
|
||||
-- ^ List of Subscriber functions
|
||||
|
||||
-- | Subscribe to the 'Participant''s events
|
||||
partSubscribe
|
||||
:: prt
|
||||
-- ^ The 'Participant''s subscriber storage
|
||||
-> (Mesg prt -> Affection ())
|
||||
-- ^ What to do in case of a 'Message'
|
||||
-- (Subscriber function)
|
||||
-> Affection UUID
|
||||
-- ^ 'UUID' of the registered subscriber Function
|
||||
|
||||
-- | Unsubscribe a Subscriber function from Participant
|
||||
partUnSubscribe
|
||||
:: prt
|
||||
-- ^ The 'Participant''s subscriber storage to unsubscribe from
|
||||
-> UUID
|
||||
-- ^ The subscriber function's 'UUID'
|
||||
-> Affection ()
|
||||
|
||||
-- | Get the 'Participant' to emit a 'Message' on all of its subscribers
|
||||
partEmit
|
||||
:: prt
|
||||
-- ^ The 'Participant''s subscriber storage
|
||||
-> Mesg prt
|
||||
-- ^ The 'Message' to emit
|
||||
-> Affection ()
|
||||
partEmit p m = do
|
||||
liftIO $ logIO Verbose $ "Emitting message: " <> S.fromString (show m)
|
||||
l <- partSubscribers p
|
||||
mapM_ ($ m) l
|
||||
|
||||
-- | Helper function to generate new 'UUID's
|
||||
genUUID :: Affection UUID
|
||||
genUUID = liftIO nextRandom
|
|
@ -1,9 +0,0 @@
|
|||
module Affection.MessageBus.Message
|
||||
( module M
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message.Class as M
|
||||
import Affection.MessageBus.Message.WindowMessage as M
|
||||
import Affection.MessageBus.Message.KeyboardMessage as M
|
||||
import Affection.MessageBus.Message.MouseMessage as M
|
||||
import Affection.MessageBus.Message.JoystickMessage as M
|
|
@ -1,6 +0,0 @@
|
|||
module Affection.MessageBus.Message.Class where
|
||||
|
||||
-- | Typeclass definition for messages
|
||||
class Message msg where
|
||||
-- | return the time when the message was sent
|
||||
msgTime :: msg -> Double
|
|
@ -1,67 +0,0 @@
|
|||
module Affection.MessageBus.Message.JoystickMessage
|
||||
( JoystickMessage(..)
|
||||
-- | Vector export
|
||||
, Linear.V2
|
||||
-- | SDL exports
|
||||
, SDL.JoyHatPosition
|
||||
, SDL.JoyButtonState
|
||||
, SDL.JoyDeviceConnection
|
||||
-- | Number exports
|
||||
, Word8
|
||||
, Int16
|
||||
, Int32
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message.Class
|
||||
|
||||
import Data.Word (Word8)
|
||||
import Data.Int (Int32, Int16)
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Linear (V2(..))
|
||||
|
||||
-- | Datatype for handling all possible joystick events handed over from sdl2
|
||||
data JoystickMessage
|
||||
-- | Movement of a Joystick axis
|
||||
= MsgJoystickAxis
|
||||
{ msgJAWhen :: Double -- ^ Time of event
|
||||
, msgJAWhich :: Int32 -- ^ Joystick identifier
|
||||
, msgJAAxis :: Word8 -- ^ Axis identifier
|
||||
, msgJAValue :: Int16 -- ^ Axis value
|
||||
}
|
||||
-- | Movement of a joystick ball controller
|
||||
| MsgJoystickBall
|
||||
{ msgJBWhen :: Double -- ^ Time of event
|
||||
, msgJBWhich :: Int32 -- ^ Joystick identifier
|
||||
, msgJBBall :: Word8 -- ^ Ball identifier
|
||||
, msgJBRelMotion :: V2 Int16 -- ^ Motion relative to previous position
|
||||
}
|
||||
-- | Movement of joystick hat controller
|
||||
| MsgJoystickHat
|
||||
{ msgJHWhen :: Double -- ^ Time of event
|
||||
, msgJHWhich :: Int32 -- ^ Joystick identifier
|
||||
, msgJHHat :: Word8 -- ^ Hat identifier
|
||||
, msgJHPosition :: SDL.JoyHatPosition -- ^ New hat position
|
||||
}
|
||||
-- | Joystick button event
|
||||
| MsgJoystickButton
|
||||
{ msgJBWhen :: Double -- ^ Time of event
|
||||
, msgJBWhich :: Int32 -- ^ Joystick identifier
|
||||
, msgJBButton :: Word8 -- ^ Button identifier
|
||||
, msgJBState :: SDL.JoyButtonState -- ^ New Button state
|
||||
}
|
||||
-- | Joystick device event
|
||||
| MsgJoystickDevice
|
||||
{ msgJDWhen :: Double -- ^ Time of event
|
||||
, msgJDWhich :: Int32 -- ^ Joystick identifier
|
||||
, msgJDConnection :: SDL.JoyDeviceConnection -- ^ Connection status
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
instance Message JoystickMessage where
|
||||
msgTime (MsgJoystickAxis t _ _ _) = t
|
||||
msgTime (MsgJoystickBall t _ _ _) = t
|
||||
msgTime (MsgJoystickHat t _ _ _) = t
|
||||
msgTime (MsgJoystickButton t _ _ _) = t
|
||||
msgTime (MsgJoystickDevice t _ _) = t
|
|
@ -1,26 +0,0 @@
|
|||
module Affection.MessageBus.Message.KeyboardMessage
|
||||
( KeyboardMessage(..)
|
||||
-- | SDL reexports
|
||||
, SDL.Window
|
||||
, SDL.InputMotion
|
||||
, SDL.Keysym
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message.Class
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Dataatype for handling all keyboard events haded down from SDL2
|
||||
data KeyboardMessage
|
||||
-- | Arbitrary Keyboard event
|
||||
= MsgKeyboardEvent
|
||||
{ msgKbdWhen :: Double -- ^ Message time
|
||||
, msgKbdWindow :: Maybe SDL.Window -- ^ Affected Window
|
||||
, msgKbdKeyMotion :: SDL.InputMotion -- ^ Input motion of button (pressed/released)
|
||||
, msgKbdKeyRepeat :: Bool -- ^ Is this a repeated event?
|
||||
, msgKbdKeysym :: SDL.Keysym -- ^ The button's 'SDL.Keysym'
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
instance Message KeyboardMessage where
|
||||
msgTime (MsgKeyboardEvent t _ _ _ _) = t
|
|
@ -1,54 +0,0 @@
|
|||
module Affection.MessageBus.Message.MouseMessage
|
||||
( MouseMessage(..)
|
||||
-- | SDL reexports
|
||||
, SDL.Window
|
||||
, SDL.MouseDevice
|
||||
, SDL.MouseButton
|
||||
, SDL.InputMotion
|
||||
, SDL.MouseScrollDirection
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message.Class
|
||||
|
||||
import Data.Word (Word8)
|
||||
import Data.Int (Int32)
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Linear (V2(..))
|
||||
|
||||
-- Datatype for handling mouse events handed down from SDL2
|
||||
data MouseMessage
|
||||
-- | Mouse motion event
|
||||
= MsgMouseMotion
|
||||
{ msgMMWhen :: Double -- ^ Message time
|
||||
, msgMMWindow :: Maybe SDL.Window -- ^ Focused window (if any)
|
||||
, msgMMWhich :: SDL.MouseDevice -- ^ Mouse device identifier
|
||||
, msgMMState :: [SDL.MouseButton] -- ^ List of pressed mouse buttons
|
||||
, msgMMPos :: V2 Int32 -- ^ Absolute mouse positiom
|
||||
, msgMMRelMotion :: V2 Int32 -- ^ Mouse movement relative to previous position
|
||||
}
|
||||
-- | Mouse button event
|
||||
| MsgMouseButton
|
||||
{ msgMBWhen :: Double -- ^ Message time
|
||||
, msgMBWindow :: Maybe SDL.Window -- ^ Focused window (if any)
|
||||
, msgMBMotion :: SDL.InputMotion -- ^ Button's input motion
|
||||
, msgMBWhich :: SDL.MouseDevice -- ^ Mouse device identifier
|
||||
, msgMBButton :: SDL.MouseButton -- ^ Affected mouse button
|
||||
, msgMBClicks :: Word8 -- ^ Number of clicks
|
||||
, msgMBPos :: V2 Int32 -- ^ Absolute mouse position
|
||||
}
|
||||
-- | Mouse wheel event
|
||||
| MsgMouseWheel
|
||||
{ msgMWWhen :: Double -- ^ Message time
|
||||
, msgMWWhindow :: Maybe SDL.Window -- ^ Focused window (if any)
|
||||
, msgMWWhich :: SDL.MouseDevice -- ^ Mouse device identifier
|
||||
, msgMWPos :: V2 Int32 -- ^ Absolute mouse position
|
||||
, msgMWDIrection :: SDL.MouseScrollDirection -- ^ Scroll direction
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
instance Message MouseMessage where
|
||||
msgTime (MsgMouseMotion t _ _ _ _ _) = t
|
||||
msgTime (MsgMouseButton t _ _ _ _ _ _) = t
|
||||
msgTime (MsgMouseWheel t _ _ _ _) = t
|
|
@ -1,106 +0,0 @@
|
|||
module Affection.MessageBus.Message.WindowMessage
|
||||
( WindowMessage(..)
|
||||
-- | SDL reexports
|
||||
, SDL.Window
|
||||
) where
|
||||
|
||||
import Affection.MessageBus.Message.Class
|
||||
|
||||
import Data.Int (Int32)
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Linear (V2(..))
|
||||
|
||||
-- | Datatype for handling Window events handed down rom SDL2
|
||||
data WindowMessage
|
||||
-- | Window show event
|
||||
= MsgWindowShow
|
||||
{ msgWSWhen :: Double -- ^ Message time
|
||||
, msgWSWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window hide event
|
||||
| MsgWindowHide
|
||||
{ msgWHWhen :: Double -- ^ Message time
|
||||
, msgWHWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window expose event
|
||||
| MsgWindowExpose
|
||||
{ msgWEWhen :: Double -- ^ Message time
|
||||
, msgWEWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window move event
|
||||
| MsgWindowMove
|
||||
{ msgWMWhen :: Double -- ^ Message time
|
||||
, msgWMWindow :: SDL.Window -- ^ Window identifier
|
||||
, msgWMNewPos :: V2 Int32 -- ^ New absolute window position
|
||||
}
|
||||
-- | Window resize event
|
||||
| MsgWindowResize
|
||||
{ msgWRWhen :: Double -- ^ Message time
|
||||
, msgWRWindow :: SDL.Window -- ^ Window identifier
|
||||
, msgWRNewSize :: V2 Int32 -- ^ New absolute window size
|
||||
}
|
||||
-- | Window size change event
|
||||
| MsgWindowSizeChange
|
||||
{ msgWSCWhen :: Double -- ^ Message time
|
||||
, msgWSCWindow :: SDL.Window -- ^ Window identifier
|
||||
, msgWSCNewSize :: V2 Int32 -- ^ New absolute window size
|
||||
}
|
||||
-- | Window minimize event
|
||||
| MsgWindowMinimize
|
||||
{ msgWMinWhen :: Double -- ^ Message time
|
||||
, msgWMinWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window maximize event
|
||||
| MsgWindowMaximize
|
||||
{ msgWMaxWhen :: Double -- ^ Message time
|
||||
, msgWMaxWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window restore event
|
||||
| MsgWindowRestore
|
||||
{ msgWRestWhen :: Double -- ^ Message time
|
||||
, msgWRestWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window gain mouse focus event
|
||||
| MsgWindowGainMouseFocus
|
||||
{ msgWGMFWhen :: Double -- ^ Message Time
|
||||
, msgWGMFWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window lose mouse focus event
|
||||
| MsgWindowLoseMouseFocus
|
||||
{ msgWLMFWhen :: Double -- ^ Message Time
|
||||
, msgWLMFWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window gain keyboard focus event
|
||||
| MsgWindowGainKeyboardFocus
|
||||
{ msgWGKFWhen :: Double -- ^ Message time
|
||||
, msgWGKFWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window lose keyboard focus event
|
||||
| MsgWindowLoseKeyboardFocus
|
||||
{ msgWLKFWhen :: Double -- ^ Message time
|
||||
, msgWLKFWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
-- | Window close event
|
||||
| MsgWindowClose
|
||||
{ msgWCWhen :: Double -- ^ Message time
|
||||
, msgWCWindow :: SDL.Window -- ^ Window identifier
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
instance Message WindowMessage where
|
||||
msgTime (MsgWindowShow t _) = t
|
||||
msgTime (MsgWindowHide t _) = t
|
||||
msgTime (MsgWindowExpose t _) = t
|
||||
msgTime (MsgWindowMove t _ _) = t
|
||||
msgTime (MsgWindowResize t _ _) = t
|
||||
msgTime (MsgWindowSizeChange t _ _) = t
|
||||
msgTime (MsgWindowMinimize t _) = t
|
||||
msgTime (MsgWindowMaximize t _) = t
|
||||
msgTime (MsgWindowRestore t _) = t
|
||||
msgTime (MsgWindowGainMouseFocus t _) = t
|
||||
msgTime (MsgWindowLoseMouseFocus t _) = t
|
||||
msgTime (MsgWindowGainKeyboardFocus t _) = t
|
||||
msgTime (MsgWindowLoseKeyboardFocus t _) = t
|
||||
msgTime (MsgWindowClose t _) = t
|
|
@ -1,20 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
|
||||
module Affection.StateMachine where
|
||||
|
||||
import Affection.Types
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Typeclass for simple scaffolding of a state machine
|
||||
class StateMachine us a where
|
||||
-- | State load routine
|
||||
smLoad :: a -> us -> Affection ()
|
||||
-- | state update routine
|
||||
smUpdate :: a -> us -> Double -> Affection ()
|
||||
-- | State event handler routine
|
||||
smEvent :: a -> us -> [SDL.EventPayload] -> Affection ()
|
||||
-- | State draw routine
|
||||
smDraw :: a -> us -> Affection ()
|
||||
-- | State clean routine
|
||||
smClean :: a -> us -> Affection ()
|
|
@ -1,9 +0,0 @@
|
|||
module Affection.Subsystems
|
||||
( module S
|
||||
) where
|
||||
|
||||
import Affection.Subsystems.Class as S
|
||||
import Affection.Subsystems.AffectionKeyboard as S
|
||||
import Affection.Subsystems.AffectionWindow as S
|
||||
import Affection.Subsystems.AffectionMouse as S
|
||||
import Affection.Subsystems.AffectionJoystick as S
|
|
@ -1,119 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Affection.Subsystems.AffectionJoystick where
|
||||
|
||||
import Affection.MessageBus
|
||||
import Affection.Types
|
||||
import Affection.Util
|
||||
import Affection.Logging
|
||||
|
||||
import Control.Monad (filterM)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
|
||||
import qualified Data.Vector as V
|
||||
import Data.String as S (fromString)
|
||||
|
||||
import Foreign.C.Types (CInt(..))
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Helper function that consumes all Joystick-related 'SDL.EventPayload's
|
||||
-- and emits appropriate 'JoystickMessage's
|
||||
consumeSDLJoystickEvents
|
||||
:: forall am. (Participant am, Mesg am ~ JoystickMessage)
|
||||
=> am -- ^ The message system participant
|
||||
-> [SDL.EventPayload] -- ^ Incoming events
|
||||
-> Affection [SDL.EventPayload] -- ^ Leftover SDL events
|
||||
consumeSDLJoystickEvents am = doConsume
|
||||
where
|
||||
doConsume
|
||||
:: [SDL.EventPayload]
|
||||
-> Affection [SDL.EventPayload]
|
||||
doConsume [] = return []
|
||||
doConsume (e:es) = do
|
||||
ts <- getElapsedTime
|
||||
case e of
|
||||
SDL.JoyAxisEvent dat -> do
|
||||
partEmit am (MsgJoystickAxis
|
||||
ts
|
||||
(SDL.joyAxisEventWhich dat)
|
||||
(SDL.joyAxisEventAxis dat)
|
||||
(SDL.joyAxisEventValue dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.JoyBallEvent dat -> do
|
||||
partEmit am (MsgJoystickBall
|
||||
ts
|
||||
(SDL.joyBallEventWhich dat)
|
||||
(SDL.joyBallEventBall dat)
|
||||
(SDL.joyBallEventRelMotion dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.JoyHatEvent dat -> do
|
||||
partEmit am (MsgJoystickHat
|
||||
ts
|
||||
(SDL.joyHatEventWhich dat)
|
||||
(SDL.joyHatEventHat dat)
|
||||
(SDL.joyHatEventValue dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.JoyButtonEvent dat -> do
|
||||
partEmit am (MsgJoystickButton
|
||||
ts
|
||||
(SDL.joyButtonEventWhich dat)
|
||||
(SDL.joyButtonEventButton dat)
|
||||
(SDL.joyButtonEventState dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.JoyDeviceEvent dat -> do
|
||||
partEmit am (MsgJoystickDevice
|
||||
ts
|
||||
(SDL.joyDeviceEventWhich dat)
|
||||
(SDL.joyDeviceEventConnection dat)
|
||||
)
|
||||
doConsume es
|
||||
_ -> fmap (e :) (doConsume es)
|
||||
|
||||
-- | Helper function to automatically connect and open newly attached joystick
|
||||
-- devices
|
||||
joystickAutoConnect
|
||||
:: JoystickMessage -- ^ Any 'JoystickMessage' will do,
|
||||
-- but listens only on 'MsgJoystickDevice' messages
|
||||
-> Affection (Maybe SDL.Joystick)
|
||||
-- ^ Returns a joystick descriptor, if successful
|
||||
joystickAutoConnect (MsgJoystickDevice _ which SDL.JoyDeviceAdded) = liftIO $ do
|
||||
[descr] <- V.toList <$>
|
||||
(V.filter (\(SDL.JoystickDevice _ i) -> i == CInt which) <$>
|
||||
SDL.availableJoysticks)
|
||||
logIO Verbose $ "Connecting Joystick " <> fromString (show which) <> " " <>
|
||||
fromString (show descr)
|
||||
Just <$> SDL.openJoystick descr
|
||||
joystickAutoConnect _ = return Nothing
|
||||
|
||||
-- | Helper function to automatically close and disconnect freshly detached
|
||||
-- joystick devices
|
||||
joystickAutoDisconnect
|
||||
:: [SDL.Joystick] -- ^ List of Joystick descriptors
|
||||
-> JoystickMessage -- ^ Any 'JoystickMessage' will do, but listens
|
||||
-- specifically to 'MsgJoystickDevice' messages
|
||||
-> Affection [SDL.Joystick] -- ^ Returns altered list of Joystick descriptors
|
||||
joystickAutoDisconnect js (MsgJoystickDevice _ which SDL.JoyDeviceRemoved) =
|
||||
liftIO $ do
|
||||
joyIds <- mapM SDL.getJoystickID js
|
||||
logIO Verbose $ "These are the Joysticks connected: " <>
|
||||
fromString (show joyIds)
|
||||
d <- filterM (\j -> fmap (== which) (SDL.getJoystickID j)) js
|
||||
if not (null d)
|
||||
then do
|
||||
logIO Verbose $ "disconnected joysticks: " <> fromString (show $ head d)
|
||||
logIO Verbose $ "Disconnecting Joystick " <> fromString (show which)
|
||||
SDL.closeJoystick (head d)
|
||||
njoys <- filterM (\j -> return $ head d /= j) js
|
||||
logIO Verbose $ "returning joysticks: " <> fromString (show njoys)
|
||||
return njoys
|
||||
else do
|
||||
logIO Error $ "Error while disconnecting Joystick"
|
||||
return js
|
||||
joystickAutoDisconnect js _ = return js
|
|
@ -1,35 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Affection.Subsystems.AffectionKeyboard where
|
||||
|
||||
import Affection.Types
|
||||
import Affection.Util
|
||||
import Affection.MessageBus
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Helper function that consumes all Keyboard-related 'SDL.EventPayload's
|
||||
-- and emits appropriate 'KeyboardMessage's
|
||||
consumeSDLKeyboardEvents
|
||||
:: forall ak. (Participant ak, Mesg ak ~ KeyboardMessage)
|
||||
=> ak -- ^ The message system participant
|
||||
-> [SDL.EventPayload] -- ^ Incoming events
|
||||
-> Affection [SDL.EventPayload] -- ^ Leftover SDL Events
|
||||
consumeSDLKeyboardEvents ak = doConsume
|
||||
where
|
||||
doConsume [] = return []
|
||||
doConsume (e:es) = do
|
||||
ts <- getElapsedTime
|
||||
case e of
|
||||
SDL.KeyboardEvent dat -> do
|
||||
partEmit ak (MsgKeyboardEvent
|
||||
ts
|
||||
(SDL.keyboardEventWindow dat)
|
||||
(SDL.keyboardEventKeyMotion dat)
|
||||
(SDL.keyboardEventRepeat dat)
|
||||
(SDL.keyboardEventKeysym dat)
|
||||
)
|
||||
doConsume es
|
||||
_ -> fmap (e :) (doConsume es)
|
|
@ -1,61 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Affection.Subsystems.AffectionMouse where
|
||||
|
||||
import Affection.MessageBus
|
||||
import Affection.Types
|
||||
import Affection.Util
|
||||
|
||||
import Linear.Affine (unP)
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Helper funtion that consumes all Mouse-related 'SDL.Eventpayload's
|
||||
-- and emits appropriate 'MouseMessage's
|
||||
consumeSDLMouseEvents
|
||||
:: forall am. (Participant am, Mesg am ~ MouseMessage)
|
||||
=> am -- ^ The message system participant
|
||||
-> [SDL.EventPayload] -- ^ Incoming events
|
||||
-> Affection [SDL.EventPayload] -- ^ Leftover SDL events
|
||||
consumeSDLMouseEvents am = doConsume
|
||||
where
|
||||
doConsume
|
||||
:: [SDL.EventPayload]
|
||||
-> Affection [SDL.EventPayload]
|
||||
doConsume [] = return []
|
||||
doConsume (e:es) = do
|
||||
ts <- getElapsedTime
|
||||
case e of
|
||||
SDL.MouseMotionEvent dat -> do
|
||||
partEmit am (MsgMouseMotion
|
||||
ts
|
||||
(SDL.mouseMotionEventWindow dat)
|
||||
(SDL.mouseMotionEventWhich dat)
|
||||
(SDL.mouseMotionEventState dat)
|
||||
(unP $ SDL.mouseMotionEventPos dat)
|
||||
(SDL.mouseMotionEventRelMotion dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.MouseButtonEvent dat -> do
|
||||
partEmit am (MsgMouseButton
|
||||
ts
|
||||
(SDL.mouseButtonEventWindow dat)
|
||||
(SDL.mouseButtonEventMotion dat)
|
||||
(SDL.mouseButtonEventWhich dat)
|
||||
(SDL.mouseButtonEventButton dat)
|
||||
(SDL.mouseButtonEventClicks dat)
|
||||
(unP $ SDL.mouseButtonEventPos dat)
|
||||
)
|
||||
doConsume es
|
||||
SDL.MouseWheelEvent dat -> do
|
||||
partEmit am (MsgMouseWheel
|
||||
ts
|
||||
(SDL.mouseWheelEventWindow dat)
|
||||
(SDL.mouseWheelEventWhich dat)
|
||||
(SDL.mouseWheelEventPos dat)
|
||||
(SDL.mouseWheelEventDirection dat)
|
||||
)
|
||||
doConsume es
|
||||
_ -> fmap (e :) (doConsume es)
|
|
@ -1,74 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE RankNTypes #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
module Affection.Subsystems.AffectionWindow where
|
||||
|
||||
import Affection.Types
|
||||
import Affection.Util
|
||||
import Affection.MessageBus
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | Helper function that consumes all Window-related 'SDL.EventPayload's
|
||||
-- and emits appropriate 'WindowMessage's.
|
||||
consumeSDLWindowEvents
|
||||
:: forall aw. (Participant aw, Mesg aw ~ WindowMessage)
|
||||
=> aw -- ^ The message system participant
|
||||
-> [SDL.EventPayload] -- ^ Incoming events
|
||||
-> Affection [SDL.EventPayload] -- ^ Leftover SDL events
|
||||
consumeSDLWindowEvents aw = doConsume
|
||||
where
|
||||
doConsume
|
||||
:: (Mesg aw ~ WindowMessage)
|
||||
=> [SDL.EventPayload]
|
||||
-> Affection [SDL.EventPayload]
|
||||
doConsume [] = return []
|
||||
doConsume (e:es) = do
|
||||
ts <- getElapsedTime
|
||||
case e of
|
||||
SDL.WindowShownEvent (SDL.WindowShownEventData window) -> do
|
||||
partEmit aw (MsgWindowShow ts window)
|
||||
doConsume es
|
||||
SDL.WindowHiddenEvent (SDL.WindowHiddenEventData window) -> do
|
||||
partEmit aw (MsgWindowHide ts window)
|
||||
doConsume es
|
||||
SDL.WindowExposedEvent (SDL.WindowExposedEventData window) -> do
|
||||
partEmit aw (MsgWindowExpose ts window)
|
||||
doConsume es
|
||||
SDL.WindowMovedEvent (SDL.WindowMovedEventData window (SDL.P newPos)) -> do
|
||||
partEmit aw (MsgWindowMove ts window newPos)
|
||||
doConsume es
|
||||
SDL.WindowResizedEvent (SDL.WindowResizedEventData window newSize) -> do
|
||||
partEmit aw (MsgWindowResize ts window newSize)
|
||||
doConsume es
|
||||
SDL.WindowSizeChangedEvent (SDL.WindowSizeChangedEventData window size) -> do
|
||||
partEmit aw (MsgWindowSizeChange ts window size)
|
||||
doConsume es
|
||||
SDL.WindowMinimizedEvent (SDL.WindowMinimizedEventData window) -> do
|
||||
partEmit aw (MsgWindowMinimize ts window)
|
||||
doConsume es
|
||||
SDL.WindowMaximizedEvent (SDL.WindowMaximizedEventData window) -> do
|
||||
partEmit aw (MsgWindowMaximize ts window)
|
||||
doConsume es
|
||||
SDL.WindowRestoredEvent (SDL.WindowRestoredEventData window) -> do
|
||||
partEmit aw (MsgWindowRestore ts window)
|
||||
doConsume es
|
||||
SDL.WindowGainedMouseFocusEvent (SDL.WindowGainedMouseFocusEventData window) -> do
|
||||
partEmit aw (MsgWindowGainMouseFocus ts window)
|
||||
doConsume es
|
||||
SDL.WindowLostMouseFocusEvent (SDL.WindowLostMouseFocusEventData window) -> do
|
||||
partEmit aw (MsgWindowLoseMouseFocus ts window)
|
||||
doConsume es
|
||||
SDL.WindowGainedKeyboardFocusEvent (SDL.WindowGainedKeyboardFocusEventData window) -> do
|
||||
partEmit aw (MsgWindowGainKeyboardFocus ts window)
|
||||
doConsume es
|
||||
SDL.WindowLostKeyboardFocusEvent (SDL.WindowLostKeyboardFocusEventData window) -> do
|
||||
partEmit aw (MsgWindowLoseKeyboardFocus ts window)
|
||||
doConsume es
|
||||
SDL.WindowClosedEvent (SDL.WindowClosedEventData window) -> do
|
||||
partEmit aw (MsgWindowClose ts window)
|
||||
doConsume es
|
||||
_ -> fmap (e :) (doConsume es)
|
|
@ -1,13 +0,0 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
module Affection.Subsystems.Class where
|
||||
|
||||
import Affection.Types
|
||||
|
||||
import qualified SDL
|
||||
|
||||
-- | This class denotes a Subsystem to be part of SDL
|
||||
class SDLSubsystem s where
|
||||
-- | Consume the given 'SDL.EventPayload's and return only those not
|
||||
-- recognised
|
||||
consumeSDLEvents :: s -> [SDL.EventPayload] -> Affection [SDL.EventPayload]
|
|
@ -1,84 +0,0 @@
|
|||
{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveFunctor #-}
|
||||
module Affection.Types
|
||||
( Affection
|
||||
, AffectionConfig(..)
|
||||
, AffectionData(..)
|
||||
, AffectionStateInner
|
||||
, AffectionState(..)
|
||||
, InitComponents(..)
|
||||
, Angle
|
||||
-- | SDL reexports
|
||||
, SDL.WindowConfig(..)
|
||||
, SDL.WindowMode(..)
|
||||
, SDL.EventPayload(..)
|
||||
, SDL.InitFlag(..)
|
||||
, SDL.Window
|
||||
, SDL.GLContext
|
||||
) where
|
||||
|
||||
import qualified SDL.Init as SDL
|
||||
import qualified SDL.Video as SDL
|
||||
import qualified SDL.Event as SDL
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.State.Strict
|
||||
import qualified Control.Monad.Parallel as MP
|
||||
|
||||
import System.Clock (TimeSpec)
|
||||
|
||||
-- | Configuration for the aplication. needed at startup.
|
||||
data AffectionConfig us = AffectionConfig
|
||||
{ initComponents :: InitComponents
|
||||
-- ^ SDL components to initialize at startup
|
||||
, windowTitle :: T.Text
|
||||
-- ^ Window title
|
||||
, windowConfigs ::
|
||||
[
|
||||
( Word -- --^ Window identifier
|
||||
, SDL.WindowConfig -- --^ Window config for given window
|
||||
, SDL.WindowMode -- -- ^ Window mode to start in
|
||||
)
|
||||
]
|
||||
-- ^ Window configurations
|
||||
}
|
||||
|
||||
-- | Components to initialize in SDL.
|
||||
data InitComponents
|
||||
= All
|
||||
| Only [SDL.InitFlag]
|
||||
|
||||
-- | Main type for defining the look, feel and action of the whole application.
|
||||
data AffectionData = AffectionData
|
||||
{ drawWindows ::
|
||||
[
|
||||
( Word -- --^ Window identifier
|
||||
, SDL.Window -- --^ Window linked with identifier
|
||||
, SDL.WindowMode -- -- ^ current screen mode
|
||||
)
|
||||
] -- ^ SDL windows
|
||||
, glContext ::
|
||||
[
|
||||
( Word -- --^ Window identifier
|
||||
, SDL.GLContext -- --^ Associated OpenGL context
|
||||
)
|
||||
] -- ^ OpenGL rendering contexts
|
||||
, elapsedTime :: Double -- ^ Elapsed time in seconds
|
||||
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick
|
||||
, sysTime :: TimeSpec -- ^ System time (NOT the time on the clock)
|
||||
, pausedTime :: Bool -- ^ Should the update loop be executed?
|
||||
}
|
||||
|
||||
-- | Inner 'StateT' monad for the update state
|
||||
type AffectionStateInner sd a = StateT sd a
|
||||
|
||||
-- | Affection's state monad
|
||||
newtype AffectionState sd m a = AffectionState
|
||||
{ runState :: AffectionStateInner sd m a }
|
||||
deriving (Functor, Applicative, Monad, MonadIO, MonadState sd)
|
||||
|
||||
instance MP.MonadParallel m => MP.MonadParallel (AffectionState sd m)
|
||||
|
||||
type Affection a = AffectionState AffectionData IO a
|
||||
|
||||
type Angle = Double
|
|
@ -1,86 +0,0 @@
|
|||
module Affection.Util where
|
||||
|
||||
import Affection.Types
|
||||
import Affection.Logging
|
||||
import Affection.MessageBus.Message.WindowMessage
|
||||
|
||||
import SDL (($=))
|
||||
import qualified SDL
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import System.Clock
|
||||
|
||||
import Data.String (fromString)
|
||||
import Data.List (find)
|
||||
|
||||
import Control.Monad.State
|
||||
|
||||
-- | Prehandle SDL events
|
||||
preHandleEvents :: [SDL.Event] -> Affection [SDL.EventPayload]
|
||||
preHandleEvents evs =
|
||||
return $ map SDL.eventPayload evs
|
||||
|
||||
-- | block a thread for a specified amount of time
|
||||
delaySec
|
||||
:: Int -- ^ Number of seconds
|
||||
-> IO ()
|
||||
delaySec dur = SDL.delay (fromIntegral $ dur * 1000)
|
||||
|
||||
-- | Get time since start but always the same in the current tick.
|
||||
getElapsedTime :: Affection Double
|
||||
getElapsedTime = gets elapsedTime
|
||||
|
||||
-- | Get delta time (time elapsed from last frame)
|
||||
getDelta :: Affection Double
|
||||
getDelta = gets deltaTime
|
||||
|
||||
-- | Toggle the Screen mode between 'SDL.Windowed' and 'SDL.FullscreenDesktop'.
|
||||
-- Pauses the Engine in the process.
|
||||
toggleScreen :: Word -> Affection ()
|
||||
toggleScreen windowIdent = do
|
||||
ad <- get
|
||||
let mwindow = find (\(ident, _, _) -> ident == windowIdent) (drawWindows ad)
|
||||
case mwindow of
|
||||
Just (ident, window, mode) -> do
|
||||
newMode <- case mode of
|
||||
SDL.FullscreenDesktop -> do
|
||||
SDL.setWindowMode window SDL.Windowed
|
||||
return SDL.Windowed
|
||||
SDL.Windowed -> do
|
||||
SDL.setWindowMode window SDL.FullscreenDesktop
|
||||
return SDL.FullscreenDesktop
|
||||
x -> do
|
||||
liftIO $ logIO Warn ("Unexpected window mode: " <> fromString (show x))
|
||||
return x
|
||||
now <- liftIO $ getTime Monotonic
|
||||
put ad
|
||||
{ sysTime = now
|
||||
, drawWindows = map
|
||||
(\e@(lid, win, _) ->
|
||||
if lid == ident
|
||||
then (lid, win, newMode)
|
||||
else e
|
||||
)
|
||||
(drawWindows ad)
|
||||
}
|
||||
Nothing -> do
|
||||
liftIO $ logIO Warn ("No window found with ident " <> fromString (show windowIdent))
|
||||
|
||||
-- | Fit the GL Viewport to Window size
|
||||
fitViewport
|
||||
:: Double -- ^ Image Ratio (width / height)
|
||||
-> WindowMessage -- ^ Incoming Message. Listens only on
|
||||
-- 'MsgWindowResize' and ignores all others.
|
||||
-> Affection ()
|
||||
fitViewport ratio (MsgWindowResize _ _ (SDL.V2 w h)) = do
|
||||
liftIO $ logIO Verbose "Fitting Viewport to size"
|
||||
if (fromIntegral w / fromIntegral h) > ratio
|
||||
then do
|
||||
let nw = floor (fromIntegral h * ratio)
|
||||
dw = floor ((fromIntegral w - fromIntegral nw) / 2 :: Double)
|
||||
GL.viewport $= (GL.Position dw 0, GL.Size nw h)
|
||||
else do
|
||||
let nh = floor (fromIntegral w / ratio)
|
||||
dh = floor ((fromIntegral h - fromIntegral nh) / 2 :: Double)
|
||||
GL.viewport $= (GL.Position 0 dh, GL.Size w nh)
|
||||
fitViewport _ _ = return ()
|
8
src/Classes.hs
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Classes
|
||||
( module C
|
||||
) where
|
||||
|
||||
import Classes.Scene as C
|
||||
import Classes.Prop as C
|
||||
import Classes.Actor as C
|
||||
import Classes.Collectable as C
|
10
src/Classes/Actor.hs
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Classes.Actor where
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Classes.Prop
|
||||
import Physics.Classes.Collidible
|
||||
|
||||
class (Prop a, Collidible a) => Actor a where
|
||||
|
||||
perform :: Double -> a -> a
|
27
src/Classes/Collectable.hs
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Classes.Collectable where
|
||||
|
||||
import Physics.Classes.Collidible (Collidible)
|
||||
|
||||
-- | All kinds of Effects present in the game
|
||||
data Effect
|
||||
= HealthUp
|
||||
| SpeedUp
|
||||
| JumpUp
|
||||
| ArmorUp
|
||||
| Antidote
|
||||
| StopTime
|
||||
| Invisibility
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | The Effect holder type definition
|
||||
data EffectHolder = EffectHolder
|
||||
{ effectDuration :: Double -- ^ Duration of stored effect
|
||||
, effectReleased :: Effect -- ^ The actual effect released
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
class Collidible c => Collectable c where
|
||||
|
||||
effect
|
||||
:: c -- ^ Collectable object
|
||||
-> EffectHolder -- ^ The descriptor of the effect contained
|
11
src/Classes/Prop.hs
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Classes.Prop where
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Drawable
|
||||
|
||||
class (Show a, Drawable a) => Prop a where
|
||||
|
||||
residentLayer :: a -> Word
|
||||
|
||||
bindPropTexture :: a -> IO ()
|
30
src/Classes/Scene.hs
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Classes.Scene where
|
||||
|
||||
import Affection
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types.Util
|
||||
import Types.Subsystems
|
||||
|
||||
class Scene a where
|
||||
|
||||
-- | Perform initialization and output a (possibly empty) data container.
|
||||
initScene :: IO a
|
||||
|
||||
-- | Load actual data into the initialized container.
|
||||
loadScene :: a -> TMVar Progress -> IO ()
|
||||
|
||||
-- | Query whether loading data is finished.
|
||||
isSceneLoaded :: a -> Affection Bool
|
||||
|
||||
-- | Run updates on the data given the time elapsed since last frame
|
||||
update :: a -> Double -> Affection ()
|
||||
|
||||
-- | Handle input events
|
||||
onEvents :: a -> TranslatorMessage -> Affection ()
|
||||
|
||||
-- | perform the drawing
|
||||
render :: a -> Affection ()
|
6
src/Graphics.hs
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Graphics
|
||||
( module G
|
||||
) where
|
||||
|
||||
import Graphics.Classes as G
|
||||
import Graphics.Types as G
|
8
src/Graphics/Classes.hs
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Graphics.Classes
|
||||
( module GC
|
||||
) where
|
||||
|
||||
import Graphics.Classes.Bindable as GC
|
||||
import Graphics.Classes.Buffer as GC
|
||||
import Graphics.Classes.VertexLayout as GC
|
||||
import Graphics.Classes.Drawable as GC
|
10
src/Graphics/Classes/Bindable.hs
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Graphics.Classes.Bindable where
|
||||
|
||||
-- | typeclass for bindable objects like buffers, vertex arrays or shaders
|
||||
class Bindable a where
|
||||
|
||||
-- bind the object in context
|
||||
bind :: a -> IO ()
|
||||
|
||||
-- release object from context
|
||||
unbind :: a -> IO ()
|
47
src/Graphics/Classes/Buffer.hs
Normal file
|
@ -0,0 +1,47 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
module Graphics.Classes.Buffer where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Foreign.Storable
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
-- | this aims to be a typeclass for all used buffer objects throughout the
|
||||
-- game. all buffer objects have to instanciate the Bindable typeclass.
|
||||
-- think of it as some kind of interface in the object oriented context
|
||||
class (Bindable a, Storable (StoreType a)) =>
|
||||
Buffer a where
|
||||
|
||||
-- | datatype inside the buffer
|
||||
type StoreType a :: *
|
||||
|
||||
-- | container datatype for 'StoreType's
|
||||
type StoreContainer a :: * -> *
|
||||
|
||||
-- | what buffer target does the buffer bind to
|
||||
target :: a -> GL.BufferTarget
|
||||
|
||||
-- | retrieve ID from buffer object
|
||||
glId :: a -> IO (GL.BufferObject)
|
||||
|
||||
-- | bind the buffer object and fill it with null data
|
||||
initialize :: a -> IO ()
|
||||
|
||||
-- | fill the buffer with actual data
|
||||
write
|
||||
:: a
|
||||
-> Word
|
||||
-- ^ write offset from beginning of buffer in number of data elements
|
||||
-> StoreContainer a (StoreType a)
|
||||
-- ^ Data to write
|
||||
-> IO ()
|
||||
|
||||
-- | expand the buffer to double of it's previous size.
|
||||
expand :: a -> IO ()
|
||||
|
||||
-- | free resources and delete the object
|
||||
delete :: a -> IO ()
|
18
src/Graphics/Classes/Drawable.hs
Normal file
|
@ -0,0 +1,18 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Graphics.Classes.Drawable where
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
-- iternal imports
|
||||
|
||||
import Graphics.Types.VertexBuffer (Vertex)
|
||||
|
||||
-- | A typeclass for all drawable objects
|
||||
class Drawable a where
|
||||
|
||||
-- -- | List type for resulting vertices and indices
|
||||
-- type VertexList a :: * -> *
|
||||
|
||||
-- | Function returning a tuple of Vectors of draw order indices and the
|
||||
-- appropriate vertices.
|
||||
toVertices :: a -> (V.Vector Word, V.Vector Vertex)
|
18
src/Graphics/Classes/VertexLayout.hs
Normal file
|
@ -0,0 +1,18 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
module Graphics.Classes.VertexLayout where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
class (Bindable (VertBuffer v)) => VertexLayout v where
|
||||
|
||||
type VertBuffer v :: *
|
||||
|
||||
layoutElements :: v -> [(GL.GLuint, GL.VertexArrayDescriptor GL.GLfloat)]
|
||||
|
||||
addBuffer :: v -> VertBuffer v -> IO ()
|
9
src/Graphics/Types.hs
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Graphics.Types
|
||||
( module GT
|
||||
) where
|
||||
|
||||
import Graphics.Types.VertexArray as GT
|
||||
import Graphics.Types.VertexBuffer as GT
|
||||
import Graphics.Types.IndexBuffer as GT
|
||||
import Graphics.Types.Shader as GT
|
||||
import Graphics.Types.Texture as GT
|
148
src/Graphics/Types/IndexBuffer.hs
Normal file
|
@ -0,0 +1,148 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Graphics.Types.IndexBuffer where
|
||||
|
||||
import Affection
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import SDL (($=))
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
import qualified Data.Vector.Storable as VS
|
||||
|
||||
import Control.Monad (when)
|
||||
import Control.Monad.Loops (whileM_)
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import Foreign
|
||||
import Foreign.C.Types
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
import Graphics.Classes.Buffer
|
||||
|
||||
-- layout of the IndexBuffer data object
|
||||
data IndexBuffer = IndexBuffer
|
||||
{ iBufId :: TVar GL.BufferObject -- buffer id
|
||||
, iBufSize :: TVar GL.GLsizeiptr -- size of data
|
||||
-- , iBufData :: Ptr a -- pointer to data
|
||||
, iBufCount :: TVar GL.GLint -- number of data elements
|
||||
}
|
||||
|
||||
-- instanciate typeclass from Buffer and fill in missing implementations
|
||||
instance Buffer IndexBuffer where
|
||||
|
||||
type StoreType IndexBuffer = GL.GLuint
|
||||
|
||||
type StoreContainer IndexBuffer = VS.Vector
|
||||
|
||||
target _ = GL.ElementArrayBuffer
|
||||
|
||||
glId = readTVarIO . iBufId
|
||||
|
||||
initialize buf = do
|
||||
-- bind the buffer using the default iplementation of the typeclass
|
||||
bind buf
|
||||
size <- readTVarIO $ iBufSize buf
|
||||
-- fill in the data
|
||||
GL.bufferData (target buf) $=
|
||||
( size
|
||||
, nullPtr
|
||||
, GL.DynamicDraw
|
||||
)
|
||||
-- release the buffer using the default implementation of the typeclass
|
||||
unbind buf
|
||||
|
||||
write buf offset dat = do
|
||||
whileM_
|
||||
(do
|
||||
currentSize <- readTVarIO (iBufSize buf)
|
||||
pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType IndexBuffer)
|
||||
> fromIntegral currentSize)
|
||||
$ do
|
||||
currentBufSize <- readTVarIO (iBufSize buf)
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType IndexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
-- bind buffer, just to be safe
|
||||
bind buf
|
||||
let elemCount = fromIntegral offset + VS.length dat
|
||||
logIO Verbose ("elemCount: " <> (fromString $ show elemCount))
|
||||
currentCount <- atomically $ readTVar (iBufCount buf)
|
||||
when (fromIntegral elemCount > currentCount) $
|
||||
atomically $ writeTVar (iBufCount buf) (fromIntegral elemCount)
|
||||
VS.unsafeWith dat $ \ ptr ->
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
(CPtrdiff $ fromIntegral offset *
|
||||
fromIntegral (sizeOf (undefined :: StoreType IndexBuffer)))
|
||||
(CPtrdiff $ fromIntegral $
|
||||
VS.length dat * sizeOf (undefined :: StoreType IndexBuffer))
|
||||
ptr
|
||||
|
||||
expand buf = do
|
||||
unbind buf
|
||||
delete buf
|
||||
newId <- GL.genObjectName
|
||||
newSize <- (2 *) <$> readTVarIO (iBufSize buf)
|
||||
atomically $ do
|
||||
writeTVar (iBufId buf) newId
|
||||
writeTVar (iBufSize buf) newSize
|
||||
initialize buf
|
||||
|
||||
delete buf = do
|
||||
unbind buf
|
||||
GL.deleteObjectName =<< (readTVarIO $ iBufId buf)
|
||||
|
||||
|
||||
instance Bindable IndexBuffer where
|
||||
|
||||
-- bind the buffer
|
||||
bind buf =
|
||||
(\ a -> GL.bindBuffer (target buf) $= Just a) =<< glId buf
|
||||
|
||||
-- unbind the buffer
|
||||
unbind buf = GL.bindBuffer (target buf) $= Nothing
|
||||
|
||||
newIndexBuffer
|
||||
:: Word
|
||||
-> IO IndexBuffer -- newly built IndexBuffer data object
|
||||
newIndexBuffer initLength = do
|
||||
-- create the buffer object in applicative style
|
||||
buf <- IndexBuffer
|
||||
-- generate the ID
|
||||
<$> (newTVarIO =<< GL.genObjectName)
|
||||
-- compute buffer size
|
||||
<*> newTVarIO (CPtrdiff (fromIntegral $
|
||||
(fromIntegral initLength * sizeOf (undefined :: StoreType IndexBuffer))))
|
||||
-- -- make pointer out of list
|
||||
-- <*> newArray list
|
||||
-- -- get count
|
||||
<*> newTVarIO 0
|
||||
-- fill the data in to the buffer
|
||||
initialize buf
|
||||
-- return the data object
|
||||
return buf
|
201
src/Graphics/Types/Shader.hs
Normal file
|
@ -0,0 +1,201 @@
|
|||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
|
||||
module Graphics.Types.Shader where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
import qualified Graphics.GL as GLRaw
|
||||
|
||||
import Data.StateVar
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
|
||||
import Control.Concurrent.MVar
|
||||
|
||||
import Linear
|
||||
|
||||
import Foreign.Marshal.Array (withArray)
|
||||
import Foreign.Storable
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
data Shader = Shader
|
||||
{ shaderId :: GL.Program
|
||||
, shaderSources :: [ShaderSource]
|
||||
, shaderUniforms :: MVar [ShaderUniform]
|
||||
}
|
||||
|
||||
-- make Shader Bindable
|
||||
instance Bindable Shader where
|
||||
|
||||
bind s = GL.currentProgram $= Just (shaderId s)
|
||||
|
||||
unbind _ = GL.currentProgram $= Nothing
|
||||
|
||||
data ShaderSource = ShaderSource
|
||||
{ shaderSourceType :: GL.ShaderType
|
||||
, shaderPath :: FilePath
|
||||
}
|
||||
|
||||
data ShaderUniform = ShaderUniform
|
||||
{ shaderUniformName :: String
|
||||
, shaderUniformLocation :: GL.UniformLocation
|
||||
}
|
||||
|
||||
-- orphan instance to make linear's M44 uniforms
|
||||
instance GL.Uniform (M44 GL.GLfloat) where
|
||||
uniform (GL.UniformLocation ul) = makeStateVar getter setter
|
||||
where
|
||||
getter = error "cannot implement: get uniform M44 GLfloat"
|
||||
-- GL.withNewMatrix GL.RowMajor $ getUniformWith GLRaw.glGetUniformfv loc
|
||||
setter (V4
|
||||
(V4 a b c d)
|
||||
(V4 e f g h)
|
||||
(V4 i j k l)
|
||||
(V4 m n o p)) = do
|
||||
mat <- GL.newMatrix GL.RowMajor [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p] :: IO (GL.GLmatrix GL.GLfloat)
|
||||
GL.withMatrix mat $ GLRaw.glUniformMatrix4fv ul 1 . isRowMajor
|
||||
uniformv (GL.UniformLocation _) _ _ = error "can not implement uniformv for M44 GLfloat"
|
||||
-- GLRaw.glUniformMatrix4fv ul count 0 (castPtr buf `asTypeOf` elemType buf)
|
||||
-- where
|
||||
-- elemType = undefined :: GL.MatrixComponent c => Ptr (GL.GLmatrix c) -> Ptr c
|
||||
|
||||
-- getUniformWith :: (GL.GLuint -> GL.GLint -> Ptr a -> IO ()) -> GL.UniformLocation -> Ptr a -> IO ()
|
||||
-- getUniformWith getter (GL.UniformLocation ul) buf = do
|
||||
-- program <- fmap (GL.programID . fromJust) $ get GL.currentProgram
|
||||
-- getter program ul buf
|
||||
|
||||
isRowMajor :: GL.MatrixOrder -> GL.GLboolean
|
||||
isRowMajor p = if (GL.RowMajor == p) then 1 else 0
|
||||
|
||||
-- create new data object of type Shader
|
||||
newShader :: [ShaderSource] -> IO Shader
|
||||
newShader shaderSrc = do
|
||||
-- create program Object
|
||||
program <- GL.createProgram
|
||||
|
||||
-- create shaders from the source codes given
|
||||
compilates <- mapM
|
||||
(\(ShaderSource type_ path) -> do
|
||||
-- read in shader source from File
|
||||
source<- B.readFile path
|
||||
|
||||
-- compile the shader
|
||||
compiledShader <- compileShaderSource type_ source
|
||||
return (type_, compiledShader)
|
||||
)
|
||||
shaderSrc
|
||||
|
||||
-- attach, link and validate the shader program
|
||||
GL.attachedShaders program $= map snd compilates
|
||||
GL.linkProgram program
|
||||
GL.validateProgram program
|
||||
|
||||
ok <- get (GL.validateStatus program)
|
||||
if ok
|
||||
then
|
||||
putStrLn "Shaderprogram linked successfully!"
|
||||
else do
|
||||
info <- get (GL.programInfoLog program)
|
||||
putStrLn "Shaderprogram linking failed!\nInfo log says:"
|
||||
putStrLn info
|
||||
GL.deleteObjectName program
|
||||
|
||||
-- throw away the shaders, since they are linked into the shader program
|
||||
mapM_ (\s -> GL.deleteObjectName s) (map snd compilates)
|
||||
|
||||
-- return data object
|
||||
Shader program shaderSrc <$> newMVar []
|
||||
|
||||
-- pass uniform values into Shader program
|
||||
setUniformList :: (Storable a, GL.Uniform a) => Shader -> String -> [a] -> IO ()
|
||||
setUniformList (Shader shaderProgram _ sUniforms) uniname data_ = do
|
||||
-- check if uniform location is already cached
|
||||
locs <- readMVar sUniforms
|
||||
|
||||
-- retrieve uniform location
|
||||
let unilocs = filter
|
||||
(\(ShaderUniform name _) -> name == uniname)
|
||||
locs
|
||||
|
||||
case unilocs of
|
||||
[] -> do
|
||||
print ("Unknown uniform: " <> uniname)
|
||||
print "Retrieving uniform location from shader program"
|
||||
loc@(GL.UniformLocation locNum) <- get $ GL.uniformLocation shaderProgram uniname
|
||||
if locNum < 0
|
||||
then
|
||||
print ("Uniform does not exist in shader program: " <> uniname)
|
||||
else do
|
||||
-- set the data
|
||||
withArray data_ $ \ptr ->
|
||||
GL.uniformv loc (fromIntegral $ length data_) ptr
|
||||
--GL.uniform loc $= data_
|
||||
-- add uniform to cache
|
||||
modifyMVar_ sUniforms
|
||||
(\list -> return $ ShaderUniform uniname loc : list)
|
||||
[ShaderUniform _ loc] ->
|
||||
-- set the data
|
||||
withArray data_ $ \ptr ->
|
||||
GL.uniformv loc (fromIntegral $ length data_) ptr
|
||||
|
||||
setUniform :: (GL.Uniform a) => Shader -> String -> a -> IO ()
|
||||
setUniform (Shader shaderProgram _ sUniforms) uniname data_ = do
|
||||
-- check if uniform location is already cached
|
||||
locs <- readMVar sUniforms
|
||||
|
||||
-- retrieve uniform location
|
||||
let unilocs = filter
|
||||
(\(ShaderUniform name _) -> name == uniname)
|
||||
locs
|
||||
|
||||
case unilocs of
|
||||
[] -> do
|
||||
print ("Unknown uniform: " <> uniname)
|
||||
print "Retrieving uniform location from shader program"
|
||||
loc@(GL.UniformLocation locNum) <- get $ GL.uniformLocation shaderProgram uniname
|
||||
if locNum < 0
|
||||
then
|
||||
print ("Uniform does not exist in shader program: " <> uniname)
|
||||
else do
|
||||
-- set the data
|
||||
--withArray data_ $ \ptr ->
|
||||
-- GL.uniformv loc (length data_) ptr
|
||||
GL.uniform loc $= data_
|
||||
-- add uniform to cache
|
||||
modifyMVar_ sUniforms
|
||||
(\list -> return $ ShaderUniform uniname loc : list)
|
||||
[ShaderUniform _ loc] ->
|
||||
-- set the data
|
||||
GL.uniform loc $= data_
|
||||
|
||||
-- | compile a shader from source
|
||||
compileShaderSource
|
||||
:: GL.ShaderType -- ^ what type of shader we are compiling
|
||||
-> B.ByteString -- ^ its source code
|
||||
-> IO GL.Shader
|
||||
compileShaderSource type_ source = do
|
||||
-- create shader object of specified type
|
||||
shaderObject <- GL.createShader type_
|
||||
|
||||
-- assign source code to shader object
|
||||
GL.shaderSourceBS shaderObject $= source
|
||||
|
||||
-- actually compile the shader
|
||||
GL.compileShader shaderObject
|
||||
|
||||
-- error handling
|
||||
ok <- GL.compileStatus shaderObject
|
||||
|
||||
if ok
|
||||
then
|
||||
putStrLn (show type_ ++ ": compilation successful!")
|
||||
else do
|
||||
info <- get (GL.shaderInfoLog shaderObject)
|
||||
putStrLn (show type_ ++ ": compilation failed!\nInfo log says:")
|
||||
putStrLn info
|
||||
GL.deleteObjectName shaderObject
|
||||
|
||||
return shaderObject
|
83
src/Graphics/Types/Texture.hs
Normal file
|
@ -0,0 +1,83 @@
|
|||
module Graphics.Types.Texture where
|
||||
|
||||
import SDL (($=))
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Codec.Picture
|
||||
import Codec.Picture.Extra
|
||||
|
||||
import Data.Vector.Storable (unsafeWith)
|
||||
|
||||
import Linear
|
||||
|
||||
import Foreign
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
data Texture = Texture
|
||||
{ textureId :: GL.TextureObject
|
||||
, textureSlot :: GL.TextureUnit
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Bindable Texture where
|
||||
|
||||
bind t = do
|
||||
GL.activeTexture $= textureSlot t
|
||||
GL.textureBinding GL.Texture2D $= Just (textureId t)
|
||||
|
||||
unbind _ = GL.textureBinding GL.Texture2D $= Nothing
|
||||
|
||||
newTexture :: FilePath -> GL.GLuint -> IO (V2 Word, Texture)
|
||||
newTexture fp slot = do
|
||||
|
||||
-- read in image from filesystem
|
||||
img <- flipVertically <$> convertRGBA8 <$>
|
||||
either
|
||||
(\err -> error $ "reading image file " <> fp <> " failed: " <> err)
|
||||
id
|
||||
<$>
|
||||
readImage fp
|
||||
|
||||
-- extract the raw pointer from vector
|
||||
unsafeWith (imageData img) $ \ptr -> do
|
||||
-- create texture object
|
||||
tex <- Texture
|
||||
<$> GL.genObjectName
|
||||
<*> (pure $ GL.TextureUnit slot)
|
||||
-- <*> (pure fp)
|
||||
let dimensions = fromIntegral <$> V2 (imageWidth img) (imageHeight img)
|
||||
-- <*> (pure $ componentCount (VS.head $ imageData img))
|
||||
data_ = castPtr ptr
|
||||
|
||||
-- bind texture
|
||||
bind tex
|
||||
|
||||
-- set texture parameters
|
||||
GL.textureFilter GL.Texture2D $= ((GL.Linear', Nothing), GL.Linear')
|
||||
GL.textureWrapMode GL.Texture2D GL.S $= (GL.Repeated, GL.Repeat)
|
||||
GL.textureWrapMode GL.Texture2D GL.T $= (GL.Repeated, GL.Repeat)
|
||||
|
||||
-- put data into GPU memory
|
||||
loadTexture tex dimensions data_
|
||||
|
||||
-- unbind texture
|
||||
unbind tex
|
||||
|
||||
-- pass texture object out
|
||||
return (fmap fromIntegral dimensions, tex)
|
||||
|
||||
loadTexture :: Texture -> V2 GL.GLsizei -> Ptr () -> IO ()
|
||||
loadTexture _ dimensions data_ =
|
||||
let (V2 w h) = dimensions
|
||||
in GL.texImage2D
|
||||
GL.Texture2D
|
||||
GL.NoProxy
|
||||
0
|
||||
GL.RGBA'
|
||||
(GL.TextureSize2D w h)
|
||||
0
|
||||
(GL.PixelData GL.RGBA GL.UnsignedByte data_)
|
25
src/Graphics/Types/VertexArray.hs
Normal file
|
@ -0,0 +1,25 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Graphics.Types.VertexArray where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import SDL (($=))
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
newtype VertexArray = VertexArray
|
||||
{ vArrId :: GL.VertexArrayObject
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Bindable VertexArray where
|
||||
|
||||
bind va = GL.bindVertexArrayObject $= Just (vArrId va)
|
||||
|
||||
unbind _ = GL.bindVertexArrayObject $= Nothing
|
||||
|
||||
newVertexArray :: IO VertexArray
|
||||
newVertexArray = VertexArray
|
||||
<$> GL.genObjectName
|
222
src/Graphics/Types/VertexBuffer.hs
Normal file
|
@ -0,0 +1,222 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
module Graphics.Types.VertexBuffer where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import SDL (($=))
|
||||
|
||||
import Control.Monad.Loops (whileM_)
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import qualified Data.Vector.Storable as VS
|
||||
|
||||
import Linear
|
||||
|
||||
import Foreign
|
||||
import Foreign.C.Types
|
||||
import Foreign.Storable.Generic
|
||||
|
||||
import GHC.Generics
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Classes.Bindable
|
||||
import Graphics.Classes.Buffer
|
||||
import Graphics.Classes.VertexLayout
|
||||
|
||||
-- | layout of the VertexBuffer data object
|
||||
data VertexBuffer = VertexBuffer
|
||||
{ vBufId :: TVar GL.BufferObject -- ^ buffer id
|
||||
, vBufSize :: TVar GL.GLsizeiptr -- ^ size of data
|
||||
-- , vBufData :: Ptr a -- pointer to data
|
||||
}
|
||||
|
||||
data Vertex = Vertex
|
||||
{ vertPosition :: V3 GL.GLfloat
|
||||
, vertColor :: V4 GL.GLfloat
|
||||
, vertTexCoord :: V2 GL.GLfloat
|
||||
, vertTexID :: GL.GLfloat
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
-- | make vertices instances of 'Storable'. it's a kind of magic ^.^
|
||||
instance GStorable Vertex
|
||||
instance GStorable (V2 GL.GLfloat)
|
||||
instance GStorable (V3 GL.GLfloat)
|
||||
instance GStorable (V4 GL.GLfloat)
|
||||
|
||||
-- | Smart constructor for a new Vertex
|
||||
newVertex
|
||||
:: V3 GL.GLfloat
|
||||
-> V4 GL.GLfloat
|
||||
-> V2 GL.GLfloat
|
||||
-> GL.GLfloat
|
||||
-> Vertex
|
||||
newVertex pos color texcoord index =
|
||||
Vertex
|
||||
pos
|
||||
color
|
||||
texcoord
|
||||
index
|
||||
|
||||
-- | Instanciate typeclass Buffer and fill in missing implementations
|
||||
instance Buffer VertexBuffer where
|
||||
|
||||
type StoreType VertexBuffer = Vertex
|
||||
|
||||
type StoreContainer VertexBuffer = VS.Vector
|
||||
|
||||
target _ = GL.ArrayBuffer
|
||||
|
||||
glId = readTVarIO . vBufId
|
||||
|
||||
initialize buf = do
|
||||
-- bind the buffer using the default iplementation of the typeclass
|
||||
bind buf
|
||||
size <- readTVarIO (vBufSize buf)
|
||||
-- fill in the data
|
||||
GL.bufferData (target buf) $=
|
||||
( size
|
||||
, nullPtr
|
||||
, GL.DynamicDraw
|
||||
)
|
||||
-- release the buffer using the default implementation of the typeclass
|
||||
unbind buf
|
||||
|
||||
write buf offset dat = do
|
||||
whileM_
|
||||
(do
|
||||
currentSize <- readTVarIO (vBufSize buf)
|
||||
pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType VertexBuffer)
|
||||
> fromIntegral currentSize)
|
||||
$ do
|
||||
currentBufSize <- readTVarIO (vBufSize buf)
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType VertexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
-- bind buffer, just to be safe
|
||||
bind buf
|
||||
VS.unsafeWith dat $ \ ptr ->
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
-- target buffer type
|
||||
GL.WriteToBuffer
|
||||
-- data access direction
|
||||
(CPtrdiff $ fromIntegral offset *
|
||||
fromIntegral (sizeOf (undefined :: StoreType VertexBuffer)))
|
||||
-- offset from buffer start
|
||||
(CPtrdiff $ fromIntegral $
|
||||
VS.length dat * sizeOf (undefined :: StoreType VertexBuffer))
|
||||
-- length of data to write
|
||||
ptr
|
||||
-- pointer to first data object
|
||||
|
||||
--le | expand the buffer to double of it's previous size.
|
||||
-- This discards all previously written data and layouts, as internally the
|
||||
-- old buffer is discarded and a new buffer allocated.
|
||||
expand buf = do
|
||||
-- unbind the buffer before meddling with its innards
|
||||
unbind buf
|
||||
-- free the old buffer
|
||||
delete buf
|
||||
-- generate new buffer
|
||||
newId <- GL.genObjectName
|
||||
-- calculate new size
|
||||
newSize <- (2 *) <$> readTVarIO (vBufSize buf)
|
||||
-- update data object
|
||||
atomically $ do
|
||||
writeTVar (vBufId buf) newId
|
||||
writeTVar (vBufSize buf) newSize
|
||||
-- allocate and fill buffer with null data
|
||||
initialize buf
|
||||
|
||||
delete buf = do
|
||||
unbind buf
|
||||
GL.deleteObjectName =<< (readTVarIO $ vBufId buf)
|
||||
|
||||
-- | Instanciate Bindable typeclass required by Buffer typeclass implement it
|
||||
instance Bindable VertexBuffer where
|
||||
|
||||
-- bind the buffer
|
||||
bind buf =
|
||||
(\a -> GL.bindBuffer (target buf) $= Just a) =<< glId buf
|
||||
|
||||
-- unbind the buffer
|
||||
unbind buf =
|
||||
GL.bindBuffer (target buf) $= Nothing
|
||||
|
||||
-- | smart constructor for a VertexBuffer data object
|
||||
newVertexBuffer
|
||||
:: Word -- ^ initial Buffer size
|
||||
-> IO VertexBuffer -- ^ newly built VertexBuffer data object
|
||||
newVertexBuffer initSize = do
|
||||
-- let dummyVertex = newVertex (V3 0 0 0) (V4 0 0 0 0) (V2 0 0) 0
|
||||
-- create the buffer object in applicative style
|
||||
buf <- VertexBuffer
|
||||
-- generate the ID
|
||||
<$> (newTVarIO =<< GL.genObjectName)
|
||||
-- compute buffer size
|
||||
<*> (newTVarIO (CPtrdiff (fromIntegral $
|
||||
(fromIntegral initSize * sizeOf (undefined :: StoreType VertexBuffer)))))
|
||||
-- make pointer out of list
|
||||
-- <*> newArray list
|
||||
-- fill the data in to the buffer
|
||||
initialize buf
|
||||
-- return the data object
|
||||
return buf
|
||||
|
||||
instance VertexLayout Vertex where
|
||||
|
||||
type VertBuffer Vertex = VertexBuffer
|
||||
|
||||
layoutElements _ =
|
||||
foldl
|
||||
(\acc (index, count) ->
|
||||
( index
|
||||
, GL.VertexArrayDescriptor
|
||||
count
|
||||
GL.Float
|
||||
(fromIntegral $ sizeOf (undefined :: Vertex))
|
||||
(nullPtr `plusPtr` (sizeOf (undefined :: GL.GLfloat) * fromIntegral
|
||||
(sum (map ((\(GL.VertexArrayDescriptor c _ _ _) -> c) . snd) acc))))
|
||||
) : acc
|
||||
)
|
||||
[]
|
||||
(zip [0 ..] [3, 4, 2, 1])
|
||||
|
||||
addBuffer vert vb = do
|
||||
-- bind vertex buffer to associate them
|
||||
bind vb
|
||||
-- enable and fill vertex attrib pointer(s)
|
||||
let list = layoutElements vert
|
||||
mapM_
|
||||
(\(index, descriptor) -> do
|
||||
GL.vertexAttribArray (GL.AttribLocation index) $= GL.Enabled
|
||||
GL.vertexAttribPointer (GL.AttribLocation index) $=
|
||||
( GL.ToNormalizedFloat
|
||||
, descriptor
|
||||
)
|
||||
)
|
||||
list
|
||||
unbind vb
|
156
src/Main.hs
Normal file
|
@ -0,0 +1,156 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main where
|
||||
|
||||
import Affection
|
||||
|
||||
import SDL (($=), get)
|
||||
import qualified SDL
|
||||
import qualified SDL.Raw.Video as SDL (glSetAttribute)
|
||||
import qualified SDL.Raw.Enum as SDL
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Control.Monad (when, void, unless)
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import qualified Data.Map.Strict as M
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
import Linear
|
||||
|
||||
-- internal imports
|
||||
|
||||
import StateMachine()
|
||||
import Types
|
||||
import Classes
|
||||
import Util
|
||||
import Scenes.Test
|
||||
|
||||
instance Affectionate GameData where
|
||||
preLoop = preLoad
|
||||
handleEvents = handle
|
||||
update = Main.update
|
||||
draw = Main.draw
|
||||
loadState = Main.init
|
||||
cleanUp _ = return ()
|
||||
hasNextStep = liftIO . readTVarIO . gameRunning
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let config = AffectionConfig
|
||||
{ initComponents = All
|
||||
, windowTitle = "Pituicat"
|
||||
, windowConfigs =
|
||||
[ ( 0
|
||||
, SDL.defaultWindow
|
||||
{ SDL.windowInitialSize = V2 800 600
|
||||
, SDL.windowResizable = False
|
||||
, SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
||||
{ SDL.glProfile = SDL.Core SDL.Normal 4 0
|
||||
}
|
||||
}
|
||||
, SDL.Windowed
|
||||
)
|
||||
]
|
||||
} :: AffectionConfig GameData
|
||||
withAffection config
|
||||
|
||||
preLoad :: GameData -> Affection ()
|
||||
preLoad gd = do
|
||||
translatorUUID <- partSubscribe
|
||||
(subKeyboard $ gameSubsystems gd)
|
||||
(\mesg ->
|
||||
case mesg of
|
||||
(MsgKeyboardEvent time _ motion False keysym) -> do
|
||||
translator <- liftIO $ readTVarIO (gameActionTranslation gd)
|
||||
case
|
||||
( SDL.keysymScancode keysym
|
||||
, translateSDLModifiers (SDL.keysymModifier keysym)
|
||||
) `M.lookup`
|
||||
translator
|
||||
of
|
||||
Just action ->
|
||||
partEmit
|
||||
(subTranslator $ gameSubsystems gd)
|
||||
(TranslatorMessage action time motion)
|
||||
Nothing ->
|
||||
globalKeyHandle gd mesg
|
||||
_ ->
|
||||
return ()
|
||||
)
|
||||
windowCloseUUID <- partSubscribe
|
||||
(subWindow $ gameSubsystems gd)
|
||||
(\mesg -> case mesg of
|
||||
MsgWindowClose _ _ ->
|
||||
liftIO $ atomically $ writeTVar (gameRunning gd) False
|
||||
MsgWindowResize {} ->
|
||||
fitViewport (800 / 600) mesg
|
||||
_ ->
|
||||
return ()
|
||||
)
|
||||
liftIO $ atomically $ writeTVar
|
||||
(gameGeneralClean gd)
|
||||
[translatorUUID, windowCloseUUID]
|
||||
|
||||
handle :: GameData -> [SDL.EventPayload] -> Affection ()
|
||||
handle gd evs = do
|
||||
state <- liftIO (readTVarIO $ gameState gd)
|
||||
smEvent state gd evs
|
||||
|
||||
update :: GameData -> Double -> Affection ()
|
||||
update gd dt = do
|
||||
loadProgress <- liftIO $ atomically $ readTMVar $ gameStateLoadProgress gd
|
||||
when (fst loadProgress < 1) $
|
||||
liftIO (logIO Verbose ("Progress: " <> snd loadProgress))
|
||||
state <- liftIO $ readTVarIO $ gameState gd
|
||||
isStagePresent <- liftIO $ atomically $ fmap not $ isEmptyTMVar $ gameScene gd
|
||||
if isStagePresent
|
||||
then do
|
||||
liftIO $ logIO Verbose "Stage is present"
|
||||
(Stage sceneContainer) <- liftIO $ atomically $ readTMVar $ gameScene gd
|
||||
sceneLoaded <- isSceneLoaded sceneContainer
|
||||
if not sceneLoaded
|
||||
then do
|
||||
liftIO $ logIO Verbose "Loading scene"
|
||||
smLoad state gd
|
||||
evHandler <- partSubscribe
|
||||
(subTranslator $ gameSubsystems gd)
|
||||
(onEvents sceneContainer)
|
||||
liftIO $ atomically $ writeTVar (gameSceneClean gd) (Just evHandler)
|
||||
else
|
||||
smUpdate state gd dt
|
||||
else
|
||||
liftIO $ logIO Error "No Stage to play on"
|
||||
|
||||
draw :: GameData -> Affection ()
|
||||
draw gd = do
|
||||
state <- liftIO (readTVarIO $ gameState gd)
|
||||
liftIO $ logIO Verbose (fromString $ "now drawing: " <> show state)
|
||||
GL.clearColor $= GL.Color4 0 0 0 1
|
||||
smDraw state gd
|
||||
err <- SDL.get GL.errors
|
||||
unless (null err) (liftIO $ logIO Error ("loop errors: " <> fromString (show err)))
|
||||
|
||||
init :: IO GameData
|
||||
init = do
|
||||
GL.blend $= GL.Enabled
|
||||
GL.blendFunc $= (GL.SrcAlpha, GL.OneMinusSrcAlpha)
|
||||
void $ SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1
|
||||
GameData
|
||||
<$> (newTMVarIO . Stage =<< (initScene :: IO Test))
|
||||
<*> newTVarIO Loading
|
||||
<*> newTMVarIO (0, "Ohai!")
|
||||
<*> (Subsystems
|
||||
<$> (SubWindow <$> newTVarIO [])
|
||||
<*> (SubMouse <$> newTVarIO [])
|
||||
<*> (SubKeyboard <$> newTVarIO [])
|
||||
<*> (SubTranslator <$> newTVarIO [])
|
||||
)
|
||||
<*> newTVarIO defaultTranslation
|
||||
<*> newTVarIO True
|
||||
<*> newTVarIO Nothing
|
||||
<*> newTVarIO Nothing
|
||||
<*> newTVarIO []
|
||||
<*> newTVarIO Nothing
|
73
src/Map.hs
Normal file
|
@ -0,0 +1,73 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Map where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Linear
|
||||
|
||||
import Codec.Picture
|
||||
import Codec.Picture.Extra
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Control.Monad (foldM)
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Graphics
|
||||
|
||||
constructMap :: LevelDescriptor -> GL.GLuint -> IO LevelMap
|
||||
constructMap desc tilemapSlot = do
|
||||
tilemap <- uncurry TileMap <$> newTexture (levelTileMap desc) tilemapSlot
|
||||
(layers, dimensions) <- foldM
|
||||
(\(layers, dims) descTup -> do
|
||||
(nlayer, ndims) <-
|
||||
readLayer descTup (fmap fromIntegral $ tileMapDimensions tilemap)
|
||||
if not (null layers) && ndims /= dims
|
||||
then error ("Map Layer dimensions mismatch in: " <> snd descTup)
|
||||
else return (layers ++ [nlayer], ndims)
|
||||
)
|
||||
([], V2 0 0)
|
||||
(V.fromList $ levelLayerPath desc)
|
||||
LevelMap
|
||||
<$> pure (V.fromList layers)
|
||||
<*> pure (levelWalkLayer desc)
|
||||
<*> pure (fmap fromIntegral dimensions)
|
||||
<*> pure tilemap
|
||||
<*> pure (V2 (fst $ levelStartPos desc) (snd $ levelStartPos desc))
|
||||
|
||||
readLayer
|
||||
:: (Word, FilePath) -- ^ index and path of the layer descriptor image
|
||||
-> V2 Float -- ^ size of Tilemap in pixels
|
||||
-> IO ((V.Vector Tile), V2 Int)
|
||||
readLayer (_, path) (V2 tx ty) = do
|
||||
img <- flipVertically <$> convertRGBA8 <$> either error id <$> readImage path
|
||||
let width = imageWidth img
|
||||
height = imageHeight img
|
||||
layer = V.foldl
|
||||
(\acc (py, px) -> case (pixelAt img px py) of
|
||||
(PixelRGBA8 r g b _) -> if r >= 253
|
||||
then
|
||||
acc `V.snoc` Tile
|
||||
(V2 (fromIntegral px) (fromIntegral py))
|
||||
( (V2
|
||||
((255 - fromIntegral g) * (32 / tx))
|
||||
(1 - (255 - fromIntegral b + 1) * (32 / ty))
|
||||
)
|
||||
, (V2
|
||||
((255 - fromIntegral g + 1) * (32 / tx))
|
||||
(1 - (255 - fromIntegral b) * (32 / ty))
|
||||
)
|
||||
)
|
||||
(case r of
|
||||
255 -> Solid
|
||||
254 -> Platform
|
||||
_ -> Decoration
|
||||
)
|
||||
else
|
||||
acc
|
||||
)
|
||||
V.empty
|
||||
(V.fromList ((,) <$> [0 .. height - 1] <*> [0 .. width - 1]))
|
||||
return (layer, V2 width height)
|
5
src/Physics.hs
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Physics
|
||||
( module P
|
||||
) where
|
||||
|
||||
import Physics.Classes as P
|
6
src/Physics/Classes.hs
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Physics.Classes
|
||||
( module PC
|
||||
) where
|
||||
|
||||
import Physics.Classes.Mass as PC
|
||||
import Physics.Classes.Collidible as PC
|
271
src/Physics/Classes/Collidible.hs
Normal file
|
@ -0,0 +1,271 @@
|
|||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Physics.Classes.Collidible where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import Linear
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
import Data.List (sortBy)
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Physics.Classes.Mass
|
||||
|
||||
data CollisionResult time direction
|
||||
= NoCollision
|
||||
| CollisionImminent
|
||||
{ collisionTime :: time
|
||||
, collisionDirection :: direction
|
||||
}
|
||||
| OverlapCollision
|
||||
{ collisionDepth :: direction
|
||||
}
|
||||
deriving (Show, Eq)
|
||||
|
||||
-- | Typeclass for implementing collision results on objects.
|
||||
class (Show c, Mass c) => Collidible c where
|
||||
|
||||
-- | returns the bottom left and top right corners relative to the objects
|
||||
-- positional vector of the axis aligned bounding box (AABB) serving here
|
||||
-- as collision boundaries.
|
||||
boundary
|
||||
:: c -- ^ Object
|
||||
-> ( V2 Double
|
||||
, V2 Double
|
||||
) -- ^ Bottom left and top right corner of AABB relative to position
|
||||
|
||||
collisionCheck
|
||||
:: (Collidible other)
|
||||
=> Double -- ^ Time step length
|
||||
-> c -- ^ First object
|
||||
-> other -- ^ second object
|
||||
-> CollisionResult Double (V2 Int) -- ^ Do the objects collide?
|
||||
collisionCheck dt m1 m2 =
|
||||
let d1@(V2 d1x d1y) = velocity m1
|
||||
d2@(V2 d2x d2y) = velocity m2
|
||||
p1@(V2 p1x p1y) = position m1
|
||||
p2@(V2 p2x p2y) = position m2
|
||||
(m1b1@(V2 m1b1x m1b1y), m1b2@(V2 m1b2x m1b2y)) = boundary m1
|
||||
(m2b1@(V2 m2b1x m2b1y), m2b2@(V2 m2b2x m2b2y)) = boundary m2
|
||||
(V2 pm1b1x pm1b1y, V2 pm1b2x pm1b2y) = (p1 +) <$> boundary m1
|
||||
(V2 pm2b1x pm2b1y, V2 pm2b2x pm2b2y) = (p2 +) <$> boundary m2
|
||||
m1p1@(V2 m1p1x m1p1y) = p1 + m1b1
|
||||
m1p2 = p1 + V2 m1b1x m1b2y
|
||||
m1p3@(V2 m1p3x m1p3y) = p1 + m1b2
|
||||
m1p4@(V2 m1p4x _) = p1 + V2 m1b2x m1b1y
|
||||
m2p1@(V2 m2p1x m2p1y) = p2 + m2b1
|
||||
m2p2 = p2 + V2 m2b1x m2b2y
|
||||
m2p3@(V2 m2p3x m2p3y) = p2 + m2b2
|
||||
m2p4 = p2 + V2 m2b2x m2b1y
|
||||
(V2 b1minx b1miny, V2 b1maxx b1maxy) =
|
||||
( V2
|
||||
((\(V2 x _) -> x) (if d1x < 0 then m1p1 + ((dt *) <$> d1) else m1p1))
|
||||
((\(V2 _ y) -> y) (if d1y < 0 then m1p1 + ((dt *) <$> d1) else m1p1))
|
||||
, V2
|
||||
((\(V2 x _) -> x) (if d1x < 0 then m1p3 else m1p3 + ((dt *) <$> d1)))
|
||||
((\(V2 _ y) -> y) (if d1y < 0 then m1p3 else m1p3 + ((dt *) <$> d1)))
|
||||
)
|
||||
(V2 b2minx b2miny, V2 b2maxx b2maxy) =
|
||||
( V2
|
||||
((\(V2 x _) -> x) (if d2x < 0 then m2p1 + ((dt *) <$> d2) else m2p1))
|
||||
((\(V2 _ y) -> y) (if d2y < 0 then m2p1 + ((dt *) <$> d2) else m2p1))
|
||||
, V2
|
||||
((\(V2 x _) -> x) (if d2x < 0 then m2p3 else m2p3 + ((dt *) <$> d2)))
|
||||
((\(V2 _ y) -> y) (if d2y < 0 then m2p3 else m2p3 + ((dt *) <$> d2)))
|
||||
)
|
||||
broadphaseOverlap =
|
||||
let in2 =
|
||||
(b1minx > b2minx && b1minx < b2maxx &&
|
||||
b1miny > b2miny && b1miny < b2maxy) ||
|
||||
(b1maxx > b2minx && b1maxx < b2maxx &&
|
||||
b1miny > b2miny && b1miny < b2maxy) ||
|
||||
(b1minx > b2minx && b1minx < b2maxx &&
|
||||
b1maxy > b2miny && b1maxy < b2maxy) ||
|
||||
(b1maxx > b2minx && b1maxx < b2maxx &&
|
||||
b1maxy > b2miny && b1maxy < b2maxy)
|
||||
in1 =
|
||||
(b2minx > b1minx && b2minx < b1maxx &&
|
||||
b2miny > b1miny && b2miny < b1maxy) ||
|
||||
(b2maxx > b1minx && b2maxx < b1maxx &&
|
||||
b2miny > b1miny && b2miny < b1maxy) ||
|
||||
(b2minx > b1minx && b2minx < b1maxx &&
|
||||
b2maxy > b1miny && b2maxy < b1maxy) ||
|
||||
(b2maxx > b1minx && b2maxx < b1maxx &&
|
||||
b2maxy > b1miny && b2maxy < b1maxy)
|
||||
in
|
||||
in2 || in1
|
||||
overlap =
|
||||
let in1 =
|
||||
(pm1b1x > pm2b1x && pm1b1x < pm2b2x &&
|
||||
pm1b1y > pm2b1y && pm1b1y < pm2b2y) ||
|
||||
(pm1b2x > pm2b1x && pm1b2x < pm2b2x &&
|
||||
pm1b1y > pm2b1y && pm1b1y < pm2b2y) ||
|
||||
(pm1b1x > pm2b1x && pm1b2x < pm2b2x &&
|
||||
pm1b2y > pm2b1y && pm1b2y < pm2b2y) ||
|
||||
(pm1b2x > pm2b1x && pm1b2x < pm2b2x &&
|
||||
pm1b2y > pm2b1y && pm1b2y < pm2b2y)
|
||||
in2 =
|
||||
(pm2b1x > pm1b1x && pm2b1x < pm1b2x &&
|
||||
pm2b1y > pm1b1y && pm2b1y < pm1b2y) ||
|
||||
(pm2b2x > pm1b1x && pm2b2x < pm1b2x &&
|
||||
pm2b1y > pm1b1y && pm2b1y < pm1b2y) ||
|
||||
(pm2b1x > pm1b1x && pm2b2x < pm1b2x &&
|
||||
pm2b2y > pm1b1y && pm2b2y < pm1b2y) ||
|
||||
(pm2b2x > pm1b1x && pm2b2x < pm1b2x &&
|
||||
pm2b2y > pm1b1y && pm2b2y < pm1b2y)
|
||||
in
|
||||
in2 || in1
|
||||
tx =
|
||||
let p1x = (\(V2 x _) -> x) (if d1x < 0 then m1p1 else m1p4)
|
||||
p2x = (\(V2 x _) -> x) (if d1x < 0 then m2p4 else m2p1)
|
||||
in
|
||||
if d2x - d1x == 0 then dt else (p1x - p2x) / (d2x - d1x)
|
||||
ty =
|
||||
let p1y = (\(V2 _ y) -> y) (if d1y < 0 then m1p1 else m1p2)
|
||||
p2y = (\(V2 _ y) -> y) (if d1y < 0 then m2p2 else m2p1)
|
||||
in
|
||||
if d2y - d1y == 0 then dt else (p1y - p2y) / (d2y - d1y)
|
||||
in
|
||||
if broadphaseOverlap
|
||||
then
|
||||
let coll xdir =
|
||||
let (p11, p12, p21, p22)
|
||||
| xdir =
|
||||
if d1x < 0
|
||||
then
|
||||
(m1p1, m1p2, m2p4, m2p3)
|
||||
else
|
||||
(m1p4, m1p3, m2p1, m2p2)
|
||||
| otherwise =
|
||||
if d1y < 0
|
||||
then
|
||||
(m1p1, m1p4, m2p2, m2p3)
|
||||
else
|
||||
(m1p2, m1p3, m2p1, m2p4)
|
||||
vselector (V2 x y) = if xdir then y else x
|
||||
tick = if xdir then tx else ty
|
||||
g1s = vselector $ p11 + ((tick *) <$> d1)
|
||||
g1e = vselector $ p12 + ((tick *) <$> d1)
|
||||
g2s = vselector $ p21 + ((tick *) <$> d2)
|
||||
g2e = vselector $ p22 + ((tick *) <$> d2)
|
||||
s11 = (g1s - g2s) / (g2e - g2s)
|
||||
s12 = (g1e - g2s) / (g2e - g2s)
|
||||
s21 = (g2s - g1s) / (g1e - g1s)
|
||||
s22 = (g2e - g1s) / (g1e - g1s)
|
||||
in
|
||||
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22]
|
||||
res = case (tx < dt, ty < dt, tx < ty, coll True, coll False) of
|
||||
(True, _, True, True, _) ->
|
||||
CollisionImminent tx (V2 (floor $ signum d1x) 0)
|
||||
(_, True, False, _, True) ->
|
||||
CollisionImminent ty (V2 0 (floor $ signum d1y))
|
||||
(True, _, False, True, False) ->
|
||||
CollisionImminent tx (V2 (floor $ signum d1x) 0)
|
||||
(_, True, True, False, True) ->
|
||||
CollisionImminent ty (V2 0 (floor $ signum d1y))
|
||||
(_, _, _, False, False) ->
|
||||
NoCollision
|
||||
(_, _, True, _, _) ->
|
||||
A.log A.Debug "CORNER CASE!" NoCollision
|
||||
(False, False, _, _, _) ->
|
||||
NoCollision
|
||||
x -> error $
|
||||
"Unhandled combination of collision check results: "
|
||||
<> fromString (show x)
|
||||
in
|
||||
case res of
|
||||
CollisionImminent _ _ ->
|
||||
res
|
||||
NoCollision ->
|
||||
if overlap
|
||||
then
|
||||
let xoverlap = floor (maximum (filter (0 >)
|
||||
[ pm2b2x - pm2b1x
|
||||
, pm2b1x - pm1b2x
|
||||
]))
|
||||
yoverlap = floor (maximum (filter (0 >)
|
||||
[ pm2b1y - pm1b2y
|
||||
, pm2b2y - pm1b1y
|
||||
]))
|
||||
in
|
||||
if xoverlap < yoverlap
|
||||
then
|
||||
if xoverlap < 0
|
||||
then OverlapCollision
|
||||
(V2 xoverlap 0)
|
||||
else
|
||||
NoCollision
|
||||
else
|
||||
if yoverlap < 0
|
||||
then OverlapCollision
|
||||
(V2 0 yoverlap)
|
||||
else NoCollision
|
||||
else NoCollision
|
||||
_ -> A.log
|
||||
A.Error
|
||||
"Premature overlap collision detection"
|
||||
NoCollision
|
||||
else
|
||||
NoCollision
|
||||
|
||||
-- | This Function is called for every collision on both colliding objects.
|
||||
collide
|
||||
:: (Collidible other)
|
||||
=> c -- ^ Original object
|
||||
-> [(other, CollisionResult Double (V2 Int))] -- ^ Collision partners and results
|
||||
-> Double -- ^ Timestep length
|
||||
-> c -- ^ Updated original object
|
||||
collide coll1 collrs = elasticCollision 0.9 coll1 (head collrs)
|
||||
|
||||
-- | Implementation of a dampened elastic collision used as default collision
|
||||
-- implementation of the collision reaction
|
||||
elasticCollision
|
||||
:: (Collidible c1, Collidible c2)
|
||||
=> Double
|
||||
-> c1
|
||||
-> (c2, CollisionResult Double (V2 Int))
|
||||
-> Double -- ^ Timestep length
|
||||
-> c1
|
||||
elasticCollision _ mo1 (_, NoCollision) _ = mo1
|
||||
elasticCollision damping mo1 (mo2, CollisionImminent ddt (V2 dirx diry)) dt =
|
||||
let v1@(V2 v1x v1y) = velocity mo1
|
||||
(V2 v2x v2y) = velocity mo2
|
||||
p1 = position mo1
|
||||
m1 = mass mo1
|
||||
m2 = mass mo2
|
||||
v1x' = 2 * (m1 * v1x + m2 * v2x) / (m1 + m2) - v1x
|
||||
v1y' = 2 * (m1 * v1y + m2 * v2y) / (m1 + m2) - v1y
|
||||
nvel = if m1 == recip 0
|
||||
then V2 0 0
|
||||
else (damping *) <$>
|
||||
if m2 == recip 0
|
||||
then
|
||||
if dirx /= 0
|
||||
then V2 (-v1x) v1y
|
||||
else V2 v1x (-v1y)
|
||||
else V2 v1x' v1y'
|
||||
in
|
||||
velocityUpdater
|
||||
mo1
|
||||
nvel
|
||||
elasticCollision damping mo1 (mo2, OverlapCollision depth) dt =
|
||||
let m1 = mass mo1
|
||||
m2 = mass mo2
|
||||
(V2 dx dy) = (/ dt) . fromIntegral <$> depth
|
||||
v1x' = 2 * (m1 * dx + m2 * (-dx)) / (m1 + m2) - dx
|
||||
v1y' = 2 * (m1 * dy + m2 * (-dy)) / (m1 + m2) - dy
|
||||
nvel = if m1 == recip 0
|
||||
then V2 0 0
|
||||
else (damping *) <$>
|
||||
if m2 == recip 0
|
||||
then
|
||||
if dx /= 0
|
||||
then V2 (-v1x') v1y'
|
||||
else V2 v1x' (-v1y')
|
||||
else
|
||||
V2 v1x' v1y'
|
||||
in
|
||||
velocityUpdater mo1 nvel
|
62
src/Physics/Classes/Mass.hs
Normal file
|
@ -0,0 +1,62 @@
|
|||
module Physics.Classes.Mass where
|
||||
|
||||
import Linear
|
||||
|
||||
-- | This typeclass is a centerpiece of the physics implementation and is used
|
||||
-- to implement the basic mass properties of a (very simplified) physical body.
|
||||
class Mass m where
|
||||
|
||||
-- | The mass of the mass object.
|
||||
mass :: m -> Double
|
||||
|
||||
-- | Retrieve the acceleration of the mass object.
|
||||
acceleration :: m -> V2 Double
|
||||
|
||||
-- | Overwrite the acceleration of the mass object.
|
||||
accelerationUpdater :: m -> (V2 Double -> m)
|
||||
|
||||
-- | retrieve the velocity of the mass object.
|
||||
velocity :: m -> V2 Double
|
||||
|
||||
-- | Overwrite the velocity of the mass object.
|
||||
velocityUpdater :: m -> (V2 Double -> m)
|
||||
|
||||
-- | Retrieve the position of the mass object.
|
||||
position :: m -> V2 Double
|
||||
|
||||
-- | Overwrite the position of the mass object.
|
||||
positionUpdater :: m -> (V2 Double -> m)
|
||||
|
||||
-- | The update function to let a mass react to gravitational pull.
|
||||
-- Apply all accelerations before calling the default implementation of
|
||||
-- this function, since it will add the gravitational pull to already
|
||||
-- existing accelerations.
|
||||
gravitate
|
||||
:: V2 Double -- ^ Vector of gravitational acceleration
|
||||
-> m -- ^ Original mass object
|
||||
-> m -- ^ Updated mass object
|
||||
gravitate g m =
|
||||
let acc = acceleration m + g
|
||||
in
|
||||
accelerationUpdater m acc
|
||||
|
||||
-- | Apply acceleration to mass object und thus change its velocity
|
||||
accelerate
|
||||
:: Double -- ^ Time step duration
|
||||
-> m -- ^ Original mass object
|
||||
-> m -- ^ Updated mass object
|
||||
accelerate dt m =
|
||||
let vel = velocity m + ((dt *) <$> acceleration m)
|
||||
in
|
||||
velocityUpdater m vel
|
||||
|
||||
-- | Apply velocity to mass object and thus change its position
|
||||
-- Changes in position smaller than around half a pixel per second are ignored.
|
||||
move
|
||||
:: Double -- ^ Time step duration
|
||||
-> m -- ^ Original mass object
|
||||
-> m -- ^ Updated mass object
|
||||
move dt m =
|
||||
let dpos = (dt *) <$> velocity m
|
||||
in
|
||||
positionUpdater m (position m + dpos)
|
23
src/Renderer.hs
Normal file
|
@ -0,0 +1,23 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Renderer where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import Foreign.Ptr
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics
|
||||
|
||||
draw :: VertexArray -> IndexBuffer -> Shader -> IO ()
|
||||
draw va ib sp = do
|
||||
bind sp
|
||||
bind va
|
||||
bind ib
|
||||
count <- atomically $ readTVar $ iBufCount ib
|
||||
GL.drawElements GL.Triangles count GL.UnsignedInt nullPtr
|
||||
|
||||
-- clear :: IO ()
|
||||
-- clear = GL.clear [GL.ColorBuffer]
|
94
src/Scenes/Test.hs
Normal file
|
@ -0,0 +1,94 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Scenes.Test
|
||||
( module Test
|
||||
) where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import Linear
|
||||
|
||||
import qualified Data.Vector.Storable as VS
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
import Data.Maybe (fromJust)
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Classes
|
||||
import Graphics
|
||||
import Renderer as R
|
||||
import Scenes.Test.Types as Test
|
||||
import Scenes.Test.Util as Test
|
||||
import Scenes.Test.Load as Test
|
||||
import Scenes.Test.Update as Test
|
||||
import Scenes.Test.EventHandler as Test
|
||||
|
||||
instance Scene Test where
|
||||
|
||||
initScene =
|
||||
Test
|
||||
<$> newEmptyTMVarIO
|
||||
<*> newEmptyTMVarIO
|
||||
<*> newTVarIO False
|
||||
<*> newTVarIO Nothing
|
||||
<*> newTVarIO V.empty
|
||||
<*> newTVarIO V.empty
|
||||
<*> newTVarIO V.empty
|
||||
<*> newTVarIO (PVM identity identity identity)
|
||||
<*> newTVarIO []
|
||||
|
||||
loadScene = load
|
||||
|
||||
isSceneLoaded = liftIO . readTVarIO . testLoaded
|
||||
|
||||
update = Test.update
|
||||
|
||||
onEvents = singleHandler
|
||||
|
||||
render level = liftIO $ do
|
||||
(GLAssets va vb ib sh _) <- atomically (readTMVar $ testGraphics level)
|
||||
(LevelMap layers _ _ tileMap _) <-
|
||||
atomically (readTMVar $ testMap level)
|
||||
|
||||
stageSet <- readTVarIO (testStageSet level)
|
||||
nonPlayerCast <- readTVarIO (testCast level)
|
||||
powerups <- V.map Cast <$> readTVarIO (testPowerups level)
|
||||
-- A.logIO A.Debug (fromString $ V.foldl (\acc (Cast p) -> acc ++ show p ++ " ") "" powerups)
|
||||
pituicat <- readTVarIO (testPlayer level)
|
||||
let cast = Cast (fromJust pituicat) `V.cons` powerups V.++
|
||||
nonPlayerCast
|
||||
(V2 px py) = realToFrac <$> pcPos (fromJust pituicat)
|
||||
|
||||
atomically $ modifyTVar (testMatrices level) $ \pvm ->
|
||||
pvm
|
||||
{ pvmV = mkTransformationMat
|
||||
identity
|
||||
(V3 (400 - px) (300 - py) 0)
|
||||
}
|
||||
|
||||
(PVM p v m) <- readTVarIO (testMatrices level)
|
||||
|
||||
let (indices, vertices) = populate
|
||||
layers
|
||||
stageSet
|
||||
cast
|
||||
|
||||
bind va
|
||||
bind vb
|
||||
bind ib
|
||||
bind sh
|
||||
|
||||
setUniform sh "u_mvp" (p !*! v !*! m)
|
||||
write vb 0 vertices
|
||||
|
||||
write ib 0 (VS.map fromIntegral indices)
|
||||
|
||||
bind (tileMapTexture tileMap)
|
||||
V.mapM_(\(StageSet prop) -> bindPropTexture prop) stageSet
|
||||
V.mapM_(\(Cast c) -> bindPropTexture c) cast
|
||||
R.draw va ib sh
|
44
src/Scenes/Test/EventHandler.hs
Normal file
|
@ -0,0 +1,44 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Scenes.Test.EventHandler where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Linear
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Scenes.Test.Types
|
||||
|
||||
singleHandler
|
||||
:: Test
|
||||
-> TranslatorMessage
|
||||
-> Affection ()
|
||||
singleHandler level event = do
|
||||
let multiplier = if tmKeyMotion event == SDL.Pressed then 1 else 0
|
||||
changeDirection cat state =
|
||||
Just cat
|
||||
{ pcMoveState = if multiplier > 0 then Just state else Nothing
|
||||
}
|
||||
liftIO $ atomically $ modifyTVar (testPlayer level) (\(Just pituicat) ->
|
||||
A.log Debug ("Grounded: " <> fromString (show $ pcGrounded pituicat)) $
|
||||
case tmAction event of
|
||||
Jump -> if multiplier > 0 && pcGrounded pituicat
|
||||
then A.log Debug "jumping"
|
||||
(Just pituicat
|
||||
{ pcVel = pcVel pituicat + V2 0 300
|
||||
, pcGrounded = False
|
||||
}
|
||||
)
|
||||
else
|
||||
Just pituicat
|
||||
MoveRight -> changeDirection pituicat MoveRight
|
||||
MoveLeft -> changeDirection pituicat MoveLeft
|
||||
_ -> Just pituicat
|
||||
)
|
127
src/Scenes/Test/Load.hs
Normal file
|
@ -0,0 +1,127 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Scenes.Test.Load where
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.Vector.Storable as VS
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import Control.Monad (void)
|
||||
|
||||
import Linear
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Classes
|
||||
import Graphics
|
||||
import Map
|
||||
import Scenes.Test.Types
|
||||
import Scenes.Test.Util
|
||||
|
||||
load
|
||||
:: Test
|
||||
-> TMVar Progress
|
||||
-> IO ()
|
||||
load level progress = do
|
||||
atomically $ do
|
||||
void $ takeTMVar progress
|
||||
putTMVar progress (0, "Loading test level...")
|
||||
loadedMap <- constructMap testLevelDesc 0
|
||||
atomically $ putTMVar (testMap level) loadedMap
|
||||
void $ atomically $ do
|
||||
void $ takeTMVar progress
|
||||
putTMVar progress (0.5, "Loaded test level map!")
|
||||
void $ atomically $ swapTVar (testLoaded level) True
|
||||
|
||||
vertexArray <- newVertexArray
|
||||
|
||||
bind vertexArray
|
||||
|
||||
vertexBuffer <- newVertexBuffer 1024
|
||||
|
||||
bind vertexBuffer
|
||||
|
||||
--let vertices = VS.fromList (createQuad (V2 (400 - 16) (300 - 16)) 0)
|
||||
|
||||
--write vertexBuffer 0 vertices
|
||||
|
||||
indexBuffer <- newIndexBuffer 1024
|
||||
|
||||
bind indexBuffer
|
||||
|
||||
-- let indices = VS.fromList [0, 1, 2, 2, 3, 0]
|
||||
|
||||
-- write indexBuffer 0 indices
|
||||
|
||||
addBuffer (undefined :: Vertex) vertexBuffer
|
||||
|
||||
(_, tex) <- newTexture "res/pituicat/pituicat.png" 1
|
||||
bind tex
|
||||
|
||||
shader <- newShader
|
||||
[ ShaderSource GL.VertexShader "./res/shaders/vert.shader"
|
||||
, ShaderSource GL.FragmentShader "./res/shaders/frag.shader"
|
||||
]
|
||||
|
||||
let projection = ortho 0 800 0 600 (-1) 1 :: M44 GL.GLfloat
|
||||
view = mkTransformationMat
|
||||
(identity :: M33 GL.GLfloat)
|
||||
(V3 (400 - sx) (300 - sy) 0)
|
||||
model = mkTransformationMat (identity :: M33 GL.GLfloat) (V3 0 0 0)
|
||||
startpos@(V2 sx sy) = V2 100 1948
|
||||
pituicat = Pituicat
|
||||
(realToFrac <$> startpos)
|
||||
(V2 0 0)
|
||||
(V2 0 0)
|
||||
(V2 0 0)
|
||||
(V2 0 0)
|
||||
100
|
||||
tex
|
||||
False
|
||||
Nothing
|
||||
ViewRight
|
||||
[]
|
||||
False
|
||||
oil = PowerUp
|
||||
(realToFrac <$> (startpos + V2 200 0))
|
||||
(V2 0 0)
|
||||
(V2 0 0)
|
||||
5000
|
||||
tex
|
||||
(EffectHolder 5 SpeedUp)
|
||||
|
||||
|
||||
bind shader
|
||||
setUniform shader "u_mvp" (projection !*! view !*! model)
|
||||
setUniformList
|
||||
shader
|
||||
"u_textures"
|
||||
(map
|
||||
textureSlot
|
||||
[ (tileMapTexture $ mapTileMap loadedMap)
|
||||
, tex
|
||||
]
|
||||
)
|
||||
|
||||
unbind vertexArray
|
||||
unbind vertexBuffer
|
||||
unbind indexBuffer
|
||||
unbind tex
|
||||
unbind shader
|
||||
|
||||
atomically $ do
|
||||
putTMVar (testGraphics level)
|
||||
(GLAssets vertexArray vertexBuffer indexBuffer shader [tex])
|
||||
writeTVar (testPlayer level) (Just pituicat)
|
||||
writeTVar (testCast level)
|
||||
(V.fromList [Cast (oil {puPos = puPos oil + V2 200 0})])
|
||||
writeTVar (testPowerups level) (V.fromList [oil])
|
||||
writeTVar (testLoaded level) True
|
||||
writeTVar (testMatrices level) (PVM projection view model)
|
||||
|
||||
void $ atomically $ do
|
||||
void $ takeTMVar progress
|
||||
putTMVar progress (1, "Loaded graphics!")
|
40
src/Scenes/Test/Types.hs
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Scenes.Test.Types where
|
||||
|
||||
import Affection
|
||||
|
||||
import Linear
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Graphics
|
||||
|
||||
data Test = Test
|
||||
{ testMap :: TMVar LevelMap
|
||||
, testGraphics :: TMVar GLAssets
|
||||
, testLoaded :: TVar Bool
|
||||
, testPlayer :: TVar (Maybe Pituicat)
|
||||
, testStageSet :: TVar (V.Vector StageSet)
|
||||
, testCast :: TVar (V.Vector Cast)
|
||||
, testPowerups :: TVar (V.Vector PowerUp)
|
||||
, testMatrices :: TVar PVM
|
||||
, testClean :: TVar [UUID]
|
||||
}
|
||||
|
||||
data GLAssets = GLAssets
|
||||
{ glVA :: VertexArray
|
||||
, glVB :: VertexBuffer
|
||||
, glIB :: IndexBuffer
|
||||
, glSP :: Shader
|
||||
, glTx :: [Texture]
|
||||
}
|
||||
|
||||
data PVM = PVM
|
||||
{ pvmP :: M44 Float
|
||||
, pvmV :: M44 Float
|
||||
, pvmM :: M44 Float
|
||||
}
|
268
src/Scenes/Test/Update.hs
Normal file
|
@ -0,0 +1,268 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE AllowAmbiguousTypes #-}
|
||||
module Scenes.Test.Update where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
import Data.List (sortOn)
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Data.Maybe
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Scenes.Test.Types
|
||||
import Classes
|
||||
import Types
|
||||
import Physics
|
||||
|
||||
update
|
||||
:: Test
|
||||
-> Double
|
||||
-> Affection ()
|
||||
update level dt = liftIO $ do
|
||||
logIO Debug ("FPS: " <> fromString (show $ 1 / dt))
|
||||
|
||||
atomically $ do
|
||||
lmap <- readTMVar (testMap level)
|
||||
cast <-
|
||||
V.map (\(Cast c) -> Cast $ perform dt c) <$> readTVar (testCast level)
|
||||
powerups <- V.filter ((0 <) . puTTL) .
|
||||
V.map (perform dt) <$>
|
||||
readTVar (testPowerups level)
|
||||
cat <- perform dt . fromJust <$> readTVar (testPlayer level)
|
||||
let layer = mapLayers lmap V.! fromIntegral (mapWalkLayer lmap)
|
||||
tangibles =
|
||||
V.map TTile layer V.++
|
||||
V.map TCast cast V.++
|
||||
V.map TPowerUp powerups `V.snoc`
|
||||
TPlayer cat
|
||||
|
||||
|
||||
indexedTangibles = V.zip
|
||||
(V.fromList [0 .. (V.length tangibles - 1)])
|
||||
tangibles
|
||||
collidedTangibles =
|
||||
let collisionPartners =
|
||||
V.foldl
|
||||
(\iacc (index, tangible1) ->
|
||||
let partners =
|
||||
V.foldl
|
||||
(\jacc (qInd, tangible2) ->
|
||||
let res = collisionCheck dt tangible1 tangible2
|
||||
in
|
||||
case res of
|
||||
c@(CollisionImminent _ _) ->
|
||||
if qInd /= index
|
||||
then jacc `V.snoc` (qInd, c)
|
||||
else jacc
|
||||
_ -> jacc
|
||||
)
|
||||
V.empty
|
||||
indexedTangibles
|
||||
in
|
||||
if V.null partners
|
||||
then iacc
|
||||
else iacc `V.snoc`
|
||||
( index
|
||||
, sortOn (collisionTime . snd) (V.toList partners)
|
||||
)
|
||||
)
|
||||
V.empty
|
||||
indexedTangibles
|
||||
updater (aindex, partners) =
|
||||
let aobject = (snd $ indexedTangibles V.! aindex)
|
||||
digest = map
|
||||
(\(pindex, presults) ->
|
||||
( snd $ indexedTangibles V.! pindex
|
||||
, presults
|
||||
)
|
||||
)
|
||||
partners
|
||||
res =
|
||||
(\d ->
|
||||
let inter =
|
||||
collide
|
||||
aobject
|
||||
d
|
||||
dt
|
||||
in
|
||||
inter
|
||||
)
|
||||
digest
|
||||
in
|
||||
(aindex, res)
|
||||
in
|
||||
tangibles `V.update`
|
||||
V.map
|
||||
updater
|
||||
(A.log
|
||||
A.Debug
|
||||
("Collision partners: " <>
|
||||
fromString (show collisionPartners))
|
||||
collisionPartners
|
||||
)
|
||||
(newCast, newPowerups, mnewCat@(Just _)) = V.foldl
|
||||
(\acc@(castAcc, pAcc, _) input ->
|
||||
case input of
|
||||
TCast c ->
|
||||
(castAcc `V.snoc` move dt c, pAcc, mnewCat)
|
||||
TPowerUp p ->
|
||||
(castAcc, pAcc `V.snoc` move dt p, mnewCat)
|
||||
TPlayer ncat ->
|
||||
(castAcc, pAcc, Just (move dt ncat))
|
||||
TTile _ ->
|
||||
acc
|
||||
)
|
||||
(V.empty, V.empty, Nothing)
|
||||
collidedTangibles
|
||||
writeTVar (testCast level) newCast
|
||||
writeTVar (testPowerups level) newPowerups
|
||||
writeTVar (testPlayer level) mnewCat
|
||||
|
||||
-- oldCast <- V.map (\(Cast c) -> Cast $ perform dt c) <$>
|
||||
-- readTVar (testCast level)
|
||||
-- oldCat <- perform dt <$> fromJust <$> readTVar (testPlayer level)
|
||||
-- modifyTVar (testCast level) $ \cast ->
|
||||
-- let playedCast =
|
||||
-- V.map
|
||||
-- (\(Cast c) -> Cast (perform dt c))
|
||||
-- cast
|
||||
-- collidedCast =
|
||||
-- V.map
|
||||
-- (\(Cast c1) ->
|
||||
-- let partners = V.foldl
|
||||
-- (\acc@(Cast _, ires) (Cast c2) ->
|
||||
-- let res = collisionCheck dt c1 c2
|
||||
-- in
|
||||
-- if res /= NoCollision &&
|
||||
-- collisionTime res < collisionTime ires
|
||||
-- then (Cast c2, res)
|
||||
-- else acc
|
||||
-- )
|
||||
-- (Cast c1, NoCollision)
|
||||
-- playedCast
|
||||
-- in
|
||||
-- if null partners
|
||||
-- then Cast c1
|
||||
-- else
|
||||
-- uncurry
|
||||
-- (\(Cast c2) result -> Cast $ collide c1 c2 result)
|
||||
-- partners
|
||||
-- )
|
||||
-- playedCast
|
||||
-- wallCast (Cast c) =
|
||||
-- Cast $ performWorldCollision c layer dt
|
||||
-- walledCast =
|
||||
-- V.map wallCast collidedCast
|
||||
-- cattedCast = V.map
|
||||
-- (\(Cast c) ->
|
||||
-- Cast $ collide c oldCat $ collisionCheck dt c oldCat
|
||||
-- )
|
||||
-- walledCast
|
||||
-- in
|
||||
-- V.map
|
||||
-- (\(Cast c) -> Cast $
|
||||
-- move dt c
|
||||
-- )
|
||||
-- walledCast
|
||||
-- releasedEffects <- stateTVar (testPowerups level) $ \pus ->
|
||||
-- let living = V.foldl
|
||||
-- (\acc pu ->
|
||||
-- let npu = perform dt pu
|
||||
-- in
|
||||
-- if puTTL npu > 0
|
||||
-- then npu `V.cons` acc
|
||||
-- else acc
|
||||
-- )
|
||||
-- V.empty
|
||||
-- pus
|
||||
-- indexCollected = V.filter ((/= NoCollision) . snd) $
|
||||
-- V.zip (V.fromList [0..length living])
|
||||
-- (V.map
|
||||
-- (collisionCheck dt oldCat)
|
||||
-- living
|
||||
-- )
|
||||
-- collected = V.foldl
|
||||
-- (\acc (ind, _) ->
|
||||
-- (living V.! ind) `V.cons` acc
|
||||
-- )
|
||||
-- V.empty
|
||||
-- indexCollected
|
||||
-- differ = V.foldl
|
||||
-- (\acc life -> if life `V.elem` collected
|
||||
-- then acc
|
||||
-- else life `V.cons` acc
|
||||
-- )
|
||||
-- V.empty
|
||||
-- living
|
||||
-- fin = V.map
|
||||
-- (\pu -> move dt $ performWorldCollision pu layer dt)
|
||||
-- differ
|
||||
-- in
|
||||
-- (collected, fin)
|
||||
-- modifyTVar
|
||||
-- (testPlayer level) $ \(Just pituicat) ->
|
||||
-- let playedCat = perform dt pituicat
|
||||
-- castCat =
|
||||
-- let allPartners = V.zip (V.fromList [0..V.length oldCast])
|
||||
-- (V.map
|
||||
-- (\(Cast c) -> collisionCheck dt playedCat c)
|
||||
-- oldCast
|
||||
-- )
|
||||
-- filtered = (V.filter ((/= NoCollision) . snd) allPartners)
|
||||
-- partner = V.minimumBy
|
||||
-- (\(_, e) (_, f) -> collisionTime e `compare` collisionTime f)
|
||||
-- filtered
|
||||
-- in
|
||||
-- if V.null filtered
|
||||
-- then
|
||||
-- playedCat
|
||||
-- else
|
||||
-- uncurry
|
||||
-- (\(Cast c) cr -> collide playedCat c cr)
|
||||
-- (oldCast V.! fst partner, snd partner)
|
||||
-- walledCat = performWorldCollision castCat layer dt
|
||||
-- affectedCat = walledCat
|
||||
-- { pcEffects = pcEffects walledCat ++
|
||||
-- map puEffect (V.toList releasedEffects)
|
||||
-- }
|
||||
-- in Just $ move dt affectedCat
|
||||
|
||||
-- performWorldCollision
|
||||
-- :: (Collidible c)
|
||||
-- => c -- ^ Cast member to check
|
||||
-- -> Layer -- ^ The walk layer of the level
|
||||
-- -> Double -- ^ Tick length
|
||||
-- -> c -- ^ Updated cast member
|
||||
-- performWorldCollision c layer dt =
|
||||
-- let partner = V.foldl
|
||||
-- (\acc@(part, cr) tile ->
|
||||
-- let res = collisionCheck dt c tile
|
||||
-- ret = if cr == NoCollision && res == NoCollision
|
||||
-- then
|
||||
-- acc
|
||||
-- else
|
||||
-- if cr == NoCollision && res /= NoCollision
|
||||
-- then (tile, res)
|
||||
-- else
|
||||
-- if cr /= NoCollision && res == NoCollision
|
||||
-- then
|
||||
-- acc
|
||||
-- else
|
||||
-- if collisionTime cr < collisionTime res
|
||||
-- then acc
|
||||
-- else (tile, res)
|
||||
-- in
|
||||
-- ret
|
||||
-- )
|
||||
-- (V.head layer, collisionCheck dt c $ V.head layer)
|
||||
-- layer
|
||||
-- in
|
||||
-- (uncurry (collide c) partner) dt
|
111
src/Scenes/Test/Util.hs
Normal file
|
@ -0,0 +1,111 @@
|
|||
{-#LANGUAGE OverloadedStrings #-}
|
||||
module Scenes.Test.Util where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import Linear
|
||||
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.Vector.Storable as VS
|
||||
|
||||
import Control.Arrow ((***))
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Classes
|
||||
import Types
|
||||
import Graphics
|
||||
|
||||
testLevelDesc :: LevelDescriptor
|
||||
testLevelDesc = LevelDescriptor
|
||||
[ (0, "res/maps/00_test/00_test.bmp")
|
||||
]
|
||||
0
|
||||
"res/tiles/00_test/00_test.png"
|
||||
(3, 3)
|
||||
|
||||
createQuad :: V2 GL.GLfloat -> Int -> [Vertex]
|
||||
createQuad (V2 x y) index =
|
||||
[ newVertex
|
||||
(V3 x y 0)
|
||||
(V4 0 0 0 1)
|
||||
(V2 0 (1 - (50 / 1024)))
|
||||
(fromIntegral index)
|
||||
, newVertex
|
||||
(V3 (x + 32) y 0)
|
||||
(V4 0 0 0 1)
|
||||
(V2 (50 / 1024) (1 - (50/1024)))
|
||||
(fromIntegral index)
|
||||
, newVertex
|
||||
(V3 (x + 32) (y + 32) 0)
|
||||
(V4 0 0 0 1)
|
||||
(V2 (50 / 1024) 1)
|
||||
(fromIntegral index)
|
||||
, newVertex
|
||||
(V3 x (y + 32) 0)
|
||||
(V4 0 0 0 1)
|
||||
(V2 0 1)
|
||||
(fromIntegral index)
|
||||
]
|
||||
|
||||
populate
|
||||
:: V.Vector Layer
|
||||
-> V.Vector StageSet
|
||||
-> V.Vector Cast
|
||||
-> (VS.Vector Word, VS.Vector Vertex)
|
||||
populate layers props actors =
|
||||
(VS.convert *** VS.convert) $ foldl
|
||||
(\(is, vs) (num, l) ->
|
||||
let propsHere = V.filter (\(StageSet s) -> residentLayer s == num) props
|
||||
actorsHere = V.filter (\(Cast c) -> residentLayer c == num) actors
|
||||
(pisRaw, pvs) = V.foldl
|
||||
(\(ais, avs) (StageSet s) ->
|
||||
let (nis, nvs) = toVertices s
|
||||
in
|
||||
( ais V.++
|
||||
(V.map
|
||||
(+ (if null ais then 0 else V.maximum ais + 1))
|
||||
nis
|
||||
)
|
||||
, avs V.++ nvs)
|
||||
)
|
||||
(V.empty, V.empty)
|
||||
propsHere
|
||||
(cisRaw, cvs) = V.foldl
|
||||
(\(ais, avs) (Cast c) ->
|
||||
let (nis, nvs) = toVertices c
|
||||
in
|
||||
( ais V.++
|
||||
(V.map
|
||||
(+ (if null ais then 0 else V.maximum ais + 1))
|
||||
nis
|
||||
)
|
||||
, avs V.++ nvs)
|
||||
)
|
||||
(V.empty, V.empty)
|
||||
actorsHere
|
||||
(lisRaw, lvs) = toVertices l
|
||||
lis = V.map
|
||||
(+ if null is then 0 else V.maximum is + 1)
|
||||
lisRaw
|
||||
pis = V.map
|
||||
(+
|
||||
if null (is V.++ lis)
|
||||
then 0
|
||||
else V.maximum (is V.++ lis) + 1)
|
||||
pisRaw
|
||||
cis = V.map
|
||||
(+
|
||||
if null (is V.++ lis V.++ pis)
|
||||
then 0
|
||||
else V.maximum (is V.++ lis V.++ pis) + 1)
|
||||
cisRaw
|
||||
in
|
||||
( is V.++ lis V.++ pis V.++ cis
|
||||
, vs V.++ lvs V.++ pvs V.++ cvs
|
||||
)
|
||||
)
|
||||
(V.empty, V.empty)
|
||||
(V.zip (V.fromList [0 ..]) layers)
|
60
src/StateMachine.hs
Normal file
|
@ -0,0 +1,60 @@
|
|||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module StateMachine where
|
||||
|
||||
import Affection
|
||||
|
||||
import Data.Maybe (isNothing)
|
||||
|
||||
import Control.Monad (void, when)
|
||||
|
||||
import Control.Concurrent.STM
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types
|
||||
import Classes
|
||||
|
||||
-- import State.Loading
|
||||
-- import State.MainGame
|
||||
|
||||
instance StateMachine GameData State where
|
||||
|
||||
smLoad Loading gd = do
|
||||
mThreadId <- liftIO $ atomically $ readTVar (gameLoadThread gd)
|
||||
when (isNothing mThreadId) $ do
|
||||
(Stage scene) <- liftIO $ atomically $ readTMVar $ gameScene gd
|
||||
-- ctx <- liftIO $ atomically $ fromJust <$>
|
||||
-- (readTVar $ gameLoadContext gd)
|
||||
ad <- get -- get inner state of engine
|
||||
-- let win = ((\(_, y, _) -> y) $ head $ drawWindows ad)
|
||||
liftIO $
|
||||
loadScene scene (gameStateLoadProgress gd)
|
||||
-- SDL.glMakeCurrent win (snd $ head $ glContext ad)
|
||||
-- liftIO $ atomically $ writeTVar (gameLoadThread gd) (Just tid)
|
||||
|
||||
smLoad x _ = error ("State load not yet implemented: " <> show x)
|
||||
|
||||
|
||||
smUpdate Loading gd dt = do
|
||||
(Stage scene) <- liftIO $ atomically $ readTMVar $ gameScene gd
|
||||
Classes.update scene dt
|
||||
|
||||
smUpdate x _ _ = error ("State update not yet implemented: " <> show x)
|
||||
|
||||
|
||||
smDraw Loading gd = do
|
||||
(Stage scene) <- liftIO $ atomically $ readTMVar $ gameScene gd
|
||||
render scene
|
||||
|
||||
smDraw x _ = error ("State draw not yet implemented: " <> show x)
|
||||
|
||||
|
||||
smEvent _ gd evs = do
|
||||
let Subsystems w m k _ = gameSubsystems gd
|
||||
void . (consumeSDLEvents k) =<<
|
||||
consumeSDLEvents m =<<
|
||||
consumeSDLEvents w evs
|
||||
|
||||
|
||||
smClean x _ = error ("State clean not yet implemented: " <> show x)
|
13
src/Types.hs
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Types
|
||||
( module T
|
||||
) where
|
||||
|
||||
import Types.Application as T
|
||||
import Types.Subsystems as T
|
||||
import Types.Map as T
|
||||
import Types.Cast as T
|
||||
import Types.StageSet as T
|
||||
import Types.Player as T
|
||||
import Types.Util as T
|
||||
import Types.PowerUp as T
|
||||
import Types.Tangible as T
|
40
src/Types/Application.hs
Normal file
|
@ -0,0 +1,40 @@
|
|||
{-# LANGUAGE ExistentialQuantification #-}
|
||||
module Types.Application where
|
||||
|
||||
import Affection
|
||||
|
||||
import qualified SDL
|
||||
|
||||
import Control.Concurrent (ThreadId)
|
||||
import Control.Concurrent.STM
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Types.Subsystems
|
||||
import Types.Util
|
||||
|
||||
import Classes.Scene
|
||||
|
||||
data GameData = GameData
|
||||
{ gameScene :: TMVar Stage
|
||||
, gameState :: TVar State
|
||||
, gameStateLoadProgress :: TMVar Progress
|
||||
, gameSubsystems :: Subsystems
|
||||
, gameActionTranslation :: TVar ActionTranslation
|
||||
, gameRunning :: TVar Bool
|
||||
, gameLoadThread :: TVar (Maybe ThreadId)
|
||||
, gameLoadContext :: TVar (Maybe SDL.GLContext)
|
||||
, gameGeneralClean :: TVar [UUID]
|
||||
, gameSceneClean :: TVar (Maybe UUID)
|
||||
}
|
||||
|
||||
-- Existential type wrapper to make all Scenes implementing Scene
|
||||
-- homogenous.
|
||||
-- See more at https://wiki.haskell.org/Existential_type#Dynamic_dispatch_mechanism_of_OOP
|
||||
data Stage = forall a. Scene a => Stage a
|
||||
|
||||
data State
|
||||
= Loading
|
||||
| Running
|
||||
| Pausing
|
||||
deriving (Show)
|
37
src/Types/Cast.hs
Normal file
|
@ -0,0 +1,37 @@
|
|||
{-# LANGUAGE ExistentialQuantification #-}
|
||||
module Types.Cast where
|
||||
|
||||
-- internale imports
|
||||
|
||||
import Classes.Actor
|
||||
import Physics.Classes
|
||||
|
||||
data Cast = forall a. Actor a => Cast a
|
||||
|
||||
instance Show Cast where
|
||||
|
||||
show (Cast a) = show a
|
||||
|
||||
instance Mass Cast where
|
||||
|
||||
mass (Cast a) = mass a
|
||||
|
||||
acceleration (Cast a) = acceleration a
|
||||
|
||||
accelerationUpdater (Cast a) = Cast . accelerationUpdater a
|
||||
|
||||
velocity (Cast a) = velocity a
|
||||
|
||||
velocityUpdater (Cast a) = Cast . velocityUpdater a
|
||||
|
||||
position (Cast a) = position a
|
||||
|
||||
positionUpdater (Cast a) = Cast . positionUpdater a
|
||||
|
||||
instance Collidible Cast where
|
||||
|
||||
boundary (Cast c) = boundary c
|
||||
|
||||
collisionCheck dt (Cast c1) c2 = collisionCheck dt c1 c2
|
||||
|
||||
collide (Cast c1) res dt = Cast $ collide c1 res dt
|
124
src/Types/Map.hs
Normal file
|
@ -0,0 +1,124 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
module Types.Map where
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Linear
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Graphics.Types.Texture
|
||||
import Graphics.Types.VertexBuffer
|
||||
import Graphics.Classes.Drawable
|
||||
import Physics.Classes
|
||||
|
||||
data LevelMap = LevelMap
|
||||
{ mapLayers :: V.Vector Layer -- ^ Layer stack
|
||||
, mapWalkLayer :: Word -- ^ Collision layer index in stack
|
||||
, mapDimensions :: V2 Word -- ^ Dimension of map in tiles
|
||||
, mapTileMap :: TileMap -- ^ The tile map
|
||||
, mapStartPos :: V2 Word -- ^ Player start position
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
type Layer = V.Vector Tile
|
||||
|
||||
instance Drawable Layer where
|
||||
|
||||
-- type VertexList Layer = V.Vector
|
||||
|
||||
toVertices vt = V.foldl
|
||||
(\(acci, accv) (multi, a) ->
|
||||
let (ris, vs) = toVertices a
|
||||
is = V.map (multi * 4 +) ris
|
||||
in (acci V.++ is, accv V.++ vs)
|
||||
)
|
||||
(V.empty, V.empty)
|
||||
(V.zip (V.fromList [0 ..]) vt)
|
||||
|
||||
data Tile = Tile
|
||||
{ tilePosition :: V2 Word -- ^
|
||||
, tileOffset :: (V2 Float, V2 Float) -- ^ Graphics offset on 'TileMap'
|
||||
, tileType :: TileType -- ^ Type of tile
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Drawable Tile where
|
||||
|
||||
-- type VertexList Tile = V.Vector
|
||||
|
||||
toVertices (Tile (V2 x y) (V2 u1 v1, V2 u2 v2) _) =
|
||||
( V.fromList [ 0, 1, 2, 2, 3, 0 ]
|
||||
, V.fromList
|
||||
[ newVertex
|
||||
(V3 (fromIntegral x * 32) (fromIntegral y * 32) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 u1 v1)
|
||||
0
|
||||
, newVertex
|
||||
(V3 (fromIntegral (x + 1) * 32) (fromIntegral y * 32) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 u2 v1)
|
||||
0
|
||||
, newVertex
|
||||
(V3 (fromIntegral (x + 1) * 32) (fromIntegral (y + 1) * 32) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 u2 v2)
|
||||
0
|
||||
, newVertex
|
||||
(V3 (fromIntegral x * 32) (fromIntegral (y + 1) * 32) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 u1 v2)
|
||||
0
|
||||
]
|
||||
)
|
||||
|
||||
instance Mass Tile where
|
||||
|
||||
mass _ = recip 0
|
||||
|
||||
acceleration _ = V2 0 0
|
||||
|
||||
accelerationUpdater t = const t
|
||||
|
||||
velocity _ = V2 0 0
|
||||
|
||||
velocityUpdater t = const t
|
||||
|
||||
position t =
|
||||
let (V2 x y) = fromIntegral <$> tilePosition t
|
||||
in
|
||||
V2 (x * 32 + 16) (y * 32 + 16)
|
||||
|
||||
positionUpdater t = const t
|
||||
|
||||
instance Collidible Tile where
|
||||
|
||||
boundary _ =
|
||||
( V2 (-16) (-16)
|
||||
, V2 16 16
|
||||
)
|
||||
|
||||
data TileType
|
||||
= Solid
|
||||
| Platform
|
||||
| Decoration
|
||||
deriving (Enum, Ord, Eq, Show)
|
||||
|
||||
data TileMap = TileMap
|
||||
{ tileMapDimensions :: V2 Word -- ^ Dimensions of tile map image in pixels
|
||||
, tileMapTexture :: Texture -- ^ Texture object on GPU
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
data LevelDescriptor = LevelDescriptor
|
||||
{ levelLayerPath :: [(Word, FilePath)] -- ^ Indexed paths to the layers
|
||||
, levelWalkLayer :: Word -- ^ Index of walk layer
|
||||
, levelTileMap :: FilePath -- ^ Filepath to tile map
|
||||
, levelStartPos :: (Word, Word) -- ^ Player start position
|
||||
-- , levelCollectibles :: [(V2 Word, ())] -- ^ TODO; Collectibles and their tile coords
|
||||
-- , levelEnemies :: [(V2 Word, ())] -- ^ TODO: Enemies and their tile coords
|
||||
-- , levelInteractables :: [(V2 Word, ())] -- ^ TODO: Interactables and their coords
|
||||
}
|
||||
deriving (Eq, Show)
|
220
src/Types/Player.hs
Normal file
|
@ -0,0 +1,220 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Types.Player where
|
||||
|
||||
import Affection as A
|
||||
|
||||
import Linear
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Data.String (fromString)
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Util
|
||||
|
||||
import Classes.Prop
|
||||
import Classes.Actor
|
||||
import Classes.Collectable
|
||||
|
||||
import Graphics.Classes.Drawable
|
||||
import Graphics.Classes.Bindable
|
||||
import Graphics.Types.VertexBuffer
|
||||
import Graphics.Types.Texture
|
||||
|
||||
import Physics.Classes
|
||||
|
||||
import Types.Subsystems
|
||||
|
||||
catMoveVelocity :: Double
|
||||
catMoveVelocity = 100
|
||||
|
||||
data Pituicat = Pituicat
|
||||
{ pcPos :: V2 Double
|
||||
, pcVel :: V2 Double
|
||||
, pcMoveVel :: V2 Double
|
||||
, pcTMoveVel :: V2 Double
|
||||
, pcAcc :: V2 Double
|
||||
, pcHealth :: Int
|
||||
, pcTexture :: Texture
|
||||
, pcGrounded :: Bool
|
||||
, pcMoveState :: Maybe Action
|
||||
, pcViewDirection :: ViewDirection
|
||||
, pcEffects :: [EffectHolder]
|
||||
, pcXColl :: Bool
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
data ViewDirection = ViewLeft | ViewRight
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Drawable Pituicat where
|
||||
|
||||
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _ vd _ _) =
|
||||
( V.fromList [0, 1, 2, 2, 3, 0]
|
||||
, V.fromList
|
||||
[ newVertex
|
||||
(V3 (realToFrac x - 25) (realToFrac y - 25) 0)
|
||||
(V4 1 1 1 1)
|
||||
(if vd == ViewRight
|
||||
then V2 0 (1 - 50 / 1024)
|
||||
else V2 (50 / 1024) (1 - 50 / 1024)
|
||||
)
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x + 25) (realToFrac y - 25) 0)
|
||||
(V4 1 1 1 1)
|
||||
(if vd == ViewRight
|
||||
then V2 (50 / 1024) (1 - 50 / 1024)
|
||||
else V2 0 (1 - 50 / 1024)
|
||||
)
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x + 25) (realToFrac y + 25) 0)
|
||||
(V4 1 1 1 1)
|
||||
(if vd == ViewRight
|
||||
then V2 (50 / 1024) 1
|
||||
else V2 0 1
|
||||
)
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x - 25) (realToFrac y + 25) 0)
|
||||
(V4 1 1 1 1)
|
||||
(if vd == ViewRight
|
||||
then V2 0 1
|
||||
else V2 (50 / 1024) 1
|
||||
)
|
||||
1
|
||||
]
|
||||
)
|
||||
|
||||
instance Prop Pituicat where
|
||||
|
||||
residentLayer _ = 0
|
||||
|
||||
bindPropTexture = bind . pcTexture
|
||||
|
||||
instance Actor Pituicat where
|
||||
|
||||
perform dt p =
|
||||
let (V2 _ dy) = velocity physCat
|
||||
moveFact =
|
||||
if
|
||||
not (any ((SpeedUp ==) . effectReleased) (pcEffects p))
|
||||
then 1
|
||||
else 2
|
||||
physCat = (accelerate dt . gravitate constG)
|
||||
(p
|
||||
{ pcAcc = V2 0 0
|
||||
, pcTMoveVel =
|
||||
case pcMoveState p of
|
||||
Just MoveRight -> V2 (catMoveVelocity * moveFact) 0
|
||||
Just MoveLeft -> V2 ((-catMoveVelocity) * moveFact) 0
|
||||
_ -> V2 0 0
|
||||
}
|
||||
)
|
||||
finalCat = physCat
|
||||
{ pcMoveVel = (if pcXColl physCat then V2 0 1 else V2 1 1) *
|
||||
lerp (min 0.95 (60 * dt)) (pcMoveVel physCat) (pcTMoveVel physCat)
|
||||
, pcGrounded = pcGrounded physCat && abs dy * dt <= 2
|
||||
, pcEffects =
|
||||
foldl
|
||||
(\acc eff ->
|
||||
let nduration = effectDuration eff - dt
|
||||
in
|
||||
if nduration > 0
|
||||
then
|
||||
eff { effectDuration = nduration} : acc
|
||||
else
|
||||
acc
|
||||
)
|
||||
[]
|
||||
(pcEffects p)
|
||||
}
|
||||
in
|
||||
A.log A.Debug ("*meow* am at: " <> fromString (show $ position finalCat))
|
||||
(finalCat
|
||||
{ pcViewDirection = if pcGrounded finalCat
|
||||
then
|
||||
case pcMoveState finalCat of
|
||||
Just MoveRight -> ViewRight
|
||||
Just MoveLeft -> ViewLeft
|
||||
_ -> pcViewDirection finalCat
|
||||
else
|
||||
pcViewDirection finalCat
|
||||
}
|
||||
)
|
||||
|
||||
instance Mass Pituicat where
|
||||
|
||||
mass _ = 100
|
||||
|
||||
acceleration = pcAcc
|
||||
|
||||
accelerationUpdater cat =
|
||||
\accel -> cat
|
||||
{ pcAcc = accel
|
||||
}
|
||||
|
||||
velocity =
|
||||
pcVel
|
||||
|
||||
velocityUpdater cat =
|
||||
\vel -> cat
|
||||
{ pcVel = vel
|
||||
}
|
||||
|
||||
position = pcPos
|
||||
|
||||
positionUpdater cat =
|
||||
\pos -> cat
|
||||
{ pcPos = pos
|
||||
}
|
||||
|
||||
move dt cat =
|
||||
let dpos = (dt *) <$> velocity cat
|
||||
mpos = (dt *) <$>
|
||||
(if pcXColl cat then V2 (-1) 1 else V2 1 1) * pcMoveVel cat
|
||||
in
|
||||
positionUpdater cat (position cat + dpos + mpos)
|
||||
|
||||
instance Collidible Pituicat where
|
||||
|
||||
boundary cat =
|
||||
if pcViewDirection cat == ViewRight
|
||||
then
|
||||
( V2 (-18) (-25)
|
||||
, V2 25 15
|
||||
)
|
||||
else
|
||||
( V2 (-25) (-25)
|
||||
, V2 18 15
|
||||
)
|
||||
|
||||
collide cat [] _ = cat
|
||||
{ pcXColl = False
|
||||
}
|
||||
collide cat collrs@((_, NoCollision):_) _ = cat
|
||||
{ pcXColl = any
|
||||
(\(_, CollisionImminent _ (V2 cx _)) -> cx /= 0)
|
||||
(filter ((NoCollision /= ) . snd) collrs)
|
||||
}
|
||||
collide cat collrs@(collr@(_, OverlapCollision direction):_) dt =
|
||||
elasticCollision 0.3 cat collr dt
|
||||
collide cat collrs@(collr@(other, CollisionImminent ddt (V2 dirx diry)):_) dt =
|
||||
let ncat = elasticCollision 0.3 cat collr dt
|
||||
vel@(V2 vx vy) = velocity ncat
|
||||
moveVel@(V2 mx my) = pcMoveVel cat
|
||||
nvel = V2
|
||||
(if abs mx > abs vx
|
||||
then 0
|
||||
else signum vx * (abs vx - abs mx)
|
||||
)
|
||||
((\(V2 _ y) -> y) (if diry /= 0 then pcVel ncat else pcVel cat))
|
||||
grounded =
|
||||
diry == -1 && abs (vy * ddt) < 2
|
||||
in
|
||||
ncat
|
||||
{ pcGrounded = grounded
|
||||
, pcXColl = not grounded && diry /= 0
|
||||
}
|
119
src/Types/PowerUp.hs
Normal file
|
@ -0,0 +1,119 @@
|
|||
module Types.PowerUp where
|
||||
|
||||
import qualified Data.Vector as V
|
||||
|
||||
import Linear
|
||||
|
||||
-- internal imports
|
||||
|
||||
import Classes.Collectable
|
||||
import Classes.Prop
|
||||
import Classes.Actor
|
||||
|
||||
import Physics.Classes
|
||||
|
||||
import Graphics.Types.VertexBuffer
|
||||
import Graphics.Types.Texture
|
||||
import Graphics.Classes.Drawable
|
||||
import Graphics.Classes.Bindable
|
||||
|
||||
import Util
|
||||
|
||||
data PowerUp = PowerUp
|
||||
{ puPos :: V2 Double
|
||||
, puVel :: V2 Double
|
||||
, puAcc :: V2 Double
|
||||
, puTTL :: Double
|
||||
, puTexture :: Texture
|
||||
, puEffect :: EffectHolder
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Drawable PowerUp where
|
||||
|
||||
toVertices (PowerUp (V2 x y) _ _ _ _ _) =
|
||||
( V.fromList [0, 1, 2, 2, 3, 0]
|
||||
, V.fromList
|
||||
[ newVertex
|
||||
(V3 (realToFrac x - 20) (realToFrac y - 20) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 0 (1 - 50 / 1024))
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x + 20) (realToFrac y - 20) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 (50 / 1024) (1 - 50 / 1024))
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x + 20) (realToFrac y + 20) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 (50 / 1024) 1)
|
||||
1
|
||||
, newVertex
|
||||
(V3 (realToFrac x - 20) (realToFrac y + 20) 0)
|
||||
(V4 1 1 1 1)
|
||||
(V2 0 1)
|
||||
1
|
||||
]
|
||||
)
|
||||
|
||||
instance Prop PowerUp where
|
||||
|
||||
residentLayer _ = 0
|
||||
|
||||
bindPropTexture = bind . puTexture
|
||||
|
||||
instance Actor PowerUp where
|
||||
|
||||
perform dt o =
|
||||
let phys = (accelerate dt . gravitate constG)
|
||||
o
|
||||
{ puAcc = V2 0 0
|
||||
, puTTL = puTTL o - dt
|
||||
}
|
||||
in
|
||||
phys
|
||||
|
||||
instance Mass PowerUp where
|
||||
|
||||
mass _ = 0.1
|
||||
|
||||
acceleration = puAcc
|
||||
|
||||
accelerationUpdater o =
|
||||
\acc -> o
|
||||
{ puAcc = acc
|
||||
}
|
||||
|
||||
velocity = puVel
|
||||
|
||||
velocityUpdater o =
|
||||
\vel -> o
|
||||
{ puVel = vel
|
||||
}
|
||||
|
||||
position = puPos
|
||||
|
||||
positionUpdater o =
|
||||
\pos -> o
|
||||
{ puPos = pos
|
||||
}
|
||||
|
||||
instance Collidible PowerUp where
|
||||
|
||||
boundary _ =
|
||||
( V2 (-20) (-20)
|
||||
, V2 20 20
|
||||
)
|
||||
|
||||
collide o ((_, NoCollision):_) _ = o
|
||||
collide o [] _ = o
|
||||
|
||||
collide o (collr:_) dt =
|
||||
let no = elasticCollision 0.5 o collr dt
|
||||
in
|
||||
no
|
||||
|
||||
instance Collectable PowerUp where
|
||||
|
||||
effect = puEffect
|