├── .classpath
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── COPYING
├── README
├── default.properties
├── proguard.cfg
├── res
├── drawable-hdpi
│ └── icon.png
├── drawable-ldpi
│ └── icon.png
├── drawable-mdpi
│ ├── grass2.png
│ ├── icon.png
│ ├── mario.png
│ ├── walk.png
│ └── worm2.png
├── drawable-nodpi
│ ├── dirt.png
│ ├── flower.png
│ ├── grass.png
│ ├── maincharacter.png
│ ├── mario.png
│ ├── plant.png
│ ├── rock.png
│ ├── sand.png
│ ├── tree.png
│ ├── walk.png
│ ├── water1.png
│ ├── water2.png
│ ├── water3.png
│ ├── world_map.jpg
│ └── worm2.png
├── layout
│ ├── home.xml
│ └── main.xml
└── values
│ └── strings.xml
├── src
└── com
│ └── kylepaulsen
│ └── openAndroidGame
│ ├── BaseTiles.java
│ ├── Biome.java
│ ├── Constants.java
│ ├── CopyOfPlayer.java
│ ├── GameProgram.java
│ ├── GraphicsView.java
│ ├── Home.java
│ ├── LocationTask.java
│ ├── MainActivity.java
│ ├── Monster.java
│ ├── Player.java
│ ├── PlayerAnimated.java
│ ├── Tile.java
│ ├── World.java
│ └── WorldEnt.java
└── worldMapLatLongToPixel.txt
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #java specific
2 | *.class
3 |
4 |
5 | ## generic files to ignore
6 | *~
7 | *.lock
8 | *.DS_Store
9 | *.swp
10 | *.out
11 |
12 | # ignore generated folders
13 | /bin/
14 | /gen/
15 |
16 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | OpenAndroidGame
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jul 06 19:38:47 PDT 2011
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | ';[p=-[pp]]
29 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | Open-Android-Game Copyright © 2011 Open-Android-Game Group
2 | The Open-Android-Game Group consists of:
3 | Kyle Paulsen
4 | Ryan Souza
5 | Xiaolong Cheng
6 | Max Strater
7 |
8 | Licence terms:
9 |
10 | GNU GENERAL PUBLIC LICENSE
11 | Version 2, June 1991
12 |
13 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 | Everyone is permitted to copy and distribute verbatim copies
16 | of this license document, but changing it is not allowed.
17 |
18 | Preamble
19 |
20 | The licenses for most software are designed to take away your
21 | freedom to share and change it. By contrast, the GNU General Public
22 | License is intended to guarantee your freedom to share and change free
23 | software--to make sure the software is free for all its users. This
24 | General Public License applies to most of the Free Software
25 | Foundation's software and to any other program whose authors commit to
26 | using it. (Some other Free Software Foundation software is covered by
27 | the GNU Lesser General Public License instead.) You can apply it to
28 | your programs, too.
29 |
30 | When we speak of free software, we are referring to freedom, not
31 | price. Our General Public Licenses are designed to make sure that you
32 | have the freedom to distribute copies of free software (and charge for
33 | this service if you wish), that you receive source code or can get it
34 | if you want it, that you can change the software or use pieces of it
35 | in new free programs; and that you know you can do these things.
36 |
37 | To protect your rights, we need to make restrictions that forbid
38 | anyone to deny you these rights or to ask you to surrender the rights.
39 | These restrictions translate to certain responsibilities for you if you
40 | distribute copies of the software, or if you modify it.
41 |
42 | For example, if you distribute copies of such a program, whether
43 | gratis or for a fee, you must give the recipients all the rights that
44 | you have. You must make sure that they, too, receive or can get the
45 | source code. And you must show them these terms so they know their
46 | rights.
47 |
48 | We protect your rights with two steps: (1) copyright the software, and
49 | (2) offer you this license which gives you legal permission to copy,
50 | distribute and/or modify the software.
51 |
52 | Also, for each author's protection and ours, we want to make certain
53 | that everyone understands that there is no warranty for this free
54 | software. If the software is modified by someone else and passed on, we
55 | want its recipients to know that what they have is not the original, so
56 | that any problems introduced by others will not reflect on the original
57 | authors' reputations.
58 |
59 | Finally, any free program is threatened constantly by software
60 | patents. We wish to avoid the danger that redistributors of a free
61 | program will individually obtain patent licenses, in effect making the
62 | program proprietary. To prevent this, we have made it clear that any
63 | patent must be licensed for everyone's free use or not licensed at all.
64 |
65 | The precise terms and conditions for copying, distribution and
66 | modification follow.
67 |
68 | GNU GENERAL PUBLIC LICENSE
69 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
70 |
71 | 0. This License applies to any program or other work which contains
72 | a notice placed by the copyright holder saying it may be distributed
73 | under the terms of this General Public License. The "Program", below,
74 | refers to any such program or work, and a "work based on the Program"
75 | means either the Program or any derivative work under copyright law:
76 | that is to say, a work containing the Program or a portion of it,
77 | either verbatim or with modifications and/or translated into another
78 | language. (Hereinafter, translation is included without limitation in
79 | the term "modification".) Each licensee is addressed as "you".
80 |
81 | Activities other than copying, distribution and modification are not
82 | covered by this License; they are outside its scope. The act of
83 | running the Program is not restricted, and the output from the Program
84 | is covered only if its contents constitute a work based on the
85 | Program (independent of having been made by running the Program).
86 | Whether that is true depends on what the Program does.
87 |
88 | 1. You may copy and distribute verbatim copies of the Program's
89 | source code as you receive it, in any medium, provided that you
90 | conspicuously and appropriately publish on each copy an appropriate
91 | copyright notice and disclaimer of warranty; keep intact all the
92 | notices that refer to this License and to the absence of any warranty;
93 | and give any other recipients of the Program a copy of this License
94 | along with the Program.
95 |
96 | You may charge a fee for the physical act of transferring a copy, and
97 | you may at your option offer warranty protection in exchange for a fee.
98 |
99 | 2. You may modify your copy or copies of the Program or any portion
100 | of it, thus forming a work based on the Program, and copy and
101 | distribute such modifications or work under the terms of Section 1
102 | above, provided that you also meet all of these conditions:
103 |
104 | a) You must cause the modified files to carry prominent notices
105 | stating that you changed the files and the date of any change.
106 |
107 | b) You must cause any work that you distribute or publish, that in
108 | whole or in part contains or is derived from the Program or any
109 | part thereof, to be licensed as a whole at no charge to all third
110 | parties under the terms of this License.
111 |
112 | c) If the modified program normally reads commands interactively
113 | when run, you must cause it, when started running for such
114 | interactive use in the most ordinary way, to print or display an
115 | announcement including an appropriate copyright notice and a
116 | notice that there is no warranty (or else, saying that you provide
117 | a warranty) and that users may redistribute the program under
118 | these conditions, and telling the user how to view a copy of this
119 | License. (Exception: if the Program itself is interactive but
120 | does not normally print such an announcement, your work based on
121 | the Program is not required to print an announcement.)
122 |
123 | These requirements apply to the modified work as a whole. If
124 | identifiable sections of that work are not derived from the Program,
125 | and can be reasonably considered independent and separate works in
126 | themselves, then this License, and its terms, do not apply to those
127 | sections when you distribute them as separate works. But when you
128 | distribute the same sections as part of a whole which is a work based
129 | on the Program, the distribution of the whole must be on the terms of
130 | this License, whose permissions for other licensees extend to the
131 | entire whole, and thus to each and every part regardless of who wrote it.
132 |
133 | Thus, it is not the intent of this section to claim rights or contest
134 | your rights to work written entirely by you; rather, the intent is to
135 | exercise the right to control the distribution of derivative or
136 | collective works based on the Program.
137 |
138 | In addition, mere aggregation of another work not based on the Program
139 | with the Program (or with a work based on the Program) on a volume of
140 | a storage or distribution medium does not bring the other work under
141 | the scope of this License.
142 |
143 | 3. You may copy and distribute the Program (or a work based on it,
144 | under Section 2) in object code or executable form under the terms of
145 | Sections 1 and 2 above provided that you also do one of the following:
146 |
147 | a) Accompany it with the complete corresponding machine-readable
148 | source code, which must be distributed under the terms of Sections
149 | 1 and 2 above on a medium customarily used for software interchange; or,
150 |
151 | b) Accompany it with a written offer, valid for at least three
152 | years, to give any third party, for a charge no more than your
153 | cost of physically performing source distribution, a complete
154 | machine-readable copy of the corresponding source code, to be
155 | distributed under the terms of Sections 1 and 2 above on a medium
156 | customarily used for software interchange; or,
157 |
158 | c) Accompany it with the information you received as to the offer
159 | to distribute corresponding source code. (This alternative is
160 | allowed only for noncommercial distribution and only if you
161 | received the program in object code or executable form with such
162 | an offer, in accord with Subsection b above.)
163 |
164 | The source code for a work means the preferred form of the work for
165 | making modifications to it. For an executable work, complete source
166 | code means all the source code for all modules it contains, plus any
167 | associated interface definition files, plus the scripts used to
168 | control compilation and installation of the executable. However, as a
169 | special exception, the source code distributed need not include
170 | anything that is normally distributed (in either source or binary
171 | form) with the major components (compiler, kernel, and so on) of the
172 | operating system on which the executable runs, unless that component
173 | itself accompanies the executable.
174 |
175 | If distribution of executable or object code is made by offering
176 | access to copy from a designated place, then offering equivalent
177 | access to copy the source code from the same place counts as
178 | distribution of the source code, even though third parties are not
179 | compelled to copy the source along with the object code.
180 |
181 | 4. You may not copy, modify, sublicense, or distribute the Program
182 | except as expressly provided under this License. Any attempt
183 | otherwise to copy, modify, sublicense or distribute the Program is
184 | void, and will automatically terminate your rights under this License.
185 | However, parties who have received copies, or rights, from you under
186 | this License will not have their licenses terminated so long as such
187 | parties remain in full compliance.
188 |
189 | 5. You are not required to accept this License, since you have not
190 | signed it. However, nothing else grants you permission to modify or
191 | distribute the Program or its derivative works. These actions are
192 | prohibited by law if you do not accept this License. Therefore, by
193 | modifying or distributing the Program (or any work based on the
194 | Program), you indicate your acceptance of this License to do so, and
195 | all its terms and conditions for copying, distributing or modifying
196 | the Program or works based on it.
197 |
198 | 6. Each time you redistribute the Program (or any work based on the
199 | Program), the recipient automatically receives a license from the
200 | original licensor to copy, distribute or modify the Program subject to
201 | these terms and conditions. You may not impose any further
202 | restrictions on the recipients' exercise of the rights granted herein.
203 | You are not responsible for enforcing compliance by third parties to
204 | this License.
205 |
206 | 7. If, as a consequence of a court judgment or allegation of patent
207 | infringement or for any other reason (not limited to patent issues),
208 | conditions are imposed on you (whether by court order, agreement or
209 | otherwise) that contradict the conditions of this License, they do not
210 | excuse you from the conditions of this License. If you cannot
211 | distribute so as to satisfy simultaneously your obligations under this
212 | License and any other pertinent obligations, then as a consequence you
213 | may not distribute the Program at all. For example, if a patent
214 | license would not permit royalty-free redistribution of the Program by
215 | all those who receive copies directly or indirectly through you, then
216 | the only way you could satisfy both it and this License would be to
217 | refrain entirely from distribution of the Program.
218 |
219 | If any portion of this section is held invalid or unenforceable under
220 | any particular circumstance, the balance of the section is intended to
221 | apply and the section as a whole is intended to apply in other
222 | circumstances.
223 |
224 | It is not the purpose of this section to induce you to infringe any
225 | patents or other property right claims or to contest validity of any
226 | such claims; this section has the sole purpose of protecting the
227 | integrity of the free software distribution system, which is
228 | implemented by public license practices. Many people have made
229 | generous contributions to the wide range of software distributed
230 | through that system in reliance on consistent application of that
231 | system; it is up to the author/donor to decide if he or she is willing
232 | to distribute software through any other system and a licensee cannot
233 | impose that choice.
234 |
235 | This section is intended to make thoroughly clear what is believed to
236 | be a consequence of the rest of this License.
237 |
238 | 8. If the distribution and/or use of the Program is restricted in
239 | certain countries either by patents or by copyrighted interfaces, the
240 | original copyright holder who places the Program under this License
241 | may add an explicit geographical distribution limitation excluding
242 | those countries, so that distribution is permitted only in or among
243 | countries not thus excluded. In such case, this License incorporates
244 | the limitation as if written in the body of this License.
245 |
246 | 9. The Free Software Foundation may publish revised and/or new versions
247 | of the General Public License from time to time. Such new versions will
248 | be similar in spirit to the present version, but may differ in detail to
249 | address new problems or concerns.
250 |
251 | Each version is given a distinguishing version number. If the Program
252 | specifies a version number of this License which applies to it and "any
253 | later version", you have the option of following the terms and conditions
254 | either of that version or of any later version published by the Free
255 | Software Foundation. If the Program does not specify a version number of
256 | this License, you may choose any version ever published by the Free Software
257 | Foundation.
258 |
259 | 10. If you wish to incorporate parts of the Program into other free
260 | programs whose distribution conditions are different, write to the author
261 | to ask for permission. For software which is copyrighted by the Free
262 | Software Foundation, write to the Free Software Foundation; we sometimes
263 | make exceptions for this. Our decision will be guided by the two goals
264 | of preserving the free status of all derivatives of our free software and
265 | of promoting the sharing and reuse of software generally.
266 |
267 | NO WARRANTY
268 |
269 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
270 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
271 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
272 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
273 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
274 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
275 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
276 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
277 | REPAIR OR CORRECTION.
278 |
279 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
280 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
281 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
282 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
283 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
284 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
285 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
286 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
287 | POSSIBILITY OF SUCH DAMAGES.
288 |
289 | END OF TERMS AND CONDITIONS
290 |
291 | How to Apply These Terms to Your New Programs
292 |
293 | If you develop a new program, and you want it to be of the greatest
294 | possible use to the public, the best way to achieve this is to make it
295 | free software which everyone can redistribute and change under these terms.
296 |
297 | To do so, attach the following notices to the program. It is safest
298 | to attach them to the start of each source file to most effectively
299 | convey the exclusion of warranty; and each file should have at least
300 | the "copyright" line and a pointer to where the full notice is found.
301 |
302 |
303 | Copyright (C)
304 |
305 | This program is free software; you can redistribute it and/or modify
306 | it under the terms of the GNU General Public License as published by
307 | the Free Software Foundation; either version 2 of the License, or
308 | (at your option) any later version.
309 |
310 | This program is distributed in the hope that it will be useful,
311 | but WITHOUT ANY WARRANTY; without even the implied warranty of
312 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
313 | GNU General Public License for more details.
314 |
315 | You should have received a copy of the GNU General Public License along
316 | with this program; if not, write to the Free Software Foundation, Inc.,
317 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
318 |
319 | Also add information on how to contact you by electronic and paper mail.
320 |
321 | If the program is interactive, make it output a short notice like this
322 | when it starts in an interactive mode:
323 |
324 | Gnomovision version 69, Copyright (C) year name of author
325 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
326 | This is free software, and you are welcome to redistribute it
327 | under certain conditions; type `show c' for details.
328 |
329 | The hypothetical commands `show w' and `show c' should show the appropriate
330 | parts of the General Public License. Of course, the commands you use may
331 | be called something other than `show w' and `show c'; they could even be
332 | mouse-clicks or menu items--whatever suits your program.
333 |
334 | You should also get your employer (if you work as a programmer) or your
335 | school, if any, to sign a "copyright disclaimer" for the program, if
336 | necessary. Here is a sample; alter the names:
337 |
338 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
339 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
340 |
341 | , 1 April 1989
342 | Ty Coon, President of Vice
343 |
344 | This General Public License does not permit incorporating your program into
345 | proprietary programs. If your program is a subroutine library, you may
346 | consider it more useful to permit linking proprietary applications with the
347 | library. If this is what you want to do, use the GNU Lesser General
348 | Public License instead of this License.
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Open-Android-Game Copyright © 2011 Open-Android-Game Group
2 | The Open-Android-Game Group consists of:
3 | Kyle Paulsen
4 | Ryan Souza
5 | Xiaolong Cheng
6 | Max Strater
7 |
8 | This is our Open Android Game.
9 | It it built on the Android 2.1 Platform.
10 |
11 | BUILD INSTRUCTIONS
12 | ========================================
13 |
14 | It really helps if you have an android phone - this is an android app after
15 | all.
16 |
17 | * First you need the android SDK. You can get it here:
18 | http://developer.android.com/sdk/index.html
19 | Download the correct one for your system.
20 |
21 | * This guide is very detailed about how to set things up:
22 | http://developer.android.com/sdk/installing.html
23 | Make sure you follow steps 1-4 carefully as they are the most important.
24 | On step 4 make sure you check SDK Platform Android 2.1
25 |
26 | * Import the project into Eclipse.
27 | File->Import General->"Existing Projects Into Workspace"
28 |
29 | * At this point you should be able to build (Run -> Run).
30 | If you are getting tons of errors then eclipse isn't looking in the
31 | correct place for some libraries. You will need to find the correct
32 | JARs and add them to the list of Libraries for the project.
33 | Add them here:
34 | Project->Properties then... "Java Build Path" on the left
35 | and then the libraries tab near the top.
36 | The required libraries are:
37 | * Android.jar in the android 7 directory somewhere in the sdk directory.
38 | * JRE System Library
39 |
40 | * If you build and run in the emulator right away, the app will probably crash
41 | due to insufficient memory. This is why it's important to run using your own
42 | device. Even if the emulator doesn't crash, it might run extremely slow to a
43 | point where the game is unplayable. Use this guide to set up your device to
44 | run the build:
45 | http://developer.android.com/guide/developing/device.html#setting-up
46 | You don't need to do step 1 of this guide as it was already done.
47 |
48 |
49 | ABOUT
50 | ========================================
51 |
52 | So far this game is a top down 2D scroller - as in the player has a bird's
53 | eye view of his character and the world around him. This game is to become
54 | somewhat of a exploration/creation/survival game. Hopefully, in the future,
55 | all 3 of these themes will be an integral part of this game. Also hopefully,
56 | the game will have a title. One other thing we aim to do is procedurally
57 | generate all maps (and maybe other things) based on the player's
58 | GPS coordinates. All other ideas can be read about in our repository wiki.
59 |
60 |
--------------------------------------------------------------------------------
/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-7
12 |
--------------------------------------------------------------------------------
/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/grass2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-mdpi/grass2.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/mario.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-mdpi/mario.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/walk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-mdpi/walk.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/worm2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-mdpi/worm2.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/dirt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/dirt.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/flower.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/flower.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/grass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/grass.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/maincharacter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/maincharacter.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/mario.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/mario.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/plant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/plant.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/rock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/rock.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/sand.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/sand.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/tree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/tree.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/walk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/walk.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/water1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/water1.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/water2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/water2.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/water3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/water3.png
--------------------------------------------------------------------------------
/res/drawable-nodpi/world_map.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/world_map.jpg
--------------------------------------------------------------------------------
/res/drawable-nodpi/worm2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kylepaulsen/Open-Android-Game/757867e8170de270af54a2f4fea7e1af48558f96/res/drawable-nodpi/worm2.png
--------------------------------------------------------------------------------
/res/layout/home.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, MainActivity!
4 | OpenAndroidGame
5 | Play!
6 | Game Intro
7 |
8 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/BaseTiles.java:
--------------------------------------------------------------------------------
1 | /* BaseTiles.java - Class for loading and displaying just the tiles that show up.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import java.util.HashMap;
11 | import java.util.Vector;
12 |
13 | import android.graphics.Bitmap;
14 | import android.graphics.BitmapFactory;
15 | import android.graphics.Canvas;
16 | import android.graphics.Matrix;
17 | import android.graphics.Paint;
18 | import android.graphics.Point;
19 | import android.graphics.Rect;
20 | import android.content.Context;
21 | import android.content.res.Resources;
22 | import android.util.Log;
23 |
24 | public class BaseTiles {
25 | private Canvas canvas;
26 | private HashMap tileLib;
27 | private Bitmap buffer_cur, buffer_off;
28 | private boolean dirty;
29 | private Rect paint_pixel_extent;
30 | private Rect local_pixel_extent;
31 | //private int offset_x, offset_y;
32 | private Rect local_tile_extent;
33 | private Rect global_tile_extent;
34 |
35 | private Boolean load_new_tiles;
36 | private Thread loading;
37 | private volatile boolean loading_new_tiles;
38 |
39 | private byte[][] layer;
40 |
41 | //local tile extent dimension consts:
42 | //32
43 | private int TILE_WIDTH = 30, TILE_HEIGHT = 22;
44 | //private int TILE_WIDTH = 32, TILE_HEIGHT = 32;
45 |
46 | //private int BUFFER_PADDING = 1, BUFFER_SHIFT = 4;
47 | private int BUFFER_PADDING = 2, BUFFER_SHIFT = 5;
48 |
49 | //private Bitmap tile_bitmaps[];
50 |
51 | public BaseTiles(HashMap tileLib, World world){
52 | this.tileLib = tileLib;
53 | this.dirty = true;
54 | this.buffer_cur = Bitmap.createBitmap(TILE_WIDTH * Constants.WORLD_TILE_SIZE, TILE_HEIGHT * Constants.WORLD_TILE_SIZE, Bitmap.Config.ARGB_8888);
55 | this.buffer_off = Bitmap.createBitmap(TILE_WIDTH * Constants.WORLD_TILE_SIZE, TILE_HEIGHT * Constants.WORLD_TILE_SIZE, Bitmap.Config.ARGB_8888);
56 |
57 | this.canvas = new Canvas(this.buffer_cur);
58 | this.local_pixel_extent = new Rect(0, 0, Constants.WINDOW_WIDTH * 2 / 3, Constants.WINDOW_HEIGHT * 2 / 3);
59 | this.paint_pixel_extent = new Rect(0, 0, Constants.WINDOW_WIDTH, Constants.WINDOW_HEIGHT);
60 | //this.local_pixel_extent.offset(320, 320);
61 |
62 | this.local_tile_extent = new Rect(0, 0, 0, 0);
63 | this.global_tile_extent = new Rect(0, 0, TILE_WIDTH, TILE_HEIGHT);
64 | //this.global_tile_extent.offsetTo(10, 10);
65 | this.layer = world.getWorldArr();
66 |
67 | this.load_new_tiles = false;
68 | //loadTileBitmaps();
69 | drawInitialTiles();
70 | }
71 |
72 | /*
73 | private void loadTileBitmaps() {
74 | Resources rsc = context.getResources();
75 | tile_bitmaps = new Bitmap[4];
76 | tile_bitmaps[Constants.TILE_GRASS_ID] = BitmapFactory.decodeResource(rsc, R.drawable.grass);
77 | tile_bitmaps[Constants.TILE_DIRT_ID] = BitmapFactory.decodeResource(rsc, R.drawable.dirt);
78 | tile_bitmaps[Constants.TILE_SAND_ID] = BitmapFactory.decodeResource(rsc, R.drawable.sand);
79 | tile_bitmaps[Constants.TILE_WATER_ID] = BitmapFactory.decodeResource(rsc, R.drawable.water1);
80 |
81 |
82 |
83 | }*/
84 |
85 | public void render(Canvas c){
86 | synchronized(buffer_cur) {
87 | c.drawBitmap(buffer_cur, local_pixel_extent, paint_pixel_extent, null);
88 | }
89 | }
90 |
91 | private void drawInitialTiles() {
92 | drawAllTiles(canvas, global_tile_extent);
93 | }
94 |
95 | private void drawAllTiles(Canvas c, Rect g_extent) {
96 | for(int i = 0; i < TILE_WIDTH; ++i) {
97 | for(int j = 0; j < TILE_HEIGHT; ++j) {
98 | paintLocalCell(canvas, g_extent, i, j);
99 | }
100 | }
101 | }
102 |
103 | public void moveLocation(int dx, int dy) {
104 | local_pixel_extent.offset(dx, dy);
105 |
106 | synchronized(load_new_tiles) {
107 | if(load_new_tiles) return;
108 | }
109 |
110 | // Handle updating the local_tile_extent
111 | int ts = Constants.WORLD_TILE_SIZE;
112 |
113 | int top = local_pixel_extent.top / ts;
114 | int bottom = local_pixel_extent.bottom / ts + (local_pixel_extent.bottom % ts > 0 ? 1 : 0);
115 | int left = local_pixel_extent.left / ts;
116 | int right = local_pixel_extent.right / ts + (local_pixel_extent.right % ts > 0 ? 1 : 0);
117 |
118 | local_tile_extent.set(left, top, right, bottom);
119 | updateGlobalExtent();
120 | }
121 |
122 | private void updateGlobalExtent() {
123 | Rect l = local_tile_extent;
124 | boolean left=false, top=false, bottom=false, right=false;
125 |
126 | if(l.left < BUFFER_PADDING) left = true;
127 | if(l.top < BUFFER_PADDING) top = true;
128 | if(TILE_WIDTH - l.right < BUFFER_PADDING) right = true;
129 | if(TILE_HEIGHT - l.bottom < BUFFER_PADDING) bottom = true;
130 | // Move global extent
131 | if(left || top || bottom || right) {
132 | synchronized(load_new_tiles) {
133 | load_new_tiles = true;
134 | }
135 |
136 | int dx = 0, dy = 0;
137 |
138 | if(left) dx = -1 * BUFFER_SHIFT;
139 | else if(right) dx = 1 * BUFFER_SHIFT;
140 |
141 | if(top) dy = -1 * BUFFER_SHIFT;
142 | else if(bottom) dy = 1 * BUFFER_SHIFT;
143 |
144 | loading = new TileLoader(dx, dy);
145 | loading.start();
146 | //Log.d("check"," " + left + top + bottom + right);
147 |
148 |
149 | }
150 | }
151 |
152 | public void setLocationWorld(int tile_x, int tile_y) {
153 | Log.d("setlocation", "start");
154 | synchronized(load_new_tiles) {
155 | if(load_new_tiles) loading.stop();
156 | loading = null;
157 | }
158 |
159 | int w_half = TILE_WIDTH / 2;
160 | int h_half = TILE_HEIGHT / 2;
161 |
162 | Rect new_g_extent = new Rect(global_tile_extent);
163 | new_g_extent.offsetTo(w_half + tile_x, h_half + tile_y);
164 |
165 | Rect new_px_extent = new Rect(local_pixel_extent);
166 | new_px_extent.offsetTo(w_half * 32 + (TILE_WIDTH % 2) * 16, h_half * 32 + (TILE_HEIGHT % 2) * 16);
167 |
168 | synchronized(buffer_cur) {
169 | canvas.drawColor(0xFF000000);
170 | }
171 | Bitmap buffer = buffer_off;
172 | canvas.setBitmap(buffer);
173 | drawAllTiles(canvas, new_g_extent);
174 |
175 | synchronized(buffer_cur) {
176 | buffer_off = buffer_cur;
177 | buffer_cur = buffer;
178 | global_tile_extent = new_g_extent;
179 | local_pixel_extent = new_px_extent;
180 | }
181 |
182 | synchronized(load_new_tiles) {
183 | load_new_tiles = false;
184 | }
185 | Log.d("setlocation", "stop");
186 |
187 | }
188 |
189 | public void paintLocalCell(Canvas c, Rect g_extent, int x, int y) {
190 | byte cell_type = getLocalCellType(g_extent, x, y);
191 | int ts = Constants.WORLD_TILE_SIZE;
192 |
193 | if(cell_type > 0)
194 | canvas.drawBitmap(tileLib.get(cell_type).getBitmap(), x*ts, y*ts, null);
195 |
196 | /*
197 | // TODO: call paintCell(c, cell_type) to paint actual graphics
198 | int color = 0;
199 | if(cell_type == 0) color = 0xFFFFFFFF;
200 | if(cell_type == 1) color = 0xFF00FF00;
201 | if(cell_type == 2) color = 0xFFFF0000;
202 | if(cell_type == 3) color = 0xFF0000FF;
203 | if(cell_type == 4) color = 0xFFFFFF00;
204 | if(cell_type == 5) color = 0xFFFF00FF;
205 | if(cell_type == 6) color = 0xFF00FFFF;
206 | if(cell_type == 7) color = 0xFF000000;
207 |
208 | p.setStyle(Paint.Style.FILL);
209 | p.setColor(color);
210 | canvas.drawRect(x*ts, y*ts, x*ts+ts, y*ts+ts, p);
211 | p.setStyle(Paint.Style.STROKE);
212 | p.setColor(0xFF005500);
213 | canvas.drawRect(x*ts, y*ts, x*ts+ts, y*ts+ts, p);
214 | */
215 | }
216 |
217 | /*
218 | * Given the tile coords of the coord views
219 | */
220 | public byte getLocalCellType(Rect g_extent, int tile_x, int tile_y) {
221 | int x = tile_x + g_extent.left;
222 | int y = tile_y + g_extent.top;
223 |
224 | if(x > -1 && x < Constants.WORLD_SIZE && y > -1 && y < Constants.WORLD_SIZE){
225 | //if(layer[x][y] == 0)
226 | //return 1;
227 |
228 | return layer[x][y];
229 | //return (x+y)%8;
230 | }else{
231 | return Constants.TILE_WATER_ID;
232 | }
233 | }
234 |
235 | public Point getCenterLocation(){
236 | int w_half = TILE_WIDTH / 2;
237 | int h_half = TILE_HEIGHT / 2;
238 |
239 | synchronized(buffer_cur) {
240 | int x = (int)Math.floor(local_pixel_extent.exactCenterX()/Constants.WORLD_TILE_SIZE)-w_half+(int)Math.floor(global_tile_extent.exactCenterX());
241 | int y = (int)Math.floor(local_pixel_extent.exactCenterY()/Constants.WORLD_TILE_SIZE)-h_half+(int)Math.floor(global_tile_extent.exactCenterY());
242 | return new Point(x, y);
243 | }
244 | }
245 |
246 | public Point getPixelsInTile(){
247 | synchronized(buffer_cur) {
248 | int x = (int)(local_pixel_extent.exactCenterX()%Constants.WORLD_TILE_SIZE);
249 | int y = (int)(local_pixel_extent.exactCenterY()%Constants.WORLD_TILE_SIZE);
250 | return new Point(x, y);
251 | }
252 | }
253 |
254 | public Point getstuff(){
255 | int x = local_pixel_extent.top;
256 | int y = local_pixel_extent.left;
257 | return new Point(x, y);
258 | }
259 |
260 | private class TileLoader extends Thread{
261 | Rect new_extent;
262 | int dx, dy;
263 |
264 | public TileLoader(int dx, int dy){
265 | super();
266 | this.dx = dx;
267 | this.dy = dy;
268 | new_extent = new Rect(global_tile_extent);
269 | new_extent.offset(dx, dy);
270 | }
271 |
272 | @Override
273 | public void run() {
274 | // TODO Auto-generated method stub
275 | //super.run();
276 |
277 | int ts = Constants.WORLD_TILE_SIZE;
278 |
279 | Rect old_extent = global_tile_extent;
280 | Bitmap buffer = buffer_off;
281 | canvas.setBitmap(buffer);
282 |
283 | // Draw the old buffer on the new one, shifted
284 | canvas.drawColor(0xFF000000);
285 | canvas.drawBitmap(buffer_cur,-1 * dx * ts, -1 * dy * ts, null);
286 | // That is for painting the still okay tiles
287 |
288 | // TODO: Replace this
289 | // Instead of drawing all tiles draw just draw the new ones
290 | // dx is the change in x, dy in y
291 | //TODO: drawEdgeTiles(dx, dy, new_extent, canvas)
292 | //call paintlocaltile(canvas_extent, local_x, local_y);
293 |
294 | // START
295 | drawAllTiles(canvas, new_extent);
296 | // END
297 |
298 | Rect new_px_extent = new Rect(local_pixel_extent);
299 | new_px_extent.offset(-1 * dx * ts, -1 * dy * ts);
300 |
301 |
302 | synchronized(buffer_cur) {
303 | buffer_off = buffer_cur;
304 | buffer_cur = buffer;
305 | global_tile_extent = new_extent;
306 | local_pixel_extent = new_px_extent;
307 | }
308 |
309 | synchronized(load_new_tiles) {
310 | load_new_tiles = false;
311 | }
312 | }
313 |
314 | }
315 | }
316 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Biome.java:
--------------------------------------------------------------------------------
1 | /* Biome.java - Class for describing biomes.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.content.Context;
11 | import android.graphics.Bitmap;
12 | import android.graphics.BitmapFactory;
13 | import android.graphics.Color;
14 | import android.widget.Toast;
15 |
16 | /*
17 | * This class is for describing biomes with lots of public vars...
18 | * It gets information from the world_map.jpg pixel data.
19 | */
20 | public class Biome {
21 | Context con;
22 | double lat, lon;
23 | int lonPxl, latPxl;
24 |
25 |
26 | public Biome(Context context, double latitude, double longitude){
27 | this.con = context;
28 | this.lat = latitude;
29 | this.lon = longitude;
30 | }
31 |
32 | //This function will set a bunch of public vars to describe
33 | //the current biome for the world generator.
34 | public float[] anazlyze(){
35 | //get the corresponding pixel.
36 | this.lonPxl = lonToPxlX(this.lon);
37 | this.latPxl = latToPxlY(this.lat);
38 |
39 | //The options code is very important so make sure we read a correct pixel value.
40 | BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
41 | decodeOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
42 |
43 | //get the pixel color in the world map.
44 |
45 | //THIS IS PROBLY CAUSING MEMORY TO RUN OUT ON SOME PHONES! NEED TO FIGURE OUT HOW TO GET BIOME
46 | //DATA FROM A SMALLER IMAGE OR ANOTHER WAY!!!
47 | //Bitmap world = BitmapFactory.decodeResource(con.getResources(), R.drawable.world_map, decodeOptions);
48 | //int landColor = world.getPixel(this.lonPxl, this.latPxl);
49 | //int red = Color.red(landColor);
50 | //int green = Color.green(landColor);
51 | //int blue = Color.blue(landColor);
52 |
53 |
54 | //Toast.makeText(con, "looking for pxl: "+this.lonPxl+", "+this.latPxl, Toast.LENGTH_LONG).show();
55 | //Toast.makeText(con, "Pxl rgb is: "+Color.red(landColor)+", "+Color.green(landColor)+", "+Color.blue(landColor), Toast.LENGTH_LONG).show();
56 |
57 | //get hsv
58 | float hsv[] = new float[3];
59 | //Color.RGBToHSV(red, green, blue, hsv);
60 |
61 | return hsv;
62 | //now if the h in hsv is between certain ranges, we have a biome.
63 | //we could also use r, g, b, s or v for something.
64 | }
65 |
66 | public int latToPxlY(double lat){
67 | //formula found in worldMapLatLongToPixel.txt
68 | return (int) (Math.floor(lat/-0.06698049772278683227848101265823) + 1351);
69 | }
70 |
71 | public int lonToPxlX(double lon){
72 | //formula found in worldMapLatLongToPixel.txt
73 | return (int) (Math.floor(lon/0.06657861654370824053452115812918) + 2697);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Constants.java:
--------------------------------------------------------------------------------
1 | /* Constants.java - Class for random game constants.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | public final class Constants {
11 | //Window height and width get set in MainActivity.
12 | public static int WINDOW_HEIGHT;
13 | public static int WINDOW_WIDTH;
14 |
15 | //Base Game Constants
16 | public final static int GAME_TARGET_FPS = 20;
17 | //World Region Size
18 | public final static int WORLD_SIZE = 140;
19 | //World Tile Size
20 | public final static int WORLD_TILE_SIZE = 32;
21 | //Camera Default Move Speed
22 | public final static int DEFAULT_CAM_MOVE_SPEED = 1;
23 |
24 | //Player Constants
25 | public final static int PLAYER_BOUNDING_BOX_RADIUS = 15;
26 |
27 | //World Tile Constants
28 | public final static byte TILE_AIR_ID = 0;
29 | public final static byte TILE_GRASS_ID = 1;
30 | public final static byte TILE_DIRT_ID = 2;
31 | public final static byte TILE_SAND_ID = 3;
32 | public final static byte TILE_WATER_ID = 4;
33 |
34 | //Generation Constants
35 | public final static int GEN_SUFACE_ITERATIONS = 15;
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/CopyOfPlayer.java:
--------------------------------------------------------------------------------
1 | /* Player.java -- class for describing a single player
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.graphics.Bitmap;
11 | import android.graphics.Canvas;
12 | import android.graphics.Paint;
13 | import android.graphics.RectF;
14 |
15 | // some random behavior
16 | public class CopyOfPlayer {
17 | private int health;
18 |
19 |
20 | private int x; // (x, y) position for up-left corner
21 | private int y ;
22 | private int speedX = 5; // random number
23 | private int speedY = 3;
24 |
25 | int xMax, yMax;
26 | int xMin = 0;
27 | int yMin = 0;
28 | //private RectF bounds;
29 | //private Paint paint;
30 |
31 | // picture icon of the player, width and height
32 | private Bitmap bitmap;
33 | private int width;
34 | private int height;
35 |
36 |
37 | /* initialization, set to simple color,
38 | we need a picture later
39 | */
40 | // public Player(int color){
41 | // bounds = new RectF();
42 | // paint = new Paint();
43 | // paint.setColor(color);
44 | //
45 | // }
46 | public CopyOfPlayer(Bitmap bitmap, int x, int y){
47 | this.bitmap =bitmap;
48 | this.width = bitmap.getWidth();
49 | this.height = bitmap.getHeight();
50 | this.x =x;
51 | this.y =y;
52 | }
53 |
54 |
55 | /* update the location,
56 | * and keep the player in bound.
57 | */
58 | public void moveWithCollisionDetection(){
59 | // get new (x, y) position
60 | x = x+ speedX;
61 | y = y+ speedY;
62 |
63 | // detect collision on edge of screen
64 | if (x+width >xMax){
65 | speedX = -speedX;
66 | x = xMax - width;
67 | } else if (x < xMin){
68 | speedX = -speedX;
69 | x = xMin;
70 | }
71 |
72 | if (y + height > yMax){
73 | speedY= -speedY;
74 | y = yMax -height;
75 | } else if (y < yMin) {
76 | speedY= -speedY;
77 | y = yMin;
78 | }
79 | }
80 |
81 | // another updating method
82 | public void UpdateLocation(){
83 | x = x+speedX;
84 | y = y+speedY;
85 | }
86 |
87 | public void draw(Canvas canvas){
88 |
89 | canvas.drawBitmap(bitmap, x, y, null);
90 | }
91 |
92 | public int getWidth() {
93 | return width;
94 | }
95 | public int getHeight(){
96 | return height;
97 | }
98 |
99 | public int getX(){
100 | return x;
101 | }
102 | public void setX(int x){
103 | this.x=x;
104 | }
105 |
106 | public int getY(){
107 | return y;
108 | }
109 | public void setY(int y){
110 | this.y =y;
111 | }
112 |
113 | public int getSpeedX(){
114 | return speedX;
115 | }
116 | public void setSpeedX(int speedX){
117 | this.speedX =speedX;
118 | }
119 | public int getSpeedY(){
120 | return speedY;
121 | }
122 | public void setSpeedY(int speedY){
123 | this.speedY=speedY;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/GameProgram.java:
--------------------------------------------------------------------------------
1 | /* GameProgram.java - Class for game logic and main loop.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import java.util.HashMap;
11 |
12 | import android.content.Context;
13 | import android.content.res.Resources;
14 | import android.graphics.BitmapFactory;
15 | import android.graphics.Canvas;
16 | import android.graphics.Point;
17 | import android.location.Criteria;
18 | import android.location.Location;
19 | import android.location.LocationManager;
20 | import android.util.Log;
21 | import android.widget.Toast;
22 |
23 | /*
24 | * A lot of this code was inspired from
25 | * http://www.edu4java.com/androidgame/androidgame3.html
26 | *
27 | * This class will perform game logic and
28 | * call the onDraw method for each frame.
29 | */
30 | public class GameProgram extends Thread {
31 | private GraphicsView gv;
32 | private boolean running = false;
33 | //private Camera cam;
34 | private BaseTiles base_tiles;
35 | private World world;
36 | private LocationTask locTask;
37 | private long currentSeed;
38 | private Context context;
39 | private Resources res;
40 |
41 | private HashMap tileLib;
42 |
43 | private double latitude, longitude;
44 |
45 | public GameProgram(GraphicsView view, Context context){
46 | this.gv = view;
47 | this.context = context;
48 | this.res = this.context.getResources();
49 | this.locTask = new LocationTask(context);
50 | this.locTask.init();
51 |
52 | this.currentSeed = this.locTask.makeSeedFromLocation();
53 |
54 | tileLib = new HashMap();
55 | tileLib.put(Constants.TILE_GRASS_ID, new Tile(Constants.TILE_GRASS_ID, BitmapFactory.decodeResource(this.res, R.drawable.grass), true));
56 | tileLib.put(Constants.TILE_DIRT_ID, new Tile(Constants.TILE_DIRT_ID, BitmapFactory.decodeResource(this.res, R.drawable.dirt), true));
57 | tileLib.put(Constants.TILE_SAND_ID, new Tile(Constants.TILE_SAND_ID, BitmapFactory.decodeResource(this.res, R.drawable.sand), true));
58 | tileLib.put(Constants.TILE_WATER_ID, new Tile(Constants.TILE_WATER_ID, BitmapFactory.decodeResource(this.res, R.drawable.water1), false));
59 |
60 | //generate a world in 2d array
61 | world = new World(context, this.currentSeed, this.locTask.getLatitude(), this.locTask.getLongitude());
62 | world.generateWorld();
63 |
64 | //tile the world with sprites
65 | this.base_tiles = new BaseTiles(tileLib, world);
66 | //base_tiles.setLocationWorld(-35, -27);
67 |
68 | /*boolean changed = false;
69 | boolean try_again = false;
70 | Point loc;
71 | do{
72 | loc = this.base_tiles.getCenterLocation();
73 | try_again = false;
74 | if(!tileLib.get(world.getWorldArr()[loc.x][loc.y]).isPassible()){
75 | try_again = true;
76 | changed = true;
77 | ++loc.x;
78 | }
79 |
80 | }while(try_again);*/
81 | //if(changed) base_tiles.setLocationWorld(loc.x, loc.y);
82 | }
83 |
84 | @Override
85 | public void run() {
86 | long ticks = 1000 / Constants.GAME_TARGET_FPS;
87 | long startTime;
88 | long sleepFor;
89 |
90 | while(running){
91 |
92 | //Next frames' Game Logic and stuff goes here.
93 | startTime = System.currentTimeMillis();
94 |
95 | //Try to draw the next frame
96 | Canvas frame = null;
97 | try{
98 | frame = gv.getHolder().lockCanvas();
99 | synchronized(gv.getHolder()){
100 | gv.onDraw(frame);
101 | }
102 | }finally{
103 | if(frame != null){
104 | gv.getHolder().unlockCanvasAndPost(frame);
105 | }
106 | }
107 |
108 | //Sleep between frames...
109 | sleepFor = ticks - (System.currentTimeMillis() - startTime);
110 | try{
111 | if(sleepFor > 0){
112 | sleep(sleepFor);
113 | }else{
114 | //The game is lagging here...
115 | sleep(10);
116 | }
117 | }catch (InterruptedException e) {
118 | // TODO Auto-generated catch block
119 | e.printStackTrace();
120 | }
121 | }
122 | }
123 |
124 | public void setRunning(boolean s){
125 | this.running = s;
126 | }
127 |
128 | public void draw(Canvas canvas, int x, int y){
129 | //this method is called by the draw method in graphics view.
130 | //the x and y vars are the movement vars for the player.
131 | base_tiles.render(canvas);
132 |
133 | Point newDxDy;
134 |
135 | newDxDy = checkCollision(base_tiles.getCenterLocation(), base_tiles.getPixelsInTile(), x, y);
136 |
137 | //Point lol = base_tiles.getstuff();
138 | //Log.d("stuff", lol.x+" "+lol.y);
139 |
140 | if(newDxDy.x != 0 || newDxDy.y != 0){
141 | base_tiles.moveLocation(newDxDy.x, newDxDy.y);
142 | }
143 | }
144 |
145 | //returns a new dx dy in a point that is a safe movement that wont intersect
146 | //something that is un-passable. THIS FUNCTION IS WAY TOO COMPLICATED!!! D:
147 | public Point checkCollision(Point world_loc, Point tile_loc, int dx, int dy){
148 | if(dx == 0 && dy == 0) return new Point(0, 0);
149 |
150 | Point top_l = new Point(world_loc.x, world_loc.y);
151 | Point top_r = new Point(world_loc.x, world_loc.y);
152 | Point bot_l = new Point(world_loc.x, world_loc.y);
153 | Point bot_r = new Point(world_loc.x, world_loc.y);
154 |
155 | Point newDxDy = new Point(dx, dy);
156 |
157 | boolean limitX = false;
158 | boolean limitY = false;
159 |
160 | //get block coords of bounding box points of player.
161 | if(((tile_loc.x+dx)-Constants.PLAYER_BOUNDING_BOX_RADIUS) < 0){
162 | top_l.x -= 1;
163 | bot_l.x -= 1;
164 | //This is the value needed to JUST touch the side of the adjacent tile.
165 | newDxDy.x = Constants.PLAYER_BOUNDING_BOX_RADIUS-tile_loc.x;
166 | }else if(((tile_loc.x+dx)+Constants.PLAYER_BOUNDING_BOX_RADIUS) >= Constants.WORLD_TILE_SIZE){
167 | top_r.x += 1;
168 | bot_r.x += 1;
169 | //This is the value needed to JUST touch the side of the adjacent tile.
170 | newDxDy.x = -tile_loc.x-Constants.PLAYER_BOUNDING_BOX_RADIUS+Constants.WORLD_TILE_SIZE;
171 | }
172 |
173 | if(((tile_loc.y+dy)-Constants.PLAYER_BOUNDING_BOX_RADIUS) < 0){
174 | top_l.y -= 1;
175 | top_r.y -= 1;
176 | //This is the value needed to JUST touch the side of the adjacent tile.
177 | newDxDy.y = Constants.PLAYER_BOUNDING_BOX_RADIUS-tile_loc.y;
178 | }else if(((tile_loc.y+dy)+Constants.PLAYER_BOUNDING_BOX_RADIUS) > Constants.WORLD_TILE_SIZE){
179 | bot_r.y += 1;
180 | bot_l.y += 1;
181 | //This is the value needed to JUST touch the side of the adjacent tile.
182 | newDxDy.y = -tile_loc.y-Constants.PLAYER_BOUNDING_BOX_RADIUS+Constants.WORLD_TILE_SIZE;
183 | }
184 |
185 | //check for map limits:
186 | if(top_l.x < 0){
187 | limitX = true;
188 | top_l.x = 0;
189 | }
190 | if(top_l.y < 0){
191 | limitY = true;
192 | top_l.y = 0;
193 | }
194 |
195 | if(top_r.x >= Constants.WORLD_SIZE){
196 | limitX = true;
197 | top_r.x = Constants.WORLD_SIZE-1;
198 | }
199 | if(top_r.y < 0){
200 | limitY = true;
201 | top_r.y = 0;
202 | }
203 |
204 | if(bot_l.x < 0){
205 | limitX = true;
206 | bot_l.x = 0;
207 | }
208 | if(bot_l.y >= Constants.WORLD_SIZE){
209 | limitY = true;
210 | bot_l.y = Constants.WORLD_SIZE-1;
211 | }
212 |
213 | if(bot_r.x >= Constants.WORLD_SIZE){
214 | limitX = true;
215 | bot_r.x = Constants.WORLD_SIZE-1;
216 | }
217 | if(bot_r.y >= Constants.WORLD_SIZE){
218 | limitY = true;
219 | bot_r.y = Constants.WORLD_SIZE-1;
220 | }
221 |
222 | //do collision detection for bottom left corner of bounding box.
223 | if(!tileLib.get(world.getWorldArr()[bot_l.x][bot_l.y]).isPassible()){
224 | //heading south-east
225 | if(dx >= 0 && dy > 0){
226 | limitY = true;
227 | }
228 | //heading south-west
229 | if(dx < 0 && dy > 0){
230 | if(sideDetect(tile_loc.x-Constants.PLAYER_BOUNDING_BOX_RADIUS, tile_loc.y+Constants.PLAYER_BOUNDING_BOX_RADIUS, dx, dy) == 0){
231 | limitY = true;
232 | }else{
233 | limitX = true;
234 | }
235 | }
236 | //heading north-west
237 | if(dx < 0 && dy <= 0){
238 | limitX = true;
239 | }
240 | }
241 |
242 | //do collision detection for bottom right corner of bounding box.
243 | if(!tileLib.get(world.getWorldArr()[bot_r.x][bot_r.y]).isPassible()){
244 | //heading south-west
245 | if(dx <= 0 && dy > 0){
246 | limitY = true;
247 | }
248 | //heading south-east
249 | if(dx > 0 && dy > 0){
250 | if(sideDetect(tile_loc.x+Constants.PLAYER_BOUNDING_BOX_RADIUS, tile_loc.y+Constants.PLAYER_BOUNDING_BOX_RADIUS, dx, dy) == 0){
251 | limitY = true;
252 | }else{
253 | limitX = true;
254 | }
255 | }
256 | //heading north-east
257 | if(dx > 0 && dy <= 0){
258 | limitX = true;
259 | }
260 | }
261 |
262 | //do collision detection for top right corner of bounding box.
263 | if(!tileLib.get(world.getWorldArr()[top_r.x][top_r.y]).isPassible()){
264 | //heading north-west
265 | if(dx <= 0 && dy < 0){
266 | limitY = true;
267 | }
268 | //heading north-east
269 | if(dx > 0 && dy < 0){
270 | if(sideDetect(tile_loc.x+Constants.PLAYER_BOUNDING_BOX_RADIUS, tile_loc.y-Constants.PLAYER_BOUNDING_BOX_RADIUS, dx, dy) == 0){
271 | limitY = true;
272 | }else{
273 | limitX = true;
274 | }
275 | }
276 | //heading south-east
277 | if(dx > 0 && dy >= 0){
278 | limitX = true;
279 | }
280 | }
281 |
282 | //do collision detection for top left corner of bounding box.
283 | if(!tileLib.get(world.getWorldArr()[top_l.x][top_l.y]).isPassible()){
284 | //heading north-east
285 | if(dx >= 0 && dy < 0){
286 | limitY = true;
287 | }
288 | //heading north-west
289 | if(dx < 0 && dy < 0){
290 | if(sideDetect(tile_loc.x-Constants.PLAYER_BOUNDING_BOX_RADIUS, tile_loc.y-Constants.PLAYER_BOUNDING_BOX_RADIUS, dx, dy) == 0){
291 | limitY = true;
292 | }else{
293 | limitX = true;
294 | }
295 | }
296 | //heading south-west
297 | if(dx < 0 && dy >= 0){
298 | limitX = true;
299 | }
300 | }
301 |
302 | if(limitX) dx = newDxDy.x;
303 | if(limitY) dy = newDxDy.y;
304 |
305 | return new Point(dx, dy);
306 | }
307 |
308 | /* Helper function for collision detection. It tells you if you cross a
309 | // vertical tile line or a horizontal tile line first given the dy and dx
310 | // as your direction. This is needed to catch a corner of an unpassable tile
311 | // when you are running fast enough to hop over that corner between frames.
312 | // return 0 for horizontal pass or 1 for vertical or otherwise. */
313 | public int sideDetect(int sx, int sy, int dx, int dy){
314 | //java's % operator behaves weird. Example: -2%32 = -2 NOT 30.
315 | sx = sx % Constants.WORLD_TILE_SIZE;
316 | sy = sy % Constants.WORLD_TILE_SIZE;
317 | if(sx < 0) sx += Constants.WORLD_TILE_SIZE;
318 | if(sy < 0) sy += Constants.WORLD_TILE_SIZE;
319 |
320 | //already hitting a side.
321 | if(sx == 0) return 1;
322 | if(sy == 0) return 0;
323 |
324 | float slope = ((float)dy)/dx;
325 |
326 | //heading south-east
327 | if(dx >= 0 && dy >= 0){
328 | int wall_dist = Constants.WORLD_TILE_SIZE-sx;
329 | float y_diff = wall_dist*slope;
330 | if(sy+y_diff > Constants.WORLD_TILE_SIZE){
331 | return 0;
332 | }else{
333 | return 1;
334 | }
335 | }
336 |
337 | //heading north-east
338 | if(dx >= 0 && dy < 0){
339 | int wall_dist = Constants.WORLD_TILE_SIZE-sx;
340 | float y_diff = wall_dist*slope;
341 | if(sy+y_diff < 0){
342 | return 0;
343 | }else{
344 | return 1;
345 | }
346 | }
347 |
348 | //heading south-west
349 | if(dx < 0 && dy >= 0){
350 | int wall_dist = sx;
351 | float y_diff = wall_dist*slope;
352 | if(sy-y_diff > Constants.WORLD_TILE_SIZE){
353 | return 0;
354 | }else{
355 | return 1;
356 | }
357 | }
358 |
359 | //heading north-west
360 | if(dx < 0 && dy < 0){
361 | int wall_dist = sx;
362 | float y_diff = wall_dist*slope;
363 | if(sy-y_diff < 0){
364 | return 0;
365 | }else{
366 | return 1;
367 | }
368 | }
369 |
370 | return 0;
371 | }
372 |
373 | public Context getContext(){
374 | return this.context;
375 | }
376 | }
377 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/GraphicsView.java:
--------------------------------------------------------------------------------
1 | /* GraphicsView.java - Class for main drawing surface and listeners.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.content.Context;
11 | import android.graphics.Bitmap;
12 | import android.graphics.BitmapFactory;
13 | import android.graphics.Canvas;
14 | import android.graphics.Color;
15 | import android.graphics.Paint;
16 | import android.view.MotionEvent;
17 | import android.view.SurfaceHolder;
18 | import android.view.SurfaceHolder.Callback;
19 | import android.view.SurfaceView;
20 | import android.view.View;
21 | import android.widget.Toast;
22 |
23 | /**
24 | *
25 | * @author Kyle
26 | * This class is the primary graphics class that is
27 | * responsible for all drawing routines. It takes the MainActivity
28 | * as its context.
29 | *
30 | * I guess it will eventually listen for input.
31 | */
32 | public class GraphicsView extends SurfaceView implements Callback {
33 |
34 | //Create a buffer bitmap so that static things can be redrawn fast and easy.
35 | private Bitmap cBuffer;
36 | //Create a current frame canvas for animated changes in the graphics.
37 | private Canvas cFrame;
38 | //A reference to the surface stuff.
39 | private SurfaceHolder graphicsHolder;
40 | //Game loop and thread.
41 | private GameProgram prog;
42 | //save context
43 | private Context context;
44 |
45 | private Paint p;
46 |
47 | private Player player;
48 | private PlayerAnimated playerAm;
49 |
50 | private Monster monster;
51 |
52 | //player movement vars.
53 | private int x = 0, y = 0;
54 |
55 | public GraphicsView(Context context) {
56 | super(context);
57 | this.context = context;
58 |
59 | prog = new GameProgram(this, context);
60 |
61 | graphicsHolder = this.getHolder();
62 | graphicsHolder.addCallback(this);
63 |
64 | Paint p = new Paint();
65 | p.setStyle(Paint.Style.FILL);
66 | p.setColor(Color.WHITE);
67 | this.p = p;
68 |
69 | cFrame = new Canvas();
70 | //cBuffer = Bitmap.createBitmap(Constants.WINDOW_WIDTH, Constants.WINDOW_HEIGHT, Bitmap.Config.ARGB_8888);
71 | //cFrame.setBitmap(cBuffer);
72 | //cFrame.drawRect(0, 0, Constants.WINDOW_WIDTH, Constants.WINDOW_HEIGHT, p);
73 |
74 | player = new Player(prog);
75 | /*playerAm = new PlayerAnimated(BitmapFactory.decodeResource(getResources(),
76 | R.drawable.walk),
77 | 10,50,//initial location
78 | 5,
79 | 5);
80 |
81 | monster = new Monster(BitmapFactory.decodeResource(getResources(),
82 | R.drawable.worm2),
83 | (Constants.WINDOW_WIDTH/2)-16,(Constants.WINDOW_HEIGHT/2)-16,//initial location
84 | 4,
85 | 4,4);*/
86 |
87 |
88 | //keeps the screen on while playing the game.
89 | this.setKeepScreenOn(true);
90 |
91 | }
92 |
93 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
94 |
95 | }
96 |
97 | public void surfaceCreated(SurfaceHolder holder) {
98 | prog.setRunning(true);
99 | prog.start();
100 | }
101 |
102 | public void surfaceDestroyed(SurfaceHolder holder) {
103 | prog.setRunning(false);
104 | while(prog.isAlive()){
105 | try{
106 | prog.join();
107 |
108 | }catch(InterruptedException e){}
109 | }
110 | this.setKeepScreenOn(false);
111 | }
112 |
113 | //Here is the main drawing method.
114 | @Override
115 | protected void onDraw(Canvas canvas) {
116 | super.onDraw(canvas);
117 |
118 | //draw the current frame buffer.
119 | //not sure what or how I'm going to use a buffer for yet. Maybe backgrounds?
120 | //canvas.drawBitmap(cBuffer, 0, 0, null);
121 |
122 | canvas.drawColor(0xFF000000);
123 | prog.draw(canvas, x, y);
124 |
125 |
126 | //Clear canvas. Remember that surfaceviews do not clean
127 | //the canvas on each call to this method.
128 | //canvas.drawRect(0,0,canvas.getWidth(),canvas.getHeight(), p);
129 |
130 | //draw to frame and buffer.
131 | //cFrame.drawRect(x, 0, x+50, 50, p);
132 |
133 | //draw directly to canvas
134 | //p.setColor(Color.RED);
135 | //canvas.drawRect(x, 0, x+50, 50, p);
136 | //x++;
137 |
138 |
139 | //draw many Tiles, for testing purpose
140 |
141 | // for (int i =0; i<10; ++i){
142 | // for (int j=0; j<8; ++j){
143 | // Tile tile = new Tile(BitmapFactory.decodeResource(getResources(),
144 | // R.drawable.grass), 50*i, 50*j);
145 | // tile.draw(canvas);
146 | // }
147 | // }
148 |
149 | //player.moveWithCollisionDetection();
150 | //player.draw(canvas);
151 |
152 | //playerAm.update(System.currentTimeMillis());
153 | //playerAm.draw(canvas);
154 |
155 | //monster.update(System.currentTimeMillis());
156 | //monster.draw(canvas);
157 | player.update(System.currentTimeMillis());
158 | player.draw(canvas);
159 |
160 | /*
161 | p.setColor(0xFFFF0000);
162 | canvas.drawRect((Constants.WINDOW_WIDTH/2)-1, (Constants.WINDOW_HEIGHT/2)-1, (Constants.WINDOW_WIDTH/2)+1, (Constants.WINDOW_HEIGHT/2)+1, p);
163 | canvas.drawRect((Constants.WINDOW_WIDTH/2)-23, (Constants.WINDOW_HEIGHT/2)-23, (Constants.WINDOW_WIDTH/2)-21, (Constants.WINDOW_HEIGHT/2)-21, p);
164 | canvas.drawRect((Constants.WINDOW_WIDTH/2)+23, (Constants.WINDOW_HEIGHT/2)-23, (Constants.WINDOW_WIDTH/2)+21, (Constants.WINDOW_HEIGHT/2)-21, p);
165 | canvas.drawRect((Constants.WINDOW_WIDTH/2)-23, (Constants.WINDOW_HEIGHT/2)+23, (Constants.WINDOW_WIDTH/2)-21, (Constants.WINDOW_HEIGHT/2)+21, p);
166 | canvas.drawRect((Constants.WINDOW_WIDTH/2)+23, (Constants.WINDOW_HEIGHT/2)+23, (Constants.WINDOW_WIDTH/2)+21, (Constants.WINDOW_HEIGHT/2)+21, p);
167 | */
168 | }
169 |
170 | //buffer getter
171 | public Canvas getBuffer(){
172 | return this.cFrame;
173 | }
174 |
175 | //buffer setter.
176 | public void setBuffer(Canvas b){
177 | this.cFrame = b;
178 | }
179 |
180 |
181 | /*FUNCTIONS BELOW ARE TEMP, MAY BE ALTERED LATER*/
182 |
183 | // touch input handler, just for test
184 | @Override
185 | public boolean onTouchEvent(MotionEvent event) {
186 | float currentX = event.getX();
187 | float currentY = event.getY();
188 |
189 | /*
190 | if (player.getSpeedX()>0 && currentXplayer.getX()+ player.getWidth()) {
194 | player.setSpeedX(- player.getSpeedX());
195 | }
196 | if (player.getSpeedY()>0 && currentYplayer.getY()+player.getHeight()) {
200 | player.setSpeedY (- player.getSpeedY());
201 | } */
202 |
203 | // handle the animated player
204 | // playerAm.setDest(currentX, currentY);
205 | player.setDest(currentX, currentY);
206 |
207 | if(event.getAction() == MotionEvent.ACTION_UP){
208 | x = 0;
209 | y = 0;
210 | }else{
211 | x = (int)((currentX - (Constants.WINDOW_WIDTH/2))/(Constants.WINDOW_WIDTH/14));
212 | y = (int)((currentY - (Constants.WINDOW_HEIGHT/2))/(Constants.WINDOW_HEIGHT/14));
213 | }
214 |
215 | return true; // Event handled
216 | }
217 |
218 | // Called back when the view is first created or its size changes.
219 | @Override
220 | public void onSizeChanged(int w, int h, int oldW, int oldH) {
221 | // Set the movement bounds for the ball
222 | // player.xMax = w-1;
223 | // player.yMax = h-1;
224 | }
225 |
226 | }
227 |
228 |
229 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Home.java:
--------------------------------------------------------------------------------
1 | /* Home.java - The entry view of game.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | /* Xiaolong, added Aug 09 */
9 |
10 | package com.kylepaulsen.openAndroidGame;
11 |
12 | import android.app.Activity;
13 | import android.content.Intent;
14 | import android.os.Bundle;
15 | import android.util.Log;
16 | import android.view.View;
17 | import android.view.View.OnClickListener;
18 | import android.view.Window;
19 | import android.view.WindowManager;
20 | import android.widget.Button;
21 |
22 | public class Home extends Activity implements OnClickListener{
23 |
24 | private Button introBtn;
25 | private Button startBtn;
26 |
27 | /** Called when the activity is first created. */
28 | @Override
29 | public void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.home);
32 | introBtn =(Button)findViewById(R.id.intro_btn);
33 | introBtn.setOnClickListener(this);
34 | startBtn =(Button)findViewById(R.id.start_btn);
35 | startBtn.setOnClickListener(this);
36 | }
37 |
38 | @Override
39 | public void onClick(View v) {
40 | if(v==introBtn){
41 | //TODO do sth to show the intro page......
42 | }else if(v==startBtn){
43 | startActivity(new Intent(Home.this, MainActivity.class));
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/LocationTask.java:
--------------------------------------------------------------------------------
1 | /* LocationTask.java - Class for getting location data and doing things with it.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.content.Context;
11 | import android.location.Criteria;
12 | import android.location.Location;
13 | import android.location.LocationManager;
14 | import android.widget.Toast;
15 |
16 | /*
17 | * This class is in charge of everything location task related.
18 | * The first thing it does is generate a random seed from your
19 | * last location.
20 | */
21 |
22 | public class LocationTask {
23 | private Context context;
24 | private double latitude, longitude;
25 |
26 | public LocationTask(Context con){
27 | this.context = con;
28 |
29 | //just some default values...
30 | this.latitude = 3000;
31 | this.longitude = 3000;
32 | }
33 |
34 | /*
35 | * The init function tries to get the last known location from the best
36 | * provider. These settings might be changed later.
37 | * THIS MUST BE CALLED BEFORE ANY OTHER METHOD IN HERE.
38 | */
39 | public void init(){
40 | //I might not be doing something right because the location
41 | //data isn't as close as I expected it to be.
42 |
43 | LocationManager lm = (LocationManager) this.context.getSystemService(Context.LOCATION_SERVICE);
44 | Criteria criteria = new Criteria();
45 | criteria.setAccuracy(Criteria.ACCURACY_FINE);
46 | Location lastLocation = null;
47 |
48 | for(int tries=0; tries<3; ++tries){
49 | String provider = lm.getBestProvider(criteria, true);
50 | lastLocation = lm.getLastKnownLocation(provider);
51 | if(lastLocation != null){
52 | break;
53 | }
54 | }
55 |
56 | if(lastLocation == null){
57 | //couldn't get location. send error message or something...
58 | Toast.makeText(this.context, "Error: Couldn't get last location!", Toast.LENGTH_LONG).show();
59 | //default to near Salem Oregon.
60 | this.latitude = 45;
61 | this.longitude = -123;
62 | }else{
63 | this.latitude = lastLocation.getLatitude();
64 | this.longitude = lastLocation.getLongitude();
65 | }
66 | }
67 |
68 | public long makeSeedFromLocation(){
69 | /*
70 | * Here is the basic idea for generating a seed:
71 | * First add 90 to lat and 180 to long to guarantee they are positive.
72 | * Then multiply both by 100 and then divide by 5. (mult by 20).
73 | * We mult by 100 because we want to keep up to the hundredth precision
74 | * out of the lat and long before we floor them.
75 | * We divide by 5 because we want increments of 5 hundredth's to belong
76 | * to the same seed. Then we concatenate the numbers together to get the
77 | * seed. Keep in mind that we must multiply the lat_num by 10000 to avoid
78 | * digit collision during concatenation. (long_num will never be more than 7200)
79 | */
80 | if(this.latitude == 3000){
81 | Toast.makeText(this.context, "LocationTask was used without an init() call.", Toast.LENGTH_LONG).show();
82 | return 0;
83 | }
84 |
85 | long lat_num = (long) Math.floor((this.latitude+90)*20)*10000;
86 | long long_num = (long) Math.floor((this.longitude+180)*20);
87 | Toast.makeText(this.context, "Seed is: "+(lat_num+long_num), Toast.LENGTH_LONG).show();
88 | return (lat_num+long_num);
89 | }
90 |
91 | public double getLongitude(){
92 | if(this.longitude == 3000){
93 | Toast.makeText(this.context, "LocationTask was used without an init() call.", Toast.LENGTH_LONG).show();
94 | return 0;
95 | }
96 | return this.longitude;
97 | }
98 |
99 | public double getLatitude(){
100 | if(this.latitude == 3000){
101 | Toast.makeText(this.context, "LocationTask was used without an init() call.", Toast.LENGTH_LONG).show();
102 | return 0;
103 | }
104 | return this.latitude;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/MainActivity.java:
--------------------------------------------------------------------------------
1 | /* MainActivity.java - The main class that extends activity.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.app.Activity;
11 | import android.os.Bundle;
12 | import android.util.Log;
13 | import android.view.Window;
14 | import android.view.WindowManager;
15 |
16 | public class MainActivity extends Activity {
17 |
18 | GraphicsView gameView;
19 | /** Called when the activity is first created. */
20 | @Override
21 | public void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 |
24 | //Get rid of the application title bar.
25 | requestWindowFeature(Window.FEATURE_NO_TITLE);
26 | //Force application full screen.
27 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
28 |
29 | Constants.WINDOW_HEIGHT = getWindowManager().getDefaultDisplay().getHeight();
30 | Constants.WINDOW_WIDTH = getWindowManager().getDefaultDisplay().getWidth();
31 |
32 | //Kyle's android screen is 480x800
33 | Log.d("Main", "screen dimentions: "+Constants.WINDOW_WIDTH+", "+Constants.WINDOW_HEIGHT);
34 |
35 | gameView = new GraphicsView(this);
36 |
37 | //Set the graphics view as the main content view.
38 | //Note that R.layout.main is now no longer used..
39 |
40 | setContentView(gameView);
41 |
42 | }
43 | }
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Monster.java:
--------------------------------------------------------------------------------
1 | /* PlayerAnimated.java - Class for animated sprite.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | /* @date July09
11 | * @author Xiaolong
12 | */
13 | import android.graphics.Bitmap;
14 | import android.graphics.Canvas;
15 | import android.graphics.Rect;
16 |
17 | import java.lang.Math;
18 |
19 |
20 | public class Monster extends WorldEnt {
21 | private Bitmap bitmap; // the animation sequence
22 | private Rect sourceRect; // the rectangle to be drawn from the animation bitmap
23 | private int frameNrX; // number of frames in animation
24 | private int frameNrY;
25 | private int currentFrameX; // the current frame
26 | private int currentFrameY;
27 |
28 | /*Note that this is not the game FPS but the walking FPS.*/
29 | private long frameTicker; // the time of the last frame update
30 | private int framePeriod; // milliseconds between each frame (1000/fps)
31 |
32 | private int spriteWidth; // the width of the sprite to calculate the cut out rectangle
33 | private int spriteHeight; // the height of the sprite
34 |
35 | private int x; // the X coordinate of the object (top left of the image)
36 | private int y; // the Y coordinate of the object (top left of the image)
37 |
38 | //for motion use, July09
39 | private static int SPEED = 3;
40 | private int speedX, speedY;
41 | private float destX, destY;
42 |
43 |
44 | public Monster(Bitmap bitmap, int x, int y, int fps, int frameCountX, int frameCountY ){
45 | //super(bitmap);
46 | this.bitmap = bitmap;
47 | this.x =x; //initial location (x,y)
48 | this.y =y;
49 | currentFrameX =0;
50 | currentFrameY =0;
51 | frameNrX = frameCountX;
52 | frameNrY = frameCountY;
53 |
54 | /* the cutting method depend on the
55 | * source picture used here
56 | */
57 | spriteWidth = bitmap.getWidth()/frameCountX;
58 | spriteHeight = bitmap.getHeight()/frameCountY;
59 |
60 | sourceRect = new Rect(0,0,spriteWidth,spriteHeight);
61 | framePeriod = 1000/fps;
62 | frameTicker =01;
63 |
64 | this.speedX =0;
65 | this.speedY =0;
66 | }
67 |
68 | public void update(long gameTime){
69 |
70 | //firstly, update the sprite image
71 | if (gameTime > frameTicker + framePeriod){
72 | frameTicker = gameTime;// set current update time
73 | currentFrameX++; //increment frame
74 | if (currentFrameX>=frameNrX){
75 | currentFrameX =0;
76 | }
77 |
78 | }
79 | /* define the rectangle to cut out sprite
80 | * and update the correct frame
81 | */
82 | if(this.speedX>0) {
83 | currentFrameY =2;
84 | }
85 | else if (this.speedX<0) {
86 | currentFrameY =1;
87 | }
88 | else { // if move vertically
89 | if (speedY<0) currentFrameY= 3;
90 | else currentFrameY =0;
91 | }
92 |
93 | this.sourceRect.top = currentFrameY*spriteHeight;
94 | this.sourceRect.bottom = this.sourceRect.top+spriteHeight;
95 | this.sourceRect.left = currentFrameX*spriteWidth;
96 | this.sourceRect.right = this.sourceRect.left+spriteWidth;
97 |
98 | //then, update location
99 | this.updateLocation();
100 | }
101 |
102 | public void updateLocation(){
103 |
104 | //this.x = this.x + speedX;
105 | //this.y = this.y + speedY;
106 |
107 | // when it's close enough, stop moving
108 | if (Math.abs(this.destX-(this.x+0.5*this.spriteWidth))<10 ||
109 | Math.abs(this.destY-(this.y+0.5*this.spriteHeight))<10) {
110 | this.setSpeed(0, 0);
111 | }
112 | }
113 |
114 | // draw method of animated player
115 | public void draw (Canvas canvas){
116 | Rect destRect = new Rect(getX(),getY(), getX()+spriteWidth, getY()+spriteHeight);
117 | canvas.drawBitmap(bitmap, sourceRect, destRect, null);
118 | }
119 |
120 | // set destination and speed, July09
121 | public void setDest(float destX, float destY){
122 | this.destX = destX;
123 | this.destY = destY;
124 |
125 | // initial distance between destination and current location
126 | float distance = Math.round( Math.sqrt(Math.pow(destX-this.x, 2) + Math.pow(destY-this.y, 2)) );
127 | if (distance==0) distance = 1; //prevent dividing zero
128 | //calc speed
129 | this.speedX= Math.round((destX - this.x)* SPEED / distance);
130 | this.speedY =Math.round((destY - this.y)* SPEED / distance);
131 | }
132 |
133 |
134 | public void setSpeed(int sx, int sy){
135 | this.speedX =sx;
136 | this.speedY =sy;
137 | }
138 |
139 | public int getX(){
140 | return x;
141 | }
142 | public void setX(int x){
143 | this.x=x;
144 | }
145 |
146 | public int getY(){
147 | return y;
148 | }
149 | public void setY(int y){
150 | this.y =y;
151 | }
152 | }
153 |
154 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Player.java:
--------------------------------------------------------------------------------
1 | /* PlayerAnimated.java - Class for animated sprite.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | /* @date July09
11 | * @author Xiaolong
12 | */
13 | import android.graphics.Bitmap;
14 | import android.graphics.BitmapFactory;
15 | import android.graphics.Canvas;
16 | import android.graphics.Rect;
17 |
18 | import java.lang.Math;
19 |
20 |
21 | public class Player extends WorldEnt {
22 | private final int SPRITE_OFFSET_X = -4;
23 | private final int SPRITE_OFFSET_Y = 20;
24 |
25 | private Bitmap bitmap; // the animation sequence
26 | private Rect sourceRect; // the rectangle to be drawn from the animation bitmap
27 | private int frameNrX; // number of frames in animation
28 | private int frameNrY;
29 | private int frameAniDir; //frame animation direction
30 | private int currentFrameX; // the current frame
31 | private int currentFrameY;
32 |
33 | /*Note that this is not the game FPS but the walking FPS.*/
34 | private long frameTicker; // the time of the last frame update
35 | private int framePeriod; // milliseconds between each frame (1000/fps)
36 |
37 | private int spriteWidth; // the width of the sprite to calculate the cut out rectangle
38 | private int spriteHeight; // the height of the sprite
39 |
40 | private int x; // the X coordinate of the object (top left of the image)
41 | private int y; // the Y coordinate of the object (top left of the image)
42 |
43 | //for motion use, July09
44 | //private static int SPEED = 3;
45 | //private int speedX, speedY;
46 | private float destX, destY;
47 |
48 | private GameProgram gp;
49 |
50 | public Player(GameProgram gp){
51 | this.gp = gp;
52 | this.bitmap = BitmapFactory.decodeResource(this.gp.getContext().getResources(), R.drawable.maincharacter);
53 | this.x = Constants.WINDOW_WIDTH/2-16; //initial location (x,y)
54 | this.y = Constants.WINDOW_HEIGHT/2-40;
55 | this.currentFrameX = 1;
56 | this.currentFrameY = 0;
57 | this.frameNrX = 3;
58 | this.frameNrY = 4;
59 | this.frameAniDir = 0;
60 | /* the cutting method depend on the
61 | * source picture used here
62 | */
63 | this.spriteWidth = bitmap.getWidth()/frameNrX;
64 | this.spriteHeight = bitmap.getHeight()/frameNrY;
65 |
66 | sourceRect = new Rect(0,0,spriteWidth,spriteHeight);
67 | framePeriod = 1000/4; //4 is the fps
68 | frameTicker = 1;
69 |
70 | //this.speedX = 0;
71 | //this.speedY = 0;
72 | }
73 |
74 | public void update(long gameTime){
75 |
76 | //firstly, update the sprite image
77 | if (gameTime > frameTicker + framePeriod){
78 | frameTicker = gameTime;// set current update time
79 |
80 | if(currentFrameX == 0){
81 | currentFrameX = 1;
82 | frameAniDir = 0;
83 | }else if(currentFrameX == 2){
84 | currentFrameX = 1;
85 | frameAniDir = 1;
86 | }else if(currentFrameX == 1 && frameAniDir == 0){
87 | currentFrameX = 2;
88 | }else /*if(currentFrameX == 1 && frameAniDir == 1)*/{
89 | currentFrameX = 0;
90 | }
91 | }
92 | /* define the rectangle to cut out sprite
93 | * and update the correct frame
94 | */
95 | /*
96 | if(this.speedX>0) {
97 | currentFrameY =2;
98 | }
99 | else if (this.speedX<0) {
100 | currentFrameY =1;
101 | }
102 | else { // if move vertically
103 | if (speedY<0) currentFrameY= 3;
104 | else currentFrameY =0;
105 | }
106 | */
107 | this.sourceRect.top = currentFrameY*spriteHeight;
108 | this.sourceRect.bottom = this.sourceRect.top+spriteHeight;
109 | this.sourceRect.left = currentFrameX*spriteWidth;
110 | this.sourceRect.right = this.sourceRect.left+spriteWidth;
111 |
112 | //then, update location
113 | //this.updateLocation();
114 | }
115 |
116 | /*
117 | public void updateLocation(){
118 |
119 | //this.x = this.x + speedX;
120 | //this.y = this.y + speedY;
121 |
122 | // when it's close enough, stop moving
123 |
124 | if (Math.abs(this.destX-(this.x+0.5*this.spriteWidth))<10 ||
125 | Math.abs(this.destY-(this.y+0.5*this.spriteHeight))<10) {
126 | this.setSpeed(0, 0);
127 | }
128 |
129 | }*/
130 |
131 | // draw method of animated player
132 | public void draw (Canvas canvas){
133 | Rect destRect = new Rect(this.x+SPRITE_OFFSET_X, this.y+SPRITE_OFFSET_Y, (int)(this.x+(spriteWidth)*1.3)+SPRITE_OFFSET_X, (int)(this.y+(spriteHeight)*1.3)+SPRITE_OFFSET_Y);
134 | canvas.drawBitmap(bitmap, sourceRect, destRect, null);
135 | }
136 |
137 | // set destination and speed, July09
138 | public void setDest(float destX, float destY){
139 | this.destX = destX;
140 | this.destY = destY;
141 |
142 | int xDiff = (int) (Constants.WINDOW_WIDTH/2-destX);
143 | int yDiff = (int) (Constants.WINDOW_HEIGHT/2-destY);
144 |
145 | if(yDiff >= xDiff && yDiff > -xDiff){
146 | //bottom region
147 | if(currentFrameY != 3){
148 | currentFrameY = 3;
149 | }
150 | }else if(yDiff < xDiff && yDiff >= -xDiff){
151 | //right region
152 | if(currentFrameY != 1){
153 | currentFrameY = 1;
154 | }
155 | }else if(yDiff < xDiff && yDiff <= -xDiff){
156 | //top region
157 | if(currentFrameY != 0){
158 | currentFrameY = 0;
159 | }
160 | }else if(yDiff > xDiff && yDiff <= -xDiff){
161 | //left region
162 | if(currentFrameY != 2){
163 | currentFrameY = 2;
164 | }
165 | }
166 |
167 | /*
168 | // initial distance between destination and current location
169 | float distance = Math.round( Math.sqrt(Math.pow(destX-this.x, 2) + Math.pow(destY-this.y, 2)) );
170 | if (distance==0) distance = 1; //prevent dividing zero
171 | //calc speed
172 | this.speedX= Math.round((destX - this.x)* SPEED / distance);
173 | this.speedY =Math.round((destY - this.y)* SPEED / distance);
174 | */
175 | }
176 |
177 | /*
178 | public void setSpeed(int sx, int sy){
179 | this.speedX =sx;
180 | this.speedY =sy;
181 | }*/
182 |
183 | public int getX(){
184 | return x;
185 | }
186 | public void setX(int x){
187 | this.x=x;
188 | }
189 |
190 | public int getY(){
191 | return y;
192 | }
193 | public void setY(int y){
194 | this.y =y;
195 | }
196 | }
197 |
198 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/PlayerAnimated.java:
--------------------------------------------------------------------------------
1 | /* PlayerAnimated.java - Class for animated sprite.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.graphics.Bitmap;
11 | import android.graphics.Canvas;
12 | import android.graphics.Rect;
13 |
14 | import java.lang.Math;
15 |
16 | /*
17 | * @author Xiaolong
18 | * part of the code is inspired from an online tutorial
19 | * http://obviam.net/index.php/sprite-animation-with-android/
20 | *
21 | */
22 |
23 | public class PlayerAnimated {
24 | private Bitmap bitmap; // the animation sequence
25 | private Rect sourceRect; // the rectangle to be drawn from the animation bitmap
26 | private int frameNr; // number of frames in animation
27 | private int currentFrame; // the current frame
28 |
29 | /*Note that this is not the game FPS but the walking FPS.*/
30 | private long frameTicker; // the time of the last frame update
31 | private int framePeriod; // milliseconds between each frame (1000/fps)
32 |
33 | private int spriteWidth; // the width of the sprite to calculate the cut out rectangle
34 | private int spriteHeight; // the height of the sprite
35 |
36 | private int x; // the X coordinate of the object (top left of the image)
37 | private int y; // the Y coordinate of the object (top left of the image)
38 |
39 | //for motion use, July09
40 | private static int SPEED = 3;
41 | private int speedX, speedY;
42 | private float destX, destY;
43 |
44 |
45 | public PlayerAnimated(Bitmap bitmap, int x, int y,
46 | int fps, int frameCount ){
47 |
48 | this.bitmap = bitmap;
49 | this.x =x;
50 | this.y =y;
51 | currentFrame =0;
52 | frameNr = frameCount;
53 |
54 | /* the cutting method depend on the
55 | * source picture used here
56 | */
57 | spriteWidth = bitmap.getWidth()/frameCount;
58 | spriteHeight = bitmap.getHeight();
59 |
60 | sourceRect = new Rect(0,0,spriteWidth,spriteHeight);
61 | framePeriod = 1000/fps;
62 | frameTicker =01;
63 |
64 | this.speedX =0;
65 | this.speedY =0;
66 | }
67 |
68 | public void update(long gameTime){
69 |
70 | //firstly, update the sprite image
71 | if (gameTime > frameTicker + framePeriod){
72 | frameTicker = gameTime;// set current update time
73 | currentFrame++; //increment frame
74 | if (currentFrame>=frameNr){
75 | currentFrame =0;
76 | }
77 |
78 | }
79 | // define the rectangle to cut out sprite
80 | this.sourceRect.left = currentFrame*spriteWidth;
81 | this.sourceRect.right = this.sourceRect.left+spriteWidth;
82 |
83 | //then, update location
84 | this.updateLocation();
85 | }
86 |
87 | public void updateLocation(){
88 |
89 | this.x = this.x + speedX;
90 | this.y = this.y + speedY;
91 |
92 | // when it's close enough, stop moving
93 | if (Math.abs(this.destX-(this.x+0.5*this.spriteWidth))<10 ||
94 | Math.abs(this.destY-(this.y+0.5*this.spriteHeight))<10) {
95 | this.setSpeed(0, 0);
96 | }
97 | }
98 |
99 | // draw method of animated player
100 | public void draw (Canvas canvas){
101 | Rect destRect = new Rect(getX(),getY(), getX()+spriteWidth, getY()+spriteHeight);
102 | canvas.drawBitmap(bitmap, sourceRect, destRect, null);
103 | }
104 |
105 | // set destination and speed, July09
106 | public void setDest(float destX, float destY){
107 | this.destX = destX;
108 | this.destY = destY;
109 |
110 | // initial distance between destination and current location
111 | float distance = Math.round( Math.sqrt(Math.pow(destX-this.x, 2) + Math.pow(destY-this.y, 2)) );
112 | if (distance==0) distance = 1; //prevent dividing zero
113 | //calc speed
114 | this.speedX= Math.round((destX - this.x)* SPEED / distance);
115 | this.speedY =Math.round((destY - this.y)* SPEED / distance);
116 | }
117 |
118 |
119 | public void setSpeed(int sx, int sy){
120 | this.speedX =sx;
121 | this.speedY =sy;
122 | }
123 |
124 | public int getX(){
125 | return x;
126 | }
127 | public void setX(int x){
128 | this.x=x;
129 | }
130 |
131 | public int getY(){
132 | return y;
133 | }
134 | public void setY(int y){
135 | this.y =y;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/Tile.java:
--------------------------------------------------------------------------------
1 | /* Tile.java - Class for describing tiles.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.graphics.Bitmap;
11 | import android.graphics.Canvas;
12 |
13 | public class Tile {
14 |
15 | private int id;
16 | private Bitmap bitmap;
17 | private boolean passable;
18 |
19 | public Tile(int id, Bitmap bitmap, boolean passable){
20 | this.bitmap = bitmap;
21 | this.id = id;
22 | this.passable = passable;
23 | }
24 |
25 | public Bitmap getBitmap() {
26 | return this.bitmap;
27 | }
28 |
29 | public void setBitmap(Bitmap bitmap){
30 | this.bitmap = bitmap;
31 | }
32 |
33 | public boolean isPassible(){
34 | return passable;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/World.java:
--------------------------------------------------------------------------------
1 | /* World.java - Class for generating worlds in a 2d array.
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import java.util.HashMap;
11 | import java.util.Random;
12 |
13 | import android.content.Context;
14 | import android.util.Log;
15 |
16 | /*
17 | * This class will be in charge of generating random worlds based off of
18 | * some random seed (maybe a modulus of last gps coords?)
19 | * Worlds should be a 2d array that will later be tiled with sprites by the
20 | * Camera class.
21 | */
22 |
23 | public class World {
24 | private Context con;
25 | private byte worldArr[][];
26 | private long worldSeed;
27 | private double lon, lat;
28 | private Random ran;
29 |
30 | public World(Context context, long seed, double latitude, double longitude){
31 | //not sure what goes here yet.
32 | this.con = context;
33 | this.worldSeed = seed;
34 | this.ran = new Random(this.worldSeed);
35 | worldArr = new byte[Constants.WORLD_SIZE][Constants.WORLD_SIZE];
36 |
37 | for(int i=0; i chances = new HashMap();
57 | chances.put(Constants.TILE_AIR_ID, 0f);
58 | chances.put(Constants.TILE_GRASS_ID, 1.00f);
59 | chances.put(Constants.TILE_DIRT_ID, 1.00f);
60 | chances.put(Constants.TILE_SAND_ID, 0.90f);
61 | chances.put(Constants.TILE_WATER_ID, 0.90f);
62 |
63 | for(int t=0; t chances){
73 | byte next[][] = worldArr.clone();
74 |
75 | for(int j = 0; j < Constants.WORLD_SIZE-2; ++j){
76 | for(int i = 0; i < Constants.WORLD_SIZE-2; ++i){
77 | int tileCount[] = new int[chances.size()];
78 |
79 | //look at a local small square and make a histogram.
80 | for(int loc_j=0; loc_j<3; ++loc_j){
81 | for(int loc_i=0; loc_i<3; ++loc_i){
82 | int tile = worldArr[i+loc_i][j+loc_j];
83 | ++tileCount[tile];
84 | }
85 | }
86 |
87 | //pick winning tile out of a hat method where the tile that showed
88 | //up the most in the local small square gets a higher chance.
89 | int tileCountTotal = 0;
90 | for(byte k=0; k chances){
119 | byte next[][] = worldArr.clone();
120 |
121 | for(int j = 0; j < Constants.WORLD_SIZE-2; ++j){
122 | for(int i = 0; i < Constants.WORLD_SIZE-2; ++i){
123 | int tileCount[] = new int[chances.size()];
124 |
125 | byte biggest_idx = 0;
126 | int biggest_val = 0;
127 |
128 | //look at a local small square and make a histogram.
129 | for(int loc_j=0; loc_j<3; ++loc_j){
130 | for(int loc_i=0; loc_i<3; ++loc_i){
131 | if(++tileCount[worldArr[i+loc_i][j+loc_j]] > biggest_val){
132 | //the strongest tile (most counted one) wins.
133 | biggest_val = tileCount[worldArr[i+loc_i][j+loc_j]];
134 | biggest_idx = worldArr[i+loc_i][j+loc_j];
135 | }
136 | }
137 | }
138 |
139 | //award the center square in the local small square to the
140 | //winning tile.
141 | next[i+1][j+1] = biggest_idx;
142 | }
143 | }
144 | return next;
145 | }
146 |
147 | public byte[][] getWorldArr(){
148 | return this.worldArr;
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/com/kylepaulsen/openAndroidGame/WorldEnt.java:
--------------------------------------------------------------------------------
1 | /* WorldEnt.java - Abstract class for holding dynamic entities
2 | *
3 | * Copyright © 2011 Open-Android-Game Group
4 | * Please see the file COPYING in this
5 | * distribution for license terms.
6 | */
7 |
8 | package com.kylepaulsen.openAndroidGame;
9 |
10 | import android.graphics.Bitmap;
11 | import android.graphics.Canvas;
12 | import android.graphics.Rect;
13 |
14 | public abstract class WorldEnt {
15 |
16 | //i dont know what goes in here yet.
17 |
18 | /*
19 | protected Bitmap bitmap;
20 |
21 | public WorldEnt(Bitmap bitmap){
22 | this.bitmap = bitmap;
23 | }
24 | */
25 |
26 | public void draw(Canvas canvas, Rect rect){
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/worldMapLatLongToPixel.txt:
--------------------------------------------------------------------------------
1 | world_map.jpg lat long to pixel functions:
2 |
3 | lat / -0.06698049772278683227848101265823 + 1351 = pxl lat
4 | long / 0.06657861654370824053452115812918 + 2697 = pxl long
5 |
6 |
7 |
--------------------------------------------------------------------------------