├── .gitignore
├── LICENSE
├── README.md
├── doc
└── intro.md
├── examples
├── flappy
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── doc
│ │ └── intro.md
│ ├── index.html
│ ├── project.clj
│ ├── src
│ │ └── flappy
│ │ │ └── core.cljs
│ └── test
│ │ └── flappy
│ │ └── core_test.clj
└── mario
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── doc
│ └── intro.md
│ ├── index.html
│ ├── project.clj
│ ├── src
│ └── mario
│ │ └── core.cljs
│ └── test
│ └── mario
│ └── core_test.clj
├── project.clj
├── src
└── peli
│ └── engine.cljs
└── test
└── peli
└── engine_test.cljs
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | pom.xml
5 | pom.xml.asc
6 | *.jar
7 | *.class
8 | /.lein-*
9 | /.nrepl-port
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and
10 | documentation distributed under this Agreement, and
11 |
12 | b) in the case of each subsequent Contributor:
13 |
14 | i) changes to the Program, and
15 |
16 | ii) additions to the Program;
17 |
18 | where such changes and/or additions to the Program originate from and are
19 | distributed by that particular Contributor. A Contribution 'originates' from
20 | a Contributor if it was added to the Program by such Contributor itself or
21 | anyone acting on such Contributor's behalf. Contributions do not include
22 | additions to the Program which: (i) are separate modules of software
23 | distributed in conjunction with the Program under their own license
24 | agreement, and (ii) are not derivative works of the Program.
25 |
26 | "Contributor" means any person or entity that distributes the Program.
27 |
28 | "Licensed Patents" mean patent claims licensable by a Contributor which are
29 | necessarily infringed by the use or sale of its Contribution alone or when
30 | combined with the Program.
31 |
32 | "Program" means the Contributions distributed in accordance with this
33 | Agreement.
34 |
35 | "Recipient" means anyone who receives the Program under this Agreement,
36 | including all Contributors.
37 |
38 | 2. GRANT OF RIGHTS
39 |
40 | a) Subject to the terms of this Agreement, each Contributor hereby grants
41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to
42 | reproduce, prepare derivative works of, publicly display, publicly perform,
43 | distribute and sublicense the Contribution of such Contributor, if any, and
44 | such derivative works, in source code and object code form.
45 |
46 | b) Subject to the terms of this Agreement, each Contributor hereby grants
47 | Recipient a non-exclusive, worldwide, royalty-free patent license under
48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise
49 | transfer the Contribution of such Contributor, if any, in source code and
50 | object code form. This patent license shall apply to the combination of the
51 | Contribution and the Program if, at the time the Contribution is added by the
52 | Contributor, such addition of the Contribution causes such combination to be
53 | covered by the Licensed Patents. The patent license shall not apply to any
54 | other combinations which include the Contribution. No hardware per se is
55 | licensed hereunder.
56 |
57 | c) Recipient understands that although each Contributor grants the licenses
58 | to its Contributions set forth herein, no assurances are provided by any
59 | Contributor that the Program does not infringe the patent or other
60 | intellectual property rights of any other entity. Each Contributor disclaims
61 | any liability to Recipient for claims brought by any other entity based on
62 | infringement of intellectual property rights or otherwise. As a condition to
63 | exercising the rights and licenses granted hereunder, each Recipient hereby
64 | assumes sole responsibility to secure any other intellectual property rights
65 | needed, if any. For example, if a third party patent license is required to
66 | allow Recipient to distribute the Program, it is Recipient's responsibility
67 | to acquire that license before distributing the Program.
68 |
69 | d) Each Contributor represents that to its knowledge it has sufficient
70 | copyright rights in its Contribution, if any, to grant the copyright license
71 | set forth in this Agreement.
72 |
73 | 3. REQUIREMENTS
74 |
75 | A Contributor may choose to distribute the Program in object code form under
76 | its own license agreement, provided that:
77 |
78 | a) it complies with the terms and conditions of this Agreement; and
79 |
80 | b) its license agreement:
81 |
82 | i) effectively disclaims on behalf of all Contributors all warranties and
83 | conditions, express and implied, including warranties or conditions of title
84 | and non-infringement, and implied warranties or conditions of merchantability
85 | and fitness for a particular purpose;
86 |
87 | ii) effectively excludes on behalf of all Contributors all liability for
88 | damages, including direct, indirect, special, incidental and consequential
89 | damages, such as lost profits;
90 |
91 | iii) states that any provisions which differ from this Agreement are offered
92 | by that Contributor alone and not by any other party; and
93 |
94 | iv) states that source code for the Program is available from such
95 | Contributor, and informs licensees how to obtain it in a reasonable manner on
96 | or through a medium customarily used for software exchange.
97 |
98 | When the Program is made available in source code form:
99 |
100 | a) it must be made available under this Agreement; and
101 |
102 | b) a copy of this Agreement must be included with each copy of the Program.
103 |
104 | Contributors may not remove or alter any copyright notices contained within
105 | the Program.
106 |
107 | Each Contributor must identify itself as the originator of its Contribution,
108 | if any, in a manner that reasonably allows subsequent Recipients to identify
109 | the originator of the Contribution.
110 |
111 | 4. COMMERCIAL DISTRIBUTION
112 |
113 | Commercial distributors of software may accept certain responsibilities with
114 | respect to end users, business partners and the like. While this license is
115 | intended to facilitate the commercial use of the Program, the Contributor who
116 | includes the Program in a commercial product offering should do so in a
117 | manner which does not create potential liability for other Contributors.
118 | Therefore, if a Contributor includes the Program in a commercial product
119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120 | and indemnify every other Contributor ("Indemnified Contributor") against any
121 | losses, damages and costs (collectively "Losses") arising from claims,
122 | lawsuits and other legal actions brought by a third party against the
123 | Indemnified Contributor to the extent caused by the acts or omissions of such
124 | Commercial Contributor in connection with its distribution of the Program in
125 | a commercial product offering. The obligations in this section do not apply
126 | to any claims or Losses relating to any actual or alleged intellectual
127 | property infringement. In order to qualify, an Indemnified Contributor must:
128 | a) promptly notify the Commercial Contributor in writing of such claim, and
129 | b) allow the Commercial Contributor tocontrol, and cooperate with the
130 | Commercial Contributor in, the defense and any related settlement
131 | negotiations. The Indemnified Contributor may participate in any such claim
132 | at its own expense.
133 |
134 | For example, a Contributor might include the Program in a commercial product
135 | offering, Product X. That Contributor is then a Commercial Contributor. If
136 | that Commercial Contributor then makes performance claims, or offers
137 | warranties related to Product X, those performance claims and warranties are
138 | such Commercial Contributor's responsibility alone. Under this section, the
139 | Commercial Contributor would have to defend claims against the other
140 | Contributors related to those performance claims and warranties, and if a
141 | court requires any other Contributor to pay any damages as a result, the
142 | Commercial Contributor must pay those damages.
143 |
144 | 5. NO WARRANTY
145 |
146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151 | appropriateness of using and distributing the Program and assumes all risks
152 | associated with its exercise of rights under this Agreement , including but
153 | not limited to the risks and costs of program errors, compliance with
154 | applicable laws, damage to or loss of data, programs or equipment, and
155 | unavailability or interruption of operations.
156 |
157 | 6. DISCLAIMER OF LIABILITY
158 |
159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166 | OF SUCH DAMAGES.
167 |
168 | 7. GENERAL
169 |
170 | If any provision of this Agreement is invalid or unenforceable under
171 | applicable law, it shall not affect the validity or enforceability of the
172 | remainder of the terms of this Agreement, and without further action by the
173 | parties hereto, such provision shall be reformed to the minimum extent
174 | necessary to make such provision valid and enforceable.
175 |
176 | If Recipient institutes patent litigation against any entity (including a
177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178 | (excluding combinations of the Program with other software or hardware)
179 | infringes such Recipient's patent(s), then such Recipient's rights granted
180 | under Section 2(b) shall terminate as of the date such litigation is filed.
181 |
182 | All Recipient's rights under this Agreement shall terminate if it fails to
183 | comply with any of the material terms or conditions of this Agreement and
184 | does not cure such failure in a reasonable period of time after becoming
185 | aware of such noncompliance. If all Recipient's rights under this Agreement
186 | terminate, Recipient agrees to cease use and distribution of the Program as
187 | soon as reasonably practicable. However, Recipient's obligations under this
188 | Agreement and any licenses granted by Recipient relating to the Program shall
189 | continue and survive.
190 |
191 | Everyone is permitted to copy and distribute copies of this Agreement, but in
192 | order to avoid inconsistency the Agreement is copyrighted and may only be
193 | modified in the following manner. The Agreement Steward reserves the right to
194 | publish new versions (including revisions) of this Agreement from time to
195 | time. No one other than the Agreement Steward has the right to modify this
196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197 | Eclipse Foundation may assign the responsibility to serve as the Agreement
198 | Steward to a suitable separate entity. Each new version of the Agreement will
199 | be given a distinguishing version number. The Program (including
200 | Contributions) may always be distributed subject to the version of the
201 | Agreement under which it was received. In addition, after a new version of
202 | the Agreement is published, Contributor may elect to distribute the Program
203 | (including its Contributions) under the new version. Except as expressly
204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205 | licenses to the intellectual property of any Contributor under this
206 | Agreement, whether expressly, by implication, estoppel or otherwise. All
207 | rights in the Program not expressly granted under this Agreement are
208 | reserved.
209 |
210 | This Agreement is governed by the laws of the State of Washington and the
211 | intellectual property laws of the United States of America. No party to this
212 | Agreement will bring a legal action under this Agreement more than one year
213 | after the cause of action arose. Each party waives its rights to a jury trial
214 | in any resulting litigation.
215 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # peli
2 |
3 | A Clojure library designed to ... well, that part is up to you.
4 |
5 | ## Usage
6 |
7 | FIXME
8 |
9 | ## License
10 |
11 | Copyright © 2014 FIXME
12 |
13 | Distributed under the Eclipse Public License either version 1.0 or (at
14 | your option) any later version.
15 |
--------------------------------------------------------------------------------
/doc/intro.md:
--------------------------------------------------------------------------------
1 | # Introduction to peli
2 |
3 | TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
4 |
--------------------------------------------------------------------------------
/examples/flappy/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | pom.xml
5 | pom.xml.asc
6 | *.jar
7 | *.class
8 | /.lein-*
9 | /.nrepl-port
10 |
--------------------------------------------------------------------------------
/examples/flappy/LICENSE:
--------------------------------------------------------------------------------
1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and
10 | documentation distributed under this Agreement, and
11 |
12 | b) in the case of each subsequent Contributor:
13 |
14 | i) changes to the Program, and
15 |
16 | ii) additions to the Program;
17 |
18 | where such changes and/or additions to the Program originate from and are
19 | distributed by that particular Contributor. A Contribution 'originates' from
20 | a Contributor if it was added to the Program by such Contributor itself or
21 | anyone acting on such Contributor's behalf. Contributions do not include
22 | additions to the Program which: (i) are separate modules of software
23 | distributed in conjunction with the Program under their own license
24 | agreement, and (ii) are not derivative works of the Program.
25 |
26 | "Contributor" means any person or entity that distributes the Program.
27 |
28 | "Licensed Patents" mean patent claims licensable by a Contributor which are
29 | necessarily infringed by the use or sale of its Contribution alone or when
30 | combined with the Program.
31 |
32 | "Program" means the Contributions distributed in accordance with this
33 | Agreement.
34 |
35 | "Recipient" means anyone who receives the Program under this Agreement,
36 | including all Contributors.
37 |
38 | 2. GRANT OF RIGHTS
39 |
40 | a) Subject to the terms of this Agreement, each Contributor hereby grants
41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to
42 | reproduce, prepare derivative works of, publicly display, publicly perform,
43 | distribute and sublicense the Contribution of such Contributor, if any, and
44 | such derivative works, in source code and object code form.
45 |
46 | b) Subject to the terms of this Agreement, each Contributor hereby grants
47 | Recipient a non-exclusive, worldwide, royalty-free patent license under
48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise
49 | transfer the Contribution of such Contributor, if any, in source code and
50 | object code form. This patent license shall apply to the combination of the
51 | Contribution and the Program if, at the time the Contribution is added by the
52 | Contributor, such addition of the Contribution causes such combination to be
53 | covered by the Licensed Patents. The patent license shall not apply to any
54 | other combinations which include the Contribution. No hardware per se is
55 | licensed hereunder.
56 |
57 | c) Recipient understands that although each Contributor grants the licenses
58 | to its Contributions set forth herein, no assurances are provided by any
59 | Contributor that the Program does not infringe the patent or other
60 | intellectual property rights of any other entity. Each Contributor disclaims
61 | any liability to Recipient for claims brought by any other entity based on
62 | infringement of intellectual property rights or otherwise. As a condition to
63 | exercising the rights and licenses granted hereunder, each Recipient hereby
64 | assumes sole responsibility to secure any other intellectual property rights
65 | needed, if any. For example, if a third party patent license is required to
66 | allow Recipient to distribute the Program, it is Recipient's responsibility
67 | to acquire that license before distributing the Program.
68 |
69 | d) Each Contributor represents that to its knowledge it has sufficient
70 | copyright rights in its Contribution, if any, to grant the copyright license
71 | set forth in this Agreement.
72 |
73 | 3. REQUIREMENTS
74 |
75 | A Contributor may choose to distribute the Program in object code form under
76 | its own license agreement, provided that:
77 |
78 | a) it complies with the terms and conditions of this Agreement; and
79 |
80 | b) its license agreement:
81 |
82 | i) effectively disclaims on behalf of all Contributors all warranties and
83 | conditions, express and implied, including warranties or conditions of title
84 | and non-infringement, and implied warranties or conditions of merchantability
85 | and fitness for a particular purpose;
86 |
87 | ii) effectively excludes on behalf of all Contributors all liability for
88 | damages, including direct, indirect, special, incidental and consequential
89 | damages, such as lost profits;
90 |
91 | iii) states that any provisions which differ from this Agreement are offered
92 | by that Contributor alone and not by any other party; and
93 |
94 | iv) states that source code for the Program is available from such
95 | Contributor, and informs licensees how to obtain it in a reasonable manner on
96 | or through a medium customarily used for software exchange.
97 |
98 | When the Program is made available in source code form:
99 |
100 | a) it must be made available under this Agreement; and
101 |
102 | b) a copy of this Agreement must be included with each copy of the Program.
103 |
104 | Contributors may not remove or alter any copyright notices contained within
105 | the Program.
106 |
107 | Each Contributor must identify itself as the originator of its Contribution,
108 | if any, in a manner that reasonably allows subsequent Recipients to identify
109 | the originator of the Contribution.
110 |
111 | 4. COMMERCIAL DISTRIBUTION
112 |
113 | Commercial distributors of software may accept certain responsibilities with
114 | respect to end users, business partners and the like. While this license is
115 | intended to facilitate the commercial use of the Program, the Contributor who
116 | includes the Program in a commercial product offering should do so in a
117 | manner which does not create potential liability for other Contributors.
118 | Therefore, if a Contributor includes the Program in a commercial product
119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120 | and indemnify every other Contributor ("Indemnified Contributor") against any
121 | losses, damages and costs (collectively "Losses") arising from claims,
122 | lawsuits and other legal actions brought by a third party against the
123 | Indemnified Contributor to the extent caused by the acts or omissions of such
124 | Commercial Contributor in connection with its distribution of the Program in
125 | a commercial product offering. The obligations in this section do not apply
126 | to any claims or Losses relating to any actual or alleged intellectual
127 | property infringement. In order to qualify, an Indemnified Contributor must:
128 | a) promptly notify the Commercial Contributor in writing of such claim, and
129 | b) allow the Commercial Contributor tocontrol, and cooperate with the
130 | Commercial Contributor in, the defense and any related settlement
131 | negotiations. The Indemnified Contributor may participate in any such claim
132 | at its own expense.
133 |
134 | For example, a Contributor might include the Program in a commercial product
135 | offering, Product X. That Contributor is then a Commercial Contributor. If
136 | that Commercial Contributor then makes performance claims, or offers
137 | warranties related to Product X, those performance claims and warranties are
138 | such Commercial Contributor's responsibility alone. Under this section, the
139 | Commercial Contributor would have to defend claims against the other
140 | Contributors related to those performance claims and warranties, and if a
141 | court requires any other Contributor to pay any damages as a result, the
142 | Commercial Contributor must pay those damages.
143 |
144 | 5. NO WARRANTY
145 |
146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151 | appropriateness of using and distributing the Program and assumes all risks
152 | associated with its exercise of rights under this Agreement , including but
153 | not limited to the risks and costs of program errors, compliance with
154 | applicable laws, damage to or loss of data, programs or equipment, and
155 | unavailability or interruption of operations.
156 |
157 | 6. DISCLAIMER OF LIABILITY
158 |
159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166 | OF SUCH DAMAGES.
167 |
168 | 7. GENERAL
169 |
170 | If any provision of this Agreement is invalid or unenforceable under
171 | applicable law, it shall not affect the validity or enforceability of the
172 | remainder of the terms of this Agreement, and without further action by the
173 | parties hereto, such provision shall be reformed to the minimum extent
174 | necessary to make such provision valid and enforceable.
175 |
176 | If Recipient institutes patent litigation against any entity (including a
177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178 | (excluding combinations of the Program with other software or hardware)
179 | infringes such Recipient's patent(s), then such Recipient's rights granted
180 | under Section 2(b) shall terminate as of the date such litigation is filed.
181 |
182 | All Recipient's rights under this Agreement shall terminate if it fails to
183 | comply with any of the material terms or conditions of this Agreement and
184 | does not cure such failure in a reasonable period of time after becoming
185 | aware of such noncompliance. If all Recipient's rights under this Agreement
186 | terminate, Recipient agrees to cease use and distribution of the Program as
187 | soon as reasonably practicable. However, Recipient's obligations under this
188 | Agreement and any licenses granted by Recipient relating to the Program shall
189 | continue and survive.
190 |
191 | Everyone is permitted to copy and distribute copies of this Agreement, but in
192 | order to avoid inconsistency the Agreement is copyrighted and may only be
193 | modified in the following manner. The Agreement Steward reserves the right to
194 | publish new versions (including revisions) of this Agreement from time to
195 | time. No one other than the Agreement Steward has the right to modify this
196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197 | Eclipse Foundation may assign the responsibility to serve as the Agreement
198 | Steward to a suitable separate entity. Each new version of the Agreement will
199 | be given a distinguishing version number. The Program (including
200 | Contributions) may always be distributed subject to the version of the
201 | Agreement under which it was received. In addition, after a new version of
202 | the Agreement is published, Contributor may elect to distribute the Program
203 | (including its Contributions) under the new version. Except as expressly
204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205 | licenses to the intellectual property of any Contributor under this
206 | Agreement, whether expressly, by implication, estoppel or otherwise. All
207 | rights in the Program not expressly granted under this Agreement are
208 | reserved.
209 |
210 | This Agreement is governed by the laws of the State of Washington and the
211 | intellectual property laws of the United States of America. No party to this
212 | Agreement will bring a legal action under this Agreement more than one year
213 | after the cause of action arose. Each party waives its rights to a jury trial
214 | in any resulting litigation.
215 |
--------------------------------------------------------------------------------
/examples/flappy/README.md:
--------------------------------------------------------------------------------
1 | # flappy
2 |
3 | A Clojure library designed to ... well, that part is up to you.
4 |
5 | ## Usage
6 |
7 | FIXME
8 |
9 | ## License
10 |
11 | Copyright © 2014 FIXME
12 |
13 | Distributed under the Eclipse Public License either version 1.0 or (at
14 | your option) any later version.
15 |
--------------------------------------------------------------------------------
/examples/flappy/doc/intro.md:
--------------------------------------------------------------------------------
1 | # Introduction to flappy
2 |
3 | TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
4 |
--------------------------------------------------------------------------------
/examples/flappy/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |

6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/flappy/project.clj:
--------------------------------------------------------------------------------
1 | (defproject flappy "0.1.0-SNAPSHOT"
2 | :description "FIXME: write this!"
3 | :url "http://example.com/FIXME"
4 |
5 | :jvm-opts ^:replace ["-Xmx1g" "-server"]
6 |
7 | :dependencies [[kioo "0.4.0-SNAPSHOT"]
8 | [peli "0.1.0-SNAPSHOT"]
9 | [org.clojure/clojure "1.5.1"]
10 | [org.clojure/clojurescript "0.0-2138"]
11 | [org.clojure/core.async "0.1.267.0-0d7780-alpha"]]
12 |
13 | :plugins [[lein-cljsbuild "1.0.1"]]
14 |
15 | :source-paths ["src"]
16 | :resource-paths ["resources"]
17 |
18 | :cljsbuild {
19 | :builds [{:id "dev"
20 | :source-paths ["src"]
21 | :compiler {
22 | :output-to "app.js"
23 | :pretty-print true
24 | :optimizations :simple}}]})
25 |
--------------------------------------------------------------------------------
/examples/flappy/src/flappy/core.cljs:
--------------------------------------------------------------------------------
1 | (ns flappy.core
2 | (:require [peli.engine
3 | :refer [translate-coords Physics physics Gravity gravity
4 | Pen draw Collision collide apply-gravity
5 | apply-physics collide-action collide-solid
6 | remove-body play-sound schedule-edit Game World
7 | Block TextPrompt run-game edit-loop remove-overlay
8 | Framed adjust-frame?]]
9 | [cljs.core.async :refer (timeout put! chan)])
10 | (:require-macros [cljs.core.async.macros :refer (go go-loop)]))
11 |
12 | (declare overlays bodies ScoreGate)
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 | ;;
15 | ;; Edit Actions
16 | ;;
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 | (defn game-over [game]
19 | (-> game
20 | (assoc-in [:state :score] 0)
21 | (update-in [:active-world :frame] #(assoc % :x 0 :y 0))
22 | (assoc-in [:active-world :bodies] bodies)
23 | (assoc-in [:active-world :overlays] overlays)
24 | (assoc-in [:active-world :run-state] :paused)))
25 |
26 | (defn cleanup-gate [world]
27 | (if (= (:run-state world) :paused) world
28 | (assoc world :bodies
29 | (filterv #(> (+ (:x %) (:width %)) (:x (:frame world)))
30 | (:bodies world)))))
31 |
32 | (defn create-gate [world]
33 | (if (= (:run-state world) :paused) world
34 | (assoc world :bodies
35 | (let [start (+ 50 (rand-int 200))
36 | x (+ 200 (:x (last (:bodies world))))
37 | end (+ start 100)]
38 | (conj (:bodies world)
39 | (Block. (gensym) "#007F00" 50 start x 0 [0 0 5 5])
40 | (Block. (gensym) "#007F00" 50 (- 400 end) x end [5 5 0 0])
41 | (ScoreGate. (gensym) 10 100 (+ x 25) start))))))
42 |
43 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 | ;;
45 | ;; BUILDING MATERIALS
46 | ;;
47 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 |
49 | (defrecord ScoreGate [id width height x y])
50 |
51 | (defrecord Bird [id width height x y vx vy]
52 | Pen
53 | (draw [this ctx frame ch state]
54 | (let [{:keys [width height x y]} (translate-coords this frame)
55 | img (.getElementById js/document "bird")]
56 | (.drawImage ctx img x y width height)))
57 |
58 | Gravity
59 | (gravity [this ch state]
60 | (apply-gravity this))
61 |
62 | Physics
63 | (physics[this time-diff board ch state]
64 | (apply-physics this 0 board))
65 |
66 | Collision
67 | (collide [this body ch state]
68 | (condp = (type body)
69 | Block (collide-action this body
70 | {:any (fn [b]
71 | (schedule-edit game-over ch 10 :edit-game) b)})
72 | ScoreGate (do
73 | (put! ch {:action :edit-world
74 | :fn #(remove-body % (:id body))})
75 | (put! ch {:action :edit-game
76 | :fn #(update-in % [:state :score] inc)})
77 | this)
78 | this))
79 |
80 | Framed
81 | (adjust-frame? [this] true))
82 |
83 | (defrecord ScoreOverlay [id]
84 | Pen
85 | (draw [this ctx frame ch state]
86 | (set! (.-textBaseline ctx) "middle")
87 | (set! (.-font ctx) "12px Arial")
88 | (set! (.-fillStyle ctx) "#000099")
89 | (.fillText ctx (str "score: " (:score state)) 20 20)))
90 |
91 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92 | ;;
93 | ;; GAME WORLD
94 | ;;
95 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 |
97 | (def bodies
98 | [(Bird. (gensym) 22 18 100 200 2 0)
99 | (Block. (gensym) "#007F00" 50 100 300 0 [0 0 5 5])
100 | (Block. (gensym) "#007F00" 50 200 300 200 [5 5 0 0])
101 | (ScoreGate. (gensym) 10 100 325 100)])
102 |
103 | (def overlays [(ScoreOverlay. :score)
104 | (TextPrompt. :start 100 50 "Hit Enter" false {})])
105 |
106 | (def key-actions
107 | {32 {:on-down #(assoc-in % [:bodies 0 :vy] 4)}
108 | 13 {:on-down #(-> %
109 | (remove-overlay :start)
110 | (assoc :run-state :running))}
111 | 27 {:on-down #(assoc % :run-state :paused)}
112 | 80 {:on-down #(do (println %) %)}})
113 |
114 | (def world
115 | (World. {:width 20000 :height 400 :img nil :color "#7F7FFF"}
116 | {:width 400 :height 400 :x 0 :y 0 :buffer 130}
117 | bodies
118 | overlays
119 | key-actions
120 | :paused))
121 |
122 | (def game (Game. {:world1 world} nil {:score 0 :health 3 :lives 10}))
123 |
124 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 | ;;
126 | ;; Run Game
127 | ;;
128 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 |
130 | (def ch (run-game game "myCanvas" :world1))
131 | (edit-loop ch :edit-world cleanup-gate 2500)
132 | (edit-loop ch :edit-world create-gate 2500)
133 |
--------------------------------------------------------------------------------
/examples/flappy/test/flappy/core_test.clj:
--------------------------------------------------------------------------------
1 | (ns flappy.core-test
2 | (:require [clojure.test :refer :all]
3 | [flappy.core :refer :all]))
4 |
5 | (deftest a-test
6 | (testing "FIXME, I fail."
7 | (is (= 0 1))))
8 |
--------------------------------------------------------------------------------
/examples/mario/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | pom.xml
5 | pom.xml.asc
6 | *.jar
7 | *.class
8 | /.lein-*
9 | /.nrepl-port
10 |
--------------------------------------------------------------------------------
/examples/mario/LICENSE:
--------------------------------------------------------------------------------
1 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
2 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
3 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and
10 | documentation distributed under this Agreement, and
11 |
12 | b) in the case of each subsequent Contributor:
13 |
14 | i) changes to the Program, and
15 |
16 | ii) additions to the Program;
17 |
18 | where such changes and/or additions to the Program originate from and are
19 | distributed by that particular Contributor. A Contribution 'originates' from
20 | a Contributor if it was added to the Program by such Contributor itself or
21 | anyone acting on such Contributor's behalf. Contributions do not include
22 | additions to the Program which: (i) are separate modules of software
23 | distributed in conjunction with the Program under their own license
24 | agreement, and (ii) are not derivative works of the Program.
25 |
26 | "Contributor" means any person or entity that distributes the Program.
27 |
28 | "Licensed Patents" mean patent claims licensable by a Contributor which are
29 | necessarily infringed by the use or sale of its Contribution alone or when
30 | combined with the Program.
31 |
32 | "Program" means the Contributions distributed in accordance with this
33 | Agreement.
34 |
35 | "Recipient" means anyone who receives the Program under this Agreement,
36 | including all Contributors.
37 |
38 | 2. GRANT OF RIGHTS
39 |
40 | a) Subject to the terms of this Agreement, each Contributor hereby grants
41 | Recipient a non-exclusive, worldwide, royalty-free copyright license to
42 | reproduce, prepare derivative works of, publicly display, publicly perform,
43 | distribute and sublicense the Contribution of such Contributor, if any, and
44 | such derivative works, in source code and object code form.
45 |
46 | b) Subject to the terms of this Agreement, each Contributor hereby grants
47 | Recipient a non-exclusive, worldwide, royalty-free patent license under
48 | Licensed Patents to make, use, sell, offer to sell, import and otherwise
49 | transfer the Contribution of such Contributor, if any, in source code and
50 | object code form. This patent license shall apply to the combination of the
51 | Contribution and the Program if, at the time the Contribution is added by the
52 | Contributor, such addition of the Contribution causes such combination to be
53 | covered by the Licensed Patents. The patent license shall not apply to any
54 | other combinations which include the Contribution. No hardware per se is
55 | licensed hereunder.
56 |
57 | c) Recipient understands that although each Contributor grants the licenses
58 | to its Contributions set forth herein, no assurances are provided by any
59 | Contributor that the Program does not infringe the patent or other
60 | intellectual property rights of any other entity. Each Contributor disclaims
61 | any liability to Recipient for claims brought by any other entity based on
62 | infringement of intellectual property rights or otherwise. As a condition to
63 | exercising the rights and licenses granted hereunder, each Recipient hereby
64 | assumes sole responsibility to secure any other intellectual property rights
65 | needed, if any. For example, if a third party patent license is required to
66 | allow Recipient to distribute the Program, it is Recipient's responsibility
67 | to acquire that license before distributing the Program.
68 |
69 | d) Each Contributor represents that to its knowledge it has sufficient
70 | copyright rights in its Contribution, if any, to grant the copyright license
71 | set forth in this Agreement.
72 |
73 | 3. REQUIREMENTS
74 |
75 | A Contributor may choose to distribute the Program in object code form under
76 | its own license agreement, provided that:
77 |
78 | a) it complies with the terms and conditions of this Agreement; and
79 |
80 | b) its license agreement:
81 |
82 | i) effectively disclaims on behalf of all Contributors all warranties and
83 | conditions, express and implied, including warranties or conditions of title
84 | and non-infringement, and implied warranties or conditions of merchantability
85 | and fitness for a particular purpose;
86 |
87 | ii) effectively excludes on behalf of all Contributors all liability for
88 | damages, including direct, indirect, special, incidental and consequential
89 | damages, such as lost profits;
90 |
91 | iii) states that any provisions which differ from this Agreement are offered
92 | by that Contributor alone and not by any other party; and
93 |
94 | iv) states that source code for the Program is available from such
95 | Contributor, and informs licensees how to obtain it in a reasonable manner on
96 | or through a medium customarily used for software exchange.
97 |
98 | When the Program is made available in source code form:
99 |
100 | a) it must be made available under this Agreement; and
101 |
102 | b) a copy of this Agreement must be included with each copy of the Program.
103 |
104 | Contributors may not remove or alter any copyright notices contained within
105 | the Program.
106 |
107 | Each Contributor must identify itself as the originator of its Contribution,
108 | if any, in a manner that reasonably allows subsequent Recipients to identify
109 | the originator of the Contribution.
110 |
111 | 4. COMMERCIAL DISTRIBUTION
112 |
113 | Commercial distributors of software may accept certain responsibilities with
114 | respect to end users, business partners and the like. While this license is
115 | intended to facilitate the commercial use of the Program, the Contributor who
116 | includes the Program in a commercial product offering should do so in a
117 | manner which does not create potential liability for other Contributors.
118 | Therefore, if a Contributor includes the Program in a commercial product
119 | offering, such Contributor ("Commercial Contributor") hereby agrees to defend
120 | and indemnify every other Contributor ("Indemnified Contributor") against any
121 | losses, damages and costs (collectively "Losses") arising from claims,
122 | lawsuits and other legal actions brought by a third party against the
123 | Indemnified Contributor to the extent caused by the acts or omissions of such
124 | Commercial Contributor in connection with its distribution of the Program in
125 | a commercial product offering. The obligations in this section do not apply
126 | to any claims or Losses relating to any actual or alleged intellectual
127 | property infringement. In order to qualify, an Indemnified Contributor must:
128 | a) promptly notify the Commercial Contributor in writing of such claim, and
129 | b) allow the Commercial Contributor tocontrol, and cooperate with the
130 | Commercial Contributor in, the defense and any related settlement
131 | negotiations. The Indemnified Contributor may participate in any such claim
132 | at its own expense.
133 |
134 | For example, a Contributor might include the Program in a commercial product
135 | offering, Product X. That Contributor is then a Commercial Contributor. If
136 | that Commercial Contributor then makes performance claims, or offers
137 | warranties related to Product X, those performance claims and warranties are
138 | such Commercial Contributor's responsibility alone. Under this section, the
139 | Commercial Contributor would have to defend claims against the other
140 | Contributors related to those performance claims and warranties, and if a
141 | court requires any other Contributor to pay any damages as a result, the
142 | Commercial Contributor must pay those damages.
143 |
144 | 5. NO WARRANTY
145 |
146 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
147 | AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
148 | EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
149 | CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
150 | PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
151 | appropriateness of using and distributing the Program and assumes all risks
152 | associated with its exercise of rights under this Agreement , including but
153 | not limited to the risks and costs of program errors, compliance with
154 | applicable laws, damage to or loss of data, programs or equipment, and
155 | unavailability or interruption of operations.
156 |
157 | 6. DISCLAIMER OF LIABILITY
158 |
159 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
160 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
161 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
162 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
165 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
166 | OF SUCH DAMAGES.
167 |
168 | 7. GENERAL
169 |
170 | If any provision of this Agreement is invalid or unenforceable under
171 | applicable law, it shall not affect the validity or enforceability of the
172 | remainder of the terms of this Agreement, and without further action by the
173 | parties hereto, such provision shall be reformed to the minimum extent
174 | necessary to make such provision valid and enforceable.
175 |
176 | If Recipient institutes patent litigation against any entity (including a
177 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself
178 | (excluding combinations of the Program with other software or hardware)
179 | infringes such Recipient's patent(s), then such Recipient's rights granted
180 | under Section 2(b) shall terminate as of the date such litigation is filed.
181 |
182 | All Recipient's rights under this Agreement shall terminate if it fails to
183 | comply with any of the material terms or conditions of this Agreement and
184 | does not cure such failure in a reasonable period of time after becoming
185 | aware of such noncompliance. If all Recipient's rights under this Agreement
186 | terminate, Recipient agrees to cease use and distribution of the Program as
187 | soon as reasonably practicable. However, Recipient's obligations under this
188 | Agreement and any licenses granted by Recipient relating to the Program shall
189 | continue and survive.
190 |
191 | Everyone is permitted to copy and distribute copies of this Agreement, but in
192 | order to avoid inconsistency the Agreement is copyrighted and may only be
193 | modified in the following manner. The Agreement Steward reserves the right to
194 | publish new versions (including revisions) of this Agreement from time to
195 | time. No one other than the Agreement Steward has the right to modify this
196 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The
197 | Eclipse Foundation may assign the responsibility to serve as the Agreement
198 | Steward to a suitable separate entity. Each new version of the Agreement will
199 | be given a distinguishing version number. The Program (including
200 | Contributions) may always be distributed subject to the version of the
201 | Agreement under which it was received. In addition, after a new version of
202 | the Agreement is published, Contributor may elect to distribute the Program
203 | (including its Contributions) under the new version. Except as expressly
204 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
205 | licenses to the intellectual property of any Contributor under this
206 | Agreement, whether expressly, by implication, estoppel or otherwise. All
207 | rights in the Program not expressly granted under this Agreement are
208 | reserved.
209 |
210 | This Agreement is governed by the laws of the State of Washington and the
211 | intellectual property laws of the United States of America. No party to this
212 | Agreement will bring a legal action under this Agreement more than one year
213 | after the cause of action arose. Each party waives its rights to a jury trial
214 | in any resulting litigation.
215 |
--------------------------------------------------------------------------------
/examples/mario/README.md:
--------------------------------------------------------------------------------
1 | # mario
2 |
3 | A Clojure library designed to ... well, that part is up to you.
4 |
5 | ## Usage
6 |
7 | FIXME
8 |
9 | ## License
10 |
11 | Copyright © 2014 FIXME
12 |
13 | Distributed under the Eclipse Public License either version 1.0 or (at
14 | your option) any later version.
15 |
--------------------------------------------------------------------------------
/examples/mario/doc/intro.md:
--------------------------------------------------------------------------------
1 | # Introduction to mario
2 |
3 | TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
4 |
--------------------------------------------------------------------------------
/examples/mario/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |

6 |

7 |

8 |

9 |

10 |
11 |

12 |

13 |

14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/mario/project.clj:
--------------------------------------------------------------------------------
1 | (defproject mario "0.1.0-SNAPSHOT"
2 | :description "FIXME: write this!"
3 | :url "http://example.com/FIXME"
4 |
5 | :jvm-opts ^:replace ["-Xmx1g" "-server"]
6 |
7 | :dependencies [[kioo "0.4.0-SNAPSHOT"]
8 | [peli "0.1.0-SNAPSHOT"]
9 | [org.clojure/clojure "1.5.1"]
10 | [org.clojure/clojurescript "0.0-2138"]
11 | [org.clojure/core.async "0.1.267.0-0d7780-alpha"]]
12 |
13 | :plugins [[lein-cljsbuild "1.0.1"]]
14 |
15 | :source-paths ["src"]
16 | :resource-paths ["resources"]
17 |
18 | :cljsbuild {
19 | :builds [{:id "dev"
20 | :source-paths ["src"]
21 | :compiler {
22 | :output-to "app.js"
23 | :pretty-print true
24 | :optimizations :simple}}]})
25 |
--------------------------------------------------------------------------------
/examples/mario/src/mario/core.cljs:
--------------------------------------------------------------------------------
1 | (ns mario.core
2 | (:require [peli.engine
3 | :refer [translate-coords Physics physics Gravity gravity
4 | Pen draw Collision collide overlap? check-bounds
5 | apply-gravity apply-physics collide-action
6 | collide-solid remove-body remove-overlay
7 | play-sound run-game schedule-edit check-bounds
8 | Game World Block TextPrompt run-game Framed
9 | adjust-frame?]]
10 | [cljs.core.async :refer (timeout put! chan)])
11 | (:require-macros [cljs.core.async.macros :refer (go go-loop)]))
12 |
13 | (declare Hero BadGuy)
14 |
15 | (defn hero-img [{:keys [vx vy]}]
16 | (cond
17 | (and (>= vx 0) (not= vy 0)) "mario-jump-right"
18 | (and (< vx 0) (not= vy 0)) "mario-jump-left"
19 | (and (> vx 0) (= vy 0)) "mario-walk-right"
20 | (and (< vx 0) (= vy 0)) "mario-walk-left"
21 | :else "mario-stand-right"))
22 |
23 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 | ;;
25 | ;; EDIT ACTIONS
26 | ;;
27 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 | (defn reward [ch]
29 | (fn [body]
30 | (play-sound "reward")
31 | (schedule-edit #(remove-body % (:id body)) ch 700)
32 | (schedule-edit #(assoc % :bodies (conj (:bodies %) body)) ch 5000)
33 | (put! ch {:action :edit-game :fn #(update-in % [:state :score] inc)})
34 | (assoc body :vy 2 :state :gone)))
35 |
36 | (defn kill-bad-guy [ch]
37 | (fn [body]
38 | (play-sound "stomp")
39 | (schedule-edit #(remove-body % (:id body)) ch 1000)
40 | (schedule-edit #(assoc % :bodies
41 | (conj (:bodies %) (assoc body :y (- (:y body) 2))))
42 | ch 5000)
43 | (assoc body :vx 0 :height 2 :state :dead)))
44 |
45 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46 | ;;
47 | ;; BUIDLING MATERIALS
48 | ;;
49 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 | (defrecord Reward [id width height x y]
51 | Pen
52 | (draw [this ctx frame ch state]
53 | (let [{:keys [width height x y] :as obj} (translate-coords this frame)
54 | img (.getElementById js/document "coin")]
55 | (.drawImage ctx img x y width height)))
56 | Physics
57 | (physics [this time-diff board ch state]
58 | (apply-physics this 0 board))
59 |
60 | Collision
61 | (collide [this body ch state]
62 | (if (= (:state this) :gone) this
63 | (condp = (type body)
64 | Hero (collide-action this body {:any (reward ch)})
65 | this))))
66 |
67 |
68 | (defrecord Hero [id width height x y vx vy]
69 | Pen
70 | (draw [this ctx frame ch state]
71 | (let [{:keys [width height x y]} (translate-coords this frame)
72 | img (.getElementById js/document (hero-img this))]
73 | (.drawImage ctx img 7 5 19 27 x y width height)
74 | (set! (.-textBaseline ctx) "middle")
75 | (set! (.-font ctx) "12px Arial")
76 | (set! (.-fillStyle ctx) "#000099")
77 | (.fillText ctx (str "coins: "(:score state)) 20 20)))
78 |
79 | Gravity
80 | (gravity [this ch state]
81 | (apply-gravity this))
82 |
83 | Physics
84 | (physics [this time-diff board ch state]
85 | (apply-physics this 0 board))
86 |
87 | Collision
88 | (collide [this body ch state]
89 | (condp = (type body)
90 | Block (collide-solid this body)
91 | BadGuy (collide-action this body {:bottom #(assoc % :vy 5)})
92 | this))
93 |
94 | Framed
95 | (adjust-frame? [this] true))
96 |
97 | (defrecord BadGuy [id width height x y vx vy]
98 | Pen
99 | (draw [this ctx frame ch state]
100 | (let [{:keys [width height img x y]} (translate-coords this frame)
101 | img (.getElementById js/document "goomba")]
102 | (.drawImage ctx img x y width height)))
103 |
104 | Gravity
105 | (gravity [this ch state]
106 | (apply-gravity this))
107 |
108 | Physics
109 | (physics [this time-diff board ch state]
110 | (apply-physics this 0 board))
111 |
112 | Collision
113 | (collide [this body ch state]
114 | (condp = (type body)
115 | Block (-> this
116 | (collide-solid body)
117 | (collide-action body
118 | {:left #(assoc % :vx (* (:vx %) -1))
119 | :right #(assoc % :vx (* (:vx %) -1))}))
120 | Hero (if (= (:state this) :dead) this
121 | (collide-action this body {:top (kill-bad-guy ch)}))
122 | this)))
123 |
124 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 | ;;
126 | ;; GAME WORLD
127 | ;;
128 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 | (def key-actions
130 | {39 {:on-down #(assoc-in % [:bodies 0 :vx] 2) ;right
131 | :on-up #(assoc-in % [:bodies 0 :vx] 0)}
132 | 37 {:on-down #(assoc-in % [:bodies 0 :vx] -2) ;left
133 | :on-up #(assoc-in % [:bodies 0 :vx] 0)}
134 | 32 {:on-down #(update-in % [:bodies 0 :vy] ;jump
135 | (fn [vy] (if (= vy 0)
136 | (do (play-sound "jump") 5)
137 | vy)))}
138 | 13 {:on-down #(assoc (remove-overlay % "start") :run-state :running)}
139 | 27 {:on-down #(assoc % :run-state :paused)}})
140 |
141 |
142 |
143 | (def world
144 | (World. {:width 1000 :height 400 :img nil :color "#7F7FFF"}
145 | {:width 400 :height 400 :x 100 :y 0}
146 | [(Hero. (gensym) 19 27 100 200 0 0)
147 | (Block. (gensym) "#007F00" 200 100 0 300 [10 10 0 0])
148 | (Block. (gensym) "#007F00" 200 100 200 330 [0 0 0 0])
149 | (Block. (gensym) "#007F00" 200 100 400 300 [10 0 0 0])
150 | (Block. (gensym) "#007F00" 200 200 600 230 [10 10 0 0])
151 |
152 | (Block. (gensym) "#007F00" 100 50 450 250 [10 10 0 0])
153 | (Block. (gensym) "#Af8500" 100 24 250 250 [10 10 3 3])
154 |
155 | (Block. (gensym) "#Af8500" 100 24 350 190 [10 10 3 3])
156 |
157 | (Block. (gensym) "#007F00" 60 20 100 250 [3 3 3 3])
158 |
159 | (Block. (gensym) "#007F00" 50 30 105 270 [0 0 0 0])
160 | (Block. (gensym) "#007F00" 200 150 800 270 [0 10 0 0])
161 | (Reward. (gensym) 12 16 400 120 )
162 | (Reward. (gensym) 12 16 300 190 )
163 | (Reward. (gensym) 12 16 500 190 )
164 | (Reward. (gensym) 12 16 900 190 )
165 | (BadGuy. (gensym) 24 24 400 220 -1.5 0)]
166 | [(TextPrompt. "start" 100 50 "Hit Enter" false {})]
167 | key-actions
168 | :paused))
169 |
170 | (def game (Game. {:world1 world} nil {:score 0 :health 3 :lives 10}))
171 |
172 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 | ;;
174 | ;; Run Game
175 | ;;
176 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 | (def message-bus (run-game game "myCanvas" :world1))
178 |
179 |
--------------------------------------------------------------------------------
/examples/mario/test/mario/core_test.clj:
--------------------------------------------------------------------------------
1 | (ns mario.core-test
2 | (:require [clojure.test :refer :all]
3 | [mario.core :refer :all]))
4 |
5 | (deftest a-test
6 | (testing "FIXME, I fail."
7 | (is (= 0 1))))
8 |
--------------------------------------------------------------------------------
/project.clj:
--------------------------------------------------------------------------------
1 | (defproject peli "0.1.0-SNAPSHOT"
2 | :description "simple 2d game engine"
3 | :license {:name "Eclipse Public License"
4 | :url "http://www.eclipse.org/legal/epl-v10.html"}
5 | :dependencies [[org.clojure/clojure "1.5.1"]
6 | [org.clojure/clojurescript "0.0-2138"]
7 | [org.clojure/core.async "0.1.267.0-0d7780-alpha"]]
8 | :source-paths ["src"]
9 | :test-paths ["test"]
10 | :profiles {:dev {:plugins [[com.cemerick/austin "0.1.3"]
11 | [com.cemerick/clojurescript.test "0.2.1"]
12 | [lein-cljsbuild "1.0.2"]]
13 | :cljsbuild {:builds [{
14 | :source-paths ["src" "test"]
15 | :compiler {
16 | :output-to "target/main.js"
17 | :optimizations :whitespace
18 | :pretty-print true}
19 | }]
20 | :test-commands {"unit-tests" ["phantomjs"
21 | :runner
22 | "target/main.js"]}}}})
23 |
24 |
--------------------------------------------------------------------------------
/src/peli/engine.cljs:
--------------------------------------------------------------------------------
1 | (ns peli.engine
2 | (:require [cljs.core.async :refer (timeout put! chan)])
3 | (:require-macros [cljs.core.async.macros :refer (go go-loop)]))
4 |
5 | (declare overlap?)
6 |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 | ;;
9 | ;; GAME DATA STRUCTURE
10 | ;;
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 |
13 | (defrecord World [board frame bodies overlays key-actions run-state])
14 |
15 | (defrecord Game [worlds active-world state])
16 |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 | ;;
19 | ;; PROTOCOLS
20 | ;;
21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 |
23 | (defprotocol Gravity
24 | (gravity [this ch state]))
25 |
26 | (defprotocol Physics
27 | (physics [this time-diff board ch state]))
28 |
29 | (defprotocol Pen
30 | (draw [this ctx frame ch state]))
31 |
32 | (defprotocol Collision
33 | (collide [this body ch state]))
34 |
35 | (defprotocol Framed
36 | (adjust-frame? [this]))
37 |
38 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 | ;;
40 | ;; DEFAULT IMPLS
41 | ;;
42 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 |
44 | (extend-protocol Physics
45 | object
46 | (physics [this time-diff board ch state] this))
47 |
48 | (extend-protocol Gravity
49 | object
50 | (gravity [this ch state] this))
51 |
52 | (extend-protocol Pen
53 | object
54 | (draw [this ctx frame ch state] this))
55 |
56 | (extend-protocol Collision
57 | object
58 | (collide [this body ch state] this))
59 |
60 | (extend-protocol Framed
61 | object
62 | (adjust-frame? [this] false))
63 |
64 |
65 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 | ;;
67 | ;; HELPER FUNCTIONS
68 | ;;
69 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 |
71 | (defn overlap? [body1 body2]
72 | (let [{:keys [x y width height]} body1
73 | {x2 :x y2 :y h2 :height w2 :width} body2
74 | [lx ly] [(+ x width) (+ y height)]
75 | [lx2 ly2] [(+ x2 w2) (+ y2 h2)]]
76 | (and (> lx x2) (<= x lx2)
77 | (> ly y2) (<= y ly2))))
78 |
79 |
80 | (defn check-bounds [n offset min max]
81 | (cond
82 | (< n min) min
83 | (> (+ n offset) max) (- n (- (+ n offset) max))
84 | :else n))
85 |
86 |
87 | (defn translate-coords [obj frame]
88 | (assoc obj :x (- (:x obj) (:x frame))
89 | :y (- (:y obj) (:y frame))))
90 |
91 |
92 | (defn apply-gravity [obj]
93 | (let [vy (:vy obj)]
94 | (assoc obj :vy (if (> vy -5) (- vy 0.2) vy))))
95 |
96 |
97 | (defn apply-physics [obj time-dif board]
98 | (let [{:keys [height width x y vx vy]} obj]
99 | (assoc obj :x (check-bounds (+ x vx) width 0 (:width board))
100 | :y (check-bounds (- y vy) height 0 (:height board)))))
101 |
102 |
103 | (defn collide-action [{:keys [height width x y vx vy] :as body1}
104 | {x2 :x y2 :y h2 :height w2 :width :as body2}
105 | actions]
106 | (let [ox (- x vx)
107 | oy (+ y vy)
108 | ox2 (- x2 (get body2 :vx 0))
109 | oy2 (+ y2 (get body2 :vy 0))
110 | [lx ly] [(+ ox width) (+ oy height)]
111 | [lx2 ly2] [(+ ox2 w2) (+ oy2 h2)]]
112 | (cond-> body1
113 | (and (<= ly oy2) (:bottom actions)) ((:bottom actions))
114 | (and (<= lx ox2) (:right actions)) ((:right actions))
115 | (and (>= oy ly2) (:top actions)) ((:top actions))
116 | (and (>= ox lx2) (:left actions)) ((:left actions))
117 | (and (:any actions)
118 | (or (<= ly oy2) (<= lx ox2)
119 | (>= oy ly2) (>= ox lx2))) ((:any actions)))))
120 |
121 |
122 | (defn collide-solid [{:keys [height width x y vx vy] :as body1}
123 | {x2 :x y2 :y h2 :height w2 :width :as body2}]
124 | (collide-action body1 body2
125 | {:bottom #(assoc % :y (- y2 height 0.1) :vy 0)
126 | :right #(assoc % :x (- x2 width 0.1))
127 | :top #(assoc % :y (+ y2 h2 0.1) :vy 0)
128 | :left #(assoc % :x (+ x2 w2 0.1))}))
129 |
130 | (defn remove-item [w type id]
131 | (assoc w type (vec (filter #(not= id (:id %)) (type w)))))
132 |
133 | (defn remove-body [w id] (remove-item w :bodies id))
134 |
135 | (defn remove-overlay [w id] (remove-item w :overlays id))
136 |
137 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 | ;;
139 | ;; COMMON BUIDLING MATERIALS
140 | ;;
141 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
142 |
143 | (defrecord Block [id fill width height x y radii]
144 | Pen
145 | (draw [this ctx frame ch state]
146 | (let [{:keys [width height color x y radii]} (translate-coords this frame)
147 | r (+ x width)
148 | b (+ y height)
149 | [ul ur lr ll] (or radii [0 0 0 0])]
150 | (if (string? fill)
151 | (set! (.-fillStyle ctx) fill)
152 | (let [pattern (.createPattern ctx fill, "repeat")]
153 | (set! (.-fillStyle ctx) pattern)))
154 | (doto ctx
155 | (.beginPath)
156 | (.moveTo (+ x ul) y)
157 | (.lineTo (- r ur) y)
158 | (.quadraticCurveTo r y r (+ y ur))
159 | (.lineTo r (- b lr))
160 | (.quadraticCurveTo r b (- r lr) b)
161 | (.lineTo (+ x ll) b)
162 | (.quadraticCurveTo x b x (- b ll))
163 | (.lineTo x (+ y ul))
164 | (.quadraticCurveTo x y (+ x ul) y)
165 | (.closePath)
166 | (.fill)))))
167 |
168 | (defrecord TextPrompt [id width height text hidden? options]
169 | Pen
170 | (draw [this ctx frame ch state]
171 | (when-not (:hidden? this)
172 | (let [[x y] [(/ (- (:width frame) width) 2)
173 | (/ (- (:height frame) height) 2)]]
174 | (set! (.-fillStyle ctx) (get options :background-color "#cfcfcf"))
175 | (.fillRect ctx x y width height)
176 | (set! (.-strokeStyle ctx) (get options :border-color "#000099"))
177 | (set! (.-lineWidth ctx) 2)
178 | (.strokeRect ctx x y width height)
179 | (set! (.-textBaseline ctx) "middle")
180 | (set! (.-font ctx) (get options :font "12px Arial"))
181 | (set! (.-fillStyle ctx) (get options :font-color "#000099"))
182 | (let [[tx ty] [(+ x (- (/ width 2)
183 | (/ (.-width (.measureText ctx text)) 2)))
184 | (+ y (/ height 2))]]
185 | (.fillText ctx text tx ty))))))
186 |
187 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 | ;;
189 | ;; MAIN ENGINE
190 | ;;
191 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 |
193 | (defn play-sound [id]
194 | (.play (.getElementById js/document id)))
195 |
196 |
197 | (defn handle-collision [body bodies ch state]
198 | (reduce #(collide %1 %2 ch state)
199 | body (filter #(and (not= (:id body) (:id %))
200 | (overlap? body %))
201 | bodies)))
202 |
203 | (defn run-physics [world ch state]
204 | (let [{fx :x fy :y fw :width fh :height} (:frame world)
205 | nx (- fx (/ fw 2))
206 | nw (* fw 2)
207 | ny (- fy (/ fh 2))
208 | nh (* fh 2)
209 | expanded-frame {:x nx :y ny :width nw :height nh}
210 | nbodies (for [body (:bodies world)]
211 | (if (overlap? body expanded-frame)
212 | (-> body
213 | (gravity ch state)
214 | (physics 0 (:board world) ch state))
215 | body))]
216 | (assoc world :bodies
217 | (vec (for [body nbodies]
218 | (handle-collision body (filter #(overlap? % expanded-frame)
219 | nbodies) ch state))))))
220 |
221 |
222 | (defn draw-world [world ctx ch state]
223 | (set! (.-fillStyle ctx) (get-in world [:board :color]))
224 | (.fillRect ctx 0 0 (get-in world [:frame :width])
225 | (get-in world [:frame :height]))
226 | (doseq [body (:bodies world)]
227 | (if (overlap? body (:frame world))
228 | (draw body ctx (:frame world) ch state)))
229 | (doseq [overlay (:overlays world)]
230 | (draw overlay ctx (:frame world) ch state))
231 | world)
232 |
233 |
234 | (defn get-key-code [event]
235 | (let [e (if event event (.-event js/window))
236 | code (.-keyCode e)]
237 | (if (and (.-charCode e) (= code 0))
238 | (.-charCode e)
239 | code)))
240 |
241 |
242 | (defn handle-keys [ch actions]
243 | (let [on-down (set (filter #(:on-down (get actions %)) (keys actions)))
244 | on-up (set (filter #(:on-up (get actions %)) (keys actions)))]
245 | (set! (.-onkeydown js/document)
246 | #(let [code (get-key-code %)]
247 | (if (on-down code)
248 | (put! ch {:action :edit-world
249 | :fn (get-in actions [code :on-down])}))))
250 | (set! (.-onkeyup js/document)
251 | #(let [code (get-key-code %)]
252 | (if (on-up code)
253 | (put! ch {:action :edit-world
254 | :fn (get-in actions [code :on-up])}))))))
255 |
256 |
257 |
258 | (defn adjust-frame [world]
259 | (let [{:keys [x y width height buffer]} (:frame world)
260 | dw (or buffer (* width .2))
261 | dh (or buffer (* height .2))
262 | tx (+ x dw)
263 | lx (- (+ x width) dw)
264 | ty (+ y dh)
265 | ly (- (+ y height) dh)
266 | {hx :x hy :y} (first (filter adjust-frame? (:bodies world)))
267 | nworld (assoc world :frame
268 | (cond-> (:frame world)
269 | (< hx tx) (assoc :x (- x (- tx hx)))
270 | (> hx lx) (assoc :x (+ x (- hx lx)))
271 | (< hy ty) (assoc :y (- y (- ty hy)))
272 | (> hy ly) (assoc :y (+ y (- hy ly)))))
273 | {:keys [x y width height]} (:frame nworld)]
274 | (assoc nworld :frame
275 | (assoc (:frame nworld)
276 | :x (check-bounds x width 0 (get-in nworld [:board :width]))
277 | :y (check-bounds y height 0 (get-in nworld [:board :height]))))))
278 |
279 |
280 | (defn draw-action [ch world state ctx]
281 | (if (= (:run-state world) :paused)
282 | (-> world
283 | (adjust-frame)
284 | (draw-world ctx ch state))
285 | (-> world
286 | (run-physics ch state)
287 | (adjust-frame)
288 | (draw-world ctx ch state))))
289 |
290 |
291 | (defn schedule-edit
292 | ([f ch timing] (schedule-edit f ch timing nil))
293 | ([f ch timing type]
294 | (let [action (or type :edit-world)]
295 | (go (