├── .gitignore
├── .idea
├── .name
├── misc.xml
├── modules.xml
├── uiDesigner.xml
└── workspace.xml
├── LICENSE
├── README.md
├── TileMapGenerator.iml
├── screenshots
├── ground_128.gif
├── mix_128_256.gif
├── sky_128.gif
└── underground_128.gif
└── src
├── LayerGenerator.java
├── LayerMap.java
├── LayerRatio.java
├── LayerSetting.java
├── LayerType.java
├── SampleGenerator.java
├── TileMapGenerator.java
├── TileMapViewer.java
└── TileType.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # IntelliJ
26 | *.iml
27 | .idea/
28 | *.ipr
29 | *.iws
30 | out/
31 | .idea_modules/
32 |
33 | # Eclipse
34 | .metadata
35 | .classpath
36 | .project
37 | .settings/
38 | bin/
39 | tmp/
40 | *.tmp
41 | *.bak
42 | *.swp
43 | *~.nib
44 | local.properties
45 | .loadpath
46 |
47 | # NetBeans
48 | nbproject/private/
49 | build/
50 | nbbuild/
51 | dist/
52 | nbdist/
53 | nbactions.xml
54 | nb-configuration.xml
55 |
56 | # Maven
57 | target/
58 | pom.xml.tag
59 | pom.xml.releaseBackup
60 | pom.xml.versionsBackup
61 | pom.xml.next
62 | release.properties
63 |
64 | # OS X
65 | .DS_Store
66 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | TileMapGenerator
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
71 |
72 |
73 |
74 | createAndValidateSkyMap
75 | w
76 | Tile
77 | id
78 |
79 |
80 |
81 | TileType
82 | getID()
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 | 1521307699394
311 |
312 |
313 | 1521307699394
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Furkan Türkal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
TileMapGenerator Public Source Repository
2 |
3 | **Create your own 2D Maps with layer-by-layer system using Noise-Sample and BufferedImage pattern**
4 |
5 | **Warning: Please see the [Copyright & Licensing](#copyright--licensing) section before use**
6 |
7 | [What It Is](#what-it-is)
8 |
9 | [How To Use](#how-to-use)
10 |
11 | [Features](#features)
12 |
13 | [Requirements](#requirements)
14 |
15 | [About](#about)
16 |
17 | [Collaborators](#collaborators)
18 |
19 | [Branches](#branches)
20 |
21 | [Copyright & Licensing](#copyright--licensing)
22 |
23 | [Contributing](#contributing)
24 |
25 | [Contact](#contact)
26 |
27 | ## What It Is
28 |
29 | **TileMapGenerator with Java using Noise-Sample and BufferedImage pattern**
30 |
31 | TileMapGenerator program for Java language is an easy and simple way to create your own 2D Maps with layer-by-layer system.
32 |
33 | **Uses : Please see [Requirements](#requirements) before use**
34 |
35 | **128x128**
36 |
37 | * SKY
38 |
39 | 
40 |
41 | * GROUND
42 |
43 | 
44 |
45 | * UNDERGROUND
46 |
47 | 
48 |
49 | **128x256**
50 |
51 | 
52 |
53 | ## Features
54 |
55 | * Map generation engine in given specifications
56 |
57 | * Adjustable Map size
58 |
59 | * Adjustable MapViewer scale-size
60 |
61 | * Adjustable TileTypes colors & ids
62 |
63 | * Detailed Map-Layer specifications
64 |
65 | * Adjustable size & scale & step-size feature of each Map-Layer
66 |
67 | * Advanced Map sample & noise pattern generation engine
68 |
69 | * Configurable random seed for each Map-Layer
70 |
71 | * Unique, fully randomized Map generation
72 |
73 | ## How To Use
74 |
75 | **Warning: You must use power-of-two values for map-size**
76 |
77 | **Warning: You must use least 128x128 values for map-size**
78 |
79 | * Define your unique Random
80 |
81 | ```java
82 | private static final Random random = new Random(System.currentTimeMillis());
83 | ```
84 |
85 | * Define your own LayerSettings
86 |
87 | ```java
88 | LayerSetting patternLayerSetting = new LayerSetting(height, width, stepSize, depth, random);
89 |
90 | LayerSetting skyLayerSetting = new LayerSetting(128, 128, 16, 0, random);
91 | LayerSetting groundLayerSetting = new LayerSetting(128, 128, 16, 0, random);
92 | LayerSetting undergroundLayerSetting = new LayerSetting(128, 128, 16, 0, random);
93 | ```
94 |
95 | * Define your own LayerGenerators
96 |
97 | ```java
98 | LayerGenerator patternGenerator = new LayerGenerator(patternLayerSetting);
99 |
100 | LayerGenerator skyGenerator = new LayerGenerator(skyLayerSetting);
101 | LayerGenerator groundGenerator = new LayerGenerator(groundLayerSetting);
102 | LayerGenerator undergroundGenerator = new LayerGenerator(undergroundLayerSetting);
103 | ```
104 |
105 | * Create your own LayerMap
106 |
107 | ```java
108 | LayerMap patternMap = patternGenerator.doCreate(LayerType.ANY);
109 |
110 | LayerMap skyMap = skyGenerator.doCreate(LayerType.SKY);
111 | LayerMap groundMap = groundGenerator.doCreate(LayerType.GROUND);
112 | LayerMap undergroundMap = undergroundGenerator.doCreate(LayerType.UNDERGROUND);
113 | ```
114 |
115 | * View your created Map
116 |
117 | ```java
118 | TileMapViewer.ViewMap("PATTERN", heightScaleFactor, widthScaleFactor, patternMap);
119 |
120 | TileMapViewer.ViewMap("SKY", 4, 4, skyMap);
121 | TileMapViewer.ViewMap("GROUND", 4, 4, groundMap);
122 | TileMapViewer.ViewMap("UNDERGROUND", 4, 4, undergroundMap);
123 | ```
124 |
125 | ## Requirements
126 |
127 | * You should be familiar with Java family
128 | * You will need a text editor (i.e Notepad++) or IDE (i.e IntelliJ Idea)
129 | * You will need a computer on which you have the rights to install JDK and Java SE dependencies
130 |
131 | ## About
132 |
133 | TileMapGenerator was created to serve three purposes:
134 |
135 | **TileMapGenerator is a basically an simple Noise Tile-Map-Generator**
136 |
137 | 1. To act as a map-viewer which is given noise and generator ratios.
138 |
139 | 2. To act as a byte-pixel based BufferedImage viewer.
140 |
141 | 3. To act as a map-generator that you can use in your own games or research purposes.
142 |
143 | ## Collaborators
144 |
145 | **Project Manager** - Furkan Türkal (GitHub: **[dentrax](https://github.com/dentrax)**)
146 |
147 | ## Branches
148 |
149 | We publish source for the **[TileMapGenerator]** in single rolling branch:
150 |
151 | The **[master branch](https://github.com/dentrax/TileMapGenerator/tree/master)** is extensively tested by our QA team and makes a great starting point for learning the algorithms. Also tracks [live changes](https://github.com/dentrax/TileMapGenerator/commits/master) by our team.
152 |
153 | ## Copyright & Licensing
154 |
155 | The core project code is copyrighted by Markus 'Notch' Persson who made main-noise-core in Twitch live-broadcast.
156 |
157 | The main project code is copyrighted by Furkan 'Dentrax' Türkal who made enhancements, fixes and improvements. And is covered by single licence.
158 |
159 | All program code (i.e. .java) is licensed under MIT License unless otherwise specified. Please see the **[LICENSE.md](https://github.com/Dentrax/TileMapGenerator/blob/master/LICENSE)** file for more information.
160 |
161 | **References**
162 |
163 | While this repository is being prepared, it may have been quoted from some sources. (i.e Notch)
164 | If there is an unspecified source, please contact me.
165 |
166 | ## Contributing
167 |
168 | Please check the [CONTRIBUTING.md](CONTRIBUTING.md) file for contribution instructions and naming guidelines.
169 |
170 | ## Contact
171 |
172 | TileMapGenerator was created by Furkan 'Dentrax' Türkal
173 |
174 | *
175 |
176 | You can contact by URL:
177 | **[CONTACT](https://github.com/dentrax)**
178 |
179 | Best Regards
--------------------------------------------------------------------------------
/TileMapGenerator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/screenshots/ground_128.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dentrax/TileMapGenerator/4c4b2047017aa74ad0a91e07eb0c357487ea0a22/screenshots/ground_128.gif
--------------------------------------------------------------------------------
/screenshots/mix_128_256.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dentrax/TileMapGenerator/4c4b2047017aa74ad0a91e07eb0c357487ea0a22/screenshots/mix_128_256.gif
--------------------------------------------------------------------------------
/screenshots/sky_128.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dentrax/TileMapGenerator/4c4b2047017aa74ad0a91e07eb0c357487ea0a22/screenshots/sky_128.gif
--------------------------------------------------------------------------------
/screenshots/underground_128.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dentrax/TileMapGenerator/4c4b2047017aa74ad0a91e07eb0c357487ea0a22/screenshots/underground_128.gif
--------------------------------------------------------------------------------
/src/LayerGenerator.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | import javax.swing.*;
9 | import java.util.Random;
10 |
11 | public final class LayerGenerator {
12 |
13 | private LayerSetting m_layerSetting;
14 |
15 | private Random m_random;
16 |
17 | public LayerGenerator(LayerSetting layerSetting) {
18 | this.m_layerSetting = layerSetting;
19 | this.m_random = layerSetting.getRandom();
20 | }
21 |
22 | private boolean isPowerOfTwo(int number) {
23 | return number > 0 && ((number & (number - 1)) == 0);
24 | }
25 |
26 | public LayerMap doCreate(LayerType layerType){
27 | LayerMap layerMap = null;
28 |
29 | if(this.m_layerSetting.getHeight() < 128){
30 | JOptionPane.showMessageDialog(null, "Height must be least 128", "Warning", JOptionPane.INFORMATION_MESSAGE);
31 | return null;
32 | }
33 |
34 | if(!this.isPowerOfTwo(this.m_layerSetting.getHeight())){
35 | JOptionPane.showMessageDialog(null, "Height must be power-up-two", "Warning", JOptionPane.INFORMATION_MESSAGE);
36 | return null;
37 | }
38 |
39 | if(this.m_layerSetting.getWidth() < 128){
40 | JOptionPane.showMessageDialog(null, "Width must be least 128", "Warning", JOptionPane.INFORMATION_MESSAGE);
41 | return null;
42 | }
43 |
44 | if(!this.isPowerOfTwo(this.m_layerSetting.getWidth())){
45 | JOptionPane.showMessageDialog(null, "Width must be power-up-two", "Warning", JOptionPane.INFORMATION_MESSAGE);
46 | return null;
47 | }
48 |
49 | switch (layerType){
50 | case SKY:
51 | layerMap = new LayerMap(this.m_layerSetting, this.doCreateSkyMap(this.m_layerSetting.getWidth(), this.m_layerSetting.getHeight())[0]);
52 | break;
53 | case GROUND:
54 | layerMap = new LayerMap(this.m_layerSetting, this.doCreateGroundMap(this.m_layerSetting.getWidth(), this.m_layerSetting.getHeight())[0]);
55 | break;
56 | case UNDERGROUND:
57 | layerMap = new LayerMap(this.m_layerSetting, this.doCreateUndergroundMap(this.m_layerSetting.getWidth(), this.m_layerSetting.getHeight(), this.m_layerSetting.getDepth())[0]);
58 | break;
59 | }
60 |
61 | return layerMap;
62 | }
63 |
64 | private byte[][] doCreateSkyMap(int w, int h) {
65 | do {
66 | byte[][] result = this.createSkyMapSample(w, h);
67 |
68 | int[] count = new int[256];
69 |
70 | for (int i = 0; i < w * h; i++) {
71 | count[result[0][i] & 0xff]++;
72 | }
73 | if (count[TileType.CLOUD.getID() & 0xff] < 2000) continue;
74 | if (count[TileType.STAIRSDOWN.getID() & 0xff] < 2) continue;
75 |
76 | return result;
77 |
78 | } while (true);
79 | }
80 |
81 | private byte[][] doCreateGroundMap(int w, int h) {
82 | do {
83 | byte[][] result = this.createGroundMapSample(w, h);
84 |
85 | int[] count = new int[256];
86 |
87 | for (int i = 0; i < w * h; i++) {
88 | count[result[0][i] & 0xff]++;
89 | }
90 | if (count[TileType.ROCK.getID() & 0xff] < 100) continue;
91 | if (count[TileType.SAND.getID() & 0xff] < 100) continue;
92 | if (count[TileType.GRASS.getID() & 0xff] < 100) continue;
93 | if (count[TileType.TREE.getID() & 0xff] < 100) continue;
94 | if (count[TileType.STAIRSDOWN.getID() & 0xff] < 2) continue;
95 |
96 | return result;
97 |
98 | } while (true);
99 | }
100 |
101 | private byte[][] doCreateUndergroundMap(int w, int h, int depth) {
102 | do {
103 | byte[][] result = this.createUndergroundMapSample(w, h, depth);
104 |
105 | int[] count = new int[256];
106 |
107 | for (int i = 0; i < w * h; i++) {
108 | count[result[0][i] & 0xff]++;
109 | }
110 | if (count[TileType.ROCK.getID() & 0xff] < 100) continue;
111 | if (count[TileType.DIRT.getID() & 0xff] < 100) continue;
112 | if (count[(TileType.IRONORE.getID() & 0xff) + depth - 1] < 20) continue;
113 | if (depth < 3) if (count[TileType.STAIRSDOWN.getID() & 0xff] < 2) continue;
114 |
115 | return result;
116 |
117 | } while (true);
118 | }
119 |
120 |
121 | private byte[][] createSkyMapSample(int w, int h) {
122 | SampleGenerator noise1 = new SampleGenerator(this.m_layerSetting, 8);
123 | SampleGenerator noise2 = new SampleGenerator(this.m_layerSetting, 8);
124 |
125 | byte[] map = new byte[w * h];
126 | byte[] data = new byte[w * h];
127 | for (int y = 0; y < h; y++) {
128 | for (int x = 0; x < w; x++) {
129 | int i = x + y * w;
130 |
131 | double val = Math.abs(noise1.values[i] - noise2.values[i]) * 3 - 2;
132 |
133 | double xd = x / (w - 1.0) * 2 - 1;
134 | double yd = y / (h - 1.0) * 2 - 1;
135 | if (xd < 0) xd = -xd;
136 | if (yd < 0) yd = -yd;
137 | double dist = xd >= yd ? xd : yd;
138 | dist = dist * dist * dist * dist;
139 | dist = dist * dist * dist * dist;
140 | val = -val * 1 - 2.2;
141 | val = val + 1 - dist * 20;
142 |
143 | if (val < LayerRatio.SKY.NOISE_INFINITEFALL_LOWER) {
144 | map[i] = TileType.INFINITEFALL.getID();
145 | } else {
146 | map[i] = TileType.CLOUD.getID();
147 | }
148 | }
149 | }
150 |
151 | stairsLoop: for (int i = 0; i < w * h / LayerRatio.SKY.RATIO_CLOUDCACTUS; i++) {
152 | int x = m_random.nextInt(w - 2) + 1;
153 | int y = m_random.nextInt(h - 2) + 1;
154 |
155 | for (int yy = y - 1; yy <= y + 1; yy++)
156 | for (int xx = x - 1; xx <= x + 1; xx++) {
157 | if (map[xx + yy * w] != TileType.CLOUD.getID()) continue stairsLoop;
158 | }
159 |
160 | map[x + y * w] = TileType.CLOUDCACTUS.getID();
161 | }
162 |
163 | int count = 0;
164 | stairsLoop: for (int i = 0; i < w * h; i++) {
165 | int x = m_random.nextInt(w - 2) + 1;
166 | int y = m_random.nextInt(h - 2) + 1;
167 |
168 | for (int yy = y - 1; yy <= y + 1; yy++)
169 | for (int xx = x - 1; xx <= x + 1; xx++) {
170 | if (map[xx + yy * w] != TileType.CLOUD.getID()) continue stairsLoop;
171 | }
172 |
173 | map[x + y * w] = TileType.STAIRSDOWN.getID();
174 | count++;
175 | if (count == LayerRatio.SKY.MAX_STAIRS_COUNT) break;
176 | }
177 |
178 | return new byte[][] { map, data };
179 | }
180 |
181 | private byte[][] createGroundMapSample(int w, int h) {
182 | SampleGenerator mnoise1 = new SampleGenerator(this.m_layerSetting, 16);
183 | SampleGenerator mnoise2 = new SampleGenerator(this.m_layerSetting, 16);
184 | SampleGenerator mnoise3 = new SampleGenerator(this.m_layerSetting, 16);
185 |
186 | SampleGenerator noise1 = new SampleGenerator(this.m_layerSetting, 32);
187 | SampleGenerator noise2 = new SampleGenerator(this.m_layerSetting, 32);
188 |
189 | byte[] map = new byte[w * h];
190 | byte[] data = new byte[w * h];
191 | for (int y = 0; y < h; y++) {
192 | for (int x = 0; x < w; x++) {
193 | int i = x + y * w;
194 |
195 | double val = Math.abs(noise1.values[i] - noise2.values[i]) * 3 - 2;
196 | double mval = Math.abs(mnoise1.values[i] - mnoise2.values[i]);
197 | mval = Math.abs(mval - mnoise3.values[i]) * 3 - 2;
198 |
199 | double xd = x / (w - 1.0) * 2 - 1;
200 | double yd = y / (h - 1.0) * 2 - 1;
201 | if (xd < 0) xd = -xd;
202 | if (yd < 0) yd = -yd;
203 | double dist = xd >= yd ? xd : yd;
204 | dist = dist * dist * dist * dist;
205 | dist = dist * dist * dist * dist;
206 | val = val + 1 - dist * 20;
207 |
208 | if (val < LayerRatio.GROUND.NOISE_WATER_LOWER) {
209 | map[i] = TileType.WATER.getID();
210 | } else if (val > LayerRatio.GROUND.NOISE_ROCK_HIGHER && mval < LayerRatio.GROUND.NOISE_ROCK_LOWER) {
211 | map[i] = TileType.ROCK.getID();
212 | } else {
213 | map[i] = TileType.GRASS.getID();
214 | }
215 | }
216 | }
217 |
218 | for (int i = 0; i < w * h / LayerRatio.GROUND.RATIO_SAND; i++) {
219 | int xs = m_random.nextInt(w);
220 | int ys = m_random.nextInt(h);
221 | for (int k = 0; k < 10; k++) {
222 | int x = xs + m_random.nextInt(21) - 10;
223 | int y = ys + m_random.nextInt(21) - 10;
224 | for (int j = 0; j < 100; j++) {
225 | int xo = x + m_random.nextInt(5) - m_random.nextInt(5);
226 | int yo = y + m_random.nextInt(5) - m_random.nextInt(5);
227 | for (int yy = yo - 1; yy <= yo + 1; yy++)
228 | for (int xx = xo - 1; xx <= xo + 1; xx++)
229 | if (xx >= 0 && yy >= 0 && xx < w && yy < h) {
230 | if (map[xx + yy * w] == TileType.GRASS.getID()) {
231 | map[xx + yy * w] = TileType.SAND.getID();
232 | }
233 | }
234 | }
235 | }
236 | }
237 |
238 | /*
239 | * for (int i = 0; i < w * h / 2800; i++) { int xs = random.nextInt(w); int ys = random.nextInt(h); for (int k = 0; k < 10; k++) { int x = xs + random.nextInt(21) - 10; int y = ys + random.nextInt(21) - 10; for (int j = 0; j < 100; j++) { int xo = x + random.nextInt(5) - random.nextInt(5); int yo = y + random.nextInt(5) - random.nextInt(5); for (int yy = yo - 1; yy <= yo + 1; yy++) for (int xx = xo - 1; xx <= xo + 1; xx++) if (xx >= 0 && yy >= 0 && xx < w && yy < h) { if (map[xx + yy * w] == TileType.grass.getID()) { map[xx + yy * w] = TileType.dirt.getID(); } } } } }
240 | */
241 |
242 | for (int i = 0; i < w * h / LayerRatio.GROUND.RATIO_TREE; i++) {
243 | int x = m_random.nextInt(w);
244 | int y = m_random.nextInt(h);
245 | for (int j = 0; j < 200; j++) {
246 | int xx = x + m_random.nextInt(15) - m_random.nextInt(15);
247 | int yy = y + m_random.nextInt(15) - m_random.nextInt(15);
248 | if (xx >= 0 && yy >= 0 && xx < w && yy < h) {
249 | if (map[xx + yy * w] == TileType.GRASS.getID()) {
250 | map[xx + yy * w] = TileType.TREE.getID();
251 | }
252 | }
253 | }
254 | }
255 |
256 | for (int i = 0; i < w * h / LayerRatio.GROUND.RATIO_FLOWER; i++) {
257 | int x = m_random.nextInt(w);
258 | int y = m_random.nextInt(h);
259 | int col = m_random.nextInt(4);
260 | for (int j = 0; j < 30; j++) {
261 | int xx = x + m_random.nextInt(5) - m_random.nextInt(5);
262 | int yy = y + m_random.nextInt(5) - m_random.nextInt(5);
263 | if (xx >= 0 && yy >= 0 && xx < w && yy < h) {
264 | if (map[xx + yy * w] == TileType.GRASS.getID()) {
265 | map[xx + yy * w] = TileType.FLOWER.getID();
266 | data[xx + yy * w] = (byte) (col + m_random.nextInt(4) * 16);
267 | }
268 | }
269 | }
270 | }
271 |
272 | for (int i = 0; i < w * h / LayerRatio.GROUND.RATIO_CACTUS; i++) {
273 | int xx = m_random.nextInt(w);
274 | int yy = m_random.nextInt(h);
275 | if (xx >= 0 && yy >= 0 && xx < w && yy < h) {
276 | if (map[xx + yy * w] == TileType.SAND.getID()) {
277 | map[xx + yy * w] = TileType.CACTUS.getID();
278 | }
279 | }
280 | }
281 |
282 | int count = 0;
283 | stairsLoop: for (int i = 0; i < w * h / 100; i++) {
284 | int x = m_random.nextInt(w - 2) + 1;
285 | int y = m_random.nextInt(h - 2) + 1;
286 |
287 | for (int yy = y - 1; yy <= y + 1; yy++)
288 | for (int xx = x - 1; xx <= x + 1; xx++) {
289 | if (map[xx + yy * w] != TileType.ROCK.getID()) continue stairsLoop;
290 | }
291 |
292 | map[x + y * w] = TileType.STAIRSDOWN.getID();
293 | count++;
294 | if (count == LayerRatio.GROUND.MAX_STAIRS_COUNT) break;
295 | }
296 |
297 | return new byte[][] { map, data };
298 | }
299 |
300 | private byte[][] createUndergroundMapSample(int w, int h, int depth) {
301 | SampleGenerator mnoise1 = new SampleGenerator(this.m_layerSetting, 16);
302 | SampleGenerator mnoise2 = new SampleGenerator(this.m_layerSetting, 16);
303 | SampleGenerator mnoise3 = new SampleGenerator(this.m_layerSetting, 16);
304 |
305 | SampleGenerator nnoise1 = new SampleGenerator(this.m_layerSetting, 16);
306 | SampleGenerator nnoise2 = new SampleGenerator(this.m_layerSetting, 16);
307 | SampleGenerator nnoise3 = new SampleGenerator(this.m_layerSetting, 16);
308 |
309 | SampleGenerator wnoise1 = new SampleGenerator(this.m_layerSetting, 16);
310 | SampleGenerator wnoise2 = new SampleGenerator(this.m_layerSetting, 16);
311 | SampleGenerator wnoise3 = new SampleGenerator(this.m_layerSetting, 16);
312 |
313 | SampleGenerator noise1 = new SampleGenerator(this.m_layerSetting, 32);
314 | SampleGenerator noise2 = new SampleGenerator(this.m_layerSetting, 32);
315 |
316 | byte[] map = new byte[w * h];
317 | byte[] data = new byte[w * h];
318 | for (int y = 0; y < h; y++) {
319 | for (int x = 0; x < w; x++) {
320 | int i = x + y * w;
321 |
322 | double val = Math.abs(noise1.values[i] - noise2.values[i]) * 3 - 2;
323 |
324 | double mval = Math.abs(mnoise1.values[i] - mnoise2.values[i]);
325 | mval = Math.abs(mval - mnoise3.values[i]) * 3 - 2;
326 |
327 | double nval = Math.abs(nnoise1.values[i] - nnoise2.values[i]);
328 | nval = Math.abs(nval - nnoise3.values[i]) * 3 - 2;
329 |
330 | double wval = Math.abs(wnoise1.values[i] - wnoise2.values[i]);
331 | wval = Math.abs(nval - wnoise3.values[i]) * 3 - 2;
332 |
333 | double xd = x / (w - 1.0) * 2 - 1;
334 | double yd = y / (h - 1.0) * 2 - 1;
335 | if (xd < 0) xd = -xd;
336 | if (yd < 0) yd = -yd;
337 | double dist = xd >= yd ? xd : yd;
338 | dist = dist * dist * dist * dist;
339 | dist = dist * dist * dist * dist;
340 | val = val + 1 - dist * 20;
341 |
342 | if (val > LayerRatio.UNDERGROUND.NOISE_LIQUID_HIGHER && wval < -2.0 + (depth) / 2 * 3) {
343 | if (depth > LayerRatio.UNDERGROUND.DEPTH_LAVA)
344 | map[i] = TileType.LAVA.getID();
345 | else
346 | map[i] = TileType.WATER.getID();
347 | } else if (val > LayerRatio.UNDERGROUND.NOISE_DIRT_HIGHER && (mval < LayerRatio.UNDERGROUND.NOISE_DIRT_MVAL || nval < LayerRatio.UNDERGROUND.NOISE_DIRT_NVAL)) {
348 | map[i] = TileType.DIRT.getID();
349 | } else {
350 | map[i] = TileType.ROCK.getID();
351 | }
352 | }
353 | }
354 |
355 | {
356 | int r = 2;
357 | for (int i = 0; i < w * h / LayerRatio.UNDERGROUND.RATIO_IRONORE; i++) {
358 | int x = m_random.nextInt(w);
359 | int y = m_random.nextInt(h);
360 | for (int j = 0; j < 30; j++) {
361 | int xx = x + m_random.nextInt(5) - m_random.nextInt(5);
362 | int yy = y + m_random.nextInt(5) - m_random.nextInt(5);
363 | if (xx >= r && yy >= r && xx < w - r && yy < h - r) {
364 | if (map[xx + yy * w] == TileType.ROCK.getID()) {
365 | map[xx + yy * w] = (byte) ((TileType.IRONORE.getID() & 0xff) + depth - 1);
366 | }
367 | }
368 | }
369 | }
370 | }
371 |
372 | if (depth < 3) {
373 | int count = 0;
374 | stairsLoop: for (int i = 0; i < w * h / 100; i++) {
375 | int x = m_random.nextInt(w - 20) + 10;
376 | int y = m_random.nextInt(h - 20) + 10;
377 |
378 | for (int yy = y - 1; yy <= y + 1; yy++)
379 | for (int xx = x - 1; xx <= x + 1; xx++) {
380 | if (map[xx + yy * w] != TileType.ROCK.getID()) continue stairsLoop;
381 | }
382 |
383 | map[x + y * w] = TileType.STAIRSDOWN.getID();
384 | count++;
385 | if (count == LayerRatio.UNDERGROUND.MAX_STAIRS_COUNT) break;
386 | }
387 | }
388 |
389 | return new byte[][] { map, data };
390 | }
391 |
392 |
393 | }
394 |
--------------------------------------------------------------------------------
/src/LayerMap.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | public final class LayerMap {
9 |
10 | private LayerSetting m_setting;
11 |
12 | private byte[] m_mapData;
13 |
14 | public LayerMap(LayerSetting setting, byte[] mapData) {
15 | this.m_setting = setting;
16 | this.m_mapData = mapData;
17 | }
18 |
19 | public byte[] getMapData(){
20 | return this.m_mapData;
21 | }
22 |
23 | public int getHeight(){
24 | return this.m_setting.getHeight();
25 | }
26 |
27 | public int getWidth(){
28 | return this.m_setting.getWidth();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/LayerRatio.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | public final class LayerRatio {
9 |
10 | public final class SKY {
11 |
12 | public static final double NOISE_CLOUDCACTUS_HIGHER = -0.25;
13 | public static final double NOISE_INFINITEFALL_LOWER = -0.25;
14 |
15 | public static final int RATIO_CLOUDCACTUS = 50;
16 |
17 | public static final int MAX_STAIRS_COUNT = 2;
18 | }
19 |
20 | public final class GROUND {
21 |
22 | public static final double NOISE_WATER_LOWER = -0.5;
23 |
24 | public static final double NOISE_ROCK_LOWER = -1.5;
25 | public static final double NOISE_ROCK_HIGHER = 0.5;
26 |
27 | public static final int RATIO_SAND = 2800;
28 | public static final int RATIO_TREE = 400;
29 | public static final int RATIO_FLOWER = 400;
30 | public static final int RATIO_CACTUS = 100;
31 |
32 |
33 | public static final int MAX_STAIRS_COUNT = 2;
34 | }
35 |
36 | public final class UNDERGROUND{
37 | public static final int DEPTH_LAVA = 2;
38 |
39 | public static final double NOISE_LIQUID_HIGHER = -2;
40 |
41 | public static final double NOISE_DIRT_HIGHER = -2;
42 |
43 | public static final double NOISE_DIRT_MVAL = -1.7;
44 | public static final double NOISE_DIRT_NVAL = -1.4;
45 |
46 | public static final int RATIO_IRONORE = 400;
47 |
48 | public static final int MAX_STAIRS_COUNT = 4;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/LayerSetting.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | import java.util.Random;
9 |
10 | public final class LayerSetting {
11 |
12 | private int m_width;
13 |
14 | private int m_height;
15 |
16 | private int m_stepSize;
17 |
18 | private int m_depth;
19 |
20 | private Random m_random;
21 |
22 | public LayerSetting(int width, int height, int stepSize, int depth, Random random) {
23 | this.m_width = width;
24 | this.m_height = height;
25 | this.m_stepSize = stepSize;
26 | this.m_depth = depth;
27 | this.m_random = random;
28 | }
29 |
30 | public int getWidth() {
31 | return this.m_width;
32 | }
33 |
34 | public int getHeight() {
35 | return this.m_height;
36 | }
37 |
38 | public int getStepSize() {
39 | return this.m_stepSize;
40 | }
41 |
42 | public int getDepth() {
43 | return this.m_depth;
44 | }
45 |
46 | public Random getRandom() {
47 | return this.m_random;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/LayerType.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | public enum LayerType {
9 | SKY,
10 | GROUND,
11 | UNDERGROUND,
12 | }
13 |
--------------------------------------------------------------------------------
/src/SampleGenerator.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | import java.util.Random;
9 |
10 | public final class SampleGenerator {
11 |
12 | private LayerSetting m_layerSetting;
13 |
14 | private int m_height;
15 |
16 | private int m_width;
17 |
18 | public double[] values;
19 |
20 | public SampleGenerator(LayerSetting layerSetting, int stepSize) {
21 | Random random = layerSetting.getRandom();
22 |
23 | this.m_height = layerSetting.getHeight();
24 | this.m_width = layerSetting.getWidth();
25 |
26 | values = new double[m_width * m_height];
27 |
28 | for (int y = 0; y < m_width; y += stepSize) {
29 | for (int x = 0; x < m_width; x += stepSize) {
30 | setSample(x, y, random.nextFloat() * 2 - 1);
31 | }
32 | }
33 |
34 | double scale = 1.0 / m_width;
35 | double scaleMod = 1;
36 | do {
37 | int halfStep = stepSize / 2;
38 | for (int y = 0; y < m_width; y += stepSize) {
39 | for (int x = 0; x < m_width; x += stepSize) {
40 | double a = getSample(x, y);
41 | double b = getSample(x + stepSize, y);
42 | double c = getSample(x, y + stepSize);
43 | double d = getSample(x + stepSize, y + stepSize);
44 |
45 | double e = (a + b + c + d) / 4.0 + (random.nextFloat() * 2 - 1) * stepSize * scale;
46 | setSample(x + halfStep, y + halfStep, e);
47 | }
48 | }
49 | for (int y = 0; y < m_width; y += stepSize) {
50 | for (int x = 0; x < m_width; x += stepSize) {
51 | double a = getSample(x, y);
52 | double b = getSample(x + stepSize, y);
53 | double c = getSample(x, y + stepSize);
54 | double d = getSample(x + halfStep, y + halfStep);
55 | double e = getSample(x + halfStep, y - halfStep);
56 | double f = getSample(x - halfStep, y + halfStep);
57 |
58 | double H = (a + b + d + e) / 4.0 + (random.nextFloat() * 2 - 1) * stepSize * scale * 0.5;
59 | double g = (a + c + d + f) / 4.0 + (random.nextFloat() * 2 - 1) * stepSize * scale * 0.5;
60 | setSample(x + halfStep, y, H);
61 | setSample(x, y + halfStep, g);
62 | }
63 | }
64 | stepSize /= 2;
65 | scale *= (scaleMod + 0.8);
66 | scaleMod *= 0.3;
67 | } while (stepSize > 1);
68 | }
69 |
70 | private double getSample(int x, int y) {
71 | return values[(x & (this.m_width - 1)) + (y & (this.m_height - 1)) * this.m_width];
72 | }
73 |
74 | private void setSample(int x, int y, double value) {
75 | values[(x & (this.m_width - 1)) + (y & (this.m_height - 1)) * this.m_width] = value;
76 | }
77 | }
--------------------------------------------------------------------------------
/src/TileMapGenerator.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | import java.util.Random;
9 |
10 | public final class TileMapGenerator {
11 |
12 | private static final Random random = new Random(System.currentTimeMillis());
13 |
14 | public static void main(String[] args) {
15 |
16 | LayerSetting skyLayerSetting = new LayerSetting(128, 128, 16, 0, random);
17 | LayerSetting groundLayerSetting = new LayerSetting(128, 128, 16, 0, random);
18 | LayerSetting undergroundLayerSetting = new LayerSetting(128, 128, 16, 0, random);
19 |
20 | LayerGenerator skyGenerator = new LayerGenerator(skyLayerSetting);
21 | LayerGenerator groundGenerator = new LayerGenerator(groundLayerSetting);
22 | LayerGenerator undergroundGenerator = new LayerGenerator(undergroundLayerSetting);
23 |
24 | int widthScaleFactor = 4;
25 | int heightScaleFactor = 4;
26 |
27 | int attempt = 1;
28 |
29 | while (true){
30 |
31 | LayerMap skyMap = skyGenerator.doCreate(LayerType.SKY);
32 | LayerMap groundMap = groundGenerator.doCreate(LayerType.GROUND);
33 | LayerMap undergroundMap = undergroundGenerator.doCreate(LayerType.UNDERGROUND);
34 |
35 | TileMapViewer.ViewMap("SKY - Attempt: " + attempt, heightScaleFactor, widthScaleFactor, skyMap);
36 | TileMapViewer.ViewMap("GROUND - Attempt: " + attempt, heightScaleFactor, widthScaleFactor, groundMap);
37 | TileMapViewer.ViewMap("UNDERGROUND - Attempt: " + attempt, heightScaleFactor, widthScaleFactor, undergroundMap);
38 |
39 | attempt++;
40 | }
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/TileMapViewer.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | import javax.swing.*;
9 | import java.awt.*;
10 | import java.awt.image.BufferedImage;
11 |
12 | public final class TileMapViewer {
13 |
14 | public static void ViewMap(String name, int heightScaleFactor, int widthScaleFactor, LayerMap layerMap){
15 | int width = layerMap.getWidth();
16 | int height = layerMap.getHeight();
17 |
18 | byte[] mapData = layerMap.getMapData();
19 |
20 | BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
21 | int[] pixels = new int[width * height];
22 |
23 | for (int y = 0; y < height; y++) {
24 | for (int x = 0; x < width; x++) {
25 | int i = x + y * width;
26 |
27 | if (mapData[i] == TileType.WATER.getID()) pixels[i] = TileType.WATER.getHexColor();
28 | if (mapData[i] == TileType.GRASS.getID()) pixels[i] = TileType.GRASS.getHexColor();
29 | if (mapData[i] == TileType.ROCK.getID()) pixels[i] = TileType.ROCK.getHexColor();
30 | if (mapData[i] == TileType.DIRT.getID()) pixels[i] = TileType.DIRT.getHexColor();
31 | if (mapData[i] == TileType.SAND.getID()) pixels[i] = TileType.SAND.getHexColor();
32 | if (mapData[i] == TileType.TREE.getID()) pixels[i] = TileType.TREE.getHexColor();
33 | if (mapData[i] == TileType.LAVA.getID()) pixels[i] = TileType.LAVA.getHexColor();
34 | if (mapData[i] == TileType.CLOUD.getID()) pixels[i] = TileType.CLOUD.getHexColor();
35 | if (mapData[i] == TileType.STAIRSDOWN.getID()) pixels[i] = TileType.STAIRSDOWN.getHexColor();
36 | if (mapData[i] == TileType.STAIRSUP.getID()) pixels[i] = TileType.STAIRSUP.getHexColor();
37 | if (mapData[i] == TileType.CLOUDCACTUS.getID()) pixels[i] = TileType.CLOUDCACTUS.getHexColor();
38 | }
39 | }
40 |
41 | img.setRGB(0, 0, width, height, pixels, 0, width);
42 | JOptionPane.showMessageDialog(null, null, name, JOptionPane.YES_NO_OPTION, new ImageIcon(img.getScaledInstance(width * widthScaleFactor, height * heightScaleFactor, Image.SCALE_AREA_AVERAGING)));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/TileType.java:
--------------------------------------------------------------------------------
1 | // ====================================================
2 | // TileMapGenerator Copyright(C) 2018 Furkan Türkal
3 | // This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4 | // and you are welcome to redistribute it under certain conditions; See
5 | // file LICENSE, which is part of this source code package, for details.
6 | // ====================================================
7 |
8 | public enum TileType {
9 | GRASS(0, 0x208020),
10 | ROCK(1, 0xa0a0a0),
11 | WATER(2, 0x000080),
12 | FLOWER(3, 0x0),
13 | TREE(4, 0x003000),
14 | DIRT(5, 0x604040),
15 | SAND(6, 0xa0a040),
16 | CACTUS(7, 0x0),
17 | HOLE(8, 0x0),
18 | TREESAPLING(9, 0x0),
19 | CACTUSSAPLING(10, 0x0),
20 | FARMLAND(11, 0x0),
21 | WHEAT(12, 0x0),
22 | LAVA(13, 0xff2020),
23 | STAIRSDOWN(14, 0xffffff),
24 | STAIRSUP(15, 0xffffff),
25 | INFINITEFALL(16, 0x0),
26 | CLOUD(17, 0xa0a0a0),
27 | HARDROCK(18, 0x0),
28 | IRONORE(19, 0x0),
29 | GOLDORE(20, 0x0),
30 | GEMORE(21, 0x0),
31 | CLOUDCACTUS(22, 0xff00ff);
32 |
33 | private final int m_id;
34 |
35 | private final int m_hexColor;
36 |
37 | TileType(final int id, final int hexColor) {
38 | this.m_id = id;
39 | this.m_hexColor = hexColor;
40 | }
41 |
42 | public byte getID(){
43 | return (byte)(this.m_id & (0xff));
44 | }
45 |
46 | public int getHexColor() {
47 | return this.m_hexColor;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------